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