1 /*
   2  * Copyright (c) 2002, 2015, 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.util.*;
  29 import java.beans.*;
  30 import java.awt.*;
  31 import java.awt.event.*;
  32 import javax.swing.*;
  33 import javax.swing.event.*;
  34 import javax.swing.table.*;
  35 import javax.swing.tree.*;
  36 import javax.swing.text.*;
  37 import javax.swing.undo.*;
  38 import javax.accessibility.*;
  39 
  40 
  41 /**
  42  * <P>{@code SwingEventMonitor} extends {@link AWTEventMonitor} by adding a suite of
  43  * listeners conditionally installed on every Swing component instance
  44  * in the Java Virtual Machine.  The events captured by these listeners
  45  * are made available through a unified set of listeners supported by
  46  * {@code SwingEventMonitor}.  With this, all the individual events on each of the
  47  * AWT and Swing component instances are funneled into one set of listeners
  48  * broken down by category (see {@link EventID} for the categories).
  49  * <p>This class depends upon {@link EventQueueMonitor}, which provides the base
  50  * level support for capturing the top-level containers as they are created.
  51  * <p>Because this class extends {@code AWTEventMonitor}, it is not
  52  * necessary to use this class and {@code AWTEventMonitor} at the same time.
  53  * If you want to monitor both AWT and Swing components, you should
  54  * use just this class.
  55  * 
  56  * @see AWTEventMonitor
  57  *
  58  */
  59 @jdk.Exported
  60 public class SwingEventMonitor extends AWTEventMonitor {
  61 
  62     /**
  63      * The master list of all listeners registered by other classes.
  64      * This can only be publicly modified by calling the add or
  65      * remove listener methods in this class.
  66      */
  67     static protected final EventListenerList listenerList = new EventListenerList();
  68 
  69     /**
  70      * The actual listener that is installed on the component instances.
  71      * This listener calls the other registered listeners when an event
  72      * occurs.  By doing things this way, the actual number of listeners
  73      * installed on a component instance is drastically reduced.
  74      */
  75     static protected final SwingEventListener swingListener = new SwingEventListener();
  76 
  77     /**
  78      * Adds the specified listener to receive all {@link EventID#ANCESTOR ANCESTOR}
  79      * events on each component instance in the Java Virtual Machine as they occur.
  80      * <P>Note: This listener is automatically added to all component
  81      * instances created after this method is called.  In addition, it
  82      * is only added to component instances that support this listener type.
  83      * 
  84      * @param l the listener to add
  85      * @see #removeAncestorListener
  86      */
  87     static public void addAncestorListener(AncestorListener l) {
  88         if (listenerList.getListenerCount(AncestorListener.class) == 0) {
  89             swingListener.installListeners(EventID.ANCESTOR);
  90         }
  91         listenerList.add(AncestorListener.class, l);
  92     }
  93 
  94     /**
  95      * Removes the specified listener so it no longer receives
  96      * {@link EventID#ANCESTOR ANCESTOR} events when they occur.
  97      * 
  98      * @param l the listener to remove
  99      * @see #addAncestorListener
 100      */
 101     static public void removeAncestorListener(AncestorListener l) {
 102         listenerList.remove(AncestorListener.class, l);
 103         if (listenerList.getListenerCount(AncestorListener.class) == 0) {
 104             swingListener.removeListeners(EventID.ANCESTOR);
 105         }
 106     }
 107 
 108     /**
 109      * Adds the specified listener to receive all {@link EventID#CARET CARET} events
 110      * on each component instance in the Java Virtual Machine as they occur.
 111      * <P>Note: This listener is automatically added to all component
 112      * instances created after this method is called.  In addition, it
 113      * is only added to component instances that support this listener type.
 114      * 
 115      * @param l the listener to add
 116      * @see #removeCaretListener
 117      */
 118     static public void addCaretListener(CaretListener l) {
 119         if (listenerList.getListenerCount(CaretListener.class) == 0) {
 120             swingListener.installListeners(EventID.CARET);
 121         }
 122         listenerList.add(CaretListener.class, l);
 123     }
 124 
 125     /**
 126      * Removes the specified listener so it no longer receives
 127      * {@link EventID#CARET CARET} events when they occur.
 128      *
 129      * @param l the listener to remove
 130      * @see #addCaretListener
 131      */
 132     static public void removeCaretListener(CaretListener l) {
 133         listenerList.remove(CaretListener.class, l);
 134         if (listenerList.getListenerCount(CaretListener.class) == 0) {
 135             swingListener.removeListeners(EventID.CARET);
 136         }
 137     }
 138 
 139     /**
 140      * Adds the specified listener to receive all
 141      * {@link EventID#CELLEDITOR CELLEDITOR} events on each
 142      * component instance in the Java Virtual Machine as they occur.
 143      * <P>Note: This listener is automatically added to all component
 144      * instances created after this method is called.  In addition, it
 145      * is only added to component instances that support this listener type.
 146      *
 147      * @param l the listener to add
 148      * @see #removeCellEditorListener
 149      */
 150     static public void addCellEditorListener(CellEditorListener l) {
 151         if (listenerList.getListenerCount(CellEditorListener.class) == 0) {
 152             swingListener.installListeners(EventID.CELLEDITOR);
 153         }
 154         listenerList.add(CellEditorListener.class, l);
 155     }
 156 
 157     /**
 158      * Removes the specified listener so it no longer receives
 159      * {@link EventID#CELLEDITOR CELLEDITOR} events when they occur.
 160      *
 161      * @param l the listener to remove
 162      * @see #addCellEditorListener
 163      */
 164     static public void removeCellEditorListener(CellEditorListener l) {
 165         listenerList.remove(CellEditorListener.class, l);
 166         if (listenerList.getListenerCount(CellEditorListener.class) == 0) {
 167             swingListener.removeListeners(EventID.CELLEDITOR);
 168         }
 169     }
 170 
 171     /**
 172      * Adds the specified listener to receive all {@link EventID#CHANGE CHANGE}
 173      * events on each component instance in the Java Virtual Machine as they occur.
 174      * <P>Note: This listener is automatically added to all component
 175      * instances created after this method is called.  In addition, it
 176      * is only added to component instances that support this listener type.
 177      * 
 178      * @param l the listener to add
 179      * @see #removeChangeListener
 180      */
 181     static public void addChangeListener(ChangeListener l) {
 182         if (listenerList.getListenerCount(ChangeListener.class) == 0) {
 183             swingListener.installListeners(EventID.CHANGE);
 184         }
 185         listenerList.add(ChangeListener.class, l);
 186     }
 187 
 188     /**
 189      * Removes the specified listener so it no longer receives
 190      * {@link EventID#CHANGE CHANGE} events when they occur.
 191      *
 192      * @param l the listener to remove
 193      * @see #addChangeListener
 194      */
 195     static public void removeChangeListener(ChangeListener l) {
 196         listenerList.remove(ChangeListener.class, l);
 197         if (listenerList.getListenerCount(ChangeListener.class) == 0) {
 198             swingListener.removeListeners(EventID.CHANGE);
 199         }
 200     }
 201 
 202     /**
 203      * Adds the specified listener to receive all {@link EventID#COLUMNMODEL COLUMNMODEL}
 204      * events on each component instance in the Java Virtual Machine as they occur.
 205      * <P>Note: This listener is automatically added to all component
 206      * instances created after this method is called.  In addition, it
 207      * is only added to component instances that support this listener type.
 208      *
 209      * @param l the listener to add
 210      * @see #removeColumnModelListener
 211      */
 212     static public void addColumnModelListener(TableColumnModelListener l) {
 213         if (listenerList.getListenerCount(TableColumnModelListener.class) == 0) {
 214             swingListener.installListeners(EventID.COLUMNMODEL);
 215         }
 216         listenerList.add(TableColumnModelListener.class, l);
 217     }
 218 
 219     /**
 220      * Removes the specified listener so it no longer receives
 221      * {@link EventID#COLUMNMODEL COLUMNMODEL} events when they occur.
 222      *
 223      * @param l the listener to remove
 224      * @see #addColumnModelListener
 225      */
 226     static public void removeColumnModelListener(TableColumnModelListener l) {
 227         listenerList.remove(TableColumnModelListener.class, l);
 228         if (listenerList.getListenerCount(TableColumnModelListener.class) == 0) {
 229             swingListener.removeListeners(EventID.COLUMNMODEL);
 230         }
 231     }
 232 
 233     /**
 234      * Adds the specified listener to receive all {@link EventID#DOCUMENT DOCUMENT}
 235      * events on each component instance in the Java Virtual Machine as they occur.
 236      * <P>Note: This listener is automatically added to all component
 237      * instances created after this method is called.  In addition, it
 238      * is only added to component instances that support this listener type.
 239      *
 240      * @param l the listener to add
 241      * @see #removeDocumentListener
 242      */
 243     static public void addDocumentListener(DocumentListener l) {
 244         if (listenerList.getListenerCount(DocumentListener.class) == 0) {
 245             swingListener.installListeners(EventID.DOCUMENT);
 246         }
 247         listenerList.add(DocumentListener.class, l);
 248     }
 249 
 250     /**
 251      * Removes the specified listener so it no longer receives
 252      * {@link EventID#DOCUMENT DOCUMENT} events when they occur.
 253      *
 254      * @param l the listener to remove
 255      * @see #addDocumentListener
 256      */
 257     static public void removeDocumentListener(DocumentListener l) {
 258         listenerList.remove(DocumentListener.class, l);
 259         if (listenerList.getListenerCount(DocumentListener.class) == 0) {
 260             swingListener.removeListeners(EventID.DOCUMENT);
 261         }
 262     }
 263 
 264     /**
 265      * Adds the specified listener to receive all {@link EventID#LISTDATA LISTDATA}
 266      * events on each component instance in the Java Virtual Machine as they occur.
 267      * <P>Note: This listener is automatically added to all component
 268      * instances created after this method is called.  In addition, it
 269      * is only added to component instances that support this listener type.
 270      *
 271      * @param l the listener to add
 272      * @see #removeListDataListener
 273      */
 274     static public void addListDataListener(ListDataListener l) {
 275         if (listenerList.getListenerCount(ListDataListener.class) == 0) {
 276             swingListener.installListeners(EventID.LISTDATA);
 277         }
 278         listenerList.add(ListDataListener.class, l);
 279     }
 280 
 281     /**
 282      * Removes the specified listener so it no longer receives
 283      * {@link EventID#LISTDATA LISTDATA} events when they occur.
 284      * 
 285      * @param l the listener to remove
 286      * @see #addListDataListener
 287      */
 288     static public void removeListDataListener(ListDataListener l) {
 289         listenerList.remove(ListDataListener.class, l);
 290         if (listenerList.getListenerCount(ListDataListener.class) == 0) {
 291             swingListener.removeListeners(EventID.LISTDATA);
 292         }
 293     }
 294 
 295     /**
 296      * Adds the specified listener to receive all {@link EventID#LISTSELECTION LISTSELECTION}
 297      * events on each component instance in the Java Virtual Machine as they occur.
 298      * <P>Note: This listener is automatically added to all component
 299      * instances created after this method is called.  In addition, it
 300      * is only added to component instances that support this listener type.
 301      * 
 302      * @param l the listener to add
 303      * @see #removeListSelectionListener
 304      */
 305     static public void addListSelectionListener(ListSelectionListener l) {
 306         if (listenerList.getListenerCount(ListSelectionListener.class) == 0) {
 307             swingListener.installListeners(EventID.LISTSELECTION);
 308         }
 309         listenerList.add(ListSelectionListener.class, l);
 310     }
 311 
 312     /**
 313      * Removes the specified listener so it no longer receives
 314      * {@link EventID#LISTSELECTION LISTSELECTION} events when they occur.
 315      * 
 316      * @param l the listener to remove
 317      * @see #addListSelectionListener
 318      */
 319     static public void removeListSelectionListener(ListSelectionListener l) {
 320         listenerList.remove(ListSelectionListener.class, l);
 321         if (listenerList.getListenerCount(ListSelectionListener.class) == 0) {
 322             swingListener.removeListeners(EventID.LISTSELECTION);
 323         }
 324     }
 325 
 326     /**
 327      * Adds the specified listener to receive all {@link EventID#MENU MENU} events
 328      * on each component instance in the Java Virtual Machine as they occur.
 329      * <P>Note: This listener is automatically added to all component
 330      * instances created after this method is called.  In addition, it
 331      * is only added to component instances that support this listener type.
 332      * 
 333      * @param l the listener to add
 334      * @see #removeMenuListener
 335      */
 336     static public void addMenuListener(MenuListener l) {
 337         if (listenerList.getListenerCount(MenuListener.class) == 0) {
 338             swingListener.installListeners(EventID.MENU);
 339         }
 340         listenerList.add(MenuListener.class, l);
 341     }
 342 
 343     /**
 344      * Removes the specified listener so it no longer receives
 345      * {@link EventID#MENU MENU} events when they occur.
 346      * 
 347      * @param l the listener to remove
 348      * @see #addMenuListener
 349      */
 350     static public void removeMenuListener(MenuListener l) {
 351         listenerList.remove(MenuListener.class, l);
 352         if (listenerList.getListenerCount(MenuListener.class) == 0) {
 353             swingListener.removeListeners(EventID.MENU);
 354         }
 355     }
 356 
 357     /**
 358      * Adds the specified listener to receive all {@link EventID#POPUPMENU POPUPMENU}
 359      * events on each component instance in the Java Virtual Machine as they occur.
 360      * <P>Note: This listener is automatically added to all component
 361      * instances created after this method is called.  In addition, it
 362      * is only added to component instances that support this listener type.
 363      * 
 364      * @param l the listener to add
 365      * @see #removePopupMenuListener
 366      */
 367     static public void addPopupMenuListener(PopupMenuListener l) {
 368         if (listenerList.getListenerCount(PopupMenuListener.class) == 0) {
 369             swingListener.installListeners(EventID.POPUPMENU);
 370         }
 371         listenerList.add(PopupMenuListener.class, l);
 372     }
 373 
 374     /**
 375      * Removes the specified listener so it no longer receives
 376      * {@link EventID#POPUPMENU POPUPMENU} events when they occur.
 377      * 
 378      * @param l the listener to remove
 379      * @see #addPopupMenuListener
 380      */
 381     static public void removePopupMenuListener(PopupMenuListener l) {
 382         listenerList.remove(PopupMenuListener.class, l);
 383         if (listenerList.getListenerCount(PopupMenuListener.class) == 0) {
 384             swingListener.removeListeners(EventID.POPUPMENU);
 385         }
 386     }
 387 
 388     /**
 389      * Adds the specified listener to receive all {@link EventID#TABLEMODEL TABLEMODEL}
 390      * events on each component instance in the Java Virtual Machine as they occur.
 391      * <P>Note: This listener is automatically added to all component
 392      * instances created after this method is called.  In addition, it
 393      * is only added to component instances that support this listener type.
 394      * 
 395      * @param l the listener to add
 396      * @see #removeTableModelListener
 397      */
 398     static public void addTableModelListener(TableModelListener l) {
 399         if (listenerList.getListenerCount(TableModelListener.class) == 0) {
 400             swingListener.installListeners(EventID.TABLEMODEL);
 401         }
 402         listenerList.add(TableModelListener.class, l);
 403     }
 404 
 405     /**
 406      * Removes the specified listener so it no longer receives
 407      * {@link EventID#TABLEMODEL TABLEMODEL} events when they occur.
 408      * 
 409      * @param l the listener to remove
 410      * @see #addTableModelListener
 411      */
 412     static public void removeTableModelListener(TableModelListener l) {
 413         listenerList.remove(TableModelListener.class, l);
 414         if (listenerList.getListenerCount(TableModelListener.class) == 0) {
 415             swingListener.removeListeners(EventID.TABLEMODEL);
 416         }
 417     }
 418 
 419     /**
 420      * Adds the specified listener to receive all {@link EventID#TREEEXPANSION TREEEXPANSION}
 421      * events on each component instance in the Java Virtual Machine as they occur.
 422      * <P>Note: This listener is automatically added to all component
 423      * instances created after this method is called.  In addition, it
 424      * is only added to component instances that support this listener type.
 425      * 
 426      * @param l the listener to add
 427      * @see #removeTreeExpansionListener
 428      */
 429     static public void addTreeExpansionListener(TreeExpansionListener l) {
 430         if (listenerList.getListenerCount(TreeExpansionListener.class) == 0) {
 431             swingListener.installListeners(EventID.TREEEXPANSION);
 432         }
 433         listenerList.add(TreeExpansionListener.class, l);
 434     }
 435 
 436     /**
 437      * Removes the specified listener so it no longer receives
 438      * {@link EventID#TREEEXPANSION TREEEXPANSION} events when they occur.
 439      * 
 440      * @param l the listener to remove
 441      * @see #addTreeExpansionListener
 442      */
 443     static public void removeTreeExpansionListener(TreeExpansionListener l) {
 444         listenerList.remove(TreeExpansionListener.class, l);
 445         if (listenerList.getListenerCount(TreeExpansionListener.class) == 0) {
 446             swingListener.removeListeners(EventID.TREEEXPANSION);
 447         }
 448     }
 449 
 450     /**
 451      * Adds the specified listener to receive all {@link EventID#TREEMODEL TREEMODEL}
 452      * events on each component instance in the Java Virtual Machine as they occur.
 453      * <P>Note: This listener is automatically added to all component
 454      * instances created after this method is called.  In addition, it
 455      * is only added to component instances that support this listener type.
 456      * 
 457      * @param l the listener to add
 458      * @see #removeTreeModelListener
 459      */
 460     static public void addTreeModelListener(TreeModelListener l) {
 461         if (listenerList.getListenerCount(TreeModelListener.class) == 0) {
 462             swingListener.installListeners(EventID.TREEMODEL);
 463         }
 464         listenerList.add(TreeModelListener.class, l);
 465     }
 466 
 467     /**
 468      * Removes the specified listener so it no longer receives
 469      * {@link EventID#TREEMODEL TREEMODEL} events when they occur.
 470      * 
 471      * @param l the listener to remove
 472      * @see #addTreeModelListener
 473      */
 474     static public void removeTreeModelListener(TreeModelListener l) {
 475         listenerList.remove(TreeModelListener.class, l);
 476         if (listenerList.getListenerCount(TreeModelListener.class) == 0) {
 477             swingListener.removeListeners(EventID.TREEMODEL);
 478         }
 479     }
 480 
 481     /**
 482      * Adds the specified listener to receive all {@link EventID#TREESELECTION TREESELECTION}
 483      * events on each component instance in the Java Virtual Machine as they occur.
 484      * <P>Note: This listener is automatically added to all component
 485      * instances created after this method is called.  In addition, it
 486      * is only added to component instances that support this listener type.
 487      * 
 488      * @param l the listener to add
 489      * @see #removeTreeSelectionListener
 490      */
 491     static public void addTreeSelectionListener(TreeSelectionListener l) {
 492         if (listenerList.getListenerCount(TreeSelectionListener.class) == 0) {
 493             swingListener.installListeners(EventID.TREESELECTION);
 494         }
 495         listenerList.add(TreeSelectionListener.class, l);
 496     }
 497 
 498     /**
 499      * Removes the specified listener so it no longer receives
 500      * {@link EventID#TREESELECTION TREESELECTION} events when they occur.
 501      * @see #addTreeSelectionListener
 502      * @param l the listener to remove
 503      */
 504     static public void removeTreeSelectionListener(TreeSelectionListener l) {
 505         listenerList.remove(TreeSelectionListener.class, l);
 506         if (listenerList.getListenerCount(TreeSelectionListener.class) == 0) {
 507             swingListener.removeListeners(EventID.TREESELECTION);
 508         }
 509     }
 510 
 511     /**
 512      * Adds the specified listener to receive all {@link EventID#UNDOABLEEDIT UNDOABLEEDIT}
 513      * events on each component instance in the Java Virtual Machine as 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 #removeUndoableEditListener
 520      */
 521     static public void addUndoableEditListener(UndoableEditListener l) {
 522         if (listenerList.getListenerCount(UndoableEditListener.class) == 0) {
 523             swingListener.installListeners(EventID.UNDOABLEEDIT);
 524         }
 525         listenerList.add(UndoableEditListener.class, l);
 526     }
 527 
 528     /**
 529      * Removes the specified listener so it no longer receives
 530      * {@link EventID#UNDOABLEEDIT UNDOABLEEDIT} events when they occur.
 531      * 
 532      * @param l the listener to remove
 533      * @see #addUndoableEditListener
 534      */
 535     static public void removeUndoableEditListener(UndoableEditListener l) {
 536         listenerList.remove(UndoableEditListener.class, l);
 537         if (listenerList.getListenerCount(UndoableEditListener.class) == 0) {
 538             swingListener.removeListeners(EventID.UNDOABLEEDIT);
 539         }
 540     }
 541 
 542     /**
 543      * Adds the specified listener to receive all {@link EventID#INTERNALFRAME INTERNALFRAME}
 544      * events on each component instance in the Java Virtual Machine as they occur.
 545      * <P>Note: This listener is automatically added to all component
 546      * instances created after this method is called.  In addition, it
 547      * is only added to component instances that support this listener type.
 548      * 
 549      * @param l the listener to add
 550      * @see #removeInternalFrameListener
 551      */
 552     static public void addInternalFrameListener(InternalFrameListener l) {
 553         if (listenerList.getListenerCount(InternalFrameListener.class) == 0) {
 554             swingListener.installListeners(EventID.INTERNALFRAME);
 555         }
 556         listenerList.add(InternalFrameListener.class, l);
 557     }
 558 
 559     /**
 560      * Removes the specified listener so it no longer receives
 561      * {@link EventID#INTERNALFRAME INTERNALFRAME} events when they occur.
 562      * 
 563      * @param l the listener to remove
 564      * @see #addInternalFrameListener
 565      */
 566     static public void removeInternalFrameListener(InternalFrameListener l) {
 567         listenerList.remove(InternalFrameListener.class, l);
 568         if (listenerList.getListenerCount(InternalFrameListener.class) == 0) {
 569             swingListener.removeListeners(EventID.INTERNALFRAME);
 570         }
 571     }
 572 
 573     /**
 574      * Adds the specified listener to receive all {@link EventID#PROPERTYCHANGE PROPERTYCHANGE}
 575      * events on each component instance in the Java Virtual Machine as they occur.
 576      * <P>Note: This listener is automatically added to all component
 577      * instances created after this method is called.  In addition, it
 578      * is only added to component instances that support this listener type.
 579      * 
 580      * @param l the listener to add
 581      * @see #removePropertyChangeListener
 582      */
 583     static public void addPropertyChangeListener(PropertyChangeListener l) {
 584         if (listenerList.getListenerCount(PropertyChangeListener.class) == 0) {
 585             swingListener.installListeners(EventID.PROPERTYCHANGE);
 586         }
 587         listenerList.add(PropertyChangeListener.class, l);
 588     }
 589 
 590     /**
 591      * Removes the specified listener so it no longer receives
 592      * {@link EventID#PROPERTYCHANGE PROPERTYCHANGE} events when they occur.
 593      * @see #addPropertyChangeListener
 594      * @param l the listener to remove
 595      */
 596     static public void removePropertyChangeListener(PropertyChangeListener l) {
 597         listenerList.remove(PropertyChangeListener.class, l);
 598         if (listenerList.getListenerCount(PropertyChangeListener.class) == 0) {
 599             swingListener.removeListeners(EventID.PROPERTYCHANGE);
 600         }
 601     }
 602 
 603     /**
 604      * Adds the specified listener to receive all {@link EventID#VETOABLECHANGE VETOABLECHANGE}
 605      * events on each component instance in the Java Virtual Machine as they occur.
 606      * <P>Note: This listener is automatically added to all component
 607      * instances created after this method is called.  In addition, it
 608      * is only added to component instances that support this listener type.
 609      * 
 610      * @param l the listener to add
 611      * @see #removeVetoableChangeListener
 612      */
 613     static public void addVetoableChangeListener(VetoableChangeListener l) {
 614         if (listenerList.getListenerCount(VetoableChangeListener.class) == 0) {
 615             swingListener.installListeners(EventID.VETOABLECHANGE);
 616         }
 617         listenerList.add(VetoableChangeListener.class, l);
 618     }
 619 
 620     /**
 621      * Removes the specified listener so it no longer receives
 622      * {@link EventID#VETOABLECHANGE VETOABLECHANGE} events when they occur.
 623      * 
 624      * @param l the listener to remove
 625      * @see #addVetoableChangeListener
 626      */
 627     static public void removeVetoableChangeListener(VetoableChangeListener l) {
 628         listenerList.remove(VetoableChangeListener.class, l);
 629         if (listenerList.getListenerCount(VetoableChangeListener.class) == 0) {
 630             swingListener.removeListeners(EventID.VETOABLECHANGE);
 631         }
 632     }
 633 
 634 
 635     /**
 636      * SwingEventListener is the class that does all the work for
 637      * SwingEventMonitor.  It is not intended for use by any other class
 638      * except SwingEventMonitor.
 639      *
 640      */
 641     static class SwingEventListener extends AWTEventsListener
 642             implements AncestorListener, CaretListener, CellEditorListener,
 643             ChangeListener, DocumentListener, ListDataListener,
 644             ListSelectionListener, MenuListener, PopupMenuListener,
 645             TableColumnModelListener, TableModelListener, TreeExpansionListener,
 646             TreeModelListener, TreeSelectionListener, UndoableEditListener,
 647             InternalFrameListener,
 648             PropertyChangeListener, VetoableChangeListener {
 649 
 650         /**
 651          * internal variables for Caret introspection
 652          */
 653         private java.lang.Class caretListeners[];
 654         private java.lang.reflect.Method removeCaretMethod;
 655         private java.lang.reflect.Method addCaretMethod;
 656         private java.lang.Object caretArgs[];
 657 
 658         /**
 659          * internal variables for CellEditor introspection
 660          */
 661         private java.lang.Class cellEditorListeners[];
 662         private java.lang.reflect.Method removeCellEditorMethod;
 663         private java.lang.reflect.Method addCellEditorMethod;
 664         private java.lang.Object cellEditorArgs[];
 665         private java.lang.reflect.Method getCellEditorMethod;
 666 
 667         /**
 668          * internal variables for Change introspection
 669          */
 670         private java.lang.Class changeListeners[];
 671         private java.lang.reflect.Method removeChangeMethod;
 672         private java.lang.reflect.Method addChangeMethod;
 673         private java.lang.Object changeArgs[];
 674 
 675         /**
 676          * internal variable for ColumnModel introspection
 677          */
 678         private java.lang.reflect.Method getColumnModelMethod;
 679 
 680         /**
 681          * internal variables for Document introspection
 682          */
 683         private java.lang.Class documentListeners[];
 684         private java.lang.reflect.Method removeDocumentMethod;
 685         private java.lang.reflect.Method addDocumentMethod;
 686         private java.lang.Object documentArgs[];
 687         private java.lang.reflect.Method getDocumentMethod;
 688 
 689         /**
 690          * internal variable for ListData, Table, and Tree introspection
 691          */
 692         private java.lang.reflect.Method getModelMethod;
 693 
 694         /**
 695          * internal variables for ListSelection introspection
 696          */
 697         private java.lang.Class listSelectionListeners[];
 698         private java.lang.reflect.Method removeListSelectionMethod;
 699         private java.lang.reflect.Method addListSelectionMethod;
 700         private java.lang.Object listSelectionArgs[];
 701         private java.lang.reflect.Method getSelectionModelMethod;
 702 
 703         /**
 704          * internal variables for Menu introspection
 705          */
 706         private java.lang.Class menuListeners[];
 707         private java.lang.reflect.Method removeMenuMethod;
 708         private java.lang.reflect.Method addMenuMethod;
 709         private java.lang.Object menuArgs[];
 710 
 711         /**
 712          * internal variables for PopupMenu introspection
 713          */
 714         private java.lang.Class popupMenuListeners[];
 715         private java.lang.reflect.Method removePopupMenuMethod;
 716         private java.lang.reflect.Method addPopupMenuMethod;
 717         private java.lang.Object popupMenuArgs[];
 718         private java.lang.reflect.Method getPopupMenuMethod;
 719 
 720         /**
 721          * internal variables for TreeExpansion introspection
 722          */
 723         private java.lang.Class treeExpansionListeners[];
 724         private java.lang.reflect.Method removeTreeExpansionMethod;
 725         private java.lang.reflect.Method addTreeExpansionMethod;
 726         private java.lang.Object treeExpansionArgs[];
 727 
 728         /**
 729          * internal variables for TreeSelection introspection
 730          */
 731         private java.lang.Class treeSelectionListeners[];
 732         private java.lang.reflect.Method removeTreeSelectionMethod;
 733         private java.lang.reflect.Method addTreeSelectionMethod;
 734         private java.lang.Object treeSelectionArgs[];
 735 
 736         /**
 737          * internal variables for UndoableEdit introspection
 738          */
 739         private java.lang.Class undoableEditListeners[];
 740         private java.lang.reflect.Method removeUndoableEditMethod;
 741         private java.lang.reflect.Method addUndoableEditMethod;
 742         private java.lang.Object undoableEditArgs[];
 743 
 744         /**
 745          * internal variables for InternalFrame introspection
 746          */
 747         private java.lang.Class internalFrameListeners[];
 748         private java.lang.reflect.Method removeInternalFrameMethod;
 749         private java.lang.reflect.Method addInternalFrameMethod;
 750         private java.lang.Object internalFrameArgs[];
 751 
 752         /**
 753          * internal variables for PropertyChange introspection
 754          */
 755         private java.lang.Class propertyChangeListeners[];
 756         private java.lang.reflect.Method removePropertyChangeMethod;
 757         private java.lang.reflect.Method addPropertyChangeMethod;
 758         private java.lang.Object propertyChangeArgs[];
 759 
 760         /**
 761          * internal variables for a variety of change introspections
 762          */
 763         private java.lang.Class nullClass[];
 764         private java.lang.Object nullArgs[];
 765 
 766         /**
 767          * Create a new instance of this class and install it on each component
 768          * instance in the virtual machine that supports any of the currently
 769          * registered listeners in SwingEventMonitor.  Also registers itself
 770          * as a TopLevelWindowListener with EventQueueMonitor so it can
 771          * automatically add new listeners to new components.
 772          * @see EventQueueMonitor
 773          * @see SwingEventMonitor
 774          */
 775         public SwingEventListener() {
 776             initializeIntrospection();
 777             installListeners();
 778             EventQueueMonitor.addTopLevelWindowListener(this);
 779         }
 780 
 781         /**
 782          * Set up all of the variables needed for introspection
 783          */
 784         private boolean initializeIntrospection() {
 785             try {
 786                 caretListeners = new java.lang.Class[1];
 787                 caretArgs = new java.lang.Object[1];
 788                 caretListeners[0] = Class.forName("javax.swing.event.CaretListener");
 789                 caretArgs[0] = this;
 790 
 791                 cellEditorListeners = new java.lang.Class[1];
 792                 cellEditorArgs = new java.lang.Object[1];
 793                 cellEditorListeners[0] = Class.forName("javax.swing.event.CellEditorListener");
 794                 cellEditorArgs[0] = this;
 795 
 796                 changeListeners = new java.lang.Class[1];
 797                 changeArgs = new java.lang.Object[1];
 798                 changeListeners[0] = Class.forName("javax.swing.event.ChangeListener");
 799                 changeArgs[0] = this;
 800 
 801                 documentListeners = new java.lang.Class[1];
 802                 documentArgs = new java.lang.Object[1];
 803                 documentListeners[0] = Class.forName("javax.swing.event.DocumentListener");
 804                 documentArgs[0] = this;
 805 
 806                 listSelectionListeners = new java.lang.Class[1];
 807                 listSelectionArgs = new java.lang.Object[1];
 808                 listSelectionListeners[0] = Class.forName("javax.swing.event.ListSelectionListener");
 809                 listSelectionArgs[0] = this;
 810 
 811                 menuListeners = new java.lang.Class[1];
 812                 menuArgs = new java.lang.Object[1];
 813                 menuListeners[0] = Class.forName("javax.swing.event.MenuListener");
 814                 menuArgs[0] = this;
 815 
 816                 popupMenuListeners = new java.lang.Class[1];
 817                 popupMenuArgs = new java.lang.Object[1];
 818                 popupMenuListeners[0] = Class.forName("javax.swing.event.PopupMenuListener");
 819                 popupMenuArgs[0] = this;
 820 
 821                 treeExpansionListeners = new java.lang.Class[1];
 822                 treeExpansionArgs = new java.lang.Object[1];
 823                 treeExpansionListeners[0] = Class.forName("javax.swing.event.TreeExpansionListener");
 824                 treeExpansionArgs[0] = this;
 825 
 826                 treeSelectionListeners = new java.lang.Class[1];
 827                 treeSelectionArgs = new java.lang.Object[1];
 828                 treeSelectionListeners[0] = Class.forName("javax.swing.event.TreeSelectionListener");
 829                 treeSelectionArgs[0] = this;
 830 
 831                 undoableEditListeners = new java.lang.Class[1];
 832                 undoableEditArgs = new java.lang.Object[1];
 833                 undoableEditListeners[0] = Class.forName("javax.swing.event.UndoableEditListener");
 834                 undoableEditArgs[0] = this;
 835 
 836                 internalFrameListeners = new java.lang.Class[1];
 837                 internalFrameArgs = new java.lang.Object[1];
 838                 internalFrameListeners[0] = Class.forName("javax.swing.event.InternalFrameListener");
 839                 internalFrameArgs[0] = this;
 840 
 841                 nullClass = new java.lang.Class[0];
 842                 nullArgs = new java.lang.Object[0];
 843 
 844             } catch (ClassNotFoundException e) {
 845                 System.out.println("EXCEPTION - Class 'javax.swing.event.*' not in CLASSPATH");
 846                 return false;
 847             }
 848 
 849             try {
 850                 propertyChangeListeners = new java.lang.Class[1];
 851                 propertyChangeArgs = new java.lang.Object[1];
 852                 propertyChangeListeners[0] = Class.forName("java.beans.PropertyChangeListener");
 853                 propertyChangeArgs[0] = this;
 854 
 855             } catch (ClassNotFoundException e) {
 856                 System.out.println("EXCEPTION - Class 'java.beans.*' not in CLASSPATH");
 857                 return false;
 858             }
 859 
 860             return true;
 861         }
 862 
 863         /**
 864          * Installs all appropriate Swing listeners to just the component.
 865          * Also calls super (AWTEventsListener.installListeners()) to install
 866          * the requested AWT listeners.
 867          * @param c the component to add listeners to
 868          */
 869         protected void installListeners(Component c) {
 870 
 871             // This SwingEventListener needs to be notified when a new
 872             // Swing component has been added so it can add Swing listeners
 873             // to these components.  As a result, we always need a Container
 874             // listener on every Container.
 875             //
 876             installListeners(c,EventID.CONTAINER);
 877 
 878             // conditionally install Swing listeners
 879             //
 880             if (SwingEventMonitor.listenerList.getListenerCount(AncestorListener.class) > 0) {
 881                 installListeners(c,EventID.ANCESTOR);
 882             }
 883             if (SwingEventMonitor.listenerList.getListenerCount(CaretListener.class) > 0) {
 884                 installListeners(c,EventID.CARET);
 885             }
 886             if (SwingEventMonitor.listenerList.getListenerCount(CellEditorListener.class) > 0) {
 887                 installListeners(c,EventID.CELLEDITOR);
 888             }
 889             if (SwingEventMonitor.listenerList.getListenerCount(ChangeListener.class) > 0) {
 890                 installListeners(c,EventID.CHANGE);
 891             }
 892             if (SwingEventMonitor.listenerList.getListenerCount(TableColumnModelListener.class) > 0) {
 893                 installListeners(c,EventID.COLUMNMODEL);
 894             }
 895             if (SwingEventMonitor.listenerList.getListenerCount(DocumentListener.class) > 0) {
 896                 installListeners(c,EventID.DOCUMENT);
 897             }
 898             if (SwingEventMonitor.listenerList.getListenerCount(ListDataListener.class) > 0) {
 899                 installListeners(c,EventID.LISTDATA);
 900             }
 901             if (SwingEventMonitor.listenerList.getListenerCount(ListSelectionListener.class) > 0) {
 902                 installListeners(c,EventID.LISTSELECTION);
 903             }
 904             if (SwingEventMonitor.listenerList.getListenerCount(MenuListener.class) > 0) {
 905                 installListeners(c,EventID.MENU);
 906             }
 907             if (SwingEventMonitor.listenerList.getListenerCount(PopupMenuListener.class) > 0) {
 908                 installListeners(c,EventID.POPUPMENU);
 909             }
 910             if (SwingEventMonitor.listenerList.getListenerCount(TableModelListener.class) > 0) {
 911                 installListeners(c,EventID.TABLEMODEL);
 912             }
 913             if (SwingEventMonitor.listenerList.getListenerCount(TreeExpansionListener.class) > 0) {
 914                 installListeners(c,EventID.TREEEXPANSION);
 915             }
 916             if (SwingEventMonitor.listenerList.getListenerCount(TreeModelListener.class) > 0) {
 917                 installListeners(c,EventID.TREEMODEL);
 918             }
 919             if (SwingEventMonitor.listenerList.getListenerCount(TreeSelectionListener.class) > 0) {
 920                 installListeners(c,EventID.TREESELECTION);
 921             }
 922             if (SwingEventMonitor.listenerList.getListenerCount(UndoableEditListener.class) > 0) {
 923                 installListeners(c,EventID.UNDOABLEEDIT);
 924             }
 925             if (SwingEventMonitor.listenerList.getListenerCount(InternalFrameListener.class) > 0) {
 926                 installListeners(c,EventID.INTERNALFRAME);
 927             }
 928 
 929             // Conditionally install Beans listeners
 930             //
 931             if (SwingEventMonitor.listenerList.getListenerCount(PropertyChangeListener.class) > 0) {
 932                 installListeners(c,EventID.PROPERTYCHANGE);
 933             }
 934             if (SwingEventMonitor.listenerList.getListenerCount(VetoableChangeListener.class) > 0) {
 935                 installListeners(c,EventID.VETOABLECHANGE);
 936             }
 937 
 938             // Now install the AWT listeners if needed.
 939             //
 940             super.installListeners(c);
 941         }
 942 
 943         /**
 944          * Installs all appropriate Swing listeners to the component and all its
 945          * children.  As a precaution, it always attempts to remove itself as
 946          * a listener first so we're always guaranteed it will installed itself
 947          * just once.
 948          * @param c the component to add listeners to
 949          * @param eventID the eventID to add listeners for
 950          */
 951         protected void installListeners(Component c, int eventID) {
 952 
 953             // install the appropriate listener hook into this component
 954             //
 955             switch (eventID) {
 956 
 957             case EventID.CONTAINER:
 958                 if (c instanceof Container) {
 959                     ((Container) c).removeContainerListener(this);
 960                     ((Container) c).addContainerListener(this);
 961                 }
 962                 break;
 963 
 964             case EventID.ANCESTOR:
 965                 if (c instanceof JComponent) {
 966                     ((JComponent) c).removeAncestorListener(this);
 967                     ((JComponent) c).addAncestorListener(this);
 968                 }
 969                 break;
 970 
 971             case EventID.CARET:
 972                 try {
 973                     removeCaretMethod = c.getClass().getMethod(
 974                         "removeCaretListener", caretListeners);
 975                     addCaretMethod = c.getClass().getMethod(
 976                         "addCaretListener", caretListeners);
 977                     try {
 978                         removeCaretMethod.invoke(c, caretArgs);
 979                         addCaretMethod.invoke(c, caretArgs);
 980                     } catch (java.lang.reflect.InvocationTargetException e) {
 981                         System.out.println("Exception: " + e.toString());
 982                     } catch (IllegalAccessException e) {
 983                         System.out.println("Exception: " + e.toString());
 984                     }
 985                 } catch (NoSuchMethodException e) {
 986                     // System.out.println("Exception: " + e.toString());
 987                 } catch (SecurityException e) {
 988                     System.out.println("Exception: " + e.toString());
 989                 }
 990                 break;
 991 
 992             case EventID.CELLEDITOR:
 993                 //  Look for components which support the getCellEditor method
 994                 //  (e.g. JTable, JTree)
 995                 //
 996                 try {
 997                     getCellEditorMethod = c.getClass().getMethod(
 998                         "getCellEditorMethod", nullClass);
 999                     try {
1000                         Object o = getCellEditorMethod.invoke(c, nullArgs);
1001                         if (o != null && o instanceof CellEditor) {
1002                             ((CellEditor) o).removeCellEditorListener(this);
1003                             ((CellEditor) o).addCellEditorListener(this);
1004                         }
1005                     } catch (java.lang.reflect.InvocationTargetException e) {
1006                         System.out.println("Exception: " + e.toString());
1007                     } catch (IllegalAccessException e) {
1008                         System.out.println("Exception: " + e.toString());
1009                     }
1010                 } catch (NoSuchMethodException e) {
1011                     // System.out.println("Exception: " + e.toString());
1012                 } catch (SecurityException e) {
1013                     System.out.println("Exception: " + e.toString());
1014                 }
1015 
1016                 //  Look for components which support CellEditor listeners
1017                 //  (no current example)
1018                 //
1019                 try {
1020                     removeCellEditorMethod = c.getClass().getMethod(
1021                         "removeCellEditorListener", cellEditorListeners);
1022                     addCellEditorMethod = c.getClass().getMethod(
1023                         "addCellEditorListener", cellEditorListeners);
1024                     try {
1025                         removeCellEditorMethod.invoke(c, cellEditorArgs);
1026                         addCellEditorMethod.invoke(c, cellEditorArgs);
1027                     } catch (java.lang.reflect.InvocationTargetException e) {
1028                         System.out.println("Exception: " + e.toString());
1029                     } catch (IllegalAccessException e) {
1030                         System.out.println("Exception: " + e.toString());
1031                     }
1032                 } catch (NoSuchMethodException e) {
1033                     // System.out.println("Exception: " + e.toString());
1034                 } catch (SecurityException e) {
1035                     System.out.println("Exception: " + e.toString());
1036                 }
1037                 break;
1038 
1039             case EventID.CHANGE:
1040     //  [[[FIXME:  Need to add support for Style, StyleContext  -pk]]]
1041 
1042                 //  Look for components which support Change listeners
1043                 //  (e.g. AbstractButton, Caret, JProgressBar, JSlider,
1044                 //   JTabbedpane, JTextComponent, JViewport)
1045                 //
1046                 try {
1047                     removeChangeMethod = c.getClass().getMethod(
1048                         "removeChangeListener", changeListeners);
1049                     addChangeMethod = c.getClass().getMethod(
1050                         "addChangeListener", changeListeners);
1051                     try {
1052                         removeChangeMethod.invoke(c, changeArgs);
1053                         addChangeMethod.invoke(c, changeArgs);
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 
1065                 //  Look for components which support the getModel method
1066                 //  whose model supports Change listeners
1067                 //  (e.g. BoundedRangeModel, ButtonModel, SingleSelectionModel)
1068                 //
1069                 try {
1070                     getModelMethod = c.getClass().getMethod(
1071                         "getModel", nullClass);
1072                     try {
1073                         Object o = getModelMethod.invoke(c, nullArgs);
1074                         if (o != null) {
1075                             removeChangeMethod = o.getClass().getMethod(
1076                                 "removeChangeListener", changeListeners);
1077                             addChangeMethod = o.getClass().getMethod(
1078                                 "addChangeListener", changeListeners);
1079                             removeChangeMethod.invoke(o, changeArgs);
1080                             addChangeMethod.invoke(o, changeArgs);
1081                         }
1082                     } catch (java.lang.reflect.InvocationTargetException e) {
1083                         System.out.println("Exception: " + e.toString());
1084                     } catch (IllegalAccessException e) {
1085                         System.out.println("Exception: " + e.toString());
1086                     }
1087                 } catch (NoSuchMethodException e) {
1088                     // System.out.println("Exception: " + e.toString());
1089                 } catch (SecurityException e) {
1090                     System.out.println("Exception: " + e.toString());
1091                 }
1092 
1093                 break;
1094 
1095             case EventID.COLUMNMODEL:
1096                 try {
1097                     getColumnModelMethod = c.getClass().getMethod(
1098                         "getTableColumnModel", nullClass);
1099                     try {
1100                         Object o = getColumnModelMethod.invoke(c, nullArgs);
1101                         if (o != null && o instanceof TableColumnModel) {
1102                             ((TableColumnModel) o).removeColumnModelListener(this);
1103                             ((TableColumnModel) o).addColumnModelListener(this);
1104                         }
1105                     } catch (java.lang.reflect.InvocationTargetException e) {
1106                         System.out.println("Exception: " + e.toString());
1107                     } catch (IllegalAccessException e) {
1108                         System.out.println("Exception: " + e.toString());
1109                     }
1110                 } catch (NoSuchMethodException e) {
1111                     // System.out.println("Exception: " + e.toString());
1112                 } catch (SecurityException e) {
1113                     System.out.println("Exception: " + e.toString());
1114                 }
1115                 break;
1116 
1117             case EventID.DOCUMENT:
1118                 //  Look for components which support the getDocument method
1119                 //  (e.g. JTextComponent)
1120                 //
1121                 try {
1122                     getDocumentMethod = c.getClass().getMethod(
1123                         "getDocument", nullClass);
1124                     try {
1125                         Object o = getDocumentMethod.invoke(c, nullArgs);
1126                         if (o != null && o instanceof Document) {
1127                             ((Document) o).removeDocumentListener(this);
1128                             ((Document) o).addDocumentListener(this);
1129                         }
1130                     } catch (java.lang.reflect.InvocationTargetException e) {
1131                         System.out.println("Exception: " + e.toString());
1132                     } catch (IllegalAccessException e) {
1133                         System.out.println("Exception: " + e.toString());
1134                     }
1135                 } catch (NoSuchMethodException e) {
1136                     // System.out.println("Exception: " + e.toString());
1137                 } catch (SecurityException e) {
1138                     System.out.println("Exception: " + e.toString());
1139                 }
1140 
1141                 //  Look for components which support Document listeners
1142                 //  (no current example)
1143                 //
1144                 try {
1145                     removeDocumentMethod = c.getClass().getMethod(
1146                         "removeDocumentListener", documentListeners);
1147                     addDocumentMethod = c.getClass().getMethod(
1148                         "addDocumentListener", documentListeners);
1149                     try {
1150                         removeDocumentMethod.invoke(c, documentArgs);
1151                         addDocumentMethod.invoke(c, documentArgs);
1152                     } catch (java.lang.reflect.InvocationTargetException e) {
1153                         System.out.println("Exception: " + e.toString());
1154                     } catch (IllegalAccessException e) {
1155                         System.out.println("Exception: " + e.toString());
1156                     }
1157                 } catch (NoSuchMethodException e) {
1158                     // System.out.println("Exception: " + e.toString());
1159                 } catch (SecurityException e) {
1160                     System.out.println("Exception: " + e.toString());
1161                 }
1162                 //  Add the monitor as a PropertyChangeListener for document
1163                 //  change events from text components.
1164                 //
1165                 if (c instanceof JTextComponent) {
1166                     try {
1167                         removePropertyChangeMethod = c.getClass().getMethod(
1168                             "removePropertyChangeListener",
1169                             propertyChangeListeners);
1170                         addPropertyChangeMethod = c.getClass().getMethod(
1171                             "addPropertyChangeListener",
1172                             propertyChangeListeners);
1173                         try {
1174                             removePropertyChangeMethod.invoke(c,
1175                                 propertyChangeArgs);
1176                             addPropertyChangeMethod.invoke(c,
1177                                 propertyChangeArgs);
1178                         } catch (java.lang.reflect.InvocationTargetException e) {
1179                             System.out.println("Exception: " + e.toString());
1180                         } catch (IllegalAccessException e) {
1181                             System.out.println("Exception: " + e.toString());
1182                         }
1183                     } catch (NoSuchMethodException e) {
1184                         // System.out.println("Exception: " + e.toString());
1185                     } catch (SecurityException e) {
1186                         System.out.println("Exception: " + e.toString());
1187                     }
1188                 }
1189                 break;
1190 
1191             case EventID.LISTDATA:
1192             case EventID.TABLEMODEL:
1193             case EventID.TREEMODEL:
1194                 try {
1195                     getModelMethod = c.getClass().getMethod(
1196                         "getModel", nullClass);
1197                     try {
1198                         Object o = getModelMethod.invoke(c, nullArgs);
1199                         if (o != null) {
1200                             if (eventID == EventID.LISTDATA &&
1201                                 o instanceof ListModel) {
1202                                 ((ListModel) o).removeListDataListener(this);
1203                                 ((ListModel) o).addListDataListener(this);
1204                             } else if (eventID == EventID.TABLEMODEL &&
1205                                 o instanceof TableModel) {
1206                                 ((TableModel) o).removeTableModelListener(this);
1207                                 ((TableModel) o).addTableModelListener(this);
1208                             } else if (
1209                                 o instanceof TreeModel) {
1210                                 ((TreeModel) o).removeTreeModelListener(this);
1211                                 ((TreeModel) o).addTreeModelListener(this);
1212                             }
1213                         }
1214                     } catch (java.lang.reflect.InvocationTargetException e) {
1215                         System.out.println("Exception: " + e.toString());
1216                     } catch (IllegalAccessException e) {
1217                         System.out.println("Exception: " + e.toString());
1218                     }
1219                 } catch (NoSuchMethodException e) {
1220                     // System.out.println("Exception: " + e.toString());
1221                 } catch (SecurityException e) {
1222                     System.out.println("Exception: " + e.toString());
1223                 }
1224                 break;
1225 
1226             case EventID.LISTSELECTION:
1227                 //  Look for components which support ListSelectionListeners
1228                 //  (e.g. JList)
1229                 //
1230                 try {
1231                     removeListSelectionMethod = c.getClass().getMethod(
1232                         "removeListSelectionListener", listSelectionListeners);
1233                     addListSelectionMethod = c.getClass().getMethod(
1234                         "addListSelectionListener", listSelectionListeners);
1235                     try {
1236                         removeListSelectionMethod.invoke(c, listSelectionArgs);
1237                         addListSelectionMethod.invoke(c, listSelectionArgs);
1238                     } catch (java.lang.reflect.InvocationTargetException e) {
1239                         System.out.println("Exception: " + e.toString());
1240                     } catch (IllegalAccessException e) {
1241                         System.out.println("Exception: " + e.toString());
1242                     }
1243                 } catch (NoSuchMethodException e) {
1244                     // System.out.println("Exception: " + e.toString());
1245                 } catch (SecurityException e) {
1246                     System.out.println("Exception: " + e.toString());
1247                 }
1248 
1249                 //  Look for selection models which support ListSelectionListeners
1250                 //  (e.g. JTable's selection model)
1251                 //
1252                 try {
1253                     getSelectionModelMethod = c.getClass().getMethod(
1254                         "getSelectionModel", nullClass);
1255                     try {
1256                         Object o = getSelectionModelMethod.invoke(c, nullArgs);
1257                         if (o != null && o instanceof ListSelectionModel) {
1258                             ((ListSelectionModel) o).removeListSelectionListener(this);
1259                             ((ListSelectionModel) o).addListSelectionListener(this);
1260                         }
1261                     } catch (java.lang.reflect.InvocationTargetException e) {
1262                         System.out.println("Exception: " + e.toString());
1263                     } catch (IllegalAccessException e) {
1264                         System.out.println("Exception: " + e.toString());
1265                     }
1266                 } catch (NoSuchMethodException e) {
1267                     // System.out.println("Exception: " + e.toString());
1268                 } catch (SecurityException e) {
1269                     System.out.println("Exception: " + e.toString());
1270                 }
1271                 break;
1272 
1273             case EventID.MENU:
1274                 try {
1275                     removeMenuMethod = c.getClass().getMethod(
1276                         "removeMenuListener", menuListeners);
1277                     addMenuMethod = c.getClass().getMethod(
1278                         "addMenuListener", menuListeners);
1279                     try {
1280                         removeMenuMethod.invoke(c, menuArgs);
1281                         addMenuMethod.invoke(c, menuArgs);
1282                     } catch (java.lang.reflect.InvocationTargetException e) {
1283                         System.out.println("Exception: " + e.toString());
1284                     } catch (IllegalAccessException e) {
1285                         System.out.println("Exception: " + e.toString());
1286                     }
1287                 } catch (NoSuchMethodException e) {
1288                     // System.out.println("Exception: " + e.toString());
1289                 } catch (SecurityException e) {
1290                     System.out.println("Exception: " + e.toString());
1291                 }
1292                 break;
1293 
1294             case EventID.POPUPMENU:
1295                 //  Look for components which support PopupMenuListeners
1296                 //  (e.g. JPopupMenu)
1297                 //
1298                 try {
1299                     removePopupMenuMethod = c.getClass().getMethod(
1300                         "removePopupMenuListener", popupMenuListeners);
1301                     addPopupMenuMethod = c.getClass().getMethod(
1302                         "addPopupMenuListener", popupMenuListeners);
1303                     try {
1304                         removePopupMenuMethod.invoke(c, popupMenuArgs);
1305                         addPopupMenuMethod.invoke(c, popupMenuArgs);
1306                     } catch (java.lang.reflect.InvocationTargetException e) {
1307                         System.out.println("Exception: " + e.toString());
1308                     } catch (IllegalAccessException e) {
1309                         System.out.println("Exception: " + e.toString());
1310                     }
1311                 } catch (NoSuchMethodException e) {
1312                     // System.out.println("Exception: " + e.toString());
1313                 } catch (SecurityException e) {
1314                     System.out.println("Exception: " + e.toString());
1315                 }
1316 
1317                 //  Look for components which support getPopupMenu
1318                 //  (e.g. JMenu)
1319                 //
1320                 try {
1321                     getPopupMenuMethod = c.getClass().getMethod(
1322                         "getPopupMenu", nullClass);
1323                     try {
1324                         Object o = getPopupMenuMethod.invoke(c, nullArgs);
1325                         if (o != null) {
1326                             removePopupMenuMethod = o.getClass().getMethod(
1327                                 "removePopupMenuListener", popupMenuListeners);
1328                             addPopupMenuMethod = o.getClass().getMethod(
1329                                 "addPopupMenuListener", popupMenuListeners);
1330                             removePopupMenuMethod.invoke(o, popupMenuArgs);
1331                             addPopupMenuMethod.invoke(o, popupMenuArgs);
1332                         }
1333                     } catch (java.lang.reflect.InvocationTargetException e) {
1334                         System.out.println("Exception: " + e.toString());
1335                     } catch (IllegalAccessException e) {
1336                         System.out.println("Exception: " + e.toString());
1337                     }
1338                 } catch (NoSuchMethodException e) {
1339                     // System.out.println("Exception: " + e.toString());
1340                 } catch (SecurityException e) {
1341                     System.out.println("Exception: " + e.toString());
1342                 }
1343                 break;
1344 
1345             case EventID.TREEEXPANSION:
1346                 try {
1347                     removeTreeExpansionMethod = c.getClass().getMethod(
1348                         "removeTreeExpansionListener", treeExpansionListeners);
1349                     addTreeExpansionMethod = c.getClass().getMethod(
1350                         "addTreeExpansionListener", treeExpansionListeners);
1351                     try {
1352                         removeTreeExpansionMethod.invoke(c, treeExpansionArgs);
1353                         addTreeExpansionMethod.invoke(c, treeExpansionArgs);
1354                     } catch (java.lang.reflect.InvocationTargetException e) {
1355                         System.out.println("Exception: " + e.toString());
1356                     } catch (IllegalAccessException e) {
1357                         System.out.println("Exception: " + e.toString());
1358                     }
1359                 } catch (NoSuchMethodException e) {
1360                     // System.out.println("Exception: " + e.toString());
1361                 } catch (SecurityException e) {
1362                     System.out.println("Exception: " + e.toString());
1363                 }
1364                 break;
1365 
1366             case EventID.TREESELECTION:
1367                 try {
1368                     removeTreeSelectionMethod = c.getClass().getMethod(
1369                         "removeTreeSelectionListener", treeSelectionListeners);
1370                     addTreeSelectionMethod = c.getClass().getMethod(
1371                         "addTreeSelectionListener", treeSelectionListeners);
1372                     try {
1373                         removeTreeSelectionMethod.invoke(c, treeSelectionArgs);
1374                         addTreeSelectionMethod.invoke(c, treeSelectionArgs);
1375                     } catch (java.lang.reflect.InvocationTargetException e) {
1376                         System.out.println("Exception: " + e.toString());
1377                     } catch (IllegalAccessException e) {
1378                         System.out.println("Exception: " + e.toString());
1379                     }
1380                 } catch (NoSuchMethodException e) {
1381                     // System.out.println("Exception: " + e.toString());
1382                 } catch (SecurityException e) {
1383                     System.out.println("Exception: " + e.toString());
1384                 }
1385                 break;
1386 
1387             case EventID.UNDOABLEEDIT:
1388                 //  Look for components which support the getDocument method
1389                 //  (e.g. JTextComponent)
1390                 //
1391                 try {
1392                     getDocumentMethod = c.getClass().getMethod(
1393                         "getDocument", nullClass);
1394                     try {
1395                         Object o = getDocumentMethod.invoke(c, nullArgs);
1396                         if (o != null && o instanceof Document) {
1397                             ((Document) o).removeUndoableEditListener(this);
1398                             ((Document) o).addUndoableEditListener(this);
1399                         }
1400                     } catch (java.lang.reflect.InvocationTargetException e) {
1401                         System.out.println("Exception: " + e.toString());
1402                     } catch (IllegalAccessException e) {
1403                         System.out.println("Exception: " + e.toString());
1404                     }
1405                 } catch (NoSuchMethodException e) {
1406                     // System.out.println("Exception: " + e.toString());
1407                 } catch (SecurityException e) {
1408                     System.out.println("Exception: " + e.toString());
1409                 }
1410 
1411                 //  Look for components which support UndoableEdit listeners
1412                 //  (no current example)
1413                 //
1414                 try {
1415                     removeUndoableEditMethod = c.getClass().getMethod(
1416                         "removeUndoableEditListener", undoableEditListeners);
1417                     addUndoableEditMethod = c.getClass().getMethod(
1418                         "addUndoableEditListener", undoableEditListeners);
1419                     try {
1420                         removeUndoableEditMethod.invoke(c, undoableEditArgs);
1421                         addUndoableEditMethod.invoke(c, undoableEditArgs);
1422                     } catch (java.lang.reflect.InvocationTargetException e) {
1423                         System.out.println("Exception: " + e.toString());
1424                     } catch (IllegalAccessException e) {
1425                         System.out.println("Exception: " + e.toString());
1426                     }
1427                 } catch (NoSuchMethodException e) {
1428                     // System.out.println("Exception: " + e.toString());
1429                 } catch (SecurityException e) {
1430                     System.out.println("Exception: " + e.toString());
1431                 }
1432                 break;
1433 
1434             case EventID.INTERNALFRAME:
1435                 //  Look for components which support InternalFrame listeners
1436                 //  (e.g. JInternalFrame)
1437                 //
1438               try {
1439                     removeInternalFrameMethod = c.getClass().getMethod(
1440                         "removeInternalFrameListener", internalFrameListeners);
1441                     addInternalFrameMethod = c.getClass().getMethod(
1442                         "addInternalFrameListener", internalFrameListeners);
1443                     try {
1444                         removeInternalFrameMethod.invoke(c, internalFrameArgs);
1445                         addInternalFrameMethod.invoke(c, internalFrameArgs);
1446                     } catch (java.lang.reflect.InvocationTargetException e) {
1447                         System.out.println("Exception: " + e.toString());
1448                     } catch (IllegalAccessException e) {
1449                         System.out.println("Exception: " + e.toString());
1450                     }
1451                 } catch (NoSuchMethodException e) {
1452                     // System.out.println("Exception: " + e.toString());
1453                 } catch (SecurityException e) {
1454                     System.out.println("Exception: " + e.toString());
1455                 }
1456                 break;
1457 
1458             case EventID.PROPERTYCHANGE:
1459                 //  Look for components which support PropertyChange listeners
1460                 //  (e.g. JComponent)
1461                 //
1462                 try {
1463                     removePropertyChangeMethod = c.getClass().getMethod(
1464                         "removePropertyChangeListener", propertyChangeListeners);
1465                     addPropertyChangeMethod = c.getClass().getMethod(
1466                         "addPropertyChangeListener", propertyChangeListeners);
1467                     try {
1468                         removePropertyChangeMethod.invoke(c, propertyChangeArgs);
1469                         addPropertyChangeMethod.invoke(c, propertyChangeArgs);
1470                     } catch (java.lang.reflect.InvocationTargetException e) {
1471                         System.out.println("Exception: " + e.toString());
1472                     } catch (IllegalAccessException e) {
1473                         System.out.println("Exception: " + e.toString());
1474                     }
1475                 } catch (NoSuchMethodException e) {
1476                     // System.out.println("Exception: " + e.toString());
1477                 } catch (SecurityException e) {
1478                     System.out.println("Exception: " + e.toString());
1479                 }
1480 
1481                 //  Look for components which support the getSelectionModel method
1482                 //  (e.g. JTextComponent)
1483                 //
1484                 try {
1485                     getSelectionModelMethod = c.getClass().getMethod(
1486                         "getSelectionModel", nullClass);
1487                     try {
1488                         Object o = getSelectionModelMethod.invoke(c, nullArgs);
1489                         if (o != null && o instanceof TreeSelectionModel) {
1490                             ((TreeSelectionModel) o).removePropertyChangeListener(this);
1491                             ((TreeSelectionModel) o).addPropertyChangeListener(this);
1492                         }
1493                     } catch (java.lang.reflect.InvocationTargetException e) {
1494                         System.out.println("Exception: " + e.toString());
1495                     } catch (IllegalAccessException e) {
1496                         System.out.println("Exception: " + e.toString());
1497                     }
1498                 } catch (NoSuchMethodException e) {
1499                     // System.out.println("Exception: " + e.toString());
1500                 } catch (SecurityException e) {
1501                     System.out.println("Exception: " + e.toString());
1502                 }
1503                 break;
1504 
1505             case EventID.VETOABLECHANGE:
1506                 if (c instanceof JComponent) {
1507                     ((JComponent) c).removeVetoableChangeListener(this);
1508                     ((JComponent) c).addVetoableChangeListener(this);
1509                 }
1510                 break;
1511 
1512             // Don't bother recursing the children if this isn't going to
1513             // accomplish anything.
1514             //
1515             default:
1516                 return;
1517             }
1518 
1519             if (c instanceof Container) {
1520                 int count = ((Container) c).getComponentCount();
1521                 for (int i = 0; i < count; i++) {
1522                     installListeners(((Container) c).getComponent(i), eventID);
1523                 }
1524             }
1525         }
1526 
1527         /**
1528          * Removes all listeners for the given component and all its children.
1529          * @param c the component
1530          */
1531         protected void removeListeners(Component c) {
1532 
1533             // conditionaly remove the Swing listeners
1534             //
1535             if (SwingEventMonitor.listenerList.getListenerCount(AncestorListener.class) > 0) {
1536                 removeListeners(c,EventID.ANCESTOR);
1537             }
1538             if (SwingEventMonitor.listenerList.getListenerCount(CaretListener.class) > 0) {
1539                 removeListeners(c,EventID.CARET);
1540             }
1541             if (SwingEventMonitor.listenerList.getListenerCount(CellEditorListener.class) > 0) {
1542                 removeListeners(c,EventID.CELLEDITOR);
1543             }
1544             if (SwingEventMonitor.listenerList.getListenerCount(ChangeListener.class) > 0) {
1545                 removeListeners(c,EventID.CHANGE);
1546             }
1547             if (SwingEventMonitor.listenerList.getListenerCount(TableColumnModelListener.class) > 0) {
1548                 removeListeners(c,EventID.COLUMNMODEL);
1549             }
1550             if (SwingEventMonitor.listenerList.getListenerCount(DocumentListener.class) > 0) {
1551                 removeListeners(c,EventID.DOCUMENT);
1552             }
1553             if (SwingEventMonitor.listenerList.getListenerCount(ListDataListener.class) > 0) {
1554                 removeListeners(c,EventID.LISTDATA);
1555             }
1556             if (SwingEventMonitor.listenerList.getListenerCount(ListSelectionListener.class) > 0) {
1557                 removeListeners(c,EventID.LISTSELECTION);
1558             }
1559             if (SwingEventMonitor.listenerList.getListenerCount(MenuListener.class) > 0) {
1560                 removeListeners(c,EventID.MENU);
1561             }
1562             if (SwingEventMonitor.listenerList.getListenerCount(PopupMenuListener.class) > 0) {
1563                 removeListeners(c,EventID.POPUPMENU);
1564             }
1565             if (SwingEventMonitor.listenerList.getListenerCount(TableModelListener.class) > 0) {
1566                 removeListeners(c,EventID.TABLEMODEL);
1567             }
1568             if (SwingEventMonitor.listenerList.getListenerCount(TreeExpansionListener.class) > 0) {
1569                 removeListeners(c,EventID.TREEEXPANSION);
1570             }
1571             if (SwingEventMonitor.listenerList.getListenerCount(TreeModelListener.class) > 0) {
1572                 removeListeners(c,EventID.TREEMODEL);
1573             }
1574             if (SwingEventMonitor.listenerList.getListenerCount(TreeSelectionListener.class) > 0) {
1575                 removeListeners(c,EventID.TREESELECTION);
1576             }
1577             if (SwingEventMonitor.listenerList.getListenerCount(UndoableEditListener.class) > 0) {
1578                 removeListeners(c,EventID.UNDOABLEEDIT);
1579             }
1580             if (SwingEventMonitor.listenerList.getListenerCount(InternalFrameListener.class) > 0) {
1581                 removeListeners(c,EventID.INTERNALFRAME);
1582             }
1583 
1584             // conditionaly remove the beans listeners
1585             //
1586             if (SwingEventMonitor.listenerList.getListenerCount(PropertyChangeListener.class) > 0) {
1587                 removeListeners(c,EventID.PROPERTYCHANGE);
1588             }
1589             if (SwingEventMonitor.listenerList.getListenerCount(VetoableChangeListener.class) > 0) {
1590                 removeListeners(c,EventID.VETOABLECHANGE);
1591             }
1592 
1593             // Now remove the AWT listeners if needed.
1594             //
1595             super.removeListeners(c);
1596         }
1597 
1598         /**
1599          * Removes all Swing listeners for the event ID from the component and
1600          * all of its children.
1601          * @param c the component to remove listeners from
1602          */
1603         protected void removeListeners(Component c, int eventID) {
1604 
1605             // remove the appropriate listener hook into this component
1606             //
1607             switch (eventID) {
1608 
1609             case EventID.CONTAINER:
1610                 //Never remove these because we're always interested in them
1611                 // for our own use.
1612                 break;
1613 
1614             case EventID.ANCESTOR:
1615                 if (c instanceof JComponent) {
1616                     ((JComponent) c).removeAncestorListener(this);
1617                 }
1618                 break;
1619 
1620             case EventID.CARET:
1621                 try {
1622                     removeCaretMethod = c.getClass().getMethod(
1623                         "removeCaretListener", caretListeners);
1624                     try {
1625                         removeCaretMethod.invoke(c, caretArgs);
1626                     } catch (java.lang.reflect.InvocationTargetException e) {
1627                         System.out.println("Exception: " + e.toString());
1628                     } catch (IllegalAccessException e) {
1629                         System.out.println("Exception: " + e.toString());
1630                     }
1631                 } catch (NoSuchMethodException e) {
1632                     // System.out.println("Exception: " + e.toString());
1633                 } catch (SecurityException e) {
1634                     System.out.println("Exception: " + e.toString());
1635                 }
1636                 break;
1637 
1638             case EventID.CELLEDITOR:
1639                 //  Look for components which support the getCellEditor method
1640                 //  (e.g. JTable, JTree)
1641                 //
1642                 try {
1643                     getCellEditorMethod = c.getClass().getMethod(
1644                         "getCellEditorMethod", nullClass);
1645                     try {
1646                         Object o = getCellEditorMethod.invoke(c, nullArgs);
1647                         if (o != null && o instanceof CellEditor) {
1648                             ((CellEditor) o).removeCellEditorListener(this);
1649                         }
1650                     } catch (java.lang.reflect.InvocationTargetException e) {
1651                         System.out.println("Exception: " + e.toString());
1652                     } catch (IllegalAccessException e) {
1653                         System.out.println("Exception: " + e.toString());
1654                     }
1655                 } catch (NoSuchMethodException e) {
1656                     // System.out.println("Exception: " + e.toString());
1657                 } catch (SecurityException e) {
1658                     System.out.println("Exception: " + e.toString());
1659                 }
1660 
1661                 //  Look for components which support CellEditor listeners
1662                 //  (no current example)
1663                 //
1664                 try {
1665                     removeCellEditorMethod = c.getClass().getMethod(
1666                         "removeCellEditorListener", cellEditorListeners);
1667                     try {
1668                         removeCellEditorMethod.invoke(c, cellEditorArgs);
1669                     } catch (java.lang.reflect.InvocationTargetException e) {
1670                         System.out.println("Exception: " + e.toString());
1671                     } catch (IllegalAccessException e) {
1672                         System.out.println("Exception: " + e.toString());
1673                     }
1674                 } catch (NoSuchMethodException e) {
1675                     // System.out.println("Exception: " + e.toString());
1676                 } catch (SecurityException e) {
1677                     System.out.println("Exception: " + e.toString());
1678                 }
1679                 break;
1680 
1681             case EventID.CHANGE:
1682     //  [[[FIXME:  Need to add support for Style, StyleContext -pk ]]]
1683 
1684                 //  Look for components which support Change listeners
1685                 //  (e.g. AbstractButton, Caret, JProgressBar, JSlider,
1686                 //   JTabbedpane, JTextComponent, JViewport)
1687                 //
1688                 try {
1689                     removeChangeMethod = c.getClass().getMethod(
1690                         "removeChangeListener", changeListeners);
1691                     try {
1692                         removeChangeMethod.invoke(c, changeArgs);
1693                     } catch (java.lang.reflect.InvocationTargetException e) {
1694                         System.out.println("Exception: " + e.toString());
1695                     } catch (IllegalAccessException e) {
1696                         System.out.println("Exception: " + e.toString());
1697                     }
1698                 } catch (NoSuchMethodException e) {
1699                     // System.out.println("Exception: " + e.toString());
1700                 } catch (SecurityException e) {
1701                     System.out.println("Exception: " + e.toString());
1702                 }
1703 
1704                 //  Look for components which support the getModel method
1705                 //  whose model supports Change listeners
1706                 //  (e.g. BoundedRangeModel, ButtonModel, SingleSelectionModel)
1707                 //
1708                 try {
1709                     getModelMethod = c.getClass().getMethod(
1710                         "getModel", nullClass);
1711                     try {
1712                         Object o = getModelMethod.invoke(c, nullArgs);
1713                         if (o != null) {
1714                             removeChangeMethod = o.getClass().getMethod(
1715                                 "removeChangeListener", changeListeners);
1716                             removeChangeMethod.invoke(o, changeArgs);
1717                         }
1718                     } catch (java.lang.reflect.InvocationTargetException e) {
1719                         System.out.println("Exception: " + e.toString());
1720                     } catch (IllegalAccessException e) {
1721                         System.out.println("Exception: " + e.toString());
1722                     }
1723                 } catch (NoSuchMethodException e) {
1724                     // System.out.println("Exception: " + e.toString());
1725                 } catch (SecurityException e) {
1726                     System.out.println("Exception: " + e.toString());
1727                 }
1728                 break;
1729 
1730             case EventID.COLUMNMODEL:
1731                 try {
1732                     getColumnModelMethod = c.getClass().getMethod(
1733                         "getTableColumnModel", nullClass);
1734                     try {
1735                         Object o = getColumnModelMethod.invoke(c, nullArgs);
1736                         if (o != null && o instanceof TableColumnModel) {
1737                             ((TableColumnModel) o).removeColumnModelListener(this);
1738                         }
1739                     } catch (java.lang.reflect.InvocationTargetException e) {
1740                         System.out.println("Exception: " + e.toString());
1741                     } catch (IllegalAccessException e) {
1742                         System.out.println("Exception: " + e.toString());
1743                     }
1744                 } catch (NoSuchMethodException e) {
1745                     // System.out.println("Exception: " + e.toString());
1746                 } catch (SecurityException e) {
1747                     System.out.println("Exception: " + e.toString());
1748                 }
1749                 break;
1750 
1751             case EventID.DOCUMENT:
1752                 //  Look for components which support the getDocument method
1753                 //  (e.g. JTextComponent)
1754                 //
1755                 try {
1756                     getDocumentMethod = c.getClass().getMethod(
1757                         "getDocument", nullClass);
1758                     try {
1759                         Object o = getDocumentMethod.invoke(c, nullArgs);
1760                         if (o != null && o instanceof Document) {
1761                             ((Document) o).removeDocumentListener(this);
1762                         }
1763                     } catch (java.lang.reflect.InvocationTargetException e) {
1764                         System.out.println("Exception: " + e.toString());
1765                     } catch (IllegalAccessException e) {
1766                         System.out.println("Exception: " + e.toString());
1767                     }
1768                 } catch (NoSuchMethodException e) {
1769                     // System.out.println("Exception: " + e.toString());
1770                 } catch (SecurityException e) {
1771                     System.out.println("Exception: " + e.toString());
1772                 }
1773 
1774                 //  Look for components which support Document listeners
1775                 //  (no current example)
1776                 //
1777                 try {
1778                     removeDocumentMethod = c.getClass().getMethod(
1779                         "removeDocumentListener", documentListeners);
1780                     try {
1781                         removeDocumentMethod.invoke(c, documentArgs);
1782                     } catch (java.lang.reflect.InvocationTargetException e) {
1783                         System.out.println("Exception: " + e.toString());
1784                     } catch (IllegalAccessException e) {
1785                         System.out.println("Exception: " + e.toString());
1786                     }
1787                 } catch (NoSuchMethodException e) {
1788                     // System.out.println("Exception: " + e.toString());
1789                 } catch (SecurityException e) {
1790                     System.out.println("Exception: " + e.toString());
1791                 }
1792                 break;
1793 
1794             case EventID.LISTDATA:
1795             case EventID.TABLEMODEL:
1796             case EventID.TREEMODEL:
1797                 try {
1798                     getModelMethod = c.getClass().getMethod(
1799                         "getModel", nullClass);
1800                     try {
1801                         Object o = getModelMethod.invoke(c, nullArgs);
1802                         if (o != null) {
1803                             if (eventID == EventID.LISTDATA &&
1804                                 o instanceof ListModel) {
1805                                 ((ListModel) o).removeListDataListener(this);
1806                             } else if (eventID == EventID.TABLEMODEL &&
1807                                 o instanceof TableModel) {
1808                                 ((TableModel) o).removeTableModelListener(this);
1809                             } else if (
1810                                 o instanceof TreeModel) {
1811                                 ((TreeModel) o).removeTreeModelListener(this);
1812                             }
1813                         }
1814                     } catch (java.lang.reflect.InvocationTargetException e) {
1815                         System.out.println("Exception: " + e.toString());
1816                     } catch (IllegalAccessException e) {
1817                         System.out.println("Exception: " + e.toString());
1818                     }
1819                 } catch (NoSuchMethodException e) {
1820                     // System.out.println("Exception: " + e.toString());
1821                 } catch (SecurityException e) {
1822                     System.out.println("Exception: " + e.toString());
1823                 }
1824                 break;
1825 
1826             case EventID.LISTSELECTION:
1827                 //  Look for components which support ListSelectionListeners
1828                 //  (e.g. JList)
1829                 //
1830                 try {
1831                     removeListSelectionMethod = c.getClass().getMethod(
1832                         "removeListSelectionListener", listSelectionListeners);
1833                     try {
1834                         removeListSelectionMethod.invoke(c, listSelectionArgs);
1835                     } catch (java.lang.reflect.InvocationTargetException e) {
1836                         System.out.println("Exception: " + e.toString());
1837                     } catch (IllegalAccessException e) {
1838                         System.out.println("Exception: " + e.toString());
1839                     }
1840                 } catch (NoSuchMethodException e) {
1841                     // System.out.println("Exception: " + e.toString());
1842                 } catch (SecurityException e) {
1843                     System.out.println("Exception: " + e.toString());
1844                 }
1845 
1846                 // Look for selection models which support
1847                 // ListSelectionListeners (e.g. JTable's selection model)
1848                 //
1849                 try {
1850                     getSelectionModelMethod = c.getClass().getMethod(
1851                         "getSelectionModel", nullClass);
1852                     try {
1853                         Object o = getSelectionModelMethod.invoke(c, nullArgs);
1854                         if (o != null && o instanceof ListSelectionModel) {
1855                             ((ListSelectionModel) o).removeListSelectionListener(this);
1856                         }
1857                     } catch (java.lang.reflect.InvocationTargetException e) {
1858                         System.out.println("Exception: " + e.toString());
1859                     } catch (IllegalAccessException e) {
1860                         System.out.println("Exception: " + e.toString());
1861                     }
1862                 } catch (NoSuchMethodException e) {
1863                     // System.out.println("Exception: " + e.toString());
1864                 } catch (SecurityException e) {
1865                     System.out.println("Exception: " + e.toString());
1866                 }
1867                 break;
1868 
1869             case EventID.MENU:
1870                 try {
1871                     removeMenuMethod = c.getClass().getMethod(
1872                         "removeMenuListener", menuListeners);
1873                     try {
1874                         removeMenuMethod.invoke(c, menuArgs);
1875                     } catch (java.lang.reflect.InvocationTargetException e) {
1876                         System.out.println("Exception: " + e.toString());
1877                     } catch (IllegalAccessException e) {
1878                         System.out.println("Exception: " + e.toString());
1879                     }
1880                 } catch (NoSuchMethodException e) {
1881                     // System.out.println("Exception: " + e.toString());
1882                 } catch (SecurityException e) {
1883                     System.out.println("Exception: " + e.toString());
1884                 }
1885                 break;
1886 
1887             case EventID.POPUPMENU:
1888                 //  Look for components which support PopupMenuListeners
1889                 //  (e.g. JPopupMenu)
1890                 //
1891                 try {
1892                     removePopupMenuMethod = c.getClass().getMethod(
1893                         "removePopupMenuListener", popupMenuListeners);
1894                     try {
1895                         removePopupMenuMethod.invoke(c, popupMenuArgs);
1896                     } catch (java.lang.reflect.InvocationTargetException e) {
1897                         System.out.println("Exception: " + e.toString());
1898                     } catch (IllegalAccessException e) {
1899                         System.out.println("Exception: " + e.toString());
1900                     }
1901                 } catch (NoSuchMethodException e) {
1902                     // System.out.println("Exception: " + e.toString());
1903                 } catch (SecurityException e) {
1904                     System.out.println("Exception: " + e.toString());
1905                 }
1906 
1907                 //  Look for components which support getPopupMenu
1908                 //  (e.g. JMenu)
1909                 //
1910                 try {
1911                     getPopupMenuMethod = c.getClass().getMethod(
1912                         "getPopupMenu", nullClass);
1913                     try {
1914                         Object o = getPopupMenuMethod.invoke(c, nullArgs);
1915                         if (o != null) {
1916                             removePopupMenuMethod = o.getClass().getMethod(
1917                                 "removePopupMenuListener", popupMenuListeners);
1918                             removePopupMenuMethod.invoke(o, popupMenuArgs);
1919                         }
1920                     } catch (java.lang.reflect.InvocationTargetException e) {
1921                         System.out.println("Exception: " + e.toString());
1922                     } catch (IllegalAccessException e) {
1923                         System.out.println("Exception: " + e.toString());
1924                     }
1925                 } catch (NoSuchMethodException e) {
1926                     // System.out.println("Exception: " + e.toString());
1927                 } catch (SecurityException e) {
1928                     System.out.println("Exception: " + e.toString());
1929                 }
1930                 break;
1931 
1932             case EventID.TREEEXPANSION:
1933                 try {
1934                     removeTreeExpansionMethod = c.getClass().getMethod(
1935                         "removeTreeExpansionListener", treeExpansionListeners);
1936                     try {
1937                         removeTreeExpansionMethod.invoke(c, treeExpansionArgs);
1938                     } catch (java.lang.reflect.InvocationTargetException e) {
1939                         System.out.println("Exception: " + e.toString());
1940                     } catch (IllegalAccessException e) {
1941                         System.out.println("Exception: " + e.toString());
1942                     }
1943                 } catch (NoSuchMethodException e) {
1944                     // System.out.println("Exception: " + e.toString());
1945                 } catch (SecurityException e) {
1946                     System.out.println("Exception: " + e.toString());
1947                 }
1948                 break;
1949 
1950             case EventID.TREESELECTION:
1951                 try {
1952                     removeTreeSelectionMethod = c.getClass().getMethod(
1953                         "removeTreeSelectionListener", treeSelectionListeners);
1954                     try {
1955                         removeTreeSelectionMethod.invoke(c, treeSelectionArgs);
1956                     } catch (java.lang.reflect.InvocationTargetException e) {
1957                         System.out.println("Exception: " + e.toString());
1958                     } catch (IllegalAccessException e) {
1959                         System.out.println("Exception: " + e.toString());
1960                     }
1961                 } catch (NoSuchMethodException e) {
1962                     // System.out.println("Exception: " + e.toString());
1963                 } catch (SecurityException e) {
1964                     System.out.println("Exception: " + e.toString());
1965                 }
1966                 break;
1967 
1968             case EventID.UNDOABLEEDIT:
1969                 //  Look for components which support the getDocument method
1970                 //  (e.g. JTextComponent)
1971                 //
1972                 try {
1973                     getDocumentMethod = c.getClass().getMethod(
1974                         "getDocument", nullClass);
1975                     try {
1976                         Object o = getDocumentMethod.invoke(c, nullArgs);
1977                         if (o != null && o instanceof Document) {
1978                             ((Document) o).removeUndoableEditListener(this);
1979                         }
1980                     } catch (java.lang.reflect.InvocationTargetException e) {
1981                         System.out.println("Exception: " + e.toString());
1982                     } catch (IllegalAccessException e) {
1983                         System.out.println("Exception: " + e.toString());
1984                     }
1985                 } catch (NoSuchMethodException e) {
1986                     // System.out.println("Exception: " + e.toString());
1987                 } catch (SecurityException e) {
1988                     System.out.println("Exception: " + e.toString());
1989                 }
1990 
1991                 //  Look for components which support UndoableEdit listeners
1992                 //  (no current example)
1993                 //
1994                 try {
1995                     removeUndoableEditMethod = c.getClass().getMethod(
1996                         "removeUndoableEditListener", undoableEditListeners);
1997                     try {
1998                         removeUndoableEditMethod.invoke(c, undoableEditArgs);
1999                     } catch (java.lang.reflect.InvocationTargetException e) {
2000                         System.out.println("Exception: " + e.toString());
2001                     } catch (IllegalAccessException e) {
2002                         System.out.println("Exception: " + e.toString());
2003                     }
2004                 } catch (NoSuchMethodException e) {
2005                     // System.out.println("Exception: " + e.toString());
2006                 } catch (SecurityException e) {
2007                     System.out.println("Exception: " + e.toString());
2008                 }
2009                 break;
2010 
2011             case EventID.INTERNALFRAME:
2012               try {
2013                     removeInternalFrameMethod = c.getClass().getMethod(
2014                         "removeInternalFrameListener", internalFrameListeners);
2015                     try {
2016                         removeInternalFrameMethod.invoke(c, internalFrameArgs);
2017                     } catch (java.lang.reflect.InvocationTargetException e) {
2018                         System.out.println("Exception: " + e.toString());
2019                     } catch (IllegalAccessException e) {
2020                         System.out.println("Exception: " + e.toString());
2021                     }
2022                 } catch (NoSuchMethodException e) {
2023                     // System.out.println("Exception: " + e.toString());
2024                 } catch (SecurityException e) {
2025                     System.out.println("Exception: " + e.toString());
2026                 }
2027                 break;
2028 
2029             case EventID.PROPERTYCHANGE:
2030                 //  Look for components which support PropertyChange listeners
2031                 //  (e.g. JComponent)
2032                 //
2033                 try {
2034                     removePropertyChangeMethod = c.getClass().getMethod(
2035                         "removePropertyChangeListener", propertyChangeListeners);
2036                     try {
2037                         removePropertyChangeMethod.invoke(c, propertyChangeArgs);
2038                     } catch (java.lang.reflect.InvocationTargetException e) {
2039                         System.out.println("Exception: " + e.toString());
2040                     } catch (IllegalAccessException e) {
2041                         System.out.println("Exception: " + e.toString());
2042                     }
2043                 } catch (NoSuchMethodException e) {
2044                     // System.out.println("Exception: " + e.toString());
2045                 } catch (SecurityException e) {
2046                     System.out.println("Exception: " + e.toString());
2047                 }
2048 
2049                 // Look for components which support the getSelectionModel
2050                 // method (e.g. JTextComponent)
2051                 //
2052                 try {
2053                     getSelectionModelMethod = c.getClass().getMethod(
2054                         "getSelectionModel", nullClass);
2055                     try {
2056                         Object o = getSelectionModelMethod.invoke(c, nullArgs);
2057                         if (o != null && o instanceof TreeSelectionModel) {
2058                             ((TreeSelectionModel) o).removePropertyChangeListener(this);
2059                         }
2060                     } catch (java.lang.reflect.InvocationTargetException e) {
2061                         System.out.println("Exception: " + e.toString());
2062                     } catch (IllegalAccessException e) {
2063                         System.out.println("Exception: " + e.toString());
2064                     }
2065                 } catch (NoSuchMethodException e) {
2066                     // System.out.println("Exception: " + e.toString());
2067                 } catch (SecurityException e) {
2068                     System.out.println("Exception: " + e.toString());
2069                 }
2070                 break;
2071 
2072             case EventID.VETOABLECHANGE:
2073                 if (c instanceof JComponent) {
2074                     ((JComponent) c).removeVetoableChangeListener(this);
2075                 }
2076                 break;
2077 
2078             default:
2079                 return;
2080             }
2081 
2082             if (c instanceof Container) {
2083                 int count = ((Container) c).getComponentCount();
2084                 for (int i = 0; i < count; i++) {
2085                     removeListeners(((Container) c).getComponent(i), eventID);
2086                 }
2087             }
2088         }
2089 
2090         /********************************************************************/
2091         /*                                                                  */
2092         /* Listener Interface Methods                                       */
2093         /*                                                                  */
2094         /********************************************************************/
2095 
2096         /* ContainerListener Methods ************************************/
2097 
2098         public void componentAdded(ContainerEvent e) {
2099             installListeners(e.getChild());
2100         }
2101         public void componentRemoved(ContainerEvent e) {
2102             removeListeners(e.getChild());
2103         }
2104 
2105         /* AncestorListener Methods ******************************************/
2106 
2107         public void ancestorAdded(AncestorEvent e) {
2108             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2109             for (int i = listeners.length-2; i>=0; i-=2) {
2110                 if (listeners[i]==AncestorListener.class) {
2111                     ((AncestorListener)listeners[i+1]).ancestorAdded(e);
2112                 }
2113             }
2114         }
2115 
2116         public void ancestorRemoved(AncestorEvent e) {
2117             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2118             for (int i = listeners.length-2; i>=0; i-=2) {
2119                 if (listeners[i]==AncestorListener.class) {
2120                     ((AncestorListener)listeners[i+1]).ancestorRemoved(e);
2121                 }
2122             }
2123         }
2124 
2125         public void ancestorMoved(AncestorEvent e) {
2126             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2127             for (int i = listeners.length-2; i>=0; i-=2) {
2128                 if (listeners[i]==AncestorListener.class) {
2129                     ((AncestorListener)listeners[i+1]).ancestorMoved(e);
2130                 }
2131             }
2132         }
2133 
2134         /* CaretListener Methods ******************************************/
2135 
2136         public void caretUpdate(CaretEvent e) {
2137             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2138             for (int i = listeners.length-2; i>=0; i-=2) {
2139                 if (listeners[i]==CaretListener.class) {
2140                     ((CaretListener)listeners[i+1]).caretUpdate(e);
2141                 }
2142             }
2143         }
2144 
2145         /* CellEditorListener Methods *****************************************/
2146 
2147         public void editingStopped(ChangeEvent e) {
2148             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2149             for (int i = listeners.length-2; i>=0; i-=2) {
2150                 if (listeners[i]==CellEditorListener.class) {
2151                     ((CellEditorListener)listeners[i+1]).editingStopped(e);
2152                 }
2153             }
2154         }
2155 
2156         public void editingCanceled(ChangeEvent e) {
2157             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2158             for (int i = listeners.length-2; i>=0; i-=2) {
2159                 if (listeners[i]==CellEditorListener.class) {
2160                     ((CellEditorListener)listeners[i+1]).editingCanceled(e);
2161                 }
2162             }
2163         }
2164 
2165         /* ChangeListener Methods *****************************************/
2166 
2167         public void stateChanged(ChangeEvent e) {
2168             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2169             for (int i = listeners.length-2; i>=0; i-=2) {
2170                 if (listeners[i]==ChangeListener.class) {
2171                     ((ChangeListener)listeners[i+1]).stateChanged(e);
2172                 }
2173             }
2174         }
2175 
2176         /* TableColumnModelListener Methods *******************************/
2177 
2178         public void columnAdded(TableColumnModelEvent e) {
2179             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2180             for (int i = listeners.length-2; i>=0; i-=2) {
2181                 if (listeners[i]==TableColumnModelListener.class) {
2182                     ((TableColumnModelListener)listeners[i+1]).columnAdded(e);
2183                 }
2184             }
2185         }
2186         public void columnMarginChanged(ChangeEvent e) {
2187             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2188             for (int i = listeners.length-2; i>=0; i-=2) {
2189                 if (listeners[i]==TableColumnModelListener.class) {
2190                     ((TableColumnModelListener)listeners[i+1]).columnMarginChanged(e);
2191                 }
2192             }
2193         }
2194         public void columnMoved(TableColumnModelEvent e) {
2195             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2196             for (int i = listeners.length-2; i>=0; i-=2) {
2197                 if (listeners[i]==TableColumnModelListener.class) {
2198                     ((TableColumnModelListener)listeners[i+1]).columnMoved(e);
2199                 }
2200             }
2201         }
2202         public void columnRemoved(TableColumnModelEvent e) {
2203             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2204             for (int i = listeners.length-2; i>=0; i-=2) {
2205                 if (listeners[i]==TableColumnModelListener.class) {
2206                     ((TableColumnModelListener)listeners[i+1]).columnRemoved(e);
2207                 }
2208             }
2209         }
2210         public void columnSelectionChanged(ListSelectionEvent e) {
2211             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2212             for (int i = listeners.length-2; i>=0; i-=2) {
2213                 if (listeners[i]==TableColumnModelListener.class) {
2214                     ((TableColumnModelListener)listeners[i+1]).columnSelectionChanged(e);
2215                 }
2216             }
2217         }
2218 
2219         /* DocumentListener Methods **************************************/
2220 
2221         public void changedUpdate(DocumentEvent e) {
2222             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2223             for (int i = listeners.length-2; i>=0; i-=2) {
2224                 if (listeners[i]==DocumentListener.class) {
2225                     ((DocumentListener)listeners[i+1]).changedUpdate(e);
2226                 }
2227             }
2228         }
2229         public void insertUpdate(DocumentEvent e) {
2230             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2231             for (int i = listeners.length-2; i>=0; i-=2) {
2232                 if (listeners[i]==DocumentListener.class) {
2233                     ((DocumentListener)listeners[i+1]).insertUpdate(e);
2234                 }
2235             }
2236         }
2237         public void removeUpdate(DocumentEvent e) {
2238             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2239             for (int i = listeners.length-2; i>=0; i-=2) {
2240                 if (listeners[i]==DocumentListener.class) {
2241                     ((DocumentListener)listeners[i+1]).removeUpdate(e);
2242                 }
2243             }
2244         }
2245 
2246         /* ListDataListener Methods *****************************************/
2247 
2248         public void contentsChanged(ListDataEvent e) {
2249             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2250             for (int i = listeners.length-2; i>=0; i-=2) {
2251                 if (listeners[i]==ListDataListener.class) {
2252                     ((ListDataListener)listeners[i+1]).contentsChanged(e);
2253                 }
2254             }
2255         }
2256         public void intervalAdded(ListDataEvent e) {
2257             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2258             for (int i = listeners.length-2; i>=0; i-=2) {
2259                 if (listeners[i]==ListDataListener.class) {
2260                     ((ListDataListener)listeners[i+1]).intervalAdded(e);
2261                 }
2262             }
2263         }
2264         public void intervalRemoved(ListDataEvent e) {
2265             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2266             for (int i = listeners.length-2; i>=0; i-=2) {
2267                 if (listeners[i]==ListDataListener.class) {
2268                     ((ListDataListener)listeners[i+1]).intervalRemoved(e);
2269                 }
2270             }
2271         }
2272 
2273         /* ListSelectionListener Methods ***********************************/
2274 
2275         public void valueChanged(ListSelectionEvent e) {
2276             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2277             for (int i = listeners.length-2; i>=0; i-=2) {
2278                 if (listeners[i]==ListSelectionListener.class) {
2279                     ((ListSelectionListener)listeners[i+1]).valueChanged(e);
2280                 }
2281             }
2282         }
2283 
2284         /* MenuListener Methods *****************************************/
2285 
2286         public void menuCanceled(MenuEvent e) {
2287             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2288             for (int i = listeners.length-2; i>=0; i-=2) {
2289                 if (listeners[i]==MenuListener.class) {
2290                     ((MenuListener)listeners[i+1]).menuCanceled(e);
2291                 }
2292             }
2293         }
2294         public void menuDeselected(MenuEvent e) {
2295             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2296             for (int i = listeners.length-2; i>=0; i-=2) {
2297                 if (listeners[i]==MenuListener.class) {
2298                     ((MenuListener)listeners[i+1]).menuDeselected(e);
2299                 }
2300             }
2301         }
2302         public void menuSelected(MenuEvent e) {
2303             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2304             for (int i = listeners.length-2; i>=0; i-=2) {
2305                 if (listeners[i]==MenuListener.class) {
2306                     ((MenuListener)listeners[i+1]).menuSelected(e);
2307                 }
2308             }
2309         }
2310 
2311         /* PopupMenuListener Methods **************************************/
2312 
2313         public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
2314             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2315             for (int i = listeners.length-2; i>=0; i-=2) {
2316                 if (listeners[i]==PopupMenuListener.class) {
2317                     ((PopupMenuListener)listeners[i+1]).popupMenuWillBecomeVisible(e);
2318                 }
2319             }
2320         }
2321 
2322         public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
2323             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2324             for (int i = listeners.length-2; i>=0; i-=2) {
2325                 if (listeners[i]==PopupMenuListener.class) {
2326                     ((PopupMenuListener)listeners[i+1]).popupMenuWillBecomeInvisible(e);
2327                 }
2328             }
2329         }
2330 
2331         public void popupMenuCanceled(PopupMenuEvent e) {
2332             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2333             for (int i = listeners.length-2; i>=0; i-=2) {
2334                 if (listeners[i]==PopupMenuListener.class) {
2335                     ((PopupMenuListener)listeners[i+1]).popupMenuCanceled(e);
2336                 }
2337             }
2338         }
2339 
2340         /* TableModelListener Methods **************************************/
2341 
2342         public void tableChanged(TableModelEvent e) {
2343             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2344             for (int i = listeners.length-2; i>=0; i-=2) {
2345                 if (listeners[i]==TableModelListener.class) {
2346                     ((TableModelListener)listeners[i+1]).tableChanged(e);
2347                 }
2348             }
2349         }
2350 
2351         /* TreeExpansionListener Methods **********************************/
2352 
2353         public void treeCollapsed(TreeExpansionEvent e) {
2354             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2355             for (int i = listeners.length-2; i>=0; i-=2) {
2356                 if (listeners[i]==TreeExpansionListener.class) {
2357                     ((TreeExpansionListener)listeners[i+1]).treeCollapsed(e);
2358                 }
2359             }
2360         }
2361         public void treeExpanded(TreeExpansionEvent e) {
2362             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2363             for (int i = listeners.length-2; i>=0; i-=2) {
2364                 if (listeners[i]==TreeExpansionListener.class) {
2365                     ((TreeExpansionListener)listeners[i+1]).treeExpanded(e);
2366                 }
2367             }
2368         }
2369 
2370         /* TreeModelListener Methods **********************************/
2371 
2372         public void treeNodesChanged(TreeModelEvent e) {
2373             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2374             for (int i = listeners.length-2; i>=0; i-=2) {
2375                 if (listeners[i]==TreeModelListener.class) {
2376                     ((TreeModelListener)listeners[i+1]).treeNodesChanged(e);
2377                 }
2378             }
2379         }
2380         public void treeNodesInserted(TreeModelEvent e) {
2381             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2382             for (int i = listeners.length-2; i>=0; i-=2) {
2383                 if (listeners[i]==TreeModelListener.class) {
2384                     ((TreeModelListener)listeners[i+1]).treeNodesInserted(e);
2385                 }
2386             }
2387         }
2388         public void treeNodesRemoved(TreeModelEvent e) {
2389             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2390             for (int i = listeners.length-2; i>=0; i-=2) {
2391                 if (listeners[i]==TreeModelListener.class) {
2392                     ((TreeModelListener)listeners[i+1]).treeNodesRemoved(e);
2393                 }
2394             }
2395         }
2396         public void treeStructureChanged(TreeModelEvent e) {
2397             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2398             for (int i = listeners.length-2; i>=0; i-=2) {
2399                 if (listeners[i]==TreeModelListener.class) {
2400                     ((TreeModelListener)listeners[i+1]).treeStructureChanged(e);
2401                 }
2402             }
2403         }
2404 
2405         /* TreeSelectionListener Methods ***********************************/
2406 
2407         public void valueChanged(TreeSelectionEvent e) {
2408             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2409             for (int i = listeners.length-2; i>=0; i-=2) {
2410                 if (listeners[i]==TreeSelectionListener.class) {
2411                     ((TreeSelectionListener)listeners[i+1]).valueChanged(e);
2412                 }
2413             }
2414         }
2415 
2416         /* UndoableEditListener Methods **************************************/
2417 
2418         public void undoableEditHappened(UndoableEditEvent e) {
2419             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2420             for (int i = listeners.length-2; i>=0; i-=2) {
2421                 if (listeners[i]==UndoableEditListener.class) {
2422                     ((UndoableEditListener)listeners[i+1]).undoableEditHappened(e);
2423                 }
2424             }
2425         }
2426 
2427         /* InternalFrame Methods **********************************/
2428 
2429         public void internalFrameOpened(InternalFrameEvent e) {
2430             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2431             for (int i = listeners.length-2; i>=0; i-=2) {
2432                 if (listeners[i]==InternalFrameListener.class) {
2433                     ((InternalFrameListener)listeners[i+1]).internalFrameOpened(e);
2434                 }
2435             }
2436         }
2437 
2438         public void internalFrameActivated(InternalFrameEvent e) {
2439             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2440             for (int i = listeners.length-2; i>=0; i-=2) {
2441                 if (listeners[i]==InternalFrameListener.class) {
2442                     ((InternalFrameListener)listeners[i+1]).internalFrameActivated(e);
2443                 }
2444             }
2445         }
2446 
2447         public void internalFrameDeactivated(InternalFrameEvent e) {
2448             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2449             for (int i = listeners.length-2; i>=0; i-=2) {
2450                 if (listeners[i]==InternalFrameListener.class) {
2451                     ((InternalFrameListener)listeners[i+1]).internalFrameDeactivated(e);
2452                 }
2453             }
2454         }
2455 
2456         public void internalFrameIconified(InternalFrameEvent e) {
2457             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2458             for (int i = listeners.length-2; i>=0; i-=2) {
2459                 if (listeners[i]==InternalFrameListener.class) {
2460                     ((InternalFrameListener)listeners[i+1]).internalFrameIconified(e);
2461                 }
2462             }
2463         }
2464 
2465         public void internalFrameDeiconified(InternalFrameEvent e) {
2466             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2467             for (int i = listeners.length-2; i>=0; i-=2) {
2468                 if (listeners[i]==InternalFrameListener.class) {
2469                     ((InternalFrameListener)listeners[i+1]).internalFrameDeiconified(e);
2470                 }
2471             }
2472         }
2473 
2474         public void internalFrameClosing(InternalFrameEvent e) {
2475             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2476             for (int i = listeners.length-2; i>=0; i-=2) {
2477                 if (listeners[i]==InternalFrameListener.class) {
2478                     ((InternalFrameListener)listeners[i+1]).internalFrameClosing(e);
2479                 }
2480             }
2481         }
2482 
2483         public void internalFrameClosed(InternalFrameEvent e) {
2484             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2485             for (int i = listeners.length-2; i>=0; i-=2) {
2486                 if (listeners[i]==InternalFrameListener.class) {
2487                     ((InternalFrameListener)listeners[i+1]).internalFrameClosed(e);
2488                 }
2489             }
2490         }
2491 
2492         /* PropertyChangeListener Methods **********************************/
2493 
2494         public void propertyChange(PropertyChangeEvent e) {
2495             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2496             for (int i = listeners.length-2; i>=0; i-=2) {
2497                 if (listeners[i]==PropertyChangeListener.class) {
2498                 ((PropertyChangeListener)listeners[i+1]).propertyChange(e);
2499                 }
2500             }
2501             // Re-add the monitor as a DocumentChangeListener if
2502             // the document changed in the text component.
2503             if (e.getSource() instanceof JTextComponent) {
2504                 Document c = ((JTextComponent)e.getSource()).getDocument();
2505                 if (c == null) {
2506                     return;
2507                 }
2508                 try {
2509                     removeDocumentMethod = c.getClass().getMethod(
2510                         "removeDocumentListener", documentListeners);
2511                     addDocumentMethod = c.getClass().getMethod(
2512                         "addDocumentListener", documentListeners);
2513                     try {
2514                         removeDocumentMethod.invoke(c, documentArgs);
2515                         addDocumentMethod.invoke(c, documentArgs);
2516                     } catch (java.lang.reflect.InvocationTargetException e2) {
2517                         System.out.println("Exception: " + e2.toString());
2518                     } catch (IllegalAccessException e2) {
2519                         System.out.println("Exception: " + e2.toString());
2520                     }
2521                 } catch (NoSuchMethodException e2) {
2522                     // System.out.println("Exception: " + e2.toString());
2523                 } catch (SecurityException e2) {
2524                     System.out.println("Exception: " + e2.toString());
2525                 }
2526             }
2527 
2528         }
2529 
2530         /* VetoableChangeListener Methods **********************************/
2531 
2532         public void vetoableChange(PropertyChangeEvent e)
2533                 throws PropertyVetoException {
2534             Object[] listeners = SwingEventMonitor.listenerList.getListenerList();
2535             for (int i = listeners.length-2; i>=0; i-=2) {
2536                 if (listeners[i]==VetoableChangeListener.class) {
2537                     ((VetoableChangeListener)listeners[i+1]).vetoableChange(e);
2538                 }
2539             }
2540         }
2541     }
2542 }