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:
null, if the first argument is null, or
the arguments are equal, by way of ==.
AWTEventMulticaster.
remove(EventListener) on the
first argument, supplying the second argument to the
remove(EventListener) method.
Swing makes use of
EventListenerList for
similar logic. Refer to it for details.
javax.swing.event.EventListenerList
| Modifier and Type | Field 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 |
| Access | Constructor and Description |
|---|---|
| protected | AWTEventMulticaster(EventListener
listener-a a, EventListener listener-b b)Creates an event multicaster instance which chains listener-a with listener-b. |
| Modifier and Type | Method and Description |
|---|---|
| public void | actionPerformed(ActionEvent
the action event e)Implements java. Handles the actionPerformed event by invoking the actionPerformed methods on listener-a and listener-b. |
| public static ComponentListener | Returns: the resulting listenercomponent-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 listenercontainer-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 listenerfocus-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 listenerkey-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 listenermouse-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 listenermouse-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 listenerwindow-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 listenerwindow-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 listenerwindow-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 listeneraction-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 listeneritem-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 listeneradjustment-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 listenertext-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 listenerinput-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 listenerhierarchy-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 listenerhierarchy-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 listenermouse-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 listenerevent 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. Handles the focusLost event by invoking the focusLost methods on listener-a and listener-b. |
| private static int | |
| public static < the listener type T extends EventListener> T[] | Returns: an array of all objects chained asFooListeners by the specified multicast
listener, or an empty array if no such listeners have been
chained by the specified multicast listenerthe specified l, Class<T> java.util.EventListenerthe type of listeners requested; this parameter
should specify an interface that descends from
listenerType)java.util.EventListenerReturns an array of all the objects chained as
|
| public void | hierarchyChanged(HierarchyEvent
the item event e)Implements java. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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.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 listenerthe listener to be removed oldl)Removes a listener from this multicaster. |
| public static ComponentListener | Returns: the resulting listenercomponent-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 listenercontainer-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 listenerfocus-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 listenerkey-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 listenermouse-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 listenermouse-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 listenerwindow-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 listenerwindow-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 listenerwindow-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 listeneraction-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 listeneritem-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 listeneradjustment-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 listenertext-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 listenerinput-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 listenerhierarchy-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 listenerhierarchy-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 listenermouse-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 listenerthe 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. Invoked when the value of the text has changed. |
| public void | windowActivated(WindowEvent
the window event e)Implements java. 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. 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. 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. 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. 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. 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. 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. 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. 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. Handles the windowStateChanged event by invoking the windowStateChanged methods on listener-a and listener-b. |