/** {@inheritDoc} */
  public void setPressed(boolean b) {
    if ((isPressed() == b) || !isEnabled()) {
      return;
    }

    if (b) {
      stateMask |= PRESSED;
    } else {
      stateMask &= ~PRESSED;
    }

    if (!isPressed() && isArmed()) {
      int modifiers = 0;
      AWTEvent currentEvent = EventQueue.getCurrentEvent();
      if (currentEvent instanceof InputEvent) {
        modifiers = ((InputEvent) currentEvent).getModifiers();
      } else if (currentEvent instanceof ActionEvent) {
        modifiers = ((ActionEvent) currentEvent).getModifiers();
      }
      fireActionPerformed(
          new ActionEvent(
              this,
              ActionEvent.ACTION_PERFORMED,
              getActionCommand(),
              EventQueue.getMostRecentEventTime(),
              modifiers));
    }

    fireStateChanged();
  }
Exemplo n.º 2
0
 /**
  * Perform the specified Action on the object
  *
  * @param i zero-based index of actions
  * @return true if the action was performed; otherwise false.
  */
 public boolean doAccessibleAction(int i) {
   if (i == 0) {
     // Simulate a button click
     Toolkit.getEventQueue()
         .postEvent(
             new ActionEvent(
                 MenuItem.this,
                 ActionEvent.ACTION_PERFORMED,
                 MenuItem.this.getActionCommand(),
                 EventQueue.getMostRecentEventTime(),
                 0));
     return true;
   } else {
     return false;
   }
 }