Gridarta Editor
GoLocationAction.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 javax.swing.Action;
32 import net.sf.japi.swing.action.ActionMethod;
33 import org.jetbrains.annotations.NotNull;
34 import org.jetbrains.annotations.Nullable;
35 
40 public class GoLocationAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractMapCursorAction<G, A, R> implements EditorAction {
41 
46  @NotNull
48 
53  @Nullable
54  private Action action;
55 
60  public GoLocationAction(@NotNull final MapViewManager<G, A, R> mapViewManager) {
61  goLocationDialogManager = new GoLocationDialogManager<>(mapViewManager);
62  }
63 
64  @Override
65  public void setAction(@NotNull final Action action, @NotNull final String name) {
66  this.action = action;
67  }
68 
72  @ActionMethod
73  public void goLocation() {
74  doGoLocation(true);
75  }
76 
77  @Override
78  protected void updateAction() {
79  if (action != null) {
80  //noinspection ConstantConditions
81  action.setEnabled(doGoLocation(false));
82  }
83  }
84 
90  private boolean doGoLocation(final boolean performAction) {
91  final MapView<G, A, R> mapView = getActiveMapView();
92  if (mapView == null) {
93  return false;
94  }
95 
96  if (performAction) {
97  goLocationDialogManager.showDialog(mapView);
98  }
99 
100  return true;
101  }
102 
103 }
Graphical User Interface of Gridarta.
boolean doGoLocation(final boolean performAction)
Executes the "go location" action.
GoLocationAction(@NotNull final MapViewManager< G, A, R > mapViewManager)
Creates a new instance.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
A global editor action.
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
GameObjects are the objects based on Archetypes found on maps.
Maintains (dialog) instance associated to map view instances.
An EditorAction that openes the "go location" dialog.
final AbstractPerMapDialogManager< G, A, R, GoLocationDialog< G, A, R > > goLocationDialogManager
The AbstractPerMapDialogManager to track go location dialog instances.
Base classes for rendering maps.
void goLocation()
Opens the "go location" dialog.
A map view consists of a map grid and a map cursor, and is attached to a map control.
Definition: MapView.java:43
A dialog to ask the user for coordinates to move the cursor to.
Action action
The Action associated with this editor action.
Abstract base class for actions that have to track the current map cursor.
MapView< G, A, R > getActiveMapView()
Return the current map view.
void showDialog(final MapView< G, A, R > mapView)
Show a dialog for positioning the cursor of a map.