equal
deleted
inserted
replaced
196 * behavior. The peer is set when the <code>Component</code> is |
196 * behavior. The peer is set when the <code>Component</code> is |
197 * added to a container that also is a peer. |
197 * added to a container that also is a peer. |
198 * @see #addNotify |
198 * @see #addNotify |
199 * @see #removeNotify |
199 * @see #removeNotify |
200 */ |
200 */ |
201 transient ComponentPeer peer; |
201 transient volatile ComponentPeer peer; |
202 |
202 |
203 /** |
203 /** |
204 * The parent of the object. It may be <code>null</code> |
204 * The parent of the object. It may be <code>null</code> |
205 * for top-level components. |
205 * for top-level components. |
206 * @see #getParent |
206 * @see #getParent |
922 return comp.peer != null; |
922 return comp.peer != null; |
923 } |
923 } |
924 public Cursor getCursor(Component comp) { |
924 public Cursor getCursor(Component comp) { |
925 return comp.getCursor_NoClientCode(); |
925 return comp.getCursor_NoClientCode(); |
926 } |
926 } |
927 public ComponentPeer getPeer(Component comp) { |
927 @SuppressWarnings("unchecked") |
928 return comp.peer; |
928 public <T extends ComponentPeer> T getPeer(Component comp) { |
|
929 return (T) comp.peer; |
929 } |
930 } |
930 public void setPeer(Component comp, ComponentPeer peer) { |
931 public void setPeer(Component comp, ComponentPeer peer) { |
931 comp.peer = peer; |
932 comp.peer = peer; |
932 } |
933 } |
933 public boolean isLightweight(Component comp) { |
934 public boolean isLightweight(Component comp) { |
1064 // This method is overridden in the Window class to return null, |
1065 // This method is overridden in the Window class to return null, |
1065 // because the parent field of the Window object contains |
1066 // because the parent field of the Window object contains |
1066 // the owner of the window, not its parent. |
1067 // the owner of the window, not its parent. |
1067 Container getContainer() { |
1068 Container getContainer() { |
1068 return getParent_NoClientCode(); |
1069 return getParent_NoClientCode(); |
1069 } |
|
1070 |
|
1071 /** |
|
1072 * @deprecated As of JDK version 1.1, |
|
1073 * programs should not directly manipulate peers; |
|
1074 * replaced by <code>boolean isDisplayable()</code>. |
|
1075 * @return the peer for this component |
|
1076 */ |
|
1077 @Deprecated |
|
1078 public ComponentPeer getPeer() { |
|
1079 return peer; |
|
1080 } |
1070 } |
1081 |
1071 |
1082 /** |
1072 /** |
1083 * Associate a <code>DropTarget</code> with this component. |
1073 * Associate a <code>DropTarget</code> with this component. |
1084 * The <code>Component</code> will receive drops only if it |
1074 * The <code>Component</code> will receive drops only if it |
1177 return false; |
1167 return false; |
1178 } |
1168 } |
1179 |
1169 |
1180 graphicsConfig = gc; |
1170 graphicsConfig = gc; |
1181 |
1171 |
1182 ComponentPeer peer = getPeer(); |
1172 ComponentPeer peer = this.peer; |
1183 if (peer != null) { |
1173 if (peer != null) { |
1184 return peer.updateGraphicsData(gc); |
1174 return peer.updateGraphicsData(gc); |
1185 } |
1175 } |
1186 return false; |
1176 return false; |
1187 } |
1177 } |
1279 * @see Container#remove(Component) |
1269 * @see Container#remove(Component) |
1280 * @see Window#dispose |
1270 * @see Window#dispose |
1281 * @since 1.2 |
1271 * @since 1.2 |
1282 */ |
1272 */ |
1283 public boolean isDisplayable() { |
1273 public boolean isDisplayable() { |
1284 return getPeer() != null; |
1274 return peer != null; |
1285 } |
1275 } |
1286 |
1276 |
1287 /** |
1277 /** |
1288 * Determines whether this component should be visible when its |
1278 * Determines whether this component should be visible when its |
1289 * parent is visible. Components are |
1279 * parent is visible. Components are |
2580 * @return true if this component is completely opaque |
2570 * @return true if this component is completely opaque |
2581 * @see #isLightweight |
2571 * @see #isLightweight |
2582 * @since 1.2 |
2572 * @since 1.2 |
2583 */ |
2573 */ |
2584 public boolean isOpaque() { |
2574 public boolean isOpaque() { |
2585 if (getPeer() == null) { |
2575 if (peer == null) { |
2586 return false; |
2576 return false; |
2587 } |
2577 } |
2588 else { |
2578 else { |
2589 return !isLightweight(); |
2579 return !isLightweight(); |
2590 } |
2580 } |
2606 * it has a native peer or no peer |
2596 * it has a native peer or no peer |
2607 * @see #isDisplayable |
2597 * @see #isDisplayable |
2608 * @since 1.2 |
2598 * @since 1.2 |
2609 */ |
2599 */ |
2610 public boolean isLightweight() { |
2600 public boolean isLightweight() { |
2611 return getPeer() instanceof LightweightPeer; |
2601 return peer instanceof LightweightPeer; |
2612 } |
2602 } |
2613 |
2603 |
2614 |
2604 |
2615 /** |
2605 /** |
2616 * Sets the preferred size of this component to a constant |
2606 * Sets the preferred size of this component to a constant |
3124 * {@link Font Font} class. |
3114 * {@link Font Font} class. |
3125 * @param font the font for which font metrics is to be |
3115 * @param font the font for which font metrics is to be |
3126 * obtained |
3116 * obtained |
3127 * @return the font metrics for <code>font</code> |
3117 * @return the font metrics for <code>font</code> |
3128 * @see #getFont |
3118 * @see #getFont |
3129 * @see #getPeer |
|
3130 * @see java.awt.peer.ComponentPeer#getFontMetrics(Font) |
3119 * @see java.awt.peer.ComponentPeer#getFontMetrics(Font) |
3131 * @see Toolkit#getFontMetrics(Font) |
3120 * @see Toolkit#getFontMetrics(Font) |
3132 * @since 1.0 |
3121 * @since 1.0 |
3133 */ |
3122 */ |
3134 public FontMetrics getFontMetrics(Font font) { |
3123 public FontMetrics getFontMetrics(Font font) { |
3184 if (peer instanceof LightweightPeer) { |
3173 if (peer instanceof LightweightPeer) { |
3185 Container nativeContainer = getNativeContainer(); |
3174 Container nativeContainer = getNativeContainer(); |
3186 |
3175 |
3187 if (nativeContainer == null) return; |
3176 if (nativeContainer == null) return; |
3188 |
3177 |
3189 ComponentPeer cPeer = nativeContainer.getPeer(); |
3178 ComponentPeer cPeer = nativeContainer.peer; |
3190 |
3179 |
3191 if (cPeer != null) { |
3180 if (cPeer != null) { |
3192 cPeer.updateCursorImmediately(); |
3181 cPeer.updateCursorImmediately(); |
3193 } |
3182 } |
3194 } else if (peer != null) { |
3183 } else if (peer != null) { |
5017 // processes event |
5006 // processes event |
5018 Component source = (Component)e.getSource(); |
5007 Component source = (Component)e.getSource(); |
5019 if (source != null) { |
5008 if (source != null) { |
5020 Container target = source.getNativeContainer(); |
5009 Container target = source.getNativeContainer(); |
5021 if (target != null) { |
5010 if (target != null) { |
5022 tpeer = target.getPeer(); |
5011 tpeer = target.peer; |
5023 } |
5012 } |
5024 } |
5013 } |
5025 } |
5014 } |
5026 if (tpeer != null) { |
5015 if (tpeer != null) { |
5027 tpeer.handleEvent(e); |
5016 tpeer.handleEvent(e); |
9849 } |
9838 } |
9850 return; |
9839 return; |
9851 } |
9840 } |
9852 |
9841 |
9853 if (!isLightweight()) { |
9842 if (!isLightweight()) { |
9854 ComponentPeer peer = getPeer(); |
9843 ComponentPeer peer = this.peer; |
9855 if (peer != null) { |
9844 if (peer != null) { |
9856 // The Region class has some optimizations. That's why |
9845 // The Region class has some optimizations. That's why |
9857 // we should manually check whether it's empty and |
9846 // we should manually check whether it's empty and |
9858 // substitute the object ourselves. Otherwise we end up |
9847 // substitute the object ourselves. Otherwise we end up |
9859 // with some incorrect Region object with loX being |
9848 // with some incorrect Region object with loX being |
9973 |
9962 |
9974 while (cont != null) { |
9963 while (cont != null) { |
9975 for (int i = indexAbove; i > -1; i--) { |
9964 for (int i = indexAbove; i > -1; i--) { |
9976 Component comp = cont.getComponent(i); |
9965 Component comp = cont.getComponent(i); |
9977 if (comp != null && comp.isDisplayable() && !comp.isLightweight()) { |
9966 if (comp != null && comp.isDisplayable() && !comp.isLightweight()) { |
9978 return comp.getPeer(); |
9967 return comp.peer; |
9979 } |
9968 } |
9980 } |
9969 } |
9981 // traversing the hierarchy up to the closest HW container; |
9970 // traversing the hierarchy up to the closest HW container; |
9982 // further traversing may return a component that is not actually |
9971 // further traversing may return a component that is not actually |
9983 // a native sibling of this component and this kind of z-order |
9972 // a native sibling of this component and this kind of z-order |