Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.awt.AWTEventMulticaster
public class AWTEventMulticaster
extends Object
implements ComponentListener, ContainerListener, FocusListener, KeyListener, MouseListener, MouseMotionListener, WindowListener, WindowFocusListener, WindowStateListener, ActionListener, ItemListener, AdjustmentListener, TextListener, InputMethodListener, HierarchyListener, HierarchyBoundsListener, MouseWheelListener
AdjustmentEvent
's. However, this
same approach is useful for all events in the java.awt.event
package, and more if this class is subclassed.
AdjustmentListener al;
public void addAdjustmentListener(AdjustmentListener listener)
{
al = AWTEventMulticaster.add(al, listener);
}
public void removeAdjustmentListener(AdjustmentListener listener)
{
al = AWTEventMulticaster.remove(al, listener);
}
When it come time to process an event, simply call al
,
assuming it is not null
, and all listeners in the chain will
be fired.
The first time add
is called it is passed
null
and listener
as its arguments. This
starts building the chain. This class returns listener
which becomes the new al
. The next time, add
is called with al
and listener
and the
new listener is then chained to the old.
Field Summary | |
protected EventListener |
|
protected EventListener |
|
Constructor Summary | |
|
Method Summary | |
void |
|
static ActionListener |
|
static AdjustmentListener |
|
static ComponentListener |
|
static ContainerListener |
|
static FocusListener |
|
static HierarchyBoundsListener |
|
static HierarchyListener |
|
static InputMethodListener |
|
static ItemListener |
|
static KeyListener |
|
static MouseListener |
|
static MouseMotionListener |
|
static MouseWheelListener |
|
static TextListener |
|
static WindowFocusListener |
|
static WindowListener |
|
static WindowStateListener |
|
protected static EventListener |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
static |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void | |
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
static ActionListener |
|
static AdjustmentListener |
|
static ComponentListener |
|
static ContainerListener |
|
static FocusListener |
|
static HierarchyBoundsListener |
|
static HierarchyListener |
|
static InputMethodListener |
|
static ItemListener |
|
static KeyListener |
|
static MouseListener |
|
static MouseMotionListener |
|
static MouseWheelListener |
|
static TextListener |
|
static WindowFocusListener |
|
static WindowListener |
|
static WindowStateListener |
|
protected EventListener |
|
protected static EventListener |
|
protected static void |
|
protected void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
protected AWTEventMulticaster(EventListener a, EventListener b)
Initializes a new instance ofAWTEventMulticaster
with the specified event listener parameters. The parameters should not be null, although it is not required to enforce this with a NullPointerException.
- Parameters:
a
- the "a" listener objectb
- the "b" listener object
public void actionPerformed(ActionEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- actionPerformed in interface ActionListener
- Parameters:
e
- the event to handle
public static ActionListener add(ActionListener a, ActionListener b)
ChainActionListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
public static AdjustmentListener add(AdjustmentListener a, AdjustmentListener b)
ChainAdjustmentListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
public static ComponentListener add(ComponentListener a, ComponentListener b)
ChainComponentListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
public static ContainerListener add(ContainerListener a, ContainerListener b)
ChainContainerListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
public static FocusListener add(FocusListener a, FocusListener b)
ChainFocusListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
public static HierarchyBoundsListener add(HierarchyBoundsListener a, HierarchyBoundsListener b)
ChainHierarchyBoundsListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
- Since:
- 1.3
public static HierarchyListener add(HierarchyListener a, HierarchyListener b)
ChainHierarchyListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
- Since:
- 1.3
public static InputMethodListener add(InputMethodListener a, InputMethodListener b)
ChainInputMethodListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
- Since:
- 1.2
public static ItemListener add(ItemListener a, ItemListener b)
ChainItemListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
public static KeyListener add(KeyListener a, KeyListener b)
ChainKeyListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
public static MouseListener add(MouseListener a, MouseListener b)
ChainMouseListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
public static MouseMotionListener add(MouseMotionListener a, MouseMotionListener b)
ChainMouseMotionListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
public static MouseWheelListener add(MouseWheelListener a, MouseWheelListener b)
ChainMouseWheelListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
- Since:
- 1.4
public static TextListener add(TextListener a, TextListener b)
ChainAdjustmentListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
public static WindowFocusListener add(WindowFocusListener a, WindowFocusListener b)
ChainWindowFocusListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
- Since:
- 1.4
public static WindowListener add(WindowListener a, WindowListener b)
ChainWindowListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
public static WindowStateListener add(WindowStateListener a, WindowStateListener b)
ChainWindowStateListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
- Since:
- 1.4
protected static EventListener addInternal(EventListener a, EventListener b)
ChainEventListener
a and b.
- Parameters:
a
- the "a" listener, may be nullb
- the "b" listener, may be null
- Returns:
- latest entry in the chain
public void adjustmentValueChanged(AdjustmentEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- adjustmentValueChanged in interface AdjustmentListener
- Parameters:
e
- the event to handle
public void ancestorMoved(HierarchyEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- ancestorMoved in interface HierarchyBoundsListener
- Parameters:
e
- the event to handle
- Since:
- 1.3
public void ancestorResized(HierarchyEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- ancestorResized in interface HierarchyBoundsListener
- Parameters:
e
- the event to handle
- Since:
- 1.3
public void caretPositionChanged(InputMethodEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- caretPositionChanged in interface InputMethodListener
- Parameters:
e
- the event to handle
- Since:
- 1.2
public void componentAdded(ContainerEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- componentAdded in interface ContainerListener
- Parameters:
e
- the event to handle
public void componentHidden(ComponentEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- componentHidden in interface ComponentListener
- Parameters:
e
- the event to handle
public void componentMoved(ComponentEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- componentMoved in interface ComponentListener
- Parameters:
e
- the event to handle
public void componentRemoved(ContainerEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- componentRemoved in interface ContainerListener
- Parameters:
e
- the event to handle
public void componentResized(ComponentEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- componentResized in interface ComponentListener
- Parameters:
e
- the event to handle
public void componentShown(ComponentEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- componentShown in interface ComponentListener
- Parameters:
e
- the event to handle
public staticextends EventListener> T[] getListeners(EventListener l, Class type)
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.
- Parameters:
l
- the listener chain to convert to an arraytype
- the type of listeners to collect
- Returns:
- an array of the listeners of that type in the chain
- Throws:
ClassCastException
- if type is not assignable from EventListenerNullPointerException
- if type is nullIllegalArgumentException
- if type is Void.TYPE
- Since:
- 1.4
public void focusGained(FocusEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- focusGained in interface FocusListener
- Parameters:
e
- the event to handle
public void focusLost(FocusEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- focusLost in interface FocusListener
- Parameters:
e
- the event to handle
public void hierarchyChanged(HierarchyEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- hierarchyChanged in interface HierarchyListener
- Parameters:
e
- the event to handle
- Since:
- 1.3
public void inputMethodTextChanged(InputMethodEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- inputMethodTextChanged in interface InputMethodListener
- Parameters:
e
- the event to handle
- Since:
- 1.2
public void itemStateChanged(ItemEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- itemStateChanged in interface ItemListener
- Parameters:
e
- the event to handle
public void keyPressed(KeyEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- keyPressed in interface KeyListener
- Parameters:
e
- the event to handle
public void keyReleased(KeyEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- keyReleased in interface KeyListener
- Parameters:
e
- the event to handle
public void keyTyped(KeyEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- keyTyped in interface KeyListener
- Parameters:
e
- the event to handle
public void mouseClicked(MouseEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- mouseClicked in interface MouseListener
- Parameters:
e
- the event to handle
public void mouseDragged(MouseEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- mouseDragged in interface MouseMotionListener
- Parameters:
e
- the event to handle
public void mouseEntered(MouseEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- mouseEntered in interface MouseListener
- Parameters:
e
- the event to handle
public void mouseExited(MouseEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- mouseExited in interface MouseListener
- Parameters:
e
- the event to handle
public void mouseMoved(MouseEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- mouseMoved in interface MouseMotionListener
- Parameters:
e
- the event to handle
public void mousePressed(MouseEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- mousePressed in interface MouseListener
- Parameters:
e
- the event to handle
public void mouseReleased(MouseEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- mouseReleased in interface MouseListener
- Parameters:
e
- the event to handle
public void mouseWheelMoved(MouseWheelEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- mouseWheelMoved in interface MouseWheelListener
- Parameters:
e
- the event to handle
- Since:
- 1.4
public static ActionListener remove(ActionListener l, ActionListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
public static AdjustmentListener remove(AdjustmentListener l, AdjustmentListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
public static ComponentListener remove(ComponentListener l, ComponentListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
public static ContainerListener remove(ContainerListener l, ContainerListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
public static FocusListener remove(FocusListener l, FocusListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
public static HierarchyBoundsListener remove(HierarchyBoundsListener l, HierarchyBoundsListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
- Since:
- 1.3
public static HierarchyListener remove(HierarchyListener l, HierarchyListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
- Since:
- 1.3
public static InputMethodListener remove(InputMethodListener l, InputMethodListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
- Since:
- 1.2
public static ItemListener remove(ItemListener l, ItemListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
public static KeyListener remove(KeyListener l, KeyListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
public static MouseListener remove(MouseListener l, MouseListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
public static MouseMotionListener remove(MouseMotionListener l, MouseMotionListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
public static MouseWheelListener remove(MouseWheelListener l, MouseWheelListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
- Since:
- 1.4
public static TextListener remove(TextListener l, TextListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
public static WindowFocusListener remove(WindowFocusListener l, WindowFocusListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
- Since:
- 1.4
public static WindowListener remove(WindowListener l, WindowListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
public static WindowStateListener remove(WindowStateListener l, WindowStateListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
- Since:
- 1.4
protected EventListener remove(EventListener oldl)
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.
- Parameters:
oldl
- the object to remove from this multicaster
- Returns:
- the resulting multicaster with the specified listener removed
protected static EventListener removeInternal(EventListener l, EventListener oldl)
Removes the listeneroldl
from the listenerl
.
- Parameters:
l
- the listener chain to reduceoldl
- the listener to remove
- Returns:
- the resulting listener chain
protected static void save(ObjectOutputStream s, String k, EventListener l) throws IOException
Saves a Serializable listener chain to a serialization stream.
- Parameters:
s
- the stream to save tok
- a prefix stream put before each serializable listenerl
- the listener chain to save
- Throws:
IOException
- if serialization fails
protected void saveInternal(ObjectOutputStream s, String k) throws IOException
Saves all Serializable listeners to a serialization stream.
- Parameters:
s
- the stream to save tok
- a prefix stream put before each serializable listener
- Throws:
IOException
- if serialization fails
public void textValueChanged(TextEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- textValueChanged in interface TextListener
- Parameters:
e
- the event to handle
public void windowActivated(WindowEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- windowActivated in interface WindowListener
- Parameters:
e
- the event to handle
public void windowClosed(WindowEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- windowClosed in interface WindowListener
- Parameters:
e
- the event to handle
public void windowClosing(WindowEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- windowClosing in interface WindowListener
- Parameters:
e
- the event to handle
public void windowDeactivated(WindowEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- windowDeactivated in interface WindowListener
- Parameters:
e
- the event to handle
public void windowDeiconified(WindowEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- windowDeiconified in interface WindowListener
- Parameters:
e
- the event to handle
public void windowGainedFocus(WindowEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- windowGainedFocus in interface WindowFocusListener
- Parameters:
e
- the event to handle
- Since:
- 1.4
public void windowIconified(WindowEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- windowIconified in interface WindowListener
- Parameters:
e
- the event to handle
public void windowLostFocus(WindowEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- windowLostFocus in interface WindowFocusListener
- Parameters:
e
- the event to handle
- Since:
- 1.4
public void windowOpened(WindowEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- windowOpened in interface WindowListener
- Parameters:
e
- the event to handle
public void windowStateChanged(WindowEvent e)
Handles this event by dispatching it to the "a" and "b" listener instances.
- Specified by:
- windowStateChanged in interface WindowStateListener
- Parameters:
e
- the event to handle
- Since:
- 1.4