Gridarta Editor
WindowAction.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.gui.mapdesktop;
21 
22 import java.awt.event.ActionEvent;
23 import java.util.Set;
24 import javax.swing.AbstractAction;
25 import javax.swing.KeyStroke;
37 import net.sf.gridarta.utils.Size2D;
38 import org.jetbrains.annotations.NotNull;
39 import org.jetbrains.annotations.Nullable;
40 
45 public class WindowAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractAction {
46 
50  private static final long serialVersionUID = 1L;
51 
55  @NotNull
57 
61  @NotNull
62  private final MapView<G, A, R> mapView;
63 
67  @NotNull
69 
73  private int index = -1;
74 
79 
80  @Override
81  public void currentMapChanged(@Nullable final MapControl<G, A, R> mapControl) {
82  // ignore
83  }
84 
85  @Override
86  public void mapCreated(@NotNull final MapControl<G, A, R> mapControl, final boolean interactive) {
87  // ignore
88  }
89 
90  @Override
91  public void mapClosing(@NotNull final MapControl<G, A, R> mapControl) {
92  // ignore
93  }
94 
95  @Override
96  public void mapClosed(@NotNull final MapControl<G, A, R> mapControl) {
97  if (mapControl == mapView.getMapControl()) {
100  }
101  }
102 
103  };
104 
109 
110  @Override
111  public void mapSizeChanged(@NotNull final Size2D newSize) {
112  // ignore
113  }
114 
115  @Override
116  public void mapSquaresChanged(@NotNull final Set<MapSquare<G, A, R>> mapSquares) {
117  // ignore
118  }
119 
120  @Override
121  public void mapObjectsChanged(@NotNull final Set<G> gameObjects, @NotNull final Set<G> transientGameObjects) {
122  // ignore
123  }
124 
125  @Override
126  public void errorsChanged(@NotNull final ErrorCollector<G, A, R> errors) {
127  // ignore
128  }
129 
130  @Override
131  public void mapFileChanged(@Nullable final MapFile oldMapFile) {
132  // ignore
133  }
134 
135  @Override
136  public void modifiedChanged() {
137  updateName();
138  }
139 
140  };
141 
148  public WindowAction(@NotNull final MapDesktop<G, A, R> mapDesktop, @NotNull final MapView<G, A, R> mapView, @NotNull final MapManager<G, A, R> mapManager) {
149  this.mapDesktop = mapDesktop;
150  this.mapView = mapView;
151  this.mapManager = mapManager;
152  putValue(SHORT_DESCRIPTION, "Switches to map " + mapView.getInternalFrame().getTitle());
155  setIndex(-1);
156  }
157 
163  public final void setIndex(final int index) {
164  this.index = index;
165  if (0 <= index && index <= 10) {
166  putValue(MNEMONIC_KEY, KeyStroke.getKeyStroke(Integer.toString(index % 10)).getKeyCode());
167  putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl pressed " + index % 10));
168  } else {
169  putValue(MNEMONIC_KEY, null);
170  putValue(ACCELERATOR_KEY, null);
171  }
172  updateName();
173  }
174 
178  private void updateName() {
179  final String windowTitle = mapView.getWindowTitle();
180  putValue(NAME, 0 <= index && index <= 10 ? index + ": " + windowTitle : windowTitle);
181  }
182 
183  @Override
184  public void actionPerformed(@NotNull final ActionEvent e) {
186  }
187 
188  @NotNull
189  @Override
191  try {
192  //noinspection unchecked
193  return (WindowAction<G, A, R>) super.clone();
194  } catch (final CloneNotSupportedException ex) {
195  throw new AssertionError(ex);
196  }
197  }
198 
199 }
net.sf.gridarta.model.mapmanager
Definition: AbstractMapManager.java:20
net.sf.gridarta.gui.mapdesktop.WindowAction.WindowAction
WindowAction(@NotNull final MapDesktop< G, A, R > mapDesktop, @NotNull final MapView< G, A, R > mapView, @NotNull final MapManager< G, A, R > mapManager)
Creates a new instance.
Definition: WindowAction.java:148
net.sf.gridarta.model.mapmanager.MapManager
A MapManager manages all opened maps.
Definition: MapManager.java:37
net.sf.gridarta.model.mapmanager.MapManager.removeMapManagerListener
void removeMapManagerListener(@NotNull MapManagerListener< G, A, R > listener)
Removes a MapManagerListener to be notified.
net.sf.gridarta.gui.map.mapview.MapView.getMapControl
MapControl< G, A, R > getMapControl()
Return the controller of this view.
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.mapdesktop.WindowAction.actionPerformed
void actionPerformed(@NotNull final ActionEvent e)
Definition: WindowAction.java:184
net.sf.gridarta.gui.mapdesktop.WindowAction.index
int index
The index of this action.
Definition: WindowAction.java:73
net.sf
net.sf.gridarta.model.mapmanager.MapManagerListener
Interface for listeners listening to MapManager changes.
Definition: MapManagerListener.java:42
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.model.mapmanager.MapManager.addMapManagerListener
void addMapManagerListener(@NotNull MapManagerListener< G, A, R > listener)
Adds a MapManagerListener to be notified.
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.gui.mapdesktop.WindowAction.mapManagerListener
final MapManagerListener< G, A, R > mapManagerListener
The MapManagerListener to detect closed maps.
Definition: WindowAction.java:78
net.sf.gridarta.gui.mapdesktop.WindowAction.setIndex
final void setIndex(final int index)
Sets the index of this action so this Action knows what Mnemonic and Accelerator to use.
Definition: WindowAction.java:163
net.sf.gridarta.model.mapcontrol
Definition: DefaultMapControl.java:20
net.sf.gridarta.model.mapmodel.MapModel.addMapModelListener
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
net.sf.gridarta.gui.mapdesktop.WindowAction
Action class for selecting this window.
Definition: WindowAction.java:45
net.sf.gridarta.gui.mapdesktop.WindowAction.updateName
void updateName()
Updates the action's name to the current map state.
Definition: WindowAction.java:178
net.sf.gridarta.gui.mapdesktop.MapDesktop.setCurrentMapView
void setCurrentMapView(@NotNull final MapView< G, A, R > mapView)
Sets the given level view as the current one.
Definition: MapDesktop.java:234
net.sf.gridarta.gui
Graphical User Interface of Gridarta.
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.gui.mapdesktop.WindowAction.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: WindowAction.java:50
net.sf.gridarta.gui.map.mapview.MapView.getWindowTitle
String getWindowTitle()
Returns the title for the map window.
net.sf.gridarta.gui.mapdesktop.WindowAction.mapView
final MapView< G, A, R > mapView
The associated map view.
Definition: WindowAction.java:62
errors
errors
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:1
net.sf.gridarta.model.mapmodel.MapModel.removeMapModelListener
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
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.model.validation.ErrorCollector
An interface for classes that collect errors.
Definition: ErrorCollector.java:33
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.validation
This package contains the framework for validating maps.
Definition: AbstractValidator.java:20
net.sf.gridarta.gui.mapdesktop.WindowAction.mapManager
final MapManager< G, A, R > mapManager
The MapManager to use.
Definition: WindowAction.java:68
net.sf.gridarta.model.mapmodel.MapFile
The location of a map file with a map directory.
Definition: MapFile.java:31
net.sf.gridarta.gui.mapdesktop.WindowAction.mapDesktop
final MapDesktop< G, A, R > mapDesktop
The map desktop.
Definition: WindowAction.java:56
net.sf.gridarta.model.mapmodel.MapModelListener
Interface for listeners listening on MapModel events.
Definition: MapModelListener.java:36
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.gui.map.mapview.MapView.getInternalFrame
JInternalFrame getInternalFrame()
Returns the JInternalFrame instance for this map view.
net.sf.gridarta.gui.mapdesktop.MapDesktop< G, A, R >
net.sf.gridarta.gui.map
Base classes for rendering maps.
Definition: AbstractPerMapDialogManager.java:20
net.sf.gridarta.model.mapcontrol.MapControl
Currently nothing more than a marker interface for unification.
Definition: MapControl.java:35
net.sf.gridarta.model.mapcontrol.MapControl.getMapModel
MapModel< G, A, R > getMapModel()
Returns the map model.
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.gui.mapdesktop.WindowAction.clone
WindowAction< G, A, R > clone()
Definition: WindowAction.java:190
net.sf.gridarta.utils.Size2D
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30
net.sf.gridarta.gui.mapdesktop.WindowAction.mapModelListener
final MapModelListener< G, A, R > mapModelListener
The MapModelListener to detect modified maps.
Definition: WindowAction.java:108
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20