Skip to content

Commit 3468c6e

Browse files
committed
8365389: Remove static color fields from SwingUtilities3 and WindowsMenuItemUI
Reviewed-by: psadhukhan, aivanov, dnguyen
1 parent 5274725 commit 3468c6e

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
@@ -69,10 +69,6 @@ public class SwingUtilities3 {
6969
private static final Object DELEGATE_REPAINT_MANAGER_KEY =
7070
new StringBuilder("DelegateRepaintManagerKey");
7171

72-
private static Color disabledForeground;
73-
private static Color acceleratorSelectionForeground;
74-
private static Color acceleratorForeground;
75-
7672
/**
7773
* Registers delegate RepaintManager for {@code JComponent}.
7874
*/
@@ -204,7 +200,10 @@ public static void paintIcon(Graphics g, MenuItemLayoutHelper lh,
204200

205201

206202
public static void paintAccText(Graphics g, MenuItemLayoutHelper lh,
207-
MenuItemLayoutHelper.LayoutResult lr) {
203+
MenuItemLayoutHelper.LayoutResult lr,
204+
Color disabledForeground,
205+
Color acceleratorSelectionForeground,
206+
Color acceleratorForeground) {
208207
if (!lh.getAccText().isEmpty()) {
209208
ButtonModel model = lh.getMenuItem().getModel();
210209
g.setFont(lh.getAccFontMetrics().getFont());
@@ -243,18 +242,6 @@ public static void paintAccText(Graphics g, MenuItemLayoutHelper lh,
243242
}
244243
}
245244

246-
public static void setDisabledForeground(Color disabledFg) {
247-
disabledForeground = disabledFg;
248-
}
249-
250-
public static void setAcceleratorSelectionForeground(Color acceleratorSelectionFg) {
251-
acceleratorSelectionForeground = acceleratorSelectionFg;
252-
}
253-
254-
public static void setAcceleratorForeground(Color acceleratorFg) {
255-
acceleratorForeground = acceleratorFg;
256-
}
257-
258245
public static void paintArrowIcon(Graphics g, MenuItemLayoutHelper lh,
259246
MenuItemLayoutHelper.LayoutResult lr,
260247
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
@@ -716,11 +716,10 @@ private void paintCheckIcon(Graphics g, MenuItemLayoutHelper lh,
716716

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

726725
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
@@ -84,7 +84,9 @@ protected void paintMenuItem(Graphics g, JComponent c,
8484
int defaultTextIconGap) {
8585
if (WindowsMenuItemUI.isVistaPainting()) {
8686
WindowsMenuItemUI.paintMenuItem(accessor, g, c, checkIcon,
87-
arrowIcon, background, foreground, defaultTextIconGap,
87+
arrowIcon, background, foreground,
88+
disabledForeground, acceleratorSelectionForeground,
89+
acceleratorForeground, defaultTextIconGap,
8890
menuItem, getPropertyPrefix());
8991
return;
9092
}

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
@@ -67,9 +67,6 @@ public final class WindowsMenuItemUI extends BasicMenuItemUI {
6767
* The instance of {@code PropertyChangeListener}.
6868
*/
6969
private PropertyChangeListener changeListener;
70-
private static Color disabledForeground;
71-
private static Color acceleratorSelectionForeground;
72-
private static Color acceleratorForeground;
7370

7471
final WindowsMenuItemUIAccessor accessor =
7572
new WindowsMenuItemUIAccessor() {
@@ -167,44 +164,15 @@ protected void uninstallListeners() {
167164
changeListener = null;
168165
}
169166

170-
private static void applyInsets(Rectangle rect, Insets insets) {
171-
SwingUtilities3.applyInsets(rect, insets);
172-
}
173-
174-
private static void paintCheckIcon(Graphics g, MenuItemLayoutHelper lh,
175-
MenuItemLayoutHelper.LayoutResult lr,
176-
Color holdc, Color foreground) {
177-
SwingUtilities3.paintCheckIcon(g, lh, lr, holdc, foreground);
178-
}
179-
180-
private static void paintIcon(Graphics g, MenuItemLayoutHelper lh,
181-
MenuItemLayoutHelper.LayoutResult lr, Color holdc) {
182-
SwingUtilities3.paintIcon(g, lh, lr, holdc);
183-
}
184-
185-
private static void paintAccText(Graphics g, MenuItemLayoutHelper lh,
186-
MenuItemLayoutHelper.LayoutResult lr) {
187-
SwingUtilities3.setDisabledForeground(disabledForeground);
188-
SwingUtilities3.setAcceleratorSelectionForeground(
189-
acceleratorSelectionForeground);
190-
SwingUtilities3.setAcceleratorForeground(acceleratorForeground);
191-
SwingUtilities3.paintAccText(g, lh, lr);
192-
}
193-
194-
private static void paintArrowIcon(Graphics g, MenuItemLayoutHelper lh,
195-
MenuItemLayoutHelper.LayoutResult lr,
196-
Color foreground) {
197-
SwingUtilities3.paintArrowIcon(g, lh, lr, foreground);
198-
}
199-
200167
protected void paintMenuItem(Graphics g, JComponent c,
201168
Icon checkIcon, Icon arrowIcon,
202169
Color background, Color foreground,
203170
int defaultTextIconGap) {
204171
if (WindowsMenuItemUI.isVistaPainting()) {
205172
WindowsMenuItemUI.paintMenuItem(accessor, g, c, checkIcon,
206173
arrowIcon, background, foreground,
207-
defaultTextIconGap, menuItem,
174+
disabledForeground, acceleratorSelectionForeground,
175+
acceleratorForeground, defaultTextIconGap, menuItem,
208176
getPropertyPrefix());
209177
return;
210178
}
@@ -215,6 +183,9 @@ protected void paintMenuItem(Graphics g, JComponent c,
215183
static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
216184
JComponent c, Icon checkIcon, Icon arrowIcon,
217185
Color background, Color foreground,
186+
Color disabledForeground,
187+
Color acceleratorSelectionForeground,
188+
Color acceleratorForeground,
218189
int defaultTextIconGap, JMenuItem menuItem, String prefix) {
219190
// Save original graphics font and color
220191
Font holdf = g.getFont();
@@ -224,7 +195,7 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
224195
g.setFont(mi.getFont());
225196

226197
Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight());
227-
applyInsets(viewRect, mi.getInsets());
198+
SwingUtilities3.applyInsets(viewRect, mi.getInsets());
228199

229200
String acceleratorDelimiter =
230201
UIManager.getString("MenuItem.acceleratorDelimiter");
@@ -242,8 +213,8 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
242213
MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem();
243214

244215
paintBackground(accessor, g, mi, background);
245-
paintCheckIcon(g, lh, lr, holdc, foreground);
246-
paintIcon(g, lh, lr, holdc);
216+
SwingUtilities3.paintCheckIcon(g, lh, lr, holdc, foreground);
217+
SwingUtilities3.paintIcon(g, lh, lr, holdc);
247218

248219
if (lh.getCheckIcon() != null && lh.useCheckAndArrow()) {
249220
Rectangle rect = lr.getTextRect();
@@ -267,8 +238,10 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
267238
rect.x += lh.getAfterCheckIconGap();
268239
lr.setAccRect(rect);
269240
}
270-
paintAccText(g, lh, lr);
271-
paintArrowIcon(g, lh, lr, foreground);
241+
SwingUtilities3.paintAccText(g, lh, lr, disabledForeground,
242+
acceleratorSelectionForeground,
243+
acceleratorForeground);
244+
SwingUtilities3.paintArrowIcon(g, lh, lr, foreground);
272245

273246
// Restore original graphics font and color
274247
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
@@ -140,7 +140,8 @@ protected void paintMenuItem(Graphics g, JComponent c,
140140
if (WindowsMenuItemUI.isVistaPainting()) {
141141
WindowsMenuItemUI.paintMenuItem(accessor, g, c, checkIcon, arrowIcon,
142142
background, foreground,
143-
defaultTextIconGap, menuItem,
143+
disabledForeground, acceleratorSelectionForeground,
144+
acceleratorForeground, defaultTextIconGap, menuItem,
144145
getPropertyPrefix());
145146
return;
146147
}

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
@@ -84,7 +84,9 @@ protected void paintMenuItem(Graphics g, JComponent c,
8484
int defaultTextIconGap) {
8585
if (WindowsMenuItemUI.isVistaPainting()) {
8686
WindowsMenuItemUI.paintMenuItem(accessor, g, c, checkIcon,
87-
arrowIcon, background, foreground, defaultTextIconGap,
87+
arrowIcon, background, foreground,
88+
disabledForeground, acceleratorSelectionForeground,
89+
acceleratorForeground, defaultTextIconGap,
8890
menuItem, getPropertyPrefix());
8991
return;
9092
}

0 commit comments

Comments
 (0)