package com.apple.laf;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.basic.BasicHTML;
import javax.swing.text.View;
import sun.swing.SwingUtilities2;
import apple.laf.JRSUIConstants.*;
import com.apple.laf.AquaIcon.InvertableIcon;
import com.apple.laf.AquaUtils.RecyclableSingleton;
import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
public class {
static final byte
= 0x05,
= 0x07,
= 0x06,
= 0x0F,
kCommandMark = 0x11;
static final char
= 0x25C6,
= 0x2713,
= 0x2303,
= 0x2325,
= 0x2324,
kUCommandGlyph = 0x2318,
= 0x232B,
= 0x2326,
= 0x21E7,
= 0x21EA;
static final int = 1 << 5;
static final int = ~(InputEvent.CTRL_MASK | InputEvent.ALT_MASK | InputEvent.SHIFT_MASK | InputEvent.META_MASK | ALT_GRAPH_MASK);
interface {
public void (Graphics g, JComponent c, int menuWidth, int menuHeight);
}
static String (final int modifiers, final boolean isLeftToRight) {
return getKeyModifiersUnicode(modifiers, isLeftToRight);
}
private static String (final int modifiers, final boolean isLeftToRight) {
final StringBuilder buf = new StringBuilder(2);
if (isLeftToRight) {
if ((modifiers & InputEvent.CTRL_MASK) != 0) {
buf.append(kUControlGlyph);
}
if ((modifiers & (InputEvent.ALT_MASK | ALT_GRAPH_MASK)) != 0) {
buf.append(kUOptionGlyph);
}
if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
buf.append(kUShiftGlyph);
}
if ((modifiers & InputEvent.META_MASK) != 0) {
buf.append(kUCommandGlyph);
}
} else {
if ((modifiers & InputEvent.META_MASK) != 0) {
buf.append(kUCommandGlyph);
}
if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
buf.append(kUShiftGlyph);
}
if ((modifiers & (InputEvent.ALT_MASK | ALT_GRAPH_MASK)) != 0) {
buf.append(kUOptionGlyph);
}
if ((modifiers & InputEvent.CTRL_MASK) != 0) {
buf.append(kUControlGlyph);
}
}
return buf.toString();
}
static final RecyclableSingleton<AquaMenuPainter> = new RecyclableSingletonFromDefaultConstructor<AquaMenuPainter>(AquaMenuPainter.class);
static AquaMenuPainter () {
return sPainter.get();
}
static final int = 2;
static final int = 16;
static class extends RecyclableSingleton<Border> {
final String ;
(final String borderName) { this.borderName = borderName; }
protected Border () { return UIManager.getBorder(borderName); }
}
protected final RecyclableBorder = new RecyclableBorder("MenuBar.backgroundPainter");
protected final RecyclableBorder = new RecyclableBorder("MenuBar.selectedBackgroundPainter");
protected final RecyclableBorder = new RecyclableBorder("MenuItem.selectedBackgroundPainter");
public void (final Graphics g, final int width, final int height, final JComponent c) {
g.setColor(c == null ? Color.white : c.getBackground());
g.fillRect(0, 0, width, height);
menuBarPainter.get().paintBorder(null, g, 0, 0, width, height);
}
public void (final Graphics g, final int width, final int height) {
selectedMenuBarItemPainter.get().paintBorder(null, g, -1, 0, width + 2, height);
}
public void (final Graphics g, final int width, final int height) {
selectedMenuItemPainter.get().paintBorder(null, g, 0, 0, width, height);
}
protected void (final Client client, final Graphics g, final JComponent c, final Icon checkIcon, final Icon arrowIcon, final Color background, final Color foreground, final Color disabledForeground, final Color selectionForeground, final int defaultTextIconGap, final Font acceleratorFont) {
final JMenuItem b = (JMenuItem)c;
final ButtonModel model = b.getModel();
final int menuWidth = b.getWidth();
final int menuHeight = b.getHeight();
final Insets i = c.getInsets();
Rectangle viewRect = new Rectangle(0, 0, menuWidth, menuHeight);
viewRect.x += i.left;
viewRect.y += i.top;
viewRect.width -= (i.right + viewRect.x);
viewRect.height -= (i.bottom + viewRect.y);
final Font holdf = g.getFont();
final Color holdc = g.getColor();
final Font f = c.getFont();
g.setFont(f);
final FontMetrics fm = g.getFontMetrics(f);
final FontMetrics fmAccel = g.getFontMetrics(acceleratorFont);
if (c.isOpaque()) {
client.paintBackground(g, c, menuWidth, menuHeight);
}
final KeyStroke accelerator = b.getAccelerator();
String modifiersString = "", keyString = "";
final boolean leftToRight = AquaUtils.isLeftToRight(c);
if (accelerator != null) {
final int modifiers = accelerator.getModifiers();
if (modifiers > 0) {
modifiersString = getKeyModifiersText(modifiers, leftToRight);
}
final int keyCode = accelerator.getKeyCode();
if (keyCode != 0) {
keyString = KeyEvent.getKeyText(keyCode);
} else {
keyString += accelerator.getKeyChar();
}
}
Rectangle iconRect = new Rectangle();
Rectangle textRect = new Rectangle();
Rectangle acceleratorRect = new Rectangle();
Rectangle checkIconRect = new Rectangle();
Rectangle arrowIconRect = new Rectangle();
final String text = layoutMenuItem(b, fm, b.getText(), fmAccel, keyString, modifiersString, b.getIcon(), checkIcon, arrowIcon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, acceleratorRect, checkIconRect, arrowIconRect, b.getText() == null ? 0 : defaultTextIconGap, defaultTextIconGap);
final Container parent = b.getParent();
final boolean parentIsMenuBar = parent instanceof JMenuBar;
Container ancestor = parent;
while (ancestor != null && !(ancestor instanceof JPopupMenu)) ancestor = ancestor.getParent();
boolean isEnabled = model.isEnabled() && (ancestor == null || ancestor.isVisible());
boolean isSelected = false;
if (!isEnabled) {
g.setColor(disabledForeground);
} else {
if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
g.setColor(selectionForeground);
isSelected = true;
} else {
g.setColor(parentIsMenuBar ? parent.getForeground() : b.getForeground());
}
}
if (b.getIcon() != null) {
paintIcon(g, b, iconRect, isEnabled);
}
if (checkIcon != null) {
paintCheck(g, b, checkIcon, checkIconRect);
}
if (keyString != null && !keyString.equals("")) {
final int yAccel = acceleratorRect.y + fm.getAscent();
if (modifiersString.equals("")) {
SwingUtilities2.drawString(c, g, keyString, acceleratorRect.x, yAccel);
} else {
final int modifiers = accelerator.getModifiers();
int underlinedChar = 0;
if ((modifiers & ALT_GRAPH_MASK) > 0) underlinedChar = kUOptionGlyph;
final int emWidth = Math.max(fm.charWidth('M'), SwingUtilities.computeStringWidth(fm, keyString));
if (leftToRight) {
g.setFont(acceleratorFont);
drawString(g, c, modifiersString, underlinedChar, acceleratorRect.x, yAccel, isEnabled, isSelected);
g.setFont(f);
SwingUtilities2.drawString(c, g, keyString, acceleratorRect.x + acceleratorRect.width - emWidth, yAccel);
} else {
final int xAccel = acceleratorRect.x + emWidth;
g.setFont(acceleratorFont);
drawString(g, c, modifiersString, underlinedChar, xAccel, yAccel, isEnabled, isSelected);
g.setFont(f);
SwingUtilities2.drawString(c, g, keyString, xAccel - fm.stringWidth(keyString), yAccel);
}
}
}
if (text != null && !text.equals("")) {
final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
v.paint(g, textRect);
} else {
final int mnemonic = (AquaMnemonicHandler.isMnemonicHidden() ? -1 : model.getMnemonic());
drawString(g, c, text, mnemonic, textRect.x, textRect.y + fm.getAscent(), isEnabled, isSelected);
}
}
if (arrowIcon != null) {
paintArrow(g, b, model, arrowIcon, arrowIconRect);
}
g.setColor(holdc);
g.setFont(holdf);
}
protected Dimension (final JComponent c, final Icon checkIcon, final Icon arrowIcon, final int defaultTextIconGap, final Font acceleratorFont) {
final JMenuItem b = (JMenuItem)c;
final Icon icon = b.getIcon();
final String text = b.getText();
final KeyStroke accelerator = b.getAccelerator();
String keyString = "", modifiersString = "";
if (accelerator != null) {
final int modifiers = accelerator.getModifiers();
if (modifiers > 0) {
modifiersString = getKeyModifiersText(modifiers, true);
}
final int keyCode = accelerator.getKeyCode();
if (keyCode != 0) {
keyString = KeyEvent.getKeyText(keyCode);
} else {
keyString += accelerator.getKeyChar();
}
}
final Font font = b.getFont();
final FontMetrics fm = b.getFontMetrics(font);
final FontMetrics fmAccel = b.getFontMetrics(acceleratorFont);
Rectangle iconRect = new Rectangle();
Rectangle textRect = new Rectangle();
Rectangle acceleratorRect = new Rectangle();
Rectangle checkIconRect = new Rectangle();
Rectangle arrowIconRect = new Rectangle();
Rectangle viewRect = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);
layoutMenuItem(b, fm, text, fmAccel, keyString, modifiersString, icon, checkIcon, arrowIcon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, acceleratorRect, checkIconRect, arrowIconRect, text == null ? 0 : defaultTextIconGap, defaultTextIconGap);
Rectangle r = new Rectangle();
r.setBounds(textRect);
r = SwingUtilities.computeUnion(iconRect.x, iconRect.y, iconRect.width, iconRect.height, r);
boolean acceleratorTextIsEmpty = (keyString == null) || keyString.equals("");
if (!acceleratorTextIsEmpty) {
r.width += acceleratorRect.width;
}
if (!isTopLevelMenu(b)) {
r.width += checkIconRect.width;
r.width += defaultTextIconGap;
r.width += defaultTextIconGap;
r.width += arrowIconRect.width;
}
final Insets insets = b.getInsets();
if (insets != null) {
r.width += insets.left + insets.right;
r.height += insets.top + insets.bottom;
}
r.width += 4 + defaultTextIconGap;
r.height = Math.max(r.height, 18);
return r.getSize();
}
protected void (final Graphics g, final JMenuItem item, Icon checkIcon, Rectangle checkIconRect) {
if (isTopLevelMenu(item) || !item.isSelected()) return;
if (item.isArmed() && checkIcon instanceof InvertableIcon) {
((InvertableIcon)checkIcon).getInvertedIcon().paintIcon(item, g, checkIconRect.x, checkIconRect.y);
} else {
checkIcon.paintIcon(item, g, checkIconRect.x, checkIconRect.y);
}
}
protected void (final Graphics g, final JMenuItem c, final Rectangle localIconRect, boolean isEnabled) {
final ButtonModel model = c.getModel();
Icon icon;
if (!isEnabled) {
icon = c.getDisabledIcon();
} else if (model.isPressed() && model.isArmed()) {
icon = c.getPressedIcon();
if (icon == null) {
icon = c.getIcon();
}
} else {
icon = c.getIcon();
}
if (icon != null) icon.paintIcon(c, g, localIconRect.x, localIconRect.y);
}
protected void (Graphics g, JMenuItem c, ButtonModel model, Icon arrowIcon, Rectangle arrowIconRect) {
if (isTopLevelMenu(c)) return;
if (c instanceof JMenu && (model.isArmed() || model.isSelected()) && arrowIcon instanceof InvertableIcon) {
((InvertableIcon)arrowIcon).getInvertedIcon().paintIcon(c, g, arrowIconRect.x, arrowIconRect.y);
} else {
arrowIcon.paintIcon(c, g, arrowIconRect.x, arrowIconRect.y);
}
}
public void (final Graphics g, final JComponent c, final String text, final int underlinedChar, final int x, final int y, final boolean isEnabled, final boolean isSelected) {
char lc, uc;
int index = -1, lci, uci;
if (underlinedChar != '\0') {
uc = Character.toUpperCase((char)underlinedChar);
lc = Character.toLowerCase((char)underlinedChar);
uci = text.indexOf(uc);
lci = text.indexOf(lc);
if (uci == -1) index = lci;
else if (lci == -1) index = uci;
else index = (lci < uci) ? lci : uci;
}
SwingUtilities2.drawStringUnderlineCharAt(c, g, text, index, x, y);
}
private static boolean (final JMenuItem menuItem) {
return (menuItem instanceof JMenu) && (((JMenu)menuItem).isTopLevelMenu());
}
private String (final JMenuItem menuItem, final FontMetrics fm, final String text, final FontMetrics fmAccel, String keyString, final String modifiersString, final Icon icon, final Icon checkIcon, final Icon arrowIcon, final int verticalAlignment, final int horizontalAlignment, final int verticalTextPosition, final int horizontalTextPosition, final Rectangle viewR, final Rectangle iconR, final Rectangle textR, final Rectangle acceleratorR, final Rectangle checkIconR, final Rectangle arrowIconR, final int textIconGap, final int menuItemGap) {
SwingUtilities.layoutCompoundLabel(menuItem, fm, text, icon, verticalAlignment, SwingConstants.LEFT, verticalTextPosition, horizontalTextPosition, viewR, iconR, textR, textIconGap);
final boolean acceleratorTextIsEmpty = (keyString == null) || keyString.equals("");
if (acceleratorTextIsEmpty) {
acceleratorR.width = acceleratorR.height = 0;
keyString = "";
} else {
acceleratorR.width = SwingUtilities.computeStringWidth(fmAccel, modifiersString);
acceleratorR.width += Math.max(fm.charWidth('M'), SwingUtilities.computeStringWidth(fm, keyString));
acceleratorR.height = fmAccel.getHeight();
}
final boolean isTopLevelMenu = isTopLevelMenu(menuItem);
if (!isTopLevelMenu) {
if (checkIcon != null) {
checkIconR.width = checkIcon.getIconWidth();
checkIconR.height = checkIcon.getIconHeight();
} else {
checkIconR.width = checkIconR.height = 16;
}
if (arrowIcon != null) {
arrowIconR.width = arrowIcon.getIconWidth();
arrowIconR.height = arrowIcon.getIconHeight();
} else {
arrowIconR.width = arrowIconR.height = 16;
}
textR.x += 12;
iconR.x += 12;
}
final Rectangle labelR = iconR.union(textR);
acceleratorR.x += (viewR.width - arrowIconR.width - acceleratorR.width);
acceleratorR.y = viewR.y + (viewR.height / 2) - (acceleratorR.height / 2);
if (!isTopLevelMenu) {
arrowIconR.x = (viewR.width - arrowIconR.width) + 1;
arrowIconR.y = viewR.y + (labelR.height / 2) - (arrowIconR.height / 2) + 1;
checkIconR.y = viewR.y + (labelR.height / 2) - (checkIconR.height / 2);
checkIconR.x = 5;
textR.width += 8;
}
if (!AquaUtils.isLeftToRight(menuItem)) {
final int w = viewR.width;
checkIconR.x = w - (checkIconR.x + checkIconR.width);
iconR.x = w - (iconR.x + iconR.width);
textR.x = w - (textR.x + textR.width);
acceleratorR.x = w - (acceleratorR.x + acceleratorR.width);
arrowIconR.x = w - (arrowIconR.x + arrowIconR.width);
}
textR.x += menuItemGap;
iconR.x += menuItemGap;
return text;
}
public static Border () {
final AquaBorder border = new AquaBorder.Default();
border.painter.state.set(Widget.MENU_BAR);
return border;
}
public static Border () {
final AquaBorder border = new AquaBorder.Default();
border.painter.state.set(Widget.MENU_TITLE);
border.painter.state.set(State.PRESSED);
return border;
}
public static Border () {
final AquaBorder border = new AquaBorder.Default();
border.painter.state.set(Widget.MENU_ITEM);
border.painter.state.set(State.PRESSED);
return border;
}
}