JMenuBar.java revision 0
2976N/A * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 2976N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2976N/A * This code is free software; you can redistribute it and/or modify it 2976N/A * under the terms of the GNU General Public License version 2 only, as 2976N/A * published by the Free Software Foundation. Sun designates this 2976N/A * particular file as subject to the "Classpath" exception as provided 2976N/A * by Sun in the LICENSE file that accompanied this code. 2976N/A * This code is distributed in the hope that it will be useful, but WITHOUT 2976N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2976N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2976N/A * version 2 for more details (a copy is included in the LICENSE file that 2976N/A * You should have received a copy of the GNU General Public License version 2976N/A * 2 along with this work; if not, write to the Free Software Foundation, 2976N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2976N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2976N/A * CA 95054 USA or visit www.sun.com if you need additional information or 3824N/A * An implementation of a menu bar. You add <code>JMenu</code> objects to the 3824N/A * menu bar to construct a menu. When the user selects a <code>JMenu</code> 5728N/A * object, its associated <code>JPopupMenu</code> is displayed, allowing the 3842N/A * user to select one of the <code>JMenuItems</code> on it. 3824N/A * For information and examples of using menu bars see 2976N/A * a section in <em>The Java Tutorial.</em> 2976N/A * <strong>Warning:</strong> Swing is not thread safe. For more 4287N/A * <strong>Warning:</strong> 3824N/A * Serialized objects of this class will not be compatible with 3824N/A * future Swing releases. The current serialization support is 2976N/A * appropriate for short term storage or RMI between applications running 2976N/A * the same version of Swing. As of 1.4, support for long term storage 2976N/A * of all JavaBeans<sup><font size="-2">TM</font></sup> 2976N/A * has been added to the <code>java.beans</code> package. 4495N/A * attribute: isContainer true 2976N/A * description: A container for holding and displaying menus. 5636N/A * Model for the selected subcontrol. 5636N/A /* diagnostic aids -- should be false for production builds. */ 2976N/A private static final boolean TRACE =
false;
// trace creates and disposes 5636N/A private static final boolean DEBUG =
false;
// show bad params, misc. 4915N/A * Returns the menubar's current UI. 2976N/A * Sets the L&F object that renders this component. 2976N/A * @param ui the new MenuBarUI L&F object 5636N/A * attribute: visualUpdate true 2976N/A * description: The UI object that implements the Component's LookAndFeel. 5636N/A * Resets the UI property with a value from the current look and feel. 2976N/A * Returns the name of the L&F class that renders this component. 4495N/A * @return the string "MenuBarUI" 3007N/A * @see JComponent#getUIClassID 3449N/A * Returns the model object that handles single selections. 3449N/A * @return the <code>SingleSelectionModel</code> property 4495N/A * @see SingleSelectionModel 2976N/A * Sets the model object to handle single selections. 2976N/A * @param model the <code>SingleSelectionModel</code> to use 4261N/A * @see SingleSelectionModel 2976N/A * description: The selection model, recording which child is selected. 2976N/A * Appends the specified menu to the end of the menu bar. 2976N/A * @param c the <code>JMenu</code> component to add 3449N/A * @return the menu component 4261N/A * Returns the menu at the specified position in the menu bar. 4261N/A * @param index an integer giving the position in the menu bar, where 5224N/A * @return the <code>JMenu</code> at that position, or <code>null</code> if 2976N/A * if there is no <code>JMenu</code> at that position (ie. if 2976N/A * it is a <code>JMenuItem</code>) 2976N/A * Returns the number of items in the menu bar. 4495N/A * @return the number of items in the menu bar 4495N/A * Sets the help menu that appears when the user selects the 4495N/A * "help" option in the menu bar. This method is not yet implemented 4495N/A * and will throw an exception. 4495N/A * @param menu the JMenu that delivers help to the user 4495N/A throw new Error(
"setHelpMenu() not yet implemented.");
4495N/A * Gets the help menu for the menu bar. This method is not yet 5636N/A * implemented and will throw an exception. 4495N/A * @return the <code>JMenu</code> that delivers help to the user 2976N/A throw new Error(
"getHelpMenu() not yet implemented.");
* Returns the component at the specified index. * @param i an integer specifying the position, where 0 is first * @return the <code>Component</code> at the position, * or <code>null</code> for an invalid index * @deprecated replaced by <code>getComponent(int i)</code> * Returns the index of the specified component. * @param c the <code>Component</code> to find * @return an integer giving the component's position, where 0 is first; * or -1 if it can't be found * Sets the currently selected component, producing a * a change to the selection model. * @param sel the <code>Component</code> to select * Returns true if the menu bar currently has a component selected. * @return true if a selection has been made, else false * Returns true if the menu bars border should be painted. * @return true if the border should be painted, else false * Sets whether the border should be painted. * @param b if true and border property is not <code>null</code>, * attribute: visualUpdate true * description: Whether the border should be painted. * Paints the menubar's border if <code>BorderPainted</code> * @param g the <code>Graphics</code> context to use for painting * @see JComponent#setBorder * Sets the margin between the menubar's border and * its menus. Setting to <code>null</code> will cause the menubar to * use the default margins. * @param m an Insets object containing the margin values * attribute: visualUpdate true * description: The space between the menubar's border and its contents * Returns the margin between the menubar's border and * its menus. If there is no previous margin, it will create * a default margin with zero size. * @return an <code>Insets</code> object containing the margin values * Implemented to be a <code>MenuElement</code> -- does nothing. * Implemented to be a <code>MenuElement</code> -- does nothing. * Implemented to be a <code>MenuElement</code> -- does nothing. * Implemented to be a <code>MenuElement</code> -- returns the * menus in this menu bar. * This is the reason for implementing the <code>MenuElement</code> * interface -- so that the menu bar can be treated the same as * @return an array of menu items in the menu bar. for(i=
0,c=
tmp.
size() ; i < c ; i++)
* Implemented to be a <code>MenuElement</code>. Returns this object. * @return the current <code>Component</code> (this) * Returns a string representation of this <code>JMenuBar</code>. * is intended to be used only for debugging purposes, and the * content and format of the returned string may vary between * implementations. The returned string may be empty but may not * @return a string representation of this <code>JMenuBar</code> * Gets the AccessibleContext associated with this JMenuBar. * For JMenuBars, the AccessibleContext takes the form of an * A new AccessibleJMenuBar instance is created if necessary. * @return an AccessibleJMenuBar that serves as the * AccessibleContext of this JMenuBar * This class implements accessibility support for the * <code>JMenuBar</code> class. It provides an implementation of the * Java Accessibility API appropriate to menu bar user-interface * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Get the accessible state set of this object. * @return an instance of AccessibleState containing the current state * Get the role of this object. * @return an instance of AccessibleRole describing the role of the * Get the AccessibleSelection associated with this object. In the * implementation of the Java Accessibility API for this class, * return this object, which is responsible for implementing the * AccessibleSelection interface on behalf of itself. * Returns 1 if a menu is currently selected in this menu bar. * @return 1 if a menu is currently selected, else 0 * Returns the currently selected menu if one is selected, if (i !=
0) {
// single selection model for JMenuBar * Returns true if the current child of this object is selected. * @param i the zero-based index of the child in this Accessible * @see AccessibleContext#getAccessibleChild * Selects the nth menu in the menu bar, forcing it to * pop up. If another menu is popped up, this will force * it to close. If the nth menu is already selected, this * @param i the zero-based index of selectable items * @see #getAccessibleStateSet // first close up any open menu // menu.setPopupMenuVisible(false); // now popup the new menu // menu.setPopupMenuVisible(true); * Removes the nth selected item in the object from the object's * selection. If the nth item isn't currently selected, this * method has no effect. Otherwise, it closes the popup menu. * @param i the zero-based index of selectable items // menu.setPopupMenuVisible(false); * Clears the selection in the object, so that nothing in the * object is selected. This will close any open menu. // menu.setPopupMenuVisible(false); * Normally causes every selected item in the object to be selected * if the object supports multiple selections. This method * makes no sense in a menu bar, and so does nothing. }
// internal class AccessibleJMenuBar * Subclassed to check all the child menus. // See if we have a local binding. // We don't, pass along to children JMenu's * Overrides <code>JComponent.addNotify</code> to register this * menu bar with the current keyboard manager. * Overrides <code>JComponent.removeNotify</code> to unregister this * menu bar with the current keyboard manager. kvData[n++] =
"selectionModel";
* See JComponent.readObject() for information about serialization