package com.apple.laf;
import java.awt.*;
import java.awt.event.MouseEvent;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicMenuUI;
public class extends BasicMenuUI implements AquaMenuPainter.Client {
public static ComponentUI (final JComponent x) {
return new AquaMenuUI();
}
protected ChangeListener (final JComponent c) {
return new ChangeHandler((JMenu)c, this);
}
protected void () {
super.installDefaults();
((JMenu)menuItem).setDelay(8 * 1000 / 60);
}
protected void (final Graphics g, final JComponent c, final Icon localCheckIcon, final Icon localArrowIcon, final Color background, final Color foreground, final int localDefaultTextIconGap) {
AquaMenuPainter.instance().paintMenuItem(this, g, c, localCheckIcon, localArrowIcon, background, foreground, disabledForeground, selectionForeground, localDefaultTextIconGap, acceleratorFont);
}
protected Dimension (final JComponent c, final Icon localCheckIcon, final Icon localArrowIcon, final int localDefaultTextIconGap) {
final Dimension d = AquaMenuPainter.instance().getPreferredMenuItemSize(c, localCheckIcon, localArrowIcon, localDefaultTextIconGap, acceleratorFont);
if (c.getParent() instanceof JMenuBar) d.height = Math.max(d.height, 21);
return d;
}
public void (final Graphics g, final JComponent c, final int menuWidth, final int menuHeight) {
final Container parent = c.getParent();
final boolean parentIsMenuBar = parent instanceof JMenuBar;
final ButtonModel model = ((JMenuItem)c).getModel();
if (model.isArmed() || model.isSelected()) {
if (parentIsMenuBar) {
AquaMenuPainter.instance().paintSelectedMenuTitleBackground(g, menuWidth, menuHeight);
} else {
AquaMenuPainter.instance().paintSelectedMenuItemBackground(g, menuWidth, menuHeight);
}
} else {
if (parentIsMenuBar) {
AquaMenuPainter.instance().paintMenuBarBackground(g, menuWidth, menuHeight, c);
} else {
g.setColor(c.getBackground());
g.fillRect(0, 0, menuWidth, menuHeight);
}
}
}
protected MouseInputListener (final JComponent c) {
return new AquaMouseInputHandler();
}
protected MenuDragMouseListener (final JComponent c) {
return new MenuDragMouseHandler();
}
class MenuDragMouseHandler implements MenuDragMouseListener {
public void menuDragMouseDragged(final MenuDragMouseEvent e) {
if (menuItem.isEnabled() == false) return;
final MenuSelectionManager manager = e.getMenuSelectionManager();
final MenuElement path[] = e.getPath();
final Point p = e.getPoint();
if (p.x >= 0 && p.x < menuItem.getWidth() && p.y >= 0 && p.y < menuItem.getHeight()) {
final JMenu menu = (JMenu)menuItem;
final MenuElement selectedPath[] = manager.getSelectedPath();
if (!(selectedPath.length > 0 && selectedPath[selectedPath.length - 1] == menu.getPopupMenu())) {
if (menu.getDelay() == 0) {
appendPath(path, menu.getPopupMenu());
} else {
manager.setSelectedPath(path);
setupPostTimer(menu);
}
}
} else if (e.getID() == MouseEvent.MOUSE_RELEASED) {
final Component comp = manager.componentForPoint(e.getComponent(), e.getPoint());
if (comp == null) manager.clearSelectedPath();
}
}
public void menuDragMouseEntered(final MenuDragMouseEvent e) { }
public void menuDragMouseExited(final MenuDragMouseEvent e) { }
public void menuDragMouseReleased(final MenuDragMouseEvent e) { }
}
static void (final MenuElement[] path, final MenuElement elem) {
final MenuElement newPath[] = new MenuElement[path.length + 1];
System.arraycopy(path, 0, newPath, 0, path.length);
newPath[path.length] = elem;
MenuSelectionManager.defaultManager().setSelectedPath(newPath);
}
protected class AquaMouseInputHandler extends MouseInputHandler {
public void mouseEntered(final MouseEvent e) {
final JMenu menu = (JMenu)menuItem;
if (!menu.isEnabled()) return;
final MenuSelectionManager manager = MenuSelectionManager.defaultManager();
final MenuElement selectedPath[] = manager.getSelectedPath();
if (!(selectedPath.length > 0 && selectedPath[selectedPath.length - 1] == menu.getPopupMenu())) {
if (!menu.isTopLevelMenu() || (selectedPath.length > 0 &&
selectedPath[0] == menu.getParent())) {
if (menu.getDelay() == 0) {
appendPath(getPath(), menu.getPopupMenu());
} else {
manager.setSelectedPath(getPath());
setupPostTimer(menu);
}
}
}
}
}
}