Gridarta Editor
SetEnabledAction.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.model.match;
21 
22 import java.awt.event.ActionEvent;
23 import javax.swing.AbstractAction;
24 import org.jetbrains.annotations.NotNull;
25 
31 public class SetEnabledAction extends AbstractAction {
32 
36  private static final long serialVersionUID = 1L;
37 
42  @NotNull
44 
49  @NotNull
51 
59  public SetEnabledAction(@NotNull final MutableOrGameObjectMatcher mutableOrGameObjectMatcher, @NotNull final GameObjectMatcher gameObjectMatcher) {
60  this.mutableOrGameObjectMatcher = mutableOrGameObjectMatcher;
61  this.gameObjectMatcher = gameObjectMatcher;
62  }
63 
64  @Override
65  public void actionPerformed(@NotNull final ActionEvent e) {
66  if (!isEnabled()) {
67  return;
68  }
70  }
71 
76  private void setSelected(final boolean selected) {
77  if (selected) {
78  mutableOrGameObjectMatcher.addArchObjectMatcher(gameObjectMatcher);
79  } else {
80  mutableOrGameObjectMatcher.removeArchObjectMatcher(gameObjectMatcher);
81  }
82  }
83 
88  public boolean isSelected() {
89  return mutableOrGameObjectMatcher.containsArchObjectMatcher(gameObjectMatcher);
90  }
91 
92  @NotNull
93  @Override
95  try {
96  return (SetEnabledAction) super.clone();
97  } catch (final CloneNotSupportedException ex) {
98  throw new AssertionError(ex);
99  }
100  }
101 
102 }
Interface for classes that match GameObjects.
Action for adding / removing an GameObjectMatcher from this a.
void setSelected(final boolean selected)
Adds / removes the gameObjectMatcher.
final MutableOrGameObjectMatcher mutableOrGameObjectMatcher
The MutableOrGameObjectMatcher to add to / remove from.
SetEnabledAction(@NotNull final MutableOrGameObjectMatcher mutableOrGameObjectMatcher, @NotNull final GameObjectMatcher gameObjectMatcher)
Creates a new instance.
boolean containsArchObjectMatcher(@NotNull final GameObjectMatcher gameObjectMatcher)
Checks whether a certain GameObjectMatcher is contained in this matcher.
void removeArchObjectMatcher(@NotNull final GameObjectMatcher gameObjectMatcher)
Removes an GameObjectMatcher.
void addArchObjectMatcher(@NotNull final GameObjectMatcher gameObjectMatcher)
Adds an GameObjectMatcher.
boolean isSelected()
Returns whether gameObjectMatcher is currently enabled.
static final long serialVersionUID
The serial version UID.
final GameObjectMatcher gameObjectMatcher
The GameObjectMatcher to be added / removed.
void actionPerformed(@NotNull final ActionEvent e)