aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/javax/swing/event
diff options
context:
space:
mode:
authorTom Tromey <tromey@gcc.gnu.org>2007-01-09 19:58:05 +0000
committerTom Tromey <tromey@gcc.gnu.org>2007-01-09 19:58:05 +0000
commit97b8365cafc3a344a22d3980b8ed885f5c6d8357 (patch)
tree996a5f57d4a68c53473382e45cb22f574cb3e4db /libjava/classpath/javax/swing/event
parentc648dedbde727ca3f883bb5fd773aa4af70d3369 (diff)
downloadgcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.zip
gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.gz
gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.bz2
Merged gcj-eclipse branch to trunk.
From-SVN: r120621
Diffstat (limited to 'libjava/classpath/javax/swing/event')
-rw-r--r--libjava/classpath/javax/swing/event/EventListenerList.java60
1 files changed, 55 insertions, 5 deletions
diff --git a/libjava/classpath/javax/swing/event/EventListenerList.java b/libjava/classpath/javax/swing/event/EventListenerList.java
index bde8b3c..1568039 100644
--- a/libjava/classpath/javax/swing/event/EventListenerList.java
+++ b/libjava/classpath/javax/swing/event/EventListenerList.java
@@ -37,6 +37,9 @@ exception statement from your version. */
package javax.swing.event;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.util.EventListener;
@@ -136,7 +139,7 @@ public class EventListenerList
*
* @throws NullPointerException if <code>t</code> is <code>null</code>.
*/
- public void add(Class t, EventListener listener)
+ public <T extends EventListener> void add(Class<T> t, T listener)
{
int oldLength;
Object[] newList;
@@ -175,7 +178,7 @@ public class EventListenerList
* <code>t</code>. Thus, subclasses of <code>t</code> will not be
* counted.
*/
- public int getListenerCount(Class t)
+ public int getListenerCount(Class<?> t)
{
int result = 0;
for (int i = 0; i < listenerList.length; i += 2)
@@ -224,7 +227,7 @@ public class EventListenerList
*
* @since 1.3
*/
- public EventListener[] getListeners(Class c)
+ public <T extends EventListener> T[] getListeners(Class<T> c)
{
int count, f;
EventListener[] result;
@@ -236,7 +239,7 @@ public class EventListenerList
if (listenerList[i] == c)
result[f++] = (EventListener) listenerList[i + 1];
- return result;
+ return (T[]) result;
}
@@ -253,7 +256,7 @@ public class EventListenerList
*
* @throws NullPointerException if <code>t</code> is <code>null</code>.
*/
- public void remove(Class t, EventListener listener)
+ public <T extends EventListener> void remove(Class<T> t, T listener)
{
Object[] oldList, newList;
int oldLength;
@@ -304,4 +307,51 @@ public class EventListenerList
}
return buf.toString();
}
+
+ /**
+ * Serializes an instance to an ObjectOutputStream.
+ *
+ * @param out the stream to serialize to
+ *
+ * @throws IOException if something goes wrong
+ */
+ private void writeObject(ObjectOutputStream out)
+ throws IOException
+ {
+ out.defaultWriteObject();
+ for (int i = 0; i < listenerList.length; i += 2)
+ {
+ Class cl = (Class) listenerList[i];
+ EventListener l = (EventListener) listenerList[i + 1];
+ if (l != null && l instanceof Serializable)
+ {
+ out.writeObject(cl.getName());
+ out.writeObject(l);
+ }
+ }
+ // Write end marker.
+ out.writeObject(null);
+ }
+
+ /**
+ * Deserializes an instance from an ObjectInputStream.
+ *
+ * @param in the input stream
+ *
+ * @throws ClassNotFoundException if a serialized class can't be found
+ * @throws IOException if something goes wrong
+ */
+ private <T extends EventListener> void readObject(ObjectInputStream in)
+ throws ClassNotFoundException, IOException
+ {
+ listenerList = NO_LISTENERS;
+ in.defaultReadObject();
+ Object type;
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ while ((type = in.readObject()) != null)
+ {
+ EventListener l = (EventListener) in.readObject();
+ add(((Class<T>) Class.forName((String) type, true, cl)), (T) l);
+ }
+ }
}