Gridarta Editor
AbstractFilterConfig.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.filter;
21 
24 import org.apache.log4j.Category;
25 import org.apache.log4j.Logger;
26 import org.jetbrains.annotations.NotNull;
27 
32 public abstract class AbstractFilterConfig<F extends Filter<F, C>, C extends FilterConfig<F, C>> implements FilterConfig<F, C> {
33 
37  @NotNull
38  private static final Category LOG = Logger.getLogger(AbstractFilterConfig.class);
39 
43  private boolean enabled;
44 
48  @NotNull
50 
54  @NotNull
55  private final F filter;
56 
61  protected AbstractFilterConfig(@NotNull final F filter) {
62  this.filter = filter;
63  }
64 
65  @NotNull
66  @Override
67  public F getFilter() {
68  return filter;
69  }
70 
71  @Override
72  public void setEnabled(final boolean enabled) {
73  if (this.enabled == enabled) {
74  return;
75  }
76  this.enabled = enabled;
77 
78  if (LOG.isDebugEnabled()) {
79  LOG.debug((enabled ? "enabling" : "disabling") + " filter");
80  }
82  }
83 
84  @Override
85  public boolean isEnabled() {
86  return enabled;
87  }
88 
94  protected void fireEvent(@NotNull final FilterConfigChangeType filterConfigChangeType, @NotNull final FilterConfig<?, ?> filterConfig) {
95  for (final FilterConfigListener listener : listenerList.getListeners()) {
96  listener.configChanged(filterConfigChangeType, filterConfig);
97  }
98  }
99 
100  @Override
101  public void addConfigChangeListener(@NotNull final FilterConfigListener listener) {
102  listenerList.add(listener);
103  }
104 
105  @Override
106  public void removeConfigChangeListener(@NotNull final FilterConfigListener listener) {
107  listenerList.remove(listener);
108  }
109 
110  @Override
111  public boolean match(@NotNull final GameObject<?, ?, ?> gameObject) {
112  return filter.match(getThis(), gameObject);
113  }
114 
115  @Override
116  public boolean reset() {
117  return filter.reset(getThis());
118  }
119 
124  @NotNull
125  protected abstract C getThis();
126 
127 }
AbstractFilterConfig(@NotNull final F filter)
Creates a new instance.
final EventListenerList2< FilterConfigListener > listenerList
The registered listeners.
boolean enabled
Whether the filter is enabled.
final F filter
The Filter this filter config belongs to.
void fireEvent(@NotNull final FilterConfigChangeType filterConfigChangeType, @NotNull final FilterConfig<?, ?> filterConfig)
Notify all listeners that a FilterConfig has happened.
Abstract base class for filter configurations.
T [] getListeners()
Returns an array of all the listeners.
Interface for Filters.
Definition: Filter.java:33
void addConfigChangeListener(@NotNull final FilterConfigListener listener)
abstract C getThis()
Returns this filter config.
Base package of all Gridarta classes.
boolean match(@NotNull final GameObject<?, ?, ?> gameObject)
Reflects a game object (object on a map).
Definition: GameObject.java:36
void remove(@NotNull final T listener)
Removes a listener.
GameObjects are the objects based on Archetypes found on maps.
void add(@NotNull final T listener)
Adds a listener.
Type-safe version of EventListenerList.
void removeConfigChangeListener(@NotNull final FilterConfigListener listener)
static final Category LOG
The Logger for printing log messages.
Interface for filter configurations.
Interface for listeners interested in FilterConfig related changes.