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

📄 basicmenuitemui.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    acceleratorSelectionForeground = null;    arrowIcon = null;    selectionBackground = null;    selectionForeground = null;    acceleratorDelimiter = null;  }  /**   * Uninstalls any keyboard actions.   */  protected void uninstallKeyboardActions()  {       SwingUtilities.replaceUIInputMap(menuItem,                                     JComponent.WHEN_IN_FOCUSED_WINDOW, null);  }  /**   * Unregisters all the listeners that this UI delegate was using.   */  protected void uninstallListeners()  {    menuItem.removeMouseListener(mouseInputListener);    menuItem.removeMenuDragMouseListener(menuDragMouseListener);    menuItem.removeMenuKeyListener(menuKeyListener);    menuItem.removeItemListener(itemListener);    menuItem.removePropertyChangeListener(propertyChangeListener);  }  /**   * 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   *          The {@link JComponent} that is having this UI uninstalled.   */  public void uninstallUI(JComponent c)  {    uninstallListeners();    uninstallDefaults();    uninstallComponents(menuItem);    menuItem = null;  }  /**   * This method calls paint.   *    * @param g   *          The graphics context used to paint this menu item   * @param c   *          The menu item to paint   */  public void update(Graphics g, JComponent c)  {    paint(g, c);  }  /**   * Return text representation of the specified accelerator   *    * @param accelerator   *          Accelerator for which to return string representation   * @return $String$ Text representation of the given accelerator   */  private String getAcceleratorText(KeyStroke accelerator)  {    // convert keystroke into string format    String modifiersText = "";    int modifiers = accelerator.getModifiers();    char keyChar = accelerator.getKeyChar();    int keyCode = accelerator.getKeyCode();    if (modifiers != 0)      modifiersText = KeyEvent.getKeyModifiersText(modifiers)                      + acceleratorDelimiter;    if (keyCode == KeyEvent.VK_UNDEFINED)      return modifiersText + keyChar;    else      return modifiersText + KeyEvent.getKeyText(keyCode);  }  /**   * Calculates and return rectange in which accelerator should be displayed   *    * @param accelerator   *          accelerator for which to return the display rectangle   * @param fm   *          The font metrics used to measure the text   * @return $Rectangle$ reactangle which will be used to display accelerator   */  private Rectangle getAcceleratorRect(KeyStroke accelerator, FontMetrics fm)  {    int width = fm.stringWidth(getAcceleratorText(accelerator));    int height = fm.getHeight();    return new Rectangle(0, 0, width, height);  }  /**   * Paints accelerator inside menu item   *    * @param g   *          The graphics context used to paint the border   * @param menuItem   *          Menu item for which to draw accelerator   * @param acceleratorRect   *          rectangle representing position of the accelerator relative to the   *          menu item   * @param acceleratorText   *          accelerator's text   */  private void paintAccelerator(Graphics g, JMenuItem menuItem,                                Rectangle acceleratorRect,                                String acceleratorText)  {    g.setFont(acceleratorFont);    FontMetrics fm = g.getFontMetrics(acceleratorFont);    if (menuItem.isEnabled())      g.setColor(acceleratorForeground);    else      // FIXME: should fix this to use 'disabledForeground', but its      // default value in BasicLookAndFeel is null.      g.setColor(Color.gray);    BasicGraphicsUtils.drawString(g, acceleratorText, 0, acceleratorRect.x,                                  acceleratorRect.y + fm.getAscent());  }  /**   * This class handles mouse events occuring inside the menu item. Most of the   * events are forwarded for processing to MenuSelectionManager of the current   * menu hierarchy.   */  protected class MouseInputHandler implements MouseInputListener  {    /**     * Creates a new MouseInputHandler object.     */    protected MouseInputHandler()    {      // Nothing to do here.    }    /**     * This method is called when mouse is clicked on the menu item. It forwards     * this event to MenuSelectionManager.     *      * @param e     *          A {@link MouseEvent}.     */    public void mouseClicked(MouseEvent e)    {      MenuSelectionManager manager = MenuSelectionManager.defaultManager();      manager.processMouseEvent(e);    }    /**     * This method is called when mouse is dragged inside the menu item. It     * forwards this event to MenuSelectionManager.     *      * @param e     *          A {@link MouseEvent}.     */    public void mouseDragged(MouseEvent e)    {      MenuSelectionManager manager = MenuSelectionManager.defaultManager();      manager.processMouseEvent(e);    }    /**     * This method is called when mouse enters menu item. When this happens menu     * item is considered to be selected and selection path in     * MenuSelectionManager is set. This event is also forwarded to     * MenuSelection Manager for further processing.     *      * @param e     *          A {@link MouseEvent}.     */    public void mouseEntered(MouseEvent e)    {      Component source = (Component) e.getSource();      if (source.getParent() instanceof MenuElement)        {          MenuSelectionManager manager = MenuSelectionManager.defaultManager();          manager.setSelectedPath(getPath());          manager.processMouseEvent(e);        }    }    /**     * This method is called when mouse exits menu item. The event is forwarded     * to MenuSelectionManager for processing.     *      * @param e     *          A {@link MouseEvent}.     */    public void mouseExited(MouseEvent e)    {      MenuSelectionManager manager = MenuSelectionManager.defaultManager();      manager.processMouseEvent(e);    }    /**     * This method is called when mouse is inside the menu item. This event is     * forwarder to MenuSelectionManager for further processing.     *      * @param e     *          A {@link MouseEvent}.     */    public void mouseMoved(MouseEvent e)    {      MenuSelectionManager manager = MenuSelectionManager.defaultManager();      manager.processMouseEvent(e);    }    /**     * This method is called when mouse is pressed. This event is forwarded to     * MenuSelectionManager for further processing.     *      * @param e     *          A {@link MouseEvent}.     */    public void mousePressed(MouseEvent e)    {      MenuSelectionManager manager = MenuSelectionManager.defaultManager();      manager.processMouseEvent(e);    }    /**     * This method is called when mouse is released. If the mouse is released     * inside this menuItem, then this menu item is considered to be chosen and     * the menu hierarchy should be closed.     *      * @param e     *          A {@link MouseEvent}.     */    public void mouseReleased(MouseEvent e)    {      Rectangle size = menuItem.getBounds();      MenuSelectionManager manager = MenuSelectionManager.defaultManager();      if (e.getX() > 0 && e.getX() < size.width && e.getY() > 0          && e.getY() < size.height)        {          manager.clearSelectedPath();          menuItem.doClick();        }      else        manager.processMouseEvent(e);    }  }  /**   * This class handles mouse dragged events.   */  private class MenuDragMouseHandler implements MenuDragMouseListener  {    /**     * Tbis method is invoked when mouse is dragged over the menu item.     *      * @param e     *          The MenuDragMouseEvent     */    public void menuDragMouseDragged(MenuDragMouseEvent e)    {      MenuSelectionManager manager = MenuSelectionManager.defaultManager();      manager.setSelectedPath(e.getPath());    }    /**     * Tbis method is invoked when mouse enters the menu item while it is being     * dragged.     *      * @param e     *          The MenuDragMouseEvent     */    public void menuDragMouseEntered(MenuDragMouseEvent e)    {      MenuSelectionManager manager = MenuSelectionManager.defaultManager();      manager.setSelectedPath(e.getPath());    }    /**     * Tbis method is invoked when mouse exits the menu item while it is being     * dragged     *      * @param e the MenuDragMouseEvent     */    public void menuDragMouseExited(MenuDragMouseEvent e)    {      // TODO: What should be done here, if anything?    }    /**     * Tbis method is invoked when mouse was dragged and released inside the     * menu item.     *      * @param e     *          The MenuDragMouseEvent     */    public void menuDragMouseReleased(MenuDragMouseEvent e)    {      MenuElement[] path = e.getPath();      if (path[path.length - 1] instanceof JMenuItem)        ((JMenuItem) path[path.length - 1]).doClick();      MenuSelectionManager manager = MenuSelectionManager.defaultManager();      manager.clearSelectedPath();    }  }  /**   * This class handles key events occuring when menu item is visible on the   * screen.   */  private class MenuKeyHandler implements MenuKeyListener  {    /**     * This method is invoked when key has been pressed     *      * @param e     *          A {@link MenuKeyEvent}.     */    public void menuKeyPressed(MenuKeyEvent e)    {      // TODO: What should be done here, if anything?    }    /**     * This method is invoked when key has been pressed     *      * @param e     *          A {@link MenuKeyEvent}.     */    public void menuKeyReleased(MenuKeyEvent e)    {      // TODO: What should be done here, if anything?    }    /**     * This method is invoked when key has been typed It handles the mnemonic     * key for the menu item.     *      * @param e     *          A {@link MenuKeyEvent}.     */    public void menuKeyTyped(MenuKeyEvent e)    {      // TODO: What should be done here, if anything?    }  }    /**   * Helper class that listens for item changes to the properties of the {@link   * JMenuItem}.   */  private class ItemHandler implements ItemListener  {    /**     * This method is called when one of the menu item changes.     *     * @param evt A {@link ItemEvent}.     */    public void itemStateChanged(ItemEvent evt)    {      boolean state = false;      if (menuItem instanceof JCheckBoxMenuItem)        {          if (evt.getStateChange() == ItemEvent.SELECTED)            state = true;          ((JCheckBoxMenuItem) menuItem).setState(state);        }      menuItem.revalidate();      menuItem.repaint();    }  }}

⌨️ 快捷键说明

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