is new.
java.lang.Objectjava.awt.AWTEventMulticaster
public class AWTEventMulticaster
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:
A class which implements efficient and thread-safe multi-cast event dispatching for the AWT events defined in the java.awt.event package. This class will manage an immutable structure consisting of a chain of event listeners and will dispatch events to those listeners. Because the structure is immutable, it is safe to use this API to add/remove listeners during the process of an event dispatch operation. However, event listeners added during the process of an event dispatch operation will not be notified of the event currently being dispatched. An example of how this class could be used to implement a new component which fires "action" events:
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 ==.
the first argument, if the first argument is not an instance of AWTEventMulticaster.
result of invoking 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.
See Also:
EventListenerList
| Field Summary | |
|---|---|
| protected EventListener |
a
|
| protected EventListener |
b
|
| Constructor Summary | |
|---|---|
| protected |
AWTEventMulticaster
(
EventListener
a,
EventListener
b) Creates an event multicaster instance which chains listener-a with listener-b. |
| Method Summary | ||
|---|---|---|
| void |
actionPerformed
(
ActionEvent
e) Handles the actionPerformed event by invoking the actionPerformed methods on listener-a and listener-b. |
|
| static ActionListener |
add
(
ActionListener
a,
ActionListener
b) Adds action-listener-a with action-listener-b and returns the resulting multicast listener. |
|
| static AdjustmentListener |
add
(
AdjustmentListener
a,
AdjustmentListener
b) Adds adjustment-listener-a with adjustment-listener-b and returns the resulting multicast listener. |
|
| static ComponentListener |
add
(
ComponentListener
a,
ComponentListener
b) Adds component-listener-a with component-listener-b and returns the resulting multicast listener. |
|
| static ContainerListener |
add
(
ContainerListener
a,
ContainerListener
b) Adds container-listener-a with container-listener-b and returns the resulting multicast listener. |
|
| static FocusListener |
add
(
FocusListener
a,
FocusListener
b) Adds focus-listener-a with focus-listener-b and returns the resulting multicast listener. |
|
| static HierarchyBoundsListener |
add
(
HierarchyBoundsListener
a,
HierarchyBoundsListener
b) Adds hierarchy-bounds-listener-a with hierarchy-bounds-listener-b and returns the resulting multicast listener. |
|
| static HierarchyListener |
add
(
HierarchyListener
a,
HierarchyListener
b) Adds hierarchy-listener-a with hierarchy-listener-b and returns the resulting multicast listener. |
|
| static InputMethodListener |
add
(
InputMethodListener
a,
InputMethodListener
b) Adds input-method-listener-a with input-method-listener-b and returns the resulting multicast listener. |
|
| static ItemListener |
add
(
ItemListener
a,
ItemListener
b) Adds item-listener-a with item-listener-b and returns the resulting multicast listener. |
|
| static KeyListener |
add
(
KeyListener
a,
KeyListener
b) Adds key-listener-a with key-listener-b and returns the resulting multicast listener. |
|
| static MouseListener |
add
(
MouseListener
a,
MouseListener
b) Adds mouse-listener-a with mouse-listener-b and returns the resulting multicast listener. |
|
| static MouseMotionListener |
add
(
MouseMotionListener
a,
MouseMotionListener
b) Adds mouse-motion-listener-a with mouse-motion-listener-b and returns the resulting multicast listener. |
|
| static MouseWheelListener |
add
(
MouseWheelListener
a,
MouseWheelListener
b) Adds mouse-wheel-listener-a with mouse-wheel-listener-b and returns the resulting multicast listener. |
|
| static TextListener |
add
(
TextListener
a,
TextListener
b) |
|
| static WindowFocusListener |
add
(
WindowFocusListener
a,
WindowFocusListener
b) Adds window-focus-listener-a with window-focus-listener-b and returns the resulting multicast listener. |
|
| static WindowListener |
add
(
WindowListener
a,
WindowListener
b) Adds window-listener-a with window-listener-b and returns the resulting multicast listener. |
|
| static WindowStateListener |
add
(
WindowStateListener
a,
WindowStateListener
b) Adds window-state-listener-a with window-state-listener-b and returns the resulting multicast listener. |
|
| protected static EventListener |
addInternal
(
EventListener
a,
EventListener
b) Returns the resulting multicast listener from adding listener-a and listener-b together. |
|
| void |
adjustmentValueChanged
(
AdjustmentEvent
e) Handles the adjustmentValueChanged event by invoking the adjustmentValueChanged methods on listener-a and listener-b. |
|
| void |
ancestorMoved
(
HierarchyEvent
e) Handles the ancestorMoved event by invoking the ancestorMoved methods on listener-a and listener-b. |
|
| void |
ancestorResized
(
HierarchyEvent
e) Handles the ancestorResized event by invoking the ancestorResized methods on listener-a and listener-b. |
|
| void |
caretPositionChanged
(
InputMethodEvent
e) Handles the caretPositionChanged event by invoking the caretPositionChanged methods on listener-a and listener-b. |
|
| void |
componentAdded
(
ContainerEvent
e) Handles the componentAdded container event by invoking the componentAdded methods on listener-a and listener-b. |
|
| void |
componentHidden
(
ComponentEvent
e) Handles the componentHidden event by invoking the componentHidden methods on listener-a and listener-b. |
|
| void |
componentMoved
(
ComponentEvent
e) Handles the componentMoved event by invoking the componentMoved methods on listener-a and listener-b. |
|
| void |
componentRemoved
(
ContainerEvent
e) Handles the componentRemoved container event by invoking the componentRemoved methods on listener-a and listener-b. |
|
| void |
componentResized
(
ComponentEvent
e) Handles the componentResized event by invoking the componentResized methods on listener-a and listener-b. |
|
| void |
componentShown
(
ComponentEvent
e) Handles the componentShown event by invoking the componentShown methods on listener-a and listener-b. |
|
| void |
focusGained
(
FocusEvent
e) Handles the focusGained event by invoking the focusGained methods on listener-a and listener-b. |
|
| void |
focusLost
(
FocusEvent
e) Handles the focusLost event by invoking the focusLost methods on listener-a and listener-b. |
|
static
|
getListeners
(
EventListener
l,
Class
<T> listenerType) Returns an array of all the objects chained as FooListeners by the specified java.util.EventListener. |
|
| void |
hierarchyChanged
(
HierarchyEvent
e) Handles the hierarchyChanged event by invoking the hierarchyChanged methods on listener-a and listener-b. |
|
| void |
inputMethodTextChanged
(
InputMethodEvent
e) Handles the inputMethodTextChanged event by invoking the inputMethodTextChanged methods on listener-a and listener-b. |
|
| void |
itemStateChanged
(
ItemEvent
e) Handles the itemStateChanged event by invoking the itemStateChanged methods on listener-a and listener-b. |
|
| void |
keyPressed
(
KeyEvent
e) Handles the keyPressed event by invoking the keyPressed methods on listener-a and listener-b. |
|
| void |
keyReleased
(
KeyEvent
e) Handles the keyReleased event by invoking the keyReleased methods on listener-a and listener-b. |
|
| void |
keyTyped
(
KeyEvent
e) Handles the keyTyped event by invoking the keyTyped methods on listener-a and listener-b. |
|
| void |
mouseClicked
(
MouseEvent
e) Handles the mouseClicked event by invoking the mouseClicked methods on listener-a and listener-b. |
|
| void |
mouseDragged
(
MouseEvent
e) Handles the mouseDragged event by invoking the mouseDragged methods on listener-a and listener-b. |
|
| void |
mouseEntered
(
MouseEvent
e) Handles the mouseEntered event by invoking the mouseEntered methods on listener-a and listener-b. |
|
| void |
mouseExited
(
MouseEvent
e) Handles the mouseExited event by invoking the mouseExited methods on listener-a and listener-b. |
|
| void |
mouseMoved
(
MouseEvent
e) Handles the mouseMoved event by invoking the mouseMoved methods on listener-a and listener-b. |
|
| void |
mousePressed
(
MouseEvent
e) Handles the mousePressed event by invoking the mousePressed methods on listener-a and listener-b. |
|
| void |
mouseReleased
(
MouseEvent
e) Handles the mouseReleased event by invoking the mouseReleased methods on listener-a and listener-b. |
|
| void |
mouseWheelMoved
(
MouseWheelEvent
e) Handles the mouseWheelMoved event by invoking the mouseWheelMoved methods on listener-a and listener-b. |
|
| static ActionListener |
remove
(
ActionListener
l,
ActionListener
oldl) Removes the old action-listener from action-listener-l and returns the resulting multicast listener. |
|
| static AdjustmentListener |
remove
(
AdjustmentListener
l,
AdjustmentListener
oldl) Removes the old adjustment-listener from adjustment-listener-l and returns the resulting multicast listener. |
|
| static ComponentListener |
remove
(
ComponentListener
l,
ComponentListener
oldl) Removes the old component-listener from component-listener-l and returns the resulting multicast listener. |
|
| static ContainerListener |
remove
(
ContainerListener
l,
ContainerListener
oldl) Removes the old container-listener from container-listener-l and returns the resulting multicast listener. |
|
| protected EventListener |
remove
(
EventListener
Removes a listener from this
multicaster.
|
|
| static FocusListener |
remove
(
FocusListener
l,
FocusListener
oldl) Removes the old focus-listener from focus-listener-l and returns the resulting multicast listener. |
|
| static HierarchyBoundsListener |
remove
(
HierarchyBoundsListener
l,
HierarchyBoundsListener
oldl) Removes the old hierarchy-bounds-listener from hierarchy-bounds-listener-l and returns the resulting multicast listener. |
|
| static HierarchyListener |
remove
(
HierarchyListener
l,
HierarchyListener
oldl) Removes the old hierarchy-listener from hierarchy-listener-l and returns the resulting multicast listener. |
|
| static InputMethodListener |
remove
(
InputMethodListener
l,
InputMethodListener
oldl) Removes the old input-method-listener from input-method-listener-l and returns the resulting multicast listener. |
|
| static ItemListener |
remove
(
ItemListener
l,
ItemListener
oldl) Removes the old item-listener from item-listener-l and returns the resulting multicast listener. |
|
| static KeyListener |
remove
(
KeyListener
l,
KeyListener
oldl) Removes the old key-listener from key-listener-l and returns the resulting multicast listener. |
|
| static MouseListener |
remove
(
MouseListener
l,
MouseListener
oldl) Removes the old mouse-listener from mouse-listener-l and returns the resulting multicast listener. |
|
| static MouseMotionListener |
remove
(
MouseMotionListener
l,
MouseMotionListener
oldl) Removes the old mouse-motion-listener from mouse-motion-listener-l and returns the resulting multicast listener. |
|
| static MouseWheelListener |
remove
(
MouseWheelListener
l,
MouseWheelListener
oldl) Removes the old mouse-wheel-listener from mouse-wheel-listener-l and returns the resulting multicast listener. |
|
| static TextListener |
remove
(
TextListener
l,
TextListener
oldl) |
|
| static WindowFocusListener |
remove
(
WindowFocusListener
l,
WindowFocusListener
oldl) Removes the old window-focus-listener from window-focus-listener-l and returns the resulting multicast listener. |
|
| static WindowListener |
remove
(
WindowListener
l,
WindowListener
oldl) Removes the old window-listener from window-listener-l and returns the resulting multicast listener. |
|
| static WindowStateListener |
remove
(
WindowStateListener
l,
WindowStateListener
oldl) Removes the old window-state-listener from window-state-listener-l and returns the resulting multicast listener. |
|
| protected static EventListener |
removeInternal
(
EventListener
l,
EventListener
oldl) Returns the resulting multicast listener after removing the old listener from listener-l. |
|
| protected static void |
save
(
ObjectOutputStream
s,
String
k,
EventListener
l) |
|
| protected void |
saveInternal
(
ObjectOutputStream
s,
String
k) |
|
| void |
textValueChanged
(
TextEvent
e) Invoked when the value of the text has changed. |
|
| void |
windowActivated
(
WindowEvent
e) Handles the windowActivated event by invoking the windowActivated methods on listener-a and listener-b. |
|
| void |
windowClosed
(
WindowEvent
e) Handles the windowClosed event by invoking the windowClosed methods on listener-a and listener-b. |
|
| void |
windowClosing
(
WindowEvent
e) Handles the windowClosing event by invoking the windowClosing methods on listener-a and listener-b. |
|
| void |
windowDeactivated
(
WindowEvent
e) Handles the windowDeactivated event by invoking the windowDeactivated methods on listener-a and listener-b. |
|
| void |
windowDeiconified
(
WindowEvent
e) Handles the windowDeiconfied event by invoking the windowDeiconified methods on listener-a and listener-b. |
|
| void |
windowGainedFocus
(
WindowEvent
e) Handles the windowGainedFocus event by invoking the windowGainedFocus methods on listener-a and listener-b. |
|
| void |
windowIconified
(
WindowEvent
e) Handles the windowIconified event by invoking the windowIconified methods on listener-a and listener-b. |
|
| void |
windowLostFocus
(
WindowEvent
e) Handles the windowLostFocus event by invoking the windowLostFocus methods on listener-a and listener-b. |
|
| void |
windowOpened
(
WindowEvent
e) Handles the windowOpened event by invoking the windowOpened methods on listener-a and listener-b. |
|
| void |
windowStateChanged
(
WindowEvent
e) Handles the windowStateChanged event by invoking the windowStateChanged methods on listener-a and listener-b. |
|
| Methods inherited from class java.lang. Object |
|---|
| clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait |
| Field Detail |
|---|
protected final EventListener a
protected final EventListener b
| Constructor Detail |
|---|
protected AWTEventMulticaster(EventListener a,
EventListener b)
| Method Detail |
|---|
protected EventListener remove(EventListener oldl)
multicaster.
The returned multicaster contains all the listeners in this multicaster with the exception of all occurrences of oldl. If the resulting multicaster contains only one regular listener the regular listener may be returned. If the resulting multicaster is empty, then null may be returned instead.
No exception is thrown if oldl is null.
Returns:
resulting listener
public void componentResized(ComponentEvent e)
public void componentMoved(ComponentEvent e)
public void componentShown(ComponentEvent e)
public void componentHidden(ComponentEvent e)
public void componentAdded(ContainerEvent e)
public void componentRemoved(ContainerEvent e)
public void focusGained(FocusEvent e)
public void focusLost(FocusEvent e)
public void keyTyped(KeyEvent e)
public void keyPressed(KeyEvent e)
public void keyReleased(KeyEvent e)
public void mouseClicked(MouseEvent e)
public void mousePressed(MouseEvent e)
public void mouseReleased(MouseEvent e)
public void mouseEntered(MouseEvent e)
public void mouseExited(MouseEvent e)
public void mouseDragged(MouseEvent e)
public void mouseMoved(MouseEvent e)
public void windowOpened(WindowEvent e)
public void windowClosing(WindowEvent e)
public void windowClosed(WindowEvent e)
public void windowIconified(WindowEvent e)
public void windowDeiconified(WindowEvent e)
public void windowActivated(WindowEvent e)
public void windowDeactivated(WindowEvent e)
public void windowStateChanged(WindowEvent e)
Since:
1.4
public void windowGainedFocus(WindowEvent e)
Since:
1.4
public void windowLostFocus(WindowEvent e)
Since:
1.4
public void actionPerformed(ActionEvent e)
public void itemStateChanged(ItemEvent e)
public void adjustmentValueChanged(AdjustmentEvent e)
public void textValueChanged(TextEvent e)
public void inputMethodTextChanged(InputMethodEvent e)
public void caretPositionChanged(InputMethodEvent e)
public void hierarchyChanged(HierarchyEvent e)
Since:
1.3
public void ancestorMoved(HierarchyEvent e)
Since:
1.3
public void ancestorResized(HierarchyEvent e)
Since:
1.3
public void mouseWheelMoved(MouseWheelEvent e)
public static ComponentListener add(ComponentListener a,
ComponentListener b)
public static ContainerListener add(ContainerListener a,
ContainerListener b)
public static FocusListener add(FocusListener a,
FocusListener b)
public static KeyListener add(KeyListener a,
KeyListener b)
public static MouseListener add(MouseListener a,
MouseListener b)
public static MouseMotionListener add(MouseMotionListener a,
MouseMotionListener b)
public static WindowListener add(WindowListener a,
WindowListener b)
public static WindowStateListener add(WindowStateListener a,
WindowStateListener b)
Since:
1.4
public static WindowFocusListener add(WindowFocusListener a,
WindowFocusListener b)
Since:
1.4
public static ActionListener add(ActionListener a,
ActionListener b)
public static ItemListener add(ItemListener a,
ItemListener b)
public static AdjustmentListener add(AdjustmentListener a,
AdjustmentListener b)
public static TextListener add(TextListener a,
TextListener b)
public static InputMethodListener add(InputMethodListener a,
InputMethodListener b)
public static HierarchyListener add(HierarchyListener a,
HierarchyListener b)
Since:
1.3
public static HierarchyBoundsListener add(HierarchyBoundsListener a,
HierarchyBoundsListener b)
Since:
1.3
public static MouseWheelListener add(MouseWheelListener a,
MouseWheelListener b)
public static ComponentListener remove(ComponentListener l,
ComponentListener oldl)
public static ContainerListener remove(ContainerListener l,
ContainerListener oldl)
public static FocusListener remove(FocusListener l,
FocusListener oldl)
public static KeyListener remove(KeyListener l,
KeyListener oldl)
public static MouseListener remove(MouseListener l,
MouseListener oldl)
public static MouseMotionListener remove(MouseMotionListener l,
MouseMotionListener oldl)
public static WindowListener remove(WindowListener l,
WindowListener oldl)
public static WindowStateListener remove(WindowStateListener l,
WindowStateListener oldl)
Since:
1.4
public static WindowFocusListener remove(WindowFocusListener l,
WindowFocusListener oldl)
Since:
1.4
public static ActionListener remove(ActionListener l,
ActionListener oldl)
public static ItemListener remove(ItemListener l,
ItemListener oldl)
public static AdjustmentListener remove(AdjustmentListener l,
AdjustmentListener oldl)
public static TextListener remove(TextListener l,
TextListener oldl)
public static InputMethodListener remove(InputMethodListener l,
InputMethodListener oldl)
public static HierarchyListener remove(HierarchyListener l,
HierarchyListener oldl)
Since:
1.3
public static HierarchyBoundsListener remove(HierarchyBoundsListener l,
HierarchyBoundsListener oldl)
Since:
1.3
public static MouseWheelListener remove(MouseWheelListener l,
MouseWheelListener oldl)
protected static EventListener addInternal(EventListener a,
EventListener b)
protected static EventListener removeInternal(EventListener l,
EventListener oldl)
protected void saveInternal(ObjectOutputStream s,
String k)
throws IOException
protected static void save(ObjectOutputStream s,
String k,
EventListener l)
throws IOException
public static <T extends EventListener> T[] getListeners(EventListener l,
Class<T> listenerType)
NullPointerException
- if the specified listenertype parameter is null