Skip to content

Commit 458b9ac

Browse files
committed
8365389: Remove static color fields from SwingUtilities3 and WindowsMenuItemUI
Reviewed-by: andrew Backport-of: 3468c6e5ef7e7592cf9484736ce333fbe0eaf34d
1 parent baf3bb0 commit 458b9ac

File tree

6 files changed

+28
-64
lines changed

6 files changed

+28
-64
lines changed

src/java.desktop/share/classes/com/sun/java/swing/SwingUtilities3.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ public class SwingUtilities3 {
6666
private static final Object DELEGATE_REPAINT_MANAGER_KEY =
6767
new StringBuilder("DelegateRepaintManagerKey");
6868

69-
private static Color disabledForeground;
70-
private static Color acceleratorSelectionForeground;
71-
private static Color acceleratorForeground;
72-
7369
/**
7470
* Registers delegate RepaintManager for {@code JComponent}.
7571
*/
@@ -179,7 +175,10 @@ public static void paintIcon(Graphics g, MenuItemLayoutHelper lh,
179175

180176

181177
public static void paintAccText(Graphics g, MenuItemLayoutHelper lh,
182-
MenuItemLayoutHelper.LayoutResult lr) {
178+
MenuItemLayoutHelper.LayoutResult lr,
179+
Color disabledForeground,
180+
Color acceleratorSelectionForeground,
181+
Color acceleratorForeground) {
183182
if (!lh.getAccText().isEmpty()) {
184183
ButtonModel model = lh.getMenuItem().getModel();
185184
g.setFont(lh.getAccFontMetrics().getFont());
@@ -218,18 +217,6 @@ public static void paintAccText(Graphics g, MenuItemLayoutHelper lh,
218217
}
219218
}
220219

221-
public static void setDisabledForeground(Color disabledFg) {
222-
disabledForeground = disabledFg;
223-
}
224-
225-
public static void setAcceleratorSelectionForeground(Color acceleratorSelectionFg) {
226-
acceleratorSelectionForeground = acceleratorSelectionFg;
227-
}
228-
229-
public static void setAcceleratorForeground(Color acceleratorFg) {
230-
acceleratorForeground = acceleratorFg;
231-
}
232-
233220
public static void paintArrowIcon(Graphics g, MenuItemLayoutHelper lh,
234221
MenuItemLayoutHelper.LayoutResult lr,
235222
Color foreground) {

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuItemUI.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,11 +715,10 @@ private void paintCheckIcon(Graphics g, MenuItemLayoutHelper lh,
715715

716716
private void paintAccText(Graphics g, MenuItemLayoutHelper lh,
717717
MenuItemLayoutHelper.LayoutResult lr) {
718-
SwingUtilities3.setDisabledForeground(disabledForeground);
719-
SwingUtilities3.setAcceleratorSelectionForeground(
720-
acceleratorSelectionForeground);
721-
SwingUtilities3.setAcceleratorForeground(acceleratorForeground);
722-
SwingUtilities3.paintAccText(g, lh, lr);
718+
SwingUtilities3.paintAccText(g, lh, lr,
719+
disabledForeground,
720+
acceleratorSelectionForeground,
721+
acceleratorForeground);
723722
}
724723

725724
private void paintText(Graphics g, MenuItemLayoutHelper lh,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ protected void paintMenuItem(Graphics g, JComponent c,
8282
int defaultTextIconGap) {
8383
if (WindowsMenuItemUI.isVistaPainting()) {
8484
WindowsMenuItemUI.paintMenuItem(accessor, g, c, checkIcon,
85-
arrowIcon, background, foreground, defaultTextIconGap,
85+
arrowIcon, background, foreground,
86+
disabledForeground, acceleratorSelectionForeground,
87+
acceleratorForeground, defaultTextIconGap,
8688
menuItem, getPropertyPrefix());
8789
return;
8890
}

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

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ public class WindowsMenuItemUI extends BasicMenuItemUI {
6666
* The instance of {@code PropertyChangeListener}.
6767
*/
6868
private PropertyChangeListener changeListener;
69-
private static Color disabledForeground;
70-
private static Color acceleratorSelectionForeground;
71-
private static Color acceleratorForeground;
7269

7370
final WindowsMenuItemUIAccessor accessor =
7471
new WindowsMenuItemUIAccessor() {
@@ -164,44 +161,15 @@ protected void uninstallListeners() {
164161
changeListener = null;
165162
}
166163

167-
private static void applyInsets(Rectangle rect, Insets insets) {
168-
SwingUtilities3.applyInsets(rect, insets);
169-
}
170-
171-
private static void paintCheckIcon(Graphics g, MenuItemLayoutHelper lh,
172-
MenuItemLayoutHelper.LayoutResult lr,
173-
Color holdc, Color foreground) {
174-
SwingUtilities3.paintCheckIcon(g, lh, lr, holdc, foreground);
175-
}
176-
177-
private static void paintIcon(Graphics g, MenuItemLayoutHelper lh,
178-
MenuItemLayoutHelper.LayoutResult lr, Color holdc) {
179-
SwingUtilities3.paintIcon(g, lh, lr, holdc);
180-
}
181-
182-
private static void paintAccText(Graphics g, MenuItemLayoutHelper lh,
183-
MenuItemLayoutHelper.LayoutResult lr) {
184-
SwingUtilities3.setDisabledForeground(disabledForeground);
185-
SwingUtilities3.setAcceleratorSelectionForeground(
186-
acceleratorSelectionForeground);
187-
SwingUtilities3.setAcceleratorForeground(acceleratorForeground);
188-
SwingUtilities3.paintAccText(g, lh, lr);
189-
}
190-
191-
private static void paintArrowIcon(Graphics g, MenuItemLayoutHelper lh,
192-
MenuItemLayoutHelper.LayoutResult lr,
193-
Color foreground) {
194-
SwingUtilities3.paintArrowIcon(g, lh, lr, foreground);
195-
}
196-
197164
protected void paintMenuItem(Graphics g, JComponent c,
198165
Icon checkIcon, Icon arrowIcon,
199166
Color background, Color foreground,
200167
int defaultTextIconGap) {
201168
if (WindowsMenuItemUI.isVistaPainting()) {
202169
WindowsMenuItemUI.paintMenuItem(accessor, g, c, checkIcon,
203170
arrowIcon, background, foreground,
204-
defaultTextIconGap, menuItem,
171+
disabledForeground, acceleratorSelectionForeground,
172+
acceleratorForeground, defaultTextIconGap, menuItem,
205173
getPropertyPrefix());
206174
return;
207175
}
@@ -212,6 +180,9 @@ protected void paintMenuItem(Graphics g, JComponent c,
212180
static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
213181
JComponent c, Icon checkIcon, Icon arrowIcon,
214182
Color background, Color foreground,
183+
Color disabledForeground,
184+
Color acceleratorSelectionForeground,
185+
Color acceleratorForeground,
215186
int defaultTextIconGap, JMenuItem menuItem, String prefix) {
216187
// Save original graphics font and color
217188
Font holdf = g.getFont();
@@ -221,7 +192,7 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
221192
g.setFont(mi.getFont());
222193

223194
Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight());
224-
applyInsets(viewRect, mi.getInsets());
195+
SwingUtilities3.applyInsets(viewRect, mi.getInsets());
225196

226197
String acceleratorDelimiter =
227198
UIManager.getString("MenuItem.acceleratorDelimiter");
@@ -239,8 +210,8 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
239210
MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem();
240211

241212
paintBackground(accessor, g, mi, background);
242-
paintCheckIcon(g, lh, lr, holdc, foreground);
243-
paintIcon(g, lh, lr, holdc);
213+
SwingUtilities3.paintCheckIcon(g, lh, lr, holdc, foreground);
214+
SwingUtilities3.paintIcon(g, lh, lr, holdc);
244215

245216
if (lh.getCheckIcon() != null && lh.useCheckAndArrow()) {
246217
Rectangle rect = lr.getTextRect();
@@ -264,8 +235,10 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
264235
rect.x += lh.getAfterCheckIconGap();
265236
lr.setAccRect(rect);
266237
}
267-
paintAccText(g, lh, lr);
268-
paintArrowIcon(g, lh, lr, foreground);
238+
SwingUtilities3.paintAccText(g, lh, lr, disabledForeground,
239+
acceleratorSelectionForeground,
240+
acceleratorForeground);
241+
SwingUtilities3.paintArrowIcon(g, lh, lr, foreground);
269242

270243
// Restore original graphics font and color
271244
g.setColor(holdc);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ protected void paintMenuItem(Graphics g, JComponent c,
137137
if (WindowsMenuItemUI.isVistaPainting()) {
138138
WindowsMenuItemUI.paintMenuItem(accessor, g, c, checkIcon, arrowIcon,
139139
background, foreground,
140-
defaultTextIconGap, menuItem,
140+
disabledForeground, acceleratorSelectionForeground,
141+
acceleratorForeground, defaultTextIconGap, menuItem,
141142
getPropertyPrefix());
142143
return;
143144
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ protected void paintMenuItem(Graphics g, JComponent c,
8282
int defaultTextIconGap) {
8383
if (WindowsMenuItemUI.isVistaPainting()) {
8484
WindowsMenuItemUI.paintMenuItem(accessor, g, c, checkIcon,
85-
arrowIcon, background, foreground, defaultTextIconGap,
85+
arrowIcon, background, foreground,
86+
disabledForeground, acceleratorSelectionForeground,
87+
acceleratorForeground, defaultTextIconGap,
8688
menuItem, getPropertyPrefix());
8789
return;
8890
}

0 commit comments

Comments
 (0)