Gridarta Editor
ArchAttributesAction.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.action;
21 
22 import java.awt.Point;
23 import javax.swing.Action;
34 import net.sf.japi.swing.action.ActionMethod;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
37 
43 public class ArchAttributesAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapCursorListener<G, A, R>, MapViewManagerListener<G, A, R> {
44 
48  @NotNull
50 
54  @Nullable
56 
61  @Nullable
62  private Action action;
63 
70  this.gameObjectAttributesDialogFactory = gameObjectAttributesDialogFactory;
71  }
72 
76  @ActionMethod
77  public void archAttributes() {
78  doArchAttributes(true);
79  }
80 
81  @Override
82  public void setAction(@NotNull final Action action, @NotNull final String name) {
83  this.action = action;
84  updateActions();
85  }
86 
90  private void updateActions() {
91  if (action != null) {
92  action.setEnabled(doArchAttributes(false));
93  }
94  }
95 
101  private boolean doArchAttributes(final boolean performAction) {
102  if (currentMapView == null) {
103  return false;
104  }
105 
106  final MapCursor<G, A, R> mapCursor = currentMapView.getMapCursor();
107  final G gameObject = mapCursor.getGameObject();
108  if (gameObject == null) {
109  return false;
110  }
111 
112  if (performAction) {
114  }
115 
116  return true;
117  }
118 
119  @Override
120  public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
121  currentMapView = mapView;
122  updateActions();
123  }
124 
125  @Override
126  public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
127  // ignore
128  }
129 
130  @Override
131  public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
132  // ignore
133  }
134 
135  @Override
136  public void mapCursorChangedPos(@NotNull final Point location) {
137  updateActions();
138  }
139 
140  @Override
141  public void mapCursorChangedMode() {
142  // ignore
143  }
144 
145  @Override
146  public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) {
147  // ignore
148  }
149 
150  @Override
151  public void mapCursorChangedSize() {
152  // ignore
153  }
154 
155 }
name
name
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:2
net.sf.gridarta.action.ArchAttributesAction.mapCursorChangedMode
void mapCursorChangedMode()
This event handler is called when MapCursor changes mode (drag, select).
Definition: ArchAttributesAction.java:141
net.sf.gridarta.action.ArchAttributesAction.gameObjectAttributesDialogFactory
final GameObjectAttributesDialogFactory< G, A, R > gameObjectAttributesDialogFactory
The factory for creating game object attributes dialog instances.
Definition: ArchAttributesAction.java:49
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.mapmodel.MapSquare
A single Map Square.
Definition: MapSquare.java:45
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.showAttributeDialog
void showAttributeDialog(@NotNull final G gameObject)
Shows the game object attributes dialog for a given GameObject instance.
Definition: GameObjectAttributesDialogFactory.java:217
net.sf.gridarta.action.ArchAttributesAction
An EditorAction that opens the game object attributes dialog for the currently selected game object.
Definition: ArchAttributesAction.java:43
net.sf
net.sf.gridarta.model.mapcursor.MapCursor.getGameObject
G getGameObject()
Returns the selected GameObject.
Definition: MapCursor.java:437
net.sf.gridarta.action.ArchAttributesAction.mapCursorChangedPos
void mapCursorChangedPos(@NotNull final Point location)
This event handler is called when MapCursor has moved.
Definition: ArchAttributesAction.java:136
net.sf.gridarta.action.ArchAttributesAction.mapCursorChangedGameObject
void mapCursorChangedGameObject(@Nullable final MapSquare< G, A, R > mapSquare, @Nullable final G gameObject)
Called whenever the selected game object has changed.
Definition: ArchAttributesAction.java:146
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.action.ArchAttributesAction.doArchAttributes
boolean doArchAttributes(final boolean performAction)
Executes the "arch attributes" action.
Definition: ArchAttributesAction.java:101
net.sf.gridarta.gui.map.mapview.MapViewManagerListener
Interface for listeners interested in events related to {} instances.
Definition: MapViewManagerListener.java:33
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.gameobject.GameObject
Reflects a game object (object on a map).
Definition: GameObject.java:36
net.sf.gridarta.model.mapcursor.MapCursorListener
Interface for listeners listening to MapCursor related events.
Definition: MapCursorListener.java:36
net.sf.gridarta.gui
Graphical User Interface of Gridarta.
net.sf.gridarta.action.ArchAttributesAction.setAction
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
Definition: ArchAttributesAction.java:82
net.sf.gridarta.gui.map.mapview.MapView.getMapCursor
MapCursor< G, A, R > getMapCursor()
Returns the MapCursor of this view.
net.sf.gridarta.action.ArchAttributesAction.mapViewCreated
void mapViewCreated(@NotNull final MapView< G, A, R > mapView)
This event handler is called when a map view was created.
Definition: ArchAttributesAction.java:126
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.action.ArchAttributesAction.archAttributes
void archAttributes()
Action method for "arch attributes".
Definition: ArchAttributesAction.java:77
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.gui.map.mapview
Definition: AbstractMapView.java:20
net.sf.gridarta.action.ArchAttributesAction.ArchAttributesAction
ArchAttributesAction(@NotNull final GameObjectAttributesDialogFactory< G, A, R > gameObjectAttributesDialogFactory)
Creates a new instance.
Definition: ArchAttributesAction.java:69
net.sf.gridarta.gui.map.mapview.MapView
A map view consists of a map grid and a map cursor, and is attached to a map control.
Definition: MapView.java:43
net.sf.gridarta.model.mapcursor.MapCursor
MapCursor provides methods to move and drag on map.
Definition: MapCursor.java:58
net.sf.gridarta.action.ArchAttributesAction.currentMapView
MapView< G, A, R > currentMapView
The active map view, or.
Definition: ArchAttributesAction.java:55
net.sf.gridarta.gui.dialog.gameobjectattributes
Definition: ArchetypeTypeListCellRenderer.java:20
net.sf.gridarta.gui.dialog
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory
A factory that creates dialogs for editing game object attributes.
Definition: GameObjectAttributesDialogFactory.java:54
net.sf.gridarta.action.ArchAttributesAction.activeMapViewChanged
void activeMapViewChanged(@Nullable final MapView< G, A, R > mapView)
This event handler is called when the current map view has changed.
Definition: ArchAttributesAction.java:120
net.sf.gridarta.action.ArchAttributesAction.mapViewClosing
void mapViewClosing(@NotNull final MapView< G, A, R > mapView)
This event handler is called when a map view is to be closed.
Definition: ArchAttributesAction.java:131
net.sf.gridarta.action.ArchAttributesAction.updateActions
void updateActions()
Updates the enabled state of action.
Definition: ArchAttributesAction.java:90
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.gui.map
Base classes for rendering maps.
Definition: AbstractPerMapDialogManager.java:20
net.sf.gridarta.action.ArchAttributesAction.action
Action action
The associated Action.
Definition: ArchAttributesAction.java:62
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.utils.EditorAction
A global editor action.
Definition: EditorAction.java:29
net.sf.gridarta.model.mapcursor
Definition: MapCursor.java:20
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20
net.sf.gridarta.action.ArchAttributesAction.mapCursorChangedSize
void mapCursorChangedSize()
Called whenever the map cursor's map grid size has changed.
Definition: ArchAttributesAction.java:151