GNU Classpath (0.18) | ||
Frames | No Frames |
1: /* JComponent.java -- Every component in swing inherits from this class. 2: Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: 39: package javax.swing; 40: 41: import java.applet.Applet; 42: import java.awt.AWTEvent; 43: import java.awt.Color; 44: import java.awt.Component; 45: import java.awt.Container; 46: import java.awt.Dimension; 47: import java.awt.FlowLayout; 48: import java.awt.FocusTraversalPolicy; 49: import java.awt.Font; 50: import java.awt.Graphics; 51: import java.awt.Graphics2D; 52: import java.awt.Image; 53: import java.awt.Insets; 54: import java.awt.Point; 55: import java.awt.Rectangle; 56: import java.awt.Window; 57: import java.awt.dnd.DropTarget; 58: import java.awt.event.ActionEvent; 59: import java.awt.event.ActionListener; 60: import java.awt.event.ContainerEvent; 61: import java.awt.event.ContainerListener; 62: import java.awt.event.FocusEvent; 63: import java.awt.event.FocusListener; 64: import java.awt.event.KeyEvent; 65: import java.awt.event.MouseEvent; 66: import java.awt.geom.Rectangle2D; 67: import java.awt.image.ImageObserver; 68: import java.awt.peer.LightweightPeer; 69: import java.beans.PropertyChangeEvent; 70: import java.beans.PropertyChangeListener; 71: import java.beans.PropertyVetoException; 72: import java.beans.VetoableChangeListener; 73: import java.io.Serializable; 74: import java.util.EventListener; 75: import java.util.Hashtable; 76: import java.util.Locale; 77: import java.util.Set; 78: 79: import javax.accessibility.Accessible; 80: import javax.accessibility.AccessibleContext; 81: import javax.accessibility.AccessibleExtendedComponent; 82: import javax.accessibility.AccessibleKeyBinding; 83: import javax.accessibility.AccessibleRole; 84: import javax.accessibility.AccessibleStateSet; 85: import javax.swing.border.Border; 86: import javax.swing.event.AncestorEvent; 87: import javax.swing.event.AncestorListener; 88: import javax.swing.event.EventListenerList; 89: import javax.swing.event.SwingPropertyChangeSupport; 90: import javax.swing.plaf.ComponentUI; 91: 92: /** 93: * The base class of all Swing components. 94: * It contains generic methods to manage events, properties and sizes. Actual 95: * drawing of the component is channeled to a look-and-feel class that is 96: * implemented elsewhere. 97: * 98: * @author Ronald Veldema (rveldema&064;cs.vu.nl) 99: * @author Graydon Hoare (graydon&064;redhat.com) 100: */ 101: public abstract class JComponent extends Container implements Serializable 102: { 103: private static final long serialVersionUID = -7908749299918704233L; 104: 105: /** 106: * Accessibility support is currently missing. 107: */ 108: protected AccessibleContext accessibleContext; 109: 110: /** 111: * Basic accessibility support for <code>JComponent</code> derived 112: * widgets. 113: */ 114: public abstract class AccessibleJComponent 115: extends AccessibleAWTContainer 116: implements AccessibleExtendedComponent 117: { 118: /** 119: * Accessibility support for <code>JComponent</code>'s focus handler. 120: */ 121: protected class AccessibleFocusHandler 122: implements FocusListener 123: { 124: protected AccessibleFocusHandler(){} 125: public void focusGained(FocusEvent event){} 126: public void focusLost(FocusEvent valevent){} 127: } 128: 129: /** 130: * Accessibility support for <code>JComponent</code>'s container handler. 131: */ 132: protected class AccessibleContainerHandler 133: implements ContainerListener 134: { 135: protected AccessibleContainerHandler() {} 136: public void componentAdded(ContainerEvent event) {} 137: public void componentRemoved(ContainerEvent valevent) {} 138: } 139: 140: private static final long serialVersionUID = -7047089700479897799L; 141: 142: protected ContainerListener accessibleContainerHandler; 143: protected FocusListener accessibleFocusHandler; 144: 145: protected AccessibleJComponent() {} 146: public void addPropertyChangeListener(PropertyChangeListener listener) {} 147: public void removePropertyChangeListener(PropertyChangeListener listener) {} 148: public int getAccessibleChildrenCount() { return 0; } 149: public Accessible getAccessibleChild(int value0) { return null; } 150: public AccessibleStateSet getAccessibleStateSet() { return null; } 151: public String getAccessibleName() { return null; } 152: public String getAccessibleDescription() { return null; } 153: public AccessibleRole getAccessibleRole() { return null; } 154: protected String getBorderTitle(Border value0) { return null; } 155: public String getToolTipText() { return null; } 156: public String getTitledBorderText() { return null; } 157: public AccessibleKeyBinding getAccessibleKeyBinding() { return null; } 158: } 159: 160: /** 161: * An explicit value for the component's preferred size; if not set by a 162: * user, this is calculated on the fly by delegating to the {@link 163: * ComponentUI.getPreferredSize} method on the {@link #ui} property. 164: */ 165: Dimension preferredSize; 166: 167: /** 168: * An explicit value for the component's minimum size; if not set by a 169: * user, this is calculated on the fly by delegating to the {@link 170: * ComponentUI.getMinimumSize} method on the {@link #ui} property. 171: */ 172: Dimension minimumSize; 173: 174: /** 175: * An explicit value for the component's maximum size; if not set by a 176: * user, this is calculated on the fly by delegating to the {@link 177: * ComponentUI.getMaximumSize} method on the {@link #ui} property. 178: */ 179: Dimension maximumSize; 180: 181: /** 182: * A value between 0.0 and 1.0 indicating the preferred horizontal 183: * alignment of the component, relative to its siblings. The values 184: * {@link #LEFT_ALIGNMENT}, {@link #CENTER_ALIGNMENT}, and {@link 185: * #RIGHT_ALIGNMENT} can also be used, as synonyms for <code>0.0</code>, 186: * <code>0.5</code>, and <code>1.0</code>, respectively. Not all layout 187: * managers use this property. 188: * 189: * @see #getAlignmentX 190: * @see #setAlignmentX 191: * @see javax.swing.OverlayLayout 192: * @see javax.swing.BoxLayout 193: */ 194: float alignmentX = 0.5f; 195: 196: /** 197: * A value between 0.0 and 1.0 indicating the preferred vertical 198: * alignment of the component, relative to its siblings. The values 199: * {@link #TOP_ALIGNMENT}, {@link #CENTER_ALIGNMENT}, and {@link 200: * #BOTTOM_ALIGNMENT} can also be used, as synonyms for <code>0.0</code>, 201: * <code>0.5</code>, and <code>1.0</code>, respectively. Not all layout 202: * managers use this property. 203: * 204: * @see #getAlignmentY 205: * @see #setAlignmentY 206: * @see javax.swing.OverlayLayout 207: * @see javax.swing.BoxLayout 208: */ 209: float alignmentY = 0.5f; 210: 211: /** 212: * The border painted around this component. 213: * 214: * @see #paintBorder 215: */ 216: Border border; 217: 218: /** 219: * The text to show in the tooltip associated with this component. 220: * 221: * @see #setToolTipText 222: * @see #getToolTipText 223: */ 224: String toolTipText; 225: 226: /** 227: * <p>Whether to double buffer this component when painting. This flag 228: * should generally be <code>false</code>, except for top level 229: * components such as {@link JFrame} or {@link JApplet}.</p> 230: * 231: * <p>All children of a double buffered component are painted into the 232: * double buffer automatically, so only the top widget in a window needs 233: * to be double buffered.</p> 234: * 235: * @see #setDoubleBuffered 236: * @see #isDoubleBuffered 237: * @see #paintLock 238: * @see #paint 239: */ 240: boolean doubleBuffered = false; 241: 242: /** 243: * A set of flags indicating which debugging graphics facilities should 244: * be enabled on this component. The values should be a combination of 245: * {@link DebugGraphics.NONE_OPTION}, {@link DebugGraphics.LOG_OPTION}, 246: * {@link DebugGraphics.FLASH_OPTION}, or {@link 247: * DebugGraphics.BUFFERED_OPTION}. 248: * 249: * @see setDebugGraphicsOptions 250: * @see getDebugGraphicsOptions 251: * @see DebugGraphics 252: * @see getComponentGraphics 253: */ 254: int debugGraphicsOptions; 255: 256: /** 257: * <p>This property controls two independent behaviors simultaneously.</p> 258: * 259: * <p>First, it controls whether to fill the background of this widget 260: * when painting its body. This affects calls to {@link 261: * JComponent#paintComponent}, which in turn calls {@link 262: * ComponentUI#update} on the component's {@link #ui} property. If the 263: * component is opaque during this call, the background will be filled 264: * before calling {@link ComponentUI#paint}. This happens merely as a 265: * convenience; you may fill the component's background yourself too, 266: * but there is no need to do so if you will be filling with the same 267: * color.</p> 268: * 269: * <p>Second, it the opaque property informs swing's repaint system 270: * whether it will be necessary to paint the components "underneath" this 271: * component, in Z-order. If the component is opaque, it is considered to 272: * completely occlude components "underneath" it, so they will not be 273: * repainted along with the opaque component.</p> 274: * 275: * <p>The default value for this property is <code>false</code>, but most 276: * components will want to set it to <code>true</code> when installing UI 277: * defaults in {@link ComponentUI#installUI}.</p> 278: * 279: * @see #setOpaque 280: * @see #isOpaque 281: * @see #paintComponent 282: */ 283: boolean opaque = false; 284: 285: /** 286: * The user interface delegate for this component. Event delivery and 287: * repainting of the component are usually delegated to this object. 288: * 289: * @see #setUI 290: * @see #getUIClassID 291: * @see #updateUI 292: */ 293: protected ComponentUI ui; 294: 295: /** 296: * A hint to the focus system that this component should or should not 297: * get focus. If this is <code>false</code>, swing will not try to 298: * request focus on this component; if <code>true</code>, swing might 299: * try to request focus, but the request might fail. Thus it is only 300: * a hint guiding swing's behavior. 301: * 302: * @see #requestFocus 303: * @see #isRequestFocusEnabled 304: * @see #setRequestFocusEnabled 305: */ 306: boolean requestFocusEnabled; 307: 308: /** 309: * Flag indicating behavior of this component when the mouse is dragged 310: * outside the component and the mouse <em>stops moving</em>. If 311: * <code>true</code>, synthetic mouse events will be delivered on regular 312: * timed intervals, continuing off in the direction the mouse exited the 313: * component, until the mouse is released or re-enters the component. 314: * 315: * @see setAutoscrolls 316: * @see getAutoscrolls 317: */ 318: boolean autoscrolls = false; 319: 320: /** 321: * Listeners for events other than {@link PropertyChangeEvent} are 322: * handled by this listener list. PropertyChangeEvents are handled in 323: * {@link #changeSupport}. 324: */ 325: protected EventListenerList listenerList = new EventListenerList(); 326: 327: /** 328: * Support for {@link PropertyChangeEvent} events. This is constructed 329: * lazily when the component gets its first {@link 330: * PropertyChangeListener} subscription; until then it's an empty slot. 331: */ 332: private SwingPropertyChangeSupport changeSupport; 333: 334: 335: /** 336: * Storage for "client properties", which are key/value pairs associated 337: * with this component by a "client", such as a user application or a 338: * layout manager. This is lazily constructed when the component gets its 339: * first client property. 340: */ 341: private Hashtable clientProperties; 342: 343: private InputMap inputMap_whenFocused; 344: private InputMap inputMap_whenAncestorOfFocused; 345: private InputMap inputMap_whenInFocusedWindow; 346: private ActionMap actionMap; 347: /** @since 1.3 */ 348: private boolean verifyInputWhenFocusTarget; 349: private InputVerifier inputVerifier; 350: 351: private TransferHandler transferHandler; 352: 353: /** 354: * A lock held during recursive painting; this is used to serialize 355: * access to the double buffer, and also to select the "top level" 356: * object which should acquire the double buffer in a given widget 357: * tree (which may have multiple double buffered children). 358: * 359: * @see #doubleBuffered 360: * @see #paint 361: */ 362: private static final Object paintLock = new Object(); 363: 364: /** 365: * The default locale of the component. 366: * 367: * @see #getDefaultLocale 368: * @see #setDefaultLocale 369: */ 370: private static Locale defaultLocale; 371: 372: public static final String TOOL_TIP_TEXT_KEY = "ToolTipText"; 373: 374: /** 375: * Constant used to indicate that no condition has been assigned to a 376: * particular action. 377: * 378: * @see #registerKeyboardAction(ActionListener, KeyStroke, int) 379: */ 380: public static final int UNDEFINED_CONDITION = -1; 381: 382: /** 383: * Constant used to indicate that an action should be performed only when 384: * the component has focus. 385: * 386: * @see #registerKeyboardAction(ActionListener, KeyStroke, int) 387: */ 388: public static final int WHEN_FOCUSED = 0; 389: 390: /** 391: * Constant used to indicate that an action should be performed only when 392: * the component is an ancestor of the component which has focus. 393: * 394: * @see #registerKeyboardAction(ActionListener, KeyStroke, int) 395: */ 396: public static final int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT = 1; 397: 398: /** 399: * Constant used to indicate that an action should be performed only when 400: * the component is in the window which has focus. 401: * 402: * @see #registerKeyboardAction(ActionListener, KeyStroke, int) 403: */ 404: public static final int WHEN_IN_FOCUSED_WINDOW = 2; 405: 406: /** 407: * Creates a new <code>JComponent</code> instance. 408: */ 409: public JComponent() 410: { 411: super(); 412: super.setLayout(new FlowLayout()); 413: setDropTarget(new DropTarget()); 414: defaultLocale = Locale.getDefault(); 415: debugGraphicsOptions = DebugGraphics.NONE_OPTION; 416: setRequestFocusEnabled(true); 417: } 418: 419: /** 420: * Helper to lazily construct and return the client properties table. 421: * 422: * @return The current client properties table 423: * 424: * @see #clientProperties 425: * @see #getClientProperty 426: * @see #putClientProperty 427: */ 428: private Hashtable getClientProperties() 429: { 430: if (clientProperties == null) 431: clientProperties = new Hashtable(); 432: return clientProperties; 433: } 434: 435: /** 436: * Get a client property associated with this component and a particular 437: * key. 438: * 439: * @param key The key with which to look up the client property 440: * 441: * @return A client property associated with this object and key 442: * 443: * @see #clientProperties 444: * @see #getClientProperties 445: * @see #putClientProperty 446: */ 447: public final Object getClientProperty(Object key) 448: { 449: return getClientProperties().get(key); 450: } 451: 452: /** 453: * Add a client property <code>value</code> to this component, associated 454: * with <code>key</code>. If there is an existing client property 455: * associated with <code>key</code>, it will be replaced. 456: * 457: * @param key The key of the client property association to add 458: * @param value The value of the client property association to add 459: * 460: * @see #clientProperties 461: * @see #getClientProperties 462: * @see #getClientProperty 463: */ 464: public final void putClientProperty(Object key, Object value) 465: { 466: if (value != null) 467: getClientProperties().put(key, value); 468: else 469: getClientProperties().remove(key); 470: } 471: 472: /** 473: * Unregister an <code>AncestorListener</code>. 474: * 475: * @param listener The listener to unregister 476: * 477: * @see #addAncestorListener 478: */ 479: public void removeAncestorListener(AncestorListener listener) 480: { 481: listenerList.remove(AncestorListener.class, listener); 482: } 483: 484: /** 485: * Unregister a <code>PropertyChangeListener</code>. 486: * 487: * @param listener The listener to register 488: * 489: * @see #addPropertyChangeListener(PropertyChangeListener) 490: * @see #changeSupport 491: */ 492: public void removePropertyChangeListener(PropertyChangeListener listener) 493: { 494: if (changeSupport != null) 495: changeSupport.removePropertyChangeListener(listener); 496: } 497: 498: /** 499: * Unregister a <code>PropertyChangeListener</code>. 500: * 501: * @param propertyName The property name to unregister the listener from 502: * @param listener The listener to unregister 503: * 504: * @see #addPropertyChangeListener(String, PropertyChangeListener) 505: * @see #changeSupport 506: */ 507: public void removePropertyChangeListener(String propertyName, 508: PropertyChangeListener listener) 509: { 510: if (changeSupport != null) 511: changeSupport.removePropertyChangeListener(propertyName, listener); 512: } 513: 514: /** 515: * Unregister a <code>VetoableChangeChangeListener</code>. 516: * 517: * @param listener The listener to unregister 518: * 519: * @see #addVetoableChangeListener 520: */ 521: public void removeVetoableChangeListener(VetoableChangeListener listener) 522: { 523: listenerList.remove(VetoableChangeListener.class, listener); 524: } 525: 526: /** 527: * Register an <code>AncestorListener</code>. 528: * 529: * @param listener The listener to register 530: * 531: * @see #removeVetoableChangeListener 532: */ 533: public void addAncestorListener(AncestorListener listener) 534: { 535: listenerList.add(AncestorListener.class, listener); 536: } 537: 538: /** 539: * Register a <code>PropertyChangeListener</code>. This listener will 540: * receive any PropertyChangeEvent, regardless of property name. To 541: * listen to a specific property name, use {@link 542: * #addPropertyChangeListener(String,PropertyChangeListener)} instead. 543: * 544: * @param listener The listener to register 545: * 546: * @see #removePropertyChangeListener(PropertyChangeListener) 547: * @see #changeSupport 548: */ 549: public void addPropertyChangeListener(PropertyChangeListener listener) 550: { 551: if (changeSupport == null) 552: changeSupport = new SwingPropertyChangeSupport(this); 553: changeSupport.addPropertyChangeListener(listener); 554: } 555: 556: /** 557: * Register a <code>PropertyChangeListener</code> for a specific, named 558: * property. To listen to all property changes, regardless of name, use 559: * {@link #addPropertyChangeListener(PropertyChangeListener)} instead. 560: * 561: * @param propertyName The property name to listen to 562: * @param listener The listener to register 563: * 564: * @see #removePropertyChangeListener(String, PropertyChangeListener) 565: * @see #changeSupport 566: */ 567: public void addPropertyChangeListener(String propertyName, 568: PropertyChangeListener listener) 569: { 570: listenerList.add(PropertyChangeListener.class, listener); 571: } 572: 573: /** 574: * Register a <code>VetoableChangeListener</code>. 575: * 576: * @param listener The listener to register 577: * 578: * @see #removeVetoableChangeListener 579: * @see #listenerList 580: */ 581: public void addVetoableChangeListener(VetoableChangeListener listener) 582: { 583: listenerList.add(VetoableChangeListener.class, listener); 584: } 585: 586: /** 587: * Return all registered listeners of a particular type. 588: * 589: * @param listenerType The type of listener to return 590: * 591: * @return All listeners in the {@link #listenerList} which 592: * are of the specified type 593: * 594: * @see #listenerList 595: */ 596: public EventListener[] getListeners(Class listenerType) 597: { 598: return listenerList.getListeners(listenerType); 599: } 600: 601: /** 602: * Return all registered <code>AncestorListener</code> objects. 603: * 604: * @return The set of <code>AncestorListener</code> objects in {@link 605: * #listenerList} 606: */ 607: public AncestorListener[] getAncestorListeners() 608: { 609: return (AncestorListener[]) getListeners(AncestorListener.class); 610: } 611: 612: /** 613: * Return all registered <code>VetoableChangeListener</code> objects. 614: * 615: * @return The set of <code>VetoableChangeListener</code> objects in {@link 616: * #listenerList} 617: */ 618: public VetoableChangeListener[] getVetoableChangeListeners() 619: { 620: return (VetoableChangeListener[]) getListeners(VetoableChangeListener.class); 621: } 622: 623: /** 624: * Return all <code>PropertyChangeListener</code> objects registered to listen 625: * for a particular property. 626: * 627: * @param property The property to return the listeners of 628: * 629: * @return The set of <code>PropertyChangeListener</code> objects in 630: * {@link #changeSupport} registered to listen on the specified property 631: */ 632: public PropertyChangeListener[] getPropertyChangeListeners(String property) 633: { 634: return changeSupport == null ? new PropertyChangeListener[0] 635: : changeSupport.getPropertyChangeListeners(property); 636: } 637: 638: /** 639: * A variant of {@link #firePropertyChange(String,Object,Object)} 640: * for properties with <code>boolean</code> values. 641: */ 642: public void firePropertyChange(String propertyName, boolean oldValue, 643: boolean newValue) 644: { 645: if (changeSupport != null) 646: changeSupport.firePropertyChange(propertyName, Boolean.valueOf(oldValue), 647: Boolean.valueOf(newValue)); 648: } 649: 650: /** 651: * A variant of {@link #firePropertyChange(String,Object,Object)} 652: * for properties with <code>byte</code> values. 653: */ 654: public void firePropertyChange(String propertyName, byte oldValue, 655: byte newValue) 656: { 657: if (changeSupport != null) 658: changeSupport.firePropertyChange(propertyName, new Byte(oldValue), 659: new Byte(newValue)); 660: } 661: 662: /** 663: * A variant of {@link #firePropertyChange(String,Object,Object)} 664: * for properties with <code>char</code> values. 665: */ 666: public void firePropertyChange(String propertyName, char oldValue, 667: char newValue) 668: { 669: if (changeSupport != null) 670: changeSupport.firePropertyChange(propertyName, new Character(oldValue), 671: new Character(newValue)); 672: } 673: 674: /** 675: * A variant of {@link #firePropertyChange(String,Object,Object)} 676: * for properties with <code>double</code> values. 677: */ 678: public void firePropertyChange(String propertyName, double oldValue, 679: double newValue) 680: { 681: if (changeSupport != null) 682: changeSupport.firePropertyChange(propertyName, new Double(oldValue), 683: new Double(newValue)); 684: } 685: 686: /** 687: * A variant of {@link #firePropertyChange(String,Object,Object)} 688: * for properties with <code>float</code> values. 689: */ 690: public void firePropertyChange(String propertyName, float oldValue, 691: float newValue) 692: { 693: if (changeSupport != null) 694: changeSupport.firePropertyChange(propertyName, new Float(oldValue), 695: new Float(newValue)); 696: } 697: 698: /** 699: * A variant of {@link #firePropertyChange(String,Object,Object)} 700: * for properties with <code>int</code> values. 701: */ 702: public void firePropertyChange(String propertyName, int oldValue, 703: int newValue) 704: { 705: if (changeSupport != null) 706: changeSupport.firePropertyChange(propertyName, new Integer(oldValue), 707: new Integer(newValue)); 708: } 709: 710: /** 711: * A variant of {@link #firePropertyChange(String,Object,Object)} 712: * for properties with <code>long</code> values. 713: */ 714: public void firePropertyChange(String propertyName, long oldValue, 715: long newValue) 716: { 717: if (changeSupport != null) 718: changeSupport.firePropertyChange(propertyName, new Long(oldValue), 719: new Long(newValue)); 720: } 721: 722: /** 723: * Call {@link PropertyChangeListener#propertyChange} on all listeners 724: * registered to listen to a given property. Any method which changes 725: * the specified property of this component should call this method. 726: * 727: * @param propertyName The property which changed 728: * @param oldValue The old value of the property 729: * @param newValue The new value of the property 730: * 731: * @see #changeSupport 732: * @see #addPropertyChangeListener(PropertyChangeListener) 733: * @see #removePropertyChangeListener(PropertyChangeListener) 734: */ 735: protected void firePropertyChange(String propertyName, Object oldValue, 736: Object newValue) 737: { 738: if (changeSupport != null) 739: changeSupport.firePropertyChange(propertyName, oldValue, newValue); 740: } 741: 742: /** 743: * A variant of {@link #firePropertyChange(String,Object,Object)} 744: * for properties with <code>short</code> values. 745: */ 746: public void firePropertyChange(String propertyName, short oldValue, 747: short newValue) 748: { 749: if (changeSupport != null) 750: changeSupport.firePropertyChange(propertyName, new Short(oldValue), 751: new Short(newValue)); 752: } 753: 754: /** 755: * Call {@link VetoableChangeListener#vetoableChange} on all listeners 756: * registered to listen to a given property. Any method which changes 757: * the specified property of this component should call this method. 758: * 759: * @param propertyName The property which changed 760: * @param oldValue The old value of the property 761: * @param newValue The new value of the property 762: * 763: * @throws PropertyVetoException if the change was vetoed by a listener 764: * 765: * @see #addVetoableChangeListener 766: * @see #removeVetoableChangeListener 767: */ 768: protected void fireVetoableChange(String propertyName, Object oldValue, 769: Object newValue) 770: throws PropertyVetoException 771: { 772: VetoableChangeListener[] listeners = getVetoableChangeListeners(); 773: 774: PropertyChangeEvent evt = new PropertyChangeEvent(this, propertyName, oldValue, newValue); 775: 776: for (int i = 0; i < listeners.length; i++) 777: listeners[i].vetoableChange(evt); 778: } 779: 780: /** 781: * Get the value of the accessibleContext property for this component. 782: * 783: * @return the current value of the property 784: */ 785: public AccessibleContext getAccessibleContext() 786: { 787: return null; 788: } 789: 790: /** 791: * Get the value of the {@link #alignmentX} property. 792: * 793: * @return The current value of the property. 794: * 795: * @see #setAlignmentX 796: * @see #alignmentY 797: */ 798: public float getAlignmentX() 799: { 800: return alignmentX; 801: } 802: 803: /** 804: * Get the value of the {@link #alignmentY} property. 805: * 806: * @return The current value of the property. 807: * 808: * @see #setAlignmentY 809: * @see #alignmentX 810: */ 811: public float getAlignmentY() 812: { 813: return alignmentY; 814: } 815: 816: /** 817: * Get the current value of the {@link #autoscrolls} property. 818: * 819: * @return The current value of the property 820: */ 821: public boolean getAutoscrolls() 822: { 823: return autoscrolls; 824: } 825: 826: /** 827: * Set the value of the {@link #border} property. 828: * 829: * @param newBorder The new value of the property 830: * 831: * @see #getBorder 832: */ 833: public void setBorder(Border newBorder) 834: { 835: Border oldBorder = border; 836: border = newBorder; 837: firePropertyChange("border", oldBorder, newBorder); 838: } 839: 840: /** 841: * Get the value of the {@link #border} property. 842: * 843: * @return The property's current value 844: * 845: * @see #setBorder 846: */ 847: public Border getBorder() 848: { 849: return border; 850: } 851: 852: /** 853: * Get the component's current bounding box. If a rectangle is provided, 854: * use this as the return value (adjusting its fields in place); 855: * otherwise (of <code>null</code> is provided) return a new {@link 856: * Rectangle}. 857: * 858: * @param rv Optional return value to use 859: * 860: * @return A rectangle bounding the component 861: */ 862: public Rectangle getBounds(Rectangle rv) 863: { 864: if (rv == null) 865: return new Rectangle(getX(), getY(), getWidth(), getHeight()); 866: else 867: { 868: rv.setBounds(getX(), getY(), getWidth(), getHeight()); 869: return rv; 870: } 871: } 872: 873: /** 874: * Prepares a graphics context for painting this object. If {@link 875: * #debugGraphicsOptions} is not equal to {@link 876: * DebugGraphics#NONE_OPTION}, produce a new {@link DebugGraphics} object 877: * wrapping the parameter. Otherwise configure the parameter with this 878: * component's foreground color and font. 879: * 880: * @param g The graphics context to wrap or configure 881: * 882: * @return A graphics context to paint this object with 883: * 884: * @see #debugGraphicsOptions 885: * @see #paint 886: */ 887: protected Graphics getComponentGraphics(Graphics g) 888: { 889: g.setFont (this.getFont()); 890: g.setColor (this.getForeground()); 891: return g; 892: } 893: 894: /** 895: * Get the value of the {@link #debugGraphicsOptions} property. 896: * 897: * @return The current value of the property. 898: * 899: * @see #setDebugGraphicsOptions 900: * @see #debugGraphicsOptions 901: */ 902: public int getDebugGraphicsOptions() 903: { 904: return 0; 905: } 906: 907: /** 908: * Get the component's insets, which are calculated from 909: * the {@link #border} property. If the border is <code>null</code>, 910: * calls {@link Container#getInsets}. 911: * 912: * @return The component's current insets 913: */ 914: public Insets getInsets() 915: { 916: if (border == null) 917: return super.getInsets(); 918: return getBorder().getBorderInsets(this); 919: } 920: 921: /** 922: * Get the component's insets, which are calculated from the {@link 923: * #border} property. If the border is <code>null</code>, calls {@link 924: * Container#getInsets}. The passed-in {@link Insets} value will be 925: * used as the return value, if possible. 926: * 927: * @param insets Return value object to reuse, if possible 928: * 929: * @return The component's current insets 930: */ 931: public Insets getInsets(Insets insets) 932: { 933: Insets t = getInsets(); 934: 935: if (insets == null) 936: return t; 937: 938: insets.left = t.left; 939: insets.right = t.right; 940: insets.top = t.top; 941: insets.bottom = t.bottom; 942: return insets; 943: } 944: 945: /** 946: * Get the component's location. The passed-in {@link Point} value 947: * will be used as the return value, if possible. 948: * 949: * @param rv Return value object to reuse, if possible 950: * 951: * @return The component's current location 952: */ 953: public Point getLocation(Point rv) 954: { 955: if (rv == null) 956: return new Point(getX(), getY()); 957: 958: rv.setLocation(getX(), getY()); 959: return rv; 960: } 961: 962: /** 963: * Get the component's maximum size. If the {@link #maximumSize} property 964: * has been explicitly set, it is returned. If the {@link #maximumSize} 965: * property has not been set but the {@link #ui} property has been, the 966: * result of {@link ComponentUI#getMaximumSize} is returned. If neither 967: * property has been set, the result of {@link Container#getMaximumSize} 968: * is returned. 969: * 970: * @return The maximum size of the component 971: * 972: * @see #maximumSize 973: * @see #setMaximumSize 974: */ 975: public Dimension getMaximumSize() 976: { 977: if (maximumSize != null) 978: return maximumSize; 979: 980: if (ui != null) 981: { 982: Dimension s = ui.getMaximumSize(this); 983: if (s != null) 984: return s; 985: } 986: 987: Dimension p = super.getMaximumSize(); 988: return p; 989: } 990: 991: /** 992: * Get the component's minimum size. If the {@link #minimumSize} property 993: * has been explicitly set, it is returned. If the {@link #minimumSize} 994: * property has not been set but the {@link #ui} property has been, the 995: * result of {@link ComponentUI#getMinimumSize} is returned. If neither 996: * property has been set, the result of {@link Container#getMinimumSize} 997: * is returned. 998: * 999: * @return The minimum size of the component 1000: * 1001: * @see #minimumSize 1002: * @see #setMinimumSize 1003: */ 1004: public Dimension getMinimumSize() 1005: { 1006: if (minimumSize != null) 1007: return minimumSize; 1008: 1009: if (ui != null) 1010: { 1011: Dimension s = ui.getMinimumSize(this); 1012: if (s != null) 1013: return s; 1014: } 1015: 1016: Dimension p = super.getMinimumSize(); 1017: return p; 1018: } 1019: 1020: /** 1021: * Get the component's preferred size. If the {@link #preferredSize} 1022: * property has been explicitly set, it is returned. If the {@link 1023: * #preferredSize} property has not been set but the {@link #ui} property 1024: * has been, the result of {@link ComponentUI#getPreferredSize} is 1025: * returned. If neither property has been set, the result of {@link 1026: * Container#getPreferredSize} is returned. 1027: * 1028: * @return The preferred size of the component 1029: * 1030: * @see #preferredSize 1031: * @see #setPreferredSize 1032: */ 1033: public Dimension getPreferredSize() 1034: { 1035: Dimension prefSize = null; 1036: if (preferredSize != null) 1037: prefSize = preferredSize; 1038: 1039: else if (ui != null) 1040: { 1041: Dimension s = ui.getPreferredSize(this); 1042: if (s != null) 1043: prefSize = s; 1044: } 1045: 1046: if (prefSize == null) 1047: prefSize = super.getPreferredSize(); 1048: // make sure that prefSize is not smaller than minSize 1049: if (minimumSize != null && prefSize != null 1050: && (minimumSize.width > prefSize.width 1051: || minimumSize.height > prefSize.height)) 1052: prefSize = new Dimension(Math.max(minimumSize.width, prefSize.width), 1053: Math.max(minimumSize.height, prefSize.height)); 1054: return prefSize; 1055: } 1056: 1057: /** 1058: * Checks if a maximum size was explicitely set on the component. 1059: * 1060: * @return <code>true</code> if a maximum size was set, 1061: * <code>false</code> otherwise 1062: * 1063: * @since 1.3 1064: */ 1065: public boolean isMaximumSizeSet() 1066: { 1067: return maximumSize != null; 1068: } 1069: 1070: /** 1071: * Checks if a minimum size was explicitely set on the component. 1072: * 1073: * @return <code>true</code> if a minimum size was set, 1074: * <code>false</code> otherwise 1075: * 1076: * @since 1.3 1077: */ 1078: public boolean isMinimumSizeSet() 1079: { 1080: return minimumSize != null; 1081: } 1082: 1083: /** 1084: * Checks if a preferred size was explicitely set on the component. 1085: * 1086: * @return <code>true</code> if a preferred size was set, 1087: * <code>false</code> otherwise 1088: * 1089: * @since 1.3 1090: */ 1091: public boolean isPreferredSizeSet() 1092: { 1093: return preferredSize != null; 1094: } 1095: 1096: /** 1097: * Return the value of the <code>nextFocusableComponent</code> property. 1098: * 1099: * @return The current value of the property, or <code>null</code> 1100: * if none has been set. 1101: * 1102: * @deprecated See {@link java.awt.FocusTraversalPolicy} 1103: */ 1104: public Component getNextFocusableComponent() 1105: { 1106: return null; 1107: } 1108: 1109: /** 1110: * Return the set of {@link KeyStroke} objects which are registered 1111: * to initiate actions on this component. 1112: * 1113: * @return An array of the registered keystrokes 1114: */ 1115: public KeyStroke[] getRegisteredKeyStrokes() 1116: { 1117: return null; 1118: } 1119: 1120: /** 1121: * Returns the first ancestor of this component which is a {@link JRootPane}. 1122: * Equivalent to calling <code>SwingUtilities.getRootPane(this);</code>. 1123: * 1124: * @return An ancestral JRootPane, or <code>null</code> if none exists. 1125: */ 1126: public JRootPane getRootPane() 1127: { 1128: JRootPane p = SwingUtilities.getRootPane(this); 1129: return p; 1130: } 1131: 1132: /** 1133: * Get the component's size. The passed-in {@link Dimension} value 1134: * will be used as the return value, if possible. 1135: * 1136: * @param rv Return value object to reuse, if possible 1137: * 1138: * @return The component's current size 1139: */ 1140: public Dimension getSize(Dimension rv) 1141: { 1142: if (rv == null) 1143: return new Dimension(getWidth(), getHeight()); 1144: else 1145: { 1146: rv.setSize(getWidth(), getHeight()); 1147: return rv; 1148: } 1149: } 1150: 1151: /** 1152: * Return the <code>toolTip</code> property of this component, creating it and 1153: * setting it if it is currently <code>null</code>. This method can be 1154: * overridden in subclasses which wish to control the exact form of 1155: * tooltip created. 1156: * 1157: * @return The current toolTip 1158: */ 1159: public JToolTip createToolTip() 1160: { 1161: JToolTip toolTip = new JToolTip(); 1162: toolTip.setComponent(this); 1163: toolTip.setTipText(toolTipText); 1164: 1165: return toolTip; 1166: } 1167: 1168: /** 1169: * Return the location at which the {@link #toolTipText} property should be 1170: * displayed, when triggered by a particular mouse event. 1171: * 1172: * @param event The event the tooltip is being presented in response to 1173: * 1174: * @return The point at which to display a tooltip, or <code>null</code> 1175: * if swing is to choose a default location. 1176: */ 1177: public Point getToolTipLocation(MouseEvent event) 1178: { 1179: return null; 1180: } 1181: 1182: /** 1183: * Set the value of the {@link #toolTipText} property. 1184: * 1185: * @param text The new property value 1186: * 1187: * @see #getToolTipText() 1188: */ 1189: public void setToolTipText(String text) 1190: { 1191: if (text == null) 1192: { 1193: ToolTipManager.sharedInstance().unregisterComponent(this); 1194: toolTipText = null; 1195: return; 1196: } 1197: 1198: // XXX: The tip text doesn't get updated unless you set it to null 1199: // and then to something not-null. This is consistent with the behaviour 1200: // of Sun's ToolTipManager. 1201: 1202: String oldText = toolTipText; 1203: toolTipText = text; 1204: 1205: if (oldText == null) 1206: ToolTipManager.sharedInstance().registerComponent(this); 1207: } 1208: 1209: /** 1210: * Get the value of the {@link #toolTipText} property. 1211: * 1212: * @return The current property value 1213: * 1214: * @see #setToolTipText 1215: */ 1216: public String getToolTipText() 1217: { 1218: return toolTipText; 1219: } 1220: 1221: /** 1222: * Get the value of the {@link #toolTipText} property, in response to a 1223: * particular mouse event. 1224: * 1225: * @param event The mouse event which triggered the tooltip 1226: * 1227: * @return The current property value 1228: * 1229: * @see #setToolTipText 1230: */ 1231: public String getToolTipText(MouseEvent event) 1232: { 1233: return getToolTipText(); 1234: } 1235: 1236: /** 1237: * Return the top level ancestral container (usually a {@link 1238: * java.awt.Window} or {@link java.applet.Applet}) which this component is 1239: * contained within, or <code>null</code> if no ancestors exist. 1240: * 1241: * @return The top level container, if it exists 1242: */ 1243: public Container getTopLevelAncestor() 1244: { 1245: Container c = getParent(); 1246: for (Container peek = c; peek != null; peek = peek.getParent()) 1247: c = peek; 1248: return c; 1249: } 1250: 1251: /** 1252: * Compute the component's visible rectangle, which is defined 1253: * recursively as either the component's bounds, if it has no parent, or 1254: * the intersection of the component's bounds with the visible rectangle 1255: * of its parent. 1256: * 1257: * @param rect The return value slot to place the visible rectangle in 1258: */ 1259: public void computeVisibleRect(Rectangle rect) 1260: { 1261: Component c = getParent(); 1262: if (c != null && c instanceof JComponent) 1263: { 1264: ((JComponent) c).computeVisibleRect(rect); 1265: rect.translate(-getX(), -getY()); 1266: Rectangle2D.intersect(rect, 1267: new Rectangle(0, 0, getWidth(), getHeight()), 1268: rect); 1269: } 1270: else 1271: rect.setRect(0, 0, getWidth(), getHeight()); 1272: } 1273: 1274: /** 1275: * Return the component's visible rectangle in a new {@link Rectangle}, 1276: * rather than via a return slot. 1277: * 1278: * @return The component's visible rectangle 1279: * 1280: * @see #computeVisibleRect(Rectangle) 1281: */ 1282: public Rectangle getVisibleRect() 1283: { 1284: Rectangle r = new Rectangle(); 1285: computeVisibleRect(r); 1286: return r; 1287: } 1288: 1289: /** 1290: * <p>Requests that this component receive input focus, giving window 1291: * focus to the top level ancestor of this component. Only works on 1292: * displayable, focusable, visible components.</p> 1293: * 1294: * <p>This method should not be called by clients; it is intended for 1295: * focus implementations. Use {@link Component#requestFocus()} instead.</p> 1296: * 1297: * @see Component#requestFocus() 1298: */ 1299: public void grabFocus() 1300: { 1301: } 1302: 1303: /** 1304: * Get the value of the {@link #doubleBuffered} property. 1305: * 1306: * @return The property's current value 1307: */ 1308: public boolean isDoubleBuffered() 1309: { 1310: return doubleBuffered; 1311: } 1312: 1313: /** 1314: * Return <code>true</code> if the provided component has no native peer; 1315: * in other words, if it is a "lightweight component". 1316: * 1317: * @param c The component to test for lightweight-ness 1318: * 1319: * @return Whether or not the component is lightweight 1320: */ 1321: public static boolean isLightweightComponent(Component c) 1322: { 1323: return c.getPeer() instanceof LightweightPeer; 1324: } 1325: 1326: /** 1327: * Return <code>true</code> if you wish this component to manage its own 1328: * focus. In particular: if you want this component to be sent 1329: * <code>TAB</code> and <code>SHIFT+TAB</code> key events, and to not 1330: * have its children considered as focus transfer targets. If 1331: * <code>true</code>, focus traversal around this component changes to 1332: * <code>CTRL+TAB</code> and <code>CTRL+SHIFT+TAB</code>. 1333: * 1334: * @return <code>true</code> if you want this component to manage its own 1335: * focus, otherwise (by default) <code>false</code> 1336: * 1337: * @deprecated 1.4 Use {@link Component#setFocusTraversalKeys(int, Set)} and 1338: * {@link Container#setFocusCycleRoot(boolean)} instead 1339: */ 1340: public boolean isManagingFocus() 1341: { 1342: return false; 1343: } 1344: 1345: /** 1346: * Return the current value of the {@link #opaque} property. 1347: * 1348: * @return The current property value 1349: */ 1350: public boolean isOpaque() 1351: { 1352: return opaque; 1353: } 1354: 1355: /** 1356: * Return <code>true</code> if the component can guarantee that none of its 1357: * children will overlap in Z-order. This is a hint to the painting system. 1358: * The default is to return <code>true</code>, but some components such as 1359: * {@link JLayeredPane} should override this to return <code>false</code>. 1360: * 1361: * @return Whether the component tiles its children 1362: */ 1363: public boolean isOptimizedDrawingEnabled() 1364: { 1365: return true; 1366: } 1367: 1368: /** 1369: * Return <code>true</code> if this component is currently painting a tile. 1370: * 1371: * @return Whether the component is painting a tile 1372: */ 1373: public boolean isPaintingTile() 1374: { 1375: return false; 1376: } 1377: 1378: /** 1379: * Get the value of the {@link #requestFocusEnabled} property. 1380: * 1381: * @return The current value of the property 1382: */ 1383: public boolean isRequestFocusEnabled() 1384: { 1385: return requestFocusEnabled; 1386: } 1387: 1388: /** 1389: * Return <code>true</code> if this component is a validation root; this 1390: * will cause calls to {@link #invalidate()} in this component's children 1391: * to be "captured" at this component, and not propagate to its parents. 1392: * For most components this should return <code>false</code>, but some 1393: * components such as {@link JViewport} will want to return 1394: * <code>true</code>. 1395: * 1396: * @return Whether this component is a validation root 1397: */ 1398: public boolean isValidateRoot() 1399: { 1400: return false; 1401: } 1402: 1403: /** 1404: * <p>Paint the component. This is a delicate process, and should only be 1405: * called from the repaint thread, under control of the {@link 1406: * RepaintManager}. Client code should usually call {@link #repaint()} to 1407: * trigger painting.</p> 1408: * 1409: * <p>This method will acquire a double buffer from the {@link 1410: * RepaintManager} if the component's {@link #doubleBuffered} property is 1411: * <code>true</code> and the <code>paint</code> call is the 1412: * <em>first</em> recursive <code>paint</code> call inside swing.</p> 1413: * 1414: * <p>The method will also modify the provided {@link Graphics} context 1415: * via the {@link #getComponentGraphics} method. If you want to customize 1416: * the graphics object used for painting, you should override that method 1417: * rather than <code>paint</code>.</p> 1418: * 1419: * <p>The body of the <code>paint</code> call involves calling {@link 1420: * #paintComponent}, {@link #paintBorder}, and {@link #paintChildren} in 1421: * order. If you want to customize painting behavior, you should override 1422: * one of these methods rather than <code>paint</code>.</p> 1423: * 1424: * <p>For more details on the painting sequence, see <a 1425: * href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html"> 1426: * this article</a>.</p> 1427: * 1428: * @param g The graphics context to paint with 1429: * 1430: * @see #paintImmediately(Rectangle) 1431: */ 1432: public void paint(Graphics g) 1433: { 1434: Graphics g2 = g; 1435: Image doubleBuffer = null; 1436: RepaintManager rm = RepaintManager.currentManager(this); 1437: 1438: if (isDoubleBuffered() 1439: && (rm.isDoubleBufferingEnabled()) 1440: && (! Thread.holdsLock(paintLock))) 1441: { 1442: doubleBuffer = rm.getOffscreenBuffer(this, getWidth(), getHeight()); 1443: } 1444: 1445: synchronized (paintLock) 1446: { 1447: if (doubleBuffer != null) 1448: { 1449: g2 = doubleBuffer.getGraphics(); 1450: g2.setClip(g.getClipBounds()); 1451: } 1452: 1453: g2 = getComponentGraphics(g2); 1454: paintComponent(g2); 1455: paintBorder(g2); 1456: paintChildren(g2); 1457: 1458: if (doubleBuffer != null) 1459: g.drawImage(doubleBuffer, 0, 0, (ImageObserver) null); 1460: } 1461: } 1462: 1463: /** 1464: * Paint the component's border. This usually means calling {@link 1465: * Border#paintBorder} on the {@link #border} property, if it is 1466: * non-<code>null</code>. You may override this if you wish to customize 1467: * border painting behavior. The border is painted after the component's 1468: * body, but before the component's children. 1469: * 1470: * @param g The graphics context with which to paint the border 1471: * 1472: * @see #paint 1473: * @see #paintChildren 1474: * @see #paintComponent 1475: */ 1476: protected void paintBorder(Graphics g) 1477: { 1478: if (getBorder() != null) 1479: getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight()); 1480: } 1481: 1482: /** 1483: * Paint the component's children. This usually means calling {@link 1484: * Container#paint}, which recursively calls {@link #paint} on any of the 1485: * component's children, with appropriate changes to coordinate space and 1486: * clipping region. You may override this if you wish to customize 1487: * children painting behavior. The children are painted after the 1488: * component's body and border. 1489: * 1490: * @param g The graphics context with which to paint the children 1491: * 1492: * @see #paint 1493: * @see #paintBorder 1494: * @see #paintComponent 1495: */ 1496: protected void paintChildren(Graphics g) 1497: { 1498: super.paint(g); 1499: } 1500: 1501: /** 1502: * Paint the component's body. This usually means calling {@link 1503: * ComponentUI#update} on the {@link #ui} property of the component, if 1504: * it is non-<code>null</code>. You may override this if you wish to 1505: * customize the component's body-painting behavior. The component's body 1506: * is painted first, before the border and children. 1507: * 1508: * @param g The graphics context with which to paint the body 1509: * 1510: * @see #paint 1511: * @see #paintBorder 1512: * @see #paintChildren 1513: */ 1514: protected void paintComponent(Graphics g) 1515: { 1516: if (ui != null) 1517: { 1518: Graphics g2 = g; 1519: if (!(g instanceof Graphics2D)) 1520: g2 = g.create(); 1521: ui.update(getComponentGraphics(g2), this); 1522: if (!(g instanceof Graphics2D)) 1523: g2.dispose(); 1524: } 1525: } 1526: 1527: /** 1528: * A variant of {@link #paintImmediately(Rectangle)} which takes 1529: * integer parameters. 1530: * 1531: * @param x The left x coordinate of the dirty region 1532: * @param y The top y coordinate of the dirty region 1533: * @param w The width of the dirty region 1534: * @param h The height of the dirty region 1535: */ 1536: public void paintImmediately(int x, int y, int w, int h) 1537: { 1538: paintImmediately(new Rectangle(x, y, w, h)); 1539: } 1540: 1541: /** 1542: * Transform the provided dirty rectangle for this component into the 1543: * appropriate ancestral {@link JRootPane} and call {@link #paint} on 1544: * that root pane. This method is called from the {@link RepaintManager} 1545: * and should always be called within the painting thread. 1546: * 1547: * @param r The dirty rectangle to paint 1548: */ 1549: public void paintImmediately(Rectangle r) 1550: { 1551: Component root = SwingUtilities.getRoot(this); 1552: if (root == null || ! root.isShowing()) 1553: return; 1554: Graphics g = root.getGraphics(); 1555: if (g == null) 1556: return; 1557: 1558: Rectangle clip = SwingUtilities.convertRectangle(this, r, root); 1559: g.setClip(clip); 1560: root.paint(g); 1561: g.dispose(); 1562: } 1563: 1564: /** 1565: * Return a string representation for this component, for use in 1566: * debugging. 1567: * 1568: * @return A string describing this component. 1569: */ 1570: protected String paramString() 1571: { 1572: StringBuffer sb = new StringBuffer(); 1573: sb.append(super.paramString()); 1574: sb.append(",alignmentX=").append(getAlignmentX()); 1575: sb.append(",alignmentY=").append(getAlignmentY()); 1576: sb.append(",border="); 1577: if (getBorder() != null) 1578: sb.append(getBorder()); 1579: sb.append(",maximumSize="); 1580: if (getMaximumSize() != null) 1581: sb.append(getMaximumSize()); 1582: sb.append(",minimumSize="); 1583: if (getMinimumSize() != null) 1584: sb.append(getMinimumSize()); 1585: sb.append(",preferredSize="); 1586: if (getPreferredSize() != null) 1587: sb.append(getPreferredSize()); 1588: return sb.toString(); 1589: } 1590: 1591: /** 1592: * A variant of {@link 1593: * #registerKeyboardAction(ActionListener,String,KeyStroke,int)} which 1594: * provides <code>null</code> for the command name. 1595: */ 1596: public void registerKeyboardAction(ActionListener act, 1597: KeyStroke stroke, 1598: int cond) 1599: { 1600: registerKeyboardAction(act, null, stroke, cond); 1601: } 1602: 1603: /* 1604: * There is some charmingly undocumented behavior sun seems to be using 1605: * to simulate the old register/unregister keyboard binding API. It's not 1606: * clear to me why this matters, but we shall endeavour to follow suit. 1607: * 1608: * Two main thing seem to be happening when you do registerKeyboardAction(): 1609: * 1610: * - no actionMap() entry gets created, just an entry in inputMap() 1611: * 1612: * - the inputMap() entry is a proxy class which invokes the the 1613: * binding's actionListener as a target, and which clobbers the command 1614: * name sent in the ActionEvent, providing the binding command name 1615: * instead. 1616: * 1617: * This much you can work out just by asking the input and action maps 1618: * what they contain after making bindings, and watching the event which 1619: * gets delivered to the recipient. Beyond that, it seems to be a 1620: * sun-private solution so I will only immitate it as much as it matters 1621: * to external observers. 1622: */ 1623: private static class ActionListenerProxy 1624: extends AbstractAction 1625: { 1626: ActionListener target; 1627: String bindingCommandName; 1628: 1629: public ActionListenerProxy(ActionListener li, 1630: String cmd) 1631: { 1632: target = li; 1633: bindingCommandName = cmd; 1634: } 1635: 1636: public void actionPerformed(ActionEvent e) 1637: { 1638: ActionEvent derivedEvent = new ActionEvent(e.getSource(), 1639: e.getID(), 1640: bindingCommandName, 1641: e.getModifiers()); 1642: target.actionPerformed(derivedEvent); 1643: } 1644: } 1645: 1646: 1647: /** 1648: * An obsolete method to register a keyboard action on this component. 1649: * You should use <code>getInputMap</code> and <code>getActionMap</code> 1650: * to fetch mapping tables from keystrokes to commands, and commands to 1651: * actions, respectively, and modify those mappings directly. 1652: * 1653: * @param act The action to be registered 1654: * @param cmd The command to deliver in the delivered {@link 1655: * java.awt.event.ActionEvent} 1656: * @param stroke The keystroke to register on 1657: * @param cond One of the values {@link #UNDEFINED_CONDITION}, 1658: * {@link #WHEN_ANCESTOR_OF_FOCUSED_COMPONENT}, {@link #WHEN_FOCUSED}, or 1659: * {@link #WHEN_IN_FOCUSED_WINDOW}, indicating the condition which must 1660: * be met for the action to be fired 1661: * 1662: * @see #unregisterKeyboardAction 1663: * @see #getConditionForKeyStroke 1664: * @see #resetKeyboardActions 1665: */ 1666: public void registerKeyboardAction(ActionListener act, 1667: String cmd, 1668: KeyStroke stroke, 1669: int cond) 1670: { 1671: getInputMap(cond).put(stroke, new ActionListenerProxy(act, cmd)); 1672: } 1673: 1674: public final void setInputMap(int condition, InputMap map) 1675: { 1676: enableEvents(AWTEvent.KEY_EVENT_MASK); 1677: switch (condition) 1678: { 1679: case WHEN_FOCUSED: 1680: inputMap_whenFocused = map; 1681: break; 1682: 1683: case WHEN_ANCESTOR_OF_FOCUSED_COMPONENT: 1684: inputMap_whenAncestorOfFocused = map; 1685: break; 1686: 1687: case WHEN_IN_FOCUSED_WINDOW: 1688: inputMap_whenInFocusedWindow = map; 1689: break; 1690: 1691: case UNDEFINED_CONDITION: 1692: default: 1693: throw new IllegalArgumentException(); 1694: } 1695: } 1696: 1697: public final InputMap getInputMap(int condition) 1698: { 1699: enableEvents(AWTEvent.KEY_EVENT_MASK); 1700: switch (condition) 1701: { 1702: case WHEN_FOCUSED: 1703: if (inputMap_whenFocused == null) 1704: inputMap_whenFocused = new InputMap(); 1705: return inputMap_whenFocused; 1706: 1707: case WHEN_ANCESTOR_OF_FOCUSED_COMPONENT: 1708: if (inputMap_whenAncestorOfFocused == null) 1709: inputMap_whenAncestorOfFocused = new InputMap(); 1710: return inputMap_whenAncestorOfFocused; 1711: 1712: case WHEN_IN_FOCUSED_WINDOW: 1713: if (inputMap_whenInFocusedWindow == null) 1714: inputMap_whenInFocusedWindow = new InputMap(); 1715: return inputMap_whenInFocusedWindow; 1716: 1717: case UNDEFINED_CONDITION: 1718: default: 1719: return null; 1720: } 1721: } 1722: 1723: public final InputMap getInputMap() 1724: { 1725: return getInputMap(WHEN_FOCUSED); 1726: } 1727: 1728: public final ActionMap getActionMap() 1729: { 1730: if (actionMap == null) 1731: actionMap = new ActionMap(); 1732: return actionMap; 1733: } 1734: 1735: public final void setActionMap(ActionMap map) 1736: { 1737: actionMap = map; 1738: } 1739: 1740: /** 1741: * Return the condition that determines whether a registered action 1742: * occurs in response to the specified keystroke. 1743: * 1744: * @param ks The keystroke to return the condition of 1745: * 1746: * @return One of the values {@link #UNDEFINED_CONDITION}, {@link 1747: * #WHEN_ANCESTOR_OF_FOCUSED_COMPONENT}, {@link #WHEN_FOCUSED}, or {@link 1748: * #WHEN_IN_FOCUSED_WINDOW} 1749: * 1750: * @deprecated As of 1.3 KeyStrokes can be registered with multiple 1751: * simultaneous conditions. 1752: * 1753: * @see #registerKeyboardAction(ActionListener, KeyStroke, int) 1754: * @see #unregisterKeyboardAction 1755: * @see #resetKeyboardActions 1756: */ 1757: public int getConditionForKeyStroke(KeyStroke ks) 1758: { 1759: if (inputMap_whenFocused != null 1760: && inputMap_whenFocused.get(ks) != null) 1761: return WHEN_FOCUSED; 1762: else if (inputMap_whenAncestorOfFocused != null 1763: && inputMap_whenAncestorOfFocused.get(ks) != null) 1764: return WHEN_ANCESTOR_OF_FOCUSED_COMPONENT; 1765: else if (inputMap_whenInFocusedWindow != null 1766: && inputMap_whenInFocusedWindow.get(ks) != null) 1767: return WHEN_IN_FOCUSED_WINDOW; 1768: else 1769: return UNDEFINED_CONDITION; 1770: } 1771: 1772: /** 1773: * Get the ActionListener (typically an {@link Action} object) which is 1774: * associated with a particular keystroke. 1775: * 1776: * @param ks The keystroke to retrieve the action of 1777: * 1778: * @return The action associated with the specified keystroke 1779: * 1780: * @deprecated Use {@link #getActionMap()} 1781: */ 1782: public ActionListener getActionForKeyStroke(KeyStroke ks) 1783: { 1784: Object cmd = getInputMap().get(ks); 1785: if (cmd != null) 1786: { 1787: if (cmd instanceof ActionListenerProxy) 1788: return (ActionListenerProxy) cmd; 1789: else if (cmd instanceof String) 1790: return getActionMap().get(cmd); 1791: } 1792: return null; 1793: } 1794: 1795: /** 1796: * A hook for subclasses which want to customize event processing. 1797: */ 1798: protected void processComponentKeyEvent(KeyEvent e) 1799: { 1800: } 1801: 1802: /** 1803: * Override the default key dispatch system from Component to hook into 1804: * the swing {@link InputMap} / {@link ActionMap} system. 1805: * 1806: * See <a 1807: * href="http://java.sun.com/products/jfc/tsc/special_report/kestrel/keybindings.html"> 1808: * this report</a> for more details, it's somewhat complex. 1809: */ 1810: protected void processKeyEvent(KeyEvent e) 1811: { 1812: // let the AWT event processing send KeyEvents to registered listeners 1813: super.processKeyEvent(e); 1814: processComponentKeyEvent(e); 1815: 1816: if (e.isConsumed()) 1817: return; 1818: 1819: // Input maps are checked in this order: 1820: // 1. The focused component's WHEN_FOCUSED map is checked. 1821: // 2. The focused component's WHEN_ANCESTOR_OF_FOCUSED_COMPONENT map. 1822: // 3. The WHEN_ANCESTOR_OF_FOCUSED_COMPONENT maps of the focused 1823: // component's parent, then its parent's parent, and so on. 1824: // Note: Input maps for disabled components are skipped. 1825: // 4. The WHEN_IN_FOCUSED_WINDOW maps of all the enabled components in 1826: // the focused window are searched. 1827: 1828: if (processKeyBinding(KeyStroke.getKeyStrokeForEvent(e), 1829: e, WHEN_FOCUSED, e.getID() == KeyEvent.KEY_PRESSED)) 1830: // This is step 1 from above comment. 1831: e.consume(); 1832: else if (processKeyBinding(KeyStroke.getKeyStrokeForEvent(e), 1833: e, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, 1834: e.getID() == KeyEvent.KEY_PRESSED)) 1835: // This is step 2 from above comment. 1836: e.consume(); 1837: else 1838: { 1839: // This is step 3 from above comment. 1840: Container current = this; 1841: while ((current = current.getParent()) instanceof JComponent) 1842: { 1843: if (((JComponent)current).processKeyBinding 1844: (KeyStroke.getKeyStrokeForEvent(e), e, 1845: WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, 1846: e.getID() == KeyEvent.KEY_PRESSED)) 1847: { 1848: e.consume(); 1849: break; 1850: } 1851: if (current instanceof Window || current instanceof Applet 1852: || current instanceof JInternalFrame) 1853: break; 1854: } 1855: if (e.isConsumed()) 1856: return; 1857: 1858: // This is step 4 from above comment. 1859: // FIXME: Implement. Note, should use ComponentInputMaps rather 1860: // than walking the entire containment hierarchy. 1861: } 1862: } 1863: 1864: protected boolean processKeyBinding(KeyStroke ks, 1865: KeyEvent e, 1866: int condition, 1867: boolean pressed) 1868: { 1869: if (isEnabled()) 1870: { 1871: Action act = null; 1872: InputMap map = getInputMap(condition); 1873: if (map != null) 1874: { 1875: Object cmd = map.get(ks); 1876: if (cmd != null) 1877: { 1878: if (cmd instanceof ActionListenerProxy) 1879: act = (Action) cmd; 1880: else 1881: act = (Action) getActionMap().get(cmd); 1882: } 1883: } 1884: if (act != null && act.isEnabled()) 1885: return SwingUtilities.notifyAction(act, ks, e, this, e.getModifiers()); 1886: } 1887: return false; 1888: } 1889: 1890: /** 1891: * Remove a keyboard action registry. 1892: * 1893: * @param aKeyStroke The keystroke to unregister 1894: * 1895: * @see #registerKeyboardAction(ActionListener, KeyStroke, int) 1896: * @see #getConditionForKeyStroke 1897: * @see #resetKeyboardActions 1898: */ 1899: public void unregisterKeyboardAction(KeyStroke aKeyStroke) 1900: { 1901: // FIXME: Must be implemented. 1902: } 1903: 1904: 1905: /** 1906: * Reset all keyboard action registries. 1907: * 1908: * @see #registerKeyboardAction(ActionListener, KeyStroke, int) 1909: * @see #unregisterKeyboardAction 1910: * @see #getConditionForKeyStroke 1911: */ 1912: public void resetKeyboardActions() 1913: { 1914: if (inputMap_whenFocused != null) 1915: inputMap_whenFocused.clear(); 1916: if (inputMap_whenAncestorOfFocused != null) 1917: inputMap_whenAncestorOfFocused.clear(); 1918: if (inputMap_whenInFocusedWindow != null) 1919: inputMap_whenInFocusedWindow.clear(); 1920: if (actionMap != null) 1921: actionMap.clear(); 1922: } 1923: 1924: /** 1925: * Mark the described region of this component as dirty in the current 1926: * {@link RepaintManager}. This will queue an asynchronous repaint using 1927: * the system painting thread in the near future. 1928: * 1929: * @param tm ignored 1930: * @param x coordinate of the region to mark as dirty 1931: * @param y coordinate of the region to mark as dirty 1932: * @param width dimension of the region to mark as dirty 1933: * @param height dimension of the region to mark as dirty 1934: */ 1935: public void repaint(long tm, int x, int y, int width, int height) 1936: { 1937: Rectangle dirty = new Rectangle(x, y, width, height); 1938: Rectangle vis = getVisibleRect(); 1939: dirty = dirty.intersection(vis); 1940: RepaintManager.currentManager(this).addDirtyRegion(this, dirty.x, dirty.y, 1941: dirty.width, 1942: dirty.height); 1943: } 1944: 1945: /** 1946: * Mark the described region of this component as dirty in the current 1947: * {@link RepaintManager}. This will queue an asynchronous repaint using 1948: * the system painting thread in the near future. 1949: * 1950: * @param r The rectangle to mark as dirty 1951: */ 1952: public void repaint(Rectangle r) 1953: { 1954: repaint((long) 0, (int) r.getX(), (int) r.getY(), (int) r.getWidth(), 1955: (int) r.getHeight()); 1956: } 1957: 1958: /** 1959: * Request focus on the default component of this component's {@link 1960: * FocusTraversalPolicy}. 1961: * 1962: * @return The result of {@link #requestFocus()} 1963: * 1964: * @deprecated Use {@link #requestFocus()} on the default component provided 1965: * from the {@link FocusTraversalPolicy} instead. 1966: */ 1967: public boolean requestDefaultFocus() 1968: { 1969: return false; 1970: } 1971: 1972: /** 1973: * Queue a an invalidation and revalidation of this component, using 1974: * {@link RepaintManager#addInvalidComponent}. 1975: */ 1976: public void revalidate() 1977: { 1978: invalidate(); 1979: RepaintManager.currentManager(this).addInvalidComponent(this); 1980: } 1981: 1982: /** 1983: * Calls <code>scrollRectToVisible</code> on the component's parent. 1984: * Components which can service this call should override. 1985: * 1986: * @param r The rectangle to make visible 1987: */ 1988: public void scrollRectToVisible(Rectangle r) 1989: { 1990: Component p = getParent(); 1991: if (p instanceof JComponent) 1992: ((JComponent) p).scrollRectToVisible(r); 1993: } 1994: 1995: /** 1996: * Set the value of the {@link #alignmentX} property. 1997: * 1998: * @param a The new value of the property 1999: */ 2000: public void setAlignmentX(float a) 2001: { 2002: alignmentX = a; 2003: } 2004: 2005: /** 2006: * Set the value of the {@link #alignmentY} property. 2007: * 2008: * @param a The new value of the property 2009: */ 2010: public void setAlignmentY(float a) 2011: { 2012: alignmentY = a; 2013: } 2014: 2015: /** 2016: * Set the value of the {@link #autoscrolls} property. 2017: * 2018: * @param a The new value of the property 2019: */ 2020: public void setAutoscrolls(boolean a) 2021: { 2022: autoscrolls = a; 2023: } 2024: 2025: /** 2026: * Set the value of the {@link #debugGraphicsOptions} property. 2027: * 2028: * @param debugOptions The new value of the property 2029: */ 2030: public void setDebugGraphicsOptions(int debugOptions) 2031: { 2032: debugGraphicsOptions = debugOptions; 2033: } 2034: 2035: /** 2036: * Set the value of the {@link #doubleBuffered} property. 2037: * 2038: * @param db The new value of the property 2039: */ 2040: public void setDoubleBuffered(boolean db) 2041: { 2042: doubleBuffered = db; 2043: } 2044: 2045: /** 2046: * Set the value of the <code>enabled</code> property. 2047: * 2048: * @param enable The new value of the property 2049: */ 2050: public void setEnabled(boolean enable) 2051: { 2052: boolean oldEnabled = isEnabled(); 2053: super.setEnabled(enable); 2054: firePropertyChange("enabled", oldEnabled, enable); 2055: } 2056: 2057: /** 2058: * Set the value of the <code>font</code> property. 2059: * 2060: * @param f The new value of the property 2061: */ 2062: public void setFont(Font f) 2063: { 2064: super.setFont(f); 2065: } 2066: 2067: /** 2068: * Set the value of the <code>background</code> property. 2069: * 2070: * @param bg The new value of the property 2071: */ 2072: public void setBackground(Color bg) 2073: { 2074: super.setBackground(bg); 2075: } 2076: 2077: /** 2078: * Set the value of the <code>foreground</code> property. 2079: * 2080: * @param fg The new value of the property 2081: */ 2082: public void setForeground(Color fg) 2083: { 2084: super.setForeground(fg); 2085: } 2086: 2087: /** 2088: * Set the value of the {@link #maximumSize} property. 2089: * 2090: * @param max The new value of the property 2091: */ 2092: public void setMaximumSize(Dimension max) 2093: { 2094: Dimension oldMaximumSize = maximumSize; 2095: maximumSize = max; 2096: firePropertyChange("maximumSize", oldMaximumSize, maximumSize); 2097: } 2098: 2099: /** 2100: * Set the value of the {@link #minimumSize} property. 2101: * 2102: * @param min The new value of the property 2103: */ 2104: public void setMinimumSize(Dimension min) 2105: { 2106: Dimension oldMinimumSize = minimumSize; 2107: minimumSize = min; 2108: firePropertyChange("minimumSize", oldMinimumSize, minimumSize); 2109: } 2110: 2111: /** 2112: * Set the value of the {@link #preferredSize} property. 2113: * 2114: * @param pref The new value of the property 2115: */ 2116: public void setPreferredSize(Dimension pref) 2117: { 2118: Dimension oldPreferredSize = preferredSize; 2119: preferredSize = pref; 2120: firePropertyChange("preferredSize", oldPreferredSize, preferredSize); 2121: } 2122: 2123: /** 2124: * Set the specified component to be the next component in the 2125: * focus cycle, overriding the {@link FocusTraversalPolicy} for 2126: * this component. 2127: * 2128: * @param aComponent The component to set as the next focusable 2129: * 2130: * @deprecated Use FocusTraversalPolicy instead 2131: */ 2132: public void setNextFocusableComponent(Component aComponent) 2133: { 2134: } 2135: 2136: /** 2137: * Set the value of the {@link #requestFocusEnabled} property. 2138: * 2139: * @param e The new value of the property 2140: */ 2141: public void setRequestFocusEnabled(boolean e) 2142: { 2143: requestFocusEnabled = e; 2144: } 2145: 2146: /** 2147: * Get the value of the {@link #transferHandler} property. 2148: * 2149: * @return The current value of the property 2150: * 2151: * @see #setTransferHandler 2152: */ 2153: 2154: public TransferHandler getTransferHandler() 2155: { 2156: return transferHandler; 2157: } 2158: 2159: /** 2160: * Set the value of the {@link #transferHandler} property. 2161: * 2162: * @param newHandler The new value of the property 2163: * 2164: * @see #getTransferHandler 2165: */ 2166: 2167: public void setTransferHandler(TransferHandler newHandler) 2168: { 2169: if (transferHandler == newHandler) 2170: return; 2171: 2172: TransferHandler oldHandler = transferHandler; 2173: transferHandler = newHandler; 2174: firePropertyChange("transferHandler", oldHandler, newHandler); 2175: } 2176: 2177: /** 2178: * Set the value of the {@link #opaque} property. 2179: * 2180: * @param isOpaque The new value of the property 2181: * 2182: * @see ComponentUI#update 2183: */ 2184: public void setOpaque(boolean isOpaque) 2185: { 2186: boolean oldOpaque = opaque; 2187: opaque = isOpaque; 2188: firePropertyChange("opaque", oldOpaque, opaque); 2189: } 2190: 2191: /** 2192: * Set the value of the visible property. 2193: * 2194: * @param v The new value of the property 2195: */ 2196: public void setVisible(boolean v) 2197: { 2198: super.setVisible(v); 2199: } 2200: 2201: /** 2202: * Call {@link #paint}. 2203: * 2204: * @param g The graphics context to paint into 2205: */ 2206: public void update(Graphics g) 2207: { 2208: paint(g); 2209: } 2210: 2211: /** 2212: * Get the value of the UIClassID property. This property should be a key 2213: * in the {@link UIDefaults} table managed by {@link UIManager}, the 2214: * value of which is the name of a class to load for the component's 2215: * {@link #ui} property. 2216: * 2217: * @return A "symbolic" name which will map to a class to use for the 2218: * component's UI, such as <code>"ComponentUI"</code> 2219: * 2220: * @see #setUI 2221: * @see #updateUI 2222: */ 2223: public String getUIClassID() 2224: { 2225: return "ComponentUI"; 2226: } 2227: 2228: /** 2229: * Install a new UI delegate as the component's {@link #ui} property. In 2230: * the process, this will call {@link ComponentUI#uninstallUI} on any 2231: * existing value for the {@link #ui} property, and {@link 2232: * ComponentUI#installUI} on the new UI delegate. 2233: * 2234: * @param newUI The new UI delegate to install 2235: * 2236: * @see #updateUI 2237: * @see #getUIClassID 2238: */ 2239: protected void setUI(ComponentUI newUI) 2240: { 2241: if (ui != null) 2242: ui.uninstallUI(this); 2243: 2244: ComponentUI oldUI = ui; 2245: ui = newUI; 2246: 2247: if (ui != null) 2248: ui.installUI(this); 2249: 2250: firePropertyChange("UI", oldUI, newUI); 2251: 2252: } 2253: 2254: /** 2255: * This method should be overridden in subclasses. In JComponent, the 2256: * method does nothing. In subclasses, it should a UI delegate 2257: * (corresponding to the symbolic name returned from {@link 2258: * #getUIClassID}) from the {@link UIManager}, and calls {@link #setUI} 2259: * with the new delegate. 2260: */ 2261: public void updateUI() 2262: { 2263: System.out.println("update UI not overwritten in class: " + this); 2264: } 2265: 2266: public static Locale getDefaultLocale() 2267: { 2268: return defaultLocale; 2269: } 2270: 2271: public static void setDefaultLocale(Locale l) 2272: { 2273: defaultLocale = l; 2274: } 2275: 2276: /** 2277: * Returns the currently set input verifier for this component. 2278: * 2279: * @return the input verifier, or <code>null</code> if none 2280: */ 2281: public InputVerifier getInputVerifier() 2282: { 2283: return inputVerifier; 2284: } 2285: 2286: /** 2287: * Sets the input verifier to use by this component. 2288: * 2289: * @param verifier the input verifier, or <code>null</code> 2290: */ 2291: public void setInputVerifier(InputVerifier verifier) 2292: { 2293: InputVerifier oldVerifier = inputVerifier; 2294: inputVerifier = verifier; 2295: firePropertyChange("inputVerifier", oldVerifier, verifier); 2296: } 2297: 2298: /** 2299: * @since 1.3 2300: */ 2301: public boolean getVerifyInputWhenFocusTarget() 2302: { 2303: return verifyInputWhenFocusTarget; 2304: } 2305: 2306: /** 2307: * @since 1.3 2308: */ 2309: public void setVerifyInputWhenFocusTarget(boolean verifyInputWhenFocusTarget) 2310: { 2311: if (this.verifyInputWhenFocusTarget == verifyInputWhenFocusTarget) 2312: return; 2313: 2314: this.verifyInputWhenFocusTarget = verifyInputWhenFocusTarget; 2315: firePropertyChange("verifyInputWhenFocusTarget", 2316: ! verifyInputWhenFocusTarget, 2317: verifyInputWhenFocusTarget); 2318: } 2319: 2320: /** 2321: * Requests that this component gets the input focus if the 2322: * requestFocusEnabled property is set to <code>true</code>. 2323: * This also means that this component's top-level window becomes 2324: * the focused window, if that is not already the case. 2325: * 2326: * The preconditions that have to be met to become a focus owner is that 2327: * the component must be displayable, visible and focusable. 2328: * 2329: * Note that this signals only a request for becoming focused. There are 2330: * situations in which it is not possible to get the focus. So developers 2331: * should not assume that the component has the focus until it receives 2332: * a {@link java.awt.event.FocusEvent} with a value of 2333: * {@link java.awt.event.FocusEvent#FOCUS_GAINED}. 2334: * 2335: * @see Component#requestFocus() 2336: */ 2337: public void requestFocus() 2338: { 2339: if (isRequestFocusEnabled()) 2340: super.requestFocus(); 2341: } 2342: 2343: /** 2344: * This method is overridden to make it public so that it can be used 2345: * by look and feel implementations. 2346: * 2347: * You should not use this method directly. Instead you are strongly 2348: * encouraged to call {@link #requestFocus()} or 2349: * {@link #requestFocusInWindow()} instead. 2350: * 2351: * @param temporary if the focus change is temporary 2352: * 2353: * @return <code>false</code> if the focus change request will definitly 2354: * fail, <code>true</code> if it will likely succeed 2355: * 2356: * @see Component#requestFocus(boolean) 2357: * 2358: * @since 1.4 2359: */ 2360: public boolean requestFocus(boolean temporary) 2361: { 2362: return super.requestFocus(temporary); 2363: } 2364: 2365: /** 2366: * Requests that this component gets the input focus if the top level 2367: * window that contains this component has the focus and the 2368: * requestFocusEnabled property is set to <code>true</code>. 2369: * 2370: * The preconditions that have to be met to become a focus owner is that 2371: * the component must be displayable, visible and focusable. 2372: * 2373: * Note that this signals only a request for becoming focused. There are 2374: * situations in which it is not possible to get the focus. So developers 2375: * should not assume that the component has the focus until it receives 2376: * a {@link java.awt.event.FocusEvent} with a value of 2377: * {@link java.awt.event.FocusEvent#FOCUS_GAINED}. 2378: * 2379: * @return <code>false</code> if the focus change request will definitly 2380: * fail, <code>true</code> if it will likely succeed 2381: * 2382: * @see Component#requestFocusInWindow() 2383: */ 2384: public boolean requestFocusInWindow() 2385: { 2386: if (isRequestFocusEnabled()) 2387: return super.requestFocusInWindow(); 2388: else 2389: return false; 2390: } 2391: 2392: /** 2393: * This method is overridden to make it public so that it can be used 2394: * by look and feel implementations. 2395: * 2396: * You should not use this method directly. Instead you are strongly 2397: * encouraged to call {@link #requestFocus()} or 2398: * {@link #requestFocusInWindow()} instead. 2399: * 2400: * @param temporary if the focus change is temporary 2401: * 2402: * @return <code>false</code> if the focus change request will definitly 2403: * fail, <code>true</code> if it will likely succeed 2404: * 2405: * @see Component#requestFocus(boolean) 2406: * 2407: * @since 1.4 2408: */ 2409: public boolean requestFocusInWindow(boolean temporary) 2410: { 2411: return super.requestFocusInWindow(temporary); 2412: } 2413: 2414: /** 2415: * Receives notification if this component is added to a parent component. 2416: * 2417: * Notification is sent to all registered AncestorListeners about the 2418: * new parent. 2419: * 2420: * This method sets up ActionListeners for all registered KeyStrokes of 2421: * this component in the chain of parent components. 2422: * 2423: * A PropertyChange event is fired to indicate that the ancestor property 2424: * has changed. 2425: * 2426: * This method is used internally and should not be used in applications. 2427: */ 2428: public void addNotify() 2429: { 2430: super.addNotify(); 2431: 2432: // let parents inherit the keybord mapping 2433: InputMap input = getInputMap(); 2434: ActionMap actions = getActionMap(); 2435: 2436: Container parent = getParent(); 2437: while ((parent != null) && (parent instanceof JComponent)) 2438: { 2439: JComponent jParent = (JComponent) parent; 2440: InputMap parentInput = jParent.getInputMap(); 2441: ActionMap parentAction = jParent.getActionMap(); 2442: 2443: KeyStroke[] ikeys = input.keys(); 2444: for (int i = 0; i < ikeys.length; i++) 2445: { 2446: Object o = input.get(ikeys[i]); 2447: parentInput.put(ikeys[i], o); 2448: } 2449: 2450: Object[] akeys = actions.keys(); 2451: for (int i = 0; i < akeys.length; i++) 2452: { 2453: Action a = actions.get(akeys[i]); 2454: parentAction.put(akeys[i], a); 2455: } 2456: 2457: parent = jParent.getParent(); 2458: } 2459: 2460: // notify ancestor listeners 2461: AncestorListener[] ls = getAncestorListeners(); 2462: AncestorEvent ev = new AncestorEvent(this, AncestorEvent.ANCESTOR_ADDED, 2463: this, parent); 2464: for (int i = 0; i < ls.length; i++) 2465: { 2466: ls[i].ancestorAdded(ev); 2467: } 2468: 2469: // fire property change event for 'ancestor' 2470: firePropertyChange("ancestor", null, parent); 2471: } 2472: 2473: /** 2474: * Receives notification that this component no longer has a parent. 2475: * 2476: * This method sends an AncestorEvent to all registered AncestorListeners, 2477: * notifying them that the parent is gone. 2478: * 2479: * The keybord actions of this component are removed from the parent and 2480: * its ancestors. 2481: * 2482: * A PropertyChangeEvent is fired to indicate that the 'ancestor' property 2483: * has changed. 2484: * 2485: * This method is called before the component is actually removed from 2486: * its parent, so the parent is still visible through 2487: * {@link Component#getParent}. 2488: */ 2489: public void removeNotify() 2490: { 2491: super.removeNotify(); 2492: 2493: // let parents inherit the keybord mapping 2494: InputMap input = getInputMap(); 2495: ActionMap actions = getActionMap(); 2496: 2497: Container parent = getParent(); 2498: while ((parent != null) && (parent instanceof JComponent)) 2499: { 2500: JComponent jParent = (JComponent) parent; 2501: InputMap parentInput = jParent.getInputMap(); 2502: ActionMap parentAction = jParent.getActionMap(); 2503: 2504: KeyStroke[] ikeys = input.allKeys(); 2505: for (int i = 0; i < ikeys.length; i++) 2506: { 2507: parentInput.remove(ikeys[i]); 2508: } 2509: 2510: Object[] akeys = actions.allKeys(); 2511: for (int i = 0; i < akeys.length; i++) 2512: { 2513: parentAction.remove(akeys[i]); 2514: } 2515: 2516: parent = jParent.getParent(); 2517: } 2518: 2519: // notify ancestor listeners 2520: AncestorListener[] ls = getAncestorListeners(); 2521: AncestorEvent ev = new AncestorEvent(this, AncestorEvent.ANCESTOR_ADDED, 2522: this, parent); 2523: for (int i = 0; i < ls.length; i++) 2524: { 2525: ls[i].ancestorAdded(ev); 2526: } 2527: 2528: // fire property change event for 'ancestor' 2529: firePropertyChange("ancestor", parent, null); 2530: } 2531: 2532: /** 2533: * Returns <code>true</code> if the coordinates (x, y) lie within 2534: * the bounds of this component and <code>false</code> otherwise. 2535: * x and y are relative to the coordinate space of the component. 2536: * 2537: * @param x the X coordinate of the point to check 2538: * @param y the Y coordinate of the point to check 2539: * 2540: * @return <code>true</code> if the specified point lies within the bounds 2541: * of this component, <code>false</code> otherwise 2542: */ 2543: public boolean contains(int x, int y) 2544: { 2545: if (ui == null) 2546: return super.contains(x, y); 2547: else 2548: return ui.contains(this, x, y); 2549: } 2550: 2551: /** 2552: * Disables this component. 2553: * 2554: * @deprecated replaced by {@link #setEnabled(boolean)} 2555: */ 2556: public void disable() 2557: { 2558: super.disable(); 2559: } 2560: 2561: /** 2562: * Enables this component. 2563: * 2564: * @deprecated replaced by {@link #setEnabled(boolean)} 2565: */ 2566: public void enable() 2567: { 2568: super.enable(); 2569: } 2570: 2571: /** 2572: * Returns the Graphics context for this component. This can be used 2573: * to draw on a component. 2574: * 2575: * @return the Graphics context for this component 2576: */ 2577: public Graphics getGraphics() 2578: { 2579: return super.getGraphics(); 2580: } 2581: 2582: /** 2583: * Returns the X coordinate of the upper left corner of this component. 2584: * Prefer this method over {@link #getBounds} or {@link #getLocation} 2585: * because it does not cause any heap allocation. 2586: * 2587: * @return the X coordinate of the upper left corner of the component 2588: */ 2589: public int getX() 2590: { 2591: return super.getX(); 2592: } 2593: 2594: /** 2595: * Returns the Y coordinate of the upper left corner of this component. 2596: * Prefer this method over {@link #getBounds} or {@link #getLocation} 2597: * because it does not cause any heap allocation. 2598: * 2599: * @return the Y coordinate of the upper left corner of the component 2600: */ 2601: public int getY() 2602: { 2603: return super.getY(); 2604: } 2605: 2606: /** 2607: * Returns the height of this component. Prefer this method over 2608: * {@link #getBounds} or {@link #getSize} because it does not cause 2609: * any heap allocation. 2610: * 2611: * @return the height of the component 2612: */ 2613: public int getHeight() 2614: { 2615: return super.getHeight(); 2616: } 2617: 2618: /** 2619: * Returns the width of this component. Prefer this method over 2620: * {@link #getBounds} or {@link #getSize} because it does not cause 2621: * any heap allocation. 2622: * 2623: * @return the width of the component 2624: */ 2625: public int getWidth() 2626: { 2627: return super.getWidth(); 2628: } 2629: 2630: /** 2631: * Return all <code>PropertyChangeListener</code> objects registered. 2632: * 2633: * @return The set of <code>PropertyChangeListener</code> objects 2634: */ 2635: public PropertyChangeListener[] getPropertyChangeListeners() 2636: { 2637: if (changeSupport == null) 2638: return new PropertyChangeListener[0]; 2639: else 2640: return changeSupport.getPropertyChangeListeners(); 2641: } 2642: 2643: /** 2644: * Prints this component to the given Graphics context. A call to this 2645: * method results in calls to the methods {@link #printComponent}, 2646: * {@link #printBorder} and {@link #printChildren} in this order. 2647: * 2648: * Double buffering is temporarily turned off so the painting goes directly 2649: * to the supplied Graphics context. 2650: * 2651: * @param g the Graphics context to print onto 2652: */ 2653: public void print(Graphics g) 2654: { 2655: boolean doubleBufferState = isDoubleBuffered(); 2656: setDoubleBuffered(false); 2657: printComponent(g); 2658: printBorder(g); 2659: printChildren(g); 2660: setDoubleBuffered(doubleBufferState); 2661: } 2662: 2663: /** 2664: * Prints this component to the given Graphics context. This invokes 2665: * {@link #print}. 2666: * 2667: * @param g the Graphics context to print onto 2668: */ 2669: public void printAll(Graphics g) 2670: { 2671: print(g); 2672: } 2673: 2674: /** 2675: * Prints this component to the specified Graphics context. The default 2676: * behaviour is to invoke {@link #paintComponent}. Override this 2677: * if you want special behaviour for printing. 2678: * 2679: * @param g the Graphics context to print onto 2680: * 2681: * @since 1.3 2682: */ 2683: public void printComponent(Graphics g) 2684: { 2685: paintComponent(g); 2686: } 2687: 2688: /** 2689: * Print this component's children to the specified Graphics context. 2690: * The default behaviour is to invoke {@link #paintChildren}. Override this 2691: * if you want special behaviour for printing. 2692: * 2693: * @param g the Graphics context to print onto 2694: * 2695: * @since 1.3 2696: */ 2697: public void printChildren(Graphics g) 2698: { 2699: paintChildren(g); 2700: } 2701: 2702: /** 2703: * Print this component's border to the specified Graphics context. 2704: * The default behaviour is to invoke {@link #paintBorder}. Override this 2705: * if you want special behaviour for printing. 2706: * 2707: * @param g the Graphics context to print onto 2708: * 2709: * @since 1.3 2710: */ 2711: public void printBorder(Graphics g) 2712: { 2713: paintBorder(g); 2714: } 2715: 2716: /** 2717: * Processes mouse motion event, like dragging and moving. 2718: * 2719: * @param ev the MouseEvent describing the mouse motion 2720: */ 2721: protected void processMouseMotionEvent(MouseEvent ev) 2722: { 2723: super.processMouseMotionEvent(ev); 2724: } 2725: 2726: /** 2727: * Moves and resizes the component. 2728: * 2729: * @param x the new horizontal location 2730: * @param y the new vertial location 2731: * @param w the new width 2732: * @param h the new height 2733: */ 2734: public void reshape(int x, int y, int w, int h) 2735: { 2736: super.reshape(x, y, w, h); 2737: } 2738: }
GNU Classpath (0.18) |