APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt

public Class AWTEventMulticaster

extends Object
implements ComponentListener, ContainerListener, FocusListener, KeyListener, MouseListener, MouseMotionListener, WindowListener, WindowFocusListener, WindowStateListener, ActionListener, ItemListener, AdjustmentListener, TextListener, InputMethodListener, HierarchyListener, HierarchyBoundsListener, MouseWheelListener
Class Inheritance
All Implemented Interfaces
java.awt.event.MouseWheelListener, java.util.EventListener, java.awt.event.HierarchyBoundsListener, java.awt.event.HierarchyListener, java.awt.event.InputMethodListener, java.awt.event.TextListener, java.awt.event.AdjustmentListener, java.awt.event.ItemListener, java.awt.event.ActionListener, java.awt.event.WindowStateListener, java.awt.event.WindowFocusListener, java.awt.event.WindowListener, java.awt.event.MouseMotionListener, java.awt.event.MouseListener, java.awt.event.KeyListener, java.awt.event.FocusListener, java.awt.event.ContainerListener, java.awt.event.ComponentListener
Known Direct Subclasses
java.awt.Toolkit.ToolkitEventMulticaster, java.awt.dnd.DnDEventMulticaster
Imports
java.awt.event.*, java.lang.reflect.Array, java.util.EventListener, .EventListener, java.io.Serializable, .ObjectOutputStream, .IOException

AWTEventMulticaster implements efficient and thread-safe multi-cast event dispatching for the AWT events defined in the java.awt.event package.

The following example illustrates how to use this class:


public myComponent extends Component {
    ActionListener actionListener = null;

    public synchronized void addActionListener(ActionListener l) {
        actionListener = AWTEventMulticaster.add(actionListener, l);
    }
    public synchronized void removeActionListener(ActionListener l) {
        actionListener = AWTEventMulticaster.remove(actionListener, l);
    }
    public void processEvent(AWTEvent e) {
        // when event occurs which causes "action" semantic
        ActionListener listener = actionListener;
        if (listener != null) {
            listener.actionPerformed(new ActionEvent());
        }
    }
}
The important point to note is the first argument to the add and remove methods is the field maintaining the listeners. In addition you must assign the result of the add and remove methods to the field maintaining the listeners.

AWTEventMulticaster is implemented as a pair of EventListeners that are set at construction time. AWTEventMulticaster is immutable. The add and remove methods do not alter AWTEventMulticaster in anyway. If necessary, a new AWTEventMulticaster is created. In this way it is safe to add and remove listeners during the process of an event dispatching. However, event listeners added during the process of an event dispatch operation are not notified of the event currently being dispatched.

All of the add methods allow null arguments. If the first argument is null, the second argument is returned. If the first argument is not null and the second argument is null, the first argument is returned. If both arguments are non-null, a new AWTEventMulticaster is created using the two arguments and returned.

For the remove methods that take two arguments, the following is returned:

Swing makes use of EventListenerList for similar logic. Refer to it for details.

Authors
John Rose, Amy Fowler
Since
1.1
See Also
javax.swing.event.EventListenerList

Field Summary

Modifier and TypeField and Description
protected final EventListener
a

A variable in the event chain (listener-a)

protected final EventListener
b

A variable in the event chain (listener-b)

private static final int

Constructor Summary

AccessConstructor and Description
protected
AWTEventMulticaster(EventListener
listener-a
a
,
EventListener
listener-b
b
)

Creates an event multicaster instance which chains listener-a with listener-b.

Method Summary

Modifier and TypeMethod and Description
public void
actionPerformed(ActionEvent
the action event
e
)

Implements java.awt.event.ActionListener.actionPerformed.

Handles the actionPerformed event by invoking the actionPerformed methods on listener-a and listener-b.

public static ComponentListener

Returns:

the resulting listener
add
(ComponentListener
component-listener-a
a
,
ComponentListener
component-listener-b
b
)

Adds component-listener-a with component-listener-b and returns the resulting multicast listener.

public static ContainerListener

Returns:

the resulting listener
add
(ContainerListener
container-listener-a
a
,
ContainerListener
container-listener-b
b
)

Adds container-listener-a with container-listener-b and returns the resulting multicast listener.

public static FocusListener

Returns:

the resulting listener
add
(FocusListener
focus-listener-a
a
,
FocusListener
focus-listener-b
b
)

Adds focus-listener-a with focus-listener-b and returns the resulting multicast listener.

public static KeyListener

Returns:

