home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.basic;
-
- import com.sun.java.swing.AbstractButton;
- import com.sun.java.swing.Icon;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.JMenu;
- import com.sun.java.swing.JMenuBar;
- import com.sun.java.swing.JMenuItem;
- import com.sun.java.swing.JPopupMenu;
- import com.sun.java.swing.KeyStroke;
- import com.sun.java.swing.LookAndFeel;
- import com.sun.java.swing.MenuElement;
- import com.sun.java.swing.MenuSelectionManager;
- import com.sun.java.swing.Timer;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.event.ChangeListener;
- import com.sun.java.swing.plaf.ComponentUI;
- import com.sun.java.swing.plaf.MenuUI;
- import com.sun.java.swing.plaf.UIResource;
- import java.awt.AWTEvent;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.Point;
- import java.awt.event.ComponentEvent;
- import java.awt.event.InputEvent;
- import java.awt.event.KeyEvent;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseMotionListener;
- import java.io.Serializable;
-
- public class BasicMenuUI extends MenuUI implements Serializable {
- protected JMenu menu;
- protected MouseListener mouseListener;
- protected MouseMotionListener dragListener;
- protected ChangeListener menuChangeListener;
- protected static Color pressedBackground;
- protected static Color pressedForeground;
- private int lastMnemonic;
- protected static final int defaultTextIconGap = 4;
- protected Icon menuArrow;
- protected Icon checkIcon;
- protected boolean oldBorderPainted;
-
- public static ComponentUI createUI(JComponent var0) {
- return new BasicMenuUI();
- }
-
- public void installUI(JComponent var1) {
- this.menu = (JMenu)var1;
- this.menu.setDelay(200);
- this.initListeners(var1);
- this.addListeners(var1);
- var1.setOpaque(true);
- LookAndFeel.installBorder(var1, "Menu.border");
- this.oldBorderPainted = this.menu.isBorderPainted();
- this.menu.setBorderPainted((Boolean)UIManager.get("MenuItem.borderPainted"));
- LookAndFeel.installColorsAndFont(var1, "Menu.background", "Menu.foreground", "Menu.font");
- this.validateKeyboardAccelerator();
- if (pressedBackground == null || pressedBackground instanceof UIResource) {
- pressedBackground = UIManager.getColor("Menu.pressedBackground");
- }
-
- if (pressedForeground == null || pressedForeground instanceof UIResource) {
- pressedForeground = UIManager.getColor("Menu.pressedForeground");
- }
-
- }
-
- public void uninstallUI(JComponent var1) {
- this.menu.setArmed(false);
- this.menu.setSelected(false);
- this.removeListeners(var1);
- var1.resetKeyboardActions();
- LookAndFeel.uninstallBorder(var1);
- ((JMenu)var1).setBorderPainted(this.oldBorderPainted);
- if (this.menuArrow instanceof UIResource) {
- this.menuArrow = null;
- }
-
- if (this.checkIcon instanceof UIResource) {
- this.checkIcon = null;
- }
-
- }
-
- protected void validateKeyboardAccelerator() {
- if (this.menu.getModel().getMnemonic() != this.lastMnemonic) {
- this.menu.unregisterKeyboardAction(KeyStroke.getKeyStroke(this.lastMnemonic, 8, false));
- this.lastMnemonic = this.menu.getModel().getMnemonic();
- this.menu.registerKeyboardAction(new PostAction(this.menu, true), KeyStroke.getKeyStroke(this.lastMnemonic, 8, false), 2);
- }
-
- }
-
- protected MouseListener createMouseListener(JComponent var1) {
- return new MouseListener((JMenu)var1);
- }
-
- protected MouseMotionListener createMouseMotionListener(JComponent var1) {
- return new BasicMenuMouseMotionListener();
- }
-
- protected ChangeListener createMenuChangeListener(JComponent var1) {
- return new MenuChangeListener((JMenu)var1, this);
- }
-
- protected void initListeners(JComponent var1) {
- this.mouseListener = this.createMouseListener(var1);
- this.dragListener = this.createMouseMotionListener(var1);
- this.menuChangeListener = this.createMenuChangeListener(var1);
- }
-
- protected void addListeners(JComponent var1) {
- ((Component)var1).addMouseListener(this.mouseListener);
- ((Component)var1).addMouseMotionListener(this.dragListener);
- ((JMenu)var1).addChangeListener(this.menuChangeListener);
- }
-
- protected void removeListeners(JComponent var1) {
- ((Component)var1).removeMouseListener(this.mouseListener);
- ((Component)var1).removeMouseMotionListener(this.dragListener);
- ((JMenu)var1).removeChangeListener(this.menuChangeListener);
- }
-
- protected void installDefaultIcons() {
- if (this.menu != null && this.menu.getParent() != null && !(this.menu.getParent() instanceof JMenuBar)) {
- if (this.menuArrow == null || this.menuArrow instanceof UIResource) {
- this.menuArrow = UIManager.getIcon("Menu.arrowIcon");
- }
-
- if (this.checkIcon == null || this.checkIcon instanceof UIResource) {
- this.checkIcon = UIManager.getIcon("MenuItem.checkIcon");
- }
- }
-
- }
-
- public void update(Graphics var1, JComponent var2) {
- this.paint(var1, var2);
- }
-
- public void paint(Graphics var1, JComponent var2) {
- this.installDefaultIcons();
- ((AbstractButton)var2).getModel();
- BasicGraphicsUtils.paintMenuItem(var1, var2, this.checkIcon, this.menuArrow, pressedBackground, pressedForeground, 4);
- }
-
- public Dimension getMinimumSize(JComponent var1) {
- return this.getPreferredSize(var1);
- }
-
- public Dimension getMaximumSize(JComponent var1) {
- return this.getPreferredSize(var1);
- }
-
- public Insets getDefaultMargin(AbstractButton var1) {
- return new Insets(2, 2, 2, 2);
- }
-
- public Dimension getPreferredSize(JComponent var1) {
- this.installDefaultIcons();
- return BasicGraphicsUtils.getPreferredMenuItemSize(var1, this.checkIcon, this.menuArrow, 4);
- }
-
- public void processMouseEvent(JMenuItem var1, MouseEvent var2, MenuElement[] var3, MenuSelectionManager var4) {
- Point var5 = var2.getPoint();
- if (((Component)var1).isEnabled()) {
- if (var5.x >= 0 && var5.x < ((JComponent)var1).getWidth() && var5.y >= 0 && var5.y < ((JComponent)var1).getHeight()) {
- JMenu var9 = (JMenu)var1;
- MenuElement[] var7 = var4.getSelectedPath();
- if (var7.length <= 0 || var7[var7.length - 1] != var9.getPopupMenu()) {
- if (var9.isTopLevelMenu() || var9.getDelay() == 0 || ((AWTEvent)var2).getID() == 506) {
- MenuElement[] var8 = new MenuElement[var3.length + 1];
- System.arraycopy(var3, 0, var8, 0, var3.length);
- var8[var3.length] = var9.getPopupMenu();
- var4.setSelectedPath(var8);
- return;
- }
-
- var4.setSelectedPath(var3);
- this.setupPostTimer(var9);
- }
-
- } else {
- if (((AWTEvent)var2).getID() == 502) {
- Component var6 = var4.componentForPoint(((ComponentEvent)var2).getComponent(), var2.getPoint());
- if (var6 == null) {
- var4.clearSelectedPath();
- }
- }
-
- }
- }
- }
-
- private int lower(int var1) {
- return var1 >= 65 && var1 <= 90 ? var1 + 97 - 65 : var1;
- }
-
- public void processKeyEvent(JMenuItem var1, KeyEvent var2, MenuElement[] var3, MenuSelectionManager var4) {
- int var5 = ((AbstractButton)var1).getMnemonic();
- if (var5 != 0) {
- if (((AWTEvent)var2).getID() == 401 && this.lower(var5) == this.lower(var2.getKeyChar())) {
- JPopupMenu var6 = ((JMenu)var1).getPopupMenu();
- MenuElement[] var7 = var6.getSubElements();
- if (var7.length > 0) {
- MenuElement[] var8 = new MenuElement[var3.length + 2];
- System.arraycopy(var3, 0, var8, 0, var3.length);
- var8[var3.length] = var6;
- var8[var3.length + 1] = var7[0];
- var4.setSelectedPath(var8);
- }
-
- ((InputEvent)var2).consume();
- }
-
- }
- }
-
- protected void setupPostTimer(JMenu var1) {
- Timer var2 = new Timer(var1.getDelay(), new PostAction(var1, false));
- var2.setRepeats(false);
- var2.start();
- }
-
- public void menuCanceled(JMenu var1) {
- MenuSelectionManager var2 = MenuSelectionManager.defaultManager();
- if (var2.isComponentPartOfCurrentMenu(var1)) {
- MenuSelectionManager.defaultManager().clearSelectedPath();
- }
-
- }
- }
-