20 package net.sf.gridarta.gui.panel.gameobjectattributes;
22 import java.awt.BorderLayout;
23 import java.awt.event.MouseAdapter;
24 import java.awt.event.MouseEvent;
25 import java.util.ArrayList;
26 import java.util.Iterator;
27 import java.util.List;
29 import java.util.Vector;
30 import javax.swing.DefaultListModel;
31 import javax.swing.JEditorPane;
32 import javax.swing.JList;
33 import javax.swing.JPanel;
34 import javax.swing.JScrollPane;
35 import javax.swing.JSplitPane;
36 import javax.swing.event.ListSelectionEvent;
37 import javax.swing.event.ListSelectionListener;
52 import org.jetbrains.annotations.NotNull;
53 import org.jetbrains.annotations.Nullable;
70 private final JList<ValidationError<G, A, R>>
errorList =
new JList<>();
76 private final JEditorPane
errorMsg =
new JEditorPane(
"text/html",
"");
95 private Vector<ValidationError<G, A, R>>
errors;
110 public void valueChanged(
final ListSelectionEvent e) {
111 if (e.getValueIsAdjusting()) {
126 public void mapSizeChanged(@NotNull
final Size2D newSize) {
136 public void mapObjectsChanged(@NotNull
final Set<G> gameObjects, @NotNull
final Set<G> transientGameObjects) {
146 public void mapFileChanged(@Nullable
final MapFile oldMapFile) {
151 public void modifiedChanged() {
161 public void activeMapViewChanged(@Nullable
final MapView<G, A, R> mapView) {
162 if (currentMapModel != null) {
165 currentMapModel = mapView == null ? null : mapView.getMapControl().getMapModel();
166 if (currentMapModel != null) {
191 setLayout(
new BorderLayout());
192 final JSplitPane splitPane =
new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
new JScrollPane(errorList),
new JScrollPane(errorMsg));
193 splitPane.setOneTouchExpandable(
true);
194 add(splitPane, BorderLayout.CENTER);
195 errorMsg.setEditable(
false);
196 errorList.addListSelectionListener(listSelectionListener);
198 errorList.addMouseListener(
new MouseAdapter() {
201 public void mousePressed(
final MouseEvent e) {
205 mapViewManager.addMapViewManagerListener(mapViewManagerListener);
206 mapView = mapViewManager.getActiveMapView();
216 listeners.
add(listener);
224 listeners.
remove(listener);
232 return errors != null && !errors.isEmpty();
241 if (errors == null) {
242 errorMsg.setText(null);
243 errorMsg.setCaretPosition(0);
248 error = errors.elementAt(index);
249 }
catch (
final ArrayIndexOutOfBoundsException ignored) {
250 errorMsg.setText(null);
251 errorMsg.setCaretPosition(0);
257 if (tmpMapView != null) {
258 final Iterator<G> gameObjectIterator = error.
getGameObjects().iterator();
259 if (gameObjectIterator.hasNext()) {
260 final G gameObject = gameObjectIterator.next();
263 final Iterator<MapSquare<G, A, R>> mapSquareIterator = error.
getMapSquares().iterator();
264 if (mapSquareIterator.hasNext()) {
270 errorMsg.setCaretPosition(0);
279 listener.warningsChanged(hasWarnings);
287 if (mapView != null) {
293 errorList.setModel(
new DefaultListModel<>());
302 assert mapView != null;
303 final List<ValidationError<G, A, R>> errorVector =
new ArrayList<>();
305 errorVector.add(validationError);
307 this.errors =
new Vector<>(errorVector);
308 errorList.setListData(this.errors);
final EventListenerList2< ErrorListViewListener > listeners
The registered listeners to notify.
void highlightEntries(final int index)
Display an error message.
final ListSelectionListener listSelectionListener
The list selection listener to detect selected list entries.
A MapModel reflects the data of a map.
Graphical User Interface of Gridarta.
T [] getListeners()
Returns an array of all the listeners.
This package contains the framework for validating maps.
Interface for listeners listening on MapModel events.
MapControl< G, A, R > getMapControl()
Return the controller of this view.
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
void fireErrorsUpdated(final boolean hasWarnings)
Notifies all listeners that the warnings may have changed.
String getMessage()
Returns the error message for this validation error.
MapModel< G, A, R > getMapModel()
Returns the map model.
Super class of all errors that could occur during map validation.
ErrorListView(@NotNull final MapViewManager< G, A, R > mapViewManager)
Create a ConnectionPanel.
Base package of all Gridarta classes.
Iterable< MapSquare< G, A, R > > getMapSquares()
Returns the MapSquares that caused the error.
Reflects a game object (object on a map).
void activeMapViewChanged(@Nullable MapView< G, A, R > mapView)
This event handler is called when the current map view has changed.
Interface for listeners interested in ErrorListView related events.
MapView< G, A, R > mapView
The MapView for displaying map errors.
void updateErrors(@NotNull final ErrorCollector< G, A, R > errors)
Updates the errors for the current map.
final JEditorPane errorMsg
The JLabel for displaying the error text.
void remove(@NotNull final T listener)
Removes a listener.
GameObjects are the objects based on Archetypes found on maps.
final MapModelListener< G, A, R > mapModelListener
The MapModelListener which is attached to currentMapModel.
void add(@NotNull final T listener)
Adds a listener.
boolean hasWarnings()
Returns whether any warnings are shown.
Interface for listeners interested in events related to MapViewManager instances. ...
final JList< ValidationError< G, A, R > > errorList
The list for displaying the errors.
void updateErrors()
Updates the displayed errors.
Base classes for rendering maps.
void setGameObject(@Nullable final G gameObject)
Sets the selected GameObject.
void addErrorListViewListener(@NotNull final ErrorListViewListener listener)
Adds an ErrorListViewListener to be notified about changes.
Vector< ValidationError< G, A, R > > errors
The currently displayed errors.
List< G > getGameObjects()
Returns the GameObjects that caused the error.
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
MapModel< G, A, R > currentMapModel
Last known active map.
Type-safe version of EventListenerList.
MapCursor< G, A, R > getMapCursor()
Returns the MapCursor of this view.
A map view consists of a map grid and a map cursor, and is attached to a map control.
An interface for classes that collect errors.
An ErrorPanel displays errors to the user.
final MapViewManagerListener< G, A, R > mapViewManagerListener
ErrorCollector< G, A, R > getErrors()
Gets the errors in this map.
static final long serialVersionUID
The serial version UID.
void removeErrorListViewListener(@NotNull final ErrorListViewListener listener)
Removes an ErrorListViewListener to be notified about changes.
void setMapSquare(@Nullable final MapSquare< G, A, R > mapSquare)
Sets the selected MapSquare.
The location of a map file with a map directory.
Interface for MapArchObjects.
The class Size2D represents a 2d rectangular area.