⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jmenubar.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* JMenuBar.java --   Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing;import java.awt.Component;import java.awt.Graphics;import java.awt.Insets;import java.awt.event.KeyEvent;import java.awt.event.MouseEvent;import javax.accessibility.Accessible;import javax.accessibility.AccessibleContext;import javax.accessibility.AccessibleRole;import javax.accessibility.AccessibleSelection;import javax.accessibility.AccessibleStateSet;import javax.swing.plaf.MenuBarUI;/** * JMenuBar is a container for menu's. For a menu bar to be seen on the * screen, at least one menu should be added to it. Just like adding * components to container, one can use add() to add menu's to the menu bar. * Menu's will be displayed in the menu  bar in the order they were added. * The JMenuBar uses selectionModel to keep track of selected menu index. * JMenuBar's selectionModel will fire ChangeEvents to its registered  * listeners when the selected index changes. */public class JMenuBar extends JComponent implements Accessible, MenuElement{  /**   * Provides accessibility support for <code>JMenuBar</code>.   *    * @author Roman Kennke (kennke@aicas.com)   */  protected class AccessibleJMenuBar extends AccessibleJComponent    implements AccessibleSelection  {    /**     * Returns the number of selected items in the menu bar. Possible values     * are <code>0</code> if nothing is selected, or <code>1</code> if one     * item is selected.     *     * @return the number of selected items in the menu bar     */    public int getAccessibleSelectionCount()    {      int count = 0;      if (getSelectionModel().getSelectedIndex() != -1)        count = 1;      return count;    }    /**     * Returns the selected with index <code>i</code> menu, or     * <code>null</code> if the specified menu is not selected.     *     * @param i the index of the menu to return     *     * @return the selected with index <code>i</code> menu, or     *         <code>null</code> if the specified menu is not selected     */    public Accessible getAccessibleSelection(int i)    {      if (getSelectionModel().getSelectedIndex() != i)        return null;      return getMenu(i);    }    /**     * Returns <code>true</code> if the specified menu is selected,     * <code>false</code> otherwise.     *     * @param i the index of the menu to check     *     *@return <code>true</code> if the specified menu is selected,     *        <code>false</code> otherwise     */    public boolean isAccessibleChildSelected(int i)    {      return getSelectionModel().getSelectedIndex() == i;    }    /**     * Selects the menu with index <code>i</code>. If another menu is already     * selected, this will be deselected.     *     * @param i the menu to be selected     */    public void addAccessibleSelection(int i)    {      getSelectionModel().setSelectedIndex(i);    }    /**     * Deselects the menu with index <code>i</code>.     *     * @param i the menu index to be deselected     */    public void removeAccessibleSelection(int i)    {      if (getSelectionModel().getSelectedIndex() == i)        getSelectionModel().clearSelection();    }    /**     * Deselects all possibly selected menus.     */    public void clearAccessibleSelection()    {      getSelectionModel().clearSelection();    }    /**     * In menu bars it is not possible to select all items, so this method     * does nothing.     */    public void selectAllAccessibleSelection()    {      // In menu bars it is not possible to select all items, so this method      // does nothing.    }    /**     * Returns the accessible role of <code>JMenuBar</code>, which is     * {@link AccessibleRole#MENU_BAR}.     *     * @return the accessible role of <code>JMenuBar</code>, which is     *         {@link AccessibleRole#MENU_BAR}     */    public AccessibleRole getAccessibleRole()    {      return AccessibleRole.MENU_BAR;    }    /**     * Returns the <code>AccessibleSelection</code> for this object. This     * method returns <code>this</code>, since the     * <code>AccessibleJMenuBar</code> manages its selection itself.     *     * @return the <code>AccessibleSelection</code> for this object     */    public AccessibleSelection getAccessibleSelection()    {      return this;    }    /**     * Returns the state of this <code>AccessibleJMenuBar</code>.     *     * @return the state of this <code>AccessibleJMenuBar</code>.     */    public AccessibleStateSet getAccessibleStateSet()    {      AccessibleStateSet stateSet = super.getAccessibleStateSet();      // TODO: Figure out what state must be added to the super state set.      return stateSet;    }  }  private static final long serialVersionUID = -8191026883931977036L;  /** JMenuBar's model. It keeps track of selected menu's index */  private transient SingleSelectionModel selectionModel;  /* 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;  /**   * Creates a new JMenuBar object.   */  public JMenuBar()  {    selectionModel = new DefaultSingleSelectionModel();    borderPainted = true;    updateUI();  }  /**   * Adds menu to the menu bar   *   * @param c menu to add   *   * @return reference to the added menu   */  public JMenu add(JMenu c)  {    c.setAlignmentX(Component.LEFT_ALIGNMENT);    super.add(c);    return c;  }  /**   * This method overrides addNotify() in the Container to register   * this menu bar with the current keyboard manager.   */  public void addNotify()  {    super.addNotify();    KeyboardManager.getManager().registerJMenuBar(this);  }  public AccessibleContext getAccessibleContext()  {    if (accessibleContext == null)      accessibleContext = new AccessibleJMenuBar();    return accessibleContext;  }  /**   * Returns reference to this menu bar   *   * @return reference to this menu bar   */  public Component getComponent()  {    return this;  }  /**   * Returns component at the specified index.   *   * @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)  {    return getComponent(i);  }  /**   * Returns index of the specified component   *   * @param c Component to search for   *   * @return index of the specified component. -1 is returned if   * specified component doesnt' exist in the menu bar.   */  public int getComponentIndex(Component c)  {    Component[] comps = getComponents();    int index = -1;    for (int i = 0; i < comps.length; i++)      {	if (comps[i].equals(c))	  {	    index = i;	    break;	  }      }    return index;  }  /**   * DOCUMENT ME!   *   * @return DOCUMENT ME!   */  public JMenu getHelpMenu()  {    return null;  }  /**   * Returns margin betweeen menu bar's border and its menues   *   * @return margin between menu bar's border and its menues   */  public Insets getMargin()  {    if (margin == null)      return new Insets(0, 0, 0, 0);    else      return margin;  }  /**   * Return menu at the specified index. If component at the   * specified index is not a menu, then null is returned.   *   * @param index index to look for the menu   *   * @return menu at specified index, or null if menu doesn't exist   * at the specified index.   */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -