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