 |
Gridarta Editor
|
Go to the documentation of this file.
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.ListSelectionListener;
68 import org.jetbrains.annotations.NotNull;
69 import org.jetbrains.annotations.Nullable;
121 private final DefaultListModel<G>
model =
new DefaultListModel<>();
133 private final Container
arrows =
new JPanel();
155 public void mapSizeChanged(@NotNull
final Size2D newSize) {
167 public void mapObjectsChanged(@NotNull
final Set<G> gameObjects, @NotNull
final Set<G> transientGameObjects) {
179 public void mapFileChanged(@Nullable
final MapFile oldMapFile) {
184 public void modifiedChanged() {
197 public void activeMapViewChanged(@Nullable
final MapView<G, A, R> mapView) {
200 if (mapView ==
null) {
204 mapModel = mapView.getMapControl().getMapModel();
243 public void mapCursorChangedPos(@NotNull
final Point location) {
248 public void mapCursorChangedMode() {
253 public void mapCursorChangedGameObject(@Nullable
final MapSquare<G, A, R> mapSquare, @Nullable
final G gameObject) {
260 public void mapCursorChangedSize() {
274 public void mousePressed(
final MouseEvent e) {
276 if (e.getClickCount() > 1) {
278 if (gameObject !=
null) {
306 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) {
312 setLayout(
new BorderLayout());
316 list.setBackground(Color.lightGray);
317 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
318 final JScrollPane scrollPane =
new JScrollPane(
list);
319 scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
320 scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
321 add(scrollPane, BorderLayout.CENTER);
323 for (
final Action tmpAction : actions) {
324 final AbstractButton button =
new JButton(tmpAction);
325 button.setMargin(
new Insets(0, 0, 0, 0));
330 if (compassIcon !=
null) {
331 final Container compass =
new JPanel();
332 compass.add(
new JLabel(compassIcon));
333 add(compass, BorderLayout.NORTH);
337 list.setFocusable(
false);
351 if (mapSquareListBottom) {
352 arrows.setLayout(
new GridLayout(4, 1));
353 add(
arrows, BorderLayout.WEST);
355 arrows.setLayout(
new FlowLayout());
356 add(
arrows, BorderLayout.SOUTH);
369 final int lastIndex =
model.getSize() - 1;
374 final RectangularShape bounds =
list.getCellBounds(lastIndex, lastIndex);
375 final int lowestY = (int) (bounds.getY() + bounds.getHeight());
376 if ((
int) e.getPoint().getY() >= lowestY) {
377 return lastIndex + 1;
380 final int listIndex =
list.locationToIndex(e.getPoint());
381 assert listIndex >= 0;
391 list.setEnabled(
false);
395 list.setEnabled(
true);
407 return actualIndex >=
model.getSize() ? null :
model.getElementAt(actualIndex);
417 if (
list.getSelectedIndex() != actualIndex) {
418 list.setSelectedIndex(actualIndex);
435 final int size =
model.getSize();
436 return index < size ? index : Math.max(0, size - 1);
445 if (mapCursor !=
null && index <
model.getSize()) {
457 if (gameObject !=
null) {
459 if (mapCursor !=
null) {
471 private static boolean isSelect(@NotNull
final InputEvent e) {
472 return (e.getModifiers() & InputEvent.BUTTON1_MASK) != 0;
480 private static boolean isInsert(@NotNull
final InputEvent e) {
481 return (e.getModifiers() & (InputEvent.BUTTON3_MASK | InputEvent.CTRL_MASK)) == InputEvent.BUTTON3_MASK;
489 private static boolean isDelete(@NotNull
final InputEvent e) {
490 return (e.getModifiers() & InputEvent.BUTTON2_MASK) != 0 || (e.getModifiers() & (InputEvent.BUTTON3_MASK | InputEvent.CTRL_MASK)) == (InputEvent.BUTTON3_MASK | InputEvent.CTRL_MASK);
494 if (this.mapModel !=
null) {
498 if (this.mapModel !=
null) {
502 if (this.mapCursor !=
null) {
506 if (this.mapCursor !=
null) {
A MapModel reflects the data of a map.
void refresh()
Re-displays the map square panel for SelectedSquareModel#getSelectedMapSquare().
MapSquare< G, A, R > getMapSquareOptional()
Returns the MapSquare this game object is part of.
final JList< G > list
The list of game objects.
void deleteGameObject(final int index)
Deletes a GameObject with a specific list index.
Base package of all Gridarta classes.
void updateArrows(final boolean mapSquareListBottom)
Updates the parameters of the arrows buttons.
void showAttributeDialog(@NotNull final G gameObject)
Shows the game object attributes dialog for a given GameObject instance.
G getGameObject()
Returns the selected GameObject.
boolean isAutojoin()
Returns whether "autojoin" is enabled.
final MapViewManagerListener< G, A, R > mapViewManagerListener
The map view manager listener.
Interface for listeners interested in events related to {} instances.
void insertGameObject(final int index)
Inserts a new game object.
final SelectedSquareModelListener< G, A, R > selectedSquareModelListener
The SelectedSquareModelListener attached to {}.
Provider for faces of GameObjects and Archetypes.
Reflects a game object (object on a map).
Container for settings that affect the rendering of maps.
final MapCursorListener< G, A, R > mapCursorListener
The MapCursorListener attached to mapCursor.
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
Interface for listeners listening to MapCursor related events.
G getListGameObject(final int index)
Returns a game object from the list.
void setGameObject(@Nullable final G gameObject)
Sets the selected GameObject.
boolean deleteSelectedGameObject(final boolean performAction, final boolean autoJoin)
Deletes the selected game object.
boolean isSelectedGameObjects(@NotNull final Iterable< G > gameObjects)
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.
Graphical User Interface of Gridarta.
final SelectedSquareModel< G, A, R > selectedSquareModel
The model for this view.
static boolean isSelect(@NotNull final InputEvent e)
Determines if "select" was selected.
void setSelectedIndex(final int index)
Sets the currently selected list index.
The panel that displays the game objects of the currently selected map square.
GameObjects are the objects based on Archetypes found on maps.
boolean setSelectedMapSquare(@Nullable final MapSquare< G, A, R > mapSquare, @Nullable final G gameObject)
Sets the currently selected map square.
Interface for MapArchObjects.
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.
int getListIndex(@NotNull final MouseEvent e)
Determines the list index for a given mouse event.
final GameObjectAttributesDialogFactory< G, A, R > gameObjectAttributesDialogFactory
The factory for creating game object attributes dialog instances.
An interface for classes that collect errors.
A map view consists of a map grid and a map cursor, and is attached to a map control.
BaseObject< G, A, R, ?> getSelection()
Returns the active arch in the left-side panel.
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)
Creates a new instance.
final ListSelectionListener listSelectionListener
The listener attached to list to be informed about selection changes.
This package contains the framework for validating maps.
MapCursor provides methods to move and drag on map.
MapCursor< G, A, R > mapCursor
The currently tracked MapCursor.
The location of a map file with a map directory.
Common base interface for ObjectChoosers.
final Container arrows
The arrow buttons.
A factory that creates dialogs for editing game object attributes.
int getValidIndex(final int index)
Determines a valid list index near a given index.
void addMapCursorListener(@NotNull final MapCursorListener< G, A, R > listener)
Register a MapCursorListener.
Interface for listeners listening on MapModel events.
void addSelectedSquareListener(@NotNull final SelectedSquareModelListener< G, A, R > listener)
Adds a SelectedSquareModelListener to be notified.
MapModel< G, A, R > mapModel
The currently active MapModel.
final MapViewSettings mapViewSettings
The MapViewSettings instance.
final DefaultListModel< G > model
The DefaultListModel of list.
CellRenderer for rendering ArchObjects on a certain map square in a list.
Base classes for rendering maps.
final MouseListener mouseListener
The MouseListener attached to the view to process mouse actions.
The face is the appearance of an object.
boolean isSelectedMapSquares(@NotNull final Iterable< MapSquare< G, A, R >> mapSquares)
final MapModelListener< G, A, R > mapModelListener
The MapModelListener attached to mapModel.
G getSelectedGameObject()
Returns the currently selected GameObject within this list (currently selected MapSquare).
static final long serialVersionUID
Serial Version UID.
The class Size2D represents a 2d rectangular area.
MapSquare< G, A, R > getSelectedMapSquare()
Returns the currently selected map square.
static boolean isDelete(@NotNull final InputEvent e)
Determines if "delete" was selected.
final ModelUpdater< G, A, R > modelUpdater
The ModelUpdater used for updating model.
final ObjectChooser< G, A, R > objectChooser
The object chooser.
static boolean isInsert(@NotNull final InputEvent e)
Determines if "insert" was selected.
void setMapCursor(@Nullable final MapModel< G, A, R > mapModel, @Nullable final MapCursor< G, A, R > mapCursor)