Skip to content

Commit c69275d

Browse files
committed
8376232: Remove AppContext from Swing synth related classes
Reviewed-by: serb, azvegint
1 parent 3220c4c commit c69275d

File tree

8 files changed

+30
-307
lines changed

8 files changed

+30
-307
lines changed

src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKStyle.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import javax.swing.plaf.*;
3333
import javax.swing.plaf.synth.*;
3434

35-
import sun.awt.AppContext;
3635
import sun.awt.UNIXToolkit;
3736
import sun.swing.SwingUtilities2;
3837
import javax.swing.plaf.synth.SynthIcon;
@@ -961,11 +960,11 @@ private Icon getStyleSpecificIcon(String key,
961960

962961
static class GTKStockIconInfo {
963962
private static Map<String,Integer> ICON_TYPE_MAP;
964-
private static final Object ICON_SIZE_KEY = new StringBuffer("IconSize");
963+
964+
private static Dimension[] iconSizesMap;
965965

966966
private static Dimension[] getIconSizesMap() {
967-
AppContext appContext = AppContext.getAppContext();
968-
Dimension[] iconSizes = (Dimension[])appContext.get(ICON_SIZE_KEY);
967+
Dimension[] iconSizes = iconSizesMap;
969968

970969
if (iconSizes == null) {
971970
iconSizes = new Dimension[7];
@@ -976,7 +975,7 @@ private static Dimension[] getIconSizesMap() {
976975
iconSizes[4] = new Dimension(20, 20); // GTK_ICON_SIZE_BUTTON
977976
iconSizes[5] = new Dimension(32, 32); // GTK_ICON_SIZE_DND
978977
iconSizes[6] = new Dimension(48, 48); // GTK_ICON_SIZE_DIALOG
979-
appContext.put(ICON_SIZE_KEY, iconSizes);
978+
iconSizesMap = iconSizes;
980979
}
981980
return iconSizes;
982981
}

src/java.desktop/share/classes/javax/swing/plaf/nimbus/Effect.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
*/
2525
package javax.swing.plaf.nimbus;
2626

27-
import sun.awt.AppContext;
28-
2927
import java.awt.image.BufferedImage;
3028
import java.lang.ref.SoftReference;
3129

@@ -81,13 +79,10 @@ enum EffectType {
8179
// =================================================================================================================
8280
// Static data cache
8381

82+
private static final ArrayCache ARRAY_CACHE = new ArrayCache();
83+
8484
protected static ArrayCache getArrayCache() {
85-
ArrayCache cache = (ArrayCache)AppContext.getAppContext().get(ArrayCache.class);
86-
if (cache == null){
87-
cache = new ArrayCache();
88-
AppContext.getAppContext().put(ArrayCache.class,cache);
89-
}
90-
return cache;
85+
return ARRAY_CACHE;
9186
}
9287

9388
protected static class ArrayCache {

src/java.desktop/share/classes/javax/swing/plaf/synth/ImagePainter.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.lang.ref.WeakReference;
2929
import java.net.*;
3030
import javax.swing.*;
31-
import sun.awt.AppContext;
3231
import sun.swing.plaf.synth.Paint9Painter;
3332

3433
/**
@@ -41,8 +40,6 @@
4140
* @author Scott Violet
4241
*/
4342
class ImagePainter extends SynthPainter {
44-
private static final StringBuffer CACHE_KEY =
45-
new StringBuffer("SynthCacheKey");
4643

4744
private Image image;
4845
private Insets sInsets;
@@ -53,22 +50,17 @@ class ImagePainter extends SynthPainter {
5350
private Paint9Painter imageCache;
5451
private boolean center;
5552

53+
private static volatile WeakReference<Paint9Painter> cacheRef;
54+
5655
private static Paint9Painter getPaint9Painter() {
5756
// A SynthPainter is created per <imagePainter>. We want the
58-
// cache to be shared by all, and we don't use a static because we
59-
// don't want it to persist between look and feels. For that reason
60-
// we use a AppContext specific Paint9Painter. It's backed via
57+
// cache to be shared by all. It's held via
6158
// a WeakRef so that it can go away if the look and feel changes.
62-
synchronized(CACHE_KEY) {
63-
@SuppressWarnings("unchecked")
64-
WeakReference<Paint9Painter> cacheRef =
65-
(WeakReference<Paint9Painter>)AppContext.getAppContext().
66-
get(CACHE_KEY);
59+
synchronized(ImagePainter.class) {
6760
Paint9Painter painter;
6861
if (cacheRef == null || (painter = cacheRef.get()) == null) {
6962
painter = new Paint9Painter(30);
7063
cacheRef = new WeakReference<Paint9Painter>(painter);
71-
AppContext.getAppContext().put(CACHE_KEY, cacheRef);
7264
}
7365
return painter;
7466
}

src/java.desktop/share/classes/javax/swing/plaf/synth/Region.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
*/
2525
package javax.swing.plaf.synth;
2626

27-
import sun.awt.AppContext;
28-
2927
import java.util.HashMap;
3028
import java.util.Locale;
3129
import java.util.Map;
@@ -72,8 +70,6 @@
7270
* @author Scott Violet
7371
*/
7472
public class Region {
75-
private static final Object UI_TO_REGION_MAP_KEY = new Object();
76-
private static final Object LOWER_CASE_NAME_MAP_KEY = new Object();
7773

7874
/**
7975
* ArrowButton's are special types of buttons that also render a
@@ -425,10 +421,10 @@ public class Region {
425421
*/
426422
public static final Region VIEWPORT = new Region("Viewport", false);
427423

428-
private static Map<String, Region> getUItoRegionMap() {
429-
AppContext context = AppContext.getAppContext();
430-
@SuppressWarnings("unchecked")
431-
Map<String, Region> map = (Map<String, Region>) context.get(UI_TO_REGION_MAP_KEY);
424+
private static Map<String, Region> regionMap;
425+
426+
private static synchronized Map<String, Region> getUItoRegionMap() {
427+
Map<String, Region> map = regionMap;
432428
if (map == null) {
433429
map = new HashMap<String, Region>();
434430
map.put("ArrowButtonUI", ARROW_BUTTON);
@@ -476,18 +472,18 @@ private static Map<String, Region> getUItoRegionMap() {
476472
map.put("ToolBarSeparatorUI", TOOL_BAR_SEPARATOR);
477473
map.put("TreeUI", TREE);
478474
map.put("ViewportUI", VIEWPORT);
479-
context.put(UI_TO_REGION_MAP_KEY, map);
475+
regionMap = map;
480476
}
481477
return map;
482478
}
483479

484-
private static Map<Region, String> getLowerCaseNameMap() {
485-
AppContext context = AppContext.getAppContext();
486-
@SuppressWarnings("unchecked")
487-
Map<Region, String> map = (Map<Region, String>) context.get(LOWER_CASE_NAME_MAP_KEY);
480+
private static Map<Region, String> lcRegionMap;
481+
482+
private static synchronized Map<Region, String> getLowerCaseNameMap() {
483+
Map<Region, String> map = lcRegionMap;
488484
if (map == null) {
489485
map = new HashMap<Region, String>();
490-
context.put(LOWER_CASE_NAME_MAP_KEY, map);
486+
lcRegionMap = map;
491487
}
492488
return map;
493489
}

src/java.desktop/share/classes/javax/swing/plaf/synth/SynthButtonUI.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
package javax.swing.plaf.synth;
2727

28-
import sun.awt.AppContext;
29-
3028
import javax.swing.*;
3129
import java.awt.*;
3230
import java.beans.*;

src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import javax.swing.plaf.InsetsUIResource;
6161
import javax.swing.plaf.basic.BasicLookAndFeel;
6262

63-
import sun.awt.AppContext;
6463
import sun.awt.SunToolkit;
6564
import sun.swing.DefaultLookup;
6665
import sun.swing.SwingAccessor;
@@ -101,31 +100,13 @@ public class SynthLookAndFeel extends BasicLookAndFeel {
101100
static final Insets EMPTY_UIRESOURCE_INSETS = new InsetsUIResource(
102101
0, 0, 0, 0);
103102

104-
/**
105-
* AppContext key to get the current SynthStyleFactory.
106-
*/
107-
private static final Object STYLE_FACTORY_KEY =
108-
new StringBuffer("com.sun.java.swing.plaf.gtk.StyleCache");
109-
110-
/**
111-
* AppContext key to get selectedUI.
112-
*/
113-
private static final Object SELECTED_UI_KEY = new StringBuilder("selectedUI");
114-
115-
/**
116-
* AppContext key to get selectedUIState.
117-
*/
118-
private static final Object SELECTED_UI_STATE_KEY = new StringBuilder("selectedUIState");
103+
private static ComponentUI selectedUI;
104+
private static int selectedUIStateValue;
119105

120106
/**
121-
* The last SynthStyleFactory that was asked for from AppContext
122-
* <code>lastContext</code>.
107+
* The last SynthStyleFactory that was set.
123108
*/
124109
private static SynthStyleFactory lastFactory;
125-
/**
126-
* AppContext lastLAF came from.
127-
*/
128-
private static AppContext lastContext;
129110

130111
/**
131112
* SynthStyleFactory for the this SynthLookAndFeel.
@@ -141,7 +122,7 @@ public class SynthLookAndFeel extends BasicLookAndFeel {
141122
private Handler _handler;
142123

143124
static ComponentUI getSelectedUI() {
144-
return (ComponentUI) AppContext.getAppContext().get(SELECTED_UI_KEY);
125+
return selectedUI;
145126
}
146127

147128
/**
@@ -182,23 +163,20 @@ else if (rollover && enabled) {
182163
}
183164
}
184165

185-
AppContext context = AppContext.getAppContext();
186-
187-
context.put(SELECTED_UI_KEY, uix);
188-
context.put(SELECTED_UI_STATE_KEY, Integer.valueOf(selectedUIState));
166+
selectedUI = uix;
167+
selectedUIStateValue = selectedUIState;
189168
}
190169

191170
static int getSelectedUIState() {
192-
Integer result = (Integer) AppContext.getAppContext().get(SELECTED_UI_STATE_KEY);
193-
194-
return result == null ? 0 : result.intValue();
171+
return selectedUIStateValue;
195172
}
196173

197174
/**
198175
* Clears out the selected UI that was last set in setSelectedUI.
199176
*/
200177
static void resetSelectedUI() {
201-
AppContext.getAppContext().remove(SELECTED_UI_KEY);
178+
selectedUI = null;
179+
selectedUIStateValue = 0;
202180
}
203181

204182

@@ -210,12 +188,8 @@ static void resetSelectedUI() {
210188
*/
211189
public static void setStyleFactory(SynthStyleFactory cache) {
212190
// We assume the setter is called BEFORE the getter has been invoked
213-
// for a particular AppContext.
214191
synchronized(SynthLookAndFeel.class) {
215-
AppContext context = AppContext.getAppContext();
216192
lastFactory = cache;
217-
lastContext = context;
218-
context.put(STYLE_FACTORY_KEY, cache);
219193
}
220194
}
221195

@@ -226,13 +200,6 @@ public static void setStyleFactory(SynthStyleFactory cache) {
226200
*/
227201
public static SynthStyleFactory getStyleFactory() {
228202
synchronized(SynthLookAndFeel.class) {
229-
AppContext context = AppContext.getAppContext();
230-
231-
if (lastContext == context) {
232-
return lastFactory;
233-
}
234-
lastContext = context;
235-
lastFactory = (SynthStyleFactory) context.get(STYLE_FACTORY_KEY);
236203
return lastFactory;
237204
}
238205
}

test/jdk/javax/swing/plaf/synth/7143614/bug7143614.java

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)