8365389: Remove static color fields from SwingUtilities3 and WindowsMenuItemUI

Reviewed-by: sgehwolf
Backport-of: 3468c6e5ef7e7592cf9484736ce333fbe0eaf34d
This commit is contained in:
Andrew John Hughes 2025-09-26 15:53:40 +00:00
parent 2abaf350cc
commit 25a9b9e559
6 changed files with 28 additions and 65 deletions

View File

@ -66,10 +66,6 @@ public class SwingUtilities3 {
private static final Object DELEGATE_REPAINT_MANAGER_KEY =
new StringBuilder("DelegateRepaintManagerKey");
private static Color disabledForeground;
private static Color acceleratorSelectionForeground;
private static Color acceleratorForeground;
/**
* Registers delegate RepaintManager for {@code JComponent}.
*/
@ -179,7 +175,10 @@ public class SwingUtilities3 {
public static void paintAccText(Graphics g, MenuItemLayoutHelper lh,
MenuItemLayoutHelper.LayoutResult lr) {
MenuItemLayoutHelper.LayoutResult lr,
Color disabledForeground,
Color acceleratorSelectionForeground,
Color acceleratorForeground) {
if (!lh.getAccText().isEmpty()) {
ButtonModel model = lh.getMenuItem().getModel();
g.setFont(lh.getAccFontMetrics().getFont());
@ -218,18 +217,6 @@ public class SwingUtilities3 {
}
}
public static void setDisabledForeground(Color disabledFg) {
disabledForeground = disabledFg;
}
public static void setAcceleratorSelectionForeground(Color acceleratorSelectionFg) {
acceleratorSelectionForeground = acceleratorSelectionFg;
}
public static void setAcceleratorForeground(Color acceleratorFg) {
acceleratorForeground = acceleratorFg;
}
public static void paintArrowIcon(Graphics g, MenuItemLayoutHelper lh,
MenuItemLayoutHelper.LayoutResult lr,
Color foreground) {

View File

@ -718,11 +718,10 @@ public class BasicMenuItemUI extends MenuItemUI
private void paintAccText(Graphics g, MenuItemLayoutHelper lh,
MenuItemLayoutHelper.LayoutResult lr) {
SwingUtilities3.setDisabledForeground(disabledForeground);
SwingUtilities3.setAcceleratorSelectionForeground(
acceleratorSelectionForeground);
SwingUtilities3.setAcceleratorForeground(acceleratorForeground);
SwingUtilities3.paintAccText(g, lh, lr);
SwingUtilities3.paintAccText(g, lh, lr,
disabledForeground,
acceleratorSelectionForeground,
acceleratorForeground);
}
private void paintText(Graphics g, MenuItemLayoutHelper lh,

View File

@ -84,7 +84,9 @@ public class WindowsCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI {
int defaultTextIconGap) {
if (WindowsMenuItemUI.isVistaPainting()) {
WindowsMenuItemUI.paintMenuItem(accessor, g, c, checkIcon,
arrowIcon, background, foreground, defaultTextIconGap,
arrowIcon, background, foreground,
disabledForeground, acceleratorSelectionForeground,
acceleratorForeground, defaultTextIconGap,
menuItem, getPropertyPrefix());
return;
}

View File

@ -51,10 +51,6 @@ import com.sun.java.swing.SwingUtilities3;
*/
public class WindowsMenuItemUI extends BasicMenuItemUI {
private static Color disabledForeground;
private static Color acceleratorSelectionForeground;
private static Color acceleratorForeground;
final WindowsMenuItemUIAccessor accessor =
new WindowsMenuItemUIAccessor() {
@ -96,36 +92,6 @@ public class WindowsMenuItemUI extends BasicMenuItemUI {
}
private static void applyInsets(Rectangle rect, Insets insets) {
SwingUtilities3.applyInsets(rect, insets);
}
private static void paintCheckIcon(Graphics g, MenuItemLayoutHelper lh,
MenuItemLayoutHelper.LayoutResult lr,
Color holdc, Color foreground) {
SwingUtilities3.paintCheckIcon(g, lh, lr, holdc, foreground);
}
private static void paintIcon(Graphics g, MenuItemLayoutHelper lh,
MenuItemLayoutHelper.LayoutResult lr, Color holdc) {
SwingUtilities3.paintIcon(g, lh, lr, holdc);
}
private static void paintAccText(Graphics g, MenuItemLayoutHelper lh,
MenuItemLayoutHelper.LayoutResult lr) {
SwingUtilities3.setDisabledForeground(disabledForeground);
SwingUtilities3.setAcceleratorSelectionForeground(
acceleratorSelectionForeground);
SwingUtilities3.setAcceleratorForeground(acceleratorForeground);
SwingUtilities3.paintAccText(g, lh, lr);
}
private static void paintArrowIcon(Graphics g, MenuItemLayoutHelper lh,
MenuItemLayoutHelper.LayoutResult lr,
Color foreground) {
SwingUtilities3.paintArrowIcon(g, lh, lr, foreground);
}
protected void paintMenuItem(Graphics g, JComponent c,
Icon checkIcon, Icon arrowIcon,
Color background, Color foreground,
@ -133,7 +99,8 @@ public class WindowsMenuItemUI extends BasicMenuItemUI {
if (WindowsMenuItemUI.isVistaPainting()) {
WindowsMenuItemUI.paintMenuItem(accessor, g, c, checkIcon,
arrowIcon, background, foreground,
defaultTextIconGap, menuItem,
disabledForeground, acceleratorSelectionForeground,
acceleratorForeground, defaultTextIconGap, menuItem,
getPropertyPrefix());
return;
}
@ -144,6 +111,9 @@ public class WindowsMenuItemUI extends BasicMenuItemUI {
static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
JComponent c, Icon checkIcon, Icon arrowIcon,
Color background, Color foreground,
Color disabledForeground,
Color acceleratorSelectionForeground,
Color acceleratorForeground,
int defaultTextIconGap, JMenuItem menuItem, String prefix) {
// Save original graphics font and color
Font holdf = g.getFont();
@ -153,7 +123,7 @@ public class WindowsMenuItemUI extends BasicMenuItemUI {
g.setFont(mi.getFont());
Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight());
applyInsets(viewRect, mi.getInsets());
SwingUtilities3.applyInsets(viewRect, mi.getInsets());
String acceleratorDelimiter =
UIManager.getString("MenuItem.acceleratorDelimiter");
@ -171,8 +141,8 @@ public class WindowsMenuItemUI extends BasicMenuItemUI {
MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem();
paintBackground(accessor, g, mi, background);
paintCheckIcon(g, lh, lr, holdc, foreground);
paintIcon(g, lh, lr, holdc);
SwingUtilities3.paintCheckIcon(g, lh, lr, holdc, foreground);
SwingUtilities3.paintIcon(g, lh, lr, holdc);
if (lh.getCheckIcon() != null && lh.useCheckAndArrow()) {
Rectangle rect = lr.getTextRect();
@ -196,8 +166,10 @@ public class WindowsMenuItemUI extends BasicMenuItemUI {
rect.x += lh.getAfterCheckIconGap();
lr.setAccRect(rect);
}
paintAccText(g, lh, lr);
paintArrowIcon(g, lh, lr, foreground);
SwingUtilities3.paintAccText(g, lh, lr, disabledForeground,
acceleratorSelectionForeground,
acceleratorForeground);
SwingUtilities3.paintArrowIcon(g, lh, lr, foreground);
// Restore original graphics font and color
g.setColor(holdc);

View File

@ -133,7 +133,8 @@ public class WindowsMenuUI extends BasicMenuUI {
if (WindowsMenuItemUI.isVistaPainting()) {
WindowsMenuItemUI.paintMenuItem(accessor, g, c, checkIcon, arrowIcon,
background, foreground,
defaultTextIconGap, menuItem,
disabledForeground, acceleratorSelectionForeground,
acceleratorForeground, defaultTextIconGap, menuItem,
getPropertyPrefix());
return;
}

View File

@ -83,7 +83,9 @@ public class WindowsRadioButtonMenuItemUI extends BasicRadioButtonMenuItemUI {
int defaultTextIconGap) {
if (WindowsMenuItemUI.isVistaPainting()) {
WindowsMenuItemUI.paintMenuItem(accessor, g, c, checkIcon,
arrowIcon, background, foreground, defaultTextIconGap,
arrowIcon, background, foreground,
disabledForeground, acceleratorSelectionForeground,
acceleratorForeground, defaultTextIconGap,
menuItem, getPropertyPrefix());
return;
}