1 /*
   2  * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.java.accessibility.util;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import javax.swing.*;
  31 import javax.swing.event.*;
  32 import sun.awt.AWTPermissions;
  33 
  34 /**
  35  * <P>The {@code AWTEventMonitor} implements a suite of listeners that are
  36  * conditionally installed on every AWT component instance in the Java
  37  * Virtual Machine.  The events captured by these listeners are made
  38  * available through a unified set of listeners supported by {@code AWTEventMonitor}.
  39  * With this, all the individual events on each of the AWT component
  40  * instances are funneled into one set of listeners broken down by category
  41  * (see {@link EventID} for the categories).
  42  * <p>This class depends upon {@link EventQueueMonitor}, which provides the base
  43  * level support for capturing the top-level containers as they are created.
  44  */
  45 
  46 public class AWTEventMonitor {
  47 
  48     /**
  49      * The current component with keyboard focus.
  50      *
  51      * @see #getComponentWithFocus
  52      *
  53      * @deprecated This field is unused; to get the component with focus use the
  54      * getComponentWithFocus method.
  55      */
  56     @Deprecated(since="8", forRemoval=true)
  57     static protected Component componentWithFocus = null;
  58 
  59     static private Component componentWithFocus_private = null;
  60 
  61     // Low-level listeners
  62     /**
  63      * The current list of registered ComponentListener classes.
  64      *
  65      * @see #addComponentListener
  66      * @see #removeComponentListener
  67      *
  68      * @deprecated This field is unused.
  69      */
  70     @Deprecated(since="8", forRemoval=true)
  71     static protected ComponentListener     componentListener     = null;
  72 
  73     static private ComponentListener componentListener_private = null;
  74 
  75     /**
  76      * The current list of registered ContainerListener classes.
  77      *
  78      * @see #addContainerListener
  79      * @see #removeContainerListener
  80      *
  81      * @deprecated This field is unused.
  82      */
  83     @Deprecated(since="8", forRemoval=true)
  84     static protected ContainerListener     containerListener     = null;
  85 
  86     static private ContainerListener containerListener_private = null;
  87 
  88     /**
  89      * The current list of registered FocusListener classes.
  90      *
  91      * @see #addFocusListener
  92      * @see #removeFocusListener
  93      *
  94      * @deprecated This field is unused.
  95      */
  96     @Deprecated(since="8", forRemoval=true)
  97     static protected FocusListener         focusListener         = null;
  98 
  99     static private FocusListener focusListener_private = null;
 100 
 101     /**
 102      * The current list of registered KeyListener classes.
 103      *
 104      * @see #addKeyListener
 105      * @see #removeKeyListener
 106      *
 107      * @deprecated This field is unused.
 108      */
 109     @Deprecated(since="8", forRemoval=true)
 110     static protected KeyListener           keyListener           = null;
 111 
 112     static private KeyListener keyListener_private = null;
 113 
 114     /**
 115      * The current list of registered MouseListener classes.
 116      *
 117      * @see #addMouseListener
 118      * @see #removeMouseListener
 119      *
 120      * @deprecated This field is unused.
 121      */
 122     @Deprecated(since="8", forRemoval=true)
 123     static protected MouseListener         mouseListener         = null;
 124 
 125     static private MouseListener mouseListener_private = null;
 126 
 127     /**
 128      * The current list of registered MouseMotionListener classes.
 129      *
 130      * @see #addMouseMotionListener
 131      * @see #removeMouseMotionListener
 132      *
 133      * @deprecated This field is unused.
 134      */
 135     @Deprecated(since="8", forRemoval=true)
 136     static protected MouseMotionListener   mouseMotionListener   = null;
 137 
 138     static private MouseMotionListener mouseMotionListener_private = null;
 139 
 140     /**
 141      * The current list of registered WindowListener classes.
 142      *
 143      * @see #addWindowListener
 144      * @see #removeWindowListener
 145      *
 146      * @deprecated This field is unused.
 147      */
 148     @Deprecated(since="8", forRemoval=true)
 149     static protected WindowListener        windowListener        = null;
 150 
 151     static private WindowListener windowListener_private = null;
 152 
 153 
 154     // Semantic listeners
 155     /**
 156      * The current list of registered ActionListener classes.
 157      *
 158      * @see #addActionListener
 159      * @see #removeActionListener
 160      *
 161      * @deprecated This field is unused.
 162      */
 163     @Deprecated(since="8", forRemoval=true)
 164     static protected ActionListener        actionListener        = null;
 165 
 166     static private ActionListener actionListener_private = null;
 167 
 168     /**
 169      * The current list of registered AdjustmentListener classes.
 170      *
 171      * @see #addAdjustmentListener
 172      * @see #removeAdjustmentListener
 173      *
 174      * @deprecated This field is unused.
 175      */
 176     @Deprecated(since="8", forRemoval=true)
 177     static protected AdjustmentListener    adjustmentListener    = null;
 178 
 179     static private AdjustmentListener adjustmentListener_private = null;
 180 
 181     /**
 182      * The current list of registered ItemListener classes.
 183      *
 184      * @see #addItemListener
 185      * @see #removeItemListener
 186      *
 187      * @deprecated This field is unused.
 188      */
 189     @Deprecated(since="8", forRemoval=true)
 190     static protected ItemListener          itemListener          = null;
 191 
 192     static private ItemListener itemListener_private = null;
 193 
 194     /**
 195      * The current list of registered TextListener classes.
 196      *
 197      * @see #addTextListener
 198      * @see #removeTextListener
 199      *
 200      * @deprecated This field is unused.
 201      */
 202     @Deprecated(since="8", forRemoval=true)
 203     static protected TextListener          textListener          = null;
 204 
 205     static private TextListener textListener_private = null;
 206 
 207 
 208     /**
 209      * The actual listener that is installed on the component instances.
 210      * This listener calls the other registered listeners when an event
 211      * occurs.  By doing things this way, the actual number of listeners
 212      * installed on a component instance is drastically reduced.
 213      */
 214     static private final AWTEventsListener awtListener = new AWTEventsListener();
 215 
 216     /**
 217      * Returns the component that currently has keyboard focus.  The return
 218      * value can be null.
 219      *
 220      * @return the component that has keyboard focus
 221      */
 222     static public Component getComponentWithFocus() {
 223         return componentWithFocus_private;
 224     }
 225 
 226     /*
 227      * Check permissions
 228      */
 229     static private void checkInstallPermission() {
 230         SecurityManager security = System.getSecurityManager();
 231         if (security != null) {
 232             security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION);
 233         }
 234     }
 235 
 236     /**
 237      * Adds the specified listener to receive all {@link EventID#COMPONENT COMPONENT}
 238      * events on each component instance in the Java Virtual Machine as they occur.
 239      * <P>Note: this listener is automatically added to all component
 240      * instances created after this method is called.  In addition, it
 241      * is only added to component instances that support this listener type.
 242      *
 243      * @param l the listener to add
 244      * @see #removeComponentListener
 245      */
 246     static public void addComponentListener(ComponentListener l) {
 247         if (componentListener_private == null) {
 248             checkInstallPermission();
 249             awtListener.installListeners(EventID.COMPONENT);
 250         }
 251         componentListener_private = AWTEventMulticaster.add(componentListener_private, l);
 252     }
 253 
 254     /**
 255      * Removes the specified listener so it no longer receives
 256      * {@link EventID#COMPONENT COMPONENT} events when they occur.
 257      *
 258      * @param l the listener to remove
 259      * @see #addComponentListener
 260      */
 261     static public void removeComponentListener(ComponentListener l) {
 262         componentListener_private = AWTEventMulticaster.remove(componentListener_private, l);
 263         if (componentListener_private == null) {
 264             awtListener.removeListeners(EventID.COMPONENT);
 265         }
 266     }
 267 
 268     /**
 269      * Adds the specified listener to receive all {@link EventID#CONTAINER CONTAINER}
 270      * events on each component instance in the Java Virtual Machine as they occur.
 271      * <P>Note: this listener is automatically added to all component
 272      * instances created after this method is called.  In addition, it
 273      * is only added to component instances that support this listener type.
 274      *
 275      * @param l the listener to add
 276      * @see #removeContainerListener
 277      */
 278     static public void addContainerListener(ContainerListener l) {
 279         containerListener_private = AWTEventMulticaster.add(containerListener_private, l);
 280     }
 281 
 282     /**
 283      * Removes the specified listener so it no longer receives
 284      * {@link EventID#CONTAINER CONTAINER} events when they occur.
 285      *
 286      * @param l the listener to remove
 287      * @see #addContainerListener
 288      */
 289     static public void removeContainerListener(ContainerListener l) {
 290         containerListener_private = AWTEventMulticaster.remove(containerListener_private, l);
 291     }
 292 
 293     /**
 294      * Adds the specified listener to receive all {@link EventID#FOCUS FOCUS} events
 295      * on each component instance in the Java Virtual Machine when they occur.
 296      * <P>Note: this listener is automatically added to all component
 297      * instances created after this method is called.  In addition, it
 298      * is only added to component instances that support this listener type.
 299      *
 300      * @param l the listener to add
 301      * @see #removeFocusListener
 302      */
 303     static public void addFocusListener(FocusListener l) {
 304         focusListener_private = AWTEventMulticaster.add(focusListener_private, l);
 305     }
 306 
 307     /**
 308      * Removes the specified listener so it no longer receives {@link EventID#FOCUS FOCUS}
 309      * events when they occur.
 310      *
 311      * @param l the listener to remove
 312      * @see #addFocusListener
 313      */
 314     static public void removeFocusListener(FocusListener l) {
 315         focusListener_private = AWTEventMulticaster.remove(focusListener_private, l);
 316     }
 317 
 318     /**
 319      * Adds the specified listener to receive all {@link EventID#KEY KEY} events on each
 320      * component instance in the Java Virtual Machine when they occur.
 321      * <P>Note: this listener is automatically added to all component
 322      * instances created after this method is called.  In addition, it
 323      * is only added to component instances that support this listener type.
 324      *
 325      * @param l the listener to add
 326      * @see #removeKeyListener
 327      */
 328     static public void addKeyListener(KeyListener l) {
 329         if (keyListener_private == null) {
 330             checkInstallPermission();
 331             awtListener.installListeners(EventID.KEY);
 332         }
 333         keyListener_private = AWTEventMulticaster.add(keyListener_private, l);
 334     }
 335 
 336     /**
 337      * Removes the specified listener so it no longer receives {@link EventID#KEY KEY}
 338      * events when they occur.
 339      *
 340      * @param l the listener to remove
 341      * @see #addKeyListener
 342      */
 343     static public void removeKeyListener(KeyListener l) {
 344         keyListener_private = AWTEventMulticaster.remove(keyListener_private, l);
 345         if (keyListener_private == null)  {
 346             awtListener.removeListeners(EventID.KEY);
 347         }
 348     }
 349 
 350     /**
 351      * Adds the specified listener to receive all {@link EventID#MOUSE MOUSE} events
 352      * on each component instance in the Java Virtual Machine when they occur.
 353      * <P>Note: this listener is automatically added to all component
 354      * instances created after this method is called.  In addition, it
 355      * is only added to component instances that support this listener type.
 356      *
 357      * @param l the listener to add
 358      * @see #removeMouseListener
 359      */
 360     static public void addMouseListener(MouseListener l) {
 361         if (mouseListener_private == null) {
 362             checkInstallPermission();
 363             awtListener.installListeners(EventID.MOUSE);
 364         }
 365         mouseListener_private = AWTEventMulticaster.add(mouseListener_private, l);
 366     }
 367 
 368     /**
 369      * Removes the specified listener so it no longer receives
 370      * {@link EventID#MOUSE MOUSE} events when they occur.
 371      *
 372      * @param l the listener to remove
 373      * @see #addMouseListener
 374      */
 375     static public void removeMouseListener(MouseListener l) {
 376         mouseListener_private = AWTEventMulticaster.remove(mouseListener_private, l);
 377         if (mouseListener_private == null) {
 378             awtListener.removeListeners(EventID.MOUSE);
 379         }
 380     }
 381 
 382     /**
 383      * Adds the specified listener to receive all mouse {@link EventID#MOTION MOTION}
 384      * events on each component instance in the Java Virtual Machine when they occur.
 385      * <P>Note: this listener is automatically added to all component
 386      * instances created after this method is called.  In addition, it
 387      * is only added to component instances that support this listener type.
 388      *
 389      * @param l the listener to add
 390      * @see #removeMouseMotionListener
 391      */
 392     static public void addMouseMotionListener(MouseMotionListener l) {
 393         if (mouseMotionListener_private == null) {
 394             checkInstallPermission();
 395             awtListener.installListeners(EventID.MOTION);
 396         }
 397         mouseMotionListener_private = AWTEventMulticaster.add(mouseMotionListener_private, l);
 398     }
 399 
 400     /**
 401      * Removes the specified listener so it no longer receives
 402      * {@link EventID#MOTION MOTION} events when they occur.
 403      *
 404      * @param l the listener to remove
 405      * @see #addMouseMotionListener
 406      */
 407     static public void removeMouseMotionListener(MouseMotionListener l) {
 408         mouseMotionListener_private = AWTEventMulticaster.remove(mouseMotionListener_private, l);
 409         if (mouseMotionListener_private == null) {
 410             awtListener.removeListeners(EventID.MOTION);
 411         }
 412     }
 413 
 414     /**
 415      * Adds the specified listener to receive all {@link EventID#WINDOW WINDOW}
 416      * events on each component instance in the Java Virtual Machine when they occur.
 417      * <P>Note: this listener is automatically added to all component
 418      * instances created after this method is called.  In addition, it
 419      * is only added to component instances that support this listener type.
 420      *
 421      * @param l the listener to add
 422      * @see #removeWindowListener
 423      */
 424     static public void addWindowListener(WindowListener l) {
 425         if (windowListener_private == null) {
 426             checkInstallPermission();
 427             awtListener.installListeners(EventID.WINDOW);
 428         }
 429         windowListener_private = AWTEventMulticaster.add(windowListener_private, l);
 430     }
 431 
 432     /**
 433      * Removes the specified listener so it no longer receives
 434      * {@link EventID#WINDOW WINDOW} events when they occur.
 435      *
 436      * @param l the listener to remove
 437      * @see #addWindowListener
 438      */
 439     static public void removeWindowListener(WindowListener l) {
 440         windowListener_private = AWTEventMulticaster.remove(windowListener_private, l);
 441         if (windowListener_private == null) {
 442             awtListener.removeListeners(EventID.WINDOW);
 443         }
 444     }
 445 
 446     /**
 447      * Adds the specified listener to receive all {@link EventID#ACTION ACTION}
 448      * events on each component instance in the Java Virtual Machine when they occur.
 449      * <P>Note: This listener is automatically added to all component
 450      * instances created after this method is called.  In addition, it
 451      * is only added to component instances that support this listener type.
 452      *
 453      * @param l the listener to add
 454      * @see #removeActionListener
 455      */
 456     static public void addActionListener(ActionListener l) {
 457         if (actionListener_private == null) {
 458             checkInstallPermission();
 459             awtListener.installListeners(EventID.ACTION);
 460         }
 461         actionListener_private = AWTEventMulticaster.add(actionListener_private, l);
 462     }
 463 
 464     /**
 465      * Removes the specified listener so it no longer receives
 466      * {@link EventID#ACTION ACTION} events when they occur.
 467      *
 468      * @param l the listener to remove
 469      * @see #addActionListener
 470      */
 471     static public void removeActionListener(ActionListener l) {
 472         actionListener_private = AWTEventMulticaster.remove(actionListener_private, l);
 473         if (actionListener_private == null) {
 474             awtListener.removeListeners(EventID.ACTION);
 475         }
 476     }
 477 
 478     /**
 479      * Adds the specified listener to receive all
 480      * {@link EventID#ADJUSTMENT ADJUSTMENT} events on each component instance
 481      * in the Java Virtual Machine when they occur.
 482      * <P>Note: this listener is automatically added to all component
 483      * instances created after this method is called.  In addition, it
 484      * is only added to component instances that support this listener type.
 485      *
 486      * @param l the listener to add
 487      * @see #removeAdjustmentListener
 488      */
 489     static public void addAdjustmentListener(AdjustmentListener l) {
 490         if (adjustmentListener_private == null) {
 491             checkInstallPermission();
 492             awtListener.installListeners(EventID.ADJUSTMENT);
 493         }
 494         adjustmentListener_private = AWTEventMulticaster.add(adjustmentListener_private, l);
 495     }
 496 
 497     /**
 498      * Removes the specified listener so it no longer receives
 499      * {@link EventID#ADJUSTMENT ADJUSTMENT} events when they occur.
 500      *
 501      * @param l the listener to remove
 502      * @see #addAdjustmentListener
 503      */
 504     static public void removeAdjustmentListener(AdjustmentListener l) {
 505         adjustmentListener_private = AWTEventMulticaster.remove(adjustmentListener_private, l);
 506         if (adjustmentListener_private == null) {
 507             awtListener.removeListeners(EventID.ADJUSTMENT);
 508         }
 509     }
 510 
 511     /**
 512      * Adds the specified listener to receive all {@link EventID#ITEM ITEM} events
 513      * on each component instance in the Java Virtual Machine when they occur.
 514      * <P>Note: this listener is automatically added to all component
 515      * instances created after this method is called.  In addition, it
 516      * is only added to component instances that support this listener type.
 517      *
 518      * @param l the listener to add
 519      * @see #removeItemListener
 520      */
 521     static public void addItemListener(ItemListener l) {
 522         if (itemListener_private == null) {
 523             checkInstallPermission();
 524             awtListener.installListeners(EventID.ITEM);
 525         }
 526         itemListener_private = AWTEventMulticaster.add(itemListener_private, l);
 527     }
 528 
 529     /**
 530      * Removes the specified listener so it no longer receives {@link EventID#ITEM ITEM}
 531      * events when they occur.
 532      *
 533      * @param l the listener to remove
 534      * @see #addItemListener
 535      */
 536     static public void removeItemListener(ItemListener l) {
 537         itemListener_private = AWTEventMulticaster.remove(itemListener_private, l);
 538         if (itemListener_private == null) {
 539             awtListener.removeListeners(EventID.ITEM);
 540         }
 541     }
 542 
 543     /**
 544      * Adds the specified listener to receive all {@link EventID#TEXT TEXT} events
 545      * on each component instance in the Java Virtual Machine when they occur.
 546      * <P>Note: this listener is automatically added to all component
 547      * instances created after this method is called.  In addition, it
 548      * is only added to component instances that support this listener type.
 549      *
 550      * @param l the listener to add
 551      * @see #removeTextListener
 552      */
 553     static public void addTextListener(TextListener l) {
 554         if (textListener_private == null) {
 555             checkInstallPermission();
 556             awtListener.installListeners(EventID.TEXT);
 557         }
 558         textListener_private = AWTEventMulticaster.add(textListener_private, l);
 559     }
 560 
 561     /**
 562      * Removes the specified listener so it no longer receives {@link EventID#TEXT TEXT}
 563      * events when they occur.
 564      *
 565      * @param l the listener to remove
 566      * @see #addTextListener
 567      */
 568     static public void removeTextListener(TextListener l) {
 569         textListener_private = AWTEventMulticaster.remove(textListener_private, l);
 570         if (textListener_private == null) {
 571             awtListener.removeListeners(EventID.TEXT);
 572         }
 573     }
 574 
 575 
 576     /**
 577      * AWTEventsListener is the class that does all the work for AWTEventMonitor.
 578      * It is not intended for use by any other class except AWTEventMonitor.
 579      *
 580      */
 581 
 582     static class AWTEventsListener implements TopLevelWindowListener,
 583         ActionListener, AdjustmentListener, ComponentListener,
 584         ContainerListener, FocusListener, ItemListener, KeyListener,
 585         MouseListener, MouseMotionListener, TextListener, WindowListener,
 586         ChangeListener {
 587 
 588         /**
 589          * internal variables for Action introspection
 590          */
 591         private java.lang.Class<?>[] actionListeners;
 592         private java.lang.reflect.Method removeActionMethod;
 593         private java.lang.reflect.Method addActionMethod;
 594         private java.lang.Object[] actionArgs;
 595 
 596         /**
 597          * internal variables for Item introspection
 598          */
 599         private java.lang.Class<?>[] itemListeners;
 600         private java.lang.reflect.Method removeItemMethod;
 601         private java.lang.reflect.Method addItemMethod;
 602         private java.lang.Object[] itemArgs;
 603 
 604         /**
 605          * internal variables for Text introspection
 606          */
 607         private java.lang.Class<?>[] textListeners;
 608         private java.lang.reflect.Method removeTextMethod;
 609         private java.lang.reflect.Method addTextMethod;
 610         private java.lang.Object[] textArgs;
 611 
 612         /**
 613          * internal variables for Window introspection
 614          */
 615         private java.lang.Class<?>[] windowListeners;
 616         private java.lang.reflect.Method removeWindowMethod;
 617         private java.lang.reflect.Method addWindowMethod;
 618         private java.lang.Object[] windowArgs;
 619 
 620         /**
 621          * Create a new instance of this class and install it on each component
 622          * instance in the virtual machine that supports any of the currently
 623          * registered listeners in AWTEventMonitor.  Also registers itself
 624          * as a TopLevelWindowListener with EventQueueMonitor so it can
 625          * automatically add new listeners to new components.
 626          *
 627          * @see EventQueueMonitor
 628          * @see AWTEventMonitor
 629          */
 630         public AWTEventsListener() {
 631             initializeIntrospection();
 632             installListeners();
 633             MenuSelectionManager.defaultManager().addChangeListener(this);
 634             EventQueueMonitor.addTopLevelWindowListener(this);
 635         }
 636 
 637         /**
 638          * Set up all of the variables needed for introspection
 639          */
 640         private boolean initializeIntrospection() {
 641             actionListeners = new java.lang.Class<?>[1];
 642             actionArgs = new java.lang.Object[1];
 643             actionListeners[0] = java.awt.event.ActionListener.class;
 644             actionArgs[0] = this;
 645 
 646             itemListeners = new java.lang.Class<?>[1];
 647             itemArgs = new java.lang.Object[1];
 648             itemListeners[0] = java.awt.event.ItemListener.class;
 649             itemArgs[0] = this;
 650 
 651             textListeners = new java.lang.Class<?>[1];
 652             textArgs = new java.lang.Object[1];
 653             textListeners[0] = java.awt.event.TextListener.class;
 654             textArgs[0] = this;
 655 
 656             windowListeners = new java.lang.Class<?>[1];
 657             windowArgs = new java.lang.Object[1];
 658             windowListeners[0] = java.awt.event.WindowListener.class;
 659             windowArgs[0] = this;
 660 
 661             return true;
 662         }
 663 
 664         /**
 665          * Installs all currently registered listeners on all components based
 666          * upon the current topLevelWindows cached by EventQueueMonitor.
 667          *
 668          * @see EventQueueMonitor
 669          * @see AWTEventMonitor
 670          */
 671         protected void installListeners() {
 672             Window[] topLevelWindows = EventQueueMonitor.getTopLevelWindows();
 673             if (topLevelWindows != null) {
 674                 for (int i = 0; i < topLevelWindows.length; i++) {
 675                     installListeners(topLevelWindows[i]);
 676                 }
 677             }
 678         }
 679 
 680         /**
 681          * Installs listeners for the given event ID on all components based
 682          * upon the current topLevelWindows cached by EventQueueMonitor.
 683          *
 684          * @param eventID the event ID
 685          * @see EventID
 686          */
 687         protected void installListeners(int eventID) {
 688             Window[] topLevelWindows = EventQueueMonitor.getTopLevelWindows();
 689             if (topLevelWindows != null) {
 690                 for (int i = 0; i < topLevelWindows.length; i++) {
 691                     installListeners(topLevelWindows[i], eventID);
 692                 }
 693             }
 694         }
 695 
 696         /**
 697          * Installs all currently registered listeners to just the component.
 698          * @param c the component to add listeners to
 699          */
 700         protected void installListeners(Component c) {
 701 
 702             // Container and focus listeners are always installed for our own use.
 703             //
 704             installListeners(c,EventID.CONTAINER);
 705             installListeners(c,EventID.FOCUS);
 706 
 707             // conditionally install low-level listeners
 708             //
 709             if (AWTEventMonitor.componentListener_private != null) {
 710                 installListeners(c,EventID.COMPONENT);
 711             }
 712             if (AWTEventMonitor.keyListener_private != null) {
 713                 installListeners(c,EventID.KEY);
 714             }
 715             if (AWTEventMonitor.mouseListener_private != null) {
 716                 installListeners(c,EventID.MOUSE);
 717             }
 718             if (AWTEventMonitor.mouseMotionListener_private != null) {
 719                 installListeners(c,EventID.MOTION);
 720             }
 721             if (AWTEventMonitor.windowListener_private != null) {
 722                 installListeners(c,EventID.WINDOW);
 723             }
 724 
 725             // conditionally install Semantic listeners
 726             //
 727             if (AWTEventMonitor.actionListener_private != null) {
 728                 installListeners(c,EventID.ACTION);
 729             }
 730             if (AWTEventMonitor.adjustmentListener_private != null) {
 731                 installListeners(c,EventID.ADJUSTMENT);
 732             }
 733             if (AWTEventMonitor.itemListener_private != null) {
 734                 installListeners(c,EventID.ITEM);
 735             }
 736             if (AWTEventMonitor.textListener_private != null) {
 737                 installListeners(c,EventID.TEXT);
 738             }
 739         }
 740 
 741         public void stateChanged(ChangeEvent e) {
 742             processFocusGained();
 743         }
 744 
 745         private void processFocusGained() {
 746             Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
 747             if (focusOwner == null) {
 748                 return;
 749             }
 750             MenuSelectionManager.defaultManager().removeChangeListener(this);
 751             MenuSelectionManager.defaultManager().addChangeListener(this);
 752 
 753             // Only menus and popup selections are handled by the JRootPane.
 754             if (focusOwner instanceof JRootPane) {
 755                 MenuElement [] path =
 756                     MenuSelectionManager.defaultManager().getSelectedPath();
 757                 if (path.length > 1) {
 758                     Component penult = path[path.length-2].getComponent();
 759                     Component last = path[path.length-1].getComponent();
 760 
 761                     if (last instanceof JPopupMenu ||
 762                         last instanceof JMenu) {
 763                         // This is a popup with nothing in the popup
 764                         // selected. The menu itself is selected.
 765                         componentWithFocus_private = last;
 766                     } else if (penult instanceof JPopupMenu) {
 767                         // This is a popup with an item selected
 768                         componentWithFocus_private = penult;
 769                     }
 770                 }
 771             } else {
 772                 // The focus owner has the selection.
 773                 componentWithFocus_private = focusOwner;
 774             }
 775         }
 776 
 777         /**
 778          * Installs the given listener on the component and any of its children.
 779          * As a precaution, it always attempts to remove itself as a listener
 780          * first so it's always guaranteed to have installed itself just once.
 781          *
 782          * @param c the component to add listeners to
 783          * @param eventID the eventID to add listeners for
 784          * @see EventID
 785          */
 786         protected void installListeners(Component c, int eventID) {
 787 
 788             // install the appropriate listener hook into this component
 789             //
 790             switch (eventID) {
 791 
 792             case EventID.ACTION:
 793                 try {
 794                     removeActionMethod = c.getClass().getMethod(
 795                         "removeActionListener", actionListeners);
 796                     addActionMethod = c.getClass().getMethod(
 797                         "addActionListener", actionListeners);
 798                     try {
 799                         removeActionMethod.invoke(c, actionArgs);
 800                         addActionMethod.invoke(c, actionArgs);
 801                     } catch (java.lang.reflect.InvocationTargetException e) {
 802                         System.out.println("Exception: " + e.toString());
 803                     } catch (IllegalAccessException e) {
 804                         System.out.println("Exception: " + e.toString());
 805                     }
 806                 } catch (NoSuchMethodException e) {
 807                     // System.out.println("Exception: " + e.toString());
 808                 } catch (SecurityException e) {
 809                     System.out.println("Exception: " + e.toString());
 810                 }
 811                 break;
 812 
 813             case EventID.ADJUSTMENT:
 814                 if (c instanceof Adjustable) {
 815                     ((Adjustable) c).removeAdjustmentListener(this);
 816                     ((Adjustable) c).addAdjustmentListener(this);
 817                 }
 818                 break;
 819 
 820             case EventID.COMPONENT:
 821                 c.removeComponentListener(this);
 822                 c.addComponentListener(this);
 823                 break;
 824 
 825             case EventID.CONTAINER:
 826                 if (c instanceof Container) {
 827                     ((Container) c).removeContainerListener(this);
 828                     ((Container) c).addContainerListener(this);
 829                 }
 830                 break;
 831 
 832             case EventID.FOCUS:
 833                 c.removeFocusListener(this);
 834                 c.addFocusListener(this);
 835                 processFocusGained();
 836                 break;
 837 
 838             case EventID.ITEM:
 839                 try {
 840                     removeItemMethod = c.getClass().getMethod(
 841                         "removeItemListener", itemListeners);
 842                     addItemMethod = c.getClass().getMethod(
 843                         "addItemListener", itemListeners);
 844                     try {
 845                         removeItemMethod.invoke(c, itemArgs);
 846                         addItemMethod.invoke(c, itemArgs);
 847                     } catch (java.lang.reflect.InvocationTargetException e) {
 848                         System.out.println("Exception: " + e.toString());
 849                     } catch (IllegalAccessException e) {
 850                         System.out.println("Exception: " + e.toString());
 851                     }
 852                 } catch (NoSuchMethodException e) {
 853                     // System.out.println("Exception: " + e.toString());
 854                 } catch (SecurityException e) {
 855                     System.out.println("Exception: " + e.toString());
 856                 }
 857                 // [PK] CheckboxMenuItem isn't a component but it does
 858                 // implement Interface ItemSelectable!!
 859                 // if (c instanceof CheckboxMenuItem) {
 860                 //     ((CheckboxMenuItem) c).removeItemListener(this);
 861                 //     ((CheckboxMenuItem) c).addItemListener(this);
 862                 break;
 863 
 864             case EventID.KEY:
 865                 c.removeKeyListener(this);
 866                 c.addKeyListener(this);
 867                 break;
 868 
 869             case EventID.MOUSE:
 870                 c.removeMouseListener(this);
 871                 c.addMouseListener(this);
 872                 break;
 873 
 874             case EventID.MOTION:
 875                 c.removeMouseMotionListener(this);
 876                 c.addMouseMotionListener(this);
 877                 break;
 878 
 879             case EventID.TEXT:
 880                 try {
 881                     removeTextMethod = c.getClass().getMethod(
 882                         "removeTextListener", textListeners);
 883                     addTextMethod = c.getClass().getMethod(
 884                         "addTextListener", textListeners);
 885                     try {
 886                         removeTextMethod.invoke(c, textArgs);
 887                         addTextMethod.invoke(c, textArgs);
 888                     } catch (java.lang.reflect.InvocationTargetException e) {
 889                         System.out.println("Exception: " + e.toString());
 890                     } catch (IllegalAccessException e) {
 891                         System.out.println("Exception: " + e.toString());
 892                     }
 893                 } catch (NoSuchMethodException e) {
 894                     // System.out.println("Exception: " + e.toString());
 895                 } catch (SecurityException e) {
 896                     System.out.println("Exception: " + e.toString());
 897                 }
 898                 break;
 899 
 900             case EventID.WINDOW:
 901                 try {
 902                     removeWindowMethod = c.getClass().getMethod(
 903                         "removeWindowListener", windowListeners);
 904                     addWindowMethod = c.getClass().getMethod(
 905                         "addWindowListener", windowListeners);
 906                     try {
 907                         removeWindowMethod.invoke(c, windowArgs);
 908                         addWindowMethod.invoke(c, windowArgs);
 909                     } catch (java.lang.reflect.InvocationTargetException e) {
 910                         System.out.println("Exception: " + e.toString());
 911                     } catch (IllegalAccessException e) {
 912                         System.out.println("Exception: " + e.toString());
 913                     }
 914                 } catch (NoSuchMethodException e) {
 915                     // System.out.println("Exception: " + e.toString());
 916                 } catch (SecurityException e) {
 917                     System.out.println("Exception: " + e.toString());
 918                 }
 919                 break;
 920 
 921             // Don't bother recursing the children if this isn't going to
 922             // accomplish anything.
 923             //
 924             default:
 925                 return;
 926             }
 927 
 928             // if this component is a container, recurse through children
 929             //
 930             if (c instanceof Container) {
 931                 int count = ((Container) c).getComponentCount();
 932                 for (int i = 0; i < count; i++) {
 933                     installListeners(((Container) c).getComponent(i), eventID);
 934                 }
 935             }
 936         }
 937 
 938         /**
 939          * Removes all listeners for the given event ID on all components based
 940          * upon the topLevelWindows cached by EventQueueMonitor.
 941          *
 942          * @param eventID the event ID
 943          * @see EventID
 944          */
 945         protected void removeListeners(int eventID) {
 946             Window[] topLevelWindows = EventQueueMonitor.getTopLevelWindows();
 947             if (topLevelWindows != null) {
 948                 for (int i = 0; i < topLevelWindows.length; i++) {
 949                     removeListeners(topLevelWindows[i], eventID);
 950                 }
 951             }
 952         }
 953 
 954         /**
 955          * Removes all listeners for the given component and all its children.
 956          * @param c the component
 957          */
 958         protected void removeListeners(Component c) {
 959 
 960             // conditionally remove low-level listeners
 961             //
 962             if (AWTEventMonitor.componentListener_private != null) {
 963                 removeListeners(c,EventID.COMPONENT);
 964             }
 965             if (AWTEventMonitor.keyListener_private != null) {
 966                 removeListeners(c,EventID.KEY);
 967             }
 968             if (AWTEventMonitor.mouseListener_private != null) {
 969                 removeListeners(c,EventID.MOUSE);
 970             }
 971             if (AWTEventMonitor.mouseMotionListener_private != null) {
 972                 removeListeners(c,EventID.MOTION);
 973             }
 974             if (AWTEventMonitor.windowListener_private != null) {
 975                 removeListeners(c,EventID.WINDOW);
 976             }
 977 
 978             // Remove semantic listeners
 979             //
 980             if (AWTEventMonitor.actionListener_private != null) {
 981                 removeListeners(c,EventID.ACTION);
 982             }
 983             if (AWTEventMonitor.adjustmentListener_private != null) {
 984                 removeListeners(c,EventID.ADJUSTMENT);
 985             }
 986             if (AWTEventMonitor.itemListener_private != null) {
 987                 removeListeners(c,EventID.ITEM);
 988             }
 989             if (AWTEventMonitor.textListener_private != null) {
 990                 removeListeners(c,EventID.TEXT);
 991             }
 992         }
 993 
 994         /**
 995          * Removes all listeners for the event ID from the component and all
 996          * of its children.
 997          *
 998          * @param c the component to remove listeners from
 999          * @see EventID
1000          */
1001         protected void removeListeners(Component c, int eventID) {
1002 
1003             // remove the appropriate listener hook into this component
1004             //
1005             switch (eventID) {
1006 
1007             case EventID.ACTION:
1008                 try {
1009                     removeActionMethod = c.getClass().getMethod(
1010                         "removeActionListener",
1011                         actionListeners);
1012                     try {
1013                         removeActionMethod.invoke(c, actionArgs);
1014                     } catch (java.lang.reflect.InvocationTargetException e) {
1015                         System.out.println("Exception: " + e.toString());
1016                     } catch (IllegalAccessException e) {
1017                         System.out.println("Exception: " + e.toString());
1018                     }
1019                 } catch (NoSuchMethodException e) {
1020                     // System.out.println("Exception: " + e.toString());
1021                 } catch (SecurityException e) {
1022                     System.out.println("Exception: " + e.toString());
1023                 }
1024                 break;
1025 
1026             case EventID.ADJUSTMENT:
1027                 if (c instanceof Adjustable) {
1028                     ((Adjustable) c).removeAdjustmentListener(this);
1029                 }
1030                 break;
1031 
1032             case EventID.COMPONENT:
1033                 c.removeComponentListener(this);
1034                 break;
1035 
1036             // Never remove these because we're always interested in them
1037             // for our own use.
1038             //case EventID.CONTAINER:
1039             //    if (c instanceof Container) {
1040             //        ((Container) c).removeContainerListener(this);
1041             //    }
1042             //    break;
1043             //
1044             //case EventID.FOCUS:
1045             //    c.removeFocusListener(this);
1046             //    break;
1047 
1048             case EventID.ITEM:
1049                 try {
1050                     removeItemMethod = c.getClass().getMethod(
1051                         "removeItemListener", itemListeners);
1052                     try {
1053                         removeItemMethod.invoke(c, itemArgs);
1054                     } catch (java.lang.reflect.InvocationTargetException e) {
1055                         System.out.println("Exception: " + e.toString());
1056                     } catch (IllegalAccessException e) {
1057                         System.out.println("Exception: " + e.toString());
1058                     }
1059                 } catch (NoSuchMethodException e) {
1060                     // System.out.println("Exception: " + e.toString());
1061                 } catch (SecurityException e) {
1062                     System.out.println("Exception: " + e.toString());
1063                 }
1064                 // [PK] CheckboxMenuItem isn't a component but it does
1065                 // implement Interface ItemSelectable!!
1066                 // if (c instanceof CheckboxMenuItem) {
1067                 //     ((CheckboxMenuItem) c).removeItemListener(this);
1068                 break;
1069 
1070             case EventID.KEY:
1071                 c.removeKeyListener(this);
1072                 break;
1073 
1074             case EventID.MOUSE:
1075                 c.removeMouseListener(this);
1076                 break;
1077 
1078             case EventID.MOTION:
1079                 c.removeMouseMotionListener(this);
1080                 break;
1081 
1082             case EventID.TEXT:
1083                 try {
1084                     removeTextMethod = c.getClass().getMethod(
1085                         "removeTextListener", textListeners);
1086                     try {
1087                         removeTextMethod.invoke(c, textArgs);
1088                     } catch (java.lang.reflect.InvocationTargetException e) {
1089                         System.out.println("Exception: " + e.toString());
1090                     } catch (IllegalAccessException e) {
1091                         System.out.println("Exception: " + e.toString());
1092                     }
1093                 } catch (NoSuchMethodException e) {
1094                     // System.out.println("Exception: " + e.toString());
1095                 } catch (SecurityException e) {
1096                     System.out.println("Exception: " + e.toString());
1097                 }
1098                 break;
1099 
1100             case EventID.WINDOW:
1101                 try {
1102                     removeWindowMethod = c.getClass().getMethod(
1103                         "removeWindowListener", windowListeners);
1104                     try {
1105                         removeWindowMethod.invoke(c, windowArgs);
1106                     } catch (java.lang.reflect.InvocationTargetException e) {
1107                         System.out.println("Exception: " + e.toString());
1108                     } catch (IllegalAccessException e) {
1109                         System.out.println("Exception: " + e.toString());
1110                     }
1111                 } catch (NoSuchMethodException e) {
1112                     // System.out.println("Exception: " + e.toString());
1113                 } catch (SecurityException e) {
1114                     System.out.println("Exception: " + e.toString());
1115                 }
1116                 break;
1117 
1118             default:
1119                 return;
1120             }
1121 
1122             if (c instanceof Container) {
1123                 int count = ((Container) c).getComponentCount();
1124                 for (int i = 0; i < count; i++) {
1125                     removeListeners(((Container) c).getComponent(i), eventID);
1126                 }
1127             }
1128         }
1129 
1130         /********************************************************************/
1131         /*                                                                  */
1132         /* Listener Interface Methods                                       */
1133         /*                                                                  */
1134         /********************************************************************/
1135 
1136         /* TopLevelWindow Methods ***************************************/
1137 
1138         /**
1139          * Called when top level window is created.
1140          *
1141          * @see EventQueueMonitor
1142          * @see EventQueueMonitor#addTopLevelWindowListener
1143          */
1144         public void topLevelWindowCreated(Window w) {
1145             installListeners(w);
1146         }
1147 
1148         /**
1149          * Called when top level window is destroyed.
1150          *
1151          * @see EventQueueMonitor
1152          * @see EventQueueMonitor#addTopLevelWindowListener
1153          */
1154         public void topLevelWindowDestroyed(Window w) {
1155         }
1156 
1157         /* ActionListener Methods ***************************************/
1158 
1159         /**
1160          * Called when an action is performed.
1161          *
1162          * @see AWTEventMonitor#addActionListener
1163          */
1164         public void actionPerformed(ActionEvent e) {
1165             if (AWTEventMonitor.actionListener_private != null) {
1166                 AWTEventMonitor.actionListener_private.actionPerformed(e);
1167             }
1168         }
1169 
1170         /* AdjustmentListener Methods ***********************************/
1171 
1172         /**
1173          * Called when an adjustment is made.
1174          *
1175          * @see AWTEventMonitor#addAdjustmentListener
1176          */
1177         public void adjustmentValueChanged(AdjustmentEvent e) {
1178             if (AWTEventMonitor.adjustmentListener_private != null) {
1179                 AWTEventMonitor.adjustmentListener_private.adjustmentValueChanged(e);
1180             }
1181         }
1182 
1183         /* ComponentListener Methods ************************************/
1184 
1185         /**
1186          * Called when a component is hidden.
1187          *
1188          * @see AWTEventMonitor#addComponentListener
1189          */
1190         public void componentHidden(ComponentEvent e) {
1191             if (AWTEventMonitor.componentListener_private != null) {
1192                 AWTEventMonitor.componentListener_private.componentHidden(e);
1193             }
1194         }
1195 
1196         /**
1197          * Called when a component is moved.
1198          *
1199          * @see AWTEventMonitor#addComponentListener
1200          */
1201         public void componentMoved(ComponentEvent e) {
1202             if (AWTEventMonitor.componentListener_private != null) {
1203                 AWTEventMonitor.componentListener_private.componentMoved(e);
1204             }
1205         }
1206 
1207         /**
1208          * Called when a component is resized.
1209          *
1210          * @see AWTEventMonitor#addComponentListener
1211          */
1212         public void componentResized(ComponentEvent e) {
1213             if (AWTEventMonitor.componentListener_private != null) {
1214                 AWTEventMonitor.componentListener_private.componentResized(e);
1215             }
1216         }
1217 
1218         /**
1219          * Called when a component is shown.
1220          *
1221          * @see AWTEventMonitor#addComponentListener
1222          */
1223         public void componentShown(ComponentEvent e) {
1224             if (AWTEventMonitor.componentListener_private != null) {
1225                 AWTEventMonitor.componentListener_private.componentShown(e);
1226             }
1227         }
1228 
1229         /* ContainerListener Methods ************************************/
1230 
1231         /**
1232          * Called when a component is added to a container.
1233          *
1234          * @see AWTEventMonitor#addContainerListener
1235          */
1236         public void componentAdded(ContainerEvent e) {
1237             installListeners(e.getChild());
1238             if (AWTEventMonitor.containerListener_private != null) {
1239                 AWTEventMonitor.containerListener_private.componentAdded(e);
1240             }
1241         }
1242 
1243         /**
1244          * Called when a component is removed from a container.
1245          *
1246          * @see AWTEventMonitor#addContainerListener
1247          */
1248         public void componentRemoved(ContainerEvent e) {
1249             removeListeners(e.getChild());
1250             if (AWTEventMonitor.containerListener_private != null) {
1251                 AWTEventMonitor.containerListener_private.componentRemoved(e);
1252             }
1253         }
1254 
1255         /* FocusListener Methods ****************************************/
1256 
1257         /**
1258          * Called when a component gains keyboard focus.
1259          *
1260          * @see AWTEventMonitor#addFocusListener
1261          */
1262         public void focusGained(FocusEvent e) {
1263             AWTEventMonitor.componentWithFocus_private = (Component) e.getSource();
1264             if (AWTEventMonitor.focusListener_private != null) {
1265                 AWTEventMonitor.focusListener_private.focusGained(e);
1266             }
1267         }
1268 
1269         /**
1270          * Called when a component loses keyboard focus.
1271          *
1272          * @see AWTEventMonitor#addFocusListener
1273          */
1274         public void focusLost(FocusEvent e) {
1275             AWTEventMonitor.componentWithFocus_private = null;
1276             if (AWTEventMonitor.focusListener_private != null) {
1277                 AWTEventMonitor.focusListener_private.focusLost(e);
1278             }
1279         }
1280 
1281         /* ItemListener Methods *****************************************/
1282 
1283         /**
1284          * Called when an item's state changes.
1285          *
1286          * @see AWTEventMonitor#addItemListener
1287          */
1288         public void itemStateChanged(ItemEvent e) {
1289             if (AWTEventMonitor.itemListener_private != null) {
1290                 AWTEventMonitor.itemListener_private.itemStateChanged(e);
1291             }
1292         }
1293 
1294         /* KeyListener Methods ******************************************/
1295 
1296         /**
1297          * Called when a key is pressed.
1298          *
1299          * @see AWTEventMonitor#addKeyListener
1300          */
1301         public void keyPressed(KeyEvent e) {
1302             if (AWTEventMonitor.keyListener_private != null) {
1303                 AWTEventMonitor.keyListener_private.keyPressed(e);
1304             }
1305         }
1306 
1307         /**
1308          * Called when a key is typed.
1309          *
1310          * @see AWTEventMonitor#addKeyListener
1311          */
1312         public void keyReleased(KeyEvent e) {
1313             if (AWTEventMonitor.keyListener_private != null) {
1314                 AWTEventMonitor.keyListener_private.keyReleased(e);
1315             }
1316         }
1317 
1318         /**
1319          * Called when a key is released.
1320          *
1321          * @see AWTEventMonitor#addKeyListener
1322          */
1323         public void keyTyped(KeyEvent e) {
1324             if (AWTEventMonitor.keyListener_private != null) {
1325                 AWTEventMonitor.keyListener_private.keyTyped(e);
1326             }
1327         }
1328 
1329         /* MouseListener Methods ****************************************/
1330 
1331         /**
1332          * Called when the mouse is clicked.
1333          *
1334          * @see AWTEventMonitor#addMouseListener
1335          */
1336         public void mouseClicked(MouseEvent e) {
1337             if (AWTEventMonitor.mouseListener_private != null) {
1338                 AWTEventMonitor.mouseListener_private.mouseClicked(e);
1339             }
1340         }
1341 
1342         /**
1343          * Called when the mouse enters a component.
1344          *
1345          * @see AWTEventMonitor#addMouseListener
1346          */
1347         public void mouseEntered(MouseEvent e) {
1348             if (AWTEventMonitor.mouseListener_private != null) {
1349                 AWTEventMonitor.mouseListener_private.mouseEntered(e);
1350             }
1351         }
1352 
1353         /**
1354          * Called when the mouse leaves a component.
1355          *
1356          * @see AWTEventMonitor#addMouseListener
1357          */
1358         public void mouseExited(MouseEvent e) {
1359             if (AWTEventMonitor.mouseListener_private != null) {
1360                 AWTEventMonitor.mouseListener_private.mouseExited(e);
1361             }
1362         }
1363 
1364         /**
1365          * Called when the mouse is pressed.
1366          *
1367          * @see AWTEventMonitor#addMouseListener
1368          */
1369         public void mousePressed(MouseEvent e) {
1370             if (AWTEventMonitor.mouseListener_private != null) {
1371                 AWTEventMonitor.mouseListener_private.mousePressed(e);
1372             }
1373         }
1374 
1375         /**
1376          * Called when the mouse is released.
1377          *
1378          * @see AWTEventMonitor#addMouseListener
1379          */
1380         public void mouseReleased(MouseEvent e) {
1381             if (AWTEventMonitor.mouseListener_private != null) {
1382                 AWTEventMonitor.mouseListener_private.mouseReleased(e);
1383             }
1384         }
1385 
1386         /* MouseMotionListener Methods **********************************/
1387 
1388         /**
1389          * Called when the mouse is dragged.
1390          *
1391          * @see AWTEventMonitor#addMouseMotionListener
1392          */
1393         public void mouseDragged(MouseEvent e) {
1394             if (AWTEventMonitor.mouseMotionListener_private != null) {
1395                 AWTEventMonitor.mouseMotionListener_private.mouseDragged(e);
1396             }
1397         }
1398 
1399         /**
1400          * Called when the mouse is moved.
1401          *
1402          * @see AWTEventMonitor#addMouseMotionListener
1403          */
1404         public void mouseMoved(MouseEvent e) {
1405             if (AWTEventMonitor.mouseMotionListener_private != null) {
1406                 AWTEventMonitor.mouseMotionListener_private.mouseMoved(e);
1407             }
1408         }
1409 
1410         /* TextListener Methods *****************************************/
1411 
1412         /**
1413          * Called when a component's text value changed.
1414          *
1415          * @see AWTEventMonitor#addTextListener
1416          */
1417         public void textValueChanged(TextEvent e) {
1418             if (AWTEventMonitor.textListener_private != null) {
1419                 AWTEventMonitor.textListener_private.textValueChanged(e);
1420             }
1421         }
1422 
1423         /* WindowListener Methods ***************************************/
1424 
1425         /**
1426          * Called when a window is opened.
1427          *
1428          * @see AWTEventMonitor#addWindowListener
1429          */
1430         public void windowOpened(WindowEvent e) {
1431             if (AWTEventMonitor.windowListener_private != null) {
1432                 AWTEventMonitor.windowListener_private.windowOpened(e);
1433             }
1434         }
1435 
1436         /**
1437          * Called when a window is in the process of closing.
1438          *
1439          * @see AWTEventMonitor#addWindowListener
1440          */
1441         public void windowClosing(WindowEvent e) {
1442             if (AWTEventMonitor.windowListener_private != null) {
1443                 AWTEventMonitor.windowListener_private.windowClosing(e);
1444             }
1445         }
1446 
1447         /**
1448          * Called when a window is closed.
1449          *
1450          * @see AWTEventMonitor#addWindowListener
1451          */
1452         public void windowClosed(WindowEvent e) {
1453             if (AWTEventMonitor.windowListener_private != null) {
1454                 AWTEventMonitor.windowListener_private.windowClosed(e);
1455             }
1456         }
1457 
1458         /**
1459          * Called when a window is iconified.
1460          *
1461          * @see AWTEventMonitor#addWindowListener
1462          */
1463         public void windowIconified(WindowEvent e) {
1464             if (AWTEventMonitor.windowListener_private != null) {
1465                 AWTEventMonitor.windowListener_private.windowIconified(e);
1466             }
1467         }
1468 
1469         /**
1470          * Called when a window is deiconified.
1471          *
1472          * @see AWTEventMonitor#addWindowListener
1473          */
1474         public void windowDeiconified(WindowEvent e) {
1475             if (AWTEventMonitor.windowListener_private != null) {
1476                 AWTEventMonitor.windowListener_private.windowDeiconified(e);
1477             }
1478         }
1479 
1480         /**
1481          * Called when a window is activated.
1482          *
1483          * @see AWTEventMonitor#addWindowListener
1484          */
1485         public void windowActivated(WindowEvent e) {
1486             if (AWTEventMonitor.windowListener_private != null) {
1487                 AWTEventMonitor.windowListener_private.windowActivated(e);
1488             }
1489         }
1490 
1491         /**
1492          * Called when a window is deactivated.
1493          *
1494          * @see AWTEventMonitor#addWindowListener
1495          */
1496         public void windowDeactivated(WindowEvent e) {
1497             if (AWTEventMonitor.windowListener_private != null) {
1498                 AWTEventMonitor.windowListener_private.windowDeactivated(e);
1499             }
1500         }
1501     }
1502 }