the resulting listener
add
(KeyListener
key-listener-a
a
,
KeyListener
key-listener-b
b
)

Adds key-listener-a with key-listener-b and returns the resulting multicast listener.

public static MouseListener

Returns:

the resulting listener
add
(MouseListener
mouse-listener-a
a
,
MouseListener
mouse-listener-b
b
)

Adds mouse-listener-a with mouse-listener-b and returns the resulting multicast listener.

public static MouseMotionListener

Returns:

the resulting listener
add
(MouseMotionListener
mouse-motion-listener-a
a
,
MouseMotionListener
mouse-motion-listener-b
b
)

Adds mouse-motion-listener-a with mouse-motion-listener-b and returns the resulting multicast listener.

public static WindowListener

Returns:

the resulting listener
add
(WindowListener
window-listener-a
a
,
WindowListener
window-listener-b
b
)

Adds window-listener-a with window-listener-b and returns the resulting multicast listener.

public static WindowStateListener

Returns:

the resulting listener
add
(WindowStateListener
window-state-listener-a
a
,
WindowStateListener
window-state-listener-b
b
)

Adds window-state-listener-a with window-state-listener-b and returns the resulting multicast listener.

public static WindowFocusListener

Returns:

the resulting listener
add
(WindowFocusListener
window-focus-listener-a
a
,
WindowFocusListener
window-focus-listener-b
b
)

Adds window-focus-listener-a with window-focus-listener-b and returns the resulting multicast listener.

public static ActionListener

Returns:

the resulting listener
add
(ActionListener
action-listener-a
a
,
ActionListener
action-listener-b
b
)

Adds action-listener-a with action-listener-b and returns the resulting multicast listener.

public static ItemListener

Returns:

the resulting listener
add
(ItemListener
item-listener-a
a
,
ItemListener
item-listener-b
b
)

Adds item-listener-a with item-listener-b and returns the resulting multicast listener.

public static AdjustmentListener

Returns:

the resulting listener
add
(AdjustmentListener
adjustment-listener-a
a
,
AdjustmentListener
adjustment-listener-b
b
)

Adds adjustment-listener-a with adjustment-listener-b and returns the resulting multicast listener.

public static TextListener

Returns:

the resulting listener
add
(TextListener
text-listener-a
a
,
TextListener
text-listener-b
b
)

Adds text-listener-a with text-listener-b and returns the resulting multicast listener.

public static InputMethodListener

Returns:

the resulting listener
add
(InputMethodListener
input-method-listener-a
a
,
InputMethodListener
input-method-listener-b
b
)

Adds input-method-listener-a with input-method-listener-b and returns the resulting multicast listener.

public static HierarchyListener

Returns:

the resulting listener
add
(HierarchyListener
hierarchy-listener-a
a
,
HierarchyListener
hierarchy-listener-b
b
)

Adds hierarchy-listener-a with hierarchy-listener-b and returns the resulting multicast listener.

public static HierarchyBoundsListener

Returns:

the resulting listener
add
(HierarchyBoundsListener
hierarchy-bounds-listener-a
a
,
HierarchyBoundsListener
hierarchy-bounds-listener-b
b
)

Adds hierarchy-bounds-listener-a with hierarchy-bounds-listener-b and returns the resulting multicast listener.

public static MouseWheelListener

Returns:

the resulting listener
add
(MouseWheelListener
mouse-wheel-listener-a
a
,
MouseWheelListener
mouse-wheel-listener-b
b
)

Adds mouse-wheel-listener-a with mouse-wheel-listener-b and returns the resulting multicast listener.

protected static EventListener

Returns:

the resulting listener
addInternal
(EventListener
event listener-a
a
,
EventListener
event listener-b
b
)

Returns the resulting multicast listener from adding listener-a and listener-b together.

public void
adjustmentValueChanged(AdjustmentEvent
the adjustment event
e
)

Implements java.awt.event.AdjustmentListener.adjustmentValueChanged.

Handles the adjustmentValueChanged event by invoking the adjustmentValueChanged methods on listener-a and listener-b.

public void
ancestorMoved(HierarchyEvent
the item event
e
)

Implements java.awt.event.HierarchyBoundsListener.ancestorMoved.

Handles the ancestorMoved event by invoking the ancestorMoved methods on listener-a and listener-b.

public void
ancestorResized(HierarchyEvent
the item event
e
)

Implements java.awt.event.HierarchyBoundsListener.ancestorResized.

Handles the ancestorResized event by invoking the ancestorResized methods on listener-a and listener-b.

public void
caretPositionChanged(InputMethodEvent
the item event
e
)

