mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 03:58:21 +00:00
8376432
This commit is contained in:
parent
12570be64a
commit
9219dda625
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -29,7 +29,6 @@ import java.awt.Insets;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import sun.awt.AppContext;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DefaultLookup provides a way to customize the lookup done by the
|
* DefaultLookup provides a way to customize the lookup done by the
|
||||||
@ -44,17 +43,9 @@ import sun.awt.AppContext;
|
|||||||
* @author Scott Violet
|
* @author Scott Violet
|
||||||
*/
|
*/
|
||||||
public class DefaultLookup {
|
public class DefaultLookup {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key used to store DefaultLookup for AppContext.
|
* DefaultLookup currently set.
|
||||||
*/
|
|
||||||
private static final Object DEFAULT_LOOKUP_KEY = new
|
|
||||||
StringBuffer("DefaultLookup");
|
|
||||||
/**
|
|
||||||
* Thread that last asked for a default.
|
|
||||||
*/
|
|
||||||
private static Thread currentDefaultThread;
|
|
||||||
/**
|
|
||||||
* DefaultLookup for last thread.
|
|
||||||
*/
|
*/
|
||||||
private static DefaultLookup currentDefaultLookup;
|
private static DefaultLookup currentDefaultLookup;
|
||||||
|
|
||||||
@ -63,28 +54,24 @@ public class DefaultLookup {
|
|||||||
*/
|
*/
|
||||||
private static boolean isLookupSet;
|
private static boolean isLookupSet;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the DefaultLookup instance to use for the current
|
* Sets the DefaultLookup instance to use.
|
||||||
* <code>AppContext</code>. Null implies the UIManager should be
|
* Null implies the UIManager should be used.
|
||||||
* used.
|
|
||||||
*/
|
*/
|
||||||
public static void setDefaultLookup(DefaultLookup lookup) {
|
public static void setDefaultLookup(DefaultLookup lookup) {
|
||||||
synchronized(DefaultLookup.class) {
|
synchronized(DefaultLookup.class) {
|
||||||
if (!isLookupSet && lookup == null) {
|
if (!isLookupSet && lookup == null) {
|
||||||
// Null was passed in, and no one has invoked setDefaultLookup
|
// Null was passed in, and no one has previously invoked setDefaultLookup
|
||||||
// with a non-null value, we don't need to do anything.
|
// with a non-null value, we don't need to do anything.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (lookup == null) {
|
else if (lookup == null) {
|
||||||
// null was passed in, but someone has invoked setDefaultLookup
|
// null was passed in, but someone has previously invoked setDefaultLookup
|
||||||
// with a non-null value, use an instance of DefaultLookup
|
// with a non-null value, use an instance of DefaultLookup
|
||||||
// which will fallback to UIManager.
|
// which will fallback to UIManager.
|
||||||
lookup = new DefaultLookup();
|
lookup = new DefaultLookup();
|
||||||
}
|
}
|
||||||
isLookupSet = true;
|
isLookupSet = true;
|
||||||
AppContext.getAppContext().put(DEFAULT_LOOKUP_KEY, lookup);
|
|
||||||
currentDefaultThread = Thread.currentThread();
|
|
||||||
currentDefaultLookup = lookup;
|
currentDefaultLookup = lookup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,27 +85,13 @@ public class DefaultLookup {
|
|||||||
// No one has set a valid DefaultLookup, use UIManager.
|
// No one has set a valid DefaultLookup, use UIManager.
|
||||||
return UIManager.get(key, c.getLocale());
|
return UIManager.get(key, c.getLocale());
|
||||||
}
|
}
|
||||||
Thread thisThread = Thread.currentThread();
|
|
||||||
DefaultLookup lookup;
|
DefaultLookup lookup;
|
||||||
synchronized(DefaultLookup.class) {
|
synchronized(DefaultLookup.class) {
|
||||||
// See if we've already cached the DefaultLookup for this thread,
|
|
||||||
// and use it if we have.
|
|
||||||
if (thisThread == currentDefaultThread) {
|
|
||||||
// It is cached, use it.
|
|
||||||
lookup = currentDefaultLookup;
|
lookup = currentDefaultLookup;
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Not cached, get the DefaultLookup to use from the AppContext
|
|
||||||
lookup = (DefaultLookup)AppContext.getAppContext().get(
|
|
||||||
DEFAULT_LOOKUP_KEY);
|
|
||||||
if (lookup == null) {
|
if (lookup == null) {
|
||||||
// Fallback to DefaultLookup, which will redirect to the
|
// Fallback to DefaultLookup, which will redirect to the
|
||||||
// UIManager.
|
// UIManager.
|
||||||
lookup = new DefaultLookup();
|
lookup = new DefaultLookup();
|
||||||
AppContext.getAppContext().put(DEFAULT_LOOKUP_KEY, lookup);
|
|
||||||
}
|
|
||||||
// Cache the values to make the next lookup easier.
|
|
||||||
currentDefaultThread = thisThread;
|
|
||||||
currentDefaultLookup = lookup;
|
currentDefaultLookup = lookup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user