Gridarta Editor
ViewActions.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.map.viewaction;
21 
22 import java.awt.Container;
23 import java.util.Arrays;
24 import java.util.Comparator;
25 import java.util.LinkedList;
26 import java.util.List;
27 import javax.swing.Action;
38 import net.sf.japi.swing.action.ActionMethod;
39 import org.jetbrains.annotations.NotNull;
40 import org.jetbrains.annotations.Nullable;
41 
46 public class ViewActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction {
47 
51  @NotNull
53 
57  @NotNull
58  private final List<ViewAction> viewActions = new LinkedList<>();
59 
64  @NotNull
66 
67  @Override
68  public void currentMapChanged(@Nullable final MapControl<G, A, R> mapControl) {
69  updateActions();
70  }
71 
72  @Override
73  public void mapCreated(@NotNull final MapControl<G, A, R> mapControl, final boolean interactive) {
74  // ignore
75  }
76 
77  @Override
78  public void mapClosing(@NotNull final MapControl<G, A, R> mapControl) {
79  // ignore
80  }
81 
82  @Override
83  public void mapClosed(@NotNull final MapControl<G, A, R> mapControl) {
84  // ignore
85  }
86 
87  };
88 
93  @NotNull
95 
96  @Override
97  public void gridVisibleChanged(final boolean gridVisible) {
98  // ignore
99  }
100 
101  @Override
102  public void lightVisibleChanged(final boolean lightVisible) {
103  // ignore
104  }
105 
106  @Override
107  public void smoothingChanged(final boolean smoothing) {
108  // ignore
109  }
110 
111  @Override
112  public void tileStretchingChanged(final boolean tileStretching) {
113  // ignore
114  }
115 
116  @Override
117  public void doubleFacesChanged(final boolean doubleFaces) {
118  // ignore
119  }
120 
121  @Override
122  public void alphaTypeChanged(final int alphaType) {
123  // ignore
124  }
125 
126  @Override
127  public void editTypeChanged(final int editType) {
128  updateActions();
129  }
130 
131  @Override
132  public void autojoinChanged(final boolean autojoin) {
133  // ignore
134  }
135 
136  };
137 
143  public ViewActions(@NotNull final MapViewSettings mapViewSettings, @NotNull final MapManager<G, A, R> mapManager) {
144  this.mapViewSettings = mapViewSettings;
145  mapManager.addMapManagerListener(mapManagerListener);
147  }
148 
152  @NotNull
153  private static final Comparator<ViewAction> ACTION_NAME_COMPARATOR = (o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName());
154 
159  public void init(@NotNull final Iterable<NamedGameObjectMatcher> gameObjectMatchers) {
160  for (final NamedGameObjectMatcher matcher : gameObjectMatchers) {
161  viewActions.add(new ViewAction(mapViewSettings, matcher));
162  }
163  }
164 
169  public void setMenu(@Nullable final Container viewActionsMenu) {
170  if (viewActionsMenu == null) {
171  return;
172  }
173 
174  final ViewAction[] actions = viewActions.toArray(new ViewAction[0]);
175  Arrays.sort(actions, ACTION_NAME_COMPARATOR);
176  int index = 0;
177  for (final ViewAction viewAction : actions) {
178  viewActionsMenu.add(viewAction.getCheckBoxMenuItem(), index++);
179  }
180  }
181 
185  @ActionMethod
186  public void resetView() {
187  // set edit type to zero (-> show all)
189  }
190 
194  private void updateActions() {
195  for (final ViewAction viewAction : viewActions) {
196  viewAction.updateAction();
197  }
198  }
199 
200  @Override
201  public void setAction(@NotNull final Action action, @NotNull final String name) {
202  }
203 
204 }
net.sf.gridarta.gui.map.viewaction.ViewActions.mapManagerListener
final MapManagerListener< G, A, R > mapManagerListener
The map manager listener which is attached to the current map if the current map is tracked.
Definition: ViewActions.java:65
net.sf.gridarta.gui.map.viewaction.ViewAction
Action to manage one edit type represented by one {}.
Definition: ViewAction.java:38
name
name
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:2
net.sf.gridarta.model.mapmanager
Definition: AbstractMapManager.java:20
net.sf.gridarta.gui.map.viewaction.ViewActions.init
void init(@NotNull final Iterable< NamedGameObjectMatcher > gameObjectMatchers)
Creates the view actions.
Definition: ViewActions.java:159
net.sf.gridarta.model.mapmanager.MapManager
A MapManager manages all opened maps.
Definition: MapManager.java:37
net.sf.gridarta.gui.map.viewaction.ViewActions.ViewActions
ViewActions(@NotNull final MapViewSettings mapViewSettings, @NotNull final MapManager< G, A, R > mapManager)
Creates a new instance.
Definition: ViewActions.java:143
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.gui.map.viewaction.ViewActions.mapViewSettings
final MapViewSettings mapViewSettings
The map view settings instance.
Definition: ViewActions.java:52
net.sf.gridarta.model.mapviewsettings
Definition: AbstractMapViewSettings.java:20
net.sf.gridarta.model.mapviewsettings.MapViewSettings.addMapViewSettingsListener
void addMapViewSettingsListener(@NotNull MapViewSettingsListener listener)
Register a MapViewSettingsListener.
net.sf.gridarta.gui.map.viewaction.ViewActions.setMenu
void setMenu(@Nullable final Container viewActionsMenu)
Sets the menu to add the actions to.
Definition: ViewActions.java:169
net.sf
net.sf.gridarta.model.mapmanager.MapManagerListener
Interface for listeners listening to MapManager changes.
Definition: MapManagerListener.java:42
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.mapviewsettings.MapViewSettings
Container for settings that affect the rendering of maps.
Definition: MapViewSettings.java:30
net.sf.gridarta.model.mapcontrol
Definition: DefaultMapControl.java:20
net.sf.gridarta.gui.map.viewaction.ViewActions.viewActions
final List< ViewAction > viewActions
The view actions.
Definition: ViewActions.java:58
net.sf.gridarta.gui.map.viewaction.ViewActions.mapViewSettingsListener
final MapViewSettingsListener mapViewSettingsListener
The MapViewSettingsListener attached to mapViewSettings to detect edit types changes.
Definition: ViewActions.java:94
net.sf.gridarta.model.match.NamedGameObjectMatcher
Decorates an arbitrary GameObjectMatcher with a localized name that is suitable for the user interfac...
Definition: NamedGameObjectMatcher.java:33
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.gui.map.viewaction.ViewActions.resetView
void resetView()
Action method for "reset view".
Definition: ViewActions.java:186
net.sf.gridarta.model.match
Classes related to matching {GameObjects}, so called { net.sf.gridarta.model.match....
Definition: AndGameObjectMatcher.java:20
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.gui.map.viewaction.ViewActions.updateActions
void updateActions()
Updates the actions' state to the current edit mode.
Definition: ViewActions.java:194
net.sf.gridarta.gui.map.viewaction.ViewActions.ACTION_NAME_COMPARATOR
static final Comparator< ViewAction > ACTION_NAME_COMPARATOR
The comparator for sorting menu entries.
Definition: ViewActions.java:153
net.sf.gridarta.model.mapviewsettings.MapViewSettings.unsetEditType
void unsetEditType(int editType)
Set the map view to hide squares of the given type.
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.model.mapviewsettings.MapViewSettingsListener
Interface for event listeners that are interested in changes on {}.
Definition: MapViewSettingsListener.java:31
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.utils.EditorAction
A global editor action.
Definition: EditorAction.java:29
net.sf.gridarta.gui.map.viewaction.ViewActions.setAction
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
Definition: ViewActions.java:201
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20
net.sf.gridarta.gui.map.viewaction.ViewActions
Manages edit type actions in "view" menu.
Definition: ViewActions.java:46