Gridarta Editor
EventListenerList2.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.utils;
21 
22 import java.io.Serializable;
23 import java.util.EventListener;
24 import javax.swing.event.EventListenerList;
25 import org.jetbrains.annotations.NotNull;
26 
31 public class EventListenerList2<T extends EventListener> implements Serializable {
32 
36  private static final long serialVersionUID = 1L;
37 
41  @NotNull
42  private final Class<T> t;
43 
47  @NotNull
48  private final EventListenerList eventListenerList = new EventListenerList();
49 
54  //Assume the constructor call has passed the right type; can't use Class<T>
55  //here since class literals do not work for parametrized types.
56  @SuppressWarnings("unchecked")
57  public EventListenerList2(@NotNull final Class<? extends EventListener> t) {
58  this.t = (Class<T>) t;
59  }
60 
65  @NotNull
66  public T[] getListeners() {
67  return eventListenerList.getListeners(t);
68  }
69 
74  public int getListenerCount() {
75  return eventListenerList.getListenerCount(t);
76  }
77 
82  public void add(@NotNull final T listener) {
83  eventListenerList.add(t, listener);
84  }
85 
90  public void remove(@NotNull final T listener) {
91  eventListenerList.remove(t, listener);
92  }
93 
94  @NotNull
95  @Override
96  public String toString() {
97  return eventListenerList.toString();
98  }
99 
100 }
T [] getListeners()
Returns an array of all the listeners.
static final long serialVersionUID
The serial version UID.
final EventListenerList eventListenerList
The EventListenerList flor delegation.
int getListenerCount()
Returns the number of registered listeners.
void add(@NotNull final T listener)
Adds a listener.
Type-safe version of EventListenerList.
final Class< T > t
The listener&#39;s type.