Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,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}.
*/
Expand Down Expand Up @@ -204,7 +200,10 @@ public static void paintIcon(Graphics g, MenuItemLayoutHelper lh,


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());
Expand Down Expand Up @@ -243,18 +242,6 @@ public static void paintAccText(Graphics g, MenuItemLayoutHelper lh,
}
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,10 @@ private void paintCheckIcon(Graphics g, MenuItemLayoutHelper lh,

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,20 @@ protected void paintBackground(Graphics g, JMenuItem menuItem,
super.paintBackground(g, menuItem, bgColor);
}

/**
* Paint MenuItem.
*/
@Override
protected void paintMenuItem(Graphics g, JComponent c,
Icon checkIcon, Icon arrowIcon,
Color background, Color foreground,
int defaultTextIconGap) {
if (WindowsMenuItemUI.isVistaPainting()) {
WindowsMenuItemUI.paintMenuItem(accessor, g, c, checkIcon,
arrowIcon, background, foreground, defaultTextIconGap,
menuItem, getPropertyPrefix());
WindowsMenuItemUI.paintMenuItem(accessor, g, c,
checkIcon, arrowIcon,
background, foreground,
disabledForeground,
acceleratorSelectionForeground,
acceleratorForeground,
defaultTextIconGap,
menuItem, getPropertyPrefix());
return;
}
super.paintMenuItem(g, c, checkIcon, arrowIcon, background,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,11 @@
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Enumeration;

import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.DefaultButtonModel;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JMenu;
Expand Down Expand Up @@ -67,9 +62,6 @@ public final class WindowsMenuItemUI extends BasicMenuItemUI {
* The instance of {@code PropertyChangeListener}.
*/
private PropertyChangeListener changeListener;
private static Color disabledForeground;
private static Color acceleratorSelectionForeground;
private static Color acceleratorForeground;

final WindowsMenuItemUIAccessor accessor =
new WindowsMenuItemUIAccessor() {
Expand Down Expand Up @@ -134,27 +126,6 @@ public void propertyChange(PropertyChangeEvent e) {
menuItem.addPropertyChangeListener(changeListener);
}

protected void installDefaults() {
super.installDefaults();
String prefix = getPropertyPrefix();

if (acceleratorSelectionForeground == null ||
acceleratorSelectionForeground instanceof UIResource) {
acceleratorSelectionForeground =
UIManager.getColor(prefix + ".acceleratorSelectionForeground");
}
if (acceleratorForeground == null ||
acceleratorForeground instanceof UIResource) {
acceleratorForeground =
UIManager.getColor(prefix + ".acceleratorForeground");
}
if (disabledForeground == null ||
disabledForeground instanceof UIResource) {
disabledForeground =
UIManager.getColor(prefix + ".disabledForeground");
}
}

/**
* {@inheritDoc}
*/
Expand All @@ -167,43 +138,18 @@ protected void uninstallListeners() {
changeListener = null;
}

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);
}

@Override
protected void paintMenuItem(Graphics g, JComponent c,
Icon checkIcon, Icon arrowIcon,
Color background, Color foreground,
int defaultTextIconGap) {
if (WindowsMenuItemUI.isVistaPainting()) {
WindowsMenuItemUI.paintMenuItem(accessor, g, c, checkIcon,
arrowIcon, background, foreground,
WindowsMenuItemUI.paintMenuItem(accessor, g, c,
checkIcon, arrowIcon,
background, foreground,
disabledForeground,
acceleratorSelectionForeground,
acceleratorForeground,
defaultTextIconGap, menuItem,
getPropertyPrefix());
return;
Expand All @@ -213,9 +159,16 @@ protected void paintMenuItem(Graphics g, JComponent c,
}

static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
JComponent c, Icon checkIcon, Icon arrowIcon,
JComponent c,
Icon checkIcon, Icon arrowIcon,
Color background, Color foreground,
int defaultTextIconGap, JMenuItem menuItem, String prefix) {
Color disabledForeground,
Color acceleratorSelectionForeground,
Color acceleratorForeground,
int defaultTextIconGap, JMenuItem menuItem,
String prefix) {
assert c == menuItem : "menuItem passed as 'c' must be the same";

// Save original graphics font and color
Font holdf = g.getFont();
Color holdc = g.getColor();
Expand All @@ -224,7 +177,7 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
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");
Expand All @@ -242,8 +195,8 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
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();
Expand All @@ -267,8 +220,10 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,19 @@ protected void installDefaults() {
hotTrackingOn = (obj instanceof Boolean) ? (Boolean)obj : true;
}

/**
* Paint MenuItem.
*/
@Override
protected void paintMenuItem(Graphics g, JComponent c,
Icon checkIcon, Icon arrowIcon,
Color background, Color foreground,
int defaultTextIconGap) {
assert c == menuItem : "menuItem passed as 'c' must be the same";
if (WindowsMenuItemUI.isVistaPainting()) {
WindowsMenuItemUI.paintMenuItem(accessor, g, c, checkIcon, arrowIcon,
WindowsMenuItemUI.paintMenuItem(accessor, g, c,
checkIcon, arrowIcon,
background, foreground,
disabledForeground,
acceleratorSelectionForeground,
acceleratorForeground,
defaultTextIconGap, menuItem,
getPropertyPrefix());
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,20 @@ protected void paintBackground(Graphics g, JMenuItem menuItem,
super.paintBackground(g, menuItem, bgColor);
}

/**
* Paint MenuItem.
*/
@Override
protected void paintMenuItem(Graphics g, JComponent c,
Icon checkIcon, Icon arrowIcon,
Color background, Color foreground,
int defaultTextIconGap) {
if (WindowsMenuItemUI.isVistaPainting()) {
WindowsMenuItemUI.paintMenuItem(accessor, g, c, checkIcon,
arrowIcon, background, foreground, defaultTextIconGap,
menuItem, getPropertyPrefix());
WindowsMenuItemUI.paintMenuItem(accessor, g, c,
checkIcon, arrowIcon,
background, foreground,
disabledForeground,
acceleratorSelectionForeground,
acceleratorForeground,
defaultTextIconGap,
menuItem, getPropertyPrefix());
return;
}
super.paintMenuItem(g, c, checkIcon, arrowIcon, background,
Expand Down
Loading