Gridarta Editor
ZoomAction.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 javax.swing.Action;
33 import net.sf.japi.swing.action.ActionMethod;
34 import org.jetbrains.annotations.NotNull;
35 import org.jetbrains.annotations.Nullable;
36 
41 public class ZoomAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction {
42 
46  @NotNull
48 
52  @NotNull
53  @SuppressWarnings("FieldCanBeLocal")
54  private final MapManagerListener<G, A, R> mapManagerListener = new MapManagerListener<G, A, R>() {
55 
56  @Override
57  public void currentMapChanged(@Nullable final MapControl<G, A, R> mapControl) {
58  mapModel = mapControl == null ? null : mapControl.getMapModel();
59  updateAction();
60  }
61 
62  @Override
63  public void mapCreated(@NotNull final MapControl<G, A, R> mapControl, final boolean interactive) {
64  }
65 
66  @Override
67  public void mapClosing(@NotNull final MapControl<G, A, R> mapControl) {
68  }
69 
70  @Override
71  public void mapClosed(@NotNull final MapControl<G, A, R> mapControl) {
72  }
73 
74  };
75 
79  @Nullable
80  private Action action;
81 
85  @Nullable
87 
93  public ZoomAction(@NotNull final MapManager<G, A, R> mapManager, @NotNull final RendererFactory<G, A, R> rendererFactory) {
94  this.rendererFactory = rendererFactory;
95  mapManager.addMapManagerListener(mapManagerListener);
96  }
97 
102  @ActionMethod
103  public void zoom() {
104  doAction(true);
105  }
106 
107  @Override
108  public void setAction(@NotNull final Action action, @NotNull final String name) {
109  this.action = action;
110  updateAction();
111  }
112 
116  private void updateAction() {
117  if (action != null) {
118  action.setEnabled(doAction(false));
119  }
120  }
121 
127  private boolean doAction(final boolean performAction) {
128  if (mapModel == null) {
129  return false;
130  }
131 
132  if (performAction) {
134  }
135 
136  return true;
137  }
138 
139 }
name
name
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:2
net.sf.gridarta.model.mapmanager
Definition: AbstractMapManager.java:20
net.sf.gridarta.action.ZoomAction.action
Action action
The Action for this instance.
Definition: ZoomAction.java:80
net.sf.gridarta.model.mapmodel.MapModel
A MapModel reflects the data of a map.
Definition: MapModel.java:75
net.sf.gridarta.action.ZoomAction
Shows an image of the current map and allows the user to save it.
Definition: ZoomAction.java:41
net.sf.gridarta.model.mapmanager.MapManager
A MapManager manages all opened maps.
Definition: MapManager.java:37
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.gui.misc
Definition: About.java:20
net.sf
net.sf.gridarta.model.mapmanager.MapManagerListener
Interface for listeners listening to MapManager changes.
Definition: MapManagerListener.java:42
net.sf.gridarta.gui.map.renderer.RendererFactory.newSimpleMapRenderer
MapRenderer newSimpleMapRenderer(@NotNull MapModel< G, A, R > mapModel)
Creates a new map renderer instance which paints only squares but no grid, cursor,...
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.action.ZoomAction.updateAction
void updateAction()
Updates the enabled state of action.
Definition: ZoomAction.java:116
net.sf.gridarta.gui.misc.MapPreview
The map preview of the level editor.
Definition: MapPreview.java:51
net.sf.gridarta.gui.map.renderer
Definition: AbstractIsoMapRenderer.java:20
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.mapcontrol
Definition: DefaultMapControl.java:20
net.sf.gridarta.action.ZoomAction.mapModel
MapModel< G, A, R > mapModel
The currently active MapModel.
Definition: ZoomAction.java:86
net.sf.gridarta.gui
Graphical User Interface of Gridarta.
net.sf.gridarta.action.ZoomAction.doAction
boolean doAction(final boolean performAction)
Executes the action.
Definition: ZoomAction.java:127
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.action.ZoomAction.mapManagerListener
final MapManagerListener< G, A, R > mapManagerListener
The map manager listener.
Definition: ZoomAction.java:54
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.action.ZoomAction.zoom
void zoom()
The action method for "zoom".
Definition: ZoomAction.java:103
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.gui.map.renderer.RendererFactory
Factory for creating MapRenderer instances.
Definition: RendererFactory.java:33
net.sf.gridarta.gui.map
Base classes for rendering maps.
Definition: AbstractPerMapDialogManager.java:20
net.sf.gridarta.action.ZoomAction.rendererFactory
final RendererFactory< G, A, R > rendererFactory
The ReloadFacesAction for creating map images.
Definition: ZoomAction.java:47
net.sf.gridarta.model.mapcontrol.MapControl
Currently nothing more than a marker interface for unification.
Definition: MapControl.java:35
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.action.ZoomAction.ZoomAction
ZoomAction(@NotNull final MapManager< G, A, R > mapManager, @NotNull final RendererFactory< G, A, R > rendererFactory)
Creates a new instance.
Definition: ZoomAction.java:93
net.sf.gridarta.gui.map.renderer.MapRenderer.getFullImage
BufferedImage getFullImage()
Returns an image of the entire map view.
net.sf.gridarta.utils.EditorAction
A global editor action.
Definition: EditorAction.java:29
net.sf.gridarta.action.ZoomAction.setAction
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
Definition: ZoomAction.java:108
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20