Gridarta Editor
ViewGameObjectMatcherManager.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.model.match;
21 
22 import java.awt.event.ActionEvent;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
26 import javax.swing.AbstractAction;
27 import javax.swing.Action;
28 import org.jetbrains.annotations.NotNull;
29 
35 
40  @NotNull
42 
46  @NotNull
47  private final List<GameObjectMatcherToggleAction> actions = new ArrayList<>();
48 
52  @NotNull
53  private final Action resetAction = new ResetAction(Collections.unmodifiableList(actions));
54 
61  this.mutableOrGameObjectMatcher = mutableOrGameObjectMatcher;
62  }
63 
69  @NotNull
70  public Action addArchObjectMatcher(@NotNull final GameObjectMatcher gameObjectMatcher) {
72  actions.add(action);
73  return action;
74  }
75 
80  @NotNull
81  public List<? extends Action> getAllActions() {
82  return Collections.unmodifiableList(actions);
83  }
84 
89  @NotNull
90  public Action getResetAction() {
91  return resetAction;
92  }
93 
97  private static class ResetAction extends AbstractAction {
98 
102  private static final long serialVersionUID = 1L;
103 
107  @NotNull
108  private final Iterable<? extends GameObjectMatcherToggleAction> actions;
109 
114  ResetAction(@NotNull final Iterable<? extends GameObjectMatcherToggleAction> actions) {
115  this.actions = actions;
116  }
117 
118  @Override
119  public void actionPerformed(@NotNull final ActionEvent e) {
120  for (final GameObjectMatcherToggleAction action : actions) {
121  action.setSelected(false);
122  }
123  }
124 
125  @NotNull
126  @Override
127  protected ResetAction clone() {
128  try {
129  return (ResetAction) super.clone();
130  } catch (final CloneNotSupportedException ex) {
131  throw new AssertionError(ex);
132  }
133  }
134 
135  }
136 
141  private static class GameObjectMatcherToggleAction extends AbstractAction {
142 
146  private static final long serialVersionUID = 1L;
147 
151  private boolean selected;
152 
157  @NotNull
159 
163  @NotNull
165 
174  this.gameObjectMatcher = gameObjectMatcher;
175  this.mutableOrArchObjectMatcher = mutableOrArchObjectMatcher;
176  }
177 
178  @Override
179  public void actionPerformed(@NotNull final ActionEvent e) {
180  if (!isEnabled()) {
181  return;
182  }
184  }
185 
190  protected void setSelected(final boolean selected) {
191  this.selected = selected;
192  if (selected) {
194  } else {
196  }
197  }
198 
205  public boolean isSelected() {
206  return selected;
207  }
208 
209  @NotNull
210  @Override
212  try {
213  return (GameObjectMatcherToggleAction) super.clone();
214  } catch (final CloneNotSupportedException ex) {
215  throw new AssertionError(ex);
216  }
217  }
218 
219  }
220 
221 }
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.ResetAction.actions
final Iterable<? extends GameObjectMatcherToggleAction > actions
The actions to reset.
Definition: ViewGameObjectMatcherManager.java:108
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.ResetAction.actionPerformed
void actionPerformed(@NotNull final ActionEvent e)
Definition: ViewGameObjectMatcherManager.java:119
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.getResetAction
Action getResetAction()
Gets the reset action.
Definition: ViewGameObjectMatcherManager.java:90
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.ResetAction
The reset action.
Definition: ViewGameObjectMatcherManager.java:97
net.sf.gridarta.model.match.GameObjectMatcher
Interface for classes that match GameObjects.
Definition: GameObjectMatcher.java:30
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.mutableOrGameObjectMatcher
final MutableOrGameObjectMatcher mutableOrGameObjectMatcher
The MutableOrGameObjectMatcher that is manipulated by the actions.
Definition: ViewGameObjectMatcherManager.java:41
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.GameObjectMatcherToggleAction.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: ViewGameObjectMatcherManager.java:146
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.ResetAction.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: ViewGameObjectMatcherManager.java:102
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.ResetAction.clone
ResetAction clone()
Definition: ViewGameObjectMatcherManager.java:127
net.sf.gridarta.model.match.MutableOrGameObjectMatcher
A GameObjectMatcher that delegates to other.
Definition: MutableOrGameObjectMatcher.java:33
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.GameObjectMatcherToggleAction.GameObjectMatcherToggleAction
GameObjectMatcherToggleAction(@NotNull final GameObjectMatcher gameObjectMatcher, @NotNull final MutableOrGameObjectMatcher mutableOrArchObjectMatcher)
Creates a new instance.
Definition: ViewGameObjectMatcherManager.java:173
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.GameObjectMatcherToggleAction.setSelected
void setSelected(final boolean selected)
Sets the selected state.
Definition: ViewGameObjectMatcherManager.java:190
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.addArchObjectMatcher
Action addArchObjectMatcher(@NotNull final GameObjectMatcher gameObjectMatcher)
Adds a GameObjectMatcher.
Definition: ViewGameObjectMatcherManager.java:70
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.resetAction
final Action resetAction
The reset action.
Definition: ViewGameObjectMatcherManager.java:53
net.sf.gridarta.model.match.MutableOrGameObjectMatcher.removeArchObjectMatcher
void removeArchObjectMatcher(@NotNull final GameObjectMatcher gameObjectMatcher)
Removes a GameObjectMatcher.
Definition: MutableOrGameObjectMatcher.java:91
net.sf.gridarta.model.match.MutableOrGameObjectMatcher.addArchObjectMatcher
void addArchObjectMatcher(@NotNull final GameObjectMatcher gameObjectMatcher)
Adds a GameObjectMatcher.
Definition: MutableOrGameObjectMatcher.java:81
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.GameObjectMatcherToggleAction.gameObjectMatcher
final GameObjectMatcher gameObjectMatcher
The GameObjectMatcher to add / remove.
Definition: ViewGameObjectMatcherManager.java:164
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.ResetAction.ResetAction
ResetAction(@NotNull final Iterable<? extends GameObjectMatcherToggleAction > actions)
Creates a new instance.
Definition: ViewGameObjectMatcherManager.java:114
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.getAllActions
List<? extends Action > getAllActions()
Gets all actions.
Definition: ViewGameObjectMatcherManager.java:81
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.GameObjectMatcherToggleAction.clone
GameObjectMatcherToggleAction clone()
Definition: ViewGameObjectMatcherManager.java:211
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.GameObjectMatcherToggleAction.mutableOrArchObjectMatcher
final MutableOrGameObjectMatcher mutableOrArchObjectMatcher
A MutableOrGameObjectMatcher to add / remove {} to.
Definition: ViewGameObjectMatcherManager.java:158
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.GameObjectMatcherToggleAction.selected
boolean selected
Selected state.
Definition: ViewGameObjectMatcherManager.java:151
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.actions
final List< GameObjectMatcherToggleAction > actions
The actions.
Definition: ViewGameObjectMatcherManager.java:47
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.GameObjectMatcherToggleAction.actionPerformed
void actionPerformed(@NotNull final ActionEvent e)
Definition: ViewGameObjectMatcherManager.java:179
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.GameObjectMatcherToggleAction.isSelected
boolean isSelected()
Gets the selected state.
Definition: ViewGameObjectMatcherManager.java:205
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.GameObjectMatcherToggleAction
An Action to toggle a GameObjectMatcher within a {}.
Definition: ViewGameObjectMatcherManager.java:141
net.sf.gridarta.model.match.ViewGameObjectMatcherManager
Manages GameObjectMatchers.
Definition: ViewGameObjectMatcherManager.java:34
net.sf.gridarta.model.match.ViewGameObjectMatcherManager.ViewGameObjectMatcherManager
ViewGameObjectMatcherManager(@NotNull final MutableOrGameObjectMatcher mutableOrGameObjectMatcher)
Creates a new instance.
Definition: ViewGameObjectMatcherManager.java:60