1058
1059 // NOTE: This method may be called by privileged threads.
1060 // This functionality is implemented in a package-private method
1061 // to insure that it cannot be overridden by client subclasses.
1062 // DO NOT INVOKE CLIENT CODE ON THIS THREAD!
1063 final Container getParent_NoClientCode() {
1064 return parent;
1065 }
1066
1067 // This method is overridden in the Window class to return null,
1068 // because the parent field of the Window object contains
1069 // the owner of the window, not its parent.
1070 Container getContainer() {
1071 return getParent_NoClientCode();
1072 }
1073
1074 /**
1075 * @deprecated As of JDK version 1.1,
1076 * programs should not directly manipulate peers;
1077 * replaced by <code>boolean isDisplayable()</code>.
1078 */
1079 @Deprecated
1080 public ComponentPeer getPeer() {
1081 return peer;
1082 }
1083
1084 /**
1085 * Associate a <code>DropTarget</code> with this component.
1086 * The <code>Component</code> will receive drops only if it
1087 * is enabled.
1088 *
1089 * @see #isEnabled
1090 * @param dt The DropTarget
1091 */
1092
1093 public synchronized void setDropTarget(DropTarget dt) {
1094 if (dt == dropTarget || (dropTarget != null && dropTarget.equals(dt)))
1095 return;
1096
1097 DropTarget old;
1115 if ((dropTarget = dt) != null) {
1116 try {
1117 dropTarget.setComponent(this);
1118 if (peer != null) dropTarget.addNotify(peer);
1119 } catch (IllegalArgumentException iae) {
1120 if (old != null) {
1121 try {
1122 old.setComponent(this);
1123 if (peer != null) dropTarget.addNotify(peer);
1124 } catch (IllegalArgumentException iae1) {
1125 // ignore it!
1126 }
1127 }
1128 }
1129 }
1130 }
1131
1132 /**
1133 * Gets the <code>DropTarget</code> associated with this
1134 * <code>Component</code>.
1135 */
1136
1137 public synchronized DropTarget getDropTarget() { return dropTarget; }
1138
1139 /**
1140 * Gets the <code>GraphicsConfiguration</code> associated with this
1141 * <code>Component</code>.
1142 * If the <code>Component</code> has not been assigned a specific
1143 * <code>GraphicsConfiguration</code>,
1144 * the <code>GraphicsConfiguration</code> of the
1145 * <code>Component</code> object's top-level container is
1146 * returned.
1147 * If the <code>Component</code> has been created, but not yet added
1148 * to a <code>Container</code>, this method returns <code>null</code>.
1149 *
1150 * @return the <code>GraphicsConfiguration</code> used by this
1151 * <code>Component</code> or <code>null</code>
1152 * @since 1.3
1153 */
1154 public GraphicsConfiguration getGraphicsConfiguration() {
1481 if (!enabled) {
1482 synchronized (getTreeLock()) {
1483 enabled = true;
1484 ComponentPeer peer = this.peer;
1485 if (peer != null) {
1486 peer.setEnabled(true);
1487 if (visible) {
1488 updateCursorImmediately();
1489 }
1490 }
1491 }
1492 if (accessibleContext != null) {
1493 accessibleContext.firePropertyChange(
1494 AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
1495 null, AccessibleState.ENABLED);
1496 }
1497 }
1498 }
1499
1500 /**
1501 * @deprecated As of JDK version 1.1,
1502 * replaced by <code>setEnabled(boolean)</code>.
1503 */
1504 @Deprecated
1505 public void enable(boolean b) {
1506 if (b) {
1507 enable();
1508 } else {
1509 disable();
1510 }
1511 }
1512
1513 /**
1514 * @deprecated As of JDK version 1.1,
1515 * replaced by <code>setEnabled(boolean)</code>.
1516 */
1517 @Deprecated
1518 public void disable() {
1519 if (enabled) {
1520 KeyboardFocusManager.clearMostRecentFocusOwner(this);
1639 }
1640 updateCursorImmediately();
1641 }
1642
1643 if (componentListener != null ||
1644 (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
1645 Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) {
1646 ComponentEvent e = new ComponentEvent(this,
1647 ComponentEvent.COMPONENT_SHOWN);
1648 Toolkit.getEventQueue().postEvent(e);
1649 }
1650 }
1651 Container parent = this.parent;
1652 if (parent != null) {
1653 parent.invalidate();
1654 }
1655 }
1656 }
1657
1658 /**
1659 * @deprecated As of JDK version 1.1,
1660 * replaced by <code>setVisible(boolean)</code>.
1661 */
1662 @Deprecated
1663 public void show(boolean b) {
1664 if (b) {
1665 show();
1666 } else {
1667 hide();
1668 }
1669 }
1670
1671 boolean containsFocus() {
1672 return isFocusOwner();
1673 }
1674
1675 void clearMostRecentFocusOwnerOnHide() {
1676 KeyboardFocusManager.clearMostRecentFocusOwner(this);
1677 }
1678
2051 // lightweight component location needs to be translated
2052 // relative to a native component.
2053 Container host = getNativeContainer();
2054 Point pt = host.peer.getLocationOnScreen();
2055 for(Component c = this; c != host; c = c.getParent()) {
2056 pt.x += c.x;
2057 pt.y += c.y;
2058 }
2059 return pt;
2060 } else {
2061 Point pt = peer.getLocationOnScreen();
2062 return pt;
2063 }
2064 } else {
2065 throw new IllegalComponentStateException("component must be showing on the screen to determine its location");
2066 }
2067 }
2068
2069
2070 /**
2071 * @deprecated As of JDK version 1.1,
2072 * replaced by <code>getLocation()</code>.
2073 */
2074 @Deprecated
2075 public Point location() {
2076 return location_NoClientCode();
2077 }
2078
2079 private Point location_NoClientCode() {
2080 return new Point(x, y);
2081 }
2082
2083 /**
2084 * Moves this component to a new location. The top-left corner of
2085 * the new location is specified by the <code>x</code> and <code>y</code>
2086 * parameters in the coordinate space of this component's parent.
2087 * <p>
2088 * This method changes layout-related information, and therefore,
2089 * invalidates the component hierarchy.
2090 *
2091 * @param x the <i>x</i>-coordinate of the new location's
2092 * top-left corner in the parent's coordinate space
2093 * @param y the <i>y</i>-coordinate of the new location's
2094 * top-left corner in the parent's coordinate space
2095 * @see #getLocation
2096 * @see #setBounds
2097 * @see #invalidate
2098 * @since JDK1.1
2099 */
2100 public void setLocation(int x, int y) {
2101 move(x, y);
2102 }
2103
2104 /**
2105 * @deprecated As of JDK version 1.1,
2106 * replaced by <code>setLocation(int, int)</code>.
2107 */
2108 @Deprecated
2109 public void move(int x, int y) {
2110 synchronized(getTreeLock()) {
2111 setBoundsOp(ComponentPeer.SET_LOCATION);
2112 setBounds(x, y, width, height);
2113 }
2114 }
2115
2116 /**
2117 * Moves this component to a new location. The top-left corner of
2118 * the new location is specified by point <code>p</code>. Point
2119 * <code>p</code> is given in the parent's coordinate space.
2120 * <p>
2121 * This method changes layout-related information, and therefore,
2122 * invalidates the component hierarchy.
2123 *
2124 * @param p the point defining the top-left corner
2133 setLocation(p.x, p.y);
2134 }
2135
2136 /**
2137 * Returns the size of this component in the form of a
2138 * <code>Dimension</code> object. The <code>height</code>
2139 * field of the <code>Dimension</code> object contains
2140 * this component's height, and the <code>width</code>
2141 * field of the <code>Dimension</code> object contains
2142 * this component's width.
2143 * @return a <code>Dimension</code> object that indicates the
2144 * size of this component
2145 * @see #setSize
2146 * @since JDK1.1
2147 */
2148 public Dimension getSize() {
2149 return size();
2150 }
2151
2152 /**
2153 * @deprecated As of JDK version 1.1,
2154 * replaced by <code>getSize()</code>.
2155 */
2156 @Deprecated
2157 public Dimension size() {
2158 return new Dimension(width, height);
2159 }
2160
2161 /**
2162 * Resizes this component so that it has width <code>width</code>
2163 * and height <code>height</code>.
2164 * <p>
2165 * This method changes layout-related information, and therefore,
2166 * invalidates the component hierarchy.
2167 *
2168 * @param width the new width of this component in pixels
2169 * @param height the new height of this component in pixels
2170 * @see #getSize
2171 * @see #setBounds
2172 * @see #invalidate
2173 * @since JDK1.1
2174 */
2175 public void setSize(int width, int height) {
2176 resize(width, height);
2177 }
2178
2179 /**
2180 * @deprecated As of JDK version 1.1,
2181 * replaced by <code>setSize(int, int)</code>.
2182 */
2183 @Deprecated
2184 public void resize(int width, int height) {
2185 synchronized(getTreeLock()) {
2186 setBoundsOp(ComponentPeer.SET_SIZE);
2187 setBounds(x, y, width, height);
2188 }
2189 }
2190
2191 /**
2192 * Resizes this component so that it has width <code>d.width</code>
2193 * and height <code>d.height</code>.
2194 * <p>
2195 * This method changes layout-related information, and therefore,
2196 * invalidates the component hierarchy.
2197 *
2198 * @param d the dimension specifying the new size
2199 * of this component
2200 * @throws NullPointerException if {@code d} is {@code null}
2201 * @see #setSize
2202 * @see #setBounds
2203 * @see #invalidate
2204 * @since JDK1.1
2205 */
2206 public void setSize(Dimension d) {
2207 resize(d);
2208 }
2209
2210 /**
2211 * @deprecated As of JDK version 1.1,
2212 * replaced by <code>setSize(Dimension)</code>.
2213 */
2214 @Deprecated
2215 public void resize(Dimension d) {
2216 setSize(d.width, d.height);
2217 }
2218
2219 /**
2220 * Gets the bounds of this component in the form of a
2221 * <code>Rectangle</code> object. The bounds specify this
2222 * component's width, height, and location relative to
2223 * its parent.
2224 * @return a rectangle indicating this component's bounds
2225 * @see #setBounds
2226 * @see #getLocation
2227 * @see #getSize
2228 */
2229 public Rectangle getBounds() {
2230 return bounds();
2231 }
2232
2233 /**
2234 * @deprecated As of JDK version 1.1,
2235 * replaced by <code>getBounds()</code>.
2236 */
2237 @Deprecated
2238 public Rectangle bounds() {
2239 return new Rectangle(x, y, width, height);
2240 }
2241
2242 /**
2243 * Moves and resizes this component. The new location of the top-left
2244 * corner is specified by <code>x</code> and <code>y</code>, and the
2245 * new size is specified by <code>width</code> and <code>height</code>.
2246 * <p>
2247 * This method changes layout-related information, and therefore,
2248 * invalidates the component hierarchy.
2249 *
2250 * @param x the new <i>x</i>-coordinate of this component
2251 * @param y the new <i>y</i>-coordinate of this component
2252 * @param width the new <code>width</code> of this component
2253 * @param height the new <code>height</code> of this
2254 * component
2255 * @see #getBounds
2256 * @see #setLocation(int, int)
2257 * @see #setLocation(Point)
2258 * @see #setSize(int, int)
2259 * @see #setSize(Dimension)
2260 * @see #invalidate
2261 * @since JDK1.1
2262 */
2263 public void setBounds(int x, int y, int width, int height) {
2264 reshape(x, y, width, height);
2265 }
2266
2267 /**
2268 * @deprecated As of JDK version 1.1,
2269 * replaced by <code>setBounds(int, int, int, int)</code>.
2270 */
2271 @Deprecated
2272 public void reshape(int x, int y, int width, int height) {
2273 synchronized (getTreeLock()) {
2274 try {
2275 setBoundsOp(ComponentPeer.SET_BOUNDS);
2276 boolean resized = (this.width != width) || (this.height != height);
2277 boolean moved = (this.x != x) || (this.y != y);
2278 if (!resized && !moved) {
2279 return;
2280 }
2281 int oldX = this.x;
2282 int oldY = this.y;
2283 int oldWidth = this.width;
2284 int oldHeight = this.height;
2285 this.x = x;
2286 this.y = y;
2287 this.width = width;
2614 * with a non-null value.
2615 * @since 1.5
2616 */
2617 public boolean isPreferredSizeSet() {
2618 return prefSizeSet;
2619 }
2620
2621
2622 /**
2623 * Gets the preferred size of this component.
2624 * @return a dimension object indicating this component's preferred size
2625 * @see #getMinimumSize
2626 * @see LayoutManager
2627 */
2628 public Dimension getPreferredSize() {
2629 return preferredSize();
2630 }
2631
2632
2633 /**
2634 * @deprecated As of JDK version 1.1,
2635 * replaced by <code>getPreferredSize()</code>.
2636 */
2637 @Deprecated
2638 public Dimension preferredSize() {
2639 /* Avoid grabbing the lock if a reasonable cached size value
2640 * is available.
2641 */
2642 Dimension dim = prefSize;
2643 if (dim == null || !(isPreferredSizeSet() || isValid())) {
2644 synchronized (getTreeLock()) {
2645 prefSize = (peer != null) ?
2646 peer.getPreferredSize() :
2647 getMinimumSize();
2648 dim = prefSize;
2649 }
2650 }
2651 return new Dimension(dim);
2652 }
2653
2684 *
2685 * @return true if <code>setMinimumSize</code> has been invoked with a
2686 * non-null value.
2687 * @since 1.5
2688 */
2689 public boolean isMinimumSizeSet() {
2690 return minSizeSet;
2691 }
2692
2693 /**
2694 * Gets the minimum size of this component.
2695 * @return a dimension object indicating this component's minimum size
2696 * @see #getPreferredSize
2697 * @see LayoutManager
2698 */
2699 public Dimension getMinimumSize() {
2700 return minimumSize();
2701 }
2702
2703 /**
2704 * @deprecated As of JDK version 1.1,
2705 * replaced by <code>getMinimumSize()</code>.
2706 */
2707 @Deprecated
2708 public Dimension minimumSize() {
2709 /* Avoid grabbing the lock if a reasonable cached size value
2710 * is available.
2711 */
2712 Dimension dim = minSize;
2713 if (dim == null || !(isMinimumSizeSet() || isValid())) {
2714 synchronized (getTreeLock()) {
2715 minSize = (peer != null) ?
2716 peer.getMinimumSize() :
2717 size();
2718 dim = minSize;
2719 }
2720 }
2721 return new Dimension(dim);
2722 }
2723
2764 /**
2765 * Gets the maximum size of this component.
2766 * @return a dimension object indicating this component's maximum size
2767 * @see #getMinimumSize
2768 * @see #getPreferredSize
2769 * @see LayoutManager
2770 */
2771 public Dimension getMaximumSize() {
2772 if (isMaximumSizeSet()) {
2773 return new Dimension(maxSize);
2774 }
2775 return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
2776 }
2777
2778 /**
2779 * Returns the alignment along the x axis. This specifies how
2780 * the component would like to be aligned relative to other
2781 * components. The value should be a number between 0 and 1
2782 * where 0 represents alignment along the origin, 1 is aligned
2783 * the furthest away from the origin, 0.5 is centered, etc.
2784 */
2785 public float getAlignmentX() {
2786 return CENTER_ALIGNMENT;
2787 }
2788
2789 /**
2790 * Returns the alignment along the y axis. This specifies how
2791 * the component would like to be aligned relative to other
2792 * components. The value should be a number between 0 and 1
2793 * where 0 represents alignment along the origin, 1 is aligned
2794 * the furthest away from the origin, 0.5 is centered, etc.
2795 */
2796 public float getAlignmentY() {
2797 return CENTER_ALIGNMENT;
2798 }
2799
2800 /**
2801 * Returns the baseline. The baseline is measured from the top of
2802 * the component. This method is primarily meant for
2803 * <code>LayoutManager</code>s to align components along their
2804 * baseline. A return value less than 0 indicates this component
2805 * does not have a reasonable baseline and that
2806 * <code>LayoutManager</code>s should not align this component on
2807 * its baseline.
2808 * <p>
2809 * The default implementation returns -1. Subclasses that support
2810 * baseline should override appropriately. If a value >= 0 is
2811 * returned, then the component has a valid baseline for any
2812 * size >= the minimum size and <code>getBaselineResizeBehavior</code>
2813 * can be used to determine how the baseline changes with size.
2814 *
3140 if (peer instanceof LightweightPeer) {
3141 Container nativeContainer = getNativeContainer();
3142
3143 if (nativeContainer == null) return;
3144
3145 ComponentPeer cPeer = nativeContainer.getPeer();
3146
3147 if (cPeer != null) {
3148 cPeer.updateCursorImmediately();
3149 }
3150 } else if (peer != null) {
3151 peer.updateCursorImmediately();
3152 }
3153 }
3154
3155 /**
3156 * Gets the cursor set in the component. If the component does
3157 * not have a cursor set, the cursor of its parent is returned.
3158 * If no cursor is set in the entire hierarchy,
3159 * <code>Cursor.DEFAULT_CURSOR</code> is returned.
3160 * @see #setCursor
3161 * @since JDK1.1
3162 */
3163 public Cursor getCursor() {
3164 return getCursor_NoClientCode();
3165 }
3166
3167 final Cursor getCursor_NoClientCode() {
3168 Cursor cursor = this.cursor;
3169 if (cursor != null) {
3170 return cursor;
3171 }
3172 Container parent = this.parent;
3173 if (parent != null) {
3174 return parent.getCursor_NoClientCode();
3175 } else {
3176 return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
3177 }
3178 }
3179
4243 * Inner class for blitting offscreen surfaces to a component.
4244 *
4245 * @author Michael Martak
4246 * @since 1.4
4247 */
4248 protected class BltBufferStrategy extends BufferStrategy {
4249
4250 /**
4251 * The buffering capabilities
4252 */
4253 protected BufferCapabilities caps; // = null
4254 /**
4255 * The back buffers
4256 */
4257 protected VolatileImage[] backBuffers; // = null
4258 /**
4259 * Whether or not the drawing buffer has been recently restored from
4260 * a lost state.
4261 */
4262 protected boolean validatedContents; // = false
4263 /**
4264 * Size of the back buffers
4265 */
4266 protected int width;
4267 protected int height;
4268
4269 /**
4270 * Insets for the hosting Component. The size of the back buffer
4271 * is constrained by these.
4272 */
4273 private Insets insets;
4274
4275 /**
4276 * Creates a new blt buffer strategy around a component
4277 * @param numBuffers number of buffers to create, including the
4278 * front buffer
4279 * @param caps the capabilities of the buffers
4280 */
4281 protected BltBufferStrategy(int numBuffers, BufferCapabilities caps) {
4282 this.caps = caps;
4283 createBackBuffers(numBuffers - 1);
4284 }
4285
4286 /**
4287 * {@inheritDoc}
4288 * @since 1.6
4289 */
4290 public void dispose() {
4291 if (backBuffers != null) {
4292 for (int counter = backBuffers.length - 1; counter >= 0;
4293 counter--) {
4294 if (backBuffers[counter] != null) {
4295 backBuffers[counter].flush();
4296 backBuffers[counter] = null;
4297 }
4298 }
4299 }
4300 if (Component.this.bufferStrategy == this) {
4301 Component.this.bufferStrategy = null;
4302 }
4303 }
4304
4305 /**
4306 * Creates the back buffers
4307 */
4308 protected void createBackBuffers(int numBuffers) {
4309 if (numBuffers == 0) {
4310 backBuffers = null;
4311 } else {
4312 // save the current bounds
4313 width = getWidth();
4314 height = getHeight();
4315 insets = getInsets_NoClientCode();
4316 int iWidth = width - insets.left - insets.right;
4317 int iHeight = height - insets.top - insets.bottom;
4318
4319 // It is possible for the component's width and/or height
4320 // to be 0 here. Force the size of the backbuffers to
4321 // be > 0 so that creating the image won't fail.
4322 iWidth = Math.max(1, iWidth);
4323 iHeight = Math.max(1, iHeight);
4324 if (backBuffers == null) {
4325 backBuffers = new VolatileImage[numBuffers];
4326 } else {
4576 return false;
4577 }
4578 public boolean contentsRestored() {
4579 return false;
4580 }
4581 public void show() {
4582 // Do nothing
4583 }
4584 } // Inner class SingleBufferStrategy
4585
4586 /**
4587 * Sets whether or not paint messages received from the operating system
4588 * should be ignored. This does not affect paint events generated in
4589 * software by the AWT, unless they are an immediate response to an
4590 * OS-level paint message.
4591 * <p>
4592 * This is useful, for example, if running under full-screen mode and
4593 * better performance is desired, or if page-flipping is used as the
4594 * buffer strategy.
4595 *
4596 * @since 1.4
4597 * @see #getIgnoreRepaint
4598 * @see Canvas#createBufferStrategy
4599 * @see Window#createBufferStrategy
4600 * @see java.awt.image.BufferStrategy
4601 * @see GraphicsDevice#setFullScreenWindow
4602 */
4603 public void setIgnoreRepaint(boolean ignoreRepaint) {
4604 this.ignoreRepaint = ignoreRepaint;
4605 }
4606
4607 /**
4608 * @return whether or not paint messages received from the operating system
4609 * should be ignored.
4610 *
4611 * @since 1.4
4612 * @see #setIgnoreRepaint
4613 */
4614 public boolean getIgnoreRepaint() {
4615 return ignoreRepaint;
4616 }
4617
4618 /**
4619 * Checks whether this component "contains" the specified point,
4620 * where <code>x</code> and <code>y</code> are defined to be
4621 * relative to the coordinate system of this component.
4622 * @param x the <i>x</i> coordinate of the point
4623 * @param y the <i>y</i> coordinate of the point
4624 * @see #getComponentAt(int, int)
4625 * @since JDK1.1
4626 */
4627 public boolean contains(int x, int y) {
4628 return inside(x, y);
4629 }
4630
4631 /**
4632 * @deprecated As of JDK version 1.1,
4633 * replaced by contains(int, int).
4634 */
4635 @Deprecated
4636 public boolean inside(int x, int y) {
4637 return (x >= 0) && (x < width) && (y >= 0) && (y < height);
4638 }
4639
4640 /**
4641 * Checks whether this component "contains" the specified point,
4642 * where the point's <i>x</i> and <i>y</i> coordinates are defined
4643 * to be relative to the coordinate system of this component.
4644 * @param p the point
4645 * @throws NullPointerException if {@code p} is {@code null}
4646 * @see #getComponentAt(Point)
4647 * @since JDK1.1
4648 */
4649 public boolean contains(Point p) {
4650 return contains(p.x, p.y);
4651 }
4652
4653 /**
4654 * Determines if this component or one of its immediate
4655 * subcomponents contains the (<i>x</i>, <i>y</i>) location,
4656 * and if so, returns the containing component. This method only
4657 * looks one level deep. If the point (<i>x</i>, <i>y</i>) is
4658 * inside a subcomponent that itself has subcomponents, it does not
4659 * go looking down the subcomponent tree.
4660 * <p>
4661 * The <code>locate</code> method of <code>Component</code> simply
4662 * returns the component itself if the (<i>x</i>, <i>y</i>)
4663 * coordinate location is inside its bounding box, and <code>null</code>
4664 * otherwise.
4665 * @param x the <i>x</i> coordinate
4666 * @param y the <i>y</i> coordinate
4667 * @return the component or subcomponent that contains the
4668 * (<i>x</i>, <i>y</i>) location;
4669 * <code>null</code> if the location
4670 * is outside this component
4671 * @see #contains(int, int)
4672 * @since JDK1.0
4673 */
4674 public Component getComponentAt(int x, int y) {
4675 return locate(x, y);
4676 }
4677
4678 /**
4679 * @deprecated As of JDK version 1.1,
4680 * replaced by getComponentAt(int, int).
4681 */
4682 @Deprecated
4683 public Component locate(int x, int y) {
4684 return contains(x, y) ? this : null;
4685 }
4686
4687 /**
4688 * Returns the component or subcomponent that contains the
4689 * specified point.
4690 * @param p the point
4691 * @see java.awt.Component#contains
4692 * @since JDK1.1
4693 */
4694 public Component getComponentAt(Point p) {
4695 return getComponentAt(p.x, p.y);
4696 }
4697
4698 /**
4699 * @deprecated As of JDK version 1.1,
4700 * replaced by <code>dispatchEvent(AWTEvent e)</code>.
4701 */
4702 @Deprecated
4703 public void deliverEvent(Event e) {
4704 postEvent(e);
4705 }
4706
4707 /**
4708 * Dispatches an event to this component or one of its sub components.
4709 * Calls <code>processEvent</code> before returning for 1.1-style
4710 * events which have been enabled for the <code>Component</code>.
4711 * @param e the event
4712 */
4713 public final void dispatchEvent(AWTEvent e) {
4714 dispatchEventImpl(e);
4715 }
4716
4717 @SuppressWarnings("deprecation")
4718 void dispatchEventImpl(AWTEvent e) {
6729 * @see #addHierarchyBoundsListener
6730 * @see #enableEvents
6731 * @since 1.3
6732 */
6733 protected void processHierarchyBoundsEvent(HierarchyEvent e) {
6734 HierarchyBoundsListener listener = hierarchyBoundsListener;
6735 if (listener != null) {
6736 int id = e.getID();
6737 switch (id) {
6738 case HierarchyEvent.ANCESTOR_MOVED:
6739 listener.ancestorMoved(e);
6740 break;
6741 case HierarchyEvent.ANCESTOR_RESIZED:
6742 listener.ancestorResized(e);
6743 break;
6744 }
6745 }
6746 }
6747
6748 /**
6749 * @deprecated As of JDK version 1.1
6750 * replaced by processEvent(AWTEvent).
6751 */
6752 @Deprecated
6753 public boolean handleEvent(Event evt) {
6754 switch (evt.id) {
6755 case Event.MOUSE_ENTER:
6756 return mouseEnter(evt, evt.x, evt.y);
6757
6758 case Event.MOUSE_EXIT:
6759 return mouseExit(evt, evt.x, evt.y);
6760
6761 case Event.MOUSE_MOVE:
6762 return mouseMove(evt, evt.x, evt.y);
6763
6764 case Event.MOUSE_DOWN:
6765 return mouseDown(evt, evt.x, evt.y);
6766
6767 case Event.MOUSE_DRAG:
6768 return mouseDrag(evt, evt.x, evt.y);
6772
6773 case Event.KEY_PRESS:
6774 case Event.KEY_ACTION:
6775 return keyDown(evt, evt.key);
6776
6777 case Event.KEY_RELEASE:
6778 case Event.KEY_ACTION_RELEASE:
6779 return keyUp(evt, evt.key);
6780
6781 case Event.ACTION_EVENT:
6782 return action(evt, evt.arg);
6783 case Event.GOT_FOCUS:
6784 return gotFocus(evt, evt.arg);
6785 case Event.LOST_FOCUS:
6786 return lostFocus(evt, evt.arg);
6787 }
6788 return false;
6789 }
6790
6791 /**
6792 * @deprecated As of JDK version 1.1,
6793 * replaced by processMouseEvent(MouseEvent).
6794 */
6795 @Deprecated
6796 public boolean mouseDown(Event evt, int x, int y) {
6797 return false;
6798 }
6799
6800 /**
6801 * @deprecated As of JDK version 1.1,
6802 * replaced by processMouseMotionEvent(MouseEvent).
6803 */
6804 @Deprecated
6805 public boolean mouseDrag(Event evt, int x, int y) {
6806 return false;
6807 }
6808
6809 /**
6810 * @deprecated As of JDK version 1.1,
6811 * replaced by processMouseEvent(MouseEvent).
6812 */
6813 @Deprecated
6814 public boolean mouseUp(Event evt, int x, int y) {
6815 return false;
6816 }
6817
6818 /**
6819 * @deprecated As of JDK version 1.1,
6820 * replaced by processMouseMotionEvent(MouseEvent).
6821 */
6822 @Deprecated
6823 public boolean mouseMove(Event evt, int x, int y) {
6824 return false;
6825 }
6826
6827 /**
6828 * @deprecated As of JDK version 1.1,
6829 * replaced by processMouseEvent(MouseEvent).
6830 */
6831 @Deprecated
6832 public boolean mouseEnter(Event evt, int x, int y) {
6833 return false;
6834 }
6835
6836 /**
6837 * @deprecated As of JDK version 1.1,
6838 * replaced by processMouseEvent(MouseEvent).
6839 */
6840 @Deprecated
6841 public boolean mouseExit(Event evt, int x, int y) {
6842 return false;
6843 }
6844
6845 /**
6846 * @deprecated As of JDK version 1.1,
6847 * replaced by processKeyEvent(KeyEvent).
6848 */
6849 @Deprecated
6850 public boolean keyDown(Event evt, int key) {
6851 return false;
6852 }
6853
6854 /**
6855 * @deprecated As of JDK version 1.1,
6856 * replaced by processKeyEvent(KeyEvent).
6857 */
6858 @Deprecated
6859 public boolean keyUp(Event evt, int key) {
6860 return false;
6861 }
6862
6863 /**
6864 * @deprecated As of JDK version 1.1,
6865 * should register this component as ActionListener on component
6866 * which fires action events.
6867 */
6868 @Deprecated
6869 public boolean action(Event evt, Object what) {
6870 return false;
6871 }
6872
6873 /**
6874 * Makes this <code>Component</code> displayable by connecting it to a
6875 * native screen resource.
6876 * This method is called internally by the toolkit and should
6877 * not be called directly by programs.
6878 * <p>
6879 * This method changes layout-related information, and therefore,
6880 * invalidates the component hierarchy.
6881 *
6882 * @see #isDisplayable
6883 * @see #removeNotify
7053 // (or has no shape at all).
7054 this.compoundShape = null;
7055 }
7056
7057 if (hierarchyListener != null ||
7058 (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 ||
7059 Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)) {
7060 HierarchyEvent e =
7061 new HierarchyEvent(this, HierarchyEvent.HIERARCHY_CHANGED,
7062 this, parent,
7063 HierarchyEvent.DISPLAYABILITY_CHANGED |
7064 ((isRecursivelyVisible())
7065 ? HierarchyEvent.SHOWING_CHANGED
7066 : 0));
7067 dispatchEvent(e);
7068 }
7069 }
7070 }
7071
7072 /**
7073 * @deprecated As of JDK version 1.1,
7074 * replaced by processFocusEvent(FocusEvent).
7075 */
7076 @Deprecated
7077 public boolean gotFocus(Event evt, Object what) {
7078 return false;
7079 }
7080
7081 /**
7082 * @deprecated As of JDK version 1.1,
7083 * replaced by processFocusEvent(FocusEvent).
7084 */
7085 @Deprecated
7086 public boolean lostFocus(Event evt, Object what) {
7087 return false;
7088 }
7089
7090 /**
7091 * Returns whether this <code>Component</code> can become the focus
7092 * owner.
7093 *
7094 * @return <code>true</code> if this <code>Component</code> is
7095 * focusable; <code>false</code> otherwise
7096 * @see #setFocusable
7097 * @since JDK1.1
7098 * @deprecated As of 1.4, replaced by <code>isFocusable()</code>.
7099 */
7100 @Deprecated
7101 public boolean isFocusTraversable() {
8373 *
8374 * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
8375 * @see #getPropertyChangeListeners(java.lang.String)
8376 * @see #removePropertyChangeListener(java.beans.PropertyChangeListener)
8377 */
8378 public void removePropertyChangeListener(
8379 String propertyName,
8380 PropertyChangeListener listener) {
8381 synchronized (getObjectLock()) {
8382 if (listener == null || changeSupport == null) {
8383 return;
8384 }
8385 changeSupport.removePropertyChangeListener(propertyName, listener);
8386 }
8387 }
8388
8389 /**
8390 * Returns an array of all the listeners which have been associated
8391 * with the named property.
8392 *
8393 * @return all of the <code>PropertyChangeListener</code>s associated with
8394 * the named property; if no such listeners have been added or
8395 * if <code>propertyName</code> is <code>null</code>, an empty
8396 * array is returned
8397 *
8398 * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
8399 * @see #removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
8400 * @see #getPropertyChangeListeners
8401 * @since 1.4
8402 */
8403 public PropertyChangeListener[] getPropertyChangeListeners(
8404 String propertyName) {
8405 synchronized (getObjectLock()) {
8406 if (changeSupport == null) {
8407 return new PropertyChangeListener[0];
8408 }
8409 return changeSupport.getPropertyChangeListeners(propertyName);
8410 }
8411 }
8412
8413 /**
8414 * Support for reporting bound property changes for Object properties.
8415 * This method can be called when a bound property has changed and it will
8416 * send the appropriate PropertyChangeEvent to any registered
8417 * PropertyChangeListeners.
8418 *
8419 * @param propertyName the property whose value has changed
8420 * @param oldValue the property's previous value
8421 * @param newValue the property's new value
8422 */
8423 protected void firePropertyChange(String propertyName,
8424 Object oldValue, Object newValue) {
8862 * Sets the language-sensitive orientation that is to be used to order
8863 * the elements or text within this component. Language-sensitive
8864 * <code>LayoutManager</code> and <code>Component</code>
8865 * subclasses will use this property to
8866 * determine how to lay out and draw components.
8867 * <p>
8868 * At construction time, a component's orientation is set to
8869 * <code>ComponentOrientation.UNKNOWN</code>,
8870 * indicating that it has not been specified
8871 * explicitly. The UNKNOWN orientation behaves the same as
8872 * <code>ComponentOrientation.LEFT_TO_RIGHT</code>.
8873 * <p>
8874 * To set the orientation of a single component, use this method.
8875 * To set the orientation of an entire component
8876 * hierarchy, use
8877 * {@link #applyComponentOrientation applyComponentOrientation}.
8878 * <p>
8879 * This method changes layout-related information, and therefore,
8880 * invalidates the component hierarchy.
8881 *
8882 *
8883 * @see ComponentOrientation
8884 * @see #invalidate
8885 *
8886 * @author Laura Werner, IBM
8887 * @beaninfo
8888 * bound: true
8889 */
8890 public void setComponentOrientation(ComponentOrientation o) {
8891 ComponentOrientation oldValue = componentOrientation;
8892 componentOrientation = o;
8893
8894 // This is a bound property, so report the change to
8895 // any registered listeners. (Cheap if there are none.)
8896 firePropertyChange("componentOrientation", oldValue, o);
8897
8898 // This could change the preferred size of the Component.
8899 invalidateIfValid();
8900 }
8901
8902 /**
8903 * Retrieves the language-sensitive orientation that is to be used to order
8904 * the elements or text within this component. <code>LayoutManager</code>
8905 * and <code>Component</code>
8906 * subclasses that wish to respect orientation should call this method to
8907 * get the component's orientation before performing layout or drawing.
8908 *
8909 * @see ComponentOrientation
8910 *
8911 * @author Laura Werner, IBM
8912 */
8913 public ComponentOrientation getComponentOrientation() {
8914 return componentOrientation;
8915 }
8916
8917 /**
8918 * Sets the <code>ComponentOrientation</code> property of this component
8919 * and all components contained within it.
8920 * <p>
8921 * This method changes layout-related information, and therefore,
8922 * invalidates the component hierarchy.
8923 *
8924 *
8925 * @param orientation the new component orientation of this component and
8926 * the components contained within it.
8927 * @exception NullPointerException if <code>orientation</code> is null.
8928 * @see #setComponentOrientation
9046 */
9047 protected abstract class AccessibleAWTComponent extends AccessibleContext
9048 implements Serializable, AccessibleComponent {
9049
9050 private static final long serialVersionUID = 642321655757800191L;
9051
9052 /**
9053 * Though the class is abstract, this should be called by
9054 * all sub-classes.
9055 */
9056 protected AccessibleAWTComponent() {
9057 }
9058
9059 /**
9060 * Number of PropertyChangeListener objects registered. It's used
9061 * to add/remove ComponentListener and FocusListener to track
9062 * target Component's state.
9063 */
9064 private volatile transient int propertyListenersCount = 0;
9065
9066 protected ComponentListener accessibleAWTComponentHandler = null;
9067 protected FocusListener accessibleAWTFocusHandler = null;
9068
9069 /**
9070 * Fire PropertyChange listener, if one is registered,
9071 * when shown/hidden..
9072 * @since 1.3
9073 */
9074 protected class AccessibleAWTComponentHandler implements ComponentListener {
9075 public void componentHidden(ComponentEvent e) {
9076 if (accessibleContext != null) {
9077 accessibleContext.firePropertyChange(
9078 AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
9079 AccessibleState.VISIBLE, null);
9080 }
9081 }
9082
9083 public void componentShown(ComponentEvent e) {
9084 if (accessibleContext != null) {
9085 accessibleContext.firePropertyChange(
9086 AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
|
1058
1059 // NOTE: This method may be called by privileged threads.
1060 // This functionality is implemented in a package-private method
1061 // to insure that it cannot be overridden by client subclasses.
1062 // DO NOT INVOKE CLIENT CODE ON THIS THREAD!
1063 final Container getParent_NoClientCode() {
1064 return parent;
1065 }
1066
1067 // This method is overridden in the Window class to return null,
1068 // because the parent field of the Window object contains
1069 // the owner of the window, not its parent.
1070 Container getContainer() {
1071 return getParent_NoClientCode();
1072 }
1073
1074 /**
1075 * @deprecated As of JDK version 1.1,
1076 * programs should not directly manipulate peers;
1077 * replaced by <code>boolean isDisplayable()</code>.
1078 * @return the peer for this component
1079 */
1080 @Deprecated
1081 public ComponentPeer getPeer() {
1082 return peer;
1083 }
1084
1085 /**
1086 * Associate a <code>DropTarget</code> with this component.
1087 * The <code>Component</code> will receive drops only if it
1088 * is enabled.
1089 *
1090 * @see #isEnabled
1091 * @param dt The DropTarget
1092 */
1093
1094 public synchronized void setDropTarget(DropTarget dt) {
1095 if (dt == dropTarget || (dropTarget != null && dropTarget.equals(dt)))
1096 return;
1097
1098 DropTarget old;
1116 if ((dropTarget = dt) != null) {
1117 try {
1118 dropTarget.setComponent(this);
1119 if (peer != null) dropTarget.addNotify(peer);
1120 } catch (IllegalArgumentException iae) {
1121 if (old != null) {
1122 try {
1123 old.setComponent(this);
1124 if (peer != null) dropTarget.addNotify(peer);
1125 } catch (IllegalArgumentException iae1) {
1126 // ignore it!
1127 }
1128 }
1129 }
1130 }
1131 }
1132
1133 /**
1134 * Gets the <code>DropTarget</code> associated with this
1135 * <code>Component</code>.
1136 * @return the drop target
1137 */
1138
1139 public synchronized DropTarget getDropTarget() { return dropTarget; }
1140
1141 /**
1142 * Gets the <code>GraphicsConfiguration</code> associated with this
1143 * <code>Component</code>.
1144 * If the <code>Component</code> has not been assigned a specific
1145 * <code>GraphicsConfiguration</code>,
1146 * the <code>GraphicsConfiguration</code> of the
1147 * <code>Component</code> object's top-level container is
1148 * returned.
1149 * If the <code>Component</code> has been created, but not yet added
1150 * to a <code>Container</code>, this method returns <code>null</code>.
1151 *
1152 * @return the <code>GraphicsConfiguration</code> used by this
1153 * <code>Component</code> or <code>null</code>
1154 * @since 1.3
1155 */
1156 public GraphicsConfiguration getGraphicsConfiguration() {
1483 if (!enabled) {
1484 synchronized (getTreeLock()) {
1485 enabled = true;
1486 ComponentPeer peer = this.peer;
1487 if (peer != null) {
1488 peer.setEnabled(true);
1489 if (visible) {
1490 updateCursorImmediately();
1491 }
1492 }
1493 }
1494 if (accessibleContext != null) {
1495 accessibleContext.firePropertyChange(
1496 AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
1497 null, AccessibleState.ENABLED);
1498 }
1499 }
1500 }
1501
1502 /**
1503 * Enables or disables this component.
1504 * @param b {@code true} to enable this component;
1505 * otherwise {@code false}
1506 *
1507 * @deprecated As of JDK version 1.1,
1508 * replaced by <code>setEnabled(boolean)</code>.
1509 */
1510 @Deprecated
1511 public void enable(boolean b) {
1512 if (b) {
1513 enable();
1514 } else {
1515 disable();
1516 }
1517 }
1518
1519 /**
1520 * @deprecated As of JDK version 1.1,
1521 * replaced by <code>setEnabled(boolean)</code>.
1522 */
1523 @Deprecated
1524 public void disable() {
1525 if (enabled) {
1526 KeyboardFocusManager.clearMostRecentFocusOwner(this);
1645 }
1646 updateCursorImmediately();
1647 }
1648
1649 if (componentListener != null ||
1650 (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
1651 Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) {
1652 ComponentEvent e = new ComponentEvent(this,
1653 ComponentEvent.COMPONENT_SHOWN);
1654 Toolkit.getEventQueue().postEvent(e);
1655 }
1656 }
1657 Container parent = this.parent;
1658 if (parent != null) {
1659 parent.invalidate();
1660 }
1661 }
1662 }
1663
1664 /**
1665 * Makes this component visible or invisible.
1666 * @param b {@code true} to make this component visible;
1667 * otherwise {@code false}
1668 *
1669 * @deprecated As of JDK version 1.1,
1670 * replaced by <code>setVisible(boolean)</code>.
1671 */
1672 @Deprecated
1673 public void show(boolean b) {
1674 if (b) {
1675 show();
1676 } else {
1677 hide();
1678 }
1679 }
1680
1681 boolean containsFocus() {
1682 return isFocusOwner();
1683 }
1684
1685 void clearMostRecentFocusOwnerOnHide() {
1686 KeyboardFocusManager.clearMostRecentFocusOwner(this);
1687 }
1688
2061 // lightweight component location needs to be translated
2062 // relative to a native component.
2063 Container host = getNativeContainer();
2064 Point pt = host.peer.getLocationOnScreen();
2065 for(Component c = this; c != host; c = c.getParent()) {
2066 pt.x += c.x;
2067 pt.y += c.y;
2068 }
2069 return pt;
2070 } else {
2071 Point pt = peer.getLocationOnScreen();
2072 return pt;
2073 }
2074 } else {
2075 throw new IllegalComponentStateException("component must be showing on the screen to determine its location");
2076 }
2077 }
2078
2079
2080 /**
2081 * Returns the location of this component's top left corner.
2082 * @return the location of this component's top left corner
2083 * @deprecated As of JDK version 1.1,
2084 * replaced by <code>getLocation()</code>.
2085 */
2086 @Deprecated
2087 public Point location() {
2088 return location_NoClientCode();
2089 }
2090
2091 private Point location_NoClientCode() {
2092 return new Point(x, y);
2093 }
2094
2095 /**
2096 * Moves this component to a new location. The top-left corner of
2097 * the new location is specified by the <code>x</code> and <code>y</code>
2098 * parameters in the coordinate space of this component's parent.
2099 * <p>
2100 * This method changes layout-related information, and therefore,
2101 * invalidates the component hierarchy.
2102 *
2103 * @param x the <i>x</i>-coordinate of the new location's
2104 * top-left corner in the parent's coordinate space
2105 * @param y the <i>y</i>-coordinate of the new location's
2106 * top-left corner in the parent's coordinate space
2107 * @see #getLocation
2108 * @see #setBounds
2109 * @see #invalidate
2110 * @since JDK1.1
2111 */
2112 public void setLocation(int x, int y) {
2113 move(x, y);
2114 }
2115
2116 /**
2117 * Moves this component to a new location.
2118 * @param x the <i>x</i>-coordinate of the new location's
2119 * top-left corner in the parent's coordinate space
2120 * @param y the <i>y</i>-coordinate of the new location's
2121 * top-left corner in the parent's coordinate space
2122
2123 * @deprecated As of JDK version 1.1,
2124 * replaced by <code>setLocation(int, int)</code>.
2125 */
2126 @Deprecated
2127 public void move(int x, int y) {
2128 synchronized(getTreeLock()) {
2129 setBoundsOp(ComponentPeer.SET_LOCATION);
2130 setBounds(x, y, width, height);
2131 }
2132 }
2133
2134 /**
2135 * Moves this component to a new location. The top-left corner of
2136 * the new location is specified by point <code>p</code>. Point
2137 * <code>p</code> is given in the parent's coordinate space.
2138 * <p>
2139 * This method changes layout-related information, and therefore,
2140 * invalidates the component hierarchy.
2141 *
2142 * @param p the point defining the top-left corner
2151 setLocation(p.x, p.y);
2152 }
2153
2154 /**
2155 * Returns the size of this component in the form of a
2156 * <code>Dimension</code> object. The <code>height</code>
2157 * field of the <code>Dimension</code> object contains
2158 * this component's height, and the <code>width</code>
2159 * field of the <code>Dimension</code> object contains
2160 * this component's width.
2161 * @return a <code>Dimension</code> object that indicates the
2162 * size of this component
2163 * @see #setSize
2164 * @since JDK1.1
2165 */
2166 public Dimension getSize() {
2167 return size();
2168 }
2169
2170 /**
2171 * Returns the size of this component in the form of a
2172 * <code>Dimension</code> object.
2173 * @return the {@code Dimension} object that indicates the
2174 * size of this component
2175 * @deprecated As of JDK version 1.1,
2176 * replaced by <code>getSize()</code>.
2177 */
2178 @Deprecated
2179 public Dimension size() {
2180 return new Dimension(width, height);
2181 }
2182
2183 /**
2184 * Resizes this component so that it has width <code>width</code>
2185 * and height <code>height</code>.
2186 * <p>
2187 * This method changes layout-related information, and therefore,
2188 * invalidates the component hierarchy.
2189 *
2190 * @param width the new width of this component in pixels
2191 * @param height the new height of this component in pixels
2192 * @see #getSize
2193 * @see #setBounds
2194 * @see #invalidate
2195 * @since JDK1.1
2196 */
2197 public void setSize(int width, int height) {
2198 resize(width, height);
2199 }
2200
2201 /**
2202 * Resizes this component.
2203 * @param width the new width of the component
2204 * @param height the new height of the component
2205 * @deprecated As of JDK version 1.1,
2206 * replaced by <code>setSize(int, int)</code>.
2207 */
2208 @Deprecated
2209 public void resize(int width, int height) {
2210 synchronized(getTreeLock()) {
2211 setBoundsOp(ComponentPeer.SET_SIZE);
2212 setBounds(x, y, width, height);
2213 }
2214 }
2215
2216 /**
2217 * Resizes this component so that it has width <code>d.width</code>
2218 * and height <code>d.height</code>.
2219 * <p>
2220 * This method changes layout-related information, and therefore,
2221 * invalidates the component hierarchy.
2222 *
2223 * @param d the dimension specifying the new size
2224 * of this component
2225 * @throws NullPointerException if {@code d} is {@code null}
2226 * @see #setSize
2227 * @see #setBounds
2228 * @see #invalidate
2229 * @since JDK1.1
2230 */
2231 public void setSize(Dimension d) {
2232 resize(d);
2233 }
2234
2235 /**
2236 * Resizes this component so that it has width {@code d.width}
2237 * and height {@code d.height}.
2238 * @param d the new size of this component
2239 * @deprecated As of JDK version 1.1,
2240 * replaced by <code>setSize(Dimension)</code>.
2241 */
2242 @Deprecated
2243 public void resize(Dimension d) {
2244 setSize(d.width, d.height);
2245 }
2246
2247 /**
2248 * Gets the bounds of this component in the form of a
2249 * <code>Rectangle</code> object. The bounds specify this
2250 * component's width, height, and location relative to
2251 * its parent.
2252 * @return a rectangle indicating this component's bounds
2253 * @see #setBounds
2254 * @see #getLocation
2255 * @see #getSize
2256 */
2257 public Rectangle getBounds() {
2258 return bounds();
2259 }
2260
2261 /**
2262 * Returns the bounding rectangle of this component.
2263 * @return the bounding rectangle for this component
2264 * @deprecated As of JDK version 1.1,
2265 * replaced by <code>getBounds()</code>.
2266 */
2267 @Deprecated
2268 public Rectangle bounds() {
2269 return new Rectangle(x, y, width, height);
2270 }
2271
2272 /**
2273 * Moves and resizes this component. The new location of the top-left
2274 * corner is specified by <code>x</code> and <code>y</code>, and the
2275 * new size is specified by <code>width</code> and <code>height</code>.
2276 * <p>
2277 * This method changes layout-related information, and therefore,
2278 * invalidates the component hierarchy.
2279 *
2280 * @param x the new <i>x</i>-coordinate of this component
2281 * @param y the new <i>y</i>-coordinate of this component
2282 * @param width the new <code>width</code> of this component
2283 * @param height the new <code>height</code> of this
2284 * component
2285 * @see #getBounds
2286 * @see #setLocation(int, int)
2287 * @see #setLocation(Point)
2288 * @see #setSize(int, int)
2289 * @see #setSize(Dimension)
2290 * @see #invalidate
2291 * @since JDK1.1
2292 */
2293 public void setBounds(int x, int y, int width, int height) {
2294 reshape(x, y, width, height);
2295 }
2296
2297 /**
2298 * Reshapes the bounding rectangle for this component.
2299 *
2300 * @param x the <i>x</i> coordinate of the upper left corner of the rectangle
2301 * @param y the <i>y</i> coordinate of the upper left corner of the rectangle
2302 * @param width the width of the rectangle
2303 * @param height the height of the rectangle
2304 *
2305 * @deprecated As of JDK version 1.1,
2306 * replaced by <code>setBounds(int, int, int, int)</code>.
2307 */
2308 @Deprecated
2309 public void reshape(int x, int y, int width, int height) {
2310 synchronized (getTreeLock()) {
2311 try {
2312 setBoundsOp(ComponentPeer.SET_BOUNDS);
2313 boolean resized = (this.width != width) || (this.height != height);
2314 boolean moved = (this.x != x) || (this.y != y);
2315 if (!resized && !moved) {
2316 return;
2317 }
2318 int oldX = this.x;
2319 int oldY = this.y;
2320 int oldWidth = this.width;
2321 int oldHeight = this.height;
2322 this.x = x;
2323 this.y = y;
2324 this.width = width;
2651 * with a non-null value.
2652 * @since 1.5
2653 */
2654 public boolean isPreferredSizeSet() {
2655 return prefSizeSet;
2656 }
2657
2658
2659 /**
2660 * Gets the preferred size of this component.
2661 * @return a dimension object indicating this component's preferred size
2662 * @see #getMinimumSize
2663 * @see LayoutManager
2664 */
2665 public Dimension getPreferredSize() {
2666 return preferredSize();
2667 }
2668
2669
2670 /**
2671 * Returns the component's preferred size.
2672 * @return the component's preferred size
2673 * @deprecated As of JDK version 1.1,
2674 * replaced by <code>getPreferredSize()</code>.
2675 */
2676 @Deprecated
2677 public Dimension preferredSize() {
2678 /* Avoid grabbing the lock if a reasonable cached size value
2679 * is available.
2680 */
2681 Dimension dim = prefSize;
2682 if (dim == null || !(isPreferredSizeSet() || isValid())) {
2683 synchronized (getTreeLock()) {
2684 prefSize = (peer != null) ?
2685 peer.getPreferredSize() :
2686 getMinimumSize();
2687 dim = prefSize;
2688 }
2689 }
2690 return new Dimension(dim);
2691 }
2692
2723 *
2724 * @return true if <code>setMinimumSize</code> has been invoked with a
2725 * non-null value.
2726 * @since 1.5
2727 */
2728 public boolean isMinimumSizeSet() {
2729 return minSizeSet;
2730 }
2731
2732 /**
2733 * Gets the minimum size of this component.
2734 * @return a dimension object indicating this component's minimum size
2735 * @see #getPreferredSize
2736 * @see LayoutManager
2737 */
2738 public Dimension getMinimumSize() {
2739 return minimumSize();
2740 }
2741
2742 /**
2743 * Returns the minimum size of this component.
2744 * @return the minimum size of this component
2745 * @deprecated As of JDK version 1.1,
2746 * replaced by <code>getMinimumSize()</code>.
2747 */
2748 @Deprecated
2749 public Dimension minimumSize() {
2750 /* Avoid grabbing the lock if a reasonable cached size value
2751 * is available.
2752 */
2753 Dimension dim = minSize;
2754 if (dim == null || !(isMinimumSizeSet() || isValid())) {
2755 synchronized (getTreeLock()) {
2756 minSize = (peer != null) ?
2757 peer.getMinimumSize() :
2758 size();
2759 dim = minSize;
2760 }
2761 }
2762 return new Dimension(dim);
2763 }
2764
2805 /**
2806 * Gets the maximum size of this component.
2807 * @return a dimension object indicating this component's maximum size
2808 * @see #getMinimumSize
2809 * @see #getPreferredSize
2810 * @see LayoutManager
2811 */
2812 public Dimension getMaximumSize() {
2813 if (isMaximumSizeSet()) {
2814 return new Dimension(maxSize);
2815 }
2816 return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
2817 }
2818
2819 /**
2820 * Returns the alignment along the x axis. This specifies how
2821 * the component would like to be aligned relative to other
2822 * components. The value should be a number between 0 and 1
2823 * where 0 represents alignment along the origin, 1 is aligned
2824 * the furthest away from the origin, 0.5 is centered, etc.
2825 *
2826 * @return the horizontal alignment of this component
2827 */
2828 public float getAlignmentX() {
2829 return CENTER_ALIGNMENT;
2830 }
2831
2832 /**
2833 * Returns the alignment along the y axis. This specifies how
2834 * the component would like to be aligned relative to other
2835 * components. The value should be a number between 0 and 1
2836 * where 0 represents alignment along the origin, 1 is aligned
2837 * the furthest away from the origin, 0.5 is centered, etc.
2838 *
2839 * @return the vertical alignment of this component
2840 */
2841 public float getAlignmentY() {
2842 return CENTER_ALIGNMENT;
2843 }
2844
2845 /**
2846 * Returns the baseline. The baseline is measured from the top of
2847 * the component. This method is primarily meant for
2848 * <code>LayoutManager</code>s to align components along their
2849 * baseline. A return value less than 0 indicates this component
2850 * does not have a reasonable baseline and that
2851 * <code>LayoutManager</code>s should not align this component on
2852 * its baseline.
2853 * <p>
2854 * The default implementation returns -1. Subclasses that support
2855 * baseline should override appropriately. If a value >= 0 is
2856 * returned, then the component has a valid baseline for any
2857 * size >= the minimum size and <code>getBaselineResizeBehavior</code>
2858 * can be used to determine how the baseline changes with size.
2859 *
3185 if (peer instanceof LightweightPeer) {
3186 Container nativeContainer = getNativeContainer();
3187
3188 if (nativeContainer == null) return;
3189
3190 ComponentPeer cPeer = nativeContainer.getPeer();
3191
3192 if (cPeer != null) {
3193 cPeer.updateCursorImmediately();
3194 }
3195 } else if (peer != null) {
3196 peer.updateCursorImmediately();
3197 }
3198 }
3199
3200 /**
3201 * Gets the cursor set in the component. If the component does
3202 * not have a cursor set, the cursor of its parent is returned.
3203 * If no cursor is set in the entire hierarchy,
3204 * <code>Cursor.DEFAULT_CURSOR</code> is returned.
3205 * @return the cursor for this component
3206 * @see #setCursor
3207 * @since JDK1.1
3208 */
3209 public Cursor getCursor() {
3210 return getCursor_NoClientCode();
3211 }
3212
3213 final Cursor getCursor_NoClientCode() {
3214 Cursor cursor = this.cursor;
3215 if (cursor != null) {
3216 return cursor;
3217 }
3218 Container parent = this.parent;
3219 if (parent != null) {
3220 return parent.getCursor_NoClientCode();
3221 } else {
3222 return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
3223 }
3224 }
3225
4289 * Inner class for blitting offscreen surfaces to a component.
4290 *
4291 * @author Michael Martak
4292 * @since 1.4
4293 */
4294 protected class BltBufferStrategy extends BufferStrategy {
4295
4296 /**
4297 * The buffering capabilities
4298 */
4299 protected BufferCapabilities caps; // = null
4300 /**
4301 * The back buffers
4302 */
4303 protected VolatileImage[] backBuffers; // = null
4304 /**
4305 * Whether or not the drawing buffer has been recently restored from
4306 * a lost state.
4307 */
4308 protected boolean validatedContents; // = false
4309
4310 /**
4311 * The width of the back buffers
4312 */
4313 protected int width;
4314
4315 /**
4316 * The height of the back buffers
4317 */
4318 protected int height;
4319
4320 /**
4321 * Insets for the hosting Component. The size of the back buffer
4322 * is constrained by these.
4323 */
4324 private Insets insets;
4325
4326 /**
4327 * Creates a new blt buffer strategy around a component
4328 * @param numBuffers number of buffers to create, including the
4329 * front buffer
4330 * @param caps the capabilities of the buffers
4331 */
4332 protected BltBufferStrategy(int numBuffers, BufferCapabilities caps) {
4333 this.caps = caps;
4334 createBackBuffers(numBuffers - 1);
4335 }
4336
4337 /**
4338 * {@inheritDoc}
4339 * @since 1.6
4340 */
4341 public void dispose() {
4342 if (backBuffers != null) {
4343 for (int counter = backBuffers.length - 1; counter >= 0;
4344 counter--) {
4345 if (backBuffers[counter] != null) {
4346 backBuffers[counter].flush();
4347 backBuffers[counter] = null;
4348 }
4349 }
4350 }
4351 if (Component.this.bufferStrategy == this) {
4352 Component.this.bufferStrategy = null;
4353 }
4354 }
4355
4356 /**
4357 * Creates the back buffers
4358 *
4359 * @param numBuffers the number of buffers to create
4360 */
4361 protected void createBackBuffers(int numBuffers) {
4362 if (numBuffers == 0) {
4363 backBuffers = null;
4364 } else {
4365 // save the current bounds
4366 width = getWidth();
4367 height = getHeight();
4368 insets = getInsets_NoClientCode();
4369 int iWidth = width - insets.left - insets.right;
4370 int iHeight = height - insets.top - insets.bottom;
4371
4372 // It is possible for the component's width and/or height
4373 // to be 0 here. Force the size of the backbuffers to
4374 // be > 0 so that creating the image won't fail.
4375 iWidth = Math.max(1, iWidth);
4376 iHeight = Math.max(1, iHeight);
4377 if (backBuffers == null) {
4378 backBuffers = new VolatileImage[numBuffers];
4379 } else {
4629 return false;
4630 }
4631 public boolean contentsRestored() {
4632 return false;
4633 }
4634 public void show() {
4635 // Do nothing
4636 }
4637 } // Inner class SingleBufferStrategy
4638
4639 /**
4640 * Sets whether or not paint messages received from the operating system
4641 * should be ignored. This does not affect paint events generated in
4642 * software by the AWT, unless they are an immediate response to an
4643 * OS-level paint message.
4644 * <p>
4645 * This is useful, for example, if running under full-screen mode and
4646 * better performance is desired, or if page-flipping is used as the
4647 * buffer strategy.
4648 *
4649 * @param ignoreRepaint {@code true} if the paint messages from the OS
4650 * should be ignored; otherwise {@code false}
4651 *
4652 * @since 1.4
4653 * @see #getIgnoreRepaint
4654 * @see Canvas#createBufferStrategy
4655 * @see Window#createBufferStrategy
4656 * @see java.awt.image.BufferStrategy
4657 * @see GraphicsDevice#setFullScreenWindow
4658 */
4659 public void setIgnoreRepaint(boolean ignoreRepaint) {
4660 this.ignoreRepaint = ignoreRepaint;
4661 }
4662
4663 /**
4664 * @return whether or not paint messages received from the operating system
4665 * should be ignored.
4666 *
4667 * @since 1.4
4668 * @see #setIgnoreRepaint
4669 */
4670 public boolean getIgnoreRepaint() {
4671 return ignoreRepaint;
4672 }
4673
4674 /**
4675 * Checks whether this component "contains" the specified point,
4676 * where <code>x</code> and <code>y</code> are defined to be
4677 * relative to the coordinate system of this component.
4678 * @param x the <i>x</i> coordinate of the point
4679 * @param y the <i>y</i> coordinate of the point
4680 * @return {@code true} if the point is within the component;
4681 * otherwise {@code false}
4682 * @see #getComponentAt(int, int)
4683 * @since JDK1.1
4684 */
4685 public boolean contains(int x, int y) {
4686 return inside(x, y);
4687 }
4688
4689 /**
4690 * Checks whether the point is inside of this component.
4691 * @param x the <i>x</i> coordinate of the point
4692 * @param y the <i>y</i> coordinate of the point
4693 * @return {@code true} if the point is within the component;
4694 * otherwise {@code false}
4695 * @deprecated As of JDK version 1.1,
4696 * replaced by contains(int, int).
4697 */
4698 @Deprecated
4699 public boolean inside(int x, int y) {
4700 return (x >= 0) && (x < width) && (y >= 0) && (y < height);
4701 }
4702
4703 /**
4704 * Checks whether this component "contains" the specified point,
4705 * where the point's <i>x</i> and <i>y</i> coordinates are defined
4706 * to be relative to the coordinate system of this component.
4707 * @param p the point
4708 * @return {@code true} if the point is within the component;
4709 * otherwise {@code false}
4710 * @throws NullPointerException if {@code p} is {@code null}
4711 * @see #getComponentAt(Point)
4712 * @since JDK1.1
4713 */
4714 public boolean contains(Point p) {
4715 return contains(p.x, p.y);
4716 }
4717
4718 /**
4719 * Determines if this component or one of its immediate
4720 * subcomponents contains the (<i>x</i>, <i>y</i>) location,
4721 * and if so, returns the containing component. This method only
4722 * looks one level deep. If the point (<i>x</i>, <i>y</i>) is
4723 * inside a subcomponent that itself has subcomponents, it does not
4724 * go looking down the subcomponent tree.
4725 * <p>
4726 * The <code>locate</code> method of <code>Component</code> simply
4727 * returns the component itself if the (<i>x</i>, <i>y</i>)
4728 * coordinate location is inside its bounding box, and <code>null</code>
4729 * otherwise.
4730 * @param x the <i>x</i> coordinate
4731 * @param y the <i>y</i> coordinate
4732 * @return the component or subcomponent that contains the
4733 * (<i>x</i>, <i>y</i>) location;
4734 * <code>null</code> if the location
4735 * is outside this component
4736 * @see #contains(int, int)
4737 * @since JDK1.0
4738 */
4739 public Component getComponentAt(int x, int y) {
4740 return locate(x, y);
4741 }
4742
4743 /**
4744 * @param x the <i>x</i> coordinate to search for components at
4745 * @param y the <i>y</i> coordinate to search for components at
4746 * @return the component at the specified location or {@code null}
4747 * @deprecated As of JDK version 1.1,
4748 * replaced by getComponentAt(int, int).
4749 */
4750 @Deprecated
4751 public Component locate(int x, int y) {
4752 return contains(x, y) ? this : null;
4753 }
4754
4755 /**
4756 * Returns the component or subcomponent that contains the
4757 * specified point.
4758 * @param p the point
4759 * @return the component at the specified location or {@code null}
4760 * @see java.awt.Component#contains
4761 * @since JDK1.1
4762 */
4763 public Component getComponentAt(Point p) {
4764 return getComponentAt(p.x, p.y);
4765 }
4766
4767 /**
4768 * @param e the event to deliver
4769 * @deprecated As of JDK version 1.1,
4770 * replaced by <code>dispatchEvent(AWTEvent e)</code>.
4771 */
4772 @Deprecated
4773 public void deliverEvent(Event e) {
4774 postEvent(e);
4775 }
4776
4777 /**
4778 * Dispatches an event to this component or one of its sub components.
4779 * Calls <code>processEvent</code> before returning for 1.1-style
4780 * events which have been enabled for the <code>Component</code>.
4781 * @param e the event
4782 */
4783 public final void dispatchEvent(AWTEvent e) {
4784 dispatchEventImpl(e);
4785 }
4786
4787 @SuppressWarnings("deprecation")
4788 void dispatchEventImpl(AWTEvent e) {
6799 * @see #addHierarchyBoundsListener
6800 * @see #enableEvents
6801 * @since 1.3
6802 */
6803 protected void processHierarchyBoundsEvent(HierarchyEvent e) {
6804 HierarchyBoundsListener listener = hierarchyBoundsListener;
6805 if (listener != null) {
6806 int id = e.getID();
6807 switch (id) {
6808 case HierarchyEvent.ANCESTOR_MOVED:
6809 listener.ancestorMoved(e);
6810 break;
6811 case HierarchyEvent.ANCESTOR_RESIZED:
6812 listener.ancestorResized(e);
6813 break;
6814 }
6815 }
6816 }
6817
6818 /**
6819 * @param evt the event to handle
6820 * @return {@code true} if the event was handled, {@code false} otherwise
6821 * @deprecated As of JDK version 1.1
6822 * replaced by processEvent(AWTEvent).
6823 */
6824 @Deprecated
6825 public boolean handleEvent(Event evt) {
6826 switch (evt.id) {
6827 case Event.MOUSE_ENTER:
6828 return mouseEnter(evt, evt.x, evt.y);
6829
6830 case Event.MOUSE_EXIT:
6831 return mouseExit(evt, evt.x, evt.y);
6832
6833 case Event.MOUSE_MOVE:
6834 return mouseMove(evt, evt.x, evt.y);
6835
6836 case Event.MOUSE_DOWN:
6837 return mouseDown(evt, evt.x, evt.y);
6838
6839 case Event.MOUSE_DRAG:
6840 return mouseDrag(evt, evt.x, evt.y);
6844
6845 case Event.KEY_PRESS:
6846 case Event.KEY_ACTION:
6847 return keyDown(evt, evt.key);
6848
6849 case Event.KEY_RELEASE:
6850 case Event.KEY_ACTION_RELEASE:
6851 return keyUp(evt, evt.key);
6852
6853 case Event.ACTION_EVENT:
6854 return action(evt, evt.arg);
6855 case Event.GOT_FOCUS:
6856 return gotFocus(evt, evt.arg);
6857 case Event.LOST_FOCUS:
6858 return lostFocus(evt, evt.arg);
6859 }
6860 return false;
6861 }
6862
6863 /**
6864 * @param evt the event to handle
6865 * @param x the x coordinate
6866 * @param y the y coordinate
6867 * @return {@code false}
6868 * @deprecated As of JDK version 1.1,
6869 * replaced by processMouseEvent(MouseEvent).
6870 */
6871 @Deprecated
6872 public boolean mouseDown(Event evt, int x, int y) {
6873 return false;
6874 }
6875
6876 /**
6877 * @param evt the event to handle
6878 * @param x the x coordinate
6879 * @param y the y coordinate
6880 * @return {@code false}
6881 * @deprecated As of JDK version 1.1,
6882 * replaced by processMouseMotionEvent(MouseEvent).
6883 */
6884 @Deprecated
6885 public boolean mouseDrag(Event evt, int x, int y) {
6886 return false;
6887 }
6888
6889 /**
6890 * @param evt the event to handle
6891 * @param x the x coordinate
6892 * @param y the y coordinate
6893 * @return {@code false}
6894 * @deprecated As of JDK version 1.1,
6895 * replaced by processMouseEvent(MouseEvent).
6896 */
6897 @Deprecated
6898 public boolean mouseUp(Event evt, int x, int y) {
6899 return false;
6900 }
6901
6902 /**
6903 * @param evt the event to handle
6904 * @param x the x coordinate
6905 * @param y the y coordinate
6906 * @return {@code false}
6907 * @deprecated As of JDK version 1.1,
6908 * replaced by processMouseMotionEvent(MouseEvent).
6909 */
6910 @Deprecated
6911 public boolean mouseMove(Event evt, int x, int y) {
6912 return false;
6913 }
6914
6915 /**
6916 * @param evt the event to handle
6917 * @param x the x coordinate
6918 * @param y the y coordinate
6919 * @return {@code false}
6920 * @deprecated As of JDK version 1.1,
6921 * replaced by processMouseEvent(MouseEvent).
6922 */
6923 @Deprecated
6924 public boolean mouseEnter(Event evt, int x, int y) {
6925 return false;
6926 }
6927
6928 /**
6929 * @param evt the event to handle
6930 * @param x the x coordinate
6931 * @param y the y coordinate
6932 * @return {@code false}
6933 * @deprecated As of JDK version 1.1,
6934 * replaced by processMouseEvent(MouseEvent).
6935 */
6936 @Deprecated
6937 public boolean mouseExit(Event evt, int x, int y) {
6938 return false;
6939 }
6940
6941 /**
6942 * @param evt the event to handle
6943 * @param key the key pressed
6944 * @return {@code false}
6945 * @deprecated As of JDK version 1.1,
6946 * replaced by processKeyEvent(KeyEvent).
6947 */
6948 @Deprecated
6949 public boolean keyDown(Event evt, int key) {
6950 return false;
6951 }
6952
6953 /**
6954 * @param evt the event to handle
6955 * @param key the key pressed
6956 * @return {@code false}
6957 * @deprecated As of JDK version 1.1,
6958 * replaced by processKeyEvent(KeyEvent).
6959 */
6960 @Deprecated
6961 public boolean keyUp(Event evt, int key) {
6962 return false;
6963 }
6964
6965 /**
6966 * @param evt the event to handle
6967 * @param what the object acted on
6968 * @return {@code false}
6969 * @deprecated As of JDK version 1.1,
6970 * should register this component as ActionListener on component
6971 * which fires action events.
6972 */
6973 @Deprecated
6974 public boolean action(Event evt, Object what) {
6975 return false;
6976 }
6977
6978 /**
6979 * Makes this <code>Component</code> displayable by connecting it to a
6980 * native screen resource.
6981 * This method is called internally by the toolkit and should
6982 * not be called directly by programs.
6983 * <p>
6984 * This method changes layout-related information, and therefore,
6985 * invalidates the component hierarchy.
6986 *
6987 * @see #isDisplayable
6988 * @see #removeNotify
7158 // (or has no shape at all).
7159 this.compoundShape = null;
7160 }
7161
7162 if (hierarchyListener != null ||
7163 (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 ||
7164 Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)) {
7165 HierarchyEvent e =
7166 new HierarchyEvent(this, HierarchyEvent.HIERARCHY_CHANGED,
7167 this, parent,
7168 HierarchyEvent.DISPLAYABILITY_CHANGED |
7169 ((isRecursivelyVisible())
7170 ? HierarchyEvent.SHOWING_CHANGED
7171 : 0));
7172 dispatchEvent(e);
7173 }
7174 }
7175 }
7176
7177 /**
7178 * @param evt the event to handle
7179 * @param what the object focused
7180 * @return {@code false}
7181 * @deprecated As of JDK version 1.1,
7182 * replaced by processFocusEvent(FocusEvent).
7183 */
7184 @Deprecated
7185 public boolean gotFocus(Event evt, Object what) {
7186 return false;
7187 }
7188
7189 /**
7190 * @param evt the event to handle
7191 * @param what the object focused
7192 * @return {@code false}
7193 * @deprecated As of JDK version 1.1,
7194 * replaced by processFocusEvent(FocusEvent).
7195 */
7196 @Deprecated
7197 public boolean lostFocus(Event evt, Object what) {
7198 return false;
7199 }
7200
7201 /**
7202 * Returns whether this <code>Component</code> can become the focus
7203 * owner.
7204 *
7205 * @return <code>true</code> if this <code>Component</code> is
7206 * focusable; <code>false</code> otherwise
7207 * @see #setFocusable
7208 * @since JDK1.1
7209 * @deprecated As of 1.4, replaced by <code>isFocusable()</code>.
7210 */
7211 @Deprecated
7212 public boolean isFocusTraversable() {
8484 *
8485 * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
8486 * @see #getPropertyChangeListeners(java.lang.String)
8487 * @see #removePropertyChangeListener(java.beans.PropertyChangeListener)
8488 */
8489 public void removePropertyChangeListener(
8490 String propertyName,
8491 PropertyChangeListener listener) {
8492 synchronized (getObjectLock()) {
8493 if (listener == null || changeSupport == null) {
8494 return;
8495 }
8496 changeSupport.removePropertyChangeListener(propertyName, listener);
8497 }
8498 }
8499
8500 /**
8501 * Returns an array of all the listeners which have been associated
8502 * with the named property.
8503 *
8504 * @param propertyName the property name
8505 *
8506 * @return all of the <code>PropertyChangeListener</code>s associated with
8507 * the named property; if no such listeners have been added or
8508 * if <code>propertyName</code> is <code>null</code>, an empty
8509 * array is returned
8510 *
8511 * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
8512 * @see #removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
8513 * @see #getPropertyChangeListeners
8514 * @since 1.4
8515 */
8516 public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
8517 synchronized (getObjectLock()) {
8518 if (changeSupport == null) {
8519 return new PropertyChangeListener[0];
8520 }
8521 return changeSupport.getPropertyChangeListeners(propertyName);
8522 }
8523 }
8524
8525 /**
8526 * Support for reporting bound property changes for Object properties.
8527 * This method can be called when a bound property has changed and it will
8528 * send the appropriate PropertyChangeEvent to any registered
8529 * PropertyChangeListeners.
8530 *
8531 * @param propertyName the property whose value has changed
8532 * @param oldValue the property's previous value
8533 * @param newValue the property's new value
8534 */
8535 protected void firePropertyChange(String propertyName,
8536 Object oldValue, Object newValue) {
8974 * Sets the language-sensitive orientation that is to be used to order
8975 * the elements or text within this component. Language-sensitive
8976 * <code>LayoutManager</code> and <code>Component</code>
8977 * subclasses will use this property to
8978 * determine how to lay out and draw components.
8979 * <p>
8980 * At construction time, a component's orientation is set to
8981 * <code>ComponentOrientation.UNKNOWN</code>,
8982 * indicating that it has not been specified
8983 * explicitly. The UNKNOWN orientation behaves the same as
8984 * <code>ComponentOrientation.LEFT_TO_RIGHT</code>.
8985 * <p>
8986 * To set the orientation of a single component, use this method.
8987 * To set the orientation of an entire component
8988 * hierarchy, use
8989 * {@link #applyComponentOrientation applyComponentOrientation}.
8990 * <p>
8991 * This method changes layout-related information, and therefore,
8992 * invalidates the component hierarchy.
8993 *
8994 * @param o the orientation to be set
8995 *
8996 *
8997 * @see ComponentOrientation
8998 * @see #invalidate
8999 *
9000 * @author Laura Werner, IBM
9001 * @beaninfo
9002 * bound: true
9003 */
9004 public void setComponentOrientation(ComponentOrientation o) {
9005 ComponentOrientation oldValue = componentOrientation;
9006 componentOrientation = o;
9007
9008 // This is a bound property, so report the change to
9009 // any registered listeners. (Cheap if there are none.)
9010 firePropertyChange("componentOrientation", oldValue, o);
9011
9012 // This could change the preferred size of the Component.
9013 invalidateIfValid();
9014 }
9015
9016 /**
9017 * Retrieves the language-sensitive orientation that is to be used to order
9018 * the elements or text within this component. <code>LayoutManager</code>
9019 * and <code>Component</code>
9020 * subclasses that wish to respect orientation should call this method to
9021 * get the component's orientation before performing layout or drawing.
9022 *
9023 * @return the orientation to order the elements or text
9024 * @see ComponentOrientation
9025 *
9026 * @author Laura Werner, IBM
9027 */
9028 public ComponentOrientation getComponentOrientation() {
9029 return componentOrientation;
9030 }
9031
9032 /**
9033 * Sets the <code>ComponentOrientation</code> property of this component
9034 * and all components contained within it.
9035 * <p>
9036 * This method changes layout-related information, and therefore,
9037 * invalidates the component hierarchy.
9038 *
9039 *
9040 * @param orientation the new component orientation of this component and
9041 * the components contained within it.
9042 * @exception NullPointerException if <code>orientation</code> is null.
9043 * @see #setComponentOrientation
9161 */
9162 protected abstract class AccessibleAWTComponent extends AccessibleContext
9163 implements Serializable, AccessibleComponent {
9164
9165 private static final long serialVersionUID = 642321655757800191L;
9166
9167 /**
9168 * Though the class is abstract, this should be called by
9169 * all sub-classes.
9170 */
9171 protected AccessibleAWTComponent() {
9172 }
9173
9174 /**
9175 * Number of PropertyChangeListener objects registered. It's used
9176 * to add/remove ComponentListener and FocusListener to track
9177 * target Component's state.
9178 */
9179 private volatile transient int propertyListenersCount = 0;
9180
9181 /**
9182 * A component listener to track show/hide/resize events
9183 * and convert them to PropertyChange events.
9184 */
9185 protected ComponentListener accessibleAWTComponentHandler = null;
9186
9187 /**
9188 * A listener to track focus events
9189 * and convert them to PropertyChange events.
9190 */
9191 protected FocusListener accessibleAWTFocusHandler = null;
9192
9193 /**
9194 * Fire PropertyChange listener, if one is registered,
9195 * when shown/hidden..
9196 * @since 1.3
9197 */
9198 protected class AccessibleAWTComponentHandler implements ComponentListener {
9199 public void componentHidden(ComponentEvent e) {
9200 if (accessibleContext != null) {
9201 accessibleContext.firePropertyChange(
9202 AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
9203 AccessibleState.VISIBLE, null);
9204 }
9205 }
9206
9207 public void componentShown(ComponentEvent e) {
9208 if (accessibleContext != null) {
9209 accessibleContext.firePropertyChange(
9210 AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
|