[gui][PATCH] JMenu & BasicMenuUI
Olga Rodimina
rodimina@redhat.com
Thu Jun 10 18:50:00 GMT 2004
Hi,
This patch fixes and documents JMenu and BasicMenuUI.
I'll be committing this patch to java-gui-branch.
Olga.
-------------- next part --------------
? .snprj
? libjava.proj
? patch
? resources
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2660.2.164
diff -c -p -u -r1.2660.2.164 ChangeLog
--- ChangeLog 10 Jun 2004 16:11:48 -0000 1.2660.2.164
+++ ChangeLog 10 Jun 2004 18:45:52 -0000
@@ -1,9 +1,47 @@
+2004-06-10 Olga Rodimina <rodimina@redhat.com>
+
+ * javax/swing/JMenu.java: Added javadoc.
+ (JMenu): Added MenuChangeListener to listen to
+ ChangeEvents occuring in menu's model.
+ (insert): Throw IllegalArgumentException if
+ index is less than 0
+ (setSelected): Reimplement.
+ (setPopupMenuVisible): Call menu's model isEnabled()
+ (setDelay): Throw IllegalArgumentException if
+ given amount of delay is less than 0.
+ (createActionComponent): Implemented.
+ (createActionChangeListener): Implemented.
+ (addSeparator): Implemented.
+ (getItem): Throw IllegalArgumentException if index is
+ less than 0.
+ (getItemCount): Implemented.
+ (fireMenuSelected): Changed to use menuEvent.
+ (fireMenuDeselected): Likewise.
+ (fireMenuCanceled): Likewise.
+ (setAccelerator): Changed to throw an error if this
+ method is used.
+ (doClick): Implemented.
+ (JMenu.ActionChangedListener): New inner class to handle
+ PropertyChangeEvents occuring in the actions associated with menu.
+ * javax/swing/plaf/basic/BasicMenuUI.java: Added javadoc.
+ (BasicMenuUI): Added PropertyChangeListener to the menu.
+ (createChangeListener): Implemented.
+ (createMenuDragMouseListener): Likewise.
+ (createMenuKeyListener): Likewise.
+ (createPropertyChangeListener): Likewise.
+ (uninstallListeners): Likewise.
+ (BasicMenuUI.MouseInputHandler): Reimplemented.
+ (BasicMenuUI.PropertyChangeHandler): New class. Not implemented yet.
+ (BasicMenuUI.ChangeHandler): Likewise.
+ (BasicMenuUI.MenuDragMouseHandler): Likewise.
+ (BasicMenuUI.MenuKeyHandler): Likewise.
+
2004-06-10 David Jee <djee@redhat.com>
* java/awt/MediaTracker.java
(imageUpdate): Only do notifyAll() if the image is complete.
-2004-06-10 Olga Rodimina <rodimina@redhat.com>
+2004-06-10 Olga Rodimina <rodimina@redhat.com>
* javax/swing/JApplet.java:
(getJMenuBar): Made public.
Index: javax/swing/JMenu.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JMenu.java,v
retrieving revision 1.3.8.4
diff -c -p -u -r1.3.8.4 JMenu.java
--- javax/swing/JMenu.java 8 Jun 2004 09:28:42 -0000 1.3.8.4
+++ javax/swing/JMenu.java 10 Jun 2004 18:45:53 -0000
@@ -1,5 +1,5 @@
-/* JMenu.java --
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+/* JMenuItem.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,9 +39,11 @@ package javax.swing;
import java.awt.Component;
import java.awt.Point;
+import java.awt.Window;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.ObjectOutputStream;
@@ -52,6 +54,7 @@ import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleSelection;
+import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
@@ -59,18 +62,36 @@ import javax.swing.plaf.MenuItemUI;
/**
- * DOCUMENT ME!
+ * This class represents a menu that can be added to a menu bar or
+ * to some other menu. When JMenu is selected it displays JPopupMenu
+ * containing its menu items.
*/
public class JMenu extends JMenuItem implements Accessible, MenuElement
{
static final long serialVersionUID = 4227225638931828014L;
+
+ /** name for the UI delegate for this menu. */
private static final String uiClassID = "MenuUI";
private static Hashtable listenerRegistry = null;
+
+ /** A Popup menu associated with this menu, which pops up when menu is selected */
private JPopupMenu popupMenu = new JPopupMenu();
+
+ /** MenuChangeListener that listens to change events occuring in menu's model */
private ChangeListener menuChangeListener;
- private MenuEvent menuEvent;
+
+ /** MenuEvent */
+ private MenuEvent menuEvent = new MenuEvent(this);
+
+ /*Amount of time, in milliseconds, that should pass before popupMenu
+ associated with this menu appears or disappers */
private int delay;
- protected JMenu.WinListener popupListener;
+
+ /* PopupListener */
+ protected WinListener popupListener;
+
+ /** Location at which popup menu associated with this menu will be displayed*/
+ private Point customMenuLocation;
/**
* Creates a new JMenu object.
@@ -78,55 +99,57 @@ public class JMenu extends JMenuItem imp
public JMenu()
{
super();
+ menuChangeListener = createMenuChangeListener();
+ getModel().addChangeListener(menuChangeListener);
}
/**
- * Creates a new JMenu object.
+ * Creates a new JMenu with the spicified label
*
- * @param text DOCUMENT ME!
+ * @param text label for this menu
*/
public JMenu(String text)
{
super(text);
+ menuChangeListener = createMenuChangeListener();
+ getModel().addChangeListener(menuChangeListener);
}
/**
- * Creates a new JMenu object.
+ * Creates a new JMenu object
*
- * @param action DOCUMENT ME!
+ * @param action Action that is used to create menu item tha will be
+ * added to the menu.
*/
public JMenu(Action action)
{
super(action);
+ menuChangeListener = createMenuChangeListener();
+ getModel().addChangeListener(menuChangeListener);
}
/**
- * Creates a new JMenu object.
+ * Creates a new JMenu with specified label and an option
+ * for this menu to be tear-off menu
*
- * @param text DOCUMENT ME!
- * @param tearoff DOCUMENT ME!
+ * @param text label for this menu
+ * @param tearoff true if this menu should be tear-off and false otherwise
*/
public JMenu(String text, boolean tearoff)
{
+ throw new Error("not implemented");
}
- /**
- * DOCUMENT ME!
- *
- * @param stream DOCUMENT ME!
- *
- * @throws IOException DOCUMENT ME!
- */
private void writeObject(ObjectOutputStream stream) throws IOException
{
}
/**
- * DOCUMENT ME!
+ * Adds specified menu item to this menu
*
- * @param item DOCUMENT ME!
+ * @param item Menu item to add to this menu
*
- * @return DOCUMENT ME!
+ * @return Menu item that was added
*/
public JMenuItem add(JMenuItem item)
{
@@ -134,11 +157,11 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Adds specified component to this menu.
*
- * @param component DOCUMENT ME!
+ * @param component Component to add to this menu
*
- * @return DOCUMENT ME!
+ * @return Component that was added
*/
public Component add(Component component)
{
@@ -146,12 +169,12 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Adds specified component to this menu at the given index
*
- * @param component DOCUMENT ME!
- * @param index DOCUMENT ME!
+ * @param component Component to add
+ * @param index Position of this menu item in the menu
*
- * @return DOCUMENT ME!
+ * @return Component that was added
*/
public Component add(Component component, int index)
{
@@ -159,11 +182,11 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Adds JMenuItem constructed with the specified label to this menu
*
- * @param text DOCUMENT ME!
+ * @param text label for the menu item that will be added
*
- * @return DOCUMENT ME!
+ * @return Menu Item that was added to this menu
*/
public JMenuItem add(String text)
{
@@ -171,11 +194,11 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Adds JMenuItem constructed using properties from specified action.
*
- * @param action DOCUMENT ME!
+ * @param action action to construct the menu item with
*
- * @return DOCUMENT ME!
+ * @return Menu Item that was added to this menu
*/
public JMenuItem add(Action action)
{
@@ -183,9 +206,10 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Removes given menu item from this menu. Nothing happens if
+ * this menu doesn't contain specified menu item.
*
- * @param item DOCUMENT ME!
+ * @param item Menu Item which needs to be removed
*/
public void remove(JMenuItem item)
{
@@ -193,9 +217,9 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Removes component at the specified index from this menu
*
- * @param index DOCUMENT ME!
+ * @param index Position of the component that needs to be removed in the menu
*/
public void remove(int index)
{
@@ -203,9 +227,9 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Removes given component from this menu.
*
- * @param component DOCUMENT ME!
+ * @param component Component to remove
*/
public void remove(Component component)
{
@@ -214,7 +238,7 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Removes all menu items from the menu
*/
public void removeAll()
{
@@ -222,49 +246,56 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Creates JMenuItem with the specified text and inserts it in the
+ * at the specified index
*
- * @param text DOCUMENT ME!
- * @param index DOCUMENT ME!
+ * @param text label for the new menu item
+ * @param index index at which to insert newly created menu item.
*/
public void insert(String text, int index)
{
- popupMenu.insert(new JMenuItem(text), index);
+ this.insert(new JMenuItem(text), index);
}
/**
- * DOCUMENT ME!
- *
- * @param item DOCUMENT ME!
- * @param index DOCUMENT ME!
+ * Creates JMenuItem with the specified text and inserts it in the
+ * at the specified index. IllegalArgumentException is thrown
+ * if index is less than 0
*
- * @return DOCUMENT ME!
+ * @param item menu item to insert
+ * @param index index at which to insert menu item.
+ * @return Menu item that was added to the menu
*/
public JMenuItem insert(JMenuItem item, int index)
{
+ if (index < 0)
+ throw new IllegalArgumentException("index less than zero");
+
popupMenu.insert(item, index);
return item;
}
/**
- * DOCUMENT ME!
- *
- * @param action DOCUMENT ME!
- * @param index DOCUMENT ME!
- *
- * @return DOCUMENT ME!
+ * Creates JMenuItem with the associated action and inserts it to the menu
+ * at the specified index. IllegalArgumentException is thrown
+ * if index is less than 0
+ *
+ * @param action Action for the new menu item
+ * @param index index at which to insert newly created menu item.
+ * @return Menu item that was added to the menu
*/
public JMenuItem insert(Action action, int index)
{
JMenuItem item = new JMenuItem(action);
- popupMenu.insert(item, index);
+ this.insert(item, index);
return item;
}
/**
- * DOCUMENT ME!
+ * This method sets this menuItem's UI to the UIManager's default for the
+ * current look and feel.
*/
public void updateUI()
{
@@ -273,9 +304,10 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * This method returns a name to identify which look and feel class will be
+ * the UI delegate for the menu.
*
- * @return DOCUMENT ME!
+ * @return The Look and Feel classID. "MenuUI"
*/
public String getUIClassID()
{
@@ -283,9 +315,9 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Sets model for this menu.
*
- * @param model DOCUMENT ME!
+ * @param model model to set
*/
public void setModel(ButtonModel model)
{
@@ -293,29 +325,32 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Returns true if the menu is selected and false otherwise
*
- * @return DOCUMENT ME!
+ * @return true if the menu is selected and false otherwise
*/
public boolean isSelected()
{
- return super.isSelected();
+ return super.isArmed();
}
/**
- * DOCUMENT ME!
+ * Changes this menu selected state if selected is true and false otherwise
+ * This method fires menuEvents to model's registered listeners.
*
- * @param selected DOCUMENT ME!
+ * @param selected true if the menu should be selected and false otherwise
*/
public void setSelected(boolean selected)
{
- super.setSelected(selected);
+ super.setArmed(true);
+ fireMenuSelected();
}
/**
- * DOCUMENT ME!
+ * Checks if PopupMenu associated with this menu is visible
*
- * @return DOCUMENT ME!
+ * @return true if the popup associated with this menu is currently visible on the screen and
+ * false otherwise.
*/
public boolean isPopupMenuVisible()
{
@@ -323,20 +358,20 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Sets popup menu visibility
*
- * @param popup DOCUMENT ME!
+ * @param popup true if popup should be visible and false otherwise
*/
public void setPopupMenuVisible(boolean popup)
{
- if (isEnabled())
+ if (getModel().isEnabled())
popupMenu.setVisible(popup);
}
/**
- * DOCUMENT ME!
+ * Returns origin point of the popup menu
*
- * @return DOCUMENT ME!
+ * @return Point containing
*/
protected Point getPopupMenuOrigin()
{
@@ -349,9 +384,11 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Returns delay property.
*
- * @return DOCUMENT ME!
+ * @return delay property, indicating number of milliseconds before
+ * popup menu associated with the menu appears or disappears after
+ * menu was selected or deselected respectively
*/
public int getDelay()
{
@@ -359,20 +396,25 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Sets delay property for this menu. If given time for the delay
+ * property is negative, then IllegalArgumentException is thrown
*
- * @param delay DOCUMENT ME!
+ * @param delay number of milliseconds before
+ * popup menu associated with the menu appears or disappears after
+ * menu was selected or deselected respectively
*/
public void setDelay(int delay)
{
+ if (delay < 0)
+ throw new IllegalArgumentException("delay less than 0");
this.delay = delay;
}
/**
- * DOCUMENT ME!
+ * Sets location at which popup menu should be displayed
*
- * @param x DOCUMENT ME!
- * @param y DOCUMENT ME!
+ * @param x x-coordinate of the menu location
+ * @param y y-coordinate of the menu location
*/
public void setMenuLocation(int x, int y)
{
@@ -380,54 +422,62 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Creates and returns JMenuItem associated with the given action
*
- * @param action DOCUMENT ME!
+ * @param action Action to use for creation of JMenuItem
*
- * @return DOCUMENT ME!
+ * @return JMenuItem that was creted with given action
*/
protected JMenuItem createActionComponent(Action action)
{
- return null;
+ return new JMenuItem(action);
}
/**
- * DOCUMENT ME!
+ * Creates ActionChangeListener to listen for PropertyChangeEvents occuring
+ * in the action that is associated with this menu
*
- * @param item DOCUMENT ME!
+ * @param item menu that contains action to listen to
*
- * @return DOCUMENT ME!
+ * @return The PropertyChangeListener
*/
protected PropertyChangeListener createActionChangeListener(JMenuItem item)
{
- return null;
+ return new ActionChangedListener(item);
}
/**
- * DOCUMENT ME!
+ * Adds separator to the end of the menu items in the menu.
*/
public void addSeparator()
{
+ getPopupMenu().addSeparator();
}
/**
- * DOCUMENT ME!
+ * Inserts separator in the menu at the specified index.
*
- * @param index DOCUMENT ME!
+ * @param index Index at which separator should be inserted
*/
public void insertSeparator(int index)
{
+ // Insert a horizontal separator at the position specified by the
+ // integer index. The index must be positive, or the method
+ // throws an IllegalArgumentException.
}
/**
- * DOCUMENT ME!
+ * Returns menu item located at the specified index in the menu
*
- * @param index DOCUMENT ME!
+ * @param index Index at which to look for the menu item
*
- * @return DOCUMENT ME!
+ * @return menu item located at the specified index in the menu
*/
public JMenuItem getItem(int index)
{
+ if (index < 0)
+ throw new IllegalArgumentException("index less than 0");
+
Component c = popupMenu.getComponentAtIndex(index);
if (c instanceof JMenuItem)
@@ -437,29 +487,32 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Returns number of items in the menu
*
- * @return DOCUMENT ME!
+ * @return number of items in the menu
*/
public int getItemCount()
{
- return 0;
+ // returns the number of items on
+ // the menu, including separators.
+ return getComponents().length;
}
/**
- * DOCUMENT ME!
+ * Checks if this menu is a tear-off menu.
*
- * @return DOCUMENT ME!
+ * @return true if this menu is a tear-off menu and false otherwise
*/
public boolean isTearOff()
{
+ // NOT YET IMPLEMENTED
return false;
}
/**
- * DOCUMENT ME!
+ * Returns number of menu components in this menu
*
- * @return DOCUMENT ME!
+ * @return number of menu components in this menu
*/
public int getMenuComponentCount()
{
@@ -467,11 +520,12 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Returns menu component located at the givent index
+ * in the menu
*
- * @param index DOCUMENT ME!
+ * @param index index at which to get the menu component in the menu
*
- * @return DOCUMENT ME!
+ * @return Menu Component located in the menu at the specified index
*/
public Component getMenuComponent(int index)
{
@@ -479,9 +533,9 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Return components belonging to this menu
*
- * @return DOCUMENT ME!
+ * @return components belonging to this menu
*/
public Component[] getMenuComponents()
{
@@ -489,9 +543,11 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Checks if this menu is a top level menu. The menu is top
+ * level menu if it is inside the menu bar. While if the menu
+ * inside some other menu, it is considered to be a pull-right menu.
*
- * @return DOCUMENT ME!
+ * @return true if this menu is top level menu, and false otherwise
*/
public boolean isTopLevelMenu()
{
@@ -502,11 +558,12 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Checks if given component exists in this menu. The submenus of
+ * this menu are checked as well
*
- * @param component DOCUMENT ME!
+ * @param component Component to look for
*
- * @return DOCUMENT ME!
+ * @return true if the given component exists in this menu, and false otherwise
*/
public boolean isMenuComponent(Component component)
{
@@ -514,9 +571,9 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Returns popup menu associated with the menu.
*
- * @return DOCUMENT ME!
+ * @return popup menu associated with the menu.
*/
public JPopupMenu getPopupMenu()
{
@@ -524,9 +581,9 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Adds MenuListener to the menu
*
- * @param listener DOCUMENT ME!
+ * @param listener MenuListener to add
*/
public void addMenuListener(MenuListener listener)
{
@@ -534,9 +591,9 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * Removes MenuListener from the menu
*
- * @param listener DOCUMENT ME!
+ * @param listener MenuListener to remove
*/
public void removeMenuListener(MenuListener listener)
{
@@ -544,83 +601,125 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * This method fires MenuEvents to all menu's MenuListeners. In this case
+ * menuSelected() method of MenuListeners is called to indicated that the menu
+ * was selected.
*/
protected void fireMenuSelected()
{
EventListener[] ll = listenerList.getListeners(MenuListener.class);
for (int i = 0; i < ll.length; i++)
- ((MenuListener) ll[i]).menuSelected(new MenuEvent(this));
+ ((MenuListener) ll[i]).menuSelected(menuEvent);
}
/**
- * DOCUMENT ME!
+ * This method fires MenuEvents to all menu's MenuListeners. In this case
+ * menuDeselected() method of MenuListeners is called to indicated that the menu
+ * was deselected.
*/
protected void fireMenuDeselected()
{
EventListener[] ll = listenerList.getListeners(MenuListener.class);
for (int i = 0; i < ll.length; i++)
- ((MenuListener) ll[i]).menuDeselected(new MenuEvent(this));
+ ((MenuListener) ll[i]).menuDeselected(menuEvent);
}
/**
- * DOCUMENT ME!
+ * This method fires MenuEvents to all menu's MenuListeners. In this case
+ * menuSelected() method of MenuListeners is called to indicated that the menu
+ * was cancelled. The menu is cancelled when it's popup menu is close without selection.
*/
protected void fireMenuCanceled()
{
EventListener[] ll = listenerList.getListeners(MenuListener.class);
for (int i = 0; i < ll.length; i++)
- ((MenuListener) ll[i]).menuCanceled(new MenuEvent(this));
+ ((MenuListener) ll[i]).menuCanceled(menuEvent);
}
/**
- * DOCUMENT ME!
+ * Creates MenuChangeListener to listen to change events occuring
+ * in the model
*
- * @return DOCUMENT ME!
+ * @return ChangeListener
*/
private ChangeListener createMenuChangeListener()
{
- return null;
+ return new MenuChangeListener();
}
/**
- * DOCUMENT ME!
+ * Creates WinListener that listens to the menu;s popup menu.
*
- * @param popup DOCUMENT ME!
+ * @param popup JPopupMenu to listen to
*
- * @return DOCUMENT ME!
+ * @return The WinListener
*/
- protected JMenu.WinListener createWinListener(JPopupMenu popup)
+ protected WinListener createWinListener(JPopupMenu popup)
{
- return null;
+ return new WinListener(popup);
}
/**
- * DOCUMENT ME!
+ * Method of the MenuElementInterface. It reacts to the selection
+ * changes in the menu. If this menu was selected, then it
+ * displayes popup menu associated with it and if this menu was
+ * deselected it hides the popup menu.
*
- * @param changed DOCUMENT ME!
+ * @param changed true if the menu was selected and false otherwise
*/
public void menuSelectionChanged(boolean changed)
{
+ // if this menu selection is true, then activate this menu and
+ // display popup associated with this menu
+ if (changed)
+ {
+ setArmed(true);
+ fireMenuSelected();
+
+ int x = 0;
+ int y = 0;
+ if (customMenuLocation == null)
+ {
+ // Calculate correct position of the popup. Note that location of the popup
+ // passed to show() should be relative to the popup's invoker
+ if (isTopLevelMenu())
+ y = this.getHeight();
+ else
+ x = this.getWidth();
+ }
+ else
+ {
+ x = customMenuLocation.x;
+ y = customMenuLocation.y;
+ }
+
+ getPopupMenu().show(this, x, y);
+ }
+
+ else
+ {
+ fireMenuDeselected();
+ popupMenu.setVisible(false);
+ setArmed(false);
+ }
}
/**
- * DOCUMENT ME!
+ * Method of MenuElement interface. Returns sub components of
+ * this menu.
*
- * @return DOCUMENT ME!
+ * @return array containing popupMenu that is associated with this menu
*/
public MenuElement[] getSubElements()
{
- return new MenuElement[] { popupMenu };
+ return new MenuElement[] { popupMenu };
}
/**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
+ * @return Returns reference to itself
*/
public Component getComponent()
{
@@ -628,48 +727,60 @@ public class JMenu extends JMenuItem imp
}
/**
- * DOCUMENT ME!
+ * This method is overriden with empty implementation, s.t the
+ * accelerator couldn't be set for the menu. The mnemonic should
+ * be used for the menu instead.
*
- * @param keystroke DOCUMENT ME!
+ * @param keystroke accelerator for this menu
*/
public void setAccelerator(KeyStroke keystroke)
{
- super.setAccelerator(keystroke);
+ throw new Error("setAccelerator() is not defined for JMenu. Use setMnemonic() instead.");
}
/**
- * DOCUMENT ME!
+ * This method process KeyEvent occuring when the menu is visible
*
- * @param event DOCUMENT ME!
+ * @param event The KeyEvent
*/
protected void processKeyEvent(KeyEvent event)
{
}
/**
- * DOCUMENT ME!
+ * Programatically performs click
*
- * @param time DOCUMENT ME!
+ * @param time Number of milliseconds for which this menu stays pressed
*/
public void doClick(int time)
{
+ getModel().setArmed(true);
+ getModel().setPressed(true);
+ try
+ {
+ java.lang.Thread.sleep(time);
+ }
+ catch (java.lang.InterruptedException e)
+ {
+ // probably harmless
+ }
+
+ getModel().setPressed(false);
+ getModel().setArmed(false);
+ popupMenu.show(this, this.getWidth(), 0);
}
/**
- * DOCUMENT ME!
+ * A string that describes this JMenu. Normally only used
+ * for debugging.
*
- * @return DOCUMENT ME!
+ * @return A string describing this JMenu
*/
protected String paramString()
{
return "JMenu";
}
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
public AccessibleContext getAccessibleContext()
{
if (accessibleContext == null)
@@ -678,156 +789,112 @@ public class JMenu extends JMenuItem imp
return accessibleContext;
}
- /**
- * DOCUMENT ME!
- */
protected class AccessibleJMenu extends AccessibleJMenuItem
implements AccessibleSelection
{
- private static final long serialVersionUID = -8131864021059524309L;
-
- /**
- * Creates a new AccessibleJMenu object.
- */
protected AccessibleJMenu()
{
}
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
public int getAccessibleChildrenCount()
{
return 0;
}
- /**
- * DOCUMENT ME!
- *
- * @param value0 DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
public Accessible getAccessibleChild(int value0)
{
return null;
}
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
public AccessibleSelection getAccessibleSelection()
{
return null;
}
- /**
- * DOCUMENT ME!
- *
- * @param value0 DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
public Accessible getAccessibleSelection(int value0)
{
return null;
}
- /**
- * DOCUMENT ME!
- *
- * @param value0 DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
public boolean isAccessibleChildSelected(int value0)
{
return false;
}
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
public AccessibleRole getAccessibleRole()
{
return AccessibleRole.MENU;
}
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
public int getAccessibleSelectionCount()
{
return 0;
}
- /**
- * DOCUMENT ME!
- *
- * @param value0 DOCUMENT ME!
- */
public void addAccessibleSelection(int value0)
{
}
- /**
- * DOCUMENT ME!
- *
- * @param value0 DOCUMENT ME!
- */
public void removeAccessibleSelection(int value0)
{
}
- /**
- * DOCUMENT ME!
- */
public void clearAccessibleSelection()
{
}
- /**
- * DOCUMENT ME!
- */
public void selectAllAccessibleSelection()
{
}
}
- /**
- * DOCUMENT ME!
- */
protected class WinListener extends WindowAdapter implements Serializable
{
- private static final long serialVersionUID = -6415815570638474823L;
-
JPopupMenu popupMenu;
+ private static final long serialVersionUID = -6415815570638474823L;
+
+ public WinListener(JPopupMenu popup)
+ {
+ }
- /**
- * Creates a new WinListener object.
- *
- * @param value0 DOCUMENT ME!
- * @param value1 DOCUMENT ME!
- */
- public WinListener(JPopupMenu value1)
+ public void windowClosing(WindowEvent event)
{
}
+ }
+
+ /** This class listens to ChangeEvent fired by menu's model*/
+ protected class MenuChangeListener implements ChangeListener
+ {
+ /** This method is invoked when there is change in menu's model property */
+ public void stateChanged(ChangeEvent e)
+ {
+ revalidate();
+ repaint();
+ }
+ }
+
+ /**
+ * This class listens to PropertyChangeEvents occuring in menu's action
+ */
+ protected class ActionChangedListener implements PropertyChangeListener
+ {
+ /** menu item associated with the action */
+ private JMenuItem menuItem;
+
+ /** Creates new ActionChangedListener and adds it to menuItem's action */
+ public ActionChangedListener(JMenuItem menuItem)
+ {
+ this.menuItem = menuItem;
+
+ Action a = menuItem.getAction();
+ if (a != null)
+ a.addPropertyChangeListener(this);
+ }
- /**
- * DOCUMENT ME!
- *
- * @param value0 DOCUMENT ME!
- */
- public void windowClosing(WindowEvent value0)
+ /**This method is invoked when some change occures in menuItem's action*/
+ public void propertyChange(PropertyChangeEvent evt)
{
+ // FIXME: Need to implement
}
}
}
Index: javax/swing/JPopupMenu.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JPopupMenu.java,v
retrieving revision 1.3.8.6
diff -c -p -u -r1.3.8.6 JPopupMenu.java
--- javax/swing/JPopupMenu.java 8 Jun 2004 09:28:42 -0000 1.3.8.6
+++ javax/swing/JPopupMenu.java 10 Jun 2004 18:45:53 -0000
@@ -96,6 +96,7 @@ public class JPopupMenu extends JCompone
lightWeightPopupEnabled = defaultLWPopupEnabled;
selectionModel = new DefaultSingleSelectionModel();
+ super.setVisible(false);
}
/**
Index: javax/swing/plaf/basic/BasicMenuUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicMenuUI.java,v
retrieving revision 1.1.2.5
diff -c -p -u -r1.1.2.5 BasicMenuUI.java
--- javax/swing/plaf/basic/BasicMenuUI.java 3 Jun 2004 14:21:53 -0000 1.1.2.5
+++ javax/swing/plaf/basic/BasicMenuUI.java 10 Jun 2004 18:45:53 -0000
@@ -1,5 +1,5 @@
/* BasicMenuUI.java
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -53,6 +53,7 @@ import javax.swing.JComponent;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
import javax.swing.MenuElement;
import javax.swing.MenuSelectionManager;
import javax.swing.UIDefaults;
@@ -71,12 +72,16 @@ import javax.swing.plaf.MenuItemUI;
/**
- * DOCUMENT ME!
+ * UI Delegate for JMenu
*/
public class BasicMenuUI extends BasicMenuItemUI
{
protected ChangeListener changeListener;
+
+ /* MenuListener listens to MenuEvents fired by JMenu */
protected MenuListener menuListener;
+
+ /* PropertyChangeListner that listens to propertyChangeEvents occuring in JMenu*/
protected PropertyChangeListener propertyChangeListener;
/**
@@ -84,52 +89,53 @@ public class BasicMenuUI extends BasicMe
*/
public BasicMenuUI()
{
- mouseInputListener = createMouseInputListener(menuItem);
- menuListener = createMenuListener(menuItem);
+ mouseInputListener = createMouseInputListener((JMenu) menuItem);
+ menuListener = createMenuListener((JMenu) menuItem);
+ propertyChangeListener = createPropertyChangeListener((JMenu) menuItem);
}
/**
- * DOCUMENT ME!
- *
- * @param c DOCUMENT ME!
+ * This method creates a new ChangeListener.
*
- * @return DOCUMENT ME!
+ * @return A new ChangeListener.
*/
protected ChangeListener createChangeListener(JComponent c)
{
- return null;
+ return new ChangeHandler();
}
/**
- * DOCUMENT ME!
+ * This method creates new MenuDragMouseListener to listen to mouse dragged events
+ * occuring in the Menu
*
- * @param c DOCUMENT ME!
+ * @param c the menu to listen to
*
- * @return DOCUMENT ME!
+ * @return The MenuDrageMouseListener
*/
protected MenuDragMouseListener createMenuDragMouseListener(JComponent c)
{
- return null;
+ return new MenuDragMouseHandler();
}
/**
- * DOCUMENT ME!
+ * This method creates new MenuDragKeyListener to listen to key events
*
- * @param c DOCUMENT ME!
+ * @param c the menu to listen to
*
- * @return DOCUMENT ME!
+ * @return The MenuKeyListener
*/
protected MenuKeyListener createMenuKeyListener(JComponent c)
{
- return null;
+ return new MenuKeyHandler();
}
/**
- * DOCUMENT ME!
+ * This method creates new MenuListener to listen to menu events
+ * occuring in the Menu
*
- * @param c DOCUMENT ME!
+ * @param c the menu to listen to
*
- * @return DOCUMENT ME!
+ * @return The MenuListener
*/
protected MenuListener createMenuListener(JComponent c)
{
@@ -137,11 +143,12 @@ public class BasicMenuUI extends BasicMe
}
/**
- * DOCUMENT ME!
+ * This method creates new MouseInputListener to listen to mouse input events
+ * occuring in the Menu
*
- * @param c DOCUMENT ME!
+ * @param c the menu to listen to
*
- * @return DOCUMENT ME!
+ * @return The MouseInputListener
*/
protected MouseInputListener createMouseInputListener(JComponent c)
{
@@ -149,53 +156,50 @@ public class BasicMenuUI extends BasicMe
}
/**
- * DOCUMENT ME!
+ * This method creates newPropertyChangeListener to listen to property changes
+ * occuring in the Menu
*
- * @param c DOCUMENT ME!
+ * @param c the menu to listen to
*
- * @return DOCUMENT ME!
+ * @return The PropertyChangeListener
*/
protected PropertyChangeListener createPropertyChangeListener(JComponent c)
{
- return null;
+ return new PropertyChangeHandler();
}
/**
- * DOCUMENT ME!
+ * This method creates a new BasicMenuUI.
*
- * @param x DOCUMENT ME!
+ * @param c The JComponent to create a UI for.
*
- * @return DOCUMENT ME!
+ * @return A new BasicMenuUI.
*/
- public static ComponentUI createUI(JComponent x)
+ public static ComponentUI createUI(JComponent c)
{
return new BasicMenuUI();
}
/**
- * DOCUMENT ME!
+ * Get the component's maximum size.
*
- * @param c DOCUMENT ME!
+ * @param c The JComponent for which to get maximum size
*
- * @return DOCUMENT ME!
+ * @return The maximum size of the component
*/
public Dimension getMaximumSize(JComponent c)
{
return null;
}
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
protected String getPropertyPrefix()
{
return null;
}
/**
- * DOCUMENT ME!
+ * Initializes any default properties that this UI has from the defaults for
+ * the Basic look and feel.
*/
protected void installDefaults()
{
@@ -214,14 +218,17 @@ public class BasicMenuUI extends BasicMe
}
/**
- * DOCUMENT ME!
+ * Installs any keyboard actions. The list of keys that need to be bound are
+ * listed in Basic look and feel's defaults.
+ *
*/
protected void installKeyboardActions()
{
+ // FIXME: Need to implement
}
/**
- * DOCUMENT ME!
+ * Creates and registers all the listeners for this UI delegate.
*/
protected void installListeners()
{
@@ -229,17 +236,13 @@ public class BasicMenuUI extends BasicMe
((JMenu) menuItem).addMenuListener(menuListener);
}
- /**
- * DOCUMENT ME!
- *
- * @param menu DOCUMENT ME!
- */
protected void setupPostTimer(JMenu menu)
{
}
/**
- * DOCUMENT ME!
+ * This method uninstalls the defaults and sets any objects created during
+ * install to null
*/
protected void uninstallDefaults()
{
@@ -255,30 +258,35 @@ public class BasicMenuUI extends BasicMe
}
/**
- * DOCUMENT ME!
+ * Uninstalls any keyboard actions. The list of keys used are listed in
+ * Basic look and feel's defaults.
*/
protected void uninstallKeyboardActions()
{
+ // FIXME: Need to implement
}
/**
- * DOCUMENT ME!
+ * Unregisters all the listeners that this UI delegate was using. In
+ * addition, it will also null any listeners that it was using.
*/
protected void uninstallListeners()
{
+ ((JMenu) menuItem).removeMouseListener(mouseInputListener);
+ ((JMenu) menuItem).removeMenuListener(menuListener);
+ ((JMenu) menuItem).removePropertyChangeListener(propertyChangeListener);
}
/**
- * DOCUMENT ME!
+ * This class is used by menus to handle mouse events occuring in the
+ * menu.
*/
protected class MouseInputHandler implements MouseInputListener
{
- protected MouseInputHandler()
- {
- }
-
public void mouseClicked(MouseEvent e)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.processMouseEvent(e);
}
public void mouseDragged(MouseEvent e)
@@ -289,34 +297,31 @@ public class BasicMenuUI extends BasicMe
public void mouseEntered(MouseEvent e)
{
- MenuSelectionManager manager = MenuSelectionManager.defaultManager();
- manager.setSelectedPath(getPath());
- manager.processMouseEvent(e);
-
- JMenu subMenu = (JMenu) menuItem;
- int x = 0;
- int y = 0;
+ /* When mouse enters menu item, it should be considered selected
- // location of the popup menu is relative to the invoker
- if (subMenu.isTopLevelMenu())
+ if (i) if this menu is a submenu in some other menu
+ (ii) or if this menu is in a menu bar and some other menu in a menu bar was just
+ selected. (If nothing was selected, menu should be pressed before
+ it will be selected)
+ */
+
+ JMenu menu = (JMenu) menuItem;
+ if (! menu.isTopLevelMenu()
+ || (menu.isTopLevelMenu()
+ && (((JMenuBar) menu.getParent()).isSelected())))
{
- JMenuBar mb = (JMenuBar) subMenu.getParent();
-
- // Subtract menuBar's insets.bottom and popupMenu's insets.top,
- // s.t. the space between menu bar and its popup menu is equal to
- // menuBar's margin. By default menuBar's margin is Insets(0,0,0,0).
- y = subMenu.getHeight() - mb.getInsets().bottom
- - subMenu.getPopupMenu().getInsets().top + mb.getMargin().bottom;
+ // set new selection and forward this event to MenuSelectionManager
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.setSelectedPath(getPath());
+ manager.processMouseEvent(e);
}
- else
- x = subMenu.getWidth();
-
- subMenu.getPopupMenu().show(subMenu, x, y);
}
public void mouseExited(MouseEvent e)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.processMouseEvent(e);
}
public void mouseMoved(MouseEvent e)
@@ -325,6 +330,37 @@ public class BasicMenuUI extends BasicMe
public void mousePressed(MouseEvent e)
{
+
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ JMenu menu = (JMenu) menuItem;
+ manager.processMouseEvent(e);
+
+ // Menu should be displayed when the menu is pressed only if
+ // it is top-level menu
+ if (menu.isTopLevelMenu())
+ {
+ if (menu.getPopupMenu().isVisible())
+ {
+ // If menu is visible and menu button was pressed..
+ // then need to cancel the menu
+ menu.fireMenuCanceled();
+ manager.clearSelectedPath();
+ }
+ else
+ {
+ // Display the menu
+ int x = 0;
+ int y = menu.getHeight();
+
+ menu.fireMenuSelected();
+ manager.setSelectedPath(getPath());
+
+ JMenuBar mb = (JMenuBar) menu.getParent();
+
+ // set selectedIndex of the selectionModel of a menuBar
+ mb.getSelectionModel().setSelectedIndex(mb.getComponentIndex(menu));
+ }
+ }
}
public void mouseReleased(MouseEvent e)
@@ -334,18 +370,141 @@ public class BasicMenuUI extends BasicMe
}
}
+ /**
+ * This class handles MenuEvents fired by the JMenu
+ */
protected class MenuHandler implements MenuListener
{
+ /**
+ * This method is called when menu is cancelled. The menu is cancelled
+ * when its popup menu is closed without selection.
+ *
+ * @param e The MenuEvent.
+ */
public void menuCanceled(MenuEvent e)
{
}
+ /**
+ * This method is called when menu is deselected.
+ *
+ * @param e The MenuEvent.
+ */
public void menuDeselected(MenuEvent e)
{
}
+ /**
+ * This method is called when menu is selected.
+ *
+ * @param e The MenuEvent.
+ */
public void menuSelected(MenuEvent e)
{
}
}
+
+ /**
+ * This class handles PropertyChangeEvents fired from the JMenu
+ */
+ protected class PropertyChangeHandler implements PropertyChangeListener
+ {
+ /**
+ * This method is called whenever one of the properties of the menu item
+ * changes.
+ *
+ * @param e The PropertyChangeEvent.
+ */
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ }
+ }
+
+ protected class ChangeHandler implements ChangeListener
+ {
+ public void stateChanged(ChangeEvent e)
+ {
+ // FIXME: It seems that this class is not used anywhere
+ }
+ }
+
+ /**
+ * This class handles mouse dragged events.
+ */
+ protected class MenuDragMouseHandler implements MenuDragMouseListener
+ {
+ /**
+ * Tbis method is invoked when mouse is dragged over the menu item.
+ *
+ * @param e The MenuDragMouseEvent
+ */
+ public void menuDragMouseDragged(MenuDragMouseEvent e)
+ {
+ }
+
+ /**
+ * Tbis method is invoked when mouse enters the menu item while it is
+ * being dragged.
+ *
+ * @param e The MenuDragMouseEvent
+ */
+ public void menuDragMouseEntered(MenuDragMouseEvent e)
+ {
+ }
+
+ /**
+ * Tbis method is invoked when mouse exits the menu item while
+ * it is being dragged
+ *
+ * @param e The MenuDragMouseEvent
+ */
+ public void menuDragMouseExited(MenuDragMouseEvent e)
+ {
+ }
+
+ /**
+ * Tbis method is invoked when mouse was dragged and released
+ * inside the menu item.
+ *
+ * @param e The MenuDragMouseEvent
+ */
+ public void menuDragMouseReleased(MenuDragMouseEvent e)
+ {
+ }
+ }
+
+ /**
+ * This class handles key events occuring when menu item is visible on the
+ * screen.
+ */
+ protected class MenuKeyHandler implements MenuKeyListener
+ {
+ /**
+ * This method is invoked when key has been pressed
+ *
+ * @param e A {@link MenuKeyEvent}.
+ */
+ public void menuKeyPressed(MenuKeyEvent e)
+ {
+ }
+
+ /**
+ * This method is invoked when key has been pressed
+ *
+ * @param e A {@link MenuKeyEvent}.
+ */
+ public void menuKeyReleased(MenuKeyEvent e)
+ {
+ }
+
+ /**
+ * This method is invoked when key has been typed
+ * It handles the mnemonic key for the menu item.
+ *
+ * @param e A {@link MenuKeyEvent}.
+ */
+ public void menuKeyTyped(MenuKeyEvent e)
+ {
+ }
+ }
}
More information about the Java-patches
mailing list