src/java.desktop/share/classes/java/awt/Component.java

Print this page




1068     Container getContainer() {
1069         return getParent_NoClientCode();
1070     }
1071 
1072     /**
1073      * Associate a <code>DropTarget</code> with this component.
1074      * The <code>Component</code> will receive drops only if it
1075      * is enabled.
1076      *
1077      * @see #isEnabled
1078      * @param dt The DropTarget
1079      */
1080 
1081     public synchronized void setDropTarget(DropTarget dt) {
1082         if (dt == dropTarget || (dropTarget != null && dropTarget.equals(dt)))
1083             return;
1084 
1085         DropTarget old;
1086 
1087         if ((old = dropTarget) != null) {
1088             if (peer != null) dropTarget.removeNotify(peer);
1089 
1090             DropTarget t = dropTarget;
1091 
1092             dropTarget = null;
1093 
1094             try {
1095                 t.setComponent(null);
1096             } catch (IllegalArgumentException iae) {
1097                 // ignore it.
1098             }
1099         }
1100 
1101         // if we have a new one, and we have a peer, add it!
1102 
1103         if ((dropTarget = dt) != null) {
1104             try {
1105                 dropTarget.setComponent(this);
1106                 if (peer != null) dropTarget.addNotify(peer);
1107             } catch (IllegalArgumentException iae) {
1108                 if (old != null) {
1109                     try {
1110                         old.setComponent(this);
1111                         if (peer != null) dropTarget.addNotify(peer);
1112                     } catch (IllegalArgumentException iae1) {
1113                         // ignore it!
1114                     }
1115                 }
1116             }
1117         }
1118     }
1119 
1120     /**
1121      * Gets the <code>DropTarget</code> associated with this
1122      * <code>Component</code>.
1123      *
1124      * @return the drop target
1125      */
1126 
1127     public synchronized DropTarget getDropTarget() { return dropTarget; }
1128 
1129     /**
1130      * Gets the <code>GraphicsConfiguration</code> associated with this
1131      * <code>Component</code>.


6990             } else {
6991                 // It's native. If the parent is lightweight it will need some
6992                 // help.
6993                 Container parent = getContainer();
6994                 if (parent != null && parent.isLightweight()) {
6995                     relocateComponent();
6996                     if (!parent.isRecursivelyVisibleUpToHeavyweightContainer())
6997                     {
6998                         peer.setVisible(false);
6999                     }
7000                 }
7001             }
7002             invalidate();
7003 
7004             int npopups = (popups != null? popups.size() : 0);
7005             for (int i = 0 ; i < npopups ; i++) {
7006                 PopupMenu popup = popups.elementAt(i);
7007                 popup.addNotify();
7008             }
7009 
7010             if (dropTarget != null) dropTarget.addNotify(peer);
7011 
7012             peerFont = getFont();
7013 
7014             if (getContainer() != null && !isAddNotifyComplete) {
7015                 getContainer().increaseComponentCount(this);
7016             }
7017 
7018 
7019             // Update stacking order
7020             updateZOrder();
7021 
7022             if (!isAddNotifyComplete) {
7023                 mixOnShowing();
7024             }
7025 
7026             isAddNotifyComplete = true;
7027 
7028             if (hierarchyListener != null ||
7029                 (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 ||
7030                 Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)) {


7077                 popup.removeNotify();
7078             }
7079             // If there is any input context for this component, notify
7080             // that this component is being removed. (This has to be done
7081             // before hiding peer.)
7082             if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) {
7083                 InputContext inputContext = getInputContext();
7084                 if (inputContext != null) {
7085                     inputContext.removeNotify(this);
7086                 }
7087             }
7088 
7089             ComponentPeer p = peer;
7090             if (p != null) {
7091                 boolean isLightweight = isLightweight();
7092 
7093                 if (bufferStrategy instanceof FlipBufferStrategy) {
7094                     ((FlipBufferStrategy)bufferStrategy).destroyBuffers();
7095                 }
7096 
7097                 if (dropTarget != null) dropTarget.removeNotify(peer);
7098 
7099                 // Hide peer first to stop system events such as cursor moves.
7100                 if (visible) {
7101                     p.setVisible(false);
7102                 }
7103 
7104                 peer = null; // Stop peer updates.
7105                 peerFont = null;
7106 
7107                 Toolkit.getEventQueue().removeSourceEvents(this, false);
7108                 KeyboardFocusManager.getCurrentKeyboardFocusManager().
7109                     discardKeyEvents(this);
7110 
7111                 p.dispose();
7112 
7113                 mixOnHiding(isLightweight);
7114 
7115                 isAddNotifyComplete = false;
7116                 // Nullifying compoundShape means that the component has normal shape
7117                 // (or has no shape at all).




1068     Container getContainer() {
1069         return getParent_NoClientCode();
1070     }
1071 
1072     /**
1073      * Associate a <code>DropTarget</code> with this component.
1074      * The <code>Component</code> will receive drops only if it
1075      * is enabled.
1076      *
1077      * @see #isEnabled
1078      * @param dt The DropTarget
1079      */
1080 
1081     public synchronized void setDropTarget(DropTarget dt) {
1082         if (dt == dropTarget || (dropTarget != null && dropTarget.equals(dt)))
1083             return;
1084 
1085         DropTarget old;
1086 
1087         if ((old = dropTarget) != null) {
1088             dropTarget.removeNotify();
1089 
1090             DropTarget t = dropTarget;
1091 
1092             dropTarget = null;
1093 
1094             try {
1095                 t.setComponent(null);
1096             } catch (IllegalArgumentException iae) {
1097                 // ignore it.
1098             }
1099         }
1100 
1101         // if we have a new one, and we have a peer, add it!
1102 
1103         if ((dropTarget = dt) != null) {
1104             try {
1105                 dropTarget.setComponent(this);
1106                 dropTarget.addNotify();
1107             } catch (IllegalArgumentException iae) {
1108                 if (old != null) {
1109                     try {
1110                         old.setComponent(this);
1111                         dropTarget.addNotify();
1112                     } catch (IllegalArgumentException iae1) {
1113                         // ignore it!
1114                     }
1115                 }
1116             }
1117         }
1118     }
1119 
1120     /**
1121      * Gets the <code>DropTarget</code> associated with this
1122      * <code>Component</code>.
1123      *
1124      * @return the drop target
1125      */
1126 
1127     public synchronized DropTarget getDropTarget() { return dropTarget; }
1128 
1129     /**
1130      * Gets the <code>GraphicsConfiguration</code> associated with this
1131      * <code>Component</code>.


6990             } else {
6991                 // It's native. If the parent is lightweight it will need some
6992                 // help.
6993                 Container parent = getContainer();
6994                 if (parent != null && parent.isLightweight()) {
6995                     relocateComponent();
6996                     if (!parent.isRecursivelyVisibleUpToHeavyweightContainer())
6997                     {
6998                         peer.setVisible(false);
6999                     }
7000                 }
7001             }
7002             invalidate();
7003 
7004             int npopups = (popups != null? popups.size() : 0);
7005             for (int i = 0 ; i < npopups ; i++) {
7006                 PopupMenu popup = popups.elementAt(i);
7007                 popup.addNotify();
7008             }
7009 
7010             if (dropTarget != null) dropTarget.addNotify();
7011 
7012             peerFont = getFont();
7013 
7014             if (getContainer() != null && !isAddNotifyComplete) {
7015                 getContainer().increaseComponentCount(this);
7016             }
7017 
7018 
7019             // Update stacking order
7020             updateZOrder();
7021 
7022             if (!isAddNotifyComplete) {
7023                 mixOnShowing();
7024             }
7025 
7026             isAddNotifyComplete = true;
7027 
7028             if (hierarchyListener != null ||
7029                 (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 ||
7030                 Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)) {


7077                 popup.removeNotify();
7078             }
7079             // If there is any input context for this component, notify
7080             // that this component is being removed. (This has to be done
7081             // before hiding peer.)
7082             if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) {
7083                 InputContext inputContext = getInputContext();
7084                 if (inputContext != null) {
7085                     inputContext.removeNotify(this);
7086                 }
7087             }
7088 
7089             ComponentPeer p = peer;
7090             if (p != null) {
7091                 boolean isLightweight = isLightweight();
7092 
7093                 if (bufferStrategy instanceof FlipBufferStrategy) {
7094                     ((FlipBufferStrategy)bufferStrategy).destroyBuffers();
7095                 }
7096 
7097                 if (dropTarget != null) dropTarget.removeNotify();
7098 
7099                 // Hide peer first to stop system events such as cursor moves.
7100                 if (visible) {
7101                     p.setVisible(false);
7102                 }
7103 
7104                 peer = null; // Stop peer updates.
7105                 peerFont = null;
7106 
7107                 Toolkit.getEventQueue().removeSourceEvents(this, false);
7108                 KeyboardFocusManager.getCurrentKeyboardFocusManager().
7109                     discardKeyEvents(this);
7110 
7111                 p.dispose();
7112 
7113                 mixOnHiding(isLightweight);
7114 
7115                 isAddNotifyComplete = false;
7116                 // Nullifying compoundShape means that the component has normal shape
7117                 // (or has no shape at all).