|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package com.sun.java.accessibility.util; |
|
|
|
import java.util.*; |
|
import java.awt.*; |
|
import java.awt.event.*; |
|
import javax.accessibility.*; |
|
import javax.swing.*; |
|
import javax.swing.event.*; |
|
import sun.security.util.SecurityConstants.AWT; |
|
|
|
/** |
|
* <P>The {@code AWTEventMonitor} implements a suite of listeners that are |
|
* conditionally installed on every AWT component instance in the Java |
|
* Virtual Machine. The events captured by these listeners are made |
|
* available through a unified set of listeners supported by {@code AWTEventMonitor}. |
|
* With this, all the individual events on each of the AWT component |
|
* instances are funneled into one set of listeners broken down by category |
|
* (see {@link EventID} for the categories). |
|
* <p>This class depends upon {@link EventQueueMonitor}, which provides the base |
|
* level support for capturing the top-level containers as they are created. |
|
*/ |
|
|
|
@jdk.Exported |
|
public class AWTEventMonitor { |
|
|
|
static private boolean runningOnJDK1_4 = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Deprecated |
|
static protected Component componentWithFocus = null; |
|
|
|
static private Component componentWithFocus_private = null; |
|
|
|
// Low-level listeners |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Deprecated |
|
static protected ComponentListener componentListener = null; |
|
|
|
static private ComponentListener componentListener_private = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Deprecated |
|
static protected ContainerListener containerListener = null; |
|
|
|
static private ContainerListener containerListener_private = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Deprecated |
|
static protected FocusListener focusListener = null; |
|
|
|
static private FocusListener focusListener_private = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Deprecated |
|
static protected KeyListener keyListener = null; |
|
|
|
static private KeyListener keyListener_private = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Deprecated |
|
static protected MouseListener mouseListener = null; |
|
|
|
static private MouseListener mouseListener_private = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Deprecated |
|
static protected MouseMotionListener mouseMotionListener = null; |
|
|
|
static private MouseMotionListener mouseMotionListener_private = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Deprecated |
|
static protected WindowListener windowListener = null; |
|
|
|
static private WindowListener windowListener_private = null; |
|
|
|
|
|
// Semantic listeners |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Deprecated |
|
static protected ActionListener actionListener = null; |
|
|
|
static private ActionListener actionListener_private = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Deprecated |
|
static protected AdjustmentListener adjustmentListener = null; |
|
|
|
static private AdjustmentListener adjustmentListener_private = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Deprecated |
|
static protected ItemListener itemListener = null; |
|
|
|
static private ItemListener itemListener_private = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Deprecated |
|
static protected TextListener textListener = null; |
|
|
|
static private TextListener textListener_private = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Deprecated |
|
static protected AWTEventsListener awtListener = new AWTEventsListener(); |
|
|
|
static private final AWTEventsListener awtListener_private = new AWTEventsListener(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public Component getComponentWithFocus() { |
|
return componentWithFocus_private; |
|
} |
|
|
|
|
|
|
|
*/ |
|
static private void checkInstallPermission() { |
|
SecurityManager security = System.getSecurityManager(); |
|
if (security != null) { |
|
security.checkPermission(AWT.ALL_AWT_EVENTS_PERMISSION); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void addComponentListener(ComponentListener l) { |
|
if (componentListener_private == null) { |
|
checkInstallPermission(); |
|
awtListener_private.installListeners(EventID.COMPONENT); |
|
} |
|
componentListener_private = AWTEventMulticaster.add(componentListener_private, l); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void removeComponentListener(ComponentListener l) { |
|
componentListener_private = AWTEventMulticaster.remove(componentListener_private, l); |
|
if (componentListener_private == null) { |
|
awtListener_private.removeListeners(EventID.COMPONENT); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void addContainerListener(ContainerListener l) { |
|
containerListener_private = AWTEventMulticaster.add(containerListener_private, l); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void removeContainerListener(ContainerListener l) { |
|
containerListener_private = AWTEventMulticaster.remove(containerListener_private, l); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void addFocusListener(FocusListener l) { |
|
focusListener_private = AWTEventMulticaster.add(focusListener_private, l); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void removeFocusListener(FocusListener l) { |
|
focusListener_private = AWTEventMulticaster.remove(focusListener_private, l); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void addKeyListener(KeyListener l) { |
|
if (keyListener_private == null) { |
|
checkInstallPermission(); |
|
awtListener_private.installListeners(EventID.KEY); |
|
} |
|
keyListener_private = AWTEventMulticaster.add(keyListener_private, l); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void removeKeyListener(KeyListener l) { |
|
keyListener_private = AWTEventMulticaster.remove(keyListener_private, l); |
|
if (keyListener_private == null) { |
|
awtListener_private.removeListeners(EventID.KEY); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void addMouseListener(MouseListener l) { |
|
if (mouseListener_private == null) { |
|
checkInstallPermission(); |
|
awtListener_private.installListeners(EventID.MOUSE); |
|
} |
|
mouseListener_private = AWTEventMulticaster.add(mouseListener_private, l); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void removeMouseListener(MouseListener l) { |
|
mouseListener_private = AWTEventMulticaster.remove(mouseListener_private, l); |
|
if (mouseListener_private == null) { |
|
awtListener_private.removeListeners(EventID.MOUSE); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void addMouseMotionListener(MouseMotionListener l) { |
|
if (mouseMotionListener_private == null) { |
|
checkInstallPermission(); |
|
awtListener_private.installListeners(EventID.MOTION); |
|
} |
|
mouseMotionListener_private = AWTEventMulticaster.add(mouseMotionListener_private, l); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void removeMouseMotionListener(MouseMotionListener l) { |
|
mouseMotionListener_private = AWTEventMulticaster.remove(mouseMotionListener_private, l); |
|
if (mouseMotionListener_private == null) { |
|
awtListener_private.removeListeners(EventID.MOTION); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void addWindowListener(WindowListener l) { |
|
if (windowListener_private == null) { |
|
checkInstallPermission(); |
|
awtListener_private.installListeners(EventID.WINDOW); |
|
} |
|
windowListener_private = AWTEventMulticaster.add(windowListener_private, l); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void removeWindowListener(WindowListener l) { |
|
windowListener_private = AWTEventMulticaster.remove(windowListener_private, l); |
|
if (windowListener_private == null) { |
|
awtListener_private.removeListeners(EventID.WINDOW); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void addActionListener(ActionListener l) { |
|
if (actionListener_private == null) { |
|
checkInstallPermission(); |
|
awtListener_private.installListeners(EventID.ACTION); |
|
} |
|
actionListener_private = AWTEventMulticaster.add(actionListener_private, l); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void removeActionListener(ActionListener l) { |
|
actionListener_private = AWTEventMulticaster.remove(actionListener_private, l); |
|
if (actionListener_private == null) { |
|
awtListener_private.removeListeners(EventID.ACTION); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void addAdjustmentListener(AdjustmentListener l) { |
|
if (adjustmentListener_private == null) { |
|
checkInstallPermission(); |
|
awtListener_private.installListeners(EventID.ADJUSTMENT); |
|
} |
|
adjustmentListener_private = AWTEventMulticaster.add(adjustmentListener_private, l); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void removeAdjustmentListener(AdjustmentListener l) { |
|
adjustmentListener_private = AWTEventMulticaster.remove(adjustmentListener_private, l); |
|
if (adjustmentListener_private == null) { |
|
awtListener_private.removeListeners(EventID.ADJUSTMENT); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void addItemListener(ItemListener l) { |
|
if (itemListener_private == null) { |
|
checkInstallPermission(); |
|
awtListener_private.installListeners(EventID.ITEM); |
|
} |
|
itemListener_private = AWTEventMulticaster.add(itemListener_private, l); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void removeItemListener(ItemListener l) { |
|
itemListener_private = AWTEventMulticaster.remove(itemListener_private, l); |
|
if (itemListener_private == null) { |
|
awtListener_private.removeListeners(EventID.ITEM); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void addTextListener(TextListener l) { |
|
if (textListener_private == null) { |
|
checkInstallPermission(); |
|
awtListener_private.installListeners(EventID.TEXT); |
|
} |
|
textListener_private = AWTEventMulticaster.add(textListener_private, l); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static public void removeTextListener(TextListener l) { |
|
textListener_private = AWTEventMulticaster.remove(textListener_private, l); |
|
if (textListener_private == null) { |
|
awtListener_private.removeListeners(EventID.TEXT); |
|
} |
|
} |
|
|
|
|
|
/** |
|
* AWTEventsListener is the class that does all the work for AWTEventMonitor. |
|
* It is not intended for use by any other class except AWTEventMonitor. |
|
* |
|
*/ |
|
|
|
static class AWTEventsListener implements TopLevelWindowListener, |
|
ActionListener, AdjustmentListener, ComponentListener, |
|
ContainerListener, FocusListener, ItemListener, KeyListener, |
|
MouseListener, MouseMotionListener, TextListener, WindowListener, |
|
ChangeListener { |
|
|
|
|
|
|
|
*/ |
|
private java.lang.Class actionListeners[]; |
|
private java.lang.reflect.Method removeActionMethod; |
|
private java.lang.reflect.Method addActionMethod; |
|
private java.lang.Object actionArgs[]; |
|
|
|
|
|
|
|
*/ |
|
private java.lang.Class itemListeners[]; |
|
private java.lang.reflect.Method removeItemMethod; |
|
private java.lang.reflect.Method addItemMethod; |
|
private java.lang.Object itemArgs[]; |
|
|
|
|
|
|
|
*/ |
|
private java.lang.Class textListeners[]; |
|
private java.lang.reflect.Method removeTextMethod; |
|
private java.lang.reflect.Method addTextMethod; |
|
private java.lang.Object textArgs[]; |
|
|
|
|
|
|
|
*/ |
|
private java.lang.Class windowListeners[]; |
|
private java.lang.reflect.Method removeWindowMethod; |
|
private java.lang.reflect.Method addWindowMethod; |
|
private java.lang.Object windowArgs[]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public AWTEventsListener() { |
|
String version = System.getProperty("java.version"); |
|
if (version != null) { |
|
runningOnJDK1_4 = (version.compareTo("1.4") >= 0); |
|
} |
|
initializeIntrospection(); |
|
installListeners(); |
|
if (runningOnJDK1_4) { |
|
MenuSelectionManager.defaultManager().addChangeListener(this); |
|
} |
|
EventQueueMonitor.addTopLevelWindowListener(this); |
|
} |
|
|
|
|
|
|
|
*/ |
|
private boolean initializeIntrospection() { |
|
try { |
|
actionListeners = new java.lang.Class[1]; |
|
actionArgs = new java.lang.Object[1]; |
|
actionListeners[0] = Class.forName("java.awt.event.ActionListener"); |
|
actionArgs[0] = this; |
|
|
|
itemListeners = new java.lang.Class[1]; |
|
itemArgs = new java.lang.Object[1]; |
|
itemListeners[0] = Class.forName("java.awt.event.ItemListener"); |
|
itemArgs[0] = this; |
|
|
|
textListeners = new java.lang.Class[1]; |
|
textArgs = new java.lang.Object[1]; |
|
textListeners[0] = Class.forName("java.awt.event.TextListener"); |
|
textArgs[0] = this; |
|
|
|
windowListeners = new java.lang.Class[1]; |
|
windowArgs = new java.lang.Object[1]; |
|
windowListeners[0] = Class.forName("java.awt.event.WindowListener"); |
|
windowArgs[0] = this; |
|
|
|
return true; |
|
} catch (ClassNotFoundException e) { |
|
System.out.println("EXCEPTION - Class 'java.awt.event.*' not in CLASSPATH"); |
|
return false; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected void installListeners() { |
|
Window topLevelWindows[] = EventQueueMonitor.getTopLevelWindows(); |
|
if (topLevelWindows != null) { |
|
for (int i = 0; i < topLevelWindows.length; i++) { |
|
installListeners(topLevelWindows[i]); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected void installListeners(int eventID) { |
|
Window topLevelWindows[] = EventQueueMonitor.getTopLevelWindows(); |
|
if (topLevelWindows != null) { |
|
for (int i = 0; i < topLevelWindows.length; i++) { |
|
installListeners(topLevelWindows[i], eventID); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
protected void installListeners(Component c) { |
|
|
|
// Container and focus listeners are always installed for our own use. |
|
|
|
installListeners(c,EventID.CONTAINER); |
|
installListeners(c,EventID.FOCUS); |
|
|
|
// conditionally install low-level listeners |
|
|
|
if (AWTEventMonitor.componentListener_private != null) { |
|
installListeners(c,EventID.COMPONENT); |
|
} |
|
if (AWTEventMonitor.keyListener_private != null) { |
|
installListeners(c,EventID.KEY); |
|
} |
|
if (AWTEventMonitor.mouseListener_private != null) { |
|
installListeners(c,EventID.MOUSE); |
|
} |
|
if (AWTEventMonitor.mouseMotionListener_private != null) { |
|
installListeners(c,EventID.MOTION); |
|
} |
|
if (AWTEventMonitor.windowListener_private != null) { |
|
installListeners(c,EventID.WINDOW); |
|
} |
|
|
|
// conditionally install Semantic listeners |
|
|
|
if (AWTEventMonitor.actionListener_private != null) { |
|
installListeners(c,EventID.ACTION); |
|
} |
|
if (AWTEventMonitor.adjustmentListener_private != null) { |
|
installListeners(c,EventID.ADJUSTMENT); |
|
} |
|
if (AWTEventMonitor.itemListener_private != null) { |
|
installListeners(c,EventID.ITEM); |
|
} |
|
if (AWTEventMonitor.textListener_private != null) { |
|
installListeners(c,EventID.TEXT); |
|
} |
|
} |
|
|
|
public void stateChanged(ChangeEvent e) { |
|
processFocusGained(); |
|
} |
|
|
|
private void processFocusGained() { |
|
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); |
|
if (focusOwner == null) { |
|
return; |
|
} |
|
MenuSelectionManager.defaultManager().removeChangeListener(this); |
|
MenuSelectionManager.defaultManager().addChangeListener(this); |
|
|
|
|
|
if (focusOwner instanceof JRootPane) { |
|
MenuElement [] path = |
|
MenuSelectionManager.defaultManager().getSelectedPath(); |
|
if (path.length > 1) { |
|
Component penult = path[path.length-2].getComponent(); |
|
Component last = path[path.length-1].getComponent(); |
|
|
|
if (last instanceof JPopupMenu || |
|
last instanceof JMenu) { |
|
// This is a popup with nothing in the popup |
|
|
|
componentWithFocus_private = last; |
|
} else if (penult instanceof JPopupMenu) { |
|
|
|
componentWithFocus_private = penult; |
|
} |
|
} |
|
} else { |
|
|
|
componentWithFocus_private = focusOwner; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected void installListeners(Component c, int eventID) { |
|
|
|
// install the appropriate listener hook into this component |
|
|
|
switch (eventID) { |
|
|
|
case EventID.ACTION: |
|
try { |
|
removeActionMethod = c.getClass().getMethod( |
|
"removeActionListener", actionListeners); |
|
addActionMethod = c.getClass().getMethod( |
|
"addActionListener", actionListeners); |
|
try { |
|
removeActionMethod.invoke(c, actionArgs); |
|
addActionMethod.invoke(c, actionArgs); |
|
} catch (java.lang.reflect.InvocationTargetException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} catch (IllegalAccessException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} |
|
} catch (NoSuchMethodException e) { |
|
// System.out.println("Exception: " + e.toString()); |
|
} catch (SecurityException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} |
|
break; |
|
|
|
case EventID.ADJUSTMENT: |
|
if (c instanceof Adjustable) { |
|
((Adjustable) c).removeAdjustmentListener(this); |
|
((Adjustable) c).addAdjustmentListener(this); |
|
} |
|
break; |
|
|
|
case EventID.COMPONENT: |
|
c.removeComponentListener(this); |
|
c.addComponentListener(this); |
|
break; |
|
|
|
case EventID.CONTAINER: |
|
if (c instanceof Container) { |
|
((Container) c).removeContainerListener(this); |
|
((Container) c).addContainerListener(this); |
|
} |
|
break; |
|
|
|
case EventID.FOCUS: |
|
c.removeFocusListener(this); |
|
c.addFocusListener(this); |
|
|
|
if (runningOnJDK1_4) { |
|
processFocusGained(); |
|
|
|
} else { |
|
if ((c != componentWithFocus_private) && c.hasFocus()) { |
|
componentWithFocus_private = c; |
|
} |
|
} |
|
break; |
|
|
|
case EventID.ITEM: |
|
try { |
|
removeItemMethod = c.getClass().getMethod( |
|
"removeItemListener", itemListeners); |
|
addItemMethod = c.getClass().getMethod( |
|
"addItemListener", itemListeners); |
|
try { |
|
removeItemMethod.invoke(c, itemArgs); |
|
addItemMethod.invoke(c, itemArgs); |
|
} catch (java.lang.reflect.InvocationTargetException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} catch (IllegalAccessException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} |
|
} catch (NoSuchMethodException e) { |
|
// System.out.println("Exception: " + e.toString()); |
|
} catch (SecurityException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} |
|
// [PK] CheckboxMenuItem isn't a component but it does |
|
// implement Interface ItemSelectable!! |
|
// if (c instanceof CheckboxMenuItem) { |
|
// ((CheckboxMenuItem) c).removeItemListener(this); |
|
|
|
break; |
|
|
|
case EventID.KEY: |
|
c.removeKeyListener(this); |
|
c.addKeyListener(this); |
|
break; |
|
|
|
case EventID.MOUSE: |
|
c.removeMouseListener(this); |
|
c.addMouseListener(this); |
|
break; |
|
|
|
case EventID.MOTION: |
|
c.removeMouseMotionListener(this); |
|
c.addMouseMotionListener(this); |
|
break; |
|
|
|
case EventID.TEXT: |
|
try { |
|
removeTextMethod = c.getClass().getMethod( |
|
"removeTextListener", textListeners); |
|
addTextMethod = c.getClass().getMethod( |
|
"addTextListener", textListeners); |
|
try { |
|
removeTextMethod.invoke(c, textArgs); |
|
addTextMethod.invoke(c, textArgs); |
|
} catch (java.lang.reflect.InvocationTargetException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} catch (IllegalAccessException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} |
|
} catch (NoSuchMethodException e) { |
|
// System.out.println("Exception: " + e.toString()); |
|
} catch (SecurityException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} |
|
break; |
|
|
|
case EventID.WINDOW: |
|
try { |
|
removeWindowMethod = c.getClass().getMethod( |
|
"removeWindowListener", windowListeners); |
|
addWindowMethod = c.getClass().getMethod( |
|
"addWindowListener", windowListeners); |
|
try { |
|
removeWindowMethod.invoke(c, windowArgs); |
|
addWindowMethod.invoke(c, windowArgs); |
|
} catch (java.lang.reflect.InvocationTargetException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} catch (IllegalAccessException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} |
|
} catch (NoSuchMethodException e) { |
|
// System.out.println("Exception: " + e.toString()); |
|
} catch (SecurityException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} |
|
break; |
|
|
|
// Don't bother recursing the children if this isn't going to |
|
// accomplish anything. |
|
|
|
default: |
|
return; |
|
} |
|
|
|
// if this component is a container, recurse through children |
|
|
|
if (c instanceof Container) { |
|
int count = ((Container) c).getComponentCount(); |
|
for (int i = 0; i < count; i++) { |
|
installListeners(((Container) c).getComponent(i), eventID); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected void removeListeners(int eventID) { |
|
Window topLevelWindows[] = EventQueueMonitor.getTopLevelWindows(); |
|
if (topLevelWindows != null) { |
|
for (int i = 0; i < topLevelWindows.length; i++) { |
|
removeListeners(topLevelWindows[i], eventID); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
protected void removeListeners(Component c) { |
|
|
|
// conditionally remove low-level listeners |
|
|
|
if (AWTEventMonitor.componentListener_private != null) { |
|
removeListeners(c,EventID.COMPONENT); |
|
} |
|
if (AWTEventMonitor.keyListener_private != null) { |
|
removeListeners(c,EventID.KEY); |
|
} |
|
if (AWTEventMonitor.mouseListener_private != null) { |
|
removeListeners(c,EventID.MOUSE); |
|
} |
|
if (AWTEventMonitor.mouseMotionListener_private != null) { |
|
removeListeners(c,EventID.MOTION); |
|
} |
|
if (AWTEventMonitor.windowListener_private != null) { |
|
removeListeners(c,EventID.WINDOW); |
|
} |
|
|
|
// Remove semantic listeners |
|
|
|
if (AWTEventMonitor.actionListener_private != null) { |
|
removeListeners(c,EventID.ACTION); |
|
} |
|
if (AWTEventMonitor.adjustmentListener_private != null) { |
|
removeListeners(c,EventID.ADJUSTMENT); |
|
} |
|
if (AWTEventMonitor.itemListener_private != null) { |
|
removeListeners(c,EventID.ITEM); |
|
} |
|
if (AWTEventMonitor.textListener_private != null) { |
|
removeListeners(c,EventID.TEXT); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected void removeListeners(Component c, int eventID) { |
|
|
|
// remove the appropriate listener hook into this component |
|
|
|
switch (eventID) { |
|
|
|
case EventID.ACTION: |
|
try { |
|
removeActionMethod = c.getClass().getMethod( |
|
"removeActionListener", |
|
actionListeners); |
|
try { |
|
removeActionMethod.invoke(c, actionArgs); |
|
} catch (java.lang.reflect.InvocationTargetException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} catch (IllegalAccessException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} |
|
} catch (NoSuchMethodException e) { |
|
// System.out.println("Exception: " + e.toString()); |
|
} catch (SecurityException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} |
|
break; |
|
|
|
case EventID.ADJUSTMENT: |
|
if (c instanceof Adjustable) { |
|
((Adjustable) c).removeAdjustmentListener(this); |
|
} |
|
break; |
|
|
|
case EventID.COMPONENT: |
|
c.removeComponentListener(this); |
|
break; |
|
|
|
// Never remove these because we're always interested in them |
|
// for our own use. |
|
//case EventID.CONTAINER: |
|
// if (c instanceof Container) { |
|
// ((Container) c).removeContainerListener(this); |
|
// } |
|
// break; |
|
// |
|
//case EventID.FOCUS: |
|
// c.removeFocusListener(this); |
|
// break; |
|
|
|
case EventID.ITEM: |
|
try { |
|
removeItemMethod = c.getClass().getMethod( |
|
"removeItemListener", itemListeners); |
|
try { |
|
removeItemMethod.invoke(c, itemArgs); |
|
} catch (java.lang.reflect.InvocationTargetException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} catch (IllegalAccessException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} |
|
} catch (NoSuchMethodException e) { |
|
// System.out.println("Exception: " + e.toString()); |
|
} catch (SecurityException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} |
|
// [PK] CheckboxMenuItem isn't a component but it does |
|
// implement Interface ItemSelectable!! |
|
// if (c instanceof CheckboxMenuItem) { |
|
|
|
break; |
|
|
|
case EventID.KEY: |
|
c.removeKeyListener(this); |
|
break; |
|
|
|
case EventID.MOUSE: |
|
c.removeMouseListener(this); |
|
break; |
|
|
|
case EventID.MOTION: |
|
c.removeMouseMotionListener(this); |
|
break; |
|
|
|
case EventID.TEXT: |
|
try { |
|
removeTextMethod = c.getClass().getMethod( |
|
"removeTextListener", textListeners); |
|
try { |
|
removeTextMethod.invoke(c, textArgs); |
|
} catch (java.lang.reflect.InvocationTargetException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} catch (IllegalAccessException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} |
|
} catch (NoSuchMethodException e) { |
|
// System.out.println("Exception: " + e.toString()); |
|
} catch (SecurityException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} |
|
break; |
|
|
|
case EventID.WINDOW: |
|
try { |
|
removeWindowMethod = c.getClass().getMethod( |
|
"removeWindowListener", windowListeners); |
|
try { |
|
removeWindowMethod.invoke(c, windowArgs); |
|
} catch (java.lang.reflect.InvocationTargetException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} catch (IllegalAccessException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} |
|
} catch (NoSuchMethodException e) { |
|
// System.out.println("Exception: " + e.toString()); |
|
} catch (SecurityException e) { |
|
System.out.println("Exception: " + e.toString()); |
|
} |
|
break; |
|
|
|
default: |
|
return; |
|
} |
|
|
|
if (c instanceof Container) { |
|
int count = ((Container) c).getComponentCount(); |
|
for (int i = 0; i < count; i++) { |
|
removeListeners(((Container) c).getComponent(i), eventID); |
|
} |
|
} |
|
} |
|
|
|
/********************************************************************/ |
|
/* */ |
|
/* Listener Interface Methods */ |
|
/* */ |
|
/********************************************************************/ |
|
|
|
/* TopLevelWindow Methods ***************************************/ |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void topLevelWindowCreated(Window w) { |
|
installListeners(w); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void topLevelWindowDestroyed(Window w) { |
|
} |
|
|
|
/* ActionListener Methods ***************************************/ |
|
|
|
|
|
|
|
|
|
*/ |
|
public void actionPerformed(ActionEvent e) { |
|
if (AWTEventMonitor.actionListener_private != null) { |
|
AWTEventMonitor.actionListener_private.actionPerformed(e); |
|
} |
|
} |
|
|
|
/* AdjustmentListener Methods ***********************************/ |
|
|
|
|
|
|
|
|
|
*/ |
|
public void adjustmentValueChanged(AdjustmentEvent e) { |
|
if (AWTEventMonitor.adjustmentListener_private != null) { |
|
AWTEventMonitor.adjustmentListener_private.adjustmentValueChanged(e); |
|
} |
|
} |
|
|
|
/* ComponentListener Methods ************************************/ |
|
|
|
|
|
|
|
|
|
*/ |
|
public void componentHidden(ComponentEvent e) { |
|
if (AWTEventMonitor.componentListener_private != null) { |
|
AWTEventMonitor.componentListener_private.componentHidden(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void componentMoved(ComponentEvent e) { |
|
if (AWTEventMonitor.componentListener_private != null) { |
|
AWTEventMonitor.componentListener_private.componentMoved(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void componentResized(ComponentEvent e) { |
|
if (AWTEventMonitor.componentListener_private != null) { |
|
AWTEventMonitor.componentListener_private.componentResized(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void componentShown(ComponentEvent e) { |
|
if (AWTEventMonitor.componentListener_private != null) { |
|
AWTEventMonitor.componentListener_private.componentShown(e); |
|
} |
|
} |
|
|
|
/* ContainerListener Methods ************************************/ |
|
|
|
|
|
|
|
|
|
*/ |
|
public void componentAdded(ContainerEvent e) { |
|
installListeners(e.getChild()); |
|
if (AWTEventMonitor.containerListener_private != null) { |
|
AWTEventMonitor.containerListener_private.componentAdded(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void componentRemoved(ContainerEvent e) { |
|
removeListeners(e.getChild()); |
|
if (AWTEventMonitor.containerListener_private != null) { |
|
AWTEventMonitor.containerListener_private.componentRemoved(e); |
|
} |
|
} |
|
|
|
/* FocusListener Methods ****************************************/ |
|
|
|
|
|
|
|
|
|
*/ |
|
public void focusGained(FocusEvent e) { |
|
AWTEventMonitor.componentWithFocus_private = (Component) e.getSource(); |
|
if (AWTEventMonitor.focusListener_private != null) { |
|
AWTEventMonitor.focusListener_private.focusGained(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void focusLost(FocusEvent e) { |
|
AWTEventMonitor.componentWithFocus_private = null; |
|
if (AWTEventMonitor.focusListener_private != null) { |
|
AWTEventMonitor.focusListener_private.focusLost(e); |
|
} |
|
} |
|
|
|
/* ItemListener Methods *****************************************/ |
|
|
|
|
|
|
|
|
|
*/ |
|
public void itemStateChanged(ItemEvent e) { |
|
if (AWTEventMonitor.itemListener_private != null) { |
|
AWTEventMonitor.itemListener_private.itemStateChanged(e); |
|
} |
|
} |
|
|
|
/* KeyListener Methods ******************************************/ |
|
|
|
|
|
|
|
|
|
*/ |
|
public void keyPressed(KeyEvent e) { |
|
if (AWTEventMonitor.keyListener_private != null) { |
|
AWTEventMonitor.keyListener_private.keyPressed(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void keyReleased(KeyEvent e) { |
|
if (AWTEventMonitor.keyListener_private != null) { |
|
AWTEventMonitor.keyListener_private.keyReleased(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void keyTyped(KeyEvent e) { |
|
if (AWTEventMonitor.keyListener_private != null) { |
|
AWTEventMonitor.keyListener_private.keyTyped(e); |
|
} |
|
} |
|
|
|
/* MouseListener Methods ****************************************/ |
|
|
|
|
|
|
|
|
|
*/ |
|
public void mouseClicked(MouseEvent e) { |
|
if (AWTEventMonitor.mouseListener_private != null) { |
|
AWTEventMonitor.mouseListener_private.mouseClicked(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void mouseEntered(MouseEvent e) { |
|
if (AWTEventMonitor.mouseListener_private != null) { |
|
AWTEventMonitor.mouseListener_private.mouseEntered(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void mouseExited(MouseEvent e) { |
|
if (AWTEventMonitor.mouseListener_private != null) { |
|
AWTEventMonitor.mouseListener_private.mouseExited(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void mousePressed(MouseEvent e) { |
|
if (AWTEventMonitor.mouseListener_private != null) { |
|
AWTEventMonitor.mouseListener_private.mousePressed(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void mouseReleased(MouseEvent e) { |
|
if (AWTEventMonitor.mouseListener_private != null) { |
|
AWTEventMonitor.mouseListener_private.mouseReleased(e); |
|
} |
|
} |
|
|
|
/* MouseMotionListener Methods **********************************/ |
|
|
|
|
|
|
|
|
|
*/ |
|
public void mouseDragged(MouseEvent e) { |
|
if (AWTEventMonitor.mouseMotionListener_private != null) { |
|
AWTEventMonitor.mouseMotionListener_private.mouseDragged(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void mouseMoved(MouseEvent e) { |
|
if (AWTEventMonitor.mouseMotionListener_private != null) { |
|
AWTEventMonitor.mouseMotionListener_private.mouseMoved(e); |
|
} |
|
} |
|
|
|
/* TextListener Methods *****************************************/ |
|
|
|
|
|
|
|
|
|
*/ |
|
public void textValueChanged(TextEvent e) { |
|
if (AWTEventMonitor.textListener_private != null) { |
|
AWTEventMonitor.textListener_private.textValueChanged(e); |
|
} |
|
} |
|
|
|
/* WindowListener Methods ***************************************/ |
|
|
|
|
|
|
|
|
|
*/ |
|
public void windowOpened(WindowEvent e) { |
|
if (AWTEventMonitor.windowListener_private != null) { |
|
AWTEventMonitor.windowListener_private.windowOpened(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void windowClosing(WindowEvent e) { |
|
if (AWTEventMonitor.windowListener_private != null) { |
|
AWTEventMonitor.windowListener_private.windowClosing(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void windowClosed(WindowEvent e) { |
|
if (AWTEventMonitor.windowListener_private != null) { |
|
AWTEventMonitor.windowListener_private.windowClosed(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void windowIconified(WindowEvent e) { |
|
if (AWTEventMonitor.windowListener_private != null) { |
|
AWTEventMonitor.windowListener_private.windowIconified(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void windowDeiconified(WindowEvent e) { |
|
if (AWTEventMonitor.windowListener_private != null) { |
|
AWTEventMonitor.windowListener_private.windowDeiconified(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void windowActivated(WindowEvent e) { |
|
if (AWTEventMonitor.windowListener_private != null) { |
|
AWTEventMonitor.windowListener_private.windowActivated(e); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void windowDeactivated(WindowEvent e) { |
|
if (AWTEventMonitor.windowListener_private != null) { |
|
AWTEventMonitor.windowListener_private.windowDeactivated(e); |
|
} |
|
} |
|
} |
|
} |