20 package net.sf.gridarta.gui.panel.selectedsquare;
22 import java.awt.BorderLayout;
23 import java.awt.Color;
24 import java.awt.Container;
25 import java.awt.FlowLayout;
26 import java.awt.GridLayout;
27 import java.awt.Insets;
28 import java.awt.Point;
29 import java.awt.event.InputEvent;
30 import java.awt.event.MouseAdapter;
31 import java.awt.event.MouseEvent;
32 import java.awt.event.MouseListener;
33 import java.awt.geom.RectangularShape;
35 import javax.swing.AbstractButton;
36 import javax.swing.Action;
37 import javax.swing.DefaultListModel;
38 import javax.swing.Icon;
39 import javax.swing.ImageIcon;
40 import javax.swing.JButton;
41 import javax.swing.JLabel;
42 import javax.swing.JList;
43 import javax.swing.JPanel;
44 import javax.swing.JScrollPane;
45 import javax.swing.JViewport;
46 import javax.swing.ListSelectionModel;
47 import javax.swing.ScrollPaneConstants;
48 import javax.swing.event.ListSelectionEvent;
49 import javax.swing.event.ListSelectionListener;
69 import org.jetbrains.annotations.NotNull;
70 import org.jetbrains.annotations.Nullable;
122 private final DefaultListModel<G>
model =
new DefaultListModel<>();
134 private final Container
arrows =
new JPanel();
156 public void mapSizeChanged(@NotNull
final Size2D newSize) {
168 public void mapObjectsChanged(@NotNull
final Set<G> gameObjects, @NotNull
final Set<G> transientGameObjects) {
180 public void mapFileChanged(@Nullable
final MapFile oldMapFile) {
185 public void modifiedChanged() {
198 public void activeMapViewChanged(@Nullable
final MapView<G, A, R> mapView) {
201 if (mapView == null) {
205 mapModel = mapView.getMapControl().getMapModel();
206 mapCursor = mapView.getMapCursor();
231 public void selectionChanged(@Nullable
final MapSquare<G, A, R> mapSquare, @Nullable
final G gameObject) {
245 public void valueChanged(
final ListSelectionEvent e) {
258 public void mapCursorChangedPos(@NotNull
final Point location) {
263 public void mapCursorChangedMode() {
268 public void mapCursorChangedGameObject(@Nullable
final MapSquare<G, A, R> mapSquare, @Nullable
final G gameObject) {
275 public void mapCursorChangedSize() {
289 public void mousePressed(
final MouseEvent e) {
291 if (e.getClickCount() > 1) {
293 if (gameObject != null) {
321 public SelectedSquareView(@NotNull
final SelectedSquareModel<G, A, R> selectedSquareModel, @NotNull
final GameObjectAttributesDialogFactory<G, A, R> gameObjectAttributesDialogFactory, @NotNull
final ObjectChooser<G, A, R> objectChooser, @NotNull
final MapViewManager<G, A, R> mapViewManager, @NotNull
final MapViewSettings mapViewSettings, @Nullable
final ImageIcon compassIcon, @NotNull
final FaceObjectProviders faceObjectProviders, @NotNull
final Icon unknownSquareIcon, @NotNull
final Action... actions) {
327 setLayout(
new BorderLayout());
331 list.setBackground(Color.lightGray);
332 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
333 final JScrollPane scrollPane =
new JScrollPane(list);
334 scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
335 scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
336 add(scrollPane, BorderLayout.CENTER);
338 for (
final Action tmpAction : actions) {
339 final AbstractButton button =
new JButton(tmpAction);
340 button.setMargin(
new Insets(0, 0, 0, 0));
345 if (compassIcon != null) {
346 final Container compass =
new JPanel();
347 compass.add(
new JLabel(compassIcon));
348 add(compass, BorderLayout.NORTH);
350 list.addListSelectionListener(listSelectionListener);
351 list.addMouseListener(mouseListener);
352 list.setFocusable(
false);
354 mapViewManager.addMapViewManagerListener(mapViewManagerListener);
355 selectedSquareModel.addSelectedSquareListener(selectedSquareModelListener);
366 if (mapSquareListBottom) {
367 arrows.setLayout(
new GridLayout(4, 1));
368 add(arrows, BorderLayout.WEST);
370 arrows.setLayout(
new FlowLayout());
371 add(arrows, BorderLayout.SOUTH);
384 final int lastIndex = model.getSize() - 1;
389 final RectangularShape bounds = list.getCellBounds(lastIndex, lastIndex);
390 final int lowestY = (int) (bounds.getY() + bounds.getHeight());
391 if ((
int) e.getPoint().getY() >= lowestY) {
392 return lastIndex + 1;
395 final int listIndex = list.locationToIndex(e.getPoint());
396 assert listIndex >= 0;
405 list.setEnabled(
false);
409 list.setEnabled(
true);
419 @SuppressWarnings(
"TypeMayBeWeakened")
422 if (actualIndex >= model.getSize()) {
426 return model.getElementAt(actualIndex);
436 if (
list.getSelectedIndex() != actualIndex) {
437 list.setSelectedIndex(actualIndex);
454 final int size =
model.getSize();
456 return Math.max(0, size - 1);
467 if (mapCursor != null && index <
model.getSize()) {
479 if (gameObject != null) {
481 if (mapCursor != null) {
493 private static boolean isSelect(@NotNull
final InputEvent e) {
494 return (e.getModifiers() & InputEvent.BUTTON1_MASK) != 0;
502 private static boolean isInsert(@NotNull
final InputEvent e) {
503 return (e.getModifiers() & (InputEvent.BUTTON3_MASK | InputEvent.CTRL_MASK)) == InputEvent.BUTTON3_MASK;
511 private static boolean isDelete(@NotNull
final InputEvent e) {
512 return (e.getModifiers() & InputEvent.BUTTON2_MASK) != 0 || (e.getModifiers() & (InputEvent.BUTTON3_MASK | InputEvent.CTRL_MASK)) == (InputEvent.BUTTON3_MASK | InputEvent.CTRL_MASK);
516 if (this.mapModel != null) {
520 if (this.mapModel != null) {
524 if (this.mapCursor != null) {
528 if (this.mapCursor != null) {
532 final G gameObject = mapCursor == null ? null : mapCursor.getGameObject();
MapModel< G, A, R > mapModel
The currently active MapModel.
final SelectedSquareModelListener< G, A, R > selectedSquareModelListener
The SelectedSquareModelListener attached to selectedSquareModel.
G getSelectedGameObject()
Returns the currently selected GameObject within this list (currently selected MapSquare).
final ObjectChooser< G, A, R > objectChooser
The object chooser.
final ListSelectionListener listSelectionListener
The listener attached to list to be informed about selection changes.
MapSquare< G, A, R > getMapSquare()
boolean isSelectedMapSquares(@NotNull final Iterable< MapSquare< G, A, R >> mapSquares)
A MapModel reflects the data of a map.
boolean isAutojoin()
Returns whether "autojoin" is enabled.
void refresh()
Re-display the map square panel for SelectedSquareModel#selectedMapSquare.
Graphical User Interface of Gridarta.
final MapCursorListener< G, A, R > mapCursorListener
The MapCursorListener attached to mapCursor.
G getListGameObject(final int index)
Return a game object from the list.
final JList< G > list
The list of game objects.
This package contains the framework for validating maps.
static boolean isSelect(@NotNull final InputEvent e)
Determines if "select" was selected.
void deleteGameObject(final int index)
Deletes a GameObject with a specific list index.
void setMapCursor(@Nullable final MapModel< G, A, R > mapModel, @Nullable final MapCursor< G, A, R > mapCursor)
void updateArrows(final boolean mapSquareListBottom)
Updates the parameters of the arrows buttons.
Interface for listeners listening on MapModel events.
final SelectedSquareModel< G, A, R > selectedSquareModel
The model for this view.
A factory that creates dialogs for editing game object attributes.
static boolean isDelete(@NotNull final InputEvent e)
Determines if "delete" was selected.
MapSquare< G, A, R > getSelectedMapSquare()
Returns the currently selected map square.
BaseObject< G, A, R, ?> getSelection()
Returns the active arch in the left-side panel.
MapCursor provides methods to move and drag on map.
final Container arrows
The arrow buttons.
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
final MapModelListener< G, A, R > mapModelListener
The MapModelListener attached to mapModel.
CellRenderer for rendering ArchObjects on a certain map square in a list.
void insertGameObject(final int index)
Inserts a new game object.
int update(@Nullable final GameObjectContainer< G, A, R > mapSquare, @Nullable final G gameObject)
Updates the model to reflect a net.sf.gridarta.model.mapmodel.MapSquare.
Base package of all Gridarta classes.
SelectedSquareView(@NotNull final SelectedSquareModel< G, A, R > selectedSquareModel, @NotNull final GameObjectAttributesDialogFactory< G, A, R > gameObjectAttributesDialogFactory, @NotNull final ObjectChooser< G, A, R > objectChooser, @NotNull final MapViewManager< G, A, R > mapViewManager, @NotNull final MapViewSettings mapViewSettings, @Nullable final ImageIcon compassIcon, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final Icon unknownSquareIcon, @NotNull final Action... actions)
Create a new instance.
void addMapCursorListener(@NotNull final MapCursorListener< G, A, R > listener)
Register a MapCursorListener.
Reflects a game object (object on a map).
int getListIndex(@NotNull final MouseEvent e)
Determine the list index for a given mouse event.
final MapViewManagerListener< G, A, R > mapViewManagerListener
The map view manager listener.
final ModelUpdater< G, A, R > modelUpdater
The ModelUpdater used for updating model.
final MouseListener mouseListener
The MouseListener attached to the view to process mouse actions.
Container for settings that affect the rendering of maps.
GameObjects are the objects based on Archetypes found on maps.
final MapViewSettings mapViewSettings
The MapViewSettings instance.
static final long serialVersionUID
Serial Version UID.
Interface for listeners interested in events related to MapViewManager instances. ...
final DefaultListModel< G > model
The DefaultListModel of list.
boolean setSelectedMapSquare(@Nullable final MapSquare< G, A, R > mapSquare, @Nullable final G gameObject)
Sets the currently selected map square.
Base classes for rendering maps.
void setGameObject(@Nullable final G gameObject)
Sets the selected GameObject.
MapCursor< G, A, R > mapCursor
The currently tracked MapCursor.
void setSelectedIndex(final int index)
Set the currently selected list index.
Provider for faces of GameObjects and Archetypes.
The face is the appearance of an object.
boolean deleteSelectedGameObject(final boolean performAction, final boolean autoJoin)
Deletes the selected game object.
The panel that displays the game objects of the currently selected map square.
int getValidIndex(final int index)
Determine a valid list index near a given index.
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.
boolean insertGameObject(final boolean performAction, @NotNull final BaseObject< G, A, R, ?> gameObject, final boolean insertAtEnd, final boolean join)
Inserts a GameObject before the selected game object.
Common base interface for ObjectChoosers.
final GameObjectAttributesDialogFactory< G, A, R > gameObjectAttributesDialogFactory
The factory for creating game object attributes dialog instances.
Interface for listeners listening to MapCursor related events.
void showAttributeDialog(@NotNull final G gameObject)
Shows the game object attributes dialog for a given GameObject instance.
boolean isSelectedGameObjects(@NotNull final Iterable< G > gameObjects)
The location of a map file with a map directory.
Interface for MapArchObjects.
static boolean isInsert(@NotNull final InputEvent e)
Determines if "insert" was selected.
The class Size2D represents a 2d rectangular area.