? .snprj ? libjava.proj ? patch Index: ChangeLog =================================================================== RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v retrieving revision 1.2660.2.60 diff -c -p -u -r1.2660.2.60 ChangeLog --- ChangeLog 26 Mar 2004 20:30:35 -0000 1.2660.2.60 +++ ChangeLog 29 Mar 2004 16:41:24 -0000 @@ -1,3 +1,14 @@ +2004-03-29 Olga Rodimina + + * Makefile.am: Added new file. + * Makefile.in: Regenerate. + * javax/swing/JMenuItem.java: Partly + implemented. Work in progress + * javax/swing/plaf/basic/BasicLookAndFeel.java: + Changed default value of acceleratorDelimiter. + * javax/swing/plaf/basic/BasicMenuItemUI.java: + New class. Partly implemented. + 2004-03-26 Mark Wielaard * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c Index: Makefile.am =================================================================== RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v retrieving revision 1.361.2.7 diff -c -p -u -r1.361.2.7 Makefile.am --- Makefile.am 23 Mar 2004 14:42:16 -0000 1.361.2.7 +++ Makefile.am 29 Mar 2004 16:41:25 -0000 @@ -1251,6 +1251,7 @@ javax/swing/plaf/basic/BasicCheckBoxUI.j javax/swing/plaf/basic/BasicGraphicsUtils.java \ javax/swing/plaf/basic/BasicLabelUI.java \ javax/swing/plaf/basic/BasicListUI.java \ +javax/swing/plaf/basic/BasicMenuItemUI.java \ javax/swing/plaf/basic/BasicOptionPaneUI.java \ javax/swing/plaf/basic/BasicPanelUI.java \ javax/swing/plaf/basic/BasicProgressBarUI.java \ Index: Makefile.in =================================================================== RCS file: /cvs/gcc/gcc/libjava/Makefile.in,v retrieving revision 1.385.2.7 diff -c -p -u -r1.385.2.7 Makefile.in --- Makefile.in 23 Mar 2004 14:42:16 -0000 1.385.2.7 +++ Makefile.in 29 Mar 2004 16:41:26 -0000 @@ -956,6 +956,7 @@ javax/swing/plaf/basic/BasicCheckBoxUI.j javax/swing/plaf/basic/BasicGraphicsUtils.java \ javax/swing/plaf/basic/BasicLabelUI.java \ javax/swing/plaf/basic/BasicListUI.java \ +javax/swing/plaf/basic/BasicMenuItemUI.java \ javax/swing/plaf/basic/BasicOptionPaneUI.java \ javax/swing/plaf/basic/BasicPanelUI.java \ javax/swing/plaf/basic/BasicProgressBarUI.java \ @@ -2998,6 +2999,7 @@ javax/swing/plaf/basic/BasicCheckBoxUI.l javax/swing/plaf/basic/BasicGraphicsUtils.lo \ javax/swing/plaf/basic/BasicLabelUI.lo \ javax/swing/plaf/basic/BasicListUI.lo \ +javax/swing/plaf/basic/BasicMenuItemUI.lo \ javax/swing/plaf/basic/BasicOptionPaneUI.lo \ javax/swing/plaf/basic/BasicPanelUI.lo \ javax/swing/plaf/basic/BasicProgressBarUI.lo \ @@ -5087,6 +5089,7 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_D .deps/javax/swing/plaf/basic/BasicLabelUI.P \ .deps/javax/swing/plaf/basic/BasicListUI.P \ .deps/javax/swing/plaf/basic/BasicLookAndFeel.P \ +.deps/javax/swing/plaf/basic/BasicMenuItemUI.P \ .deps/javax/swing/plaf/basic/BasicOptionPaneUI.P \ .deps/javax/swing/plaf/basic/BasicPanelUI.P \ .deps/javax/swing/plaf/basic/BasicProgressBarUI.P \ Index: javax/swing/JMenuItem.java =================================================================== RCS file: /cvs/gcc/gcc/libjava/javax/swing/JMenuItem.java,v retrieving revision 1.2 diff -c -p -u -r1.2 JMenuItem.java --- javax/swing/JMenuItem.java 11 Jun 2003 13:20:39 -0000 1.2 +++ javax/swing/JMenuItem.java 29 Mar 2004 16:41:26 -0000 @@ -41,6 +41,7 @@ package javax.swing; import java.awt.Component; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; +import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.IOException; import java.io.ObjectInputStream; @@ -48,6 +49,7 @@ import java.io.ObjectOutputStream; import javax.accessibility.Accessible; import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleRole; +import javax.swing.UIManager; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.MenuDragMouseEvent; @@ -56,418 +58,259 @@ import javax.swing.event.MenuKeyEvent; import javax.swing.event.MenuKeyListener; import javax.swing.plaf.MenuItemUI; -/** - * JMenuItem - * @author Andrew Selkirk - * @version 1.0 - */ -public class JMenuItem extends AbstractButton implements Accessible, MenuElement { - - //------------------------------------------------------------- - // Classes ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * AccessibleJMenuItem - */ - protected class AccessibleJMenuItem extends AccessibleAbstractButton - implements ChangeListener { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor AccessibleJMenuItem - * @param component TODO - */ - AccessibleJMenuItem(JMenuItem component) { - super(component); - // TODO - } // AccessibleJMenuItem() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * stateChanged - * @param event TODO - */ - public void stateChanged(ChangeEvent event) { - // TODO - } // stateChanged() - - /** - * getAccessibleRole - * @returns AccessibleRole - */ - public AccessibleRole getAccessibleRole() { - return AccessibleRole.MENU_ITEM; - } // getAccessibleRole() - - - } // AccessibleJMenuItem - - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - /** - * uiClassID - */ - private static final String uiClassID = "MenuItemUI"; - - /** - * accelerator - */ - private KeyStroke accelerator; - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor JMenuItem - */ - public JMenuItem() { - // TODO - } // JMenuItem() - - /** - * Constructor JMenuItem - * @param icon TODO - */ - public JMenuItem(Icon icon) { - // TODO - } // JMenuItem() - - /** - * Constructor JMenuItem - * @param text TODO - */ - public JMenuItem(String text) { - // TODO - } // JMenuItem() - - /** - * Constructor JMenuItem - * @param action TODO - */ - public JMenuItem(Action action) { - // TODO - } // JMenuItem() - - /** - * Constructor JMenuItem - * @param text TODO - * @param icon TODO - */ - public JMenuItem(String text, Icon icon) { - // TODO - } // JMenuItem() - - /** - * Constructor JMenuItem - * @param text TODO - * @param mnemonic TODO - */ - public JMenuItem(String text, int mnemonic) { - // TODO - } // JMenuItem() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * readObject - * @param stream TODO - * @exception IOException TODO - * @exception ClassNotFoundException TODO - */ - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - // TODO - } // readObject() - - /** - * writeObject - * @param stream TODO - * @exception IOException TODO - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - // TODO - } // writeObject() - - /** - * init - * @param text TODO - * @param icon TODO - */ - protected void init(String text, Icon icon) { - // TODO - } // init() - - /** - * setUI - * @param ui TODO - */ - public void setUI(MenuItemUI ui) { - super.setUI(ui); - // TODO - } // setUI() - - /** - * updateUI - */ - public void updateUI() { - setUI((MenuItemUI) UIManager.get(this)); - invalidate(); - } // updateUI() - - /** - * getUIClassID - * @returns String - */ - public String getUIClassID() { - return uiClassID; - } // getUIClassID() - - /** - * isArmed - * @returns boolean - */ - public boolean isArmed() { - return false; // TODO - } // isArmed() - - /** - * setArmed - * @param armed TODO - */ - public void setArmed(boolean armed) { - // TODO - } // setArmed() - - /** - * setEnabled - * @param enabled TODO - */ - public void setEnabled(boolean enabled) { - // TODO - } // setEnabled() - - /** - * getAccelerator - * @returns KeyStroke - */ - public KeyStroke getAccelerator() { - return null; // TODO - } // getAccelerator() - - /** - * setAccelerator - * @param keystroke TODO - */ - public void setAccelerator(KeyStroke keystroke) { - // TODO - } // setAccelerator() - - /** - * configurePropertiesFromAction - * @param action TODO - */ - protected void configurePropertiesFromAction(Action action) { - // TODO - } // configurePropertiesFromAction() - - /** - * createActionPropertyChangeListener - * @param action TODO - * @returns PropertyChangeListener - */ - protected PropertyChangeListener createActionPropertyChangeListener(Action action) { - return null; // TODO - } // createActionPropertyChangeListener() - - /** - * processMouseEvent - * @param event TODO - * @param path TODO - * @param manager TODO - */ - public void processMouseEvent(MouseEvent event, MenuElement[] path, - MenuSelectionManager manager) { - // TODO - } // processMouseEvent() - - /** - * processKeyEvent - * @param event TODO - * @param path TODO - * @param manager TODO - */ - public void processKeyEvent(KeyEvent event, MenuElement[] path, - MenuSelectionManager manager) { - // TODO - } // processKeyEvent() - - /** - * processMenuDragMouseEvent - * @param event TODO - */ - public void processMenuDragMouseEvent(MenuDragMouseEvent event) { - // TODO - } // processMenuDragMouseEvent() - - /** - * processMenuKeyEvent - * @param event TODO - */ - public void processMenuKeyEvent(MenuKeyEvent event) { - // TODO - } // processMenuKeyEvent() - - /** - * fireMenuDragMouseEntered - * @param event TODO - */ - protected void fireMenuDragMouseEntered(MenuDragMouseEvent event) { - // TODO - } // fireMenuDragMouseEntered() - - /** - * fireMenuDragMouseExited - * @param event TODO - */ - protected void fireMenuDragMouseExited(MenuDragMouseEvent event) { - // TODO - } // fireMenuDragMouseExited() - - /** - * fireMenuDragMouseDragged - * @param event TODO - */ - protected void fireMenuDragMouseDragged(MenuDragMouseEvent event) { - // TODO - } // fireMenuDragMouseDragged() - - /** - * fireMenuDragMouseReleased - * @param event TODO - */ - protected void fireMenuDragMouseReleased(MenuDragMouseEvent event) { - // TODO - } // fireMenuDragMouseReleased() - - /** - * fireMenuKeyPressed - * @param event TODO - */ - protected void fireMenuKeyPressed(MenuKeyEvent event) { - // TODO - } // fireMenuKeyPressed() - - /** - * fireMenuKeyReleased - * @param event TODO - */ - protected void fireMenuKeyReleased(MenuKeyEvent event) { - // TODO - } // fireMenuKeyReleased() - - /** - * fireMenuKeyTyped - * @param event TODO - */ - protected void fireMenuKeyTyped(MenuKeyEvent event) { - // TODO - } // fireMenuKeyTyped() - - /** - * menuSelectionChanged - * @param changed TODO - */ - public void menuSelectionChanged(boolean changed) { - // TODO - } // menuSelectionChanged() - - /** - * getSubElements - * @returns MenuElement[] - */ - public MenuElement[] getSubElements() { - return null; // TODO - } // getSubElements() - - /** - * getComponent - * @returns Component - */ - public Component getComponent() { - return null; // TODO - } // getComponent() - - /** - * addMenuDragMouseListener - * @param listener TODO - */ - public void addMenuDragMouseListener(MenuDragMouseListener listener) { - // TODO - } // addMenuDragMouseListener() - - /** - * removeMenuDragMouseListener - * @param listener TODO - */ - public void removeMenuDragMouseListener(MenuDragMouseListener listener) { - // TODO - } // removeMenuDragMouseListener() - - /** - * addMenuKeyListener - * @param listener TODO - */ - public void addMenuKeyListener(MenuKeyListener listener) { - // TODO - } // addMenuKeyListener() - - /** - * removeMenuKeyListener - * @param listener TODO - */ - public void removeMenuKeyListener(MenuKeyListener listener) { - // TODO - } // removeMenuKeyListener() - - /** - * paramString - * @returns String - */ - protected String paramString() { - return null; // TODO - } // paramString() - - /** - * getAccessibleContext - * @returns AccessibleContext - */ - public AccessibleContext getAccessibleContext() { - if (accessibleContext == null) { - accessibleContext = new AccessibleJMenuItem(this); - } // if - return accessibleContext; - } // getAccessibleContext() - - +public class JMenuItem extends AbstractButton implements Accessible, + MenuElement +{ + //------------------------------------------------------------- + // Variables -------------------------------------------------- + //------------------------------------------------------------- + private static final String uiClassID = "MenuItemUI"; + private KeyStroke accelerator; + + //------------------------------------------------------------- + // Initialization --------------------------------------------- + //------------------------------------------------------------- + public JMenuItem() + { + this(null, null); + } // JMenuItem() + + public JMenuItem(Icon icon) + { + this(null, icon); + } // JMenuItem() + + public JMenuItem(String text) + { + this(text, null); + } // JMenuItem() + + public JMenuItem(Action action) + { + // TODO + } // JMenuItem() + + public JMenuItem(String text, Icon icon) + { + super(text, icon); + } // JMenuItem() + + public JMenuItem(String text, int mnemonic) + { + super(text, null); + setMnemonic(mnemonic); + } // JMenuItem() + + //------------------------------------------------------------- + // Methods ---------------------------------------------------- + //------------------------------------------------------------- + private void readObject(ObjectInputStream stream) + throws IOException, ClassNotFoundException + { + // TODO + } // readObject() + + private void writeObject(ObjectOutputStream stream) throws IOException + { + // TODO + } // writeObject() + + protected void init(String text, Icon icon) + { + // TODO + } // init() + + public void setUI(MenuItemUI ui) + { + super.setUI(ui); + } // setUI() + + public void updateUI() + { + MenuItemUI mi = ((MenuItemUI) UIManager.getUI(this)); + setUI(mi); + invalidate(); + } // updateUI() + + public String getUIClassID() + { + return uiClassID; + } // getUIClassID() + + public boolean isArmed() + { + return getModel().isArmed(); + } // isArmed() + + public void setArmed(boolean armed) + { + getModel().setArmed(armed); + } // setArmed() + + public void setEnabled(boolean enabled) + { + setEnabled(enabled); + } // setEnabled() + + public KeyStroke getAccelerator() + { + return accelerator; + } // getAccelerator() + + public void setAccelerator(KeyStroke keystroke) + { + this.accelerator = keystroke; + } // setAccelerator() + + protected void configurePropertiesFromAction(Action action) + { + super.configurePropertiesFromAction(action); + + if (action == null) + setAccelerator(null); + else + setAccelerator((KeyStroke) (action.getValue(Action.ACCELERATOR_KEY))); + + } // configurePropertiesFromAction() + + protected PropertyChangeListener createActionPropertyChangeListener(Action action) + { + return null; + } // createActionPropertyChangeListener() + + public void processMouseEvent(MouseEvent event, MenuElement[] path, + MenuSelectionManager manager) + { + // TODO + } // processMouseEvent() + + public void processKeyEvent(KeyEvent event, MenuElement[] path, + MenuSelectionManager manager) + { + // TODO + } // processKeyEvent() + + public void processMenuDragMouseEvent(MenuDragMouseEvent event) + { + } // processMenuDragMouseEvent() + + public void processMenuKeyEvent(MenuKeyEvent event) + { + // TODO + } // processMenuKeyEvent() + + protected void fireMenuDragMouseEntered(MenuDragMouseEvent event) + { + // TODO + } // fireMenuDragMouseEntered() + + protected void fireMenuDragMouseExited(MenuDragMouseEvent event) + { + // TODO + } // fireMenuDragMouseExited() + + protected void fireMenuDragMouseDragged(MenuDragMouseEvent event) + { + // TODO + } // fireMenuDragMouseDragged() + + protected void fireMenuDragMouseReleased(MenuDragMouseEvent event) + { + // TODO + } // fireMenuDragMouseReleased() + + protected void fireMenuKeyPressed(MenuKeyEvent event) + { + // TODO + } // fireMenuKeyPressed() + + protected void fireMenuKeyReleased(MenuKeyEvent event) + { + // TODO + } // fireMenuKeyReleased() + + protected void fireMenuKeyTyped(MenuKeyEvent event) + { + // TODO + } // fireMenuKeyTyped() + + public void menuSelectionChanged(boolean changed) + { + // TODO + } // menuSelectionChanged() + + public MenuElement[] getSubElements() + { + return null; // TODO + } // getSubElements() + + public Component getComponent() + { + return null; // TODO + } // getComponent() + + public void addMenuDragMouseListener(MenuDragMouseListener listener) + { + // TODO + } // addMenuDragMouseListener() + + public void removeMenuDragMouseListener(MenuDragMouseListener listener) + { + } // removeMenuDragMouseListener() + + public void addMenuKeyListener(MenuKeyListener listener) + { + } // addMenuKeyListener() + + public void removeMenuKeyListener(MenuKeyListener listener) + { + } // removeMenuKeyListener() + + protected String paramString() + { + return "JMenuItem"; + } // paramString() + + public AccessibleContext getAccessibleContext() + { + if (accessibleContext == null) + { + accessibleContext = new AccessibleJMenuItem(this); + } + + return accessibleContext; + } // getAccessibleContext() + + //------------------------------------------------------------- + // Classes ---------------------------------------------------- + //------------------------------------------------------------- + protected class AccessibleJMenuItem extends AccessibleAbstractButton + implements ChangeListener + { + //------------------------------------------------------------- + // Variables -------------------------------------------------- + //------------------------------------------------------------- + //------------------------------------------------------------- + // Initialization --------------------------------------------- + //------------------------------------------------------------- + AccessibleJMenuItem(JMenuItem component) + { + super(component); + + // TODO + } // AccessibleJMenuItem() + + //------------------------------------------------------------- + // Methods ---------------------------------------------------- + //------------------------------------------------------------- + public void stateChanged(ChangeEvent event) + { + // TODO + } // stateChanged() + + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.MENU_ITEM; + } // getAccessibleRole() + } // AccessibleJMenuItem } // JMenuItem Index: javax/swing/plaf/basic/BasicLookAndFeel.java =================================================================== RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicLookAndFeel.java,v retrieving revision 1.4.2.6 diff -c -p -u -r1.4.2.6 BasicLookAndFeel.java --- javax/swing/plaf/basic/BasicLookAndFeel.java 23 Mar 2004 14:42:19 -0000 1.4.2.6 +++ javax/swing/plaf/basic/BasicLookAndFeel.java 29 Mar 2004 16:41:26 -0000 @@ -501,7 +501,7 @@ public abstract class BasicLookAndFeel e "MenuBar.windowBindings", new Object[] { "F10", "takeFocus" }, - "MenuItem.acceleratorDelimiter", "+", + "MenuItem.acceleratorDelimiter", "-", "MenuItem.acceleratorFont", new FontUIResource("Dialog", Font.PLAIN, 12), "MenuItem.acceleratorForeground", new ColorUIResource(Color.black), "MenuItem.acceleratorSelectionForeground", new ColorUIResource(Color.white), Index: javax/swing/plaf/basic/BasicMenuItemUI.java =================================================================== RCS file: javax/swing/plaf/basic/BasicMenuItemUI.java diff -N javax/swing/plaf/basic/BasicMenuItemUI.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ javax/swing/plaf/basic/BasicMenuItemUI.java 29 Mar 2004 16:41:26 -0000 @@ -0,0 +1,609 @@ +/* BasicMenuItemUI.java + Copyright (C) 2002, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.basic; + +import java.awt.AWTKeyStroke; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Insets; +import java.awt.Rectangle; +import java.awt.Stroke; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import javax.swing.AbstractButton; +import javax.swing.ButtonModel; +import javax.swing.Icon; +import javax.swing.JComponent; +import javax.swing.JMenuItem; +import javax.swing.KeyStroke; +import javax.swing.MenuElement; +import javax.swing.MenuSelectionManager; +import javax.swing.SwingUtilities; +import javax.swing.UIDefaults; +import javax.swing.UIManager; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.MenuDragMouseEvent; +import javax.swing.event.MenuDragMouseListener; +import javax.swing.event.MenuKeyEvent; +import javax.swing.event.MenuKeyListener; +import javax.swing.event.MouseInputListener; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.MenuItemUI; + + +public class BasicMenuItemUI extends MenuItemUI +{ + /** Font to be used when displaying menu item's accelerator. */ + protected Font acceleratorFont; + + /** Color to be used when displaying menu item's accelerator. */ + protected Color acceleratorForeground; + + /** Color to be used when displaying menu item's accelerator + * when menu item is selected. + */ + protected Color acceleratorSelectionForeground; + + /** + * Icon that is displayed after the text to indicated that this menu + * contains submenu. + */ + protected Icon arrowIcon; + + /** + * Icon that is displayed before the text. This icon is only used in + * JCheckBoxMenuItem or JRadioBoxMenuItem. + */ + protected Icon checkIcon; + + /** Number of spaces between icon and text. */ + protected int defaultTextIconGap = 4; + + /** Color of the text when menu item is disabled*/ + protected Color disabledForeground; + + /** The menu Drag mouse listener listening to the menu item. */ + protected MenuDragMouseListener menuDragMouseListener; + + /** The menu item itself*/ + protected JMenuItem menuItem; + + /** Menu Key listener listening to the menu item. */ + protected MenuKeyListener menuKeyListener; + + /** mouse input listener listening to menu item. */ + protected MouseInputListener mouseInputListener; + + /** Indicates if border should be painted */ + protected boolean oldBorderPainted; + + /** Color of text that is used when menu item is selected */ + protected Color selectionBackground; + + /** Color of the background that is used when menu item is selected.*/ + protected Color selectionForeground; + + /** String that separates description of the modifiers and the key*/ + private String acceleratorDelimiter; + + /** Number of spaces between accelerator and menu item's label. */ + private int defaultAcceleratorLabelGap = 4; + + // Constructor Summary + BasicMenuItemUI() + { + mouseInputListener = createMouseInputListener(menuItem); + menuDragMouseListener = createMenuDragMouseListener(menuItem); + menuKeyListener = createMenuKeyListener(menuItem); + } + + // Method Summary + protected MenuDragMouseListener createMenuDragMouseListener(JComponent c) + { + return new MenuDragMouseHandler(); + } + + protected MenuKeyListener createMenuKeyListener(JComponent c) + { + return new MenuKeyHandler(); + } + + protected MouseInputListener createMouseInputListener(JComponent c) + { + return new MouseInputHandler(); + } + + public static ComponentUI createUI(JComponent c) + { + return new BasicMenuItemUI(); + } + + protected void doClick(MenuSelectionManager msm) + { + // TODO + } + + public Dimension getMaximumSize(JComponent c) + { + // TODO + return null; + } + + public Dimension getMinimumSize(JComponent c) + { + // TODO + return null; + } + + public MenuElement[] getPath() + { + // TODO + return null; + } + + protected Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon, + Icon arrowIcon, + int defaultTextIconGap) + { + // TODO + return null; + } + + public Dimension getPreferredSize(JComponent c) + { + AbstractButton b = (AbstractButton) c; + Dimension d = BasicGraphicsUtils.getPreferredButtonSize(b, + defaultTextIconGap); + + // if menu item has accelerator then take accelerator's size into account + // when calculating preferred size. + + KeyStroke accelerator = ((JMenuItem) c).getAccelerator(); + Rectangle rect; + if (accelerator != null) + { + rect = getAcceleratorRect(accelerator, + b.getToolkit().getFontMetrics(acceleratorFont)); + + // add width of accelerator's text + d.width = d.width + rect.width + defaultAcceleratorLabelGap; + + // adjust the heigth of the preferred size if necessary + if (d.height < rect.height) + d.height = rect.height; + } + return d; + } + + protected String getPropertyPrefix() + { + // TODO + return null; + } + + protected void installComponents(JMenuItem menuItem) + { + // TODO + } + + protected void installDefaults() + { + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + + menuItem.setBackground(defaults.getColor("MenuItem.background")); + menuItem.setBorder(defaults.getBorder("MenuItem.border")); + menuItem.setFont(defaults.getFont("MenuItem.font")); + menuItem.setForeground(defaults.getColor("MenuItem.foreground")); + menuItem.setMargin(defaults.getInsets("MenuItem.margin")); + acceleratorFont = defaults.getFont("MenuItem.acceleratorFont"); + acceleratorForeground = defaults.getColor("MenuItem.acceleratorForeground"); + acceleratorSelectionForeground = defaults.getColor("MenuItem.acceleratorSelectionForeground"); + arrowIcon = defaults.getIcon("MenuItem.arrowIcon"); + checkIcon = defaults.getIcon("MenuItem.checkIcon"); + selectionBackground = defaults.getColor("MenuItem.selectionBackground"); + selectionForeground = defaults.getColor("MenuItem.selectionForeground"); + acceleratorDelimiter = defaults.getString("MenuItem.acceleratorDelimiter"); + } + + protected void installKeyboardActions() + { + // TODO + } + + protected void installListeners() + { + menuItem.addMouseListener(mouseInputListener); + menuItem.addMenuDragMouseListener(menuDragMouseListener); + menuItem.addMenuKeyListener(menuKeyListener); + } + + public void installUI(JComponent c) + { + super.installUI(c); + menuItem = (JMenuItem) c; + installDefaults(); + installListeners(); + } + + public void paint(Graphics g, JComponent c) + { + AbstractButton b = (AbstractButton) c; + + Rectangle tr = new Rectangle(); // text rectangle + Rectangle ir = new Rectangle(); // icon rectangle + Rectangle vr = new Rectangle(); // view rectangle + Rectangle br = new Rectangle(); // border rectangle + Rectangle ar = new Rectangle(); // accelerator rectangle + + Font f = c.getFont(); + g.setFont(f); + SwingUtilities.calculateInnerArea(b, br); + SwingUtilities.calculateInsetArea(br, b.getMargin(), vr); + + paintBackground(g, (JMenuItem) c, c.getBackground()); + + if ((b.getModel().isArmed() && b.getModel().isPressed()) || b.isSelected()) + { + if (((AbstractButton) b).isContentAreaFilled()) + { + g.setColor(b.getBackground().darker()); + g.fillRect(br.x, br.y, br.width, br.height); + } + } + else + { + if (((AbstractButton) b).isContentAreaFilled()) + { + g.setColor(b.getBackground()); + g.fillRect(br.x, br.y, br.width, br.height); + } + } + + + // paint icon + // FIXME: should paint different icon at different button state's. + // i.e disabled icon when button is disabled.. etc. + + /* + Icon i = b.getIcon(); + if (i != null) + { + int x = ir.x; + int y = ir.y; + i.paintIcon(c, g, x, y); + } + */ + + // paint text + String text = SwingUtilities.layoutCompoundLabel(c, g.getFontMetrics(f), + b.getText(), b.getIcon(), + b.getVerticalAlignment(), + b.getHorizontalAlignment(), + b.getVerticalTextPosition(), + b.getHorizontalTextPosition(), + vr, ir, tr, + defaultTextIconGap); + + paintText(g, (JMenuItem) c, tr, b.getText()); + + // paint accelerator + String acceleratorText = ""; + if (((JMenuItem) c).getAccelerator() != null) + { + acceleratorText = getAcceleratorText(((JMenuItem) c).getAccelerator()); + FontMetrics fm = g.getFontMetrics(acceleratorFont); + ar.width = fm.stringWidth(acceleratorText); + ar.height = fm.getHeight(); + ar.x = br.width - ar.width; + ar.y = br.y; + paintAccelerator(g, (JMenuItem) c, ar, acceleratorText); + + } + } + + protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) + { + Dimension size = getPreferredSize(menuItem); + Color foreground = g.getColor(); + g.setColor(bgColor); + g.drawRect(0, 0, size.width, size.height); + g.setColor(foreground); + } + + protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, + Icon arrowIcon, Color background, + Color foreground, int defaultTextIconGap) + { + // TODO + } + + protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, + String text) + { + Font f = menuItem.getFont(); + g.setFont(f); + FontMetrics fm = g.getFontMetrics(f); + g.setColor(menuItem.getForeground()); + + BasicGraphicsUtils.drawString(g, text, 0, textRect.x, + textRect.y + fm.getAscent()); + } + + protected void uninstallComponents(JMenuItem menuItem) + { + // TODO + } + + protected void uninstallDefaults() + { + menuItem.setForeground(null); + menuItem.setBackground(null); + menuItem.setBorder(null); + menuItem.setMargin(null); + menuItem.setBackground(null); + menuItem.setBorder(null); + menuItem.setFont(null); + menuItem.setForeground(null); + menuItem.setMargin(null); + acceleratorFont = null; + acceleratorForeground = null; + acceleratorSelectionForeground = null; + arrowIcon = null; + checkIcon = null; + selectionBackground = null; + selectionForeground = null; + acceleratorDelimiter = null; + } + + protected void uninstallKeyboardActions() + { + // TODO + } + + protected void uninstallListeners() + { + menuItem.removeMouseListener(mouseInputListener); + menuItem.removeMenuDragMouseListener(menuDragMouseListener); + menuItem.removeMenuKeyListener(menuKeyListener); + } + + public void uninstallUI(JComponent c) + { + uninstallListeners(); + uninstallDefaults(); + menuItem = null; + } + + public void update(Graphics g, JComponent c) + { + // TODO + } + + private String getAcceleratorText(KeyStroke accelerator) + { + + // convert keystroke into string format + + String modifiersText = ""; + int modifiers = accelerator.getModifiers(); + char keyChar = accelerator.getKeyChar(); + int keyCode = accelerator.getKeyCode(); + + if (modifiers != 0) + modifiersText = KeyEvent.getKeyModifiersText(modifiers) + + acceleratorDelimiter; + + if (keyCode == KeyEvent.VK_UNDEFINED) + return modifiersText + keyChar; + else + return modifiersText + KeyEvent.getKeyText(keyCode); + } + + private Rectangle getAcceleratorRect(KeyStroke accelerator, FontMetrics fm) + { + int width = fm.stringWidth(getAcceleratorText(accelerator)); + int height = fm.getHeight(); + return new Rectangle(0, 0, width, height); + } + + private void paintAccelerator(Graphics g, JMenuItem menuItem, Rectangle acceleratorRect, + String acceleratorText) + { + g.setFont(acceleratorFont); + FontMetrics fm = g.getFontMetrics(acceleratorFont); + g.setColor(acceleratorForeground); + BasicGraphicsUtils.drawString(g, acceleratorText, 0, acceleratorRect.x, + acceleratorRect.y + fm.getAscent()); + } + + protected class MouseInputHandler implements MouseInputListener + { + protected MouseInputHandler() + { + } + + public void mouseClicked(MouseEvent e) + { + } + + public void mouseDragged(MouseEvent e) + { + } + + public void mouseEntered(MouseEvent e) + { + if (e.getSource() instanceof AbstractButton) + { + AbstractButton button = (AbstractButton) e.getSource(); + ButtonModel model = button.getModel(); + + if (button.isRolloverEnabled()) + { + model.setRollover(true); + } + + if (model.isPressed() && + ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0)) + { + model.setArmed(true); + } + else + { + model.setArmed(false); + } + } + } + + public void mouseExited(MouseEvent e) + { + if (e.getSource() instanceof AbstractButton) + { + AbstractButton button = (AbstractButton) e.getSource(); + ButtonModel model = button.getModel(); + + if (button.isRolloverEnabled()) + { + model.setRollover(false); + } + + model.setArmed(false); + } + } + + public void mouseMoved(MouseEvent e) + { + } + + public void mousePressed(MouseEvent e) + { + if (e.getSource() instanceof AbstractButton) + { + AbstractButton button = (AbstractButton) e.getSource(); + ButtonModel model = button.getModel(); + + if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) + { + // It is important that these transitions happen in this order. + model.setArmed(true); + model.setPressed(true); + } + } + } + + public void mouseReleased(MouseEvent e) + { + + if (e.getSource() instanceof AbstractButton) + { + AbstractButton button = (AbstractButton) e.getSource(); + ButtonModel model = button.getModel(); + + if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) + { + // It is important that these transitions happen in this order. + model.setPressed(false); + model.setArmed(false); + } + } + } + } + + protected class MenuDragMouseHandler implements MenuDragMouseListener + { + public void menuDragMouseDragged(MenuDragMouseEvent e) + { + // TODO + } + + public void menuDragMouseEntered(MenuDragMouseEvent e) + { + // TODO + } + + public void menuDragMouseExited(MenuDragMouseEvent e) + { + // TODO + } + + public void menuDragMouseReleased(MenuDragMouseEvent e) + { + // TODO + } + } + + protected class MenuKeyHandler implements MenuKeyListener + { + public void menuKeyPressed(MenuKeyEvent e) + { + // TODO + } + + public void menuKeyReleased(MenuKeyEvent e) + { + // TODO + } + + public void menuKeyTyped(MenuKeyEvent e) + { + // TODO + } + } + + protected class PropertyChangeHandler + { + public void propertyChange(PropertyChangeEvent evt) + { + // TODO + } + } +}