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-2015 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 
69  public ArchAttributesAction(@NotNull final GameObjectAttributesDialogFactory<G, A, R> gameObjectAttributesDialogFactory) {
70  this.gameObjectAttributesDialogFactory = gameObjectAttributesDialogFactory;
71  updateActions();
72  }
73 
77  @ActionMethod
78  public void archAttributes() {
79  doArchAttributes(true);
80  }
81 
82  @Override
83  public void setAction(@NotNull final Action action, @NotNull final String name) {
84  this.action = action;
85  }
86 
90  private void updateActions() {
91  if (action != null) {
92  //noinspection ConstantConditions
93  action.setEnabled(doArchAttributes(false));
94  }
95  }
96 
102  private boolean doArchAttributes(final boolean performAction) {
103  if (currentMapView == null) {
104  return false;
105  }
106 
107  final MapCursor<G, A, R> mapCursor = currentMapView.getMapCursor();
108  final G gameObject = mapCursor.getGameObject();
109  if (gameObject == null) {
110  return false;
111  }
112 
113  if (performAction) {
114  gameObjectAttributesDialogFactory.showAttributeDialog(gameObject);
115  }
116 
117  return true;
118  }
119 
120  @Override
121  public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
122  currentMapView = mapView;
123  updateActions();
124  }
125 
126  @Override
127  public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
128  // ignore
129  }
130 
131  @Override
132  public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
133  // ignore
134  }
135 
136  @Override
137  public void mapCursorChangedPos(@NotNull final Point location) {
138  updateActions();
139  }
140 
141  @Override
142  public void mapCursorChangedMode() {
143  // ignore
144  }
145 
146  @Override
147  public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) {
148  // ignore
149  }
150 
151  @Override
152  public void mapCursorChangedSize() {
153  // ignore
154  }
155 
156 }
void mapCursorChangedGameObject(@Nullable final MapSquare< G, A, R > mapSquare, @Nullable final G gameObject)
Called whenever the selected game object has changed.
Graphical User Interface of Gridarta.
void mapViewCreated(@NotNull final MapView< G, A, R > mapView)
This event handler is called when a map view was created.
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
void mapCursorChangedMode()
This event handler is called when MapCursor changes mode (drag, select).
void activeMapViewChanged(@Nullable final MapView< G, A, R > mapView)
This event handler is called when the current map view has changed.
void mapViewClosing(@NotNull final MapView< G, A, R > mapView)
This event handler is called when a map view is to be closed.
G getGameObject()
Returns the selected GameObject.
Definition: MapCursor.java:437
MapCursor provides methods to move and drag on map.
Definition: MapCursor.java:57
ArchAttributesAction(@NotNull final GameObjectAttributesDialogFactory< G, A, R > gameObjectAttributesDialogFactory)
Creates a new instance.
final GameObjectAttributesDialogFactory< G, A, R > gameObjectAttributesDialogFactory
The factory for creating game object attributes dialog instances.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
void mapCursorChangedSize()
Called whenever the map cursor&#39;s map grid size has changed.
A global editor action.
An EditorAction that opens the game object attributes dialog for the currently selected game object...
GameObjects are the objects based on Archetypes found on maps.
Interface for listeners interested in events related to MapViewManager instances. ...
void mapCursorChangedPos(@NotNull final Point location)
This event handler is called when MapCursor has moved.
boolean doArchAttributes(final boolean performAction)
Executes the "arch attributes" action.
MapView< G, A, R > currentMapView
The active map view, or.
Base classes for rendering maps.
void updateActions()
Updates the enabled state of action.
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.
Definition: MapView.java:43
void archAttributes()
Action method for "arch attributes".
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.