1 /*
2 * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
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
1689 void clearCurrentFocusCycleRootOnHide() {
1690 /* do nothing */
1691 }
1692
1693 /*
1694 * Delete references from LightweightDispatcher of a heavyweight parent
1695 */
1696 void clearLightweightDispatcherOnRemove(Component removedComponent) {
1697 if (parent != null) {
1698 parent.clearLightweightDispatcherOnRemove(removedComponent);
1699 }
1700 }
1701
1702 /**
1703 * @deprecated As of JDK version 1.1,
1704 * replaced by <code>setVisible(boolean)</code>.
1705 */
1706 @Deprecated
1707 public void hide() {
1708 isPacked = false;
1709
1710 if (visible) {
1711 clearCurrentFocusCycleRootOnHide();
1712 clearMostRecentFocusOwnerOnHide();
1713 synchronized (getTreeLock()) {
1714 visible = false;
1715 mixOnHiding(isLightweight());
1716 if (containsFocus() && KeyboardFocusManager.isAutoFocusTransferEnabled()) {
1717 transferFocus(true);
1718 }
1719 ComponentPeer peer = this.peer;
1720 if (peer != null) {
1721 peer.setVisible(false);
6225 public Boolean run() {
6226 return isCoalesceEventsOverriden(clazz);
6227 }
6228 }
6229 );
6230 coalesceMap.put(clazz, enabled);
6231 return enabled;
6232 }
6233 }
6234
6235 /**
6236 * Parameter types of coalesceEvents(AWTEvent,AWTEVent).
6237 */
6238 private static final Class<?>[] coalesceEventsParams = {
6239 AWTEvent.class, AWTEvent.class
6240 };
6241
6242 /**
6243 * Indicates whether a class or its superclasses override coalesceEvents.
6244 * Must be called with lock on coalesceMap and privileged.
6245 * @see checkCoalsecing
6246 */
6247 private static boolean isCoalesceEventsOverriden(Class<?> clazz) {
6248 assert Thread.holdsLock(coalesceMap);
6249
6250 // First check superclass - we may not need to bother ourselves.
6251 Class<?> superclass = clazz.getSuperclass();
6252 if (superclass == null) {
6253 // Only occurs on implementations that
6254 // do not use null to represent the bootstrap class loader.
6255 return false;
6256 }
6257 if (superclass.getClassLoader() != null) {
6258 Boolean value = coalesceMap.get(superclass);
6259 if (value == null) {
6260 // Not done already - recurse.
6261 if (isCoalesceEventsOverriden(superclass)) {
6262 coalesceMap.put(superclass, true);
6263 return true;
6264 }
6265 } else if (value) {
7066 * <p>
7067 * This method is called by the toolkit internally and should
7068 * not be called directly by programs. Code overriding
7069 * this method should call <code>super.removeNotify</code> as
7070 * the first line of the overriding method.
7071 *
7072 * @see #isDisplayable
7073 * @see #addNotify
7074 * @since 1.0
7075 */
7076 public void removeNotify() {
7077 KeyboardFocusManager.clearMostRecentFocusOwner(this);
7078 if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
7079 getPermanentFocusOwner() == this)
7080 {
7081 KeyboardFocusManager.getCurrentKeyboardFocusManager().
7082 setGlobalPermanentFocusOwner(null);
7083 }
7084
7085 synchronized (getTreeLock()) {
7086 clearLightweightDispatcherOnRemove(this);
7087
7088 if (isFocusOwner() && KeyboardFocusManager.isAutoFocusTransferEnabledFor(this)) {
7089 transferFocus(true);
7090 }
7091
7092 if (getContainer() != null && isAddNotifyComplete) {
7093 getContainer().decreaseComponentCount(this);
7094 }
7095
7096 int npopups = (popups != null? popups.size() : 0);
7097 for (int i = 0 ; i < npopups ; i++) {
7098 PopupMenu popup = popups.elementAt(i);
7099 popup.removeNotify();
7100 }
7101 // If there is any input context for this component, notify
7102 // that this component is being removed. (This has to be done
7103 // before hiding peer.)
7104 if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) {
7105 InputContext inputContext = getInputContext();
7106 if (inputContext != null) {
7107 inputContext.removeNotify(this);
|
1 /*
2 * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
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
1689 void clearCurrentFocusCycleRootOnHide() {
1690 /* do nothing */
1691 }
1692
1693 /**
1694 * @deprecated As of JDK version 1.1,
1695 * replaced by <code>setVisible(boolean)</code>.
1696 */
1697 @Deprecated
1698 public void hide() {
1699 isPacked = false;
1700
1701 if (visible) {
1702 clearCurrentFocusCycleRootOnHide();
1703 clearMostRecentFocusOwnerOnHide();
1704 synchronized (getTreeLock()) {
1705 visible = false;
1706 mixOnHiding(isLightweight());
1707 if (containsFocus() && KeyboardFocusManager.isAutoFocusTransferEnabled()) {
1708 transferFocus(true);
1709 }
1710 ComponentPeer peer = this.peer;
1711 if (peer != null) {
1712 peer.setVisible(false);
6216 public Boolean run() {
6217 return isCoalesceEventsOverriden(clazz);
6218 }
6219 }
6220 );
6221 coalesceMap.put(clazz, enabled);
6222 return enabled;
6223 }
6224 }
6225
6226 /**
6227 * Parameter types of coalesceEvents(AWTEvent,AWTEVent).
6228 */
6229 private static final Class<?>[] coalesceEventsParams = {
6230 AWTEvent.class, AWTEvent.class
6231 };
6232
6233 /**
6234 * Indicates whether a class or its superclasses override coalesceEvents.
6235 * Must be called with lock on coalesceMap and privileged.
6236 * @see checkCoalescing
6237 */
6238 private static boolean isCoalesceEventsOverriden(Class<?> clazz) {
6239 assert Thread.holdsLock(coalesceMap);
6240
6241 // First check superclass - we may not need to bother ourselves.
6242 Class<?> superclass = clazz.getSuperclass();
6243 if (superclass == null) {
6244 // Only occurs on implementations that
6245 // do not use null to represent the bootstrap class loader.
6246 return false;
6247 }
6248 if (superclass.getClassLoader() != null) {
6249 Boolean value = coalesceMap.get(superclass);
6250 if (value == null) {
6251 // Not done already - recurse.
6252 if (isCoalesceEventsOverriden(superclass)) {
6253 coalesceMap.put(superclass, true);
6254 return true;
6255 }
6256 } else if (value) {
7057 * <p>
7058 * This method is called by the toolkit internally and should
7059 * not be called directly by programs. Code overriding
7060 * this method should call <code>super.removeNotify</code> as
7061 * the first line of the overriding method.
7062 *
7063 * @see #isDisplayable
7064 * @see #addNotify
7065 * @since 1.0
7066 */
7067 public void removeNotify() {
7068 KeyboardFocusManager.clearMostRecentFocusOwner(this);
7069 if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
7070 getPermanentFocusOwner() == this)
7071 {
7072 KeyboardFocusManager.getCurrentKeyboardFocusManager().
7073 setGlobalPermanentFocusOwner(null);
7074 }
7075
7076 synchronized (getTreeLock()) {
7077 if (isFocusOwner() && KeyboardFocusManager.isAutoFocusTransferEnabledFor(this)) {
7078 transferFocus(true);
7079 }
7080
7081 if (getContainer() != null && isAddNotifyComplete) {
7082 getContainer().decreaseComponentCount(this);
7083 }
7084
7085 int npopups = (popups != null? popups.size() : 0);
7086 for (int i = 0 ; i < npopups ; i++) {
7087 PopupMenu popup = popups.elementAt(i);
7088 popup.removeNotify();
7089 }
7090 // If there is any input context for this component, notify
7091 // that this component is being removed. (This has to be done
7092 // before hiding peer.)
7093 if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) {
7094 InputContext inputContext = getInputContext();
7095 if (inputContext != null) {
7096 inputContext.removeNotify(this);
|