jdk/src/share/classes/javax/swing/JComponent.java

Print this page




   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 package javax.swing;
  26 
  27 
  28 import java.util.HashSet;
  29 import java.util.Hashtable;
  30 import java.util.Dictionary;
  31 import java.util.Enumeration;
  32 import java.util.Locale;
  33 import java.util.Vector;
  34 import java.util.EventListener;
  35 import java.util.Set;
  36 import java.util.Map;
  37 import java.util.HashMap;
  38 
  39 import java.awt.*;
  40 import java.awt.event.*;
  41 import java.awt.image.VolatileImage;
  42 import java.awt.Graphics2D;
  43 import java.awt.peer.LightweightPeer;
  44 import java.awt.dnd.DropTarget;
  45 import java.awt.font.FontRenderContext;
  46 import java.beans.PropertyChangeListener;
  47 import java.beans.VetoableChangeListener;
  48 import java.beans.VetoableChangeSupport;
  49 import java.beans.Transient;
  50 
  51 import java.applet.Applet;
  52 
  53 import java.io.Serializable;
  54 import java.io.ObjectOutputStream;
  55 import java.io.ObjectInputStream;
  56 import java.io.IOException;
  57 import java.io.ObjectInputValidation;
  58 import java.io.InvalidObjectException;
  59 
  60 import javax.swing.border.*;
  61 import javax.swing.event.*;
  62 import javax.swing.plaf.*;
  63 import static javax.swing.ClientPropertyKey.*;
  64 import javax.accessibility.*;
  65 


 164  * future Swing releases. The current serialization support is
 165  * appropriate for short term storage or RMI between applications running
 166  * the same version of Swing.  As of 1.4, support for long term storage
 167  * of all JavaBeans™
 168  * has been added to the <code>java.beans</code> package.
 169  * Please see {@link java.beans.XMLEncoder}.
 170  *
 171  * @see KeyStroke
 172  * @see Action
 173  * @see #setBorder
 174  * @see #registerKeyboardAction
 175  * @see JOptionPane
 176  * @see #setDebugGraphicsOptions
 177  * @see #setToolTipText
 178  * @see #setAutoscrolls
 179  *
 180  * @author Hans Muller
 181  * @author Arnaud Weber
 182  * @since 1.2
 183  */

 184 @SuppressWarnings("serial") // Same-version serialization only
 185 public abstract class JComponent extends Container implements Serializable,
 186                                               TransferHandler.HasGetTransferHandler
 187 {
 188     /**
 189      * @see #getUIClassID
 190      * @see #writeObject
 191      */
 192     private static final String uiClassID = "ComponentUI";
 193 
 194     /**
 195      * @see #readObject
 196      */
 197     private static final Hashtable<ObjectInputStream, ReadObjectCallback> readObjectCallbacks =
 198             new Hashtable<ObjectInputStream, ReadObjectCallback>(1);
 199 
 200     /**
 201      * Keys to use for forward focus traversal when the JComponent is
 202      * managing focus.
 203      */


 465 
 466     private static void recycleRectangle(Rectangle rect) {
 467         synchronized(tempRectangles) {
 468             tempRectangles.add(rect);
 469         }
 470     }
 471 
 472     /**
 473      * Sets whether or not <code>getComponentPopupMenu</code> should delegate
 474      * to the parent if this component does not have a <code>JPopupMenu</code>
 475      * assigned to it.
 476      * <p>
 477      * The default value for this is false, but some <code>JComponent</code>
 478      * subclasses that are implemented as a number of <code>JComponent</code>s
 479      * may set this to true.
 480      * <p>
 481      * This is a bound property.
 482      *
 483      * @param value whether or not the JPopupMenu is inherited
 484      * @see #setComponentPopupMenu
 485      * @beaninfo
 486      *        bound: true
 487      *  description: Whether or not the JPopupMenu is inherited
 488      * @since 1.5
 489      */


 490     public void setInheritsPopupMenu(boolean value) {
 491         boolean oldValue = getFlag(INHERITS_POPUP_MENU);
 492         setFlag(INHERITS_POPUP_MENU, value);
 493         firePropertyChange("inheritsPopupMenu", oldValue, value);
 494     }
 495 
 496     /**
 497      * Returns true if the JPopupMenu should be inherited from the parent.
 498      *
 499      * @return true if the JPopupMenu should be inherited from the parent
 500      * @see #setComponentPopupMenu
 501      * @since 1.5
 502      */
 503     public boolean getInheritsPopupMenu() {
 504         return getFlag(INHERITS_POPUP_MENU);
 505     }
 506 
 507     /**
 508      * Sets the <code>JPopupMenu</code> for this <code>JComponent</code>.
 509      * The UI is responsible for registering bindings and adding the necessary
 510      * listeners such that the <code>JPopupMenu</code> will be shown at
 511      * the appropriate time. When the <code>JPopupMenu</code> is shown
 512      * depends upon the look and feel: some may show it on a mouse event,
 513      * some may enable a key binding.
 514      * <p>
 515      * If <code>popup</code> is null, and <code>getInheritsPopupMenu</code>
 516      * returns true, then <code>getComponentPopupMenu</code> will be delegated
 517      * to the parent. This provides for a way to make all child components
 518      * inherit the popupmenu of the parent.
 519      * <p>
 520      * This is a bound property.
 521      *
 522      * @param popup - the popup that will be assigned to this component
 523      *                may be null
 524      * @see #getComponentPopupMenu
 525      * @beaninfo
 526      *        bound: true
 527      *    preferred: true
 528      *  description: Popup to show
 529      * @since 1.5
 530      */


 531     public void setComponentPopupMenu(JPopupMenu popup) {
 532         if(popup != null) {
 533             enableEvents(AWTEvent.MOUSE_EVENT_MASK);
 534         }
 535         JPopupMenu oldPopup = this.popupMenu;
 536         this.popupMenu = popup;
 537         firePropertyChange("componentPopupMenu", oldPopup, popup);
 538     }
 539 
 540     /**
 541      * Returns <code>JPopupMenu</code> that assigned for this component.
 542      * If this component does not have a <code>JPopupMenu</code> assigned
 543      * to it and <code>getInheritsPopupMenu</code> is true, this
 544      * will return <code>getParent().getComponentPopupMenu()</code> (assuming
 545      * the parent is valid.)
 546      *
 547      * @return <code>JPopupMenu</code> assigned for this component
 548      *         or <code>null</code> if no popup assigned
 549      * @see #setComponentPopupMenu
 550      * @since 1.5


 626      * <code>JComponent</code> subclasses generally override this method
 627      * to narrow the argument type. For example, in <code>JSlider</code>:
 628      * <pre>
 629      * public void setUI(SliderUI newUI) {
 630      *     super.setUI(newUI);
 631      * }
 632      *  </pre>
 633      * <p>
 634      * Additionally <code>JComponent</code> subclasses must provide a
 635      * <code>getUI</code> method that returns the correct type.  For example:
 636      * <pre>
 637      * public SliderUI getUI() {
 638      *     return (SliderUI)ui;
 639      * }
 640      * </pre>
 641      *
 642      * @param newUI the new UI delegate
 643      * @see #updateUI
 644      * @see UIManager#getLookAndFeel
 645      * @see UIManager#getUI
 646      * @beaninfo
 647      *        bound: true
 648      *       hidden: true
 649      *    attribute: visualUpdate true
 650      *  description: The component's look and feel delegate.
 651      */


 652     protected void setUI(ComponentUI newUI) {
 653         /* We do not check that the UI instance is different
 654          * before allowing the switch in order to enable the
 655          * same UI instance *with different default settings*
 656          * to be installed.
 657          */
 658 
 659         uninstallUIAndProperties();
 660 
 661         // aaText shouldn't persist between look and feels, reset it.
 662         aaTextInfo =
 663             UIManager.getDefaults().get(SwingUtilities2.AA_TEXT_PROPERTY_KEY);
 664         ComponentUI oldUI = ui;
 665         ui = newUI;
 666         if (ui != null) {
 667             ui.installUI(this);
 668         }
 669 
 670         firePropertyChange("UI", oldUI, newUI);
 671         revalidate();


 693                         }
 694                     }
 695                 }
 696             }
 697         }
 698     }
 699 
 700     /**
 701      * Returns the <code>UIDefaults</code> key used to
 702      * look up the name of the <code>swing.plaf.ComponentUI</code>
 703      * class that defines the look and feel
 704      * for this component.  Most applications will never need to
 705      * call this method.  Subclasses of <code>JComponent</code> that support
 706      * pluggable look and feel should override this method to
 707      * return a <code>UIDefaults</code> key that maps to the
 708      * <code>ComponentUI</code> subclass that defines their look and feel.
 709      *
 710      * @return the <code>UIDefaults</code> key for a
 711      *          <code>ComponentUI</code> subclass
 712      * @see UIDefaults#getUI
 713      * @beaninfo
 714      *      expert: true
 715      * description: UIClassID
 716      */


 717     public String getUIClassID() {
 718         return uiClassID;
 719     }
 720 
 721 
 722     /**
 723      * Returns the graphics object used to paint this component.
 724      * If <code>DebugGraphics</code> is turned on we create a new
 725      * <code>DebugGraphics</code> object if necessary.
 726      * Otherwise we just configure the
 727      * specified graphics object's foreground and font.
 728      *
 729      * @param g the original <code>Graphics</code> object
 730      * @return a <code>Graphics</code> object configured for this component
 731      */
 732     protected Graphics getComponentGraphics(Graphics g) {
 733         Graphics componentGraphics = g;
 734         if (ui != null && DEBUG_GRAPHICS_LOADED) {
 735             if ((DebugGraphics.debugComponentCount() != 0) &&
 736                     (shouldDebugGraphics() != 0) &&


1240      * wish to print the border differently that it is painted.
1241      *
1242      * @param g the <code>Graphics</code> context in which to paint
1243      * @see #print
1244      * @since 1.3
1245      */
1246     protected void printBorder(Graphics g) {
1247         paintBorder(g);
1248     }
1249 
1250     /**
1251      *  Returns true if the component is currently painting a tile.
1252      *  If this method returns true, paint will be called again for another
1253      *  tile. This method returns false if you are not painting a tile or
1254      *  if the last tile is painted.
1255      *  Use this method to keep some state you might need between tiles.
1256      *
1257      *  @return  true if the component is currently painting a tile,
1258      *          false otherwise
1259      */

1260     public boolean isPaintingTile() {
1261         return getFlag(IS_PAINTING_TILE);
1262     }
1263 
1264     /**
1265      * Returns <code>true</code> if the current painting operation on this
1266      * component is part of a <code>print</code> operation. This method is
1267      * useful when you want to customize what you print versus what you show
1268      * on the screen.
1269      * <p>
1270      * You can detect changes in the value of this property by listening for
1271      * property change events on this component with name
1272      * <code>"paintingForPrint"</code>.
1273      * <p>
1274      * Note: This method provides complimentary functionality to that provided
1275      * by other high level Swing printing APIs. However, it deals strictly with
1276      * painting and should not be confused as providing information on higher
1277      * level print processes. For example, a {@link javax.swing.JTable#print()}
1278      * operation doesn't necessarily result in a continuous rendering of the
1279      * full component, and the return value of this method can change multiple
1280      * times during that operation. It is even possible for the component to be
1281      * painted to the screen while the printing process is ongoing. In such a
1282      * case, the return value of this method is <code>true</code> when, and only
1283      * when, the table is being painted as part of the printing process.
1284      *
1285      * @return true if the current painting operation on this component
1286      *         is part of a print operation
1287      * @see #print
1288      * @since 1.6
1289      */

1290     public final boolean isPaintingForPrint() {
1291         return getFlag(IS_PRINTING);
1292     }
1293 
1294     /**
1295      * In release 1.4, the focus subsystem was rearchitected.
1296      * For more information, see
1297      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
1298      * How to Use the Focus Subsystem</a>,
1299      * a section in <em>The Java Tutorial</em>.
1300      * <p>
1301      * Changes this <code>JComponent</code>'s focus traversal keys to
1302      * CTRL+TAB and CTRL+SHIFT+TAB. Also prevents
1303      * <code>SortingFocusTraversalPolicy</code> from considering descendants
1304      * of this JComponent when computing a focus traversal cycle.
1305      *
1306      * @return false
1307      * @see java.awt.Component#setFocusTraversalKeys
1308      * @see SortingFocusTraversalPolicy
1309      * @deprecated As of 1.4, replaced by
1310      *   <code>Component.setFocusTraversalKeys(int, Set)</code> and
1311      *   <code>Container.setFocusCycleRoot(boolean)</code>.
1312      */
1313     @Deprecated

1314     public boolean isManagingFocus() {
1315         return false;
1316     }
1317 
1318     private void registerNextFocusableComponent() {
1319         registerNextFocusableComponent(getNextFocusableComponent());
1320     }
1321 
1322     private void registerNextFocusableComponent(Component
1323                                                 nextFocusableComponent) {
1324         if (nextFocusableComponent == null) {
1325             return;
1326         }
1327 
1328         Container nearestRoot =
1329             (isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
1330         FocusTraversalPolicy policy = nearestRoot.getFocusTraversalPolicy();
1331         if (!(policy instanceof LegacyGlueFocusTraversalPolicy)) {
1332             policy = new LegacyGlueFocusTraversalPolicy(policy);
1333             nearestRoot.setFocusTraversalPolicy(policy);


1564     public void grabFocus() {
1565         requestFocus();
1566     }
1567 
1568     /**
1569      * Sets the value to indicate whether input verifier for the
1570      * current focus owner will be called before this component requests
1571      * focus. The default is true. Set to false on components such as a
1572      * Cancel button or a scrollbar, which should activate even if the
1573      * input in the current focus owner is not "passed" by the input
1574      * verifier for that component.
1575      *
1576      * @param verifyInputWhenFocusTarget value for the
1577      *        <code>verifyInputWhenFocusTarget</code> property
1578      * @see InputVerifier
1579      * @see #setInputVerifier
1580      * @see #getInputVerifier
1581      * @see #getVerifyInputWhenFocusTarget
1582      *
1583      * @since 1.3
1584      * @beaninfo
1585      *       bound: true
1586      * description: Whether the Component verifies input before accepting
1587      *              focus.
1588      */


1589     public void setVerifyInputWhenFocusTarget(boolean
1590                                               verifyInputWhenFocusTarget) {
1591         boolean oldVerifyInputWhenFocusTarget =
1592             this.verifyInputWhenFocusTarget;
1593         this.verifyInputWhenFocusTarget = verifyInputWhenFocusTarget;
1594         firePropertyChange("verifyInputWhenFocusTarget",
1595                            oldVerifyInputWhenFocusTarget,
1596                            verifyInputWhenFocusTarget);
1597     }
1598 
1599     /**
1600      * Returns the value that indicates whether the input verifier for the
1601      * current focus owner will be called before this component requests
1602      * focus.
1603      *
1604      * @return value of the <code>verifyInputWhenFocusTarget</code> property
1605      *
1606      * @see InputVerifier
1607      * @see #setInputVerifier
1608      * @see #getInputVerifier


1616 
1617 
1618     /**
1619      * Gets the <code>FontMetrics</code> for the specified <code>Font</code>.
1620      *
1621      * @param font the font for which font metrics is to be
1622      *          obtained
1623      * @return the font metrics for <code>font</code>
1624      * @throws NullPointerException if <code>font</code> is null
1625      * @since 1.5
1626      */
1627     public FontMetrics getFontMetrics(Font font) {
1628         return SwingUtilities2.getFontMetrics(this, font);
1629     }
1630 
1631 
1632     /**
1633      * Sets the preferred size of this component.
1634      * If <code>preferredSize</code> is <code>null</code>, the UI will
1635      * be asked for the preferred size.
1636      * @beaninfo
1637      *   preferred: true
1638      *       bound: true
1639      * description: The preferred size of the component.
1640      */


1641     public void setPreferredSize(Dimension preferredSize) {
1642         super.setPreferredSize(preferredSize);
1643     }
1644 
1645 
1646     /**
1647      * If the <code>preferredSize</code> has been set to a
1648      * non-<code>null</code> value just returns it.
1649      * If the UI delegate's <code>getPreferredSize</code>
1650      * method returns a non <code>null</code> value then return that;
1651      * otherwise defer to the component's layout manager.
1652      *
1653      * @return the value of the <code>preferredSize</code> property
1654      * @see #setPreferredSize
1655      * @see ComponentUI
1656      */
1657     @Transient
1658     public Dimension getPreferredSize() {
1659         if (isPreferredSizeSet()) {
1660             return super.getPreferredSize();
1661         }
1662         Dimension size = null;
1663         if (ui != null) {
1664             size = ui.getPreferredSize(this);
1665         }
1666         return (size != null) ? size : super.getPreferredSize();
1667     }
1668 
1669 
1670     /**
1671      * Sets the maximum size of this component to a constant
1672      * value.  Subsequent calls to <code>getMaximumSize</code> will always
1673      * return this value; the component's UI will not be asked
1674      * to compute it.  Setting the maximum size to <code>null</code>
1675      * restores the default behavior.
1676      *
1677      * @param maximumSize a <code>Dimension</code> containing the
1678      *          desired maximum allowable size
1679      * @see #getMaximumSize
1680      * @beaninfo
1681      *       bound: true
1682      * description: The maximum size of the component.
1683      */


1684     public void setMaximumSize(Dimension maximumSize) {
1685         super.setMaximumSize(maximumSize);
1686     }
1687 
1688 
1689     /**
1690      * If the maximum size has been set to a non-<code>null</code> value
1691      * just returns it.  If the UI delegate's <code>getMaximumSize</code>
1692      * method returns a non-<code>null</code> value then return that;
1693      * otherwise defer to the component's layout manager.
1694      *
1695      * @return the value of the <code>maximumSize</code> property
1696      * @see #setMaximumSize
1697      * @see ComponentUI
1698      */
1699     @Transient
1700     public Dimension getMaximumSize() {
1701         if (isMaximumSizeSet()) {
1702             return super.getMaximumSize();
1703         }
1704         Dimension size = null;
1705         if (ui != null) {
1706             size = ui.getMaximumSize(this);
1707         }
1708         return (size != null) ? size : super.getMaximumSize();
1709     }
1710 
1711 
1712     /**
1713      * Sets the minimum size of this component to a constant
1714      * value.  Subsequent calls to <code>getMinimumSize</code> will always
1715      * return this value; the component's UI will not be asked
1716      * to compute it.  Setting the minimum size to <code>null</code>
1717      * restores the default behavior.
1718      *
1719      * @param minimumSize the new minimum size of this component
1720      * @see #getMinimumSize
1721      * @beaninfo
1722      *       bound: true
1723      * description: The minimum size of the component.
1724      */


1725     public void setMinimumSize(Dimension minimumSize) {
1726         super.setMinimumSize(minimumSize);
1727     }
1728 
1729     /**
1730      * If the minimum size has been set to a non-<code>null</code> value
1731      * just returns it.  If the UI delegate's <code>getMinimumSize</code>
1732      * method returns a non-<code>null</code> value then return that; otherwise
1733      * defer to the component's layout manager.
1734      *
1735      * @return the value of the <code>minimumSize</code> property
1736      * @see #setMinimumSize
1737      * @see ComponentUI
1738      */
1739     @Transient
1740     public Dimension getMinimumSize() {
1741         if (isMinimumSizeSet()) {
1742             return super.getMinimumSize();
1743         }
1744         Dimension size = null;


1768      * bounds of those insets.  Borders should be used (rather
1769      * than insets) for creating both decorative and non-decorative
1770      * (such as margins and padding) regions for a swing component.
1771      * Compound borders can be used to nest multiple borders within a
1772      * single component.
1773      * <p>
1774      * Although technically you can set the border on any object
1775      * that inherits from <code>JComponent</code>, the look and
1776      * feel implementation of many standard Swing components
1777      * doesn't work well with user-set borders.  In general,
1778      * when you want to set a border on a standard Swing
1779      * component other than <code>JPanel</code> or <code>JLabel</code>,
1780      * we recommend that you put the component in a <code>JPanel</code>
1781      * and set the border on the <code>JPanel</code>.
1782      * <p>
1783      * This is a bound property.
1784      *
1785      * @param border the border to be rendered for this component
1786      * @see Border
1787      * @see CompoundBorder
1788      * @beaninfo
1789      *        bound: true
1790      *    preferred: true
1791      *    attribute: visualUpdate true
1792      *  description: The component's border.
1793      */


1794     public void setBorder(Border border) {
1795         Border         oldBorder = this.border;
1796 
1797         this.border = border;
1798         firePropertyChange("border", oldBorder, border);
1799         if (border != oldBorder) {
1800             if (border == null || oldBorder == null ||
1801                 !(border.getBorderInsets(this).equals(oldBorder.getBorderInsets(this)))) {
1802                 revalidate();
1803             }
1804             repaint();
1805         }
1806     }
1807 
1808     /**
1809      * Returns the border of this component or <code>null</code> if no
1810      * border is currently set.
1811      *
1812      * @return the border object for this component
1813      * @see #setBorder
1814      */
1815     public Border getBorder() {
1816         return border;
1817     }
1818 
1819     /**
1820      * If a border has been set on this component, returns the
1821      * border's insets; otherwise calls <code>super.getInsets</code>.
1822      *
1823      * @return the value of the insets property
1824      * @see #setBorder
1825      */

1826     public Insets getInsets() {
1827         if (border != null) {
1828             return border.getBorderInsets(this);
1829         }
1830         return super.getInsets();
1831     }
1832 
1833     /**
1834      * Returns an <code>Insets</code> object containing this component's inset
1835      * values.  The passed-in <code>Insets</code> object will be reused
1836      * if possible.
1837      * Calling methods cannot assume that the same object will be returned,
1838      * however.  All existing values within this object are overwritten.
1839      * If <code>insets</code> is null, this will allocate a new one.
1840      *
1841      * @param insets the <code>Insets</code> object, which can be reused
1842      * @return the <code>Insets</code> object
1843      * @see #getInsets
1844      * @beaninfo
1845      *   expert: true
1846      */
1847     public Insets getInsets(Insets insets) {
1848         if (insets == null) {
1849             insets = new Insets(0, 0, 0, 0);
1850         }
1851         if (border != null) {
1852             if (border instanceof AbstractBorder) {
1853                 return ((AbstractBorder)border).getBorderInsets(this, insets);
1854             } else {
1855                 // Can't reuse border insets because the Border interface
1856                 // can't be enhanced.
1857                 return border.getBorderInsets(this);
1858             }
1859         } else {
1860             // super.getInsets() always returns an Insets object with
1861             // all of its value zeroed.  No need for a new object here.
1862             insets.left = insets.top = insets.right = insets.bottom = 0;
1863             return insets;
1864         }
1865     }


1867     /**
1868      * Overrides <code>Container.getAlignmentY</code> to return
1869      * the horizontal alignment.
1870      *
1871      * @return the value of the <code>alignmentY</code> property
1872      * @see #setAlignmentY
1873      * @see java.awt.Component#getAlignmentY
1874      */
1875     public float getAlignmentY() {
1876         if (isAlignmentYSet) {
1877             return alignmentY;
1878         }
1879         return super.getAlignmentY();
1880     }
1881 
1882     /**
1883      * Sets the the horizontal alignment.
1884      *
1885      * @param alignmentY  the new horizontal alignment
1886      * @see #getAlignmentY
1887      * @beaninfo
1888      *   description: The preferred vertical alignment of the component.
1889      */


1890     public void setAlignmentY(float alignmentY) {
1891         this.alignmentY = validateAlignment(alignmentY);
1892         isAlignmentYSet = true;
1893     }
1894 
1895 
1896     /**
1897      * Overrides <code>Container.getAlignmentX</code> to return
1898      * the vertical alignment.
1899      *
1900      * @return the value of the <code>alignmentX</code> property
1901      * @see #setAlignmentX
1902      * @see java.awt.Component#getAlignmentX
1903      */
1904     public float getAlignmentX() {
1905         if (isAlignmentXSet) {
1906             return alignmentX;
1907         }
1908         return super.getAlignmentX();
1909     }
1910 
1911     /**
1912      * Sets the the vertical alignment.
1913      *
1914      * @param alignmentX  the new vertical alignment
1915      * @see #getAlignmentX
1916      * @beaninfo
1917      *   description: The preferred horizontal alignment of the component.
1918      */


1919     public void setAlignmentX(float alignmentX) {
1920         this.alignmentX = validateAlignment(alignmentX);
1921         isAlignmentXSet = true;
1922     }
1923 
1924     private float validateAlignment(float alignment) {
1925         return alignment > 1.0f ? 1.0f : alignment < 0.0f ? 0.0f : alignment;
1926     }
1927 
1928     /**
1929      * Sets the input verifier for this component.
1930      *
1931      * @param inputVerifier the new input verifier
1932      * @since 1.3
1933      * @see InputVerifier
1934      * @beaninfo
1935      *       bound: true
1936      * description: The component's input verifier.
1937      */


1938     public void setInputVerifier(InputVerifier inputVerifier) {
1939         InputVerifier oldInputVerifier = (InputVerifier)getClientProperty(
1940                                          JComponent_INPUT_VERIFIER);
1941         putClientProperty(JComponent_INPUT_VERIFIER, inputVerifier);
1942         firePropertyChange("inputVerifier", oldInputVerifier, inputVerifier);
1943     }
1944 
1945     /**
1946      * Returns the input verifier for this component.
1947      *
1948      * @return the <code>inputVerifier</code> property
1949      * @since 1.3
1950      * @see InputVerifier
1951      */
1952     public InputVerifier getInputVerifier() {
1953         return (InputVerifier)getClientProperty(JComponent_INPUT_VERIFIER);
1954     }
1955 
1956     /**
1957      * Returns this component's graphics context, which lets you draw
1958      * on a component. Use this method to get a <code>Graphics</code> object and
1959      * then invoke operations on that object to draw on the component.
1960      * @return this components graphics context
1961      */

1962     public Graphics getGraphics() {
1963         if (DEBUG_GRAPHICS_LOADED && shouldDebugGraphics() != 0) {
1964             DebugGraphics graphics = new DebugGraphics(super.getGraphics(),
1965                                                        this);
1966             return graphics;
1967         }
1968         return super.getGraphics();
1969     }
1970 
1971 
1972     /** Enables or disables diagnostic information about every graphics
1973       * operation performed within the component or one of its children.
1974       *
1975       * @param debugOptions  determines how the component should display
1976       *         the information;  one of the following options:
1977       * <ul>
1978       * <li>DebugGraphics.LOG_OPTION - causes a text message to be printed.
1979       * <li>DebugGraphics.FLASH_OPTION - causes the drawing to flash several
1980       * times.
1981       * <li>DebugGraphics.BUFFERED_OPTION - creates an
1982       *         <code>ExternalWindow</code> that displays the operations
1983       *         performed on the View's offscreen buffer.
1984       * <li>DebugGraphics.NONE_OPTION disables debugging.
1985       * <li>A value of 0 causes no changes to the debugging options.
1986       * </ul>
1987       * <code>debugOptions</code> is bitwise OR'd into the current value
1988       *
1989       * @beaninfo
1990       *   preferred: true
1991       *        enum: NONE_OPTION DebugGraphics.NONE_OPTION
1992       *              LOG_OPTION DebugGraphics.LOG_OPTION
1993       *              FLASH_OPTION DebugGraphics.FLASH_OPTION
1994       *              BUFFERED_OPTION DebugGraphics.BUFFERED_OPTION
1995       * description: Diagnostic options for graphics operations.
1996       */






1997     public void setDebugGraphicsOptions(int debugOptions) {
1998         DebugGraphics.setDebugOptions(this, debugOptions);
1999     }
2000 
2001     /** Returns the state of graphics debugging.
2002       *
2003       * @return a bitwise OR'd flag of zero or more of the following options:
2004       * <ul>
2005       * <li>DebugGraphics.LOG_OPTION - causes a text message to be printed.
2006       * <li>DebugGraphics.FLASH_OPTION - causes the drawing to flash several
2007       * times.
2008       * <li>DebugGraphics.BUFFERED_OPTION - creates an
2009       *         <code>ExternalWindow</code> that displays the operations
2010       *         performed on the View's offscreen buffer.
2011       * <li>DebugGraphics.NONE_OPTION disables debugging.
2012       * <li>A value of 0 causes no changes to the debugging options.
2013       * </ul>
2014       * @see #setDebugGraphicsOptions
2015       */
2016     public int getDebugGraphicsOptions() {


2253         for (int counter = 0; counter < 3; counter++) {
2254             InputMap km = getInputMap(counter, false);
2255             if (km != null) {
2256                 Object actionID = km.get(aKeyStroke);
2257 
2258                 if (am != null && actionID != null) {
2259                     am.remove(actionID);
2260                 }
2261                 km.remove(aKeyStroke);
2262             }
2263         }
2264     }
2265 
2266     /**
2267      * Returns the <code>KeyStrokes</code> that will initiate
2268      * registered actions.
2269      *
2270      * @return an array of <code>KeyStroke</code> objects
2271      * @see #registerKeyboardAction
2272      */

2273     public KeyStroke[] getRegisteredKeyStrokes() {
2274         int[] counts = new int[3];
2275         KeyStroke[][] strokes = new KeyStroke[3][];
2276 
2277         for (int counter = 0; counter < 3; counter++) {
2278             InputMap km = getInputMap(counter, false);
2279             strokes[counter] = (km != null) ? km.allKeys() : null;
2280             counts[counter] = (strokes[counter] != null) ?
2281                                strokes[counter].length : 0;
2282         }
2283         KeyStroke[] retValue = new KeyStroke[counts[0] + counts[1] +
2284                                             counts[2]];
2285         for (int counter = 0, last = 0; counter < 3; counter++) {
2286             if (counts[counter] > 0) {
2287                 System.arraycopy(strokes[counter], 0, retValue, last,
2288                                  counts[counter]);
2289                 last += counts[counter];
2290             }
2291         }
2292         return retValue;


2591      * Returns an enum indicating how the baseline of the component
2592      * changes as the size changes.  This method is primarily meant for
2593      * layout managers and GUI builders.
2594      * <p>
2595      * This method calls into the <code>ComponentUI</code> method of
2596      * the same name.  If this component does not have a
2597      * <code>ComponentUI</code>
2598      * <code>BaselineResizeBehavior.OTHER</code> will be
2599      * returned.  Subclasses should
2600      * never return <code>null</code>; if the baseline can not be
2601      * calculated return <code>BaselineResizeBehavior.OTHER</code>.  Callers
2602      * should first ask for the baseline using
2603      * <code>getBaseline</code> and if a value &gt;= 0 is returned use
2604      * this method.  It is acceptable for this method to return a
2605      * value other than <code>BaselineResizeBehavior.OTHER</code> even if
2606      * <code>getBaseline</code> returns a value less than 0.
2607      *
2608      * @see #getBaseline(int, int)
2609      * @since 1.6
2610      */

2611     public BaselineResizeBehavior getBaselineResizeBehavior() {
2612         if (ui != null) {
2613             return ui.getBaselineResizeBehavior(this);
2614         }
2615         return BaselineResizeBehavior.OTHER;
2616     }
2617 
2618     /**
2619      * In release 1.4, the focus subsystem was rearchitected.
2620      * For more information, see
2621      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2622      * How to Use the Focus Subsystem</a>,
2623      * a section in <em>The Java Tutorial</em>.
2624      * <p>
2625      * Requests focus on this <code>JComponent</code>'s
2626      * <code>FocusTraversalPolicy</code>'s default <code>Component</code>.
2627      * If this <code>JComponent</code> is a focus cycle root, then its
2628      * <code>FocusTraversalPolicy</code> is used. Otherwise, the
2629      * <code>FocusTraversalPolicy</code> of this <code>JComponent</code>'s
2630      * focus-cycle-root ancestor is used.


2641             (isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
2642         if (nearestRoot == null) {
2643             return false;
2644         }
2645         Component comp = nearestRoot.getFocusTraversalPolicy().
2646             getDefaultComponent(nearestRoot);
2647         if (comp != null) {
2648             comp.requestFocus();
2649             return true;
2650         } else {
2651             return false;
2652         }
2653     }
2654 
2655     /**
2656      * Makes the component visible or invisible.
2657      * Overrides <code>Component.setVisible</code>.
2658      *
2659      * @param aFlag  true to make the component visible; false to
2660      *          make it invisible
2661      *
2662      * @beaninfo
2663      *    attribute: visualUpdate true
2664      */

2665     public void setVisible(boolean aFlag) {
2666         if (aFlag != isVisible()) {
2667             super.setVisible(aFlag);
2668             if (aFlag) {
2669                 Container parent = getParent();
2670                 if (parent != null) {
2671                     Rectangle r = getBounds();
2672                     parent.repaint(r.x, r.y, r.width, r.height);
2673                 }
2674                 revalidate();
2675             }
2676         }
2677     }
2678 
2679     /**
2680      * Sets whether or not this component is enabled.
2681      * A component that is enabled may respond to user input,
2682      * while a component that is not enabled cannot respond to
2683      * user input.  Some components may alter their visual
2684      * representation when they are disabled in order to
2685      * provide feedback to the user that they cannot take input.
2686      * <p>Note: Disabling a component does not disable its children.
2687      *
2688      * <p>Note: Disabling a lightweight component does not prevent it from
2689      * receiving MouseEvents.
2690      *
2691      * @param enabled true if this component should be enabled, false otherwise
2692      * @see java.awt.Component#isEnabled
2693      * @see java.awt.Component#isLightweight
2694      *
2695      * @beaninfo
2696      *    preferred: true
2697      *        bound: true
2698      *    attribute: visualUpdate true
2699      *  description: The enabled state of the component.
2700      */


2701     public void setEnabled(boolean enabled) {
2702         boolean oldEnabled = isEnabled();
2703         super.setEnabled(enabled);
2704         firePropertyChange("enabled", oldEnabled, enabled);
2705         if (enabled != oldEnabled) {
2706             repaint();
2707         }
2708     }
2709 
2710     /**
2711      * Sets the foreground color of this component.  It is up to the
2712      * look and feel to honor this property, some may choose to ignore
2713      * it.
2714      *
2715      * @param fg  the desired foreground <code>Color</code>
2716      * @see java.awt.Component#getForeground
2717      *
2718      * @beaninfo
2719      *    preferred: true
2720      *        bound: true
2721      *    attribute: visualUpdate true
2722      *  description: The foreground color of the component.
2723      */


2724     public void setForeground(Color fg) {
2725         Color oldFg = getForeground();
2726         super.setForeground(fg);
2727         if ((oldFg != null) ? !oldFg.equals(fg) : ((fg != null) && !fg.equals(oldFg))) {
2728             // foreground already bound in AWT1.2
2729             repaint();
2730         }
2731     }
2732 
2733     /**
2734      * Sets the background color of this component.  The background
2735      * color is used only if the component is opaque, and only
2736      * by subclasses of <code>JComponent</code> or
2737      * <code>ComponentUI</code> implementations.  Direct subclasses of
2738      * <code>JComponent</code> must override
2739      * <code>paintComponent</code> to honor this property.
2740      * <p>
2741      * It is up to the look and feel to honor this property, some may
2742      * choose to ignore it.
2743      *
2744      * @param bg the desired background <code>Color</code>
2745      * @see java.awt.Component#getBackground
2746      * @see #setOpaque
2747      *
2748      * @beaninfo
2749      *    preferred: true
2750      *        bound: true
2751      *    attribute: visualUpdate true
2752      *  description: The background color of the component.
2753      */


2754     public void setBackground(Color bg) {
2755         Color oldBg = getBackground();
2756         super.setBackground(bg);
2757         if ((oldBg != null) ? !oldBg.equals(bg) : ((bg != null) && !bg.equals(oldBg))) {
2758             // background already bound in AWT1.2
2759             repaint();
2760         }
2761     }
2762 
2763     /**
2764      * Sets the font for this component.
2765      *
2766      * @param font the desired <code>Font</code> for this component
2767      * @see java.awt.Component#getFont
2768      *
2769      * @beaninfo
2770      *    preferred: true
2771      *        bound: true
2772      *    attribute: visualUpdate true
2773      *  description: The font for the component.
2774      */


2775     public void setFont(Font font) {
2776         Font oldFont = getFont();
2777         super.setFont(font);
2778         // font already bound in AWT1.2
2779         if (font != oldFont) {
2780             revalidate();
2781             repaint();
2782         }
2783     }
2784 
2785     /**
2786      * Returns the default locale used to initialize each JComponent's
2787      * locale property upon creation.
2788      *
2789      * The default locale has "AppContext" scope so that applets (and
2790      * potentially multiple lightweight applications running in a single VM)
2791      * can have their own setting. An applet can safely alter its default
2792      * locale because it will have no affect on other applets (or the browser).
2793      *
2794      * @return the default <code>Locale</code>.


3003             if (container instanceof Popup.HeavyWeightWindow) {
3004                 container = ((Window)container).getOwner();
3005             }
3006             else {
3007                 return false;
3008             }
3009         }
3010     }
3011 
3012     /**
3013      * Registers the text to display in a tool tip.
3014      * The text displays when the cursor lingers over the component.
3015      * <p>
3016      * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html">How to Use Tool Tips</a>
3017      * in <em>The Java Tutorial</em>
3018      * for further documentation.
3019      *
3020      * @param text  the string to display; if the text is <code>null</code>,
3021      *              the tool tip is turned off for this component
3022      * @see #TOOL_TIP_TEXT_KEY
3023      * @beaninfo
3024      *   preferred: true
3025      * description: The text to display in a tool tip.
3026      */


3027     public void setToolTipText(String text) {
3028         String oldText = getToolTipText();
3029         putClientProperty(TOOL_TIP_TEXT_KEY, text);
3030         ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
3031         if (text != null) {
3032             if (oldText == null) {
3033                 toolTipManager.registerComponent(this);
3034             }
3035         } else {
3036             toolTipManager.unregisterComponent(this);
3037         }
3038     }
3039 
3040     /**
3041      * Returns the tooltip string that has been set with
3042      * <code>setToolTipText</code>.
3043      *
3044      * @return the text of the tool tip
3045      * @see #TOOL_TIP_TEXT_KEY
3046      */


3165      * For example, given a <code>JPanel</code>, <code>myPanel</code>:
3166      * <pre>
3167      * MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() {
3168      *     public void mouseDragged(MouseEvent e) {
3169      *        Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1);
3170      *        ((JPanel)e.getSource()).scrollRectToVisible(r);
3171      *    }
3172      * };
3173      * myPanel.addMouseMotionListener(doScrollRectToVisible);
3174      * </pre>
3175      * The default value of the <code>autoScrolls</code>
3176      * property is <code>false</code>.
3177      *
3178      * @param autoscrolls if true, synthetic mouse dragged events
3179      *   are generated when the mouse is dragged outside of a component's
3180      *   bounds and the mouse button continues to be held down; otherwise
3181      *   false
3182      * @see #getAutoscrolls
3183      * @see JViewport
3184      * @see JScrollPane
3185      *
3186      * @beaninfo
3187      *      expert: true
3188      * description: Determines if this component automatically scrolls its contents when dragged.
3189      */


3190     public void setAutoscrolls(boolean autoscrolls) {
3191         setFlag(AUTOSCROLLS_SET, true);
3192         if (this.autoscrolls != autoscrolls) {
3193             this.autoscrolls = autoscrolls;
3194             if (autoscrolls) {
3195                 enableEvents(AWTEvent.MOUSE_EVENT_MASK);
3196                 enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
3197             }
3198             else {
3199                 Autoscroller.stop(this);
3200             }
3201         }
3202     }
3203 
3204     /**
3205      * Gets the <code>autoscrolls</code> property.
3206      *
3207      * @return the value of the <code>autoscrolls</code> property
3208      * @see JViewport
3209      * @see #setAutoscrolls


3229      * <p>
3230      * If the new {@code TransferHandler} is {@code null}, this method removes
3231      * the drop target.
3232      * <p>
3233      * Under two circumstances, this method does not modify the drop target:
3234      * First, if the existing drop target on this component was explicitly
3235      * set by the developer to a {@code non-null} value. Second, if the
3236      * system property {@code suppressSwingDropSupport} is {@code true}. The
3237      * default value for the system property is {@code false}.
3238      * <p>
3239      * Please see
3240      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/dnd/index.html">
3241      * How to Use Drag and Drop and Data Transfer</a>,
3242      * a section in <em>The Java Tutorial</em>, for more information.
3243      *
3244      * @param newHandler the new {@code TransferHandler}
3245      *
3246      * @see TransferHandler
3247      * @see #getTransferHandler
3248      * @since 1.4
3249      * @beaninfo
3250      *        bound: true
3251      *       hidden: true
3252      *  description: Mechanism for transfer of data to and from the component
3253      */


3254     public void setTransferHandler(TransferHandler newHandler) {
3255         TransferHandler oldHandler = (TransferHandler)getClientProperty(
3256                                       JComponent_TRANSFER_HANDLER);
3257         putClientProperty(JComponent_TRANSFER_HANDLER, newHandler);
3258 
3259         SwingUtilities.installSwingDropTargetAsNecessary(this, newHandler);
3260         firePropertyChange("transferHandler", oldHandler, newHandler);
3261     }
3262 
3263     /**
3264      * Gets the <code>transferHandler</code> property.
3265      *
3266      * @return  the value of the <code>transferHandler</code> property
3267      *
3268      * @see TransferHandler
3269      * @see #setTransferHandler
3270      * @since 1.4
3271      */
3272     public TransferHandler getTransferHandler() {
3273         return (TransferHandler)getClientProperty(JComponent_TRANSFER_HANDLER);


4189      * for a complete description of this method.
4190      * <p>
4191      * This method may throw a {@code ClassCastException} if any {@code Object}
4192      * in {@code keystrokes} is not an {@code AWTKeyStroke}.
4193      *
4194      * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
4195      *        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
4196      *        KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
4197      * @param keystrokes the Set of AWTKeyStroke for the specified operation
4198      * @see java.awt.KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
4199      * @see java.awt.KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
4200      * @see java.awt.KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
4201      * @throws IllegalArgumentException if id is not one of
4202      *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
4203      *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
4204      *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or if keystrokes
4205      *         contains null, or if any keystroke represents a KEY_TYPED event,
4206      *         or if any keystroke already maps to another focus traversal
4207      *         operation for this Component
4208      * @since 1.5
4209      * @beaninfo
4210      *       bound: true
4211      */
4212     public void
4213         setFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes)
4214     {
4215         if (id == KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS) {
4216             setFlag(FOCUS_TRAVERSAL_KEYS_FORWARD_SET,true);
4217         } else if (id == KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS) {
4218             setFlag(FOCUS_TRAVERSAL_KEYS_BACKWARD_SET,true);
4219         }
4220         super.setFocusTraversalKeys(id,keystrokes);
4221     }
4222 
4223     /* --- Transitional java.awt.Component Support ---
4224      * The methods and fields in this section will migrate to
4225      * java.awt.Component in the next JDK release.
4226      */
4227 
4228     /**
4229      * Returns true if this component is lightweight, that is, if it doesn't
4230      * have a native window system peer.


4316     public Point getLocation(Point rv) {
4317         if (rv == null) {
4318             return new Point(getX(), getY());
4319         }
4320         else {
4321             rv.setLocation(getX(), getY());
4322             return rv;
4323         }
4324     }
4325 
4326 
4327     /**
4328      * Returns the current x coordinate of the component's origin.
4329      * This method is preferable to writing
4330      * <code>component.getBounds().x</code>, or
4331      * <code>component.getLocation().x</code> because it doesn't cause any
4332      * heap allocations.
4333      *
4334      * @return the current x coordinate of the component's origin
4335      */

4336     public int getX() { return super.getX(); }
4337 
4338 
4339     /**
4340      * Returns the current y coordinate of the component's origin.
4341      * This method is preferable to writing
4342      * <code>component.getBounds().y</code>, or
4343      * <code>component.getLocation().y</code> because it doesn't cause any
4344      * heap allocations.
4345      *
4346      * @return the current y coordinate of the component's origin
4347      */

4348     public int getY() { return super.getY(); }
4349 
4350 
4351     /**
4352      * Returns the current width of this component.
4353      * This method is preferable to writing
4354      * <code>component.getBounds().width</code>, or
4355      * <code>component.getSize().width</code> because it doesn't cause any
4356      * heap allocations.
4357      *
4358      * @return the current width of this component
4359      */

4360     public int getWidth() { return super.getWidth(); }
4361 
4362 
4363     /**
4364      * Returns the current height of this component.
4365      * This method is preferable to writing
4366      * <code>component.getBounds().height</code>, or
4367      * <code>component.getSize().height</code> because it doesn't cause any
4368      * heap allocations.
4369      *
4370      * @return the current height of this component
4371      */

4372     public int getHeight() { return super.getHeight(); }
4373 
4374     /**
4375      * Returns true if this component is completely opaque.
4376      * <p>
4377      * An opaque component paints every pixel within its
4378      * rectangular bounds. A non-opaque component paints only a subset of
4379      * its pixels or none at all, allowing the pixels underneath it to
4380      * "show through".  Therefore, a component that does not fully paint
4381      * its pixels provides a degree of transparency.
4382      * <p>
4383      * Subclasses that guarantee to always completely paint their contents
4384      * should override this method and return true.
4385      *
4386      * @return true if this component is completely opaque
4387      * @see #setOpaque
4388      */
4389     public boolean isOpaque() {
4390         return getFlag(IS_OPAQUE);
4391     }
4392 
4393     /**
4394      * If true the component paints every pixel within its bounds.
4395      * Otherwise, the component may not paint some or all of its
4396      * pixels, allowing the underlying pixels to show through.
4397      * <p>
4398      * The default value of this property is false for <code>JComponent</code>.
4399      * However, the default value for this property on most standard
4400      * <code>JComponent</code> subclasses (such as <code>JButton</code> and
4401      * <code>JTree</code>) is look-and-feel dependent.
4402      *
4403      * @param isOpaque  true if this component should be opaque
4404      * @see #isOpaque
4405      * @beaninfo
4406      *        bound: true
4407      *       expert: true
4408      *  description: The component's opacity
4409      */


4410     public void setOpaque(boolean isOpaque) {
4411         boolean oldValue = getFlag(IS_OPAQUE);
4412         setFlag(IS_OPAQUE, isOpaque);
4413         setFlag(OPAQUE_SET, true);
4414         firePropertyChange("opaque", oldValue, isOpaque);
4415     }
4416 
4417 
4418     /**
4419      * If the specified rectangle is completely obscured by any of this
4420      * component's opaque children then returns true.  Only direct children
4421      * are considered, more distant descendants are ignored.  A
4422      * <code>JComponent</code> is opaque if
4423      * <code>JComponent.isOpaque()</code> returns true, other lightweight
4424      * components are always considered transparent, and heavyweight components
4425      * are always considered opaque.
4426      *
4427      * @param x  x value of specified rectangle
4428      * @param y  y value of specified rectangle
4429      * @param width  width of specified rectangle


4500      *
4501      * @param visibleRect a <code>Rectangle</code> computed as the
4502      *          intersection of all visible rectangles for this
4503      *          component and all of its ancestors -- this is the return
4504      *          value for this method
4505      * @see #getVisibleRect
4506      */
4507     public void computeVisibleRect(Rectangle visibleRect) {
4508         computeVisibleRect(this, visibleRect);
4509     }
4510 
4511 
4512     /**
4513      * Returns the <code>Component</code>'s "visible rectangle" -  the
4514      * intersection of this component's visible rectangle,
4515      * <code>new Rectangle(0, 0, getWidth(), getHeight())</code>,
4516      * and all of its ancestors' visible rectangles.
4517      *
4518      * @return the visible rectangle
4519      */

4520     public Rectangle getVisibleRect() {
4521         Rectangle visibleRect = new Rectangle();
4522 
4523         computeVisibleRect(visibleRect);
4524         return visibleRect;
4525     }
4526 
4527     /**
4528      * Support for reporting bound property changes for boolean properties.
4529      * This method can be called when a bound property has changed and it will
4530      * send the appropriate PropertyChangeEvent to any registered
4531      * PropertyChangeListeners.
4532      *
4533      * @param propertyName the property whose value has changed
4534      * @param oldValue the property's previous value
4535      * @param newValue the property's new value
4536      */
4537     public void firePropertyChange(String propertyName,
4538                                    boolean oldValue, boolean newValue) {
4539         super.firePropertyChange(propertyName, oldValue, newValue);


4608         if (vetoableChangeSupport == null) {
4609             return;
4610         }
4611         vetoableChangeSupport.removeVetoableChangeListener(listener);
4612     }
4613 
4614 
4615     /**
4616      * Returns an array of all the vetoable change listeners
4617      * registered on this component.
4618      *
4619      * @return all of the component's <code>VetoableChangeListener</code>s
4620      *         or an empty
4621      *         array if no vetoable change listeners are currently registered
4622      *
4623      * @see #addVetoableChangeListener
4624      * @see #removeVetoableChangeListener
4625      *
4626      * @since 1.4
4627      */

4628     public synchronized VetoableChangeListener[] getVetoableChangeListeners() {
4629         if (vetoableChangeSupport == null) {
4630             return new VetoableChangeListener[0];
4631         }
4632         return vetoableChangeSupport.getVetoableChangeListeners();
4633     }
4634 
4635 
4636     /**
4637      * Returns the top-level ancestor of this component (either the
4638      * containing <code>Window</code> or <code>Applet</code>),
4639      * or <code>null</code> if this component has not
4640      * been added to any container.
4641      *
4642      * @return the top-level <code>Container</code> that this component is in,
4643      *          or <code>null</code> if not in any container
4644      */

4645     public Container getTopLevelAncestor() {
4646         for(Container p = this; p != null; p = p.getParent()) {
4647             if(p instanceof Window || p instanceof Applet) {
4648                 return p;
4649             }
4650         }
4651         return null;
4652     }
4653 
4654     private AncestorNotifier getAncestorNotifier() {
4655         return (AncestorNotifier)
4656             getClientProperty(JComponent_ANCESTOR_NOTIFIER);
4657     }
4658 
4659     /**
4660      * Registers <code>listener</code> so that it will receive
4661      * <code>AncestorEvents</code> when it or any of its ancestors
4662      * move or are made visible or invisible.
4663      * Events are also sent when the component or its ancestors are added
4664      * or removed from the containment hierarchy.


4691         ancestorNotifier.removeAncestorListener(listener);
4692         if (ancestorNotifier.listenerList.getListenerList().length == 0) {
4693             ancestorNotifier.removeAllListeners();
4694             putClientProperty(JComponent_ANCESTOR_NOTIFIER, null);
4695         }
4696     }
4697 
4698     /**
4699      * Returns an array of all the ancestor listeners
4700      * registered on this component.
4701      *
4702      * @return all of the component's <code>AncestorListener</code>s
4703      *         or an empty
4704      *         array if no ancestor listeners are currently registered
4705      *
4706      * @see #addAncestorListener
4707      * @see #removeAncestorListener
4708      *
4709      * @since 1.4
4710      */

4711     public AncestorListener[] getAncestorListeners() {
4712         AncestorNotifier ancestorNotifier = getAncestorNotifier();
4713         if (ancestorNotifier == null) {
4714             return new AncestorListener[0];
4715         }
4716         return ancestorNotifier.getAncestorListeners();
4717     }
4718 
4719     /**
4720      * Returns an array of all the objects currently registered
4721      * as <code><em>Foo</em>Listener</code>s
4722      * upon this <code>JComponent</code>.
4723      * <code><em>Foo</em>Listener</code>s are registered using the
4724      * <code>add<em>Foo</em>Listener</code> method.
4725      *
4726      * <p>
4727      *
4728      * You can specify the <code>listenerType</code> argument
4729      * with a class literal,
4730      * such as


4928      * @see java.awt.Component#invalidate
4929      * @see java.awt.Container#validate
4930      * @see java.awt.Container#isValidateRoot
4931      */
4932     @Override
4933     public boolean isValidateRoot() {
4934         return false;
4935     }
4936 
4937 
4938     /**
4939      * Returns true if this component tiles its children -- that is, if
4940      * it can guarantee that the children will not overlap.  The
4941      * repainting system is substantially more efficient in this
4942      * common case.  <code>JComponent</code> subclasses that can't make this
4943      * guarantee, such as <code>JLayeredPane</code>,
4944      * should override this method to return false.
4945      *
4946      * @return always returns true
4947      */

4948     public boolean isOptimizedDrawingEnabled() {
4949         return true;
4950     }
4951 
4952     /**
4953      * Returns {@code true} if a paint triggered on a child component should cause
4954      * painting to originate from this Component, or one of its ancestors.
4955      * <p>
4956      * Calling {@link #repaint} or {@link #paintImmediately(int, int, int, int)}
4957      * on a Swing component will result in calling
4958      * the {@link JComponent#paintImmediately(int, int, int, int)} method of
4959      * the first ancestor which {@code isPaintingOrigin()} returns {@code true}, if there are any.
4960      * <p>
4961      * {@code JComponent} subclasses that need to be painted when any of their
4962      * children are repainted should override this method to return {@code true}.
4963      *
4964      * @return always returns {@code false}
4965      *
4966      * @see #paintImmediately(int, int, int, int)
4967      */


5377      */
5378     public void setDoubleBuffered(boolean aFlag) {
5379         setFlag(IS_DOUBLE_BUFFERED,aFlag);
5380     }
5381 
5382     /**
5383      * Returns whether this component should use a buffer to paint.
5384      *
5385      * @return true if this component is double buffered, otherwise false
5386      */
5387     public boolean isDoubleBuffered() {
5388         return getFlag(IS_DOUBLE_BUFFERED);
5389     }
5390 
5391     /**
5392      * Returns the <code>JRootPane</code> ancestor for this component.
5393      *
5394      * @return the <code>JRootPane</code> that contains this component,
5395      *          or <code>null</code> if no <code>JRootPane</code> is found
5396      */

5397     public JRootPane getRootPane() {
5398         return SwingUtilities.getRootPane(this);
5399     }
5400 
5401 
5402     /** Serialization **/
5403 
5404     /**
5405      * This is called from Component by way of reflection. Do NOT change
5406      * the name unless you change the code in Component as well.
5407      */
5408     void compWriteObjectNotify() {
5409         byte count = JComponent.getWriteObjCounter(this);
5410         JComponent.setWriteObjCounter(this, (byte)(count + 1));
5411         if (count != 0) {
5412             return;
5413         }
5414 
5415         uninstallUIAndProperties();
5416 




   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 package javax.swing;
  26 

  27 import java.util.HashSet;
  28 import java.util.Hashtable;

  29 import java.util.Enumeration;
  30 import java.util.Locale;
  31 import java.util.Vector;
  32 import java.util.EventListener;
  33 import java.util.Set;


  34 
  35 import java.awt.*;
  36 import java.awt.event.*;


  37 import java.awt.peer.LightweightPeer;
  38 import java.beans.JavaBean;
  39 import java.beans.BeanProperty;
  40 import java.beans.PropertyChangeListener;
  41 import java.beans.VetoableChangeListener;
  42 import java.beans.VetoableChangeSupport;
  43 import java.beans.Transient;
  44 
  45 import java.applet.Applet;
  46 
  47 import java.io.Serializable;
  48 import java.io.ObjectOutputStream;
  49 import java.io.ObjectInputStream;
  50 import java.io.IOException;
  51 import java.io.ObjectInputValidation;
  52 import java.io.InvalidObjectException;
  53 
  54 import javax.swing.border.*;
  55 import javax.swing.event.*;
  56 import javax.swing.plaf.*;
  57 import static javax.swing.ClientPropertyKey.*;
  58 import javax.accessibility.*;
  59 


 158  * future Swing releases. The current serialization support is
 159  * appropriate for short term storage or RMI between applications running
 160  * the same version of Swing.  As of 1.4, support for long term storage
 161  * of all JavaBeans&trade;
 162  * has been added to the <code>java.beans</code> package.
 163  * Please see {@link java.beans.XMLEncoder}.
 164  *
 165  * @see KeyStroke
 166  * @see Action
 167  * @see #setBorder
 168  * @see #registerKeyboardAction
 169  * @see JOptionPane
 170  * @see #setDebugGraphicsOptions
 171  * @see #setToolTipText
 172  * @see #setAutoscrolls
 173  *
 174  * @author Hans Muller
 175  * @author Arnaud Weber
 176  * @since 1.2
 177  */
 178 @JavaBean(defaultProperty = "UIClassID")
 179 @SuppressWarnings("serial") // Same-version serialization only
 180 public abstract class JComponent extends Container implements Serializable,
 181                                               TransferHandler.HasGetTransferHandler
 182 {
 183     /**
 184      * @see #getUIClassID
 185      * @see #writeObject
 186      */
 187     private static final String uiClassID = "ComponentUI";
 188 
 189     /**
 190      * @see #readObject
 191      */
 192     private static final Hashtable<ObjectInputStream, ReadObjectCallback> readObjectCallbacks =
 193             new Hashtable<ObjectInputStream, ReadObjectCallback>(1);
 194 
 195     /**
 196      * Keys to use for forward focus traversal when the JComponent is
 197      * managing focus.
 198      */


 460 
 461     private static void recycleRectangle(Rectangle rect) {
 462         synchronized(tempRectangles) {
 463             tempRectangles.add(rect);
 464         }
 465     }
 466 
 467     /**
 468      * Sets whether or not <code>getComponentPopupMenu</code> should delegate
 469      * to the parent if this component does not have a <code>JPopupMenu</code>
 470      * assigned to it.
 471      * <p>
 472      * The default value for this is false, but some <code>JComponent</code>
 473      * subclasses that are implemented as a number of <code>JComponent</code>s
 474      * may set this to true.
 475      * <p>
 476      * This is a bound property.
 477      *
 478      * @param value whether or not the JPopupMenu is inherited
 479      * @see #setComponentPopupMenu



 480      * @since 1.5
 481      */
 482     @BeanProperty(description
 483             = "Whether or not the JPopupMenu is inherited")
 484     public void setInheritsPopupMenu(boolean value) {
 485         boolean oldValue = getFlag(INHERITS_POPUP_MENU);
 486         setFlag(INHERITS_POPUP_MENU, value);
 487         firePropertyChange("inheritsPopupMenu", oldValue, value);
 488     }
 489 
 490     /**
 491      * Returns true if the JPopupMenu should be inherited from the parent.
 492      *
 493      * @return true if the JPopupMenu should be inherited from the parent
 494      * @see #setComponentPopupMenu
 495      * @since 1.5
 496      */
 497     public boolean getInheritsPopupMenu() {
 498         return getFlag(INHERITS_POPUP_MENU);
 499     }
 500 
 501     /**
 502      * Sets the <code>JPopupMenu</code> for this <code>JComponent</code>.
 503      * The UI is responsible for registering bindings and adding the necessary
 504      * listeners such that the <code>JPopupMenu</code> will be shown at
 505      * the appropriate time. When the <code>JPopupMenu</code> is shown
 506      * depends upon the look and feel: some may show it on a mouse event,
 507      * some may enable a key binding.
 508      * <p>
 509      * If <code>popup</code> is null, and <code>getInheritsPopupMenu</code>
 510      * returns true, then <code>getComponentPopupMenu</code> will be delegated
 511      * to the parent. This provides for a way to make all child components
 512      * inherit the popupmenu of the parent.
 513      * <p>
 514      * This is a bound property.
 515      *
 516      * @param popup - the popup that will be assigned to this component
 517      *                may be null
 518      * @see #getComponentPopupMenu




 519      * @since 1.5
 520      */
 521     @BeanProperty(preferred = true, description
 522             = "Popup to show")
 523     public void setComponentPopupMenu(JPopupMenu popup) {
 524         if(popup != null) {
 525             enableEvents(AWTEvent.MOUSE_EVENT_MASK);
 526         }
 527         JPopupMenu oldPopup = this.popupMenu;
 528         this.popupMenu = popup;
 529         firePropertyChange("componentPopupMenu", oldPopup, popup);
 530     }
 531 
 532     /**
 533      * Returns <code>JPopupMenu</code> that assigned for this component.
 534      * If this component does not have a <code>JPopupMenu</code> assigned
 535      * to it and <code>getInheritsPopupMenu</code> is true, this
 536      * will return <code>getParent().getComponentPopupMenu()</code> (assuming
 537      * the parent is valid.)
 538      *
 539      * @return <code>JPopupMenu</code> assigned for this component
 540      *         or <code>null</code> if no popup assigned
 541      * @see #setComponentPopupMenu
 542      * @since 1.5


 618      * <code>JComponent</code> subclasses generally override this method
 619      * to narrow the argument type. For example, in <code>JSlider</code>:
 620      * <pre>
 621      * public void setUI(SliderUI newUI) {
 622      *     super.setUI(newUI);
 623      * }
 624      *  </pre>
 625      * <p>
 626      * Additionally <code>JComponent</code> subclasses must provide a
 627      * <code>getUI</code> method that returns the correct type.  For example:
 628      * <pre>
 629      * public SliderUI getUI() {
 630      *     return (SliderUI)ui;
 631      * }
 632      * </pre>
 633      *
 634      * @param newUI the new UI delegate
 635      * @see #updateUI
 636      * @see UIManager#getLookAndFeel
 637      * @see UIManager#getUI





 638      */
 639     @BeanProperty(hidden = true, visualUpdate = true, description
 640             = "The component's look and feel delegate.")
 641     protected void setUI(ComponentUI newUI) {
 642         /* We do not check that the UI instance is different
 643          * before allowing the switch in order to enable the
 644          * same UI instance *with different default settings*
 645          * to be installed.
 646          */
 647 
 648         uninstallUIAndProperties();
 649 
 650         // aaText shouldn't persist between look and feels, reset it.
 651         aaTextInfo =
 652             UIManager.getDefaults().get(SwingUtilities2.AA_TEXT_PROPERTY_KEY);
 653         ComponentUI oldUI = ui;
 654         ui = newUI;
 655         if (ui != null) {
 656             ui.installUI(this);
 657         }
 658 
 659         firePropertyChange("UI", oldUI, newUI);
 660         revalidate();


 682                         }
 683                     }
 684                 }
 685             }
 686         }
 687     }
 688 
 689     /**
 690      * Returns the <code>UIDefaults</code> key used to
 691      * look up the name of the <code>swing.plaf.ComponentUI</code>
 692      * class that defines the look and feel
 693      * for this component.  Most applications will never need to
 694      * call this method.  Subclasses of <code>JComponent</code> that support
 695      * pluggable look and feel should override this method to
 696      * return a <code>UIDefaults</code> key that maps to the
 697      * <code>ComponentUI</code> subclass that defines their look and feel.
 698      *
 699      * @return the <code>UIDefaults</code> key for a
 700      *          <code>ComponentUI</code> subclass
 701      * @see UIDefaults#getUI



 702      */
 703     @BeanProperty(bound = false, expert = true, description
 704             = "UIClassID")
 705     public String getUIClassID() {
 706         return uiClassID;
 707     }
 708 
 709 
 710     /**
 711      * Returns the graphics object used to paint this component.
 712      * If <code>DebugGraphics</code> is turned on we create a new
 713      * <code>DebugGraphics</code> object if necessary.
 714      * Otherwise we just configure the
 715      * specified graphics object's foreground and font.
 716      *
 717      * @param g the original <code>Graphics</code> object
 718      * @return a <code>Graphics</code> object configured for this component
 719      */
 720     protected Graphics getComponentGraphics(Graphics g) {
 721         Graphics componentGraphics = g;
 722         if (ui != null && DEBUG_GRAPHICS_LOADED) {
 723             if ((DebugGraphics.debugComponentCount() != 0) &&
 724                     (shouldDebugGraphics() != 0) &&


1228      * wish to print the border differently that it is painted.
1229      *
1230      * @param g the <code>Graphics</code> context in which to paint
1231      * @see #print
1232      * @since 1.3
1233      */
1234     protected void printBorder(Graphics g) {
1235         paintBorder(g);
1236     }
1237 
1238     /**
1239      *  Returns true if the component is currently painting a tile.
1240      *  If this method returns true, paint will be called again for another
1241      *  tile. This method returns false if you are not painting a tile or
1242      *  if the last tile is painted.
1243      *  Use this method to keep some state you might need between tiles.
1244      *
1245      *  @return  true if the component is currently painting a tile,
1246      *          false otherwise
1247      */
1248     @BeanProperty(bound = false)
1249     public boolean isPaintingTile() {
1250         return getFlag(IS_PAINTING_TILE);
1251     }
1252 
1253     /**
1254      * Returns <code>true</code> if the current painting operation on this
1255      * component is part of a <code>print</code> operation. This method is
1256      * useful when you want to customize what you print versus what you show
1257      * on the screen.
1258      * <p>
1259      * You can detect changes in the value of this property by listening for
1260      * property change events on this component with name
1261      * <code>"paintingForPrint"</code>.
1262      * <p>
1263      * Note: This method provides complimentary functionality to that provided
1264      * by other high level Swing printing APIs. However, it deals strictly with
1265      * painting and should not be confused as providing information on higher
1266      * level print processes. For example, a {@link javax.swing.JTable#print()}
1267      * operation doesn't necessarily result in a continuous rendering of the
1268      * full component, and the return value of this method can change multiple
1269      * times during that operation. It is even possible for the component to be
1270      * painted to the screen while the printing process is ongoing. In such a
1271      * case, the return value of this method is <code>true</code> when, and only
1272      * when, the table is being painted as part of the printing process.
1273      *
1274      * @return true if the current painting operation on this component
1275      *         is part of a print operation
1276      * @see #print
1277      * @since 1.6
1278      */
1279     @BeanProperty(bound = false)
1280     public final boolean isPaintingForPrint() {
1281         return getFlag(IS_PRINTING);
1282     }
1283 
1284     /**
1285      * In release 1.4, the focus subsystem was rearchitected.
1286      * For more information, see
1287      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
1288      * How to Use the Focus Subsystem</a>,
1289      * a section in <em>The Java Tutorial</em>.
1290      * <p>
1291      * Changes this <code>JComponent</code>'s focus traversal keys to
1292      * CTRL+TAB and CTRL+SHIFT+TAB. Also prevents
1293      * <code>SortingFocusTraversalPolicy</code> from considering descendants
1294      * of this JComponent when computing a focus traversal cycle.
1295      *
1296      * @return false
1297      * @see java.awt.Component#setFocusTraversalKeys
1298      * @see SortingFocusTraversalPolicy
1299      * @deprecated As of 1.4, replaced by
1300      *   <code>Component.setFocusTraversalKeys(int, Set)</code> and
1301      *   <code>Container.setFocusCycleRoot(boolean)</code>.
1302      */
1303     @Deprecated
1304     @BeanProperty(bound = false)
1305     public boolean isManagingFocus() {
1306         return false;
1307     }
1308 
1309     private void registerNextFocusableComponent() {
1310         registerNextFocusableComponent(getNextFocusableComponent());
1311     }
1312 
1313     private void registerNextFocusableComponent(Component
1314                                                 nextFocusableComponent) {
1315         if (nextFocusableComponent == null) {
1316             return;
1317         }
1318 
1319         Container nearestRoot =
1320             (isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
1321         FocusTraversalPolicy policy = nearestRoot.getFocusTraversalPolicy();
1322         if (!(policy instanceof LegacyGlueFocusTraversalPolicy)) {
1323             policy = new LegacyGlueFocusTraversalPolicy(policy);
1324             nearestRoot.setFocusTraversalPolicy(policy);


1555     public void grabFocus() {
1556         requestFocus();
1557     }
1558 
1559     /**
1560      * Sets the value to indicate whether input verifier for the
1561      * current focus owner will be called before this component requests
1562      * focus. The default is true. Set to false on components such as a
1563      * Cancel button or a scrollbar, which should activate even if the
1564      * input in the current focus owner is not "passed" by the input
1565      * verifier for that component.
1566      *
1567      * @param verifyInputWhenFocusTarget value for the
1568      *        <code>verifyInputWhenFocusTarget</code> property
1569      * @see InputVerifier
1570      * @see #setInputVerifier
1571      * @see #getInputVerifier
1572      * @see #getVerifyInputWhenFocusTarget
1573      *
1574      * @since 1.3




1575      */
1576     @BeanProperty(description
1577             = "Whether the Component verifies input before accepting focus.")
1578     public void setVerifyInputWhenFocusTarget(boolean
1579                                               verifyInputWhenFocusTarget) {
1580         boolean oldVerifyInputWhenFocusTarget =
1581             this.verifyInputWhenFocusTarget;
1582         this.verifyInputWhenFocusTarget = verifyInputWhenFocusTarget;
1583         firePropertyChange("verifyInputWhenFocusTarget",
1584                            oldVerifyInputWhenFocusTarget,
1585                            verifyInputWhenFocusTarget);
1586     }
1587 
1588     /**
1589      * Returns the value that indicates whether the input verifier for the
1590      * current focus owner will be called before this component requests
1591      * focus.
1592      *
1593      * @return value of the <code>verifyInputWhenFocusTarget</code> property
1594      *
1595      * @see InputVerifier
1596      * @see #setInputVerifier
1597      * @see #getInputVerifier


1605 
1606 
1607     /**
1608      * Gets the <code>FontMetrics</code> for the specified <code>Font</code>.
1609      *
1610      * @param font the font for which font metrics is to be
1611      *          obtained
1612      * @return the font metrics for <code>font</code>
1613      * @throws NullPointerException if <code>font</code> is null
1614      * @since 1.5
1615      */
1616     public FontMetrics getFontMetrics(Font font) {
1617         return SwingUtilities2.getFontMetrics(this, font);
1618     }
1619 
1620 
1621     /**
1622      * Sets the preferred size of this component.
1623      * If <code>preferredSize</code> is <code>null</code>, the UI will
1624      * be asked for the preferred size.




1625      */
1626     @BeanProperty(preferred = true, description
1627             = "The preferred size of the component.")
1628     public void setPreferredSize(Dimension preferredSize) {
1629         super.setPreferredSize(preferredSize);
1630     }
1631 
1632 
1633     /**
1634      * If the <code>preferredSize</code> has been set to a
1635      * non-<code>null</code> value just returns it.
1636      * If the UI delegate's <code>getPreferredSize</code>
1637      * method returns a non <code>null</code> value then return that;
1638      * otherwise defer to the component's layout manager.
1639      *
1640      * @return the value of the <code>preferredSize</code> property
1641      * @see #setPreferredSize
1642      * @see ComponentUI
1643      */
1644     @Transient
1645     public Dimension getPreferredSize() {
1646         if (isPreferredSizeSet()) {
1647             return super.getPreferredSize();
1648         }
1649         Dimension size = null;
1650         if (ui != null) {
1651             size = ui.getPreferredSize(this);
1652         }
1653         return (size != null) ? size : super.getPreferredSize();
1654     }
1655 
1656 
1657     /**
1658      * Sets the maximum size of this component to a constant
1659      * value.  Subsequent calls to <code>getMaximumSize</code> will always
1660      * return this value; the component's UI will not be asked
1661      * to compute it.  Setting the maximum size to <code>null</code>
1662      * restores the default behavior.
1663      *
1664      * @param maximumSize a <code>Dimension</code> containing the
1665      *          desired maximum allowable size
1666      * @see #getMaximumSize



1667      */
1668     @BeanProperty(description
1669             = "The maximum size of the component.")
1670     public void setMaximumSize(Dimension maximumSize) {
1671         super.setMaximumSize(maximumSize);
1672     }
1673 
1674 
1675     /**
1676      * If the maximum size has been set to a non-<code>null</code> value
1677      * just returns it.  If the UI delegate's <code>getMaximumSize</code>
1678      * method returns a non-<code>null</code> value then return that;
1679      * otherwise defer to the component's layout manager.
1680      *
1681      * @return the value of the <code>maximumSize</code> property
1682      * @see #setMaximumSize
1683      * @see ComponentUI
1684      */
1685     @Transient
1686     public Dimension getMaximumSize() {
1687         if (isMaximumSizeSet()) {
1688             return super.getMaximumSize();
1689         }
1690         Dimension size = null;
1691         if (ui != null) {
1692             size = ui.getMaximumSize(this);
1693         }
1694         return (size != null) ? size : super.getMaximumSize();
1695     }
1696 
1697 
1698     /**
1699      * Sets the minimum size of this component to a constant
1700      * value.  Subsequent calls to <code>getMinimumSize</code> will always
1701      * return this value; the component's UI will not be asked
1702      * to compute it.  Setting the minimum size to <code>null</code>
1703      * restores the default behavior.
1704      *
1705      * @param minimumSize the new minimum size of this component
1706      * @see #getMinimumSize



1707      */
1708     @BeanProperty(description
1709             = "The minimum size of the component.")
1710     public void setMinimumSize(Dimension minimumSize) {
1711         super.setMinimumSize(minimumSize);
1712     }
1713 
1714     /**
1715      * If the minimum size has been set to a non-<code>null</code> value
1716      * just returns it.  If the UI delegate's <code>getMinimumSize</code>
1717      * method returns a non-<code>null</code> value then return that; otherwise
1718      * defer to the component's layout manager.
1719      *
1720      * @return the value of the <code>minimumSize</code> property
1721      * @see #setMinimumSize
1722      * @see ComponentUI
1723      */
1724     @Transient
1725     public Dimension getMinimumSize() {
1726         if (isMinimumSizeSet()) {
1727             return super.getMinimumSize();
1728         }
1729         Dimension size = null;


1753      * bounds of those insets.  Borders should be used (rather
1754      * than insets) for creating both decorative and non-decorative
1755      * (such as margins and padding) regions for a swing component.
1756      * Compound borders can be used to nest multiple borders within a
1757      * single component.
1758      * <p>
1759      * Although technically you can set the border on any object
1760      * that inherits from <code>JComponent</code>, the look and
1761      * feel implementation of many standard Swing components
1762      * doesn't work well with user-set borders.  In general,
1763      * when you want to set a border on a standard Swing
1764      * component other than <code>JPanel</code> or <code>JLabel</code>,
1765      * we recommend that you put the component in a <code>JPanel</code>
1766      * and set the border on the <code>JPanel</code>.
1767      * <p>
1768      * This is a bound property.
1769      *
1770      * @param border the border to be rendered for this component
1771      * @see Border
1772      * @see CompoundBorder





1773      */
1774     @BeanProperty(preferred = true, visualUpdate = true, description
1775             = "The component's border.")
1776     public void setBorder(Border border) {
1777         Border         oldBorder = this.border;
1778 
1779         this.border = border;
1780         firePropertyChange("border", oldBorder, border);
1781         if (border != oldBorder) {
1782             if (border == null || oldBorder == null ||
1783                 !(border.getBorderInsets(this).equals(oldBorder.getBorderInsets(this)))) {
1784                 revalidate();
1785             }
1786             repaint();
1787         }
1788     }
1789 
1790     /**
1791      * Returns the border of this component or <code>null</code> if no
1792      * border is currently set.
1793      *
1794      * @return the border object for this component
1795      * @see #setBorder
1796      */
1797     public Border getBorder() {
1798         return border;
1799     }
1800 
1801     /**
1802      * If a border has been set on this component, returns the
1803      * border's insets; otherwise calls <code>super.getInsets</code>.
1804      *
1805      * @return the value of the insets property
1806      * @see #setBorder
1807      */
1808     @BeanProperty(expert = true)
1809     public Insets getInsets() {
1810         if (border != null) {
1811             return border.getBorderInsets(this);
1812         }
1813         return super.getInsets();
1814     }
1815 
1816     /**
1817      * Returns an <code>Insets</code> object containing this component's inset
1818      * values.  The passed-in <code>Insets</code> object will be reused
1819      * if possible.
1820      * Calling methods cannot assume that the same object will be returned,
1821      * however.  All existing values within this object are overwritten.
1822      * If <code>insets</code> is null, this will allocate a new one.
1823      *
1824      * @param insets the <code>Insets</code> object, which can be reused
1825      * @return the <code>Insets</code> object
1826      * @see #getInsets


1827      */
1828     public Insets getInsets(Insets insets) {
1829         if (insets == null) {
1830             insets = new Insets(0, 0, 0, 0);
1831         }
1832         if (border != null) {
1833             if (border instanceof AbstractBorder) {
1834                 return ((AbstractBorder)border).getBorderInsets(this, insets);
1835             } else {
1836                 // Can't reuse border insets because the Border interface
1837                 // can't be enhanced.
1838                 return border.getBorderInsets(this);
1839             }
1840         } else {
1841             // super.getInsets() always returns an Insets object with
1842             // all of its value zeroed.  No need for a new object here.
1843             insets.left = insets.top = insets.right = insets.bottom = 0;
1844             return insets;
1845         }
1846     }


1848     /**
1849      * Overrides <code>Container.getAlignmentY</code> to return
1850      * the horizontal alignment.
1851      *
1852      * @return the value of the <code>alignmentY</code> property
1853      * @see #setAlignmentY
1854      * @see java.awt.Component#getAlignmentY
1855      */
1856     public float getAlignmentY() {
1857         if (isAlignmentYSet) {
1858             return alignmentY;
1859         }
1860         return super.getAlignmentY();
1861     }
1862 
1863     /**
1864      * Sets the the horizontal alignment.
1865      *
1866      * @param alignmentY  the new horizontal alignment
1867      * @see #getAlignmentY


1868      */
1869     @BeanProperty(description
1870             = "The preferred vertical alignment of the component.")
1871     public void setAlignmentY(float alignmentY) {
1872         this.alignmentY = validateAlignment(alignmentY);
1873         isAlignmentYSet = true;
1874     }
1875 
1876 
1877     /**
1878      * Overrides <code>Container.getAlignmentX</code> to return
1879      * the vertical alignment.
1880      *
1881      * @return the value of the <code>alignmentX</code> property
1882      * @see #setAlignmentX
1883      * @see java.awt.Component#getAlignmentX
1884      */
1885     public float getAlignmentX() {
1886         if (isAlignmentXSet) {
1887             return alignmentX;
1888         }
1889         return super.getAlignmentX();
1890     }
1891 
1892     /**
1893      * Sets the the vertical alignment.
1894      *
1895      * @param alignmentX  the new vertical alignment
1896      * @see #getAlignmentX


1897      */
1898     @BeanProperty(description
1899             = "The preferred horizontal alignment of the component.")
1900     public void setAlignmentX(float alignmentX) {
1901         this.alignmentX = validateAlignment(alignmentX);
1902         isAlignmentXSet = true;
1903     }
1904 
1905     private float validateAlignment(float alignment) {
1906         return alignment > 1.0f ? 1.0f : alignment < 0.0f ? 0.0f : alignment;
1907     }
1908 
1909     /**
1910      * Sets the input verifier for this component.
1911      *
1912      * @param inputVerifier the new input verifier
1913      * @since 1.3
1914      * @see InputVerifier



1915      */
1916     @BeanProperty(description
1917             = "The component's input verifier.")
1918     public void setInputVerifier(InputVerifier inputVerifier) {
1919         InputVerifier oldInputVerifier = (InputVerifier)getClientProperty(
1920                                          JComponent_INPUT_VERIFIER);
1921         putClientProperty(JComponent_INPUT_VERIFIER, inputVerifier);
1922         firePropertyChange("inputVerifier", oldInputVerifier, inputVerifier);
1923     }
1924 
1925     /**
1926      * Returns the input verifier for this component.
1927      *
1928      * @return the <code>inputVerifier</code> property
1929      * @since 1.3
1930      * @see InputVerifier
1931      */
1932     public InputVerifier getInputVerifier() {
1933         return (InputVerifier)getClientProperty(JComponent_INPUT_VERIFIER);
1934     }
1935 
1936     /**
1937      * Returns this component's graphics context, which lets you draw
1938      * on a component. Use this method to get a <code>Graphics</code> object and
1939      * then invoke operations on that object to draw on the component.
1940      * @return this components graphics context
1941      */
1942     @BeanProperty(bound = false)
1943     public Graphics getGraphics() {
1944         if (DEBUG_GRAPHICS_LOADED && shouldDebugGraphics() != 0) {
1945             DebugGraphics graphics = new DebugGraphics(super.getGraphics(),
1946                                                        this);
1947             return graphics;
1948         }
1949         return super.getGraphics();
1950     }
1951 
1952 
1953     /** Enables or disables diagnostic information about every graphics
1954       * operation performed within the component or one of its children.
1955       *
1956       * @param debugOptions  determines how the component should display
1957       *         the information;  one of the following options:
1958       * <ul>
1959       * <li>DebugGraphics.LOG_OPTION - causes a text message to be printed.
1960       * <li>DebugGraphics.FLASH_OPTION - causes the drawing to flash several
1961       * times.
1962       * <li>DebugGraphics.BUFFERED_OPTION - creates an
1963       *         <code>ExternalWindow</code> that displays the operations
1964       *         performed on the View's offscreen buffer.
1965       * <li>DebugGraphics.NONE_OPTION disables debugging.
1966       * <li>A value of 0 causes no changes to the debugging options.
1967       * </ul>
1968       * <code>debugOptions</code> is bitwise OR'd into the current value








1969       */
1970     @BeanProperty(bound = false, preferred = true, enumerationValues = {
1971             "DebugGraphics.NONE_OPTION",
1972             "DebugGraphics.LOG_OPTION",
1973             "DebugGraphics.FLASH_OPTION",
1974             "DebugGraphics.BUFFERED_OPTION"}, description
1975             = "Diagnostic options for graphics operations.")
1976     public void setDebugGraphicsOptions(int debugOptions) {
1977         DebugGraphics.setDebugOptions(this, debugOptions);
1978     }
1979 
1980     /** Returns the state of graphics debugging.
1981       *
1982       * @return a bitwise OR'd flag of zero or more of the following options:
1983       * <ul>
1984       * <li>DebugGraphics.LOG_OPTION - causes a text message to be printed.
1985       * <li>DebugGraphics.FLASH_OPTION - causes the drawing to flash several
1986       * times.
1987       * <li>DebugGraphics.BUFFERED_OPTION - creates an
1988       *         <code>ExternalWindow</code> that displays the operations
1989       *         performed on the View's offscreen buffer.
1990       * <li>DebugGraphics.NONE_OPTION disables debugging.
1991       * <li>A value of 0 causes no changes to the debugging options.
1992       * </ul>
1993       * @see #setDebugGraphicsOptions
1994       */
1995     public int getDebugGraphicsOptions() {


2232         for (int counter = 0; counter < 3; counter++) {
2233             InputMap km = getInputMap(counter, false);
2234             if (km != null) {
2235                 Object actionID = km.get(aKeyStroke);
2236 
2237                 if (am != null && actionID != null) {
2238                     am.remove(actionID);
2239                 }
2240                 km.remove(aKeyStroke);
2241             }
2242         }
2243     }
2244 
2245     /**
2246      * Returns the <code>KeyStrokes</code> that will initiate
2247      * registered actions.
2248      *
2249      * @return an array of <code>KeyStroke</code> objects
2250      * @see #registerKeyboardAction
2251      */
2252     @BeanProperty(bound = false)
2253     public KeyStroke[] getRegisteredKeyStrokes() {
2254         int[] counts = new int[3];
2255         KeyStroke[][] strokes = new KeyStroke[3][];
2256 
2257         for (int counter = 0; counter < 3; counter++) {
2258             InputMap km = getInputMap(counter, false);
2259             strokes[counter] = (km != null) ? km.allKeys() : null;
2260             counts[counter] = (strokes[counter] != null) ?
2261                                strokes[counter].length : 0;
2262         }
2263         KeyStroke[] retValue = new KeyStroke[counts[0] + counts[1] +
2264                                             counts[2]];
2265         for (int counter = 0, last = 0; counter < 3; counter++) {
2266             if (counts[counter] > 0) {
2267                 System.arraycopy(strokes[counter], 0, retValue, last,
2268                                  counts[counter]);
2269                 last += counts[counter];
2270             }
2271         }
2272         return retValue;


2571      * Returns an enum indicating how the baseline of the component
2572      * changes as the size changes.  This method is primarily meant for
2573      * layout managers and GUI builders.
2574      * <p>
2575      * This method calls into the <code>ComponentUI</code> method of
2576      * the same name.  If this component does not have a
2577      * <code>ComponentUI</code>
2578      * <code>BaselineResizeBehavior.OTHER</code> will be
2579      * returned.  Subclasses should
2580      * never return <code>null</code>; if the baseline can not be
2581      * calculated return <code>BaselineResizeBehavior.OTHER</code>.  Callers
2582      * should first ask for the baseline using
2583      * <code>getBaseline</code> and if a value &gt;= 0 is returned use
2584      * this method.  It is acceptable for this method to return a
2585      * value other than <code>BaselineResizeBehavior.OTHER</code> even if
2586      * <code>getBaseline</code> returns a value less than 0.
2587      *
2588      * @see #getBaseline(int, int)
2589      * @since 1.6
2590      */
2591     @BeanProperty(bound = false)
2592     public BaselineResizeBehavior getBaselineResizeBehavior() {
2593         if (ui != null) {
2594             return ui.getBaselineResizeBehavior(this);
2595         }
2596         return BaselineResizeBehavior.OTHER;
2597     }
2598 
2599     /**
2600      * In release 1.4, the focus subsystem was rearchitected.
2601      * For more information, see
2602      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2603      * How to Use the Focus Subsystem</a>,
2604      * a section in <em>The Java Tutorial</em>.
2605      * <p>
2606      * Requests focus on this <code>JComponent</code>'s
2607      * <code>FocusTraversalPolicy</code>'s default <code>Component</code>.
2608      * If this <code>JComponent</code> is a focus cycle root, then its
2609      * <code>FocusTraversalPolicy</code> is used. Otherwise, the
2610      * <code>FocusTraversalPolicy</code> of this <code>JComponent</code>'s
2611      * focus-cycle-root ancestor is used.


2622             (isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
2623         if (nearestRoot == null) {
2624             return false;
2625         }
2626         Component comp = nearestRoot.getFocusTraversalPolicy().
2627             getDefaultComponent(nearestRoot);
2628         if (comp != null) {
2629             comp.requestFocus();
2630             return true;
2631         } else {
2632             return false;
2633         }
2634     }
2635 
2636     /**
2637      * Makes the component visible or invisible.
2638      * Overrides <code>Component.setVisible</code>.
2639      *
2640      * @param aFlag  true to make the component visible; false to
2641      *          make it invisible



2642      */
2643     @BeanProperty(hidden = true, visualUpdate = true)
2644     public void setVisible(boolean aFlag) {
2645         if (aFlag != isVisible()) {
2646             super.setVisible(aFlag);
2647             if (aFlag) {
2648                 Container parent = getParent();
2649                 if (parent != null) {
2650                     Rectangle r = getBounds();
2651                     parent.repaint(r.x, r.y, r.width, r.height);
2652                 }
2653                 revalidate();
2654             }
2655         }
2656     }
2657 
2658     /**
2659      * Sets whether or not this component is enabled.
2660      * A component that is enabled may respond to user input,
2661      * while a component that is not enabled cannot respond to
2662      * user input.  Some components may alter their visual
2663      * representation when they are disabled in order to
2664      * provide feedback to the user that they cannot take input.
2665      * <p>Note: Disabling a component does not disable its children.
2666      *
2667      * <p>Note: Disabling a lightweight component does not prevent it from
2668      * receiving MouseEvents.
2669      *
2670      * @param enabled true if this component should be enabled, false otherwise
2671      * @see java.awt.Component#isEnabled
2672      * @see java.awt.Component#isLightweight






2673      */
2674     @BeanProperty(expert = true, preferred = true, visualUpdate = true, description
2675             = "The enabled state of the component.")
2676     public void setEnabled(boolean enabled) {
2677         boolean oldEnabled = isEnabled();
2678         super.setEnabled(enabled);
2679         firePropertyChange("enabled", oldEnabled, enabled);
2680         if (enabled != oldEnabled) {
2681             repaint();
2682         }
2683     }
2684 
2685     /**
2686      * Sets the foreground color of this component.  It is up to the
2687      * look and feel to honor this property, some may choose to ignore
2688      * it.
2689      *
2690      * @param fg  the desired foreground <code>Color</code>
2691      * @see java.awt.Component#getForeground






2692      */
2693     @BeanProperty(preferred = true, visualUpdate = true, description
2694             = "The foreground color of the component.")
2695     public void setForeground(Color fg) {
2696         Color oldFg = getForeground();
2697         super.setForeground(fg);
2698         if ((oldFg != null) ? !oldFg.equals(fg) : ((fg != null) && !fg.equals(oldFg))) {
2699             // foreground already bound in AWT1.2
2700             repaint();
2701         }
2702     }
2703 
2704     /**
2705      * Sets the background color of this component.  The background
2706      * color is used only if the component is opaque, and only
2707      * by subclasses of <code>JComponent</code> or
2708      * <code>ComponentUI</code> implementations.  Direct subclasses of
2709      * <code>JComponent</code> must override
2710      * <code>paintComponent</code> to honor this property.
2711      * <p>
2712      * It is up to the look and feel to honor this property, some may
2713      * choose to ignore it.
2714      *
2715      * @param bg the desired background <code>Color</code>
2716      * @see java.awt.Component#getBackground
2717      * @see #setOpaque






2718      */
2719     @BeanProperty(preferred = true, visualUpdate = true, description
2720             = "The background color of the component.")
2721     public void setBackground(Color bg) {
2722         Color oldBg = getBackground();
2723         super.setBackground(bg);
2724         if ((oldBg != null) ? !oldBg.equals(bg) : ((bg != null) && !bg.equals(oldBg))) {
2725             // background already bound in AWT1.2
2726             repaint();
2727         }
2728     }
2729 
2730     /**
2731      * Sets the font for this component.
2732      *
2733      * @param font the desired <code>Font</code> for this component
2734      * @see java.awt.Component#getFont






2735      */
2736     @BeanProperty(preferred = true, visualUpdate = true, description
2737             = "The font for the component.")
2738     public void setFont(Font font) {
2739         Font oldFont = getFont();
2740         super.setFont(font);
2741         // font already bound in AWT1.2
2742         if (font != oldFont) {
2743             revalidate();
2744             repaint();
2745         }
2746     }
2747 
2748     /**
2749      * Returns the default locale used to initialize each JComponent's
2750      * locale property upon creation.
2751      *
2752      * The default locale has "AppContext" scope so that applets (and
2753      * potentially multiple lightweight applications running in a single VM)
2754      * can have their own setting. An applet can safely alter its default
2755      * locale because it will have no affect on other applets (or the browser).
2756      *
2757      * @return the default <code>Locale</code>.


2966             if (container instanceof Popup.HeavyWeightWindow) {
2967                 container = ((Window)container).getOwner();
2968             }
2969             else {
2970                 return false;
2971             }
2972         }
2973     }
2974 
2975     /**
2976      * Registers the text to display in a tool tip.
2977      * The text displays when the cursor lingers over the component.
2978      * <p>
2979      * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html">How to Use Tool Tips</a>
2980      * in <em>The Java Tutorial</em>
2981      * for further documentation.
2982      *
2983      * @param text  the string to display; if the text is <code>null</code>,
2984      *              the tool tip is turned off for this component
2985      * @see #TOOL_TIP_TEXT_KEY



2986      */
2987     @BeanProperty(bound = false, preferred = true, description
2988             = "The text to display in a tool tip.")
2989     public void setToolTipText(String text) {
2990         String oldText = getToolTipText();
2991         putClientProperty(TOOL_TIP_TEXT_KEY, text);
2992         ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
2993         if (text != null) {
2994             if (oldText == null) {
2995                 toolTipManager.registerComponent(this);
2996             }
2997         } else {
2998             toolTipManager.unregisterComponent(this);
2999         }
3000     }
3001 
3002     /**
3003      * Returns the tooltip string that has been set with
3004      * <code>setToolTipText</code>.
3005      *
3006      * @return the text of the tool tip
3007      * @see #TOOL_TIP_TEXT_KEY
3008      */


3127      * For example, given a <code>JPanel</code>, <code>myPanel</code>:
3128      * <pre>
3129      * MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() {
3130      *     public void mouseDragged(MouseEvent e) {
3131      *        Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1);
3132      *        ((JPanel)e.getSource()).scrollRectToVisible(r);
3133      *    }
3134      * };
3135      * myPanel.addMouseMotionListener(doScrollRectToVisible);
3136      * </pre>
3137      * The default value of the <code>autoScrolls</code>
3138      * property is <code>false</code>.
3139      *
3140      * @param autoscrolls if true, synthetic mouse dragged events
3141      *   are generated when the mouse is dragged outside of a component's
3142      *   bounds and the mouse button continues to be held down; otherwise
3143      *   false
3144      * @see #getAutoscrolls
3145      * @see JViewport
3146      * @see JScrollPane




3147      */
3148     @BeanProperty(bound = false, expert = true, description
3149             = "Determines if this component automatically scrolls its contents when dragged.")
3150     public void setAutoscrolls(boolean autoscrolls) {
3151         setFlag(AUTOSCROLLS_SET, true);
3152         if (this.autoscrolls != autoscrolls) {
3153             this.autoscrolls = autoscrolls;
3154             if (autoscrolls) {
3155                 enableEvents(AWTEvent.MOUSE_EVENT_MASK);
3156                 enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
3157             }
3158             else {
3159                 Autoscroller.stop(this);
3160             }
3161         }
3162     }
3163 
3164     /**
3165      * Gets the <code>autoscrolls</code> property.
3166      *
3167      * @return the value of the <code>autoscrolls</code> property
3168      * @see JViewport
3169      * @see #setAutoscrolls


3189      * <p>
3190      * If the new {@code TransferHandler} is {@code null}, this method removes
3191      * the drop target.
3192      * <p>
3193      * Under two circumstances, this method does not modify the drop target:
3194      * First, if the existing drop target on this component was explicitly
3195      * set by the developer to a {@code non-null} value. Second, if the
3196      * system property {@code suppressSwingDropSupport} is {@code true}. The
3197      * default value for the system property is {@code false}.
3198      * <p>
3199      * Please see
3200      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/dnd/index.html">
3201      * How to Use Drag and Drop and Data Transfer</a>,
3202      * a section in <em>The Java Tutorial</em>, for more information.
3203      *
3204      * @param newHandler the new {@code TransferHandler}
3205      *
3206      * @see TransferHandler
3207      * @see #getTransferHandler
3208      * @since 1.4




3209      */
3210     @BeanProperty(hidden = true, description
3211             = "Mechanism for transfer of data to and from the component")
3212     public void setTransferHandler(TransferHandler newHandler) {
3213         TransferHandler oldHandler = (TransferHandler)getClientProperty(
3214                                       JComponent_TRANSFER_HANDLER);
3215         putClientProperty(JComponent_TRANSFER_HANDLER, newHandler);
3216 
3217         SwingUtilities.installSwingDropTargetAsNecessary(this, newHandler);
3218         firePropertyChange("transferHandler", oldHandler, newHandler);
3219     }
3220 
3221     /**
3222      * Gets the <code>transferHandler</code> property.
3223      *
3224      * @return  the value of the <code>transferHandler</code> property
3225      *
3226      * @see TransferHandler
3227      * @see #setTransferHandler
3228      * @since 1.4
3229      */
3230     public TransferHandler getTransferHandler() {
3231         return (TransferHandler)getClientProperty(JComponent_TRANSFER_HANDLER);


4147      * for a complete description of this method.
4148      * <p>
4149      * This method may throw a {@code ClassCastException} if any {@code Object}
4150      * in {@code keystrokes} is not an {@code AWTKeyStroke}.
4151      *
4152      * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
4153      *        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
4154      *        KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
4155      * @param keystrokes the Set of AWTKeyStroke for the specified operation
4156      * @see java.awt.KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
4157      * @see java.awt.KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
4158      * @see java.awt.KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
4159      * @throws IllegalArgumentException if id is not one of
4160      *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
4161      *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
4162      *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or if keystrokes
4163      *         contains null, or if any keystroke represents a KEY_TYPED event,
4164      *         or if any keystroke already maps to another focus traversal
4165      *         operation for this Component
4166      * @since 1.5


4167      */
4168     public void
4169         setFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes)
4170     {
4171         if (id == KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS) {
4172             setFlag(FOCUS_TRAVERSAL_KEYS_FORWARD_SET,true);
4173         } else if (id == KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS) {
4174             setFlag(FOCUS_TRAVERSAL_KEYS_BACKWARD_SET,true);
4175         }
4176         super.setFocusTraversalKeys(id,keystrokes);
4177     }
4178 
4179     /* --- Transitional java.awt.Component Support ---
4180      * The methods and fields in this section will migrate to
4181      * java.awt.Component in the next JDK release.
4182      */
4183 
4184     /**
4185      * Returns true if this component is lightweight, that is, if it doesn't
4186      * have a native window system peer.


4272     public Point getLocation(Point rv) {
4273         if (rv == null) {
4274             return new Point(getX(), getY());
4275         }
4276         else {
4277             rv.setLocation(getX(), getY());
4278             return rv;
4279         }
4280     }
4281 
4282 
4283     /**
4284      * Returns the current x coordinate of the component's origin.
4285      * This method is preferable to writing
4286      * <code>component.getBounds().x</code>, or
4287      * <code>component.getLocation().x</code> because it doesn't cause any
4288      * heap allocations.
4289      *
4290      * @return the current x coordinate of the component's origin
4291      */
4292     @BeanProperty(bound = false)
4293     public int getX() { return super.getX(); }
4294 
4295 
4296     /**
4297      * Returns the current y coordinate of the component's origin.
4298      * This method is preferable to writing
4299      * <code>component.getBounds().y</code>, or
4300      * <code>component.getLocation().y</code> because it doesn't cause any
4301      * heap allocations.
4302      *
4303      * @return the current y coordinate of the component's origin
4304      */
4305     @BeanProperty(bound = false)
4306     public int getY() { return super.getY(); }
4307 
4308 
4309     /**
4310      * Returns the current width of this component.
4311      * This method is preferable to writing
4312      * <code>component.getBounds().width</code>, or
4313      * <code>component.getSize().width</code> because it doesn't cause any
4314      * heap allocations.
4315      *
4316      * @return the current width of this component
4317      */
4318     @BeanProperty(bound = false)
4319     public int getWidth() { return super.getWidth(); }
4320 
4321 
4322     /**
4323      * Returns the current height of this component.
4324      * This method is preferable to writing
4325      * <code>component.getBounds().height</code>, or
4326      * <code>component.getSize().height</code> because it doesn't cause any
4327      * heap allocations.
4328      *
4329      * @return the current height of this component
4330      */
4331     @BeanProperty(bound = false)
4332     public int getHeight() { return super.getHeight(); }
4333 
4334     /**
4335      * Returns true if this component is completely opaque.
4336      * <p>
4337      * An opaque component paints every pixel within its
4338      * rectangular bounds. A non-opaque component paints only a subset of
4339      * its pixels or none at all, allowing the pixels underneath it to
4340      * "show through".  Therefore, a component that does not fully paint
4341      * its pixels provides a degree of transparency.
4342      * <p>
4343      * Subclasses that guarantee to always completely paint their contents
4344      * should override this method and return true.
4345      *
4346      * @return true if this component is completely opaque
4347      * @see #setOpaque
4348      */
4349     public boolean isOpaque() {
4350         return getFlag(IS_OPAQUE);
4351     }
4352 
4353     /**
4354      * If true the component paints every pixel within its bounds.
4355      * Otherwise, the component may not paint some or all of its
4356      * pixels, allowing the underlying pixels to show through.
4357      * <p>
4358      * The default value of this property is false for <code>JComponent</code>.
4359      * However, the default value for this property on most standard
4360      * <code>JComponent</code> subclasses (such as <code>JButton</code> and
4361      * <code>JTree</code>) is look-and-feel dependent.
4362      *
4363      * @param isOpaque  true if this component should be opaque
4364      * @see #isOpaque




4365      */
4366     @BeanProperty(expert = true, description
4367             = "The component's opacity")
4368     public void setOpaque(boolean isOpaque) {
4369         boolean oldValue = getFlag(IS_OPAQUE);
4370         setFlag(IS_OPAQUE, isOpaque);
4371         setFlag(OPAQUE_SET, true);
4372         firePropertyChange("opaque", oldValue, isOpaque);
4373     }
4374 
4375 
4376     /**
4377      * If the specified rectangle is completely obscured by any of this
4378      * component's opaque children then returns true.  Only direct children
4379      * are considered, more distant descendants are ignored.  A
4380      * <code>JComponent</code> is opaque if
4381      * <code>JComponent.isOpaque()</code> returns true, other lightweight
4382      * components are always considered transparent, and heavyweight components
4383      * are always considered opaque.
4384      *
4385      * @param x  x value of specified rectangle
4386      * @param y  y value of specified rectangle
4387      * @param width  width of specified rectangle


4458      *
4459      * @param visibleRect a <code>Rectangle</code> computed as the
4460      *          intersection of all visible rectangles for this
4461      *          component and all of its ancestors -- this is the return
4462      *          value for this method
4463      * @see #getVisibleRect
4464      */
4465     public void computeVisibleRect(Rectangle visibleRect) {
4466         computeVisibleRect(this, visibleRect);
4467     }
4468 
4469 
4470     /**
4471      * Returns the <code>Component</code>'s "visible rectangle" -  the
4472      * intersection of this component's visible rectangle,
4473      * <code>new Rectangle(0, 0, getWidth(), getHeight())</code>,
4474      * and all of its ancestors' visible rectangles.
4475      *
4476      * @return the visible rectangle
4477      */
4478     @BeanProperty(bound = false)
4479     public Rectangle getVisibleRect() {
4480         Rectangle visibleRect = new Rectangle();
4481 
4482         computeVisibleRect(visibleRect);
4483         return visibleRect;
4484     }
4485 
4486     /**
4487      * Support for reporting bound property changes for boolean properties.
4488      * This method can be called when a bound property has changed and it will
4489      * send the appropriate PropertyChangeEvent to any registered
4490      * PropertyChangeListeners.
4491      *
4492      * @param propertyName the property whose value has changed
4493      * @param oldValue the property's previous value
4494      * @param newValue the property's new value
4495      */
4496     public void firePropertyChange(String propertyName,
4497                                    boolean oldValue, boolean newValue) {
4498         super.firePropertyChange(propertyName, oldValue, newValue);


4567         if (vetoableChangeSupport == null) {
4568             return;
4569         }
4570         vetoableChangeSupport.removeVetoableChangeListener(listener);
4571     }
4572 
4573 
4574     /**
4575      * Returns an array of all the vetoable change listeners
4576      * registered on this component.
4577      *
4578      * @return all of the component's <code>VetoableChangeListener</code>s
4579      *         or an empty
4580      *         array if no vetoable change listeners are currently registered
4581      *
4582      * @see #addVetoableChangeListener
4583      * @see #removeVetoableChangeListener
4584      *
4585      * @since 1.4
4586      */
4587     @BeanProperty(bound = false)
4588     public synchronized VetoableChangeListener[] getVetoableChangeListeners() {
4589         if (vetoableChangeSupport == null) {
4590             return new VetoableChangeListener[0];
4591         }
4592         return vetoableChangeSupport.getVetoableChangeListeners();
4593     }
4594 
4595 
4596     /**
4597      * Returns the top-level ancestor of this component (either the
4598      * containing <code>Window</code> or <code>Applet</code>),
4599      * or <code>null</code> if this component has not
4600      * been added to any container.
4601      *
4602      * @return the top-level <code>Container</code> that this component is in,
4603      *          or <code>null</code> if not in any container
4604      */
4605     @BeanProperty(bound = false)
4606     public Container getTopLevelAncestor() {
4607         for(Container p = this; p != null; p = p.getParent()) {
4608             if(p instanceof Window || p instanceof Applet) {
4609                 return p;
4610             }
4611         }
4612         return null;
4613     }
4614 
4615     private AncestorNotifier getAncestorNotifier() {
4616         return (AncestorNotifier)
4617             getClientProperty(JComponent_ANCESTOR_NOTIFIER);
4618     }
4619 
4620     /**
4621      * Registers <code>listener</code> so that it will receive
4622      * <code>AncestorEvents</code> when it or any of its ancestors
4623      * move or are made visible or invisible.
4624      * Events are also sent when the component or its ancestors are added
4625      * or removed from the containment hierarchy.


4652         ancestorNotifier.removeAncestorListener(listener);
4653         if (ancestorNotifier.listenerList.getListenerList().length == 0) {
4654             ancestorNotifier.removeAllListeners();
4655             putClientProperty(JComponent_ANCESTOR_NOTIFIER, null);
4656         }
4657     }
4658 
4659     /**
4660      * Returns an array of all the ancestor listeners
4661      * registered on this component.
4662      *
4663      * @return all of the component's <code>AncestorListener</code>s
4664      *         or an empty
4665      *         array if no ancestor listeners are currently registered
4666      *
4667      * @see #addAncestorListener
4668      * @see #removeAncestorListener
4669      *
4670      * @since 1.4
4671      */
4672     @BeanProperty(bound = false)
4673     public AncestorListener[] getAncestorListeners() {
4674         AncestorNotifier ancestorNotifier = getAncestorNotifier();
4675         if (ancestorNotifier == null) {
4676             return new AncestorListener[0];
4677         }
4678         return ancestorNotifier.getAncestorListeners();
4679     }
4680 
4681     /**
4682      * Returns an array of all the objects currently registered
4683      * as <code><em>Foo</em>Listener</code>s
4684      * upon this <code>JComponent</code>.
4685      * <code><em>Foo</em>Listener</code>s are registered using the
4686      * <code>add<em>Foo</em>Listener</code> method.
4687      *
4688      * <p>
4689      *
4690      * You can specify the <code>listenerType</code> argument
4691      * with a class literal,
4692      * such as


4890      * @see java.awt.Component#invalidate
4891      * @see java.awt.Container#validate
4892      * @see java.awt.Container#isValidateRoot
4893      */
4894     @Override
4895     public boolean isValidateRoot() {
4896         return false;
4897     }
4898 
4899 
4900     /**
4901      * Returns true if this component tiles its children -- that is, if
4902      * it can guarantee that the children will not overlap.  The
4903      * repainting system is substantially more efficient in this
4904      * common case.  <code>JComponent</code> subclasses that can't make this
4905      * guarantee, such as <code>JLayeredPane</code>,
4906      * should override this method to return false.
4907      *
4908      * @return always returns true
4909      */
4910     @BeanProperty(bound = false)
4911     public boolean isOptimizedDrawingEnabled() {
4912         return true;
4913     }
4914 
4915     /**
4916      * Returns {@code true} if a paint triggered on a child component should cause
4917      * painting to originate from this Component, or one of its ancestors.
4918      * <p>
4919      * Calling {@link #repaint} or {@link #paintImmediately(int, int, int, int)}
4920      * on a Swing component will result in calling
4921      * the {@link JComponent#paintImmediately(int, int, int, int)} method of
4922      * the first ancestor which {@code isPaintingOrigin()} returns {@code true}, if there are any.
4923      * <p>
4924      * {@code JComponent} subclasses that need to be painted when any of their
4925      * children are repainted should override this method to return {@code true}.
4926      *
4927      * @return always returns {@code false}
4928      *
4929      * @see #paintImmediately(int, int, int, int)
4930      */


5340      */
5341     public void setDoubleBuffered(boolean aFlag) {
5342         setFlag(IS_DOUBLE_BUFFERED,aFlag);
5343     }
5344 
5345     /**
5346      * Returns whether this component should use a buffer to paint.
5347      *
5348      * @return true if this component is double buffered, otherwise false
5349      */
5350     public boolean isDoubleBuffered() {
5351         return getFlag(IS_DOUBLE_BUFFERED);
5352     }
5353 
5354     /**
5355      * Returns the <code>JRootPane</code> ancestor for this component.
5356      *
5357      * @return the <code>JRootPane</code> that contains this component,
5358      *          or <code>null</code> if no <code>JRootPane</code> is found
5359      */
5360     @BeanProperty(bound = false)
5361     public JRootPane getRootPane() {
5362         return SwingUtilities.getRootPane(this);
5363     }
5364 
5365 
5366     /** Serialization **/
5367 
5368     /**
5369      * This is called from Component by way of reflection. Do NOT change
5370      * the name unless you change the code in Component as well.
5371      */
5372     void compWriteObjectNotify() {
5373         byte count = JComponent.getWriteObjCounter(this);
5374         JComponent.setWriteObjCounter(this, (byte)(count + 1));
5375         if (count != 0) {
5376             return;
5377         }
5378 
5379         uninstallUIAndProperties();
5380