diff options
Diffstat (limited to 'libjava/javax/swing/JMenuBar.java')
-rw-r--r-- | libjava/javax/swing/JMenuBar.java | 160 |
1 files changed, 96 insertions, 64 deletions
diff --git a/libjava/javax/swing/JMenuBar.java b/libjava/javax/swing/JMenuBar.java index e65c1bf..c4edcd1 100644 --- a/libjava/javax/swing/JMenuBar.java +++ b/libjava/javax/swing/JMenuBar.java @@ -66,12 +66,25 @@ import javax.swing.plaf.MenuItemUI; /** - * DOCUMENT ME! + * JMenuBar */ public class JMenuBar extends JComponent implements Accessible, MenuElement { + /** 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; /** @@ -80,16 +93,16 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement 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) { @@ -107,20 +120,15 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement 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() { @@ -128,23 +136,26 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Returns component at the specified index. * - * @param i DOCUMENT ME! + * @param i index of the component to get * - * @return DOCUMENT ME! + * @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) { - return getComponentAt(i); + return getComponent(i); } /** - * 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) { @@ -175,9 +186,9 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * 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() { @@ -188,11 +199,13 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * 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) { @@ -213,9 +226,9 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Returns selection model for this menu bar. * - * @return DOCUMENT ME! + * @return selection mdoel for this menu bar. */ public SingleSelectionModel getSelectionModel() { @@ -223,9 +236,10 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * 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() { @@ -238,19 +252,21 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * 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() { @@ -258,39 +274,31 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * 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) { @@ -298,13 +306,14 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * 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); } @@ -361,7 +370,14 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement */ public void setBorderPainted(boolean b) { - paintBorder = b; + boolean old = borderPainted; + borderPainted = b; + if (b != old) + { + firePropertyChange(BORDER_PAINTED_CHANGED_PROPERTY, old, b); + revalidate(); + repaint(); + } } /** @@ -384,27 +400,42 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * 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) { @@ -412,7 +443,8 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Set the "UI" property to a class constructed, via the {@link + * UIManager}, from the current look and feel. */ public void updateUI() { |