Skip to content

Commit b0db66a

Browse files
prracevladimirlagunov
authored andcommitted
8376433: Remove AppContext from Swing Windows L&F implementation
Reviewed-by: serb, aivanov
1 parent fda71d5 commit b0db66a

File tree

6 files changed

+21
-72
lines changed

6 files changed

+21
-72
lines changed

src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/AnimationController.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2006, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -39,8 +39,6 @@
3939
import com.sun.java.swing.plaf.windows.TMSchema.Prop;
4040
import com.sun.java.swing.plaf.windows.XPStyle.Skin;
4141

42-
import sun.awt.AppContext;
43-
4442
/**
4543
* A class to help mimic Vista theme animations. The only kind of
4644
* animation it handles for now is 'transition' animation (this seems
@@ -68,8 +66,7 @@ final class AnimationController implements ActionListener, PropertyChangeListene
6866
Boolean.getBoolean("swing.disablevistaanimation");
6967

7068

71-
private static final Object ANIMATION_CONTROLLER_KEY =
72-
new StringBuilder("ANIMATION_CONTROLLER_KEY");
69+
private static AnimationController animationController;
7370

7471
private final Map<JComponent, Map<Part, AnimationState>> animationStateMap =
7572
new WeakHashMap<JComponent, Map<Part, AnimationState>>();
@@ -80,13 +77,10 @@ final class AnimationController implements ActionListener, PropertyChangeListene
8077
new javax.swing.Timer(1000/30, this);
8178

8279
private static synchronized AnimationController getAnimationController() {
83-
AppContext appContext = AppContext.getAppContext();
84-
Object obj = appContext.get(ANIMATION_CONTROLLER_KEY);
85-
if (obj == null) {
86-
obj = new AnimationController();
87-
appContext.put(ANIMATION_CONTROLLER_KEY, obj);
80+
if (animationController == null) {
81+
animationController = new AnimationController();
8882
}
89-
return (AnimationController) obj;
83+
return animationController;
9084
}
9185

9286
private AnimationController() {
@@ -316,8 +310,7 @@ private synchronized void dispose() {
316310
timer.stop();
317311
UIManager.removePropertyChangeListener(this);
318312
synchronized (AnimationController.class) {
319-
AppContext.getAppContext()
320-
.put(ANIMATION_CONTROLLER_KEY, null);
313+
animationController = null;
321314
}
322315
}
323316

src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsButtonUI.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -47,8 +47,6 @@
4747
import javax.swing.plaf.basic.BasicButtonUI;
4848
import javax.swing.plaf.basic.BasicGraphicsUtils;
4949

50-
import sun.awt.AppContext;
51-
5250
import static com.sun.java.swing.plaf.windows.TMSchema.Part;
5351
import static com.sun.java.swing.plaf.windows.TMSchema.State;
5452
import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
@@ -69,20 +67,13 @@ public final class WindowsButtonUI extends BasicButtonUI
6967

7068
private boolean defaults_initialized = false;
7169

72-
private static final Object WINDOWS_BUTTON_UI_KEY = new Object();
70+
private static final ComponentUI UI = new WindowsButtonUI();
7371

7472
// ********************************
7573
// Create PLAF
7674
// ********************************
7775
public static ComponentUI createUI(JComponent c) {
78-
AppContext appContext = AppContext.getAppContext();
79-
WindowsButtonUI windowsButtonUI =
80-
(WindowsButtonUI) appContext.get(WINDOWS_BUTTON_UI_KEY);
81-
if (windowsButtonUI == null) {
82-
windowsButtonUI = new WindowsButtonUI();
83-
appContext.put(WINDOWS_BUTTON_UI_KEY, windowsButtonUI);
84-
}
85-
return windowsButtonUI;
76+
return UI;
8677
}
8778

8879

src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsCheckBoxUI.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,8 +30,6 @@
3030
import javax.swing.UIManager;
3131
import javax.swing.plaf.ComponentUI;
3232

33-
import sun.awt.AppContext;
34-
3533
/**
3634
* Windows check box.
3735
*
@@ -43,7 +41,7 @@ public final class WindowsCheckBoxUI extends WindowsRadioButtonUI
4341
// of BasicCheckBoxUI because we want to pick up all the
4442
// painting changes made in WindowsRadioButtonUI.
4543

46-
private static final Object WINDOWS_CHECK_BOX_UI_KEY = new Object();
44+
private static final ComponentUI UI = new WindowsCheckBoxUI();
4745

4846
private static final String propertyPrefix = "CheckBox" + ".";
4947

@@ -53,14 +51,7 @@ public final class WindowsCheckBoxUI extends WindowsRadioButtonUI
5351
// Create PLAF
5452
// ********************************
5553
public static ComponentUI createUI(JComponent c) {
56-
AppContext appContext = AppContext.getAppContext();
57-
WindowsCheckBoxUI windowsCheckBoxUI =
58-
(WindowsCheckBoxUI) appContext.get(WINDOWS_CHECK_BOX_UI_KEY);
59-
if (windowsCheckBoxUI == null) {
60-
windowsCheckBoxUI = new WindowsCheckBoxUI();
61-
appContext.put(WINDOWS_CHECK_BOX_UI_KEY, windowsCheckBoxUI);
62-
}
63-
return windowsCheckBoxUI;
54+
return UI;
6455
}
6556

6657

src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsLabelUI.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -34,7 +34,6 @@
3434
import javax.swing.plaf.ComponentUI;
3535
import javax.swing.plaf.basic.BasicLabelUI;
3636

37-
import sun.awt.AppContext;
3837
import sun.swing.MnemonicHandler;
3938
import sun.swing.SwingUtilities2;
4039

@@ -43,20 +42,13 @@
4342
*/
4443
public final class WindowsLabelUI extends BasicLabelUI {
4544

46-
private static final Object WINDOWS_LABEL_UI_KEY = new Object();
45+
private static final ComponentUI UI = new WindowsLabelUI();
4746

4847
// ********************************
4948
// Create PLAF
5049
// ********************************
5150
public static ComponentUI createUI(JComponent c) {
52-
AppContext appContext = AppContext.getAppContext();
53-
WindowsLabelUI windowsLabelUI =
54-
(WindowsLabelUI) appContext.get(WINDOWS_LABEL_UI_KEY);
55-
if (windowsLabelUI == null) {
56-
windowsLabelUI = new WindowsLabelUI();
57-
appContext.put(WINDOWS_LABEL_UI_KEY, windowsLabelUI);
58-
}
59-
return windowsLabelUI;
51+
return UI;
6052
}
6153

6254
@Override

src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsRadioButtonUI.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -38,14 +38,12 @@
3838
import javax.swing.plaf.basic.BasicGraphicsUtils;
3939
import javax.swing.plaf.basic.BasicRadioButtonUI;
4040

41-
import sun.awt.AppContext;
42-
4341
/**
4442
* Windows rendition of the component.
4543
*/
4644
public class WindowsRadioButtonUI extends BasicRadioButtonUI
4745
{
48-
private static final Object WINDOWS_RADIO_BUTTON_UI_KEY = new Object();
46+
private static final ComponentUI UI = new WindowsRadioButtonUI();
4947

5048
protected int dashedRectGapX;
5149
protected int dashedRectGapY;
@@ -60,14 +58,7 @@ public class WindowsRadioButtonUI extends BasicRadioButtonUI
6058
// Create PLAF
6159
// ********************************
6260
public static ComponentUI createUI(JComponent c) {
63-
AppContext appContext = AppContext.getAppContext();
64-
WindowsRadioButtonUI windowsRadioButtonUI =
65-
(WindowsRadioButtonUI) appContext.get(WINDOWS_RADIO_BUTTON_UI_KEY);
66-
if (windowsRadioButtonUI == null) {
67-
windowsRadioButtonUI = new WindowsRadioButtonUI();
68-
appContext.put(WINDOWS_RADIO_BUTTON_UI_KEY, windowsRadioButtonUI);
69-
}
70-
return windowsRadioButtonUI;
61+
return UI;
7162
}
7263

7364
// ********************************

src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsToggleButtonUI.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -38,8 +38,6 @@
3838
import javax.swing.plaf.basic.BasicGraphicsUtils;
3939
import javax.swing.plaf.basic.BasicToggleButtonUI;
4040

41-
import sun.awt.AppContext;
42-
4341
/**
4442
* A Windows toggle button.
4543
*
@@ -54,19 +52,12 @@ public final class WindowsToggleButtonUI extends BasicToggleButtonUI
5452

5553
protected Color focusColor;
5654

57-
private static final Object WINDOWS_TOGGLE_BUTTON_UI_KEY = new Object();
55+
private static final ComponentUI UI = new WindowsToggleButtonUI();
5856

5957
private boolean defaults_initialized = false;
6058

6159
public static ComponentUI createUI(JComponent b) {
62-
AppContext appContext = AppContext.getAppContext();
63-
WindowsToggleButtonUI windowsToggleButtonUI =
64-
(WindowsToggleButtonUI) appContext.get(WINDOWS_TOGGLE_BUTTON_UI_KEY);
65-
if (windowsToggleButtonUI == null) {
66-
windowsToggleButtonUI = new WindowsToggleButtonUI();
67-
appContext.put(WINDOWS_TOGGLE_BUTTON_UI_KEY, windowsToggleButtonUI);
68-
}
69-
return windowsToggleButtonUI;
60+
return UI;
7061
}
7162

7263

0 commit comments

Comments
 (0)