Implements java.awt.event.InputMethodListener.caretPositionChanged.

Handles the caretPositionChanged event by invoking the caretPositionChanged methods on listener-a and listener-b.

public void
componentAdded(ContainerEvent
the component event
e
)

Implements java.awt.event.ContainerListener.componentAdded.

Handles the componentAdded container event by invoking the componentAdded methods on listener-a and listener-b.

public void
componentHidden(ComponentEvent
the component event
e
)

Implements java.awt.event.ComponentListener.componentHidden.

Handles the componentHidden event by invoking the componentHidden methods on listener-a and listener-b.

public void
componentMoved(ComponentEvent
the component event
e
)

Implements java.awt.event.ComponentListener.componentMoved.

Handles the componentMoved event by invoking the componentMoved methods on listener-a and listener-b.

public void
componentRemoved(ContainerEvent
the component event
e
)

Implements java.awt.event.ContainerListener.componentRemoved.

Handles the componentRemoved container event by invoking the componentRemoved methods on listener-a and listener-b.

public void
componentResized(ComponentEvent
the component event
e
)

Implements java.awt.event.ComponentListener.componentResized.

Handles the componentResized event by invoking the componentResized methods on listener-a and listener-b.

public void
componentShown(ComponentEvent
the component event
e
)

Implements java.awt.event.ComponentListener.componentShown.

Handles the componentShown event by invoking the componentShown methods on listener-a and listener-b.

public void
focusGained(FocusEvent
the focus event
e
)

Implements java.awt.event.FocusListener.focusGained.

Handles the focusGained event by invoking the focusGained methods on listener-a and listener-b.

public void
focusLost(FocusEvent
the focus event
e
)

Implements java.awt.event.FocusListener.focusLost.

Handles the focusLost event by invoking the focusLost methods on listener-a and listener-b.

private static int
getListenerCount(EventListener l, Class<?> listenerType)

public static <
the listener type
T extends EventListener
>
T[]

Returns:

an array of all objects chained as FooListeners by the specified multicast listener, or an empty array if no such listeners have been chained by the specified multicast listener
getListeners
(EventListener
the specified java.util.EventListener
l
,
Class<T>
the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
listenerType
)

Returns an array of all the objects chained as FooListeners by the specified java.util.EventListener.

public void
hierarchyChanged(HierarchyEvent
the item event
e
)

Implements java.awt.event.HierarchyListener.hierarchyChanged.

Handles the hierarchyChanged event by invoking the hierarchyChanged methods on listener-a and listener-b.

public void
inputMethodTextChanged(InputMethodEvent
the item event
e
)

Implements java.awt.event.InputMethodListener.inputMethodTextChanged.

Handles the inputMethodTextChanged event by invoking the inputMethodTextChanged methods on listener-a and listener-b.

public void
itemStateChanged(ItemEvent
the item event
e
)

Implements java.awt.event.ItemListener.itemStateChanged.

Handles the itemStateChanged event by invoking the itemStateChanged methods on listener-a and listener-b.

public void
keyPressed(KeyEvent
the key event
e
)

Implements java.awt.event.KeyListener.keyPressed.

Handles the keyPressed event by invoking the keyPressed methods on listener-a and listener-b.

public void
keyReleased(KeyEvent
the key event
e
)

Implements java.awt.event.KeyListener.keyReleased.

Handles the keyReleased event by invoking the keyReleased methods on listener-a and listener-b.

public void
keyTyped(KeyEvent
the key event
e
)

Implements java.awt.event.KeyListener.keyTyped.

Handles the keyTyped event by invoking the keyTyped methods on listener-a and listener-b.

public void
mouseClicked(MouseEvent
the mouse event
e
)

Implements java.awt.event.MouseListener.mouseClicked.

Handles the mouseClicked event by invoking the mouseClicked methods on listener-a and listener-b.

public void
mouseDragged(MouseEvent
the mouse event
e
)

Implements java.awt.event.MouseMotionListener.mouseDragged.

Handles the mouseDragged event by invoking the mouseDragged methods on listener-a and listener-b.

public void
mouseEntered(MouseEvent
the mouse event
e
)

Implements java.awt.event.MouseListener.mouseEntered.

Handles the mouseEntered event by invoking the mouseEntered methods on listener-a and listener-b.

public void
mouseExited(MouseEvent
the mouse event
e
)

Implements java.awt.event.MouseListener.mouseExited.

Handles the mouseExited event by invoking the mouseExited methods on listener-a and listener-b.

