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