| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public class AWTEventMulticaster extends Object implements ComponentListener, ContainerListener, FocusListener, KeyListener, MouseListener, MouseMotionListener, WindowListener, WindowFocusListener, WindowStateListener, ActionListener, ItemListener, AdjustmentListener, TextListener, InputMethodListener, HierarchyListener, HierarchyBoundsListener, MouseWheelListener
{@code AWTEventMulticaster} implements efficient and thread-safe multi-cast event dispatching for the AWT events defined in the {@code 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 {@code
add} and {@code remove} methods is the field maintaining the
listeners. In addition you must assign the result of the {@code add}
and {@code remove} methods to the field maintaining the listeners.
{@code AWTEventMulticaster} is implemented as a pair of {@code EventListeners} that are set at construction time. {@code AWTEventMulticaster} is immutable. The {@code add} and {@code remove} methods do not alter {@code AWTEventMulticaster} in anyway. If necessary, a new {@code 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 {@code add} methods allow {@code null} arguments. If the first argument is {@code null}, the second argument is returned. If the first argument is not {@code null} and the second argument is {@code null}, the first argument is returned. If both arguments are {@code non-null}, a new {@code AWTEventMulticaster} is created using the two arguments and returned.
For the {@code remove} methods that take two arguments, the following is returned:
Swing makes use of {@link javax.swing.event.EventListenerList EventListenerList} for similar logic. Refer to it for details.
Field Summary | |
---|---|
protected EventListener |
a
|
protected EventListener |
b
|
Constructor Summary | |
---|---|
protected |
Creates an event multicaster instance which chains listener-a with listener-b. |
Method Summary | |
---|---|
void |
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 |
Adds adjustment-listener-a with adjustment-listener-b and returns the resulting multicast listener. |
static ComponentListener |
Adds component-listener-a with component-listener-b and returns the resulting multicast listener. |
static ContainerListener |
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 |
Adds hierarchy-bounds-listener-a with hierarchy-bounds-listener-b and returns the resulting multicast listener. |
static HierarchyListener |
Adds hierarchy-listener-a with hierarchy-listener-b and returns the resulting multicast listener. |
static InputMethodListener |
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 |
Adds mouse-motion-listener-a with mouse-motion-listener-b and returns the resulting multicast listener. |
static MouseWheelListener |
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 |
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 |
Adds window-state-listener-a with window-state-listener-b and returns the resulting multicast listener. |
protected static EventListener |
Returns the resulting multicast listener from adding listener-a and listener-b together. |
void |
Handles the adjustmentValueChanged event by invoking the adjustmentValueChanged methods on listener-a and listener-b. |
void |
Handles the ancestorMoved event by invoking the ancestorMoved methods on listener-a and listener-b. |
void |
Handles the ancestorResized event by invoking the ancestorResized methods on listener-a and listener-b. |
void |
Handles the caretPositionChanged event by invoking the caretPositionChanged methods on listener-a and listener-b. |
void |
Handles the componentAdded container event by invoking the componentAdded methods on listener-a and listener-b. |
void |
Handles the componentHidden event by invoking the componentHidden methods on listener-a and listener-b. |
void |
Handles the componentMoved event by invoking the componentMoved methods on listener-a and listener-b. |
void |
Handles the componentRemoved container event by invoking the componentRemoved methods on listener-a and listener-b. |
void |
Handles the componentResized event by invoking the componentResized methods on listener-a and listener-b. |
void |
Handles the componentShown event by invoking the componentShown methods on listener-a and listener-b. |
void |
Handles the focusGained event by invoking the focusGained methods on listener-a and listener-b. |
void |
Handles the focusLost event by invoking the focusLost methods on listener-a and listener-b. |
static EventListener[] |
getListeners(EventListener l, Class listenerType) Returns an array of all the objects chained as FooListener s by the specified
java.util.EventListener .
|
void |
Handles the hierarchyChanged event by invoking the hierarchyChanged methods on listener-a and listener-b. |
void |
Handles the inputMethodTextChanged event by invoking the inputMethodTextChanged methods on listener-a and listener-b. |
void |
Handles the itemStateChanged event by invoking the itemStateChanged methods on listener-a and listener-b. |
void |
Handles the keyPressed event by invoking the keyPressed methods on listener-a and listener-b. |
void |
Handles the keyReleased event by invoking the keyReleased methods on listener-a and listener-b. |
void |
Handles the keyTyped event by invoking the keyTyped methods on listener-a and listener-b. |
void |
Handles the mouseClicked event by invoking the mouseClicked methods on listener-a and listener-b. |
void |
Handles the mouseDragged event by invoking the mouseDragged methods on listener-a and listener-b. |
void |
Handles the mouseEntered event by invoking the mouseEntered methods on listener-a and listener-b. |
void |
Handles the mouseExited event by invoking the mouseExited methods on listener-a and listener-b. |
void |
Handles the mouseMoved event by invoking the mouseMoved methods on listener-a and listener-b. |
void |
Handles the mousePressed event by invoking the mousePressed methods on listener-a and listener-b. |
void |
Handles the mouseReleased event by invoking the mouseReleased methods on listener-a and listener-b. |
void |
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 oldl) 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 |
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 |
|
void |
|
void |
Handles the windowActivated event by invoking the windowActivated methods on listener-a and listener-b. |
void |
Handles the windowClosed event by invoking the windowClosed methods on listener-a and listener-b. |
void |
Handles the windowClosing event by invoking the windowClosing methods on listener-a and listener-b. |
void |
Handles the windowDeactivated event by invoking the windowDeactivated methods on listener-a and listener-b. |
void |
Handles the windowDeiconfied event by invoking the windowDeiconified methods on listener-a and listener-b. |
void |
Handles the windowGainedFocus event by invoking the windowGainedFocus methods on listener-a and listener-b. |
void |
Handles the windowIconified event by invoking the windowIconified methods on listener-a and listener-b. |
void |
Handles the windowLostFocus event by invoking the windowLostFocus methods on listener-a and listener-b. |
void |
Handles the windowOpened event by invoking the windowOpened methods on listener-a and listener-b. |
void |
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)
a
and b
should not be null
, though implementations may vary in
choosing whether or not to throw NullPointerException
in that case.
a
- listener-ab
- listener-bMethod Detail |
---|
public void actionPerformed(ActionEvent e)
e
- the action eventpublic static ActionListener add(ActionListener a, ActionListener b)
a
- action-listener-ab
- action-listener-bpublic static AdjustmentListener add(AdjustmentListener a, AdjustmentListener b)
a
- adjustment-listener-ab
- adjustment-listener-bpublic static ComponentListener add(ComponentListener a, ComponentListener b)
a
- component-listener-ab
- component-listener-bpublic static ContainerListener add(ContainerListener a, ContainerListener b)
a
- container-listener-ab
- container-listener-bpublic static FocusListener add(FocusListener a, FocusListener b)
a
- focus-listener-ab
- focus-listener-bpublic static HierarchyBoundsListener add(HierarchyBoundsListener a, HierarchyBoundsListener b)
a
- hierarchy-bounds-listener-ab
- hierarchy-bounds-listener-bpublic static HierarchyListener add(HierarchyListener a, HierarchyListener b)
a
- hierarchy-listener-ab
- hierarchy-listener-bpublic static InputMethodListener add(InputMethodListener a, InputMethodListener b)
a
- input-method-listener-ab
- input-method-listener-bpublic static ItemListener add(ItemListener a, ItemListener b)
a
- item-listener-ab
- item-listener-bpublic static KeyListener add(KeyListener a, KeyListener b)
a
- key-listener-ab
- key-listener-bpublic static MouseListener add(MouseListener a, MouseListener b)
a
- mouse-listener-ab
- mouse-listener-bpublic static MouseMotionListener add(MouseMotionListener a, MouseMotionListener b)
a
- mouse-motion-listener-ab
- mouse-motion-listener-bpublic static MouseWheelListener add(MouseWheelListener a, MouseWheelListener b)
a
- mouse-wheel-listener-ab
- mouse-wheel-listener-bpublic static TextListener add(TextListener a, TextListener b)
a
b
public static WindowFocusListener add(WindowFocusListener a, WindowFocusListener b)
a
- window-focus-listener-ab
- window-focus-listener-bpublic static WindowListener add(WindowListener a, WindowListener b)
a
- window-listener-ab
- window-listener-bpublic static WindowStateListener add(WindowStateListener a, WindowStateListener b)
a
- window-state-listener-ab
- window-state-listener-bprotected static EventListener addInternal(EventListener a, EventListener b)
a
- event listener-ab
- event listener-bpublic void adjustmentValueChanged(AdjustmentEvent e)
e
- the adjustment eventpublic void ancestorMoved(HierarchyEvent e)
e
- the item eventpublic void ancestorResized(HierarchyEvent e)
e
- the item eventpublic void caretPositionChanged(InputMethodEvent e)
e
- the item eventpublic void componentAdded(ContainerEvent e)
e
- the component eventpublic void componentHidden(ComponentEvent e)
e
- the component eventpublic void componentMoved(ComponentEvent e)
e
- the component eventpublic void componentRemoved(ContainerEvent e)
e
- the component eventpublic void componentResized(ComponentEvent e)
e
- the component eventpublic void componentShown(ComponentEvent e)
e
- the component eventpublic void focusGained(FocusEvent e)
e
- the focus eventpublic void focusLost(FocusEvent e)
e
- the focus eventpublic static EventListener[] getListeners(EventListener l, Class listenerType)
FooListener
s by the specified
java.util.EventListener
.
FooListener
s are chained by the
AWTEventMulticaster
using the
addFooListener
method.
If a null
listener is specified, this method returns an
empty array. If the specified listener is not an instance of
AWTEventMulticaster
, this method returns an array which
contains only the specified listener. If no such listeners are chanined,
this method returns an empty array.
l
- the specified java.util.EventListener
listenerType
- the type of listeners requested; this parameter
should specify an interface that descends from
java.util.EventListener
FooListener
s by the specified multicast
listener, or an empty array if no such listeners have been
chained by the specified multicast listenerpublic void hierarchyChanged(HierarchyEvent e)
e
- the item eventpublic void inputMethodTextChanged(InputMethodEvent e)
e
- the item eventpublic void itemStateChanged(ItemEvent e)
e
- the item eventpublic void keyPressed(KeyEvent e)
e
- the key eventpublic void keyReleased(KeyEvent e)
e
- the key eventpublic void keyTyped(KeyEvent e)
e
- the key eventpublic void mouseClicked(MouseEvent e)
e
- the mouse eventpublic void mouseDragged(MouseEvent e)
e
- the mouse eventpublic void mouseEntered(MouseEvent e)
e
- the mouse eventpublic void mouseExited(MouseEvent e)
e
- the mouse eventpublic void mouseMoved(MouseEvent e)
e
- the mouse eventpublic void mousePressed(MouseEvent e)
e
- the mouse eventpublic void mouseReleased(MouseEvent e)
e
- the mouse eventpublic void mouseWheelMoved(MouseWheelEvent e)
e
- the mouse eventpublic static ActionListener remove(ActionListener l, ActionListener oldl)
l
- action-listener-loldl
- the action-listener being removedpublic static AdjustmentListener remove(AdjustmentListener l, AdjustmentListener oldl)
l
- adjustment-listener-loldl
- the adjustment-listener being removedpublic static ComponentListener remove(ComponentListener l, ComponentListener oldl)
l
- component-listener-loldl
- the component-listener being removedpublic static ContainerListener remove(ContainerListener l, ContainerListener oldl)
l
- container-listener-loldl
- the container-listener being removedprotected EventListener remove(EventListener oldl)
The returned multicaster contains all the listeners in this multicaster with the exception of all occurrences of {@code oldl}. If the resulting multicaster contains only one regular listener the regular listener may be returned. If the resulting multicaster is empty, then {@code null} may be returned instead.
No exception is thrown if {@code oldl} is {@code null}.
oldl
- the listener to be removedpublic static FocusListener remove(FocusListener l, FocusListener oldl)
l
- focus-listener-loldl
- the focus-listener being removedpublic static HierarchyBoundsListener remove(HierarchyBoundsListener l, HierarchyBoundsListener oldl)
l
- hierarchy-bounds-listener-loldl
- the hierarchy-bounds-listener being removedpublic static HierarchyListener remove(HierarchyListener l, HierarchyListener oldl)
l
- hierarchy-listener-loldl
- the hierarchy-listener being removedpublic static InputMethodListener remove(InputMethodListener l, InputMethodListener oldl)
l
- input-method-listener-loldl
- the input-method-listener being removedpublic static ItemListener remove(ItemListener l, ItemListener oldl)
l
- item-listener-loldl
- the item-listener being removedpublic static KeyListener remove(KeyListener l, KeyListener oldl)
l
- key-listener-loldl
- the key-listener being removedpublic static MouseListener remove(MouseListener l, MouseListener oldl)
l
- mouse-listener-loldl
- the mouse-listener being removedpublic static MouseMotionListener remove(MouseMotionListener l, MouseMotionListener oldl)
l
- mouse-motion-listener-loldl
- the mouse-motion-listener being removedpublic static MouseWheelListener remove(MouseWheelListener l, MouseWheelListener oldl)
l
- mouse-wheel-listener-loldl
- the mouse-wheel-listener being removedpublic static TextListener remove(TextListener l, TextListener oldl)
l
oldl
public static WindowFocusListener remove(WindowFocusListener l, WindowFocusListener oldl)
l
- window-focus-listener-loldl
- the window-focus-listener being removedpublic static WindowListener remove(WindowListener l, WindowListener oldl)
l
- window-listener-loldl
- the window-listener being removedpublic static WindowStateListener remove(WindowStateListener l, WindowStateListener oldl)
l
- window-state-listener-loldl
- the window-state-listener being removedprotected static EventListener removeInternal(EventListener l, EventListener oldl)
l
- the listener being removed fromoldl
- the listener being removedprotected static void save(ObjectOutputStream s, String k, EventListener l) throws IOException
s
k
l
IOException
protected void saveInternal(ObjectOutputStream s, String k) throws IOException
s
k
IOException
public void textValueChanged(TextEvent e)
e
public void windowActivated(WindowEvent e)
e
- the window eventpublic void windowClosed(WindowEvent e)
e
- the window eventpublic void windowClosing(WindowEvent e)
e
- the window eventpublic void windowDeactivated(WindowEvent e)
e
- the window eventpublic void windowDeiconified(WindowEvent e)
e
- the window eventpublic void windowGainedFocus(WindowEvent e)
e
- the window eventpublic void windowIconified(WindowEvent e)
e
- the window eventpublic void windowLostFocus(WindowEvent e)
e
- the window eventpublic void windowOpened(WindowEvent e)
e
- the window eventpublic void windowStateChanged(WindowEvent e)
e
- the window event
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |