示例#1
0
  public void draw(Toolkit toolkit) {
    /* Get the absolute origin of this component.
     */
    Point origin = getLocationOnScreen();

    int colorpair = getCursesColor();

    toolkit.setCursor(origin);

    int attribute = 0;
    if (!(getParent() instanceof JMenuBar)) {
      // This menu is in a JPopupMenu.
      super.draw(toolkit);
    } else {
      attribute = (super.hasFocus()) ? Toolkit.A_BOLD : Toolkit.A_REVERSE;
      toolkit.addString(" ", attribute, colorpair);
      toolkit.addString(super.getText(), attribute, colorpair);
      toolkit.addString(" ", attribute, colorpair);

      if (super.getMnemonic() > 0) {
        int mnemonicPos = super.getText().indexOf((char) super.getMnemonic());
        if (mnemonicPos != -1) {
          toolkit.setCursor(origin.addOffset(mnemonicPos + 1, 0));
          toolkit.addChar(super.getMnemonic(), attribute | Toolkit.A_UNDERLINE, colorpair);
        }
      }
    }
  }
示例#2
0
  /**
   * Displays this menu's popup menu if the specified value is true; hides the menu if it is false.
   */
  public void setPopupMenuVisible(boolean visible_) {
    _popupMenuVisible = visible_;
    if (!visible_) {
      _popup.hide();
      return;
    }

    if (_popup == null) _popup = new JPopupMenu(_menuItems);

    Point p;
    if (!this.isTopLevelMenu()) {

      /* If this menu is a submenu (i.e. it is not a direct
       * child of the menubar), check if there is enough
       * space on the right hand side of the parent menu.
       * If there is not enough space, position it on the
       * left of the parent menu.
       */
      JMenu parentmenu = (JMenu) getParentMenu();
      JPopupMenu parentpopup = parentmenu.getPopupMenu();
      p = parentpopup.getLocation();

      int verticalOffset = parentpopup.getComponentIndex(this);
      _popup.setInvoker(parentpopup);
      int parentwidth = parentpopup.getSize().width;
      Toolkit term = Toolkit.getDefaultToolkit();
      if (p.x + parentwidth + _popup.getWidth() < term.getScreenColumns()) {

        _popup.setLocation(p.addOffset(parentwidth - 1, verticalOffset));
      } else {
        _popup.setLocation(p.addOffset(-_popup.getWidth() + 1, verticalOffset));
      }
    } else {
      JMenuBar parentMenuBar = (JMenuBar) getParent();
      p = parentMenuBar.getPopupMenuLocation(this);
      _popup.setInvoker(parentMenuBar);
      _popup.setLocation(p);
    }
    _popup.show();
  }