public void
mouseMoved(MouseEvent
the mouse event
e
)

Implements java.awt.event.MouseMotionListener.mouseMoved.

Handles the mouseMoved event by invoking the mouseMoved methods on listener-a and listener-b.

public void
mousePressed(MouseEvent
the mouse event
e
)

Implements java.awt.event.MouseListener.mousePressed.

Handles the mousePressed event by invoking the mousePressed methods on listener-a and listener-b.

public void
mouseReleased(MouseEvent
the mouse event
e
)

Implements java.awt.event.MouseListener.mouseReleased.

Handles the mouseReleased event by invoking the mouseReleased methods on listener-a and listener-b.

public void
mouseWheelMoved(MouseWheelEvent
the mouse event
e
)

Implements java.awt.event.MouseWheelListener.mouseWheelMoved.

Handles the mouseWheelMoved event by invoking the mouseWheelMoved methods on listener-a and listener-b.

private static boolean
needsRebalance(AWTEventMulticaster l)

Return true if the argument represents a binary tree that needs to be rebalanced.

private static int
private static EventListener

Returns:

a balanced tree. If index0 equals index1 then this returns an EventListener from the array provided. Otherwise this returns an AWTEventMulticaster.
rebalance
(EventListener[]
the array of the EventListeners to consult
array
,
int
the lowest index (inclusive) that the return value must include
index0
,
int
the highest index (inclusive) that the return value must include.
index1
)

Recursively create a balanced tree that includes a given range of EventListeners.

protected EventListener

Returns:

resulting listener
remove
(EventListener
the listener to be removed
oldl
)

Removes a listener from this multicaster.

public static ComponentListener

Returns:

the resulting listener
remove
(ComponentListener
component-listener-l
l
,
ComponentListener
the component-listener being removed
oldl
)

Removes the old component-listener from component-listener-l and returns the resulting multicast listener.

public static ContainerListener

Returns:

the resulting listener
remove
(ContainerListener
container-listener-l
l
,
ContainerListener
the container-listener being removed
oldl
)

Removes the old container-listener from container-listener-l and returns the resulting multicast listener.

public static FocusListener

Returns:

the resulting listener
remove
(FocusListener
focus-listener-l
l
,
FocusListener
the focus-listener being removed
oldl
)

Removes the old focus-listener from focus-listener-l and returns the resulting multicast listener.

public static KeyListener

Returns:

the resulting listener
remove
(KeyListener
key-listener-l
l
,
KeyListener
the key-listener being removed
oldl
)

Removes the old key-listener from key-listener-l and returns the resulting multicast listener.

public static MouseListener

Returns:

the resulting listener
remove
(MouseListener
mouse-listener-l
l
,
MouseListener
the mouse-listener being removed
oldl
)

Removes the old mouse-listener from mouse-listener-l and returns the resulting multicast listener.

public static MouseMotionListener

Returns:

the resulting listener
remove
(MouseMotionListener
mouse-motion-listener-l
l
,
MouseMotionListener
the mouse-motion-listener being removed
oldl
)

Removes the old mouse-motion-listener from mouse-motion-listener-l and returns the resulting multicast listener.

public static WindowListener

Returns:

the resulting listener
remove
(WindowListener
window-listener-l
l
,
WindowListener
the window-listener being removed
oldl
)

Removes the old window-listener from window-listener-l and returns the resulting multicast listener.

public static WindowStateListener

Returns:

the resulting listener
remove
(WindowStateListener
window-state-listener-l
l
,
WindowStateListener
the window-state-listener being removed
oldl
)

Removes the old window-state-listener from window-state-listener-l and returns the resulting multicast listener.

public static WindowFocusListener

Returns:

the resulting listener
remove
(WindowFocusListener
window-focus-listener-l
l
,
WindowFocusListener
the window-focus-listener being removed
oldl
)

Removes the old window-focus-listener from window-focus-listener-l and returns the resulting multicast listener.

public static ActionListener

Returns:

the resulting listener
remove
(ActionListener
action-listener-l
l
,
ActionListener
the action-listener being removed
oldl
)

Removes the old action-listener from action-listener-l and returns the resulting multicast listener.

public static ItemListener

Returns:

the resulting listener
remove
(ItemListener
item-listener-l
l
,
ItemListener
the item-listener being removed
oldl
)

Removes the old item-listener from item-listener-l and returns the resulting multicast listener.

public static AdjustmentListener

Returns:

the resulting listener
remove
(AdjustmentListener
adjustment-listener-l
l
,
AdjustmentListener
the adjustment-listener being removed
oldl
)

Removes the old adjustment-listener from adjustment-listener-l and returns the resulting multicast listener.

public static TextListener

Returns:

the resulting listener
remove
(TextListener
text-listener-l
l
,
TextListener
the text-listener being removed
oldl
)

Removes the old text-listener from text-listener-l and returns the resulting multicast listener.

public static InputMethodListener

Returns:

the resulting listener
remove
(InputMethodListener
input-method-listener-l
l
,
InputMethodListener
the input-method-listener being removed
oldl
)

Removes the old input-method-listener from input-method-listener-l and returns the resulting multicast listener.

public static HierarchyListener

Returns:

the resulting listener
remove
(HierarchyListener
hierarchy-listener-l
l
,
HierarchyListener
the hierarchy-listener being removed
oldl
)

Removes the old hierarchy-listener from hierarchy-listener-l and returns the resulting multicast listener.

public static HierarchyBoundsListener

Returns:

the resulting listener
remove
(HierarchyBoundsListener
hierarchy-bounds-listener-l
l
,
HierarchyBoundsListener
the hierarchy-bounds-listener being removed
oldl
)

Removes the old hierarchy-bounds-listener from hierarchy-bounds-listener-l and returns the resulting multicast listener.

public static MouseWheelListener

Returns:

the resulting listener
remove
(MouseWheelListener
mouse-wheel-listener-l
l
,
MouseWheelListener
the mouse-wheel-listener being removed
oldl
)

Removes the old mouse-wheel-listener from mouse-wheel-listener-l and returns the resulting multicast listener.

protected static EventListener

Returns:

the resulting listener
removeInternal
(EventListener
the listener being removed from
l
,
EventListener
the listener being removed
oldl
)

Returns the resulting multicast listener after removing the old listener from listener-l.

protected static void
save(ObjectOutputStream
the stream to save to
s
,
String
a prefix stream to put before each serializable listener
k
,
EventListener
the listener chain to save
l
)

Saves a Serializable listener chain to a serialization stream.

protected void
saveInternal(ObjectOutputStream
the stream to save to
s
,
String
a prefix stream to put before each serializable listener
k
)

Serialization support.

public void
textValueChanged(TextEvent e)

Implements java.awt.event.TextListener.textValueChanged.

Invoked when the value of the text has changed.

public void
windowActivated(WindowEvent
the window event
e
)

Implements java.awt.event.WindowListener.windowActivated.

Handles the windowActivated event by invoking the windowActivated methods on listener-a and listener-b.

public void
windowClosed(WindowEvent
the window event
e
)

Implements java.awt.event.WindowListener.windowClosed.

Handles the windowClosed event by invoking the windowClosed methods on listener-a and listener-b.

public void
windowClosing(WindowEvent
the window event
e
)

Implements java.awt.event.WindowListener.windowClosing.

Handles the windowClosing event by invoking the windowClosing methods on listener-a and listener-b.

public void
windowDeactivated(WindowEvent
the window event
e
)

Implements java.awt.event.WindowListener.windowDeactivated.

Handles the windowDeactivated event by invoking the windowDeactivated methods on listener-a and listener-b.

public void
windowDeiconified(WindowEvent
the window event
e
)

Implements java.awt.event.WindowListener.windowDeiconified.

Handles the windowDeiconified event by invoking the windowDeiconified methods on listener-a and listener-b.

public void
windowGainedFocus(WindowEvent
the window event
e
)

Implements java.awt.event.WindowFocusListener.windowGainedFocus.

Handles the windowGainedFocus event by invoking the windowGainedFocus methods on listener-a and listener-b.

public void
windowIconified(WindowEvent
the window event
e
)

Implements java.awt.event.WindowListener.windowIconified.

Handles the windowIconified event by invoking the windowIconified methods on listener-a and listener-b.

public void
windowLostFocus(WindowEvent
the window event
e
)

Implements java.awt.event.WindowFocusListener.windowLostFocus.

Handles the windowLostFocus event by invoking the windowLostFocus methods on listener-a and listener-b.

public void
windowOpened(WindowEvent
the window event
e
)

Implements java.awt.event.WindowListener.windowOpened.

Handles the windowOpened event by invoking the windowOpened methods on listener-a and listener-b.

public void
windowStateChanged(WindowEvent
the window event
e
)

Implements java.awt.event.WindowStateListener.windowStateChanged.

Handles the windowStateChanged event by invoking the windowStateChanged methods on listener-a and listener-b.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait