mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-27 02:30:06 +00:00
8378297: Remove AppContext from several Swing component and related classes
Reviewed-by: azvegint, psadhukhan, dnguyen
This commit is contained in:
parent
71a1af7d0b
commit
fcc2a2922f
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -1492,14 +1492,12 @@ public class DebugGraphics extends Graphics {
|
||||
/** Returns DebugGraphicsInfo, or creates one if none exists.
|
||||
*/
|
||||
static DebugGraphicsInfo info() {
|
||||
DebugGraphicsInfo debugGraphicsInfo = (DebugGraphicsInfo)
|
||||
SwingUtilities.appContextGet(debugGraphicsInfoKey);
|
||||
if (debugGraphicsInfo == null) {
|
||||
debugGraphicsInfo = new DebugGraphicsInfo();
|
||||
SwingUtilities.appContextPut(debugGraphicsInfoKey,
|
||||
debugGraphicsInfo);
|
||||
synchronized (DebugGraphicsInfo.class) {
|
||||
if (debugGraphicsInfo == null) {
|
||||
debugGraphicsInfo = new DebugGraphicsInfo();
|
||||
}
|
||||
return debugGraphicsInfo;
|
||||
}
|
||||
return debugGraphicsInfo;
|
||||
}
|
||||
private static final Class<DebugGraphicsInfo> debugGraphicsInfoKey = DebugGraphicsInfo.class;
|
||||
private static DebugGraphicsInfo debugGraphicsInfo;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -101,13 +101,6 @@ public class JDialog extends Dialog implements WindowConstants,
|
||||
RootPaneContainer,
|
||||
TransferHandler.HasGetTransferHandler
|
||||
{
|
||||
/**
|
||||
* Key into the AppContext, used to check if should provide decorations
|
||||
* by default.
|
||||
*/
|
||||
private static final Object defaultLookAndFeelDecoratedKey =
|
||||
new StringBuffer("JDialog.defaultLookAndFeelDecorated");
|
||||
|
||||
private int defaultCloseOperation = HIDE_ON_CLOSE;
|
||||
|
||||
/**
|
||||
@ -1119,6 +1112,8 @@ public class JDialog extends Dialog implements WindowConstants,
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean defaultLAFDecorated;
|
||||
|
||||
/**
|
||||
* Provides a hint as to whether or not newly created {@code JDialog}s
|
||||
* should have their Window decorations (such as borders, widgets to
|
||||
@ -1144,11 +1139,7 @@ public class JDialog extends Dialog implements WindowConstants,
|
||||
* @since 1.4
|
||||
*/
|
||||
public static void setDefaultLookAndFeelDecorated(boolean defaultLookAndFeelDecorated) {
|
||||
if (defaultLookAndFeelDecorated) {
|
||||
SwingUtilities.appContextPut(defaultLookAndFeelDecoratedKey, Boolean.TRUE);
|
||||
} else {
|
||||
SwingUtilities.appContextPut(defaultLookAndFeelDecoratedKey, Boolean.FALSE);
|
||||
}
|
||||
defaultLAFDecorated = defaultLookAndFeelDecorated;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1160,12 +1151,7 @@ public class JDialog extends Dialog implements WindowConstants,
|
||||
* @since 1.4
|
||||
*/
|
||||
public static boolean isDefaultLookAndFeelDecorated() {
|
||||
Boolean defaultLookAndFeelDecorated =
|
||||
(Boolean) SwingUtilities.appContextGet(defaultLookAndFeelDecoratedKey);
|
||||
if (defaultLookAndFeelDecorated == null) {
|
||||
defaultLookAndFeelDecorated = Boolean.FALSE;
|
||||
}
|
||||
return defaultLookAndFeelDecorated.booleanValue();
|
||||
return defaultLAFDecorated;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -126,13 +126,6 @@ public class JFrame extends Frame implements WindowConstants,
|
||||
RootPaneContainer,
|
||||
TransferHandler.HasGetTransferHandler
|
||||
{
|
||||
/**
|
||||
* Key into the AppContext, used to check if should provide decorations
|
||||
* by default.
|
||||
*/
|
||||
private static final Object defaultLookAndFeelDecoratedKey =
|
||||
new StringBuffer("JFrame.defaultLookAndFeelDecorated");
|
||||
|
||||
private int defaultCloseOperation = HIDE_ON_CLOSE;
|
||||
|
||||
/**
|
||||
@ -755,6 +748,8 @@ public class JFrame extends Frame implements WindowConstants,
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean defaultLAFDecorated;
|
||||
|
||||
/**
|
||||
* Provides a hint as to whether or not newly created <code>JFrame</code>s
|
||||
* should have their Window decorations (such as borders, widgets to
|
||||
@ -780,11 +775,7 @@ public class JFrame extends Frame implements WindowConstants,
|
||||
* @since 1.4
|
||||
*/
|
||||
public static void setDefaultLookAndFeelDecorated(boolean defaultLookAndFeelDecorated) {
|
||||
if (defaultLookAndFeelDecorated) {
|
||||
SwingUtilities.appContextPut(defaultLookAndFeelDecoratedKey, Boolean.TRUE);
|
||||
} else {
|
||||
SwingUtilities.appContextPut(defaultLookAndFeelDecoratedKey, Boolean.FALSE);
|
||||
}
|
||||
defaultLAFDecorated = defaultLookAndFeelDecorated;
|
||||
}
|
||||
|
||||
|
||||
@ -797,12 +788,7 @@ public class JFrame extends Frame implements WindowConstants,
|
||||
* @since 1.4
|
||||
*/
|
||||
public static boolean isDefaultLookAndFeelDecorated() {
|
||||
Boolean defaultLookAndFeelDecorated =
|
||||
(Boolean) SwingUtilities.appContextGet(defaultLookAndFeelDecoratedKey);
|
||||
if (defaultLookAndFeelDecorated == null) {
|
||||
defaultLookAndFeelDecorated = Boolean.FALSE;
|
||||
}
|
||||
return defaultLookAndFeelDecorated.booleanValue();
|
||||
return defaultLAFDecorated;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -112,12 +112,6 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
|
||||
*/
|
||||
private static final String uiClassID = "PopupMenuUI";
|
||||
|
||||
/**
|
||||
* Key used in AppContext to determine if light way popups are the default.
|
||||
*/
|
||||
private static final Object defaultLWPopupEnabledKey =
|
||||
new StringBuffer("JPopupMenu.defaultLWPopupEnabledKey");
|
||||
|
||||
/** Bug#4425878-Property javax.swing.adjustPopupLocationToFit introduced */
|
||||
static boolean popupPositionFixDisabled =
|
||||
System.getProperty("javax.swing.adjustPopupLocationToFit","").equals("false");
|
||||
@ -153,6 +147,8 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
|
||||
private static final boolean VERBOSE = false; // show reuse hits/misses
|
||||
private static final boolean DEBUG = false; // show bad params, misc.
|
||||
|
||||
private static boolean defaultLWPopupEnabled = true;
|
||||
|
||||
/**
|
||||
* Sets the default value of the <code>lightWeightPopupEnabled</code>
|
||||
* property.
|
||||
@ -163,8 +159,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
|
||||
* @see #setLightWeightPopupEnabled
|
||||
*/
|
||||
public static void setDefaultLightWeightPopupEnabled(boolean aFlag) {
|
||||
SwingUtilities.appContextPut(defaultLWPopupEnabledKey,
|
||||
Boolean.valueOf(aFlag));
|
||||
defaultLWPopupEnabled = aFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -177,14 +172,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
|
||||
* @see #setDefaultLightWeightPopupEnabled
|
||||
*/
|
||||
public static boolean getDefaultLightWeightPopupEnabled() {
|
||||
Boolean b = (Boolean)
|
||||
SwingUtilities.appContextGet(defaultLWPopupEnabledKey);
|
||||
if (b == null) {
|
||||
SwingUtilities.appContextPut(defaultLWPopupEnabledKey,
|
||||
Boolean.TRUE);
|
||||
return true;
|
||||
}
|
||||
return b.booleanValue();
|
||||
return defaultLWPopupEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -80,13 +80,6 @@ public class PopupFactory {
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* The shared instanceof <code>PopupFactory</code> is per
|
||||
* <code>AppContext</code>. This is the key used in the
|
||||
* <code>AppContext</code> to locate the <code>PopupFactory</code>.
|
||||
*/
|
||||
private static final Object SharedInstanceKey =
|
||||
new StringBuffer("PopupFactory.SharedInstanceKey");
|
||||
|
||||
/**
|
||||
* Max number of items to store in any one particular cache.
|
||||
@ -118,6 +111,7 @@ public class PopupFactory {
|
||||
*/
|
||||
public PopupFactory() {}
|
||||
|
||||
static PopupFactory sharedFactory;
|
||||
/**
|
||||
* Sets the <code>PopupFactory</code> that will be used to obtain
|
||||
* <code>Popup</code>s.
|
||||
@ -132,7 +126,9 @@ public class PopupFactory {
|
||||
if (factory == null) {
|
||||
throw new IllegalArgumentException("PopupFactory can not be null");
|
||||
}
|
||||
SwingUtilities.appContextPut(SharedInstanceKey, factory);
|
||||
synchronized (PopupFactory.class) {
|
||||
sharedFactory = factory;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,14 +138,12 @@ public class PopupFactory {
|
||||
* @return Shared PopupFactory
|
||||
*/
|
||||
public static PopupFactory getSharedInstance() {
|
||||
PopupFactory factory = (PopupFactory)SwingUtilities.appContextGet(
|
||||
SharedInstanceKey);
|
||||
|
||||
if (factory == null) {
|
||||
factory = new PopupFactory();
|
||||
setSharedInstance(factory);
|
||||
synchronized (PopupFactory.class) {
|
||||
if (sharedFactory == null) {
|
||||
sharedFactory = new PopupFactory();
|
||||
}
|
||||
return sharedFactory;
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
@ -351,8 +345,6 @@ public class PopupFactory {
|
||||
* Popup implementation that uses a Window as the popup.
|
||||
*/
|
||||
private static class HeavyWeightPopup extends Popup {
|
||||
private static final Object heavyWeightPopupCacheKey =
|
||||
new StringBuffer("PopupFactory.heavyWeightPopupCache");
|
||||
|
||||
private volatile boolean isCacheEnabled = true;
|
||||
|
||||
@ -434,21 +426,16 @@ public class PopupFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<Window, List<HeavyWeightPopup>> cache;
|
||||
/**
|
||||
* Returns the cache to use for heavy weight popups. Maps from
|
||||
* <code>Window</code> to a <code>List</code> of
|
||||
* <code>HeavyWeightPopup</code>s.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<Window, List<HeavyWeightPopup>> getHeavyWeightPopupCache() {
|
||||
synchronized (HeavyWeightPopup.class) {
|
||||
Map<Window, List<HeavyWeightPopup>> cache = (Map<Window, List<HeavyWeightPopup>>)SwingUtilities.appContextGet(
|
||||
heavyWeightPopupCacheKey);
|
||||
|
||||
if (cache == null) {
|
||||
cache = new HashMap<>(2);
|
||||
SwingUtilities.appContextPut(heavyWeightPopupCacheKey,
|
||||
cache);
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
@ -728,18 +715,17 @@ public class PopupFactory {
|
||||
return popup;
|
||||
}
|
||||
|
||||
private static List<LightWeightPopup> cache;
|
||||
/**
|
||||
* Returns the cache to use for heavy weight popups.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<LightWeightPopup> getLightWeightPopupCache() {
|
||||
List<LightWeightPopup> cache = (List<LightWeightPopup>)SwingUtilities.appContextGet(
|
||||
lightWeightPopupCacheKey);
|
||||
if (cache == null) {
|
||||
cache = new ArrayList<>();
|
||||
SwingUtilities.appContextPut(lightWeightPopupCacheKey, cache);
|
||||
synchronized (LightWeightPopup.class) {
|
||||
if (cache == null) {
|
||||
cache = new ArrayList<>();
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -849,8 +835,6 @@ public class PopupFactory {
|
||||
* Popup implementation that uses a Panel as the popup.
|
||||
*/
|
||||
private static class MediumWeightPopup extends ContainerPopup {
|
||||
private static final Object mediumWeightPopupCacheKey =
|
||||
new StringBuffer("PopupFactory.mediumPopupCache");
|
||||
|
||||
/** Child of the panel. The contents are added to this. */
|
||||
private JRootPane rootPane;
|
||||
@ -877,19 +861,18 @@ public class PopupFactory {
|
||||
return popup;
|
||||
}
|
||||
|
||||
private static List<MediumWeightPopup> cache;
|
||||
/**
|
||||
* Returns the cache to use for medium weight popups.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<MediumWeightPopup> getMediumWeightPopupCache() {
|
||||
List<MediumWeightPopup> cache = (List<MediumWeightPopup>)SwingUtilities.appContextGet(
|
||||
mediumWeightPopupCacheKey);
|
||||
|
||||
if (cache == null) {
|
||||
cache = new ArrayList<>();
|
||||
SwingUtilities.appContextPut(mediumWeightPopupCacheKey, cache);
|
||||
synchronized (MediumWeightPopup.class) {
|
||||
if (cache == null) {
|
||||
cache = new ArrayList<>();
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -1899,11 +1899,6 @@ public class SwingUtilities implements SwingConstants
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// Don't use String, as it's not guaranteed to be unique in a Hashtable.
|
||||
private static final Object sharedOwnerFrameKey =
|
||||
new StringBuffer("SwingUtilities.sharedOwnerFrame");
|
||||
|
||||
@SuppressWarnings("serial") // JDK-implementation class
|
||||
static class SharedOwnerFrame extends Frame implements WindowListener {
|
||||
public void addNotify() {
|
||||
@ -1961,6 +1956,7 @@ public class SwingUtilities implements SwingConstants
|
||||
}
|
||||
}
|
||||
|
||||
private static Frame sharedOwnerFrame;
|
||||
/**
|
||||
* Returns a toolkit-private, shared, invisible Frame
|
||||
* to be the owner for JDialogs and JWindows created with
|
||||
@ -1970,14 +1966,12 @@ public class SwingUtilities implements SwingConstants
|
||||
* @see java.awt.GraphicsEnvironment#isHeadless
|
||||
*/
|
||||
static Frame getSharedOwnerFrame() throws HeadlessException {
|
||||
Frame sharedOwnerFrame =
|
||||
(Frame)SwingUtilities.appContextGet(sharedOwnerFrameKey);
|
||||
if (sharedOwnerFrame == null) {
|
||||
sharedOwnerFrame = new SharedOwnerFrame();
|
||||
SwingUtilities.appContextPut(sharedOwnerFrameKey,
|
||||
sharedOwnerFrame);
|
||||
synchronized (SharedOwnerFrame.class) {
|
||||
if (sharedOwnerFrame == null) {
|
||||
sharedOwnerFrame = new SharedOwnerFrame();
|
||||
}
|
||||
return sharedOwnerFrame;
|
||||
}
|
||||
return sharedOwnerFrame;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -61,7 +61,6 @@ public final class ToolTipManager extends MouseAdapter implements MouseMotionLis
|
||||
JComponent insideComponent;
|
||||
MouseEvent mouseEvent;
|
||||
boolean showImmediately;
|
||||
private static final Object TOOL_TIP_MANAGER_KEY = new Object();
|
||||
transient Popup tipWindow;
|
||||
/** The Window tip is being displayed in. This will be non-null if
|
||||
* the Window tip is in differs from that of insideComponent's Window.
|
||||
@ -394,19 +393,19 @@ public final class ToolTipManager extends MouseAdapter implements MouseMotionLis
|
||||
}
|
||||
}
|
||||
|
||||
private static ToolTipManager manager;
|
||||
/**
|
||||
* Returns a shared <code>ToolTipManager</code> instance.
|
||||
*
|
||||
* @return a shared <code>ToolTipManager</code> object
|
||||
*/
|
||||
public static ToolTipManager sharedInstance() {
|
||||
Object value = SwingUtilities.appContextGet(TOOL_TIP_MANAGER_KEY);
|
||||
if (value instanceof ToolTipManager) {
|
||||
return (ToolTipManager) value;
|
||||
synchronized(ToolTipManager.class) {
|
||||
if (manager == null) {
|
||||
manager = new ToolTipManager();
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
ToolTipManager manager = new ToolTipManager();
|
||||
SwingUtilities.appContextPut(TOOL_TIP_MANAGER_KEY, manager);
|
||||
return manager;
|
||||
}
|
||||
|
||||
// add keylistener here to trigger tip for access
|
||||
|
||||
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6657026
|
||||
* @summary Tests shared ToolTipManager in different application contexts
|
||||
* @author Sergey Malenkov
|
||||
* @modules java.desktop/sun.awt
|
||||
*/
|
||||
|
||||
import sun.awt.SunToolkit;
|
||||
import javax.swing.ToolTipManager;
|
||||
|
||||
public class Test6657026 implements Runnable {
|
||||
|
||||
private static final int DISMISS = 4000;
|
||||
private static final int INITIAL = 750;
|
||||
private static final int RESHOW = 500;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
ToolTipManager manager = ToolTipManager.sharedInstance();
|
||||
if (DISMISS != manager.getDismissDelay()) {
|
||||
throw new Error("unexpected dismiss delay");
|
||||
}
|
||||
if (INITIAL != manager.getInitialDelay()) {
|
||||
throw new Error("unexpected initial delay");
|
||||
}
|
||||
if (RESHOW != manager.getReshowDelay()) {
|
||||
throw new Error("unexpected reshow delay");
|
||||
}
|
||||
manager.setDismissDelay(DISMISS + 1);
|
||||
manager.setInitialDelay(INITIAL + 1);
|
||||
manager.setReshowDelay(RESHOW + 1);
|
||||
|
||||
ThreadGroup group = new ThreadGroup("$$$");
|
||||
Thread thread = new Thread(group, new Test6657026());
|
||||
thread.start();
|
||||
thread.join();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
SunToolkit.createNewAppContext();
|
||||
ToolTipManager manager = ToolTipManager.sharedInstance();
|
||||
if (DISMISS != manager.getDismissDelay()) {
|
||||
throw new Error("shared dismiss delay");
|
||||
}
|
||||
if (INITIAL != manager.getInitialDelay()) {
|
||||
throw new Error("shared initial delay");
|
||||
}
|
||||
if (RESHOW != manager.getReshowDelay()) {
|
||||
throw new Error("shared reshow delay");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user