[gui][PATCH] Javadocs and other fixes
Olga Rodimina
rodimina@redhat.com
Mon Jun 14 14:28:00 GMT 2004
Hi,
This patch adds javadocs to JMenuBar & JPopupMenu and does few other
various fixes.
I'll be committing this patch to java-gui-branch.
Olga.
-------------- next part --------------
? .snprj
? libjava.proj
? patch
? popup_Patch
? resources
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2660.2.178
diff -c -p -u -r1.2660.2.178 ChangeLog
--- ChangeLog 13 Jun 2004 07:21:42 -0000 1.2660.2.178
+++ ChangeLog 14 Jun 2004 14:05:51 -0000
@@ -1,3 +1,37 @@
+2004-06-14 Olga Rodimina <rodimina@redhat.com>
+
+ * javax/swing/JLayeredPane.java:
+ (remove): Revalidate and repaint layered pane after
+ the component was removed.
+ javax/swing/JMenu.java:
+ (setVisible): Display popup menu at the user location,
+ if one was set by the user.
+ (setMenuLocation): Reimplemented. Fixed javadoc.
+ * javax/swing/JMenuBar.java: Added javadoc.
+ (BORDER_PAINTED_CHANGED_PROPERTY): New Property.
+ (MODEL_CHANGED_PROPERTY): New Property.
+ (isSelected): Implemented.
+ (setBorderPainted): Fire PropertyChangeEvent
+ if paintBorder property changes.
+ (setSelected): Implemented.
+ (setSelectionModel): Implemented.
+ * javax/swing/JPopupMenu.java: Added Javadoc
+ (pack): Implemented.
+ (setVisible): Reimplemented.
+ (show): Fixed location.
+ (JPopupMenu.LigthWeightPopup): Reimplemented to use
+ Container instead of JPanel.
+ * javax/swing/MenuSelectionManager.java: Added Javadocs.
+ (clearSelectedPath): Reimplemented to clear selectedPath
+ in reverse order.
+ (processMouseEvent): Reimplemented.
+ (setSelectedPath): Fire stateChange event indicating that
+ selected menu path has changed.
+ (getPath): Change to use ArrayList instead of Vector.
+ * javax/swing/plaf/basic/BasicMenuBarUI.java:
+ (installUI): call installKeyboardActions().
+ (uninstallUI): call uninstallKeyboardActions().
+
2004-06-13 Michael Koch <konqueror@gmx.de>
* javax/swing/text/DefaultCaret.java,
Index: javax/swing/JLayeredPane.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JLayeredPane.java,v
retrieving revision 1.6.8.3
diff -c -p -u -r1.6.8.3 JLayeredPane.java
--- javax/swing/JLayeredPane.java 7 Jun 2004 12:41:08 -0000 1.6.8.3
+++ javax/swing/JLayeredPane.java 14 Jun 2004 14:05:53 -0000
@@ -494,6 +494,8 @@ public class JLayeredPane extends JCompo
decrLayer (layer);
componentToLayer.remove (c);
super.remove (index);
+ revalidate();
+ repaint();
}
/**
Index: javax/swing/JMenu.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JMenu.java,v
retrieving revision 1.3.8.6
diff -c -p -u -r1.3.8.6 JMenu.java
--- javax/swing/JMenu.java 10 Jun 2004 19:32:51 -0000 1.3.8.6
+++ javax/swing/JMenu.java 14 Jun 2004 14:05:53 -0000
@@ -72,7 +72,6 @@ public class JMenu extends JMenuItem imp
/** 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();
@@ -83,7 +82,7 @@ public class JMenu extends JMenuItem imp
/** MenuEvent */
private MenuEvent menuEvent = new MenuEvent(this);
- /*Amount of time, in milliseconds, that should pass before popupMenu
+ /*Amount of time, in milliseconds, that should pass before popupMenu
associated with this menu appears or disappers */
private int delay;
@@ -91,7 +90,7 @@ public class JMenu extends JMenuItem imp
protected WinListener popupListener;
/** Location at which popup menu associated with this menu will be displayed*/
- private Point customMenuLocation;
+ private Point menuLocation;
/**
* Creates a new JMenu object.
@@ -412,13 +411,14 @@ public class JMenu extends JMenuItem imp
/**
* Sets location at which popup menu should be displayed
+ * The location given is relative to this menu item
*
* @param x x-coordinate of the menu location
* @param y y-coordinate of the menu location
*/
public void setMenuLocation(int x, int y)
{
- popupMenu.setLocation(x, y);
+ menuLocation = new Point(x, y);
}
/**
@@ -681,7 +681,7 @@ public class JMenu extends JMenuItem imp
int x = 0;
int y = 0;
- if (customMenuLocation == null)
+ if (menuLocation == null)
{
// Calculate correct position of the popup. Note that location of the popup
// passed to show() should be relative to the popup's invoker
@@ -689,14 +689,11 @@ public class JMenu extends JMenuItem imp
y = this.getHeight();
else
x = this.getWidth();
+
+ getPopupMenu().show(this, x, y);
}
else
- {
- x = customMenuLocation.x;
- y = customMenuLocation.y;
- }
-
- getPopupMenu().show(this, x, y);
+ getPopupMenu().show(this, menuLocation.x, menuLocation.y);
}
else
@@ -715,7 +712,7 @@ public class JMenu extends JMenuItem imp
*/
public MenuElement[] getSubElements()
{
- return new MenuElement[] { popupMenu };
+ return new MenuElement[] { popupMenu };
}
/**
Index: javax/swing/JMenuBar.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JMenuBar.java,v
retrieving revision 1.2.18.4
diff -c -p -u -r1.2.18.4 JMenuBar.java
--- javax/swing/JMenuBar.java 9 Jun 2004 20:55:10 -0000 1.2.18.4
+++ javax/swing/JMenuBar.java 14 Jun 2004 14:05:53 -0000
@@ -66,14 +66,25 @@ import javax.swing.plaf.MenuItemUI;
/**
- * DOCUMENT ME!
+ * JMenuBar
*/
public class JMenuBar extends JComponent implements Accessible, MenuElement
{
- private static final long serialVersionUID = -8191026883931977036L;
+ /** Fired in a PropertyChangeEvent when the "borderPainted" property changes. */
+ public static final String BORDER_PAINTED_CHANGED_PROPERTY = "borderPainted";
+
+ /** Fired in a PropertyChangeEvent when the "model" changes. */
+ public static final String MODEL_CHANGED_PROPERTY = "model";
+ private static final long serialVersionUID = -8191026883931977036L;
+
+ /** JMenuBar's model. It keeps track of selected menu's index */
private transient SingleSelectionModel selectionModel;
- private boolean paintBorder;
+
+ /* borderPainted property indicating if the menuBar's border will be painted*/
+ private boolean borderPainted;
+
+ /* margin between menu bar's border and its menues*/
private Insets margin;
/**
@@ -82,16 +93,16 @@ public class JMenuBar extends JComponent
public JMenuBar()
{
selectionModel = new DefaultSingleSelectionModel();
- paintBorder = true;
+ borderPainted = true;
updateUI();
}
/**
- * DOCUMENT ME!
+ * Adds menu to the menu bar
*
- * @param c DOCUMENT ME!
+ * @param c menu to add
*
- * @return DOCUMENT ME!
+ * @return reference to the added menu
*/
public JMenu add(JMenu c)
{
@@ -109,20 +120,15 @@ public class JMenuBar extends JComponent
super.addNotify();
}
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
public AccessibleContext getAccessibleContext()
{
return null;
}
/**
- * DOCUMENT ME!
+ * Returns reference to this menu bar
*
- * @return DOCUMENT ME!
+ * @return reference to this menu bar
*/
public Component getComponent()
{
@@ -130,12 +136,12 @@ public class JMenuBar extends JComponent
}
/**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
+ * Returns component at the specified index.
*
- * @return DOCUMENT ME!
+ * @param i index of the component to get
*
+ * @return component at the specified index. Null is returned if
+ * component at the specified index doesn't exist.
* @deprecated Replaced by getComponent(int)
*/
public Component getComponentAtIndex(int i)
@@ -144,11 +150,12 @@ public class JMenuBar extends JComponent
}
/**
- * DOCUMENT ME!
+ * Returns index of the specified component
*
- * @param c DOCUMENT ME!
+ * @param c Component to search for
*
- * @return DOCUMENT ME!
+ * @return index of the specified component. -1 is returned if
+ * specified component doesnt' exist in the menu bar.
*/
public int getComponentIndex(Component c)
{
@@ -179,9 +186,9 @@ public class JMenuBar extends JComponent
}
/**
- * DOCUMENT ME!
+ * Returns margin betweeen menu bar's border and its menues
*
- * @return DOCUMENT ME!
+ * @return margin between menu bar's border and its menues
*/
public Insets getMargin()
{
@@ -192,11 +199,13 @@ public class JMenuBar extends JComponent
}
/**
- * DOCUMENT ME!
+ * Return menu at the specified index. If component at the
+ * specified index is not a menu, then null is returned.
*
- * @param index DOCUMENT ME!
+ * @param index index to look for the menu
*
- * @return DOCUMENT ME!
+ * @return menu at specified index, or null if menu doesn't exist
+ * at the specified index.
*/
public JMenu getMenu(int index)
{
@@ -217,9 +226,9 @@ public class JMenuBar extends JComponent
}
/**
- * DOCUMENT ME!
+ * Returns selection model for this menu bar.
*
- * @return DOCUMENT ME!
+ * @return selection mdoel for this menu bar.
*/
public SingleSelectionModel getSelectionModel()
{
@@ -227,9 +236,10 @@ public class JMenuBar extends JComponent
}
/**
- * DOCUMENT ME!
+ * Method of MenuElement interface. It returns subcomponents
+ * of the menu bar, which are all the menues that it contains.
*
- * @return DOCUMENT ME!
+ * @return MenuElement[] array containing menues in this menu bar
*/
public MenuElement[] getSubElements()
{
@@ -242,19 +252,21 @@ public class JMenuBar extends JComponent
}
/**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
+ * Set the "UI" property of the menu bar, which is a look and feel class
+ * responsible for handling the menuBar's input events and painting it.
+ *
+ * @return The current "UI" property
+ */
public MenuBarUI getUI()
{
return (MenuBarUI) ui;
}
/**
- * DOCUMENT ME!
+ * This method returns a name to identify which look and feel class will be
+ * the UI delegate for the menu bar.
*
- * @return DOCUMENT ME!
+ * @return The Look and Feel classID. "MenuItemUI"
*/
public String getUIClassID()
{
@@ -262,39 +274,31 @@ public class JMenuBar extends JComponent
}
/**
- * DOCUMENT ME!
+ * Returns true if menu bar paints its border and false otherwise
*
- * @return DOCUMENT ME!
+ * @return true if menu bar paints its border and false otherwise
*/
public boolean isBorderPainted()
{
- return paintBorder;
+ return borderPainted;
}
/**
- * DOCUMENT ME!
+ * Returns true if some menu in menu bar is selected.
*
- * @return DOCUMENT ME!
- */
- public boolean isManagingFocus()
- {
- return true;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
+ * @return true if some menu in menu bar is selected and false otherwise
*/
public boolean isSelected()
{
- return false;
+ return selectionModel.isSelected();
}
/**
- * DOCUMENT ME!
+ * This method does nothing by default. This method is need for the
+ * MenuElement interface to be implemented.
*
- * @param isIncluded DOCUMENT ME!
+ * @param isIncluded true if menuBar is included in the selection
+ * and false otherwise
*/
public void menuSelectionChanged(boolean isIncluded)
{
@@ -302,13 +306,14 @@ public class JMenuBar extends JComponent
}
/**
- * DOCUMENT ME!
+ * Paints border of the menu bar, if its borderPainted property is set to
+ * true.
*
- * @param g DOCUMENT ME!
+ * @param g The graphics context with which to paint the border
*/
protected void paintBorder(Graphics g)
{
- if (paintBorder)
+ if (borderPainted)
getBorder().paintBorder(this, g, 0, 0, getSize(null).width,
getSize(null).height);
}
@@ -365,7 +370,14 @@ public class JMenuBar extends JComponent
*/
public void setBorderPainted(boolean b)
{
- paintBorder = b;
+ boolean old = borderPainted;
+ borderPainted = b;
+ if (b != old)
+ {
+ firePropertyChange(BORDER_PAINTED_CHANGED_PROPERTY, old, b);
+ revalidate();
+ repaint();
+ }
}
/**
@@ -388,27 +400,42 @@ public class JMenuBar extends JComponent
}
/**
- * DOCUMENT ME!
+ * Changes menu bar's selection to the specifies menu.
+ * This method updates selected index of menu bar's model,
+ * which results in a model firing change event.
*
- * @param sel DOCUMENT ME!
+ * @param sel menu to select
*/
public void setSelected(Component sel)
{
+ int index = getComponentIndex(sel);
+ selectionModel.setSelectedIndex(index);
}
/**
- * DOCUMENT ME!
+ * Sets menuBar's selection model to the one specified
*
- * @param model DOCUMENT ME!
+ * @param model SingleSelectionModel that needs to be set for this menu bar
*/
public void setSelectionModel(SingleSelectionModel model)
{
+ selectionModel = model;
+ if (selectionModel != model)
+ {
+ SingleSelectionModel oldModel = selectionModel;
+
+ selectionModel = model;
+
+ firePropertyChange(MODEL_CHANGED_PROPERTY, oldModel,
+ this.selectionModel);
+ }
}
/**
- * DOCUMENT ME!
+ * Set the "UI" property of the menu bar, which is a look and feel class
+ * responsible for handling menuBar's input events and painting it.
*
- * @param ui DOCUMENT ME!
+ * @param ui The new "UI" property
*/
public void setUI(MenuBarUI ui)
{
@@ -416,7 +443,8 @@ public class JMenuBar extends JComponent
}
/**
- * DOCUMENT ME!
+ * Set the "UI" property to a class constructed, via the {@link
+ * UIManager}, from the current look and feel.
*/
public void updateUI()
{
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 14 Jun 2004 14:05:53 -0000
@@ -52,6 +52,7 @@ import java.awt.Point;
import java.awt.Window;
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;
@@ -68,24 +69,60 @@ import javax.swing.plaf.PopupMenuUI;
/**
* DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
*/
public class JPopupMenu extends JComponent implements Accessible, MenuElement
{
private static final long serialVersionUID = -8336996630009646009L;
-
+
+ /** name for the UI delegate for this menuItem. */
private static final String uiClassID = "PopupMenuUI";
- private static final Object defaultLWPopupEnabledKey = null;
- private static boolean defaultLWPopupEnabled = true;
+
+ /* indicates if popup's menu border should be painted*/
+ private boolean borderPainted = true;
+
+ /** Flag indicating whether lightweight, mediumweight or heavyweight popup
+ is used to display menu items.
+
+ These are the possible cases:
+
+ 1. if DefaultLightWeightPopupEnabled true
+ (i) use lightweight container if popup feets inside top-level window
+ (ii) only use heavyweight container (JWindow) if popup doesn't fit.
+
+ 2. if DefaultLightWeightPopupEnabled false
+ (i) if popup fits, use awt.Panel (mediumWeight)
+ (ii) if popup doesn't fit, use JWindow (heavyWeight)
+ */
+ private static boolean DefaultLightWeightPopupEnabled = true;
+
+ /* Component that invokes popup menu. */
transient Component invoker;
- private int locationX;
- private int locationY;
+
+ /* Label for this popup menu */
private String label;
- private boolean paintBorder;
+
+ /*Amount of space between menuItem's in JPopupMenu and JPopupMenu's border */
private Insets margin;
+
+ /** Indicates whether ligthWeight container can be used to display popup
+ menu. This flag is the same as DefaultLightWeightPopupEnabled, but setting
+ this flag can change popup menu after creation of the object */
private boolean lightWeightPopupEnabled;
+
+ /** SelectionModel that keeps track of menu selection. */
private SingleSelectionModel selectionModel;
+
+ /* Popup that is used to display JPopupMenu */
private transient Popup popup;
- private Point location;
+
+ /* Location of the popup */
+ private Point popupLocation;
+
+ /* Bound Property indicating visibility of the popup menu*/
+ public static final String VISIBLE_CHANGED_PROPERTY = "visible";
/**
* Creates a new JPopupMenu object.
@@ -93,15 +130,17 @@ public class JPopupMenu extends JCompone
public JPopupMenu()
{
updateUI();
-
- lightWeightPopupEnabled = defaultLWPopupEnabled;
+
+ lightWeightPopupEnabled = DefaultLightWeightPopupEnabled;
selectionModel = new DefaultSingleSelectionModel();
+
+ super.setVisible(false);
}
/**
- * Creates a new JPopupMenu object.
+ * Creates a new JPopupMenu with specified label
*
- * @param label DOCUMENT ME!
+ * @param label Label for popup menu.
*/
public JPopupMenu(String label)
{
@@ -133,11 +172,11 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Adds given menu item to the popup menu
*
- * @param item DOCUMENT ME!
+ * @param item menu item to add to the popup menu
*
- * @return DOCUMENT ME!
+ * @return menu item that was added to the popup menu
*/
public JMenuItem add(JMenuItem item)
{
@@ -146,11 +185,12 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Constructs menu item with a specified label and adds it to
+ * popup menu
*
- * @param text DOCUMENT ME!
+ * @param text label for the menu item to be added
*
- * @return DOCUMENT ME!
+ * @return constructed menu item that was added to the popup menu
*/
public JMenuItem add(String text)
{
@@ -159,22 +199,27 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Constructs menu item associated with the specified action
+ * and adds it to the popup menu
*
- * @param action DOCUMENT ME!
+ * @param action Action for the new menu item
*
- * @return DOCUMENT ME!
+ * @return menu item that was added to the menu
*/
public JMenuItem add(Action action)
{
JMenuItem item = new JMenuItem(action);
+
+ if (action != null)
+ action.addPropertyChangeListener(createActionChangeListener(item));
+
return add(item);
}
/**
- * DOCUMENT ME!
+ * Revomes component at the given index from the menu.
*
- * @param index DOCUMENT ME!
+ * @param index index of the component that will be removed in the menu
*/
public void remove(int index)
{
@@ -194,10 +239,11 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Create menu item associated with the given action
+ * and inserts it into the popup menu at the specified index
*
- * @param action DOCUMENT ME!
- * @param index DOCUMENT ME!
+ * @param action Action for the new menu item
+ * @param index index in the popup menu at which to insert new menu item.
*/
public void insert(Action action, int index)
{
@@ -206,10 +252,11 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Insert given component to the popup menu at the
+ * specified index
*
- * @param component DOCUMENT ME!
- * @param index DOCUMENT ME!
+ * @param component Component to insert
+ * @param index Index at which to insert given component
*/
public void insert(Component component, int index)
{
@@ -217,10 +264,10 @@ public class JPopupMenu extends JCompone
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 100.0;
constraints.weighty = 100.0;
-
+
if (index == -1)
- index = getComponents().length;
-
+ index = getComponents().length;
+
constraints.gridy = index;
super.add(component, constraints, index);
@@ -239,41 +286,45 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Paints popup menu's border if borderPainted is true
*
- * @param graphics DOCUMENT ME!
+ * @param graphics graphics context used to paint this popup's menu border.
*/
- protected void paintBorder(Graphics graphics)
+ protected void borderPainted(Graphics graphics)
{
- if (paintBorder)
+ if (borderPainted)
getBorder().paintBorder(this, graphics, 0, 0, getSize(null).width,
getSize(null).height);
}
/**
- * DOCUMENT ME!
+ * Returns flag indicating if newly created JPopupMenu will use
+ * heavyweight or lightweight container to display its menu items
*
- * @return DOCUMENT ME!
+ * @return true if JPopupMenu will use lightweight container to display
+ * menu items by default, and false otherwise.
*/
public static boolean getDefaultLightWeightPopupEnabled()
{
- return defaultLWPopupEnabled;
+ return DefaultLightWeightPopupEnabled;
}
/**
- * DOCUMENT ME!
+ * Sets whether JPopupMenu should use ligthWeight container to
+ * display it menu items by default
*
- * @param enabled DOCUMENT ME!
+ * @param enabled true if JPopupMenu should use lightweight container
+ * for displaying its menu items, and false otherwise.
*/
public static void setDefaultLightWeightPopupEnabled(boolean enabled)
{
- defaultLWPopupEnabled = enabled;
+ DefaultLightWeightPopupEnabled = enabled;
}
/**
- * DOCUMENT ME!
+ * This method returns the UI used to display the JPopupMenu.
*
- * @return DOCUMENT ME!
+ * @return The UI used to display the JPopupMenu.
*/
public PopupMenuUI getUI()
{
@@ -281,9 +332,10 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Set the "UI" property of the menu item, which is a look and feel class
+ * responsible for handling popupMenu's input events and painting it.
*
- * @param ui DOCUMENT ME!
+ * @param ui The new "UI" property
*/
public void setUI(PopupMenuUI ui)
{
@@ -291,7 +343,8 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * This method sets this menuItem's UI to the UIManager's default for the
+ * current look and feel.
*/
public void updateUI()
{
@@ -300,9 +353,10 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * This method returns a name to identify which look and feel class will be
+ * the UI delegate for the menuItem.
*
- * @return DOCUMENT ME!
+ * @return The Look and Feel classID. "PopupMenuUI"
*/
public String getUIClassID()
{
@@ -310,9 +364,10 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Returns selectionModel used by this popup menu to keep
+ * track of the selection.
*
- * @return DOCUMENT ME!
+ * @return popup menu's selection model
*/
public SingleSelectionModel getSelectionModel()
{
@@ -320,9 +375,9 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Sets selection model for this popup menu
*
- * @param model DOCUMENT ME!
+ * @param model new selection model of this popup menu
*/
public void setSelectionModel(SingleSelectionModel model)
{
@@ -357,9 +412,11 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Returns true if this popup menu will display its menu item in
+ * a lightweight container and false otherwise.
*
- * @return DOCUMENT ME!
+ * @return true if this popup menu will display its menu items
+ * in a lightweight container and false otherwise.
*/
public boolean isLightWeightPopupEnabled()
{
@@ -377,9 +434,9 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Returns label for this popup menu
*
- * @return DOCUMENT ME!
+ * @return label for this popup menu
*/
public String getLabel()
{
@@ -387,9 +444,9 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Sets label for this popup menu
*
- * @param label DOCUMENT ME!
+ * @param label label for this popup menu
*/
public void setLabel(String label)
{
@@ -397,16 +454,18 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Adds separator to this popup menu
*/
public void addSeparator()
{
+ // FIXME: Need to implement
}
/**
- * DOCUMENT ME!
+ * Adds popupMenuListener to listen for PopupMenuEvents fired
+ * by the JPopupMenu
*
- * @param listener DOCUMENT ME!
+ * @param listener PopupMenuListener to add to JPopupMenu
*/
public void addPopupMenuListener(PopupMenuListener listener)
{
@@ -414,23 +473,29 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Removes PopupMenuListener from JPopupMenu's list of listeners
*
- * @param listener DOCUMENT ME!
+ * @param listener PopupMenuListener which needs to be removed
*/
public void removePopupMenuListener(PopupMenuListener listener)
{
listenerList.remove(PopupMenuListener.class, listener);
}
+ /**
+ * Returns array of PopupMenuListeners that are listening to JPopupMenu
+ *
+ * @return Array of PopupMenuListeners that are listening to JPopupMenu
+ */
public PopupMenuListener[] getPopupMenuListeners()
{
- return ((PopupMenuListener[])
- listenerList.getListeners(PopupMenuListener.class));
+ return ((PopupMenuListener[]) listenerList.getListeners(PopupMenuListener.class));
}
/**
- * DOCUMENT ME!
+ * This method calls popupMenuWillBecomeVisible() of popup menu's
+ * PopupMenuListeners. This method is invoked just before popup menu
+ * will appear on the screen.
*/
protected void firePopupMenuWillBecomeVisible()
{
@@ -441,7 +506,9 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * This method calls popupMenuWillBecomeInvisible() of popup
+ * menu's PopupMenuListeners. This method is invoked just before popup
+ * menu will disappear from the screen
*/
protected void firePopupMenuWillBecomeInvisible()
{
@@ -452,7 +519,10 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * This method calls popupMenuCanceled() of popup menu's PopupMenuListeners.
+ * This method is invoked just before popup menu is cancelled. This happens
+ * when popup menu is closed without selecting any of its menu items. This
+ * usually happens when the top-level window is resized or moved.
*/
protected void firePopupMenuCanceled()
{
@@ -463,16 +533,18 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * This methods sets popup menu's size to its' preferred size. If the
+ * popup menu's size is previously set it will be ignored.
*/
public void pack()
{
+ super.setSize(null);
}
/**
- * DOCUMENT ME!
+ * Return visibility of the popup menu
*
- * @return DOCUMENT ME!
+ * @return true if popup menu is visible on the screen and false otherwise.
*/
public boolean isVisible()
{
@@ -480,90 +552,90 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Sets visibility property of this popup menu. If the property is
+ * set to true then popup menu will be dispayed and popup menu will
+ * hide itself if visible property is set to false.
*
- * @param visible DOCUMENT ME!
+ * @param visible true if popup menu will become visible and false otherwise.
*/
public void setVisible(boolean visible)
{
+ boolean old = isVisible();
super.setVisible(visible);
-
- firePopupMenuWillBecomeVisible();
-
- if (visible)
+ if (old != isVisible())
{
- Container rootContainer = (Container) SwingUtilities.getRoot(invoker);
+ firePropertyChange(VISIBLE_CHANGED_PROPERTY, old, (boolean) isVisible());
+ if (visible)
+ {
+ firePopupMenuWillBecomeVisible();
+ Container rootContainer = (Container) SwingUtilities.getRoot(invoker);
- boolean fit = true;
- Dimension size;
+ boolean fit = true;
+ Dimension size;
- // Determine the size of the popup menu
- if (this.getSize().width == 0 && this.getSize().width == 0)
- size = this.getPreferredSize();
+ // Determine the size of the popup menu
+ if (this.getSize().width == 0 && this.getSize().width == 0)
+ size = this.getPreferredSize();
+ else
+ size = this.getSize();
+ if ((size.width > (rootContainer.getWidth() - popupLocation.x))
+ || (size.height > (rootContainer.getHeight() - popupLocation.y)))
+ fit = false;
+ if (lightWeightPopupEnabled && fit)
+ popup = new LightWeightPopup(this);
+ else
+ {
+ if (fit)
+ popup = new MediumWeightPopup(this);
+ else
+ popup = new HeavyWeightPopup(this);
+ }
+ if (popup instanceof LightWeightPopup
+ || popup instanceof MediumWeightPopup)
+ {
+ JLayeredPane layeredPane;
+ layeredPane = SwingUtilities.getRootPane(invoker)
+ .getLayeredPane();
+ Point p = new Point(popupLocation.x, popupLocation.y);
+ SwingUtilities.convertPointFromScreen(p, layeredPane);
+ popup.show(p.x, p.y, size.width, size.height);
+ }
+ else
+ popup.show(popupLocation.x, popupLocation.y, size.width,
+ size.height);
+ }
else
- size = this.getSize();
+ {
+ // popup menu was cancelled without selection
+ if (! getSelectionModel().isSelected())
+ firePopupMenuCanceled();
- if ((size.width > (rootContainer.getWidth() - locationX))
- || (size.height > (rootContainer.getHeight() - locationY)))
- fit = false;
+ firePopupMenuWillBecomeInvisible();
- if (lightWeightPopupEnabled && fit)
- popup = new LightWeightPopup(this);
- else
- {
- if (fit)
- popup = new MediumWeightPopup(this);
- else
- popup = new HeavyWeightPopup(this);
+ popup.hide();
}
-
- if (popup instanceof LightWeightPopup
- || popup instanceof MediumWeightPopup)
- {
- JLayeredPane layeredPane;
- layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane();
- Point lp = layeredPane.getLocationOnScreen();
- Point r = SwingUtilities.getRoot(invoker).getLocationOnScreen();
- int px = locationX - (lp.x - r.x);
- int py = locationY - (lp.y - r.y);
- popup.show(px, py, size.width, size.height);
- }
- else
- popup.show(locationX, locationY, size.width, size.height);
- }
- else
- {
- firePopupMenuWillBecomeInvisible();
- popup.hide();
}
}
/**
- * DOCUMENT ME!
+ * Sets location of the popup menu.
*
- * @param x DOCUMENT ME!
- * @param y DOCUMENT ME!
+ * @param x X coordinate of the popup menu's location
+ * @param y Y coordinate of the popup menu's location
*/
public void setLocation(int x, int y)
{
- locationX = x;
- locationY = y;
- }
+ if (popupLocation == null)
+ popupLocation = new Point();
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- private boolean isPopupMenu()
- {
- return true;
+ popupLocation.x = x;
+ popupLocation.y = y;
}
/**
- * DOCUMENT ME!
+ * Returns popup menu's invoker.
*
- * @return DOCUMENT ME!
+ * @return popup menu's invoker
*/
public Component getInvoker()
{
@@ -571,9 +643,9 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Sets popup menu's invoker.
*
- * @param component DOCUMENT ME!
+ * @param component The new invoker of this popup menu
*/
public void setInvoker(Component component)
{
@@ -581,43 +653,29 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
- *
- * @param component DOCUMENT ME!
- * @param x DOCUMENT ME!
- * @param y DOCUMENT ME!
+ * This method displays JPopupMenu on the screen at the specified
+ * location. Note that x and y coordinates given to this method
+ * should be expressed in terms of the popup menus' invoker.
+ *
+ * @param component Invoker for this popup menu
+ * @param x x-coordinate of the popup menu relative to the specified invoker
+ * @param y y-coordiate of the popup menu relative to the specified invoker
*/
public void show(Component component, int x, int y)
{
setInvoker(component);
-
- Point rootOnScreen;
- rootOnScreen = SwingUtilities.getRoot(invoker).getLocationOnScreen();
- Point invokerOnScreen = invoker.getLocationOnScreen();
-
- int popupX = (invokerOnScreen.x - rootOnScreen.x) + x;
- int popupY = (invokerOnScreen.y - rootOnScreen.y) + y;
-
- setLocation(popupX , popupY);
+ Point p = new Point(x, y);
+ SwingUtilities.convertPointToScreen(p, component);
+ setLocation(p.x, p.y);
setVisible(true);
}
/**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- JPopupMenu getRootPopupMenu()
- {
- return null;
- }
-
- /**
- * DOCUMENT ME!
+ * Returns component located at the specified index in the popup menu
*
- * @param index DOCUMENT ME!
+ * @param index index of the component to return
*
- * @return DOCUMENT ME!
+ * @return component located at the specified index in the popup menu
*
* @deprecated Replaced by getComponent(int)
*/
@@ -627,11 +685,11 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Returns index of the specified component in the popup menu
*
- * @param component DOCUMENT ME!
+ * @param component Component to look for
*
- * @return DOCUMENT ME!
+ * @return index of the specified component in the popup menu
*/
public int getComponentIndex(Component component)
{
@@ -647,9 +705,9 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Sets size of the popup
*
- * @param size DOCUMENT ME!
+ * @param size Dimensions representing new size of the popup menu
*/
public void setPopupSize(Dimension size)
{
@@ -657,20 +715,20 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Sets size of the popup menu
*
- * @param x DOCUMENT ME!
- * @param y DOCUMENT ME!
+ * @param width width for the new size
+ * @param height height for the new size
*/
- public void setPopupSize(int x, int y)
+ public void setPopupSize(int width, int height)
{
- super.setSize(x, y);
+ super.setSize(width, height);
}
/**
- * DOCUMENT ME!
+ * Selects specified component in this popup menu.
*
- * @param selected DOCUMENT ME!
+ * @param selected component to select
*/
public void setSelected(Component selected)
{
@@ -679,29 +737,30 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Checks if this popup menu paints its border.
*
- * @return DOCUMENT ME!
+ * @return true if this popup menu paints its border and false otherwise.
*/
public boolean isBorderPainted()
{
- return paintBorder;
+ return borderPainted;
}
/**
- * DOCUMENT ME!
+ * Sets if the border of the popup menu should be
+ * painter or not.
*
- * @param painted DOCUMENT ME!
+ * @param painted true if the border should be painted and false otherwise
*/
public void setBorderPainted(boolean painted)
{
- paintBorder = painted;
+ borderPainted = painted;
}
/**
- * DOCUMENT ME!
+ * Returns margin for this popup menu.
*
- * @return DOCUMENT ME!
+ * @return margin for this popup menu.
*/
public Insets getMargin()
{
@@ -709,9 +768,10 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * A string that describes this JPopupMenu. Normally only used
+ * for debugging.
*
- * @return DOCUMENT ME!
+ * @return A string describing this JMenuItem
*/
protected String paramString()
{
@@ -719,12 +779,12 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
- *
- * @param event DOCUMENT ME!
- * @param path DOCUMENT ME!
- * @param manager DOCUMENT ME!
- */
+ * Process mouse events forwarded from MenuSelectionManager.
+ *
+ * @param event event forwarded from MenuSelectionManager
+ * @param path path to the menu element from which event was generated
+ * @param manager MenuSelectionManager for the current menu hierarchy
+ */
public void processMouseEvent(MouseEvent event, MenuElement[] path,
MenuSelectionManager manager)
{
@@ -743,18 +803,20 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Method of MenuElement Interface. It is invoked when
+ * popupMenu's selection has changed
*
- * @param changed DOCUMENT ME!
+ * @param changed true if this popupMenu is part of current menu
+ * hierarchy and false otherwise.
*/
public void menuSelectionChanged(boolean changed)
{
}
/**
- * DOCUMENT ME!
+ * Return subcomonents of this popup menu.
*
- * @return DOCUMENT ME!
+ * @return Array containing menuItem's of belonging to this popup menu.
*/
public MenuElement[] getSubElements()
{
@@ -768,9 +830,9 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Method of the MenuElement interface. Returns reference to itself.
*
- * @return DOCUMENT ME!
+ * @return Returns reference to itself
*/
public Component getComponent()
{
@@ -778,16 +840,16 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Checks if observing mouse event should trigger popup
+ * menu to show on the screen.
*
- * @param event DOCUMENT ME!
+ * @param event MouseEvent to check
*
- * @return DOCUMENT ME!
+ * @return true if the observing mouse event is popup trigger and false otherwise
*/
public boolean isPopupTrigger(MouseEvent event)
{
- return ((PopupMenuUI)getUI()).isPopupTrigger(event);
-
+ return ((PopupMenuUI) getUI()).isPopupTrigger(event);
}
/**
@@ -804,92 +866,97 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * This interface is used to display menu items of the JPopupMenu
*/
private interface Popup
{
/**
- * DOCUMENT ME!
+ * Displays container on the screen
*
- * @param x DOCUMENT ME!
- * @param y DOCUMENT ME!
- * @param width DOCUMENT ME!
- * @param height DOCUMENT ME!
+ * @param x x-coordinate of popup menu's location on the screen
+ * @param y y-coordinate of popup menu's location on the screen
+ * @param width width of the container that is used to display menu
+ * item's for popup menu
+ * @param height height of the container that is used to display menu
+ * item's for popup menu
*/
void show(int x, int y, int width, int height);
/**
- * DOCUMENT ME!
+ * Hides container used to display popup menu item's from the screen
*/
void hide();
}
/**
- * DOCUMENT ME!
+ * This class represents Popup menu that uses light weight container
+ * to display its contents.
*/
- private class LightWeightPopup extends JPanel implements Popup
+ private class LightWeightPopup extends Container implements Popup
{
/**
- * Creates a new LightWeightPopup object.
+ * Creates a new LightWeightPopup menu
*
- * @param c DOCUMENT ME!
+ * @param c Container containing menu items
*/
+ private Component c;
+
public LightWeightPopup(Container c)
{
- this.add(c);
+ this.c = c;
}
/**
- * DOCUMENT ME!
+ * Displayes lightweight container with menu items to the screen
*
- * @param x DOCUMENT ME!
- * @param y DOCUMENT ME!
- * @param width DOCUMENT ME!
- * @param height DOCUMENT ME!
+ * @param x x-coordinate of lightweight container on the screen
+ * @param y y-coordinate of lightweight container on the screen
+ * @param width width of the lightweight container
+ * @param height height of the lightweight container
*/
public void show(int x, int y, int width, int height)
{
JLayeredPane layeredPane;
layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane();
- this.setBounds(x, y, width, height);
- layeredPane.add(this, JLayeredPane.POPUP_LAYER, 0);
+ c.setBounds(x, y, width, height);
+ layeredPane.add(c, JLayeredPane.POPUP_LAYER, 0);
}
/**
- * DOCUMENT ME!
+ * Hides lightweight container from the screen
*/
public void hide()
{
JLayeredPane layeredPane;
layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane();
- int index = layeredPane.getIndexOf(this);
+ int index = layeredPane.getIndexOf(c);
layeredPane.remove(index);
}
}
/**
- * DOCUMENT ME!
+ * MediumWeightPopup is an AWT Panel with JPopupMenu's menu items.
+ * It is used to display JPopupMenu's menu items on the screen
*/
private class MediumWeightPopup extends Panel implements Popup
{
-
/**
* Creates a new MediumWeightPopup object.
*
- * @param c DOCUMENT ME!
+ * @param c Container with JPopupMenu's menu items
*/
public MediumWeightPopup(Container c)
{
- this.add(c);
+ this.add(c);
}
/**
- * DOCUMENT ME!
+ * Displays AWT Panel with its components on the screen
*
- * @param x DOCUMENT ME!
- * @param y DOCUMENT ME!
- * @param width DOCUMENT ME!
- * @param heigth DOCUMENT ME!
+ * @param x x-coordinate of the upper-left corner of the panel's
+ * @param y y-coordinate of the upper-left corner of the panel's
+ * @param width width of the panel
+ * @param height height of the panel
*/
public void show(int x, int y, int width, int height)
{
@@ -900,26 +967,27 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Hides This panel from the screen
*/
public void hide()
{
JLayeredPane layeredPane;
- layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane();
+ layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane();
int index = layeredPane.getIndexOf(this);
layeredPane.remove(index);
}
}
/**
- * DOCUMENT ME!
+ * HeavyWeightPopup is JWindow that is used to display JPopupMenu menu item's
+ * on the screen
*/
private class HeavyWeightPopup extends JWindow implements Popup
{
/**
* Creates a new HeavyWeightPopup object.
*
- * @param c DOCUMENT ME!
+ * @param c Container containing menu items
*/
public HeavyWeightPopup(Container c)
{
@@ -927,12 +995,12 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Displays JWindow container JPopupMenu's menu items to the screen
*
- * @param x DOCUMENT ME!
- * @param y DOCUMENT ME!
- * @param width DOCUMENT ME!
- * @param height DOCUMENT ME!
+ * @param x x-coordinate of JWindow containing menu items
+ * @param y y-coordinate of JWindow containing menu items
+ * @param width width of the JWindow
+ * @param height height of the JWindow
*/
public void show(int x, int y, int width, int height)
{
@@ -941,58 +1009,34 @@ public class JPopupMenu extends JCompone
}
/**
- * DOCUMENT ME!
+ * Hides JWindow with menu item's from the screen.
*/
public void hide()
{
- this.hide();
+ super.hide();
}
}
- /**
- * DOCUMENT ME!
- */
public static class Separator extends JSeparator
{
- /**
- * Creates a new Separator object.
- */
public Separator()
{
}
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
public String getUIClassID()
{
return null;
}
}
- /**
- * DOCUMENT ME!
- */
protected class AccessibleJPopupMenu extends AccessibleJComponent
{
private static final long serialVersionUID = 7423261328879849768L;
-
- /**
- * Creates a new AccessibleJPopupMenu object.
- *
- * @param component DOCUMENT ME!
- */
+
protected AccessibleJPopupMenu()
{
}
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
public AccessibleRole getAccessibleRole()
{
return AccessibleRole.POPUP_MENU;
Index: javax/swing/MenuSelectionManager.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/MenuSelectionManager.java,v
retrieving revision 1.2.18.2
diff -c -p -u -r1.2.18.2 MenuSelectionManager.java
--- javax/swing/MenuSelectionManager.java 7 Jun 2004 14:00:36 -0000 1.2.18.2
+++ javax/swing/MenuSelectionManager.java 14 Jun 2004 14:05:53 -0000
@@ -1,4 +1,4 @@
-/* MenuSelectionManager.java --
+/* MenuSelectionManager.java --
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,265 +35,283 @@ this exception to your version of the li
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package javax.swing;
import java.awt.Component;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
-
import java.util.ArrayList;
import java.util.Vector;
-
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;
-public class MenuSelectionManager
-{
- protected ChangeEvent changeEvent;
-
- protected EventListenerList listenerList = new EventListenerList ();
-
- private static final MenuSelectionManager manager = new MenuSelectionManager();
-
- private Vector selection = new Vector();
-
- protected void fireStateChanged ()
- {
- ChangeListener[] listeners = getChangeListeners ();
- for (int i = 0; i < listeners.length; i++)
- {
- listeners [i].stateChanged (new ChangeEvent (this));
- }
- }
-
- public void addChangeListener (ChangeListener listener)
- {
- listenerList.add (ChangeListener.class, listener);
- }
-
- public void removeChangeListener (ChangeListener listener)
- {
- listenerList.remove (ChangeListener.class, listener);
- }
-
- /** @since 1.4 */
- public ChangeListener[] getChangeListeners ()
- {
- return (ChangeListener[]) listenerList.getListeners (ChangeListener.class);
- }
-
- /**
- * Unselects all the menu elements on the selection path
- */
- public void clearSelectedPath ()
+/**
+ * This class manages current menu selectection. It provides
+ * methods to clear and set current selected menu path.
+ * It also fires StateChange event to its registered
+ * listeners whenever selected path of the current menu hierarchy
+ * changes.
+ *
+ */
+public class MenuSelectionManager
{
- for (int i = 0; i < selection.size (); i++)
- ((MenuElement) selection.get (i)).menuSelectionChanged (false);
-
- selection.clear ();
- }
- public Component componentForPoint (Component source, Point sourcePoint)
- {
- throw new UnsupportedOperationException("not implemented");
- }
-
- /**
- * Returns shared instance of MenuSelection Manager
- *
- * @return default Manager
- */
- public static MenuSelectionManager defaultManager ()
- {
- return manager;
- }
-
- /**
- * Returns path representing current menu selection
- *
- * @return Current selection path
- */
- public MenuElement[] getSelectedPath ()
- {
- MenuElement[] path = new MenuElement[selection.size ()];
+ /** ChangeEvent fired when selected path changes*/
+ protected ChangeEvent changeEvent = new ChangeEvent(this);
+
+ /** List of listeners for this MenuSelectionManager */
+ protected EventListenerList listenerList = new EventListenerList();
+
+ /** Default manager for the current menu hierarchy*/
+ private static final MenuSelectionManager manager = new MenuSelectionManager();
+
+ /** Path to the currently selected menu */
+ private Vector selectedPath = new Vector();
- for (int i = 0; i < path.length; i++)
- path[i] = (MenuElement) selection.get (i);
+ /**
+ * Fires StateChange event to registered listeners
+ */
+ protected void fireStateChanged ()
+ {
+ ChangeListener[] listeners = getChangeListeners ();
- return path;
- }
+ for (int i = 0; i < listeners.length; i++)
+ listeners[i].stateChanged (changeEvent);
+ }
- /**
- * Returns true if specified component is part of current menu
- * heirarchy and false otherwise
- *
- * @param c Component for which to check
- * @return True if specified component is part of current menu
- */
- boolean isComponentPartOfCurrentMenu (Component c)
- {
- MenuElement[] subElements;
- for (int i = 0; i < selection.size (); i++)
+ /**
+ * Adds ChangeListener to this MenuSelectionManager
+ *
+ * @param listener ChangeListener to add
+ */
+ public void addChangeListener (ChangeListener listener)
{
- subElements = ((MenuElement) selection.get (i)).getSubElements ();
- for (int j = 0; j < subElements.length; j++)
- {
- if ((subElements[j].getComponent ()).equals (c))
- return true;
- }
+ listenerList.add (ChangeListener.class, listener);
}
- return false;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- public void processKeyEvent (KeyEvent e)
- {
- throw new UnsupportedOperationException("not implemented");
- }
-
- /**
- * Forwards given mouse event to all of the source subcomponents.
- *
- * @param event Mouse event
- */
- public void processMouseEvent (MouseEvent event)
- {
-
- Component c = ((MenuElement) event.getSource ()).getComponent ();
- if (selection.size () == 0)
+ /**
+ * Removes ChangeListener from the list of registered listeners
+ * for this MenuSelectionManager.
+ *
+ * @param listener ChangeListner to remove
+ */
+ public void removeChangeListener (ChangeListener listener)
{
- ((MenuElement) event.getSource ()).processMouseEvent (event,
- getPath (c),
- manager);
- return;
+ listenerList.remove (ChangeListener.class, listener);
}
- // find the index of the source component in the current menu hierarchy
- int i = 0;
- for (i = 0; i < selection.size (); i++)
+ /**
+ * Returns list of registered listeners with MenuSelectionManager
+ *
+ * @since 1.4
+ */
+ public ChangeListener[] getChangeListeners ()
{
- MenuElement me = (MenuElement) selection.get (i);
- if (me.getComponent ().equals (c))
- break;
+ return (ChangeListener[]) listenerList.getListeners (ChangeListener.class);
}
- // Forward event to all subcomponents of the source
- Component subComp;
- for (int j = i; j < selection.size (); j++)
+ /**
+ * Unselects all the menu elements on the selection path
+ */
+ public void clearSelectedPath ()
{
- subComp = ((MenuElement)selection.get (j)).getComponent ();
- ((MenuElement) selection.get (j)).processMouseEvent (event,
- getPath (subComp),
- manager);
+ // Send events from the bottom most item in the menu - hierarchy to the
+ // top most
+ for (int i = selectedPath.size () - 1; i >= 0; i--)
+ ((MenuElement) selectedPath.get (i)).menuSelectionChanged (false);
+
+ // notify all listeners that the selected path was changed
+ fireStateChanged ();
+
+ // clear selected path
+ selectedPath.clear ();
}
- }
- /**
- * Sets menu selection to the specified path
- *
- * @param path new selection path
- */
- public void setSelectedPath (MenuElement[] path)
- {
- if (path == null)
+ /**
+ * DOCUMENT ME!
+ *
+ * @param source DOCUMENT ME!
+ * @param sourcePoint DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Component componentForPoint (Component source, Point sourcePoint)
{
- clearSelectedPath ();
- return;
+ throw new UnsupportedOperationException("not implemented");
}
- int i;
- int minSize = path.length; // size of the smaller path.
-
- if (path.length > selection.size ())
+ /**
+ * Returns shared instance of MenuSelection Manager
+ *
+ * @return default Manager
+ */
+ public static MenuSelectionManager defaultManager ()
{
- // if new selected path contains more elements then current
- // selection then first add all elements at
- // the indexes > selection.size
-
- for (i = selection.size (); i < path.length; i++)
- {
- selection.add (path[i]);
- path[i].menuSelectionChanged (true);
- }
-
- minSize = selection.size ();
+ return manager;
}
- else if (path.length < selection.size ())
+ /**
+ * Returns path representing current menu selection
+ *
+ * @return Current selection path
+ */
+ public MenuElement[] getSelectedPath ()
{
- // if new selected path contains less elements then current
- // selection then first remove all elements from the selection
- // at the indexes > path.length
-
- for (i = selection.size () - 1; i >= path.length; i--)
- {
- ((MenuElement) selection.get (i)).menuSelectionChanged (false);
- selection.remove (i);
- }
+ MenuElement[] path = new MenuElement[selectedPath.size ()];
- minSize = path.length;
- }
+ for (int i = 0; i < path.length; i++)
+ path[i] = (MenuElement) selectedPath.get (i);
- // Now compare elements in new and current selection path at the
- // same location and adjust selection until
- // same menu elements will be encountered at the
- // same index in both current and new selection path.
-
- MenuElement oldSelection;
+ return path;
+ }
- for (i = minSize - 1; i >= 0; i--)
+ /**
+ * Returns true if specified component is part of current menu
+ * heirarchy and false otherwise
+ *
+ * @param c Component for which to check
+ * @return True if specified component is part of current menu
+ */
+ boolean isComponentPartOfCurrentMenu (Component c)
{
- oldSelection = (MenuElement) selection.get (i);
+ MenuElement[] subElements;
+ for (int i = 0; i < selectedPath.size (); i++)
+ {
+ subElements = ((MenuElement) selectedPath.get (i)).getSubElements ();
+ for (int j = 0; j < subElements.length; j++)
+ {
+ if ((subElements[j].getComponent ()).equals (c))
+ return true;
+ }
+ }
- if (path[i].equals (oldSelection))
- break;
+ return false;
+ }
- oldSelection.menuSelectionChanged (false);
- path[i].menuSelectionChanged (true);
- selection.setElementAt (path[i], i);
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void processKeyEvent (KeyEvent e)
+ {
+ throw new UnsupportedOperationException("not implemented");
}
- }
+ /**
+ * Forwards given mouse event to all of the source subcomponents.
+ *
+ * @param event Mouse event
+ */
+ public void processMouseEvent (MouseEvent event)
+ {
+ JComponent c = ((JComponent) event.getSource ());
- /**
- * Returns path to the specified component
- *
- * @param c component for which to find path for
- *
- * @return path to the specified component
- */
- private MenuElement[] getPath (Component c)
- {
- Vector path = new Vector();
- path.add (c);
+ MenuElement[] path = getPath (c);
+ ((MenuElement) c).processMouseEvent (event, path, manager);
- Component parent = c.getParent ();
+ // forward events to subcomponents
+ MenuElement[] subComponents = ((MenuElement) c).getSubElements ();
- while (parent instanceof JMenu
- || parent instanceof JPopupMenu
- || parent instanceof JMenuItem
- || parent instanceof JMenuBar)
- {
- path.add (parent);
- parent = parent.getParent ();
+ for (int i = 0; i < subComponents.length; i++)
+ {
+ if (subComponents[i] instanceof JMenuItem)
+ subComponents[i].processMouseEvent (event, path, manager);
+ }
}
- MenuElement[] pathArray = new MenuElement[path.size ()];
+ /**
+ * Sets menu selection to the specified path
+ *
+ * @param path new selection path
+ */
+ public void setSelectedPath (MenuElement[] path)
+ {
+ if (path == null)
+ {
+ clearSelectedPath ();
+ return;
+ }
+
+ fireStateChanged ();
+
+ int i;
+ int minSize = path.length; // size of the smaller path.
+
+ if (path.length > selectedPath.size ())
+ {
+ // if new selected path contains more elements then current
+ // selection then first add all elements at
+ // the indexes > selectedPath.size
+ for (i = selectedPath.size (); i < path.length; i++)
+ {
+ selectedPath.add (path[i]);
+ path[i].menuSelectionChanged (true);
+ }
+
+ minSize = selectedPath.size ();
+ }
+
+ else if (path.length < selectedPath.size ())
+ {
+ // if new selected path contains less elements then current
+ // selection then first remove all elements from the selection
+ // at the indexes > path.length
+ for (i = selectedPath.size () - 1; i >= path.length; i--)
+ {
+ ((MenuElement) selectedPath.get (i)).menuSelectionChanged (false);
+ selectedPath.remove (i);
+ }
+
+ minSize = path.length;
+ }
+
+ // Now compare elements in new and current selection path at the
+ // same location and adjust selection until
+ // same menu elements will be encountered at the
+ // same index in both current and new selection path.
+ MenuElement oldSelectedPath;
+
+ for (i = minSize - 1; i >= 0; i--)
+ {
+ oldSelectedPath = (MenuElement) selectedPath.get (i);
+
+ if (path[i].equals (oldSelectedPath))
+ break;
+
+ oldSelectedPath.menuSelectionChanged (false);
+ path[i].menuSelectionChanged (true);
+ selectedPath.setElementAt (path[i], i);
+ }
+ }
- for (int i = 0; i < path.size (); i++)
- pathArray[i] = (MenuElement) path.get (path.size () - i - 1);
- return pathArray;
+ /**
+ * Returns path to the specified component
+ *
+ * @param c component for which to find path for
+ *
+ * @return path to the specified component
+ */
+ private MenuElement[] getPath (Component c)
+ {
+ ArrayList path = new ArrayList();
+ while (c instanceof MenuElement)
+ {
+ path.add (0, (MenuElement) c);
+
+ if (c instanceof JPopupMenu)
+ c = ((JPopupMenu) c).getInvoker ();
+ else
+ c = c.getParent ();
+ }
+
+ MenuElement[] pathArray = new MenuElement[path.size ()];
+ path.toArray (pathArray);
+ return pathArray;
+ }
}
-
-} // class MenuSelectionManager
Index: javax/swing/plaf/basic/BasicMenuBarUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicMenuBarUI.java,v
retrieving revision 1.1.2.2
diff -c -p -u -r1.1.2.2 BasicMenuBarUI.java
--- javax/swing/plaf/basic/BasicMenuBarUI.java 3 Jun 2004 14:21:53 -0000 1.1.2.2
+++ javax/swing/plaf/basic/BasicMenuBarUI.java 14 Jun 2004 14:05:53 -0000
@@ -1,5 +1,5 @@
-/* BasicMenuUI.java
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+/* BasicMenuBarUI.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -37,11 +37,13 @@ exception statement from your version. *
package javax.swing.plaf.basic;
+import java.awt.Dimension;
+import java.awt.GridLayout;
+import java.awt.Insets;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
-import java.awt.Dimension;
import javax.swing.BoxLayout;
import javax.swing.ButtonModel;
import javax.swing.Icon;
@@ -70,18 +72,22 @@ import javax.swing.event.MouseInputListe
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.MenuBarUI;
import javax.swing.plaf.MenuItemUI;
-import java.awt.Insets;
-import java.awt.GridLayout;
/**
- * DOCUMENT ME!
+ * UI Delegate for JMenuBar.
*/
public class BasicMenuBarUI extends MenuBarUI
{
protected ChangeListener changeListener;
+
+ /*ContainerListener that listens to the ContainerEvents fired from menu bar*/
protected ContainerListener containerListener;
+
+ /*Property change listeners that listener to PropertyChangeEvent from menu bar*/
protected PropertyChangeListener propertyChangeListener;
+
+ /* menu bar for which this UI delegate is for*/
protected JMenuBar menuBar;
/**
@@ -105,21 +111,23 @@ public class BasicMenuBarUI extends Menu
}
/**
- * DOCUMENT ME!
+ * Creates ContainerListener() to listen for ContainerEvents
+ * fired by JMenuBar
*
- * @return DOCUMENT ME!
+ * @return The ContainerListener
*/
- protected ContainerListener createContainerListener()
+ protected ContainerListener createContainerListener()
{
return new ContainerHandler();
}
/**
- * DOCUMENT ME!
+ * Factory method to create a BasicMenuBarUI for the given {@link
+ * JComponent}, which should be a {@link JMenuBar}.
*
- * @param x DOCUMENT ME!
+ * @param b The {@link JComponent} a UI is being created for.
*
- * @return DOCUMENT ME!
+ * @return A BasicMenuBarUI for the {@link JComponent}.
*/
public static ComponentUI createUI(JComponent x)
{
@@ -127,11 +135,11 @@ public class BasicMenuBarUI extends Menu
}
/**
- * DOCUMENT ME!
+ * Returns maximum size for the specified menu bar
*
- * @param c DOCUMENT ME!
+ * @param c component for which to get maximum size
*
- * @return DOCUMENT ME!
+ * @return Maximum size for the specified menu bar
*/
public Dimension getMaximumSize(JComponent c)
{
@@ -140,11 +148,11 @@ public class BasicMenuBarUI extends Menu
}
/**
- * DOCUMENT ME!
+ * Returns maximum allowed size of JMenuBar.
*
- * @param c DOCUMENT ME!
+ * @param c menuBar for which to return maximum size
*
- * @return DOCUMENT ME!
+ * @return Maximum size of the give menu bar.
*/
public Dimension getMinimumSize(JComponent c)
{
@@ -153,11 +161,11 @@ public class BasicMenuBarUI extends Menu
}
/**
- * DOCUMENT ME!
+ * Returns preferred size of JMenuBar.
*
- * @param c DOCUMENT ME!
+ * @param c menuBar for which to return preferred size
*
- * @return DOCUMENT ME!
+ * @return Preferred size of the give menu bar.
*/
public Dimension getPreferredSize(JComponent c)
{
@@ -166,7 +174,8 @@ public class BasicMenuBarUI extends Menu
}
/**
- * DOCUMENT ME!
+ * Initializes any default properties that this UI has from the defaults for
+ * the Basic look and feel.
*/
protected void installDefaults()
{
@@ -179,26 +188,29 @@ public class BasicMenuBarUI extends Menu
}
/**
- * DOCUMENT ME!
+ * This method installs the keyboard actions for the JMenuBar.
*/
protected void installKeyboardActions()
{
+ // FIXME: implement
}
/**
- * DOCUMENT ME!
+ * This method installs the listeners needed for this UI to function.
*/
protected void installListeners()
- {
+ {
menuBar.addContainerListener(containerListener);
- menuBar.addPropertyChangeListener(propertyChangeListener);
+ menuBar.addPropertyChangeListener(propertyChangeListener);
}
/**
- * DOCUMENT ME!
- *
- * @param c DOCUMENT ME!
- */
+ * Installs and initializes all fields for this UI delegate. Any properties
+ * of the UI that need to be initialized and/or set to defaults will be
+ * done now. It will also install any listeners necessary.
+ *
+ * @param c The {@link JComponent} that is having this UI installed.
+ */
public void installUI(JComponent c)
{
super.installUI(c);
@@ -206,10 +218,12 @@ public class BasicMenuBarUI extends Menu
menuBar.setLayout(new BoxLayout(menuBar, BoxLayout.X_AXIS));
installDefaults();
installListeners();
+ installKeyboardActions();
}
/**
- * DOCUMENT ME!
+ * This method uninstalls the defaults and nulls any objects created during
+ * install.
*/
protected void uninstallDefaults()
{
@@ -220,10 +234,11 @@ public class BasicMenuBarUI extends Menu
}
/**
- * DOCUMENT ME!
+ * This method reverses the work done in installKeyboardActions.
*/
protected void uninstallKeyboardActions()
{
+ // FIXME: implement.
}
/**
@@ -236,15 +251,18 @@ public class BasicMenuBarUI extends Menu
}
/**
- * DOCUMENT ME!
+ * Performs the opposite of installUI. Any properties or resources that need
+ * to be cleaned up will be done now. It will also uninstall any listeners
+ * it has. In addition, any properties of this UI will be nulled.
*
- * @param c DOCUMENT ME!
+ * @param c The {@link JComponent} that is having this UI uninstalled.
*/
public void uninstallUI(JComponent c)
{
uninstallDefaults();
- uninstallListeners();
- menuBar= null;
+ uninstallListeners();
+ uninstallKeyboardActions();
+ menuBar = null;
}
protected class ChangeHandler implements ChangeListener
@@ -254,21 +272,47 @@ public class BasicMenuBarUI extends Menu
}
}
+ /**
+ * This class handles ContainerEvents fired by JMenuBar
+ */
protected class ContainerHandler implements ContainerListener
{
+ /**
+ * This method is called whenever menu is added to the menu bar
+ *
+ * @param e The ContainerEvent.
+ */
public void componentAdded(ContainerEvent e)
{
+ System.out.println("BasicMenuBar...componentAdded.. listener");
}
+ /**
+ * This method is called whenever menu is removed from the menu bar
+ *
+ * @param e The ContainerEvent.
+ */
public void componentRemoved(ContainerEvent e)
{
+ System.out.println("BasicMenuBar...componentRemoved.. listener");
}
}
+ /**
+ * This class handles PropertyChangeEvents fired from the JMenuBar
+ */
protected class PropertyChangeHandler implements PropertyChangeListener
{
+ /**
+ * This method is called whenever one of the properties of the MenuBar
+ * changes.
+ *
+ * @param e The PropertyChangeEvent.
+ */
public void propertyChange(PropertyChangeEvent e)
{
+ if (e.getPropertyName().equals(JMenuBar.BORDER_PAINTED_CHANGED_PROPERTY))
+ menuBar.repaint();
}
}
}
More information about the Java-patches
mailing list