summaryrefslogtreecommitdiff
path: root/libjava/java/awt/AWTEventMulticaster.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/awt/AWTEventMulticaster.java')
-rw-r--r--libjava/java/awt/AWTEventMulticaster.java1229
1 files changed, 749 insertions, 480 deletions
diff --git a/libjava/java/awt/AWTEventMulticaster.java b/libjava/java/awt/AWTEventMulticaster.java
index 7bbb999daba..58950ef0b98 100644
--- a/libjava/java/awt/AWTEventMulticaster.java
+++ b/libjava/java/awt/AWTEventMulticaster.java
@@ -1,4 +1,5 @@
-/* Copyright (C) 1999, 2000, 2002 Free Software Foundation
+/* AWTEventMulticaster.java -- allows multicast chaining of listeners
+ Copyright (C) 1999, 2000, 2002 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,60 +38,87 @@ exception statement from your version. */
package java.awt;
-import java.awt.event.*;
-import java.util.EventListener;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.AdjustmentEvent;
+import java.awt.event.AdjustmentListener;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
+import java.awt.event.ContainerEvent;
+import java.awt.event.ContainerListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.HierarchyBoundsListener;
+import java.awt.event.HierarchyEvent;
+import java.awt.event.HierarchyListener;
+import java.awt.event.InputMethodEvent;
+import java.awt.event.InputMethodListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.awt.event.MouseWheelEvent;
+import java.awt.event.MouseWheelListener;
+import java.awt.event.TextEvent;
+import java.awt.event.TextListener;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowFocusListener;
+import java.awt.event.WindowListener;
+import java.awt.event.WindowStateListener;
+import java.io.IOException;
import java.io.ObjectOutputStream;
-
-/* Written using on-line Java 2 Platform Standard Edition v1.3 API
- * Specification, as well as "The Java Class Libraries", 2nd edition
- * (Addison-Wesley, 1998).
- * Status: Believed complete and correct to J2SE 1.3, except for
- * serialization support methods, save() and saveInternal(), which are
- * stubbed.
- */
+import java.io.Serializable;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.EventListener;
/**
- * This class is used to implement a chain of event handlers. Dispatching
- * using this class is thread safe. Here is a quick example of how to
- * add and delete listeners using this class. For this example, we will
- * assume are firing <code>AdjustableEvent</code>'s. However, this
- * same approach is useful for all events in the <code>java.awt.event</code>
- * package, and more if this class is subclassed.
- * <p>
- * <code>
- * AdjustmentListener al;
- *
- * public void
- * addAdjustmentListener(AdjustmentListener listener)
- * {
- * al = AWTEventMulticaster.add(al, listener);
- * }
- *
- * public void
- * removeAdjustmentListener(AdjustmentListener listener)
- * {
- * al = AWTEventMulticaster.remove(al, listener);
- * }
- * </code>
- * <p>
- * When it come time to process an event, simply call <code>al</code>,
- * assuming it is not <code>null</code>.
- * <p>
- * The first time <code>add</code> is called it is passed
- * <code>null</code> and <code>listener</code> as its arguments. This
- * starts building the chain. This class returns <code>listener</code>
- * which becomes the new <code>al</code>. The next time, <code>add</code>
- * is called with <code>al</code> and <code>listener</code> and the
- * new listener is then chained to the old.
- *
- * @author Bryce McKinlay
- * @author Aaron M. Renn (arenn@urbanophile.com)
- */
-public class AWTEventMulticaster implements ComponentListener,
- ContainerListener, FocusListener, KeyListener, MouseListener,
- MouseMotionListener, WindowListener, ActionListener, ItemListener,
- AdjustmentListener, TextListener, InputMethodListener, HierarchyListener,
- HierarchyBoundsListener
+ * This class is used to implement a chain of event handlers. Dispatching
+ * using this class is thread safe. Here is a quick example of how to
+ * add and delete listeners using this class. For this example, we will
+ * assume are firing <code>AdjustmentEvent</code>'s. However, this
+ * same approach is useful for all events in the <code>java.awt.event</code>
+ * package, and more if this class is subclassed.
+ *
+ * <p><code>
+ * AdjustmentListener al;
+ * public void addAdjustmentListener(AdjustmentListener listener)
+ * {
+ * al = AWTEventMulticaster.add(al, listener);
+ * }
+ * public void removeAdjustmentListener(AdjustmentListener listener)
+ * {
+ * al = AWTEventMulticaster.remove(al, listener);
+ * }
+ * </code>
+ *
+ * <p>When it come time to process an event, simply call <code>al</code>,
+ * assuming it is not <code>null</code>, and all listeners in the chain will
+ * be fired.
+ *
+ * <p>The first time <code>add</code> is called it is passed
+ * <code>null</code> and <code>listener</code> as its arguments. This
+ * starts building the chain. This class returns <code>listener</code>
+ * which becomes the new <code>al</code>. The next time, <code>add</code>
+ * is called with <code>al</code> and <code>listener</code> and the
+ * new listener is then chained to the old.
+ *
+ * @author Bryce McKinlay
+ * @author Aaron M. Renn <arenn@urbanophile.com>
+ * @author Eric Blake <ebb9@email.byu.edu>
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public class AWTEventMulticaster
+ implements ComponentListener, ContainerListener, FocusListener, KeyListener,
+ MouseListener, MouseMotionListener, WindowListener,
+ WindowFocusListener, WindowStateListener, ActionListener,
+ ItemListener, AdjustmentListener, TextListener,
+ InputMethodListener, HierarchyListener, HierarchyBoundsListener,
+ MouseWheelListener
{
/**
* A variable in the event chain.
@@ -98,72 +126,32 @@ public class AWTEventMulticaster implements ComponentListener,
protected final EventListener a;
/**
- * A variable in the event chain
+ * A variable in the event chain.
*/
protected final EventListener b;
/**
* Initializes a new instance of <code>AWTEventMulticaster</code> with
- * the specified event listener parameters.
+ * the specified event listener parameters. The parameters should not be
+ * null, although it is not required to enforce this with a
+ * NullPointerException.
*
- * @param a The "a" listener object.
- * @param b The "b" listener object.
+ * @param a the "a" listener object
+ * @param b the "b" listener object
*/
- protected AWTEventMulticaster(EventListener a,
- EventListener b)
+ protected AWTEventMulticaster(EventListener a, EventListener b)
{
this.a = a;
this.b = b;
}
/**
- * Chain <code>EventListener</code> b to a.
- *
- * @param a - Listener to chain to.
- * @param b - Listener to chain.
+ * Removes one instance of the specified listener from this multicaster
+ * chain. This descends recursively if either child is a multicaster, and
+ * returns a multicaster chain with the old listener removed.
*
- * @return Latest entry in the chain.
- */
- protected static EventListener addInternal(EventListener a, EventListener b)
- {
- if (a == null)
- return b;
- else if (b == null)
- return a;
- else return new AWTEventMulticaster(a, b);
- }
-
- /**
- * Removes the listener <code>old</code> from the listener <code>lis</code>.
- *
- * @param lis The listener to remove <code>old</code> from.
- * @param old The listener to remove.
- *
- * @return The resulting listener after the remove operation.
- */
- protected static EventListener removeInternal(EventListener l,
- EventListener oldl)
- {
- if (l == oldl)
- return null;
- else if (l instanceof AWTEventMulticaster)
- {
- AWTEventMulticaster mc = (AWTEventMulticaster) l;
- return mc.remove(oldl);
- }
- return l;
- }
-
- /**
- * Removes the specified object from this multicaster object. If the
- * object to remove is not part of this multicaster, then the remove
- * method on the parent multicaster (if it exists) is called and a
- * new multicaster object is returned based on that object and this
- * multicaster's non-parent object.
- *
- * @param old The object to remove from this multicaster.
- *
- * @return The resulting multicaster with the specified listener removed.
+ * @param oldl the object to remove from this multicaster
+ * @return the resulting multicaster with the specified listener removed
*/
protected EventListener remove(EventListener oldl)
{
@@ -172,361 +160,369 @@ public class AWTEventMulticaster implements ComponentListener,
return b;
if (b == oldl)
return a;
-
// If a and/or b are Multicaster's, search them recursively.
if (a instanceof AWTEventMulticaster)
{
- AWTEventMulticaster mc = (AWTEventMulticaster) a;
- EventListener newa = mc.remove(oldl);
- if (newa != a)
- return new AWTEventMulticaster (newa, b);
- }
+ EventListener newa = ((AWTEventMulticaster) a).remove(oldl);
+ if (newa != a)
+ return new AWTEventMulticaster(newa, b);
+ }
if (b instanceof AWTEventMulticaster)
{
- AWTEventMulticaster mc = (AWTEventMulticaster) a;
- EventListener newb = mc.remove(oldl);
- if (newb != b)
- return new AWTEventMulticaster (a, newb);
+ EventListener newb = ((AWTEventMulticaster) b).remove(oldl);
+ if (newb != b)
+ return new AWTEventMulticaster(a, newb);
}
-
// oldl was not found.
return this;
}
/**
- * Chain <code>ActionListener</code> b to a.
- *
- * @param a - Listener to chain to.
- * @param b - Listener to chain.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return Latest entry in the chain.
+ * @param event the event to handle
*/
- public static ActionListener add(ActionListener a, ActionListener b)
+ public void componentResized(ComponentEvent e)
{
- return (ActionListener) addInternal(a, b);
+ ((ComponentListener) a).componentResized(e);
+ ((ComponentListener) b).componentResized(e);
}
/**
- * Chain <code>AdjustmentListener</code> b to a.
- *
- * @param a - Listener to chain to.
- * @param b - Listener to chain.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return Latest entry in the chain.
+ * @param event the event to handle
*/
- public static AdjustmentListener add(AdjustmentListener a,
- AdjustmentListener b)
+ public void componentMoved(ComponentEvent e)
{
- return (AdjustmentListener) addInternal(a, b);
- }
+ ((ComponentListener) a).componentMoved(e);
+ ((ComponentListener) b).componentMoved(e);
+ }
/**
- * Chain <code>ComponentListener</code> b to a.
- *
- * @param a - Listener to chain to.
- * @param b - Listener to chain.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return Latest entry in the chain.
+ * @param event the event to handle
*/
- public static ComponentListener add(ComponentListener a, ComponentListener b)
+ public void componentShown(ComponentEvent e)
{
- return (ComponentListener) addInternal(a, b);
+ ((ComponentListener) a).componentShown(e);
+ ((ComponentListener) b).componentShown(e);
}
/**
- * Chain <code>ContainerListener</code> b to a.
- *
- * @param a - Listener to chain to.
- * @param b - Listener to chain.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return Latest entry in the chain.
+ * @param event the event to handle
*/
- public static ContainerListener add(ContainerListener a, ContainerListener b)
+ public void componentHidden(ComponentEvent e)
{
- return (ContainerListener) addInternal(a, b);
+ ((ComponentListener) a).componentHidden(e);
+ ((ComponentListener) b).componentHidden(e);
}
/**
- * Chain <code>FocusListener</code> b to a.
- *
- * @param a - Listener to chain to.
- * @param b - Listener to chain.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return Latest entry in the chain.
+ * @param event the event to handle
*/
- public static FocusListener add(FocusListener a, FocusListener b)
+ public void componentAdded(ContainerEvent e)
{
- return (FocusListener) addInternal(a, b);
+ ((ContainerListener) a).componentAdded(e);
+ ((ContainerListener) b).componentAdded(e);
}
- public static HierarchyBoundsListener add(HierarchyBoundsListener a,
- HierarchyBoundsListener b)
+ /**
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
+ *
+ * @param event the event to handle
+ */
+ public void componentRemoved(ContainerEvent e)
{
- return (HierarchyBoundsListener) addInternal(a, b);
+ ((ContainerListener) a).componentRemoved(e);
+ ((ContainerListener) b).componentRemoved(e);
}
- public static HierarchyListener add(HierarchyListener a, HierarchyListener b)
+ /**
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
+ *
+ * @param event the event to handle
+ */
+ public void focusGained(FocusEvent e)
{
- return (HierarchyListener) addInternal(a, b);
+ ((FocusListener) a).focusGained(e);
+ ((FocusListener) b).focusGained(e);
}
- public static InputMethodListener add(InputMethodListener a,
- InputMethodListener b)
+ /**
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
+ *
+ * @param event the event to handle
+ */
+ public void focusLost(FocusEvent e)
{
- return (InputMethodListener) addInternal(a, b);
+ ((FocusListener) a).focusLost(e);
+ ((FocusListener) b).focusLost(e);
}
/**
- * Chain <code>ItemListener</code> b to a.
- *
- * @param a - Listener to chain to.
- * @param b - Listener to chain.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return Latest entry in the chain.
+ * @param event the event to handle
*/
- public static ItemListener add(ItemListener a, ItemListener b)
+ public void keyTyped(KeyEvent e)
{
- return (ItemListener) addInternal(a, b);
+ ((KeyListener) a).keyTyped(e);
+ ((KeyListener) b).keyTyped(e);
}
/**
- * Chain <code>KeyListener</code> b to a.
- *
- * @param a - Listener to chain to.
- * @param b - Listener to chain.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return Latest entry in the chain.
+ * @param event the event to handle
*/
- public static KeyListener add(KeyListener a, KeyListener b)
+ public void keyPressed(KeyEvent e)
{
- return (KeyListener) addInternal(a, b);
+ ((KeyListener) a).keyPressed(e);
+ ((KeyListener) b).keyPressed(e);
}
/**
- * Chain <code>MouseListener</code> b to a.
- *
- * @param a - Listener to chain to.
- * @param b - Listener to chain.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return Latest entry in the chain.
+ * @param event the event to handle
*/
- public static MouseListener add(MouseListener a, MouseListener b)
+ public void keyReleased(KeyEvent e)
{
- return (MouseListener) addInternal(a, b);
+ ((KeyListener) a).keyReleased(e);
+ ((KeyListener) b).keyReleased(e);
}
/**
- * Chain <code>MouseMotionListener</code> b to a.
- *
- * @param a - Listener to chain to.
- * @param b - Listener to chain.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return Latest entry in the chain.
+ * @param event the event to handle
*/
- public static MouseMotionListener add(MouseMotionListener a,
- MouseMotionListener b)
+ public void mouseClicked(MouseEvent e)
{
- return (MouseMotionListener) addInternal(a, b);
+ ((MouseListener) a).mouseClicked(e);
+ ((MouseListener) b).mouseClicked(e);
}
/**
- * Chain <code>AdjustmentListener</code> b to a.
- *
- * @param a - Listener to chain to.
- * @param b - Listener to chain.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return Latest entry in the chain.
+ * @param event the event to handle
*/
- public static TextListener add(TextListener a, TextListener b)
+ public void mousePressed(MouseEvent e)
{
- return (TextListener) addInternal(a, b);
+ ((MouseListener) a).mousePressed(e);
+ ((MouseListener) b).mousePressed(e);
}
/**
- * Chain <code>WindowListener</code> b to a.
- *
- * @param a - Listener to chain to.
- * @param b - Listener to chain.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return Latest entry in the chain.
+ * @param event the event to handle
*/
- public static WindowListener add(WindowListener a, WindowListener b)
+ public void mouseReleased(MouseEvent e)
{
- return (WindowListener) addInternal(a, b);
+ ((MouseListener) a).mouseReleased(e);
+ ((MouseListener) b).mouseReleased(e);
}
/**
- * Removes the listener <code>old</code> from the listener <code>lis</code>.
- *
- * @param lis The listener to remove <code>old</code> from.
- * @param old The listener to remove.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return The resulting listener after the remove operation.
+ * @param event the event to handle
*/
- public static ActionListener remove(ActionListener l, ActionListener oldl)
+ public void mouseEntered(MouseEvent e)
{
- return (ActionListener) removeInternal(l, oldl);
+ ((MouseListener) a).mouseEntered(e);
+ ((MouseListener) b).mouseEntered(e);
}
/**
- * Removes the listener <code>old</code> from the listener <code>lis</code>.
- *
- * @param lis The listener to remove <code>old</code> from.
- * @param old The listener to remove.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return The resulting listener after the remove operation.
+ * @param event the event to handle
*/
- public static AdjustmentListener remove(AdjustmentListener l,
- AdjustmentListener oldl)
+ public void mouseExited(MouseEvent e)
{
- return (AdjustmentListener) removeInternal(l, oldl);
+ ((MouseListener) a).mouseExited(e);
+ ((MouseListener) b).mouseExited(e);
}
/**
- * Removes the listener <code>old</code> from the listener <code>lis</code>.
- *
- * @param lis The listener to remove <code>old</code> from.
- * @param old The listener to remove.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return The resulting listener after the remove operation.
+ * @param event the event to handle
*/
- public static ComponentListener remove(ComponentListener l,
- ComponentListener oldl)
+ public void mouseDragged(MouseEvent e)
{
- return (ComponentListener) removeInternal(l, oldl);
+ ((MouseMotionListener) a).mouseDragged(e);
+ ((MouseMotionListener) b).mouseDragged(e);
}
/**
- * Removes the listener <code>old</code> from the listener <code>lis</code>.
- *
- * @param lis The listener to remove <code>old</code> from.
- * @param old The listener to remove.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return The resulting listener after the remove operation.
+ * @param event the event to handle
*/
- public static ContainerListener remove(ContainerListener l,
- ContainerListener oldl)
+ public void mouseMoved(MouseEvent e)
{
- return (ContainerListener) removeInternal(l, oldl);
+ ((MouseMotionListener) a).mouseMoved(e);
+ ((MouseMotionListener) b).mouseMoved(e);
}
/**
- * Removes the listener <code>old</code> from the listener <code>lis</code>.
- *
- * @param lis The listener to remove <code>old</code> from.
- * @param old The listener to remove.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return The resulting listener after the remove operation.
+ * @param event the event to handle
*/
- public static FocusListener remove(FocusListener l, FocusListener oldl)
+ public void windowOpened(WindowEvent e)
{
- return (FocusListener) removeInternal(l, oldl);
+ ((WindowListener) a).windowOpened(e);
+ ((WindowListener) b).windowOpened(e);
}
- public static HierarchyBoundsListener remove(HierarchyBoundsListener l,
- HierarchyBoundsListener oldl)
+ /**
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
+ *
+ * @param event the event to handle
+ */
+ public void windowClosing(WindowEvent e)
{
- return (HierarchyBoundsListener) removeInternal(l, oldl);
+ ((WindowListener) a).windowClosing(e);
+ ((WindowListener) b).windowClosing(e);
}
- public static HierarchyListener remove(HierarchyListener l,
- HierarchyListener oldl)
+ /**
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
+ *
+ * @param event the event to handle
+ */
+ public void windowClosed(WindowEvent e)
{
- return (HierarchyListener) removeInternal(l, oldl);
+ ((WindowListener) a).windowClosed(e);
+ ((WindowListener) b).windowClosed(e);
}
- public static InputMethodListener remove(InputMethodListener l,
- InputMethodListener oldl)
+ /**
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
+ *
+ * @param event the event to handle
+ */
+ public void windowIconified(WindowEvent e)
{
- return (InputMethodListener) removeInternal(l, oldl);
+ ((WindowListener) a).windowIconified(e);
+ ((WindowListener) b).windowIconified(e);
}
/**
- * Removes the listener <code>old</code> from the listener <code>lis</code>.
- *
- * @param lis The listener to remove <code>old</code> from.
- * @param old The listener to remove.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return The resulting listener after the remove operation.
+ * @param event the event to handle
*/
- public static ItemListener remove(ItemListener l, ItemListener oldl)
+ public void windowDeiconified(WindowEvent e)
{
- return (ItemListener) removeInternal(l, oldl);
+ ((WindowListener) a).windowDeiconified(e);
+ ((WindowListener) b).windowDeiconified(e);
}
/**
- * Removes the listener <code>old</code> from the listener <code>lis</code>.
- *
- * @param lis The listener to remove <code>old</code> from.
- * @param old The listener to remove.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return The resulting listener after the remove operation.
+ * @param event the event to handle
*/
- public static KeyListener remove(KeyListener l, KeyListener oldl)
+ public void windowActivated(WindowEvent e)
{
- return (KeyListener) removeInternal(l, oldl);
+ ((WindowListener) a).windowActivated(e);
+ ((WindowListener) b).windowActivated(e);
}
/**
- * Removes the listener <code>old</code> from the listener <code>lis</code>.
- *
- * @param lis The listener to remove <code>old</code> from.
- * @param old The listener to remove.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return The resulting listener after the remove operation.
+ * @param event the event to handle
*/
- public static MouseListener remove(MouseListener l, MouseListener oldl)
+ public void windowDeactivated(WindowEvent e)
{
- return (MouseListener) removeInternal(l, oldl);
+ ((WindowListener) a).windowDeactivated(e);
+ ((WindowListener) b).windowDeactivated(e);
}
/**
- * Removes the listener <code>old</code> from the listener <code>lis</code>.
- *
- * @param lis The listener to remove <code>old</code> from.
- * @param old The listener to remove.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return The resulting listener after the remove operation.
+ * @param event the event to handle
+ * @since 1.4
*/
- public static MouseMotionListener remove(MouseMotionListener l,
- MouseMotionListener oldl)
+ public void windowStateChanged(WindowEvent e)
{
- return (MouseMotionListener) removeInternal(l, oldl);
+ ((WindowStateListener) a).windowStateChanged(e);
+ ((WindowStateListener) b).windowStateChanged(e);
}
/**
- * Removes the listener <code>old</code> from the listener <code>lis</code>.
- *
- * @param lis The listener to remove <code>old</code> from.
- * @param old The listener to remove.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return The resulting listener after the remove operation.
+ * @param event the event to handle
+ * @since 1.4
*/
- public static TextListener remove(TextListener l, TextListener oldl)
+ public void windowGainedFocus(WindowEvent e)
{
- return (TextListener) removeInternal(l, oldl);
+ ((WindowFocusListener) a).windowGainedFocus(e);
+ ((WindowFocusListener) b).windowGainedFocus(e);
}
/**
- * Removes the listener <code>old</code> from the listener <code>lis</code>.
- *
- * @param lis The listener to remove <code>old</code> from.
- * @param old The listener to remove.
+ * Handles this event by dispatching it to the "a" and "b" listener
+ * instances.
*
- * @return The resulting listener after the remove operation.
+ * @param event the event to handle
+ * @since 1.4
*/
- public static WindowListener remove(WindowListener l, WindowListener oldl)
+ public void windowLostFocus(WindowEvent e)
{
- return (WindowListener) removeInternal(l, oldl);
+ ((WindowFocusListener) a).windowLostFocus(e);
+ ((WindowFocusListener) b).windowLostFocus(e);
}
/**
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event The event to handle.
+ * @param event the event to handle
*/
- public void actionPerformed(ActionEvent e)
+ public void actionPerformed(ActionEvent e)
{
((ActionListener) a).actionPerformed(e);
((ActionListener) b).actionPerformed(e);
@@ -536,405 +532,678 @@ public class AWTEventMulticaster implements ComponentListener,
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event The event to handle.
+ * @param event the event to handle
*/
- public void adjustmentValueChanged(AdjustmentEvent e)
+ public void itemStateChanged(ItemEvent e)
{
- ((AdjustmentListener) a).adjustmentValueChanged(e);
- ((AdjustmentListener) b).adjustmentValueChanged(e);
+ ((ItemListener) a).itemStateChanged(e);
+ ((ItemListener) b).itemStateChanged(e);
}
/**
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event The event to handle.
+ * @param event the event to handle
*/
- public void componentHidden(ComponentEvent e)
+ public void adjustmentValueChanged(AdjustmentEvent e)
{
- ((ComponentListener) a).componentHidden(e);
- ((ComponentListener) b).componentHidden(e);
+ ((AdjustmentListener) a).adjustmentValueChanged(e);
+ ((AdjustmentListener) b).adjustmentValueChanged(e);
}
/**
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event The event to handle.
+ * @param event the event to handle
*/
- public void componentMoved(ComponentEvent e)
+ public void textValueChanged(TextEvent e)
{
- ((ComponentListener) a).componentMoved(e);
- ((ComponentListener) b).componentMoved(e);
+ ((TextListener) a).textValueChanged(e);
+ ((TextListener) b).textValueChanged(e);
}
/**
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event The event to handle.
+ * @param event the event to handle
+ * @since 1.2
*/
- public void componentResized(ComponentEvent e)
+ public void inputMethodTextChanged(InputMethodEvent e)
{
- ((ComponentListener) a).componentResized(e);
- ((ComponentListener) b).componentResized(e);
+ ((InputMethodListener) a).inputMethodTextChanged(e);
+ ((InputMethodListener) b).inputMethodTextChanged(e);
}
/**
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event The event to handle.
+ * @param event the event to handle
+ * @since 1.2
*/
- public void componentShown(ComponentEvent e)
+ public void caretPositionChanged(InputMethodEvent e)
{
- ((ComponentListener) a).componentShown(e);
- ((ComponentListener) b).componentShown(e);
+ ((InputMethodListener) a).caretPositionChanged(e);
+ ((InputMethodListener) b).caretPositionChanged(e);
}
/**
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event The event to handle.
+ * @param event the event to handle
+ * @since 1.3
*/
- public void componentAdded(ContainerEvent e)
+ public void hierarchyChanged(HierarchyEvent e)
{
- ((ContainerListener) a).componentAdded(e);
- ((ContainerListener) b).componentAdded(e);
+ ((HierarchyListener) a).hierarchyChanged(e);
+ ((HierarchyListener) b).hierarchyChanged(e);
}
/**
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event The event to handle.
+ * @param event the event to handle
+ * @since 1.3
*/
- public void componentRemoved(ContainerEvent e)
+ public void ancestorMoved(HierarchyEvent e)
{
- ((ContainerListener) a).componentRemoved(e);
- ((ContainerListener) b).componentRemoved(e);
+ ((HierarchyBoundsListener) a).ancestorMoved(e);
+ ((HierarchyBoundsListener) b).ancestorMoved(e);
}
/**
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event The event to handle.
+ * @param event the event to handle
+ * @since 1.3
*/
- public void focusGained(FocusEvent e)
+ public void ancestorResized(HierarchyEvent e)
{
- ((FocusListener) a).focusGained(e);
- ((FocusListener) b).focusGained(e);
+ ((HierarchyBoundsListener) a).ancestorResized(e);
+ ((HierarchyBoundsListener) b).ancestorResized(e);
}
/**
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event The event to handle.
+ * @param event the event to handle
+ * @since 1.4
*/
- public void focusLost(FocusEvent e)
+ public void mouseWheelMoved(MouseWheelEvent e)
{
- ((FocusListener) a).focusLost(e);
- ((FocusListener) b).focusLost(e);
+ ((MouseWheelListener) a).mouseWheelMoved(e);
+ ((MouseWheelListener) b).mouseWheelMoved(e);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>ComponentListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
*/
- public void ancestorMoved(HierarchyEvent e)
+ public static ComponentListener add(ComponentListener a, ComponentListener b)
{
- ((HierarchyBoundsListener) a).ancestorMoved(e);
- ((HierarchyBoundsListener) b).ancestorMoved(e);
+ return (ComponentListener) addInternal(a, b);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>ContainerListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
*/
- public void ancestorResized(HierarchyEvent e)
+ public static ContainerListener add(ContainerListener a, ContainerListener b)
{
- ((HierarchyBoundsListener) a).ancestorResized(e);
- ((HierarchyBoundsListener) b).ancestorResized(e);
+ return (ContainerListener) addInternal(a, b);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>FocusListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
*/
- public void hierarchyChanged(HierarchyEvent e)
+ public static FocusListener add(FocusListener a, FocusListener b)
{
- ((HierarchyListener) a).hierarchyChanged(e);
- ((HierarchyListener) b).hierarchyChanged(e);
+ return (FocusListener) addInternal(a, b);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>KeyListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
*/
- public void caretPositionChanged(InputMethodEvent e)
+ public static KeyListener add(KeyListener a, KeyListener b)
{
- ((InputMethodListener) a).caretPositionChanged(e);
- ((InputMethodListener) b).caretPositionChanged(e);
+ return (KeyListener) addInternal(a, b);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>MouseListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
*/
- public void inputMethodTextChanged(InputMethodEvent e)
+ public static MouseListener add(MouseListener a, MouseListener b)
{
- ((InputMethodListener) a).inputMethodTextChanged(e);
- ((InputMethodListener) b).inputMethodTextChanged(e);
+ return (MouseListener) addInternal(a, b);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>MouseMotionListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
*/
- public void itemStateChanged(ItemEvent e)
+ public static MouseMotionListener add(MouseMotionListener a,
+ MouseMotionListener b)
{
- ((ItemListener) a).itemStateChanged(e);
- ((ItemListener) b).itemStateChanged(e);
- }
+ return (MouseMotionListener) addInternal(a, b);
+ }
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>WindowListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
*/
- public void keyPressed(KeyEvent e)
+ public static WindowListener add(WindowListener a, WindowListener b)
{
- ((KeyListener) a).keyPressed(e);
- ((KeyListener) b).keyPressed(e);
+ return (WindowListener) addInternal(a, b);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>WindowStateListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
+ * @since 1.4
*/
- public void keyReleased(KeyEvent e)
+ public static WindowStateListener add(WindowStateListener a,
+ WindowStateListener b)
{
- ((KeyListener) a).keyReleased(e);
- ((KeyListener) b).keyReleased(e);
+ return (WindowStateListener) addInternal(a, b);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>WindowFocusListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
+ * @since 1.4
*/
- public void keyTyped(KeyEvent e)
+ public static WindowFocusListener add(WindowFocusListener a,
+ WindowFocusListener b)
{
- ((KeyListener) a).keyTyped(e);
- ((KeyListener) b).keyTyped(e);
+ return (WindowFocusListener) addInternal(a, b);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>ActionListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
*/
- public void mouseClicked(MouseEvent e)
+ public static ActionListener add(ActionListener a, ActionListener b)
{
- ((MouseListener) a).mouseClicked(e);
- ((MouseListener) b).mouseClicked(e);
+ return (ActionListener) addInternal(a, b);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>ItemListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
*/
- public void mouseEntered(MouseEvent e)
+ public static ItemListener add(ItemListener a, ItemListener b)
{
- ((MouseListener) a).mouseEntered(e);
- ((MouseListener) b).mouseEntered(e);
+ return (ItemListener) addInternal(a, b);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>AdjustmentListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
*/
- public void mouseExited(MouseEvent e)
+ public static AdjustmentListener add(AdjustmentListener a,
+ AdjustmentListener b)
{
- ((MouseListener) a).mouseExited(e);
- ((MouseListener) b).mouseExited(e);
+ return (AdjustmentListener) addInternal(a, b);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>AdjustmentListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
*/
- public void mousePressed(MouseEvent e)
+ public static TextListener add(TextListener a, TextListener b)
{
- ((MouseListener) a).mousePressed(e);
- ((MouseListener) b).mousePressed(e);
+ return (TextListener) addInternal(a, b);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>InputMethodListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
+ * @since 1.2
*/
- public void mouseReleased(MouseEvent e)
+ public static InputMethodListener add(InputMethodListener a,
+ InputMethodListener b)
{
- ((MouseListener) a).mouseReleased(e);
- ((MouseListener) b).mouseReleased(e);
+ return (InputMethodListener) addInternal(a, b);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>HierarchyListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
+ * @since 1.3
*/
- public void mouseDragged(MouseEvent e)
+ public static HierarchyListener add(HierarchyListener a, HierarchyListener b)
{
- ((MouseMotionListener) a).mouseDragged(e);
- ((MouseMotionListener) b).mouseDragged(e);
+ return (HierarchyListener) addInternal(a, b);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>HierarchyBoundsListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
+ * @since 1.3
*/
- public void mouseMoved(MouseEvent e)
+ public static HierarchyBoundsListener add(HierarchyBoundsListener a,
+ HierarchyBoundsListener b)
{
- ((MouseMotionListener) a).mouseMoved(e);
- ((MouseMotionListener) b).mouseMoved(e);
+ return (HierarchyBoundsListener) addInternal(a, b);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Chain <code>MouseWheelListener</code> a and b.
*
- * @param event The event to handle.
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
+ * @since 1.4
*/
- public void textValueChanged(TextEvent e)
+ public static MouseWheelListener add(MouseWheelListener a,
+ MouseWheelListener b)
{
- ((TextListener) a).textValueChanged(e);
- ((TextListener) b).textValueChanged(e);
+ return (MouseWheelListener) addInternal(a, b);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
- * @param event The event to handle.
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
*/
- public void windowActivated(WindowEvent e)
+ public static ComponentListener remove(ComponentListener l,
+ ComponentListener oldl)
{
- ((WindowListener) a).windowActivated(e);
- ((WindowListener) b).windowActivated(e);
+ return (ComponentListener) removeInternal(l, oldl);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
- * @param event The event to handle.
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
*/
- public void windowClosed(WindowEvent e)
+ public static ContainerListener remove(ContainerListener l,
+ ContainerListener oldl)
{
- ((WindowListener) a).windowClosed(e);
- ((WindowListener) b).windowClosed(e);
+ return (ContainerListener) removeInternal(l, oldl);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
- * @param event The event to handle.
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
*/
- public void windowClosing(WindowEvent e)
+ public static FocusListener remove(FocusListener l, FocusListener oldl)
{
- ((WindowListener) a).windowClosing(e);
- ((WindowListener) b).windowClosing(e);
+ return (FocusListener) removeInternal(l, oldl);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
- * @param event The event to handle.
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
*/
- public void windowDeactivated(WindowEvent e)
+ public static KeyListener remove(KeyListener l, KeyListener oldl)
{
- ((WindowListener) a).windowDeactivated(e);
- ((WindowListener) b).windowDeactivated(e);
+ return (KeyListener) removeInternal(l, oldl);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
- * @param event The event to handle.
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
*/
- public void windowDeiconified(WindowEvent e)
+ public static MouseListener remove(MouseListener l, MouseListener oldl)
{
- ((WindowListener) a).windowDeiconified(e);
- ((WindowListener) b).windowDeiconified(e);
+ return (MouseListener) removeInternal(l, oldl);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
- * @param event The event to handle.
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
*/
- public void windowIconified(WindowEvent e)
+ public static MouseMotionListener remove(MouseMotionListener l,
+ MouseMotionListener oldl)
{
- ((WindowListener) a).windowIconified(e);
- ((WindowListener) b).windowIconified(e);
+ return (MouseMotionListener) removeInternal(l, oldl);
}
/**
- * Handles this event by dispatching it to the "a" and "b" listener
- * instances.
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
*
- * @param event The event to handle.
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
*/
- public void windowOpened(WindowEvent e)
+ public static WindowListener remove(WindowListener l, WindowListener oldl)
{
- ((WindowListener) a).windowOpened(e);
- ((WindowListener) b).windowOpened(e);
+ return (WindowListener) removeInternal(l, oldl);
+ }
+
+ /**
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
+ *
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
+ * @since 1.4
+ */
+ public static WindowStateListener remove(WindowStateListener l,
+ WindowStateListener oldl)
+ {
+ return (WindowStateListener) removeInternal(l, oldl);
+ }
+
+ /**
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
+ *
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
+ * @since 1.4
+ */
+ public static WindowFocusListener remove(WindowFocusListener l,
+ WindowFocusListener oldl)
+ {
+ return (WindowFocusListener) removeInternal(l, oldl);
+ }
+
+ /**
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
+ *
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
+ */
+ public static ActionListener remove(ActionListener l, ActionListener oldl)
+ {
+ return (ActionListener) removeInternal(l, oldl);
+ }
+
+ /**
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
+ *
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
+ */
+ public static ItemListener remove(ItemListener l, ItemListener oldl)
+ {
+ return (ItemListener) removeInternal(l, oldl);
+ }
+
+ /**
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
+ *
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
+ */
+ public static AdjustmentListener remove(AdjustmentListener l,
+ AdjustmentListener oldl)
+ {
+ return (AdjustmentListener) removeInternal(l, oldl);
+ }
+
+ /**
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
+ *
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
+ */
+ public static TextListener remove(TextListener l, TextListener oldl)
+ {
+ return (TextListener) removeInternal(l, oldl);
+ }
+
+ /**
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
+ *
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
+ * @since 1.2
+ */
+ public static InputMethodListener remove(InputMethodListener l,
+ InputMethodListener oldl)
+ {
+ return (InputMethodListener) removeInternal(l, oldl);
+ }
+
+ /**
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
+ *
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
+ * @since 1.3
+ */
+ public static HierarchyListener remove(HierarchyListener l,
+ HierarchyListener oldl)
+ {
+ return (HierarchyListener) removeInternal(l, oldl);
+ }
+
+ /**
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
+ *
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
+ * @since 1.3
+ */
+ public static HierarchyBoundsListener remove(HierarchyBoundsListener l,
+ HierarchyBoundsListener oldl)
+ {
+ return (HierarchyBoundsListener) removeInternal(l, oldl);
+ }
+
+ /**
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
+ *
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
+ * @since 1.4
+ */
+ public static MouseWheelListener remove(MouseWheelListener l,
+ MouseWheelListener oldl)
+ {
+ return (MouseWheelListener) removeInternal(l, oldl);
+ }
+
+ /**
+ * Chain <code>EventListener</code> a and b.
+ *
+ * @param a the "a" listener, may be null
+ * @param b the "b" listener, may be null
+ * @return latest entry in the chain
+ */
+ protected static EventListener addInternal(EventListener a, EventListener b)
+ {
+ if (a == null)
+ return b;
+ if (b == null)
+ return a;
+ return new AWTEventMulticaster(a, b);
}
- protected static void save(ObjectOutputStream s, String k, EventListener l)
+ /**
+ * Removes the listener <code>oldl</code> from the listener <code>l</code>.
+ *
+ * @param l the listener chain to reduce
+ * @param oldl the listener to remove
+ * @return the resulting listener chain
+ */
+ protected static EventListener removeInternal(EventListener l,
+ EventListener oldl)
{
- throw new RuntimeException("Not Implemented");
+ if (l == oldl)
+ return null;
+ if (l instanceof AWTEventMulticaster)
+ return ((AWTEventMulticaster) l).remove(oldl);
+ return l;
}
+ /**
+ * Saves all Serializable listeners to a serialization stream.
+ *
+ * @param s the stream to save to
+ * @param k a prefix stream put before each serializable listener
+ * @throws IOException if serialization fails
+ */
protected void saveInternal(ObjectOutputStream s, String k)
+ throws IOException
+ {
+ // This is not documented by Sun, but I think it is correct.
+ if (a instanceof AWTEventMulticaster)
+ ((AWTEventMulticaster) a).saveInternal(s, k);
+ else if (a instanceof Serializable)
+ {
+ s.writeObject(k);
+ s.writeObject(a);
+ }
+ if (b instanceof AWTEventMulticaster)
+ ((AWTEventMulticaster) b).saveInternal(s, k);
+ else if (b instanceof Serializable)
+ {
+ s.writeObject(k);
+ s.writeObject(b);
+ }
+ }
+
+ /**
+ * Saves a Serializable listener chain to a serialization stream.
+ *
+ * @param s the stream to save to
+ * @param k a prefix stream put before each serializable listener
+ * @param l the listener chain to save
+ * @throws IOException if serialization fails
+ */
+ protected static void save(ObjectOutputStream s, String k, EventListener l)
+ throws IOException
+ {
+ // This is not documented by Sun, but I think it is correct.
+ if (l instanceof AWTEventMulticaster)
+ ((AWTEventMulticaster) l).saveInternal(s, k);
+ else if (l instanceof Serializable)
+ {
+ s.writeObject(k);
+ s.writeObject(l);
+ }
+ }
+
+ /**
+ * Returns an array of all chained listeners of the specified type in the
+ * given chain. A null listener returns an empty array, and a listener
+ * which is not an AWTEventMulticaster returns an array of one element. If
+ * no listeners in the chain are of the specified type, an empty array is
+ * returned.
+ *
+ * @param l the listener chain to convert to an array
+ * @param type the type of listeners to collect
+ * @return an array of the listeners of that type in the chain
+ * @throws ClassCastException if type is not assignable from EventListener
+ * @throws NullPointerException if type is null
+ * @throws IllegalArgumentException if type is Void.TYPE
+ * @since 1.4
+ */
+ public static EventListener[] getListeners(EventListener l, Class type)
{
- throw new RuntimeException("Not Implemented");
+ ArrayList list = new ArrayList();
+ if (l instanceof AWTEventMulticaster)
+ ((AWTEventMulticaster) l).getListeners(list, type);
+ else if (type.isInstance(l))
+ list.add(l);
+ EventListener[] r = (EventListener[]) Array.newInstance(type, list.size());
+ list.toArray(r);
+ return r;
+ }
+
+ /**
+ * Collects all instances of the given type in the chain into the list.
+ *
+ * @param l the list to collect into
+ * @param type the type of listeners to collect
+ * @throws NullPointerException if type is null
+ * @see #getListeners(EventListener, Class)
+ */
+ private void getListeners(ArrayList l, Class type)
+ {
+ if (a instanceof AWTEventMulticaster)
+ ((AWTEventMulticaster) a).getListeners(l, type);
+ else if (type.isInstance(a))
+ l.add(a);
+ if (b instanceof AWTEventMulticaster)
+ ((AWTEventMulticaster) b).getListeners(l, type);
+ else if (type.isInstance(b))
+ l.add(b);
}
-}
+} // class AWTEventMulticaster