Exemplo n.º 1
0
 /**
  * This is the hook through which all menu items are created. It registers the result with the
  * menuitem hashtable so that it can be fetched with getMenuItem().
  *
  * @see #getMenuItem
  */
 protected JMenuItem createMenuItem(String cmd) {
   JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix));
   URL url = getResource(cmd + imageSuffix);
   if (url != null) {
     mi.setHorizontalTextPosition(JButton.RIGHT);
     mi.setIcon(new ImageIcon(url));
   }
   String astr = getResourceString(cmd + actionSuffix);
   if (astr == null) {
     astr = cmd;
   }
   mi.setActionCommand(astr);
   Action myaction = getAction(astr); // if this is a known action
   if (myaction != null) {
     mi.addActionListener(myaction);
     myaction.addPropertyChangeListener(createActionChangeListener(mi));
     // System.out.println("myaction not null: astr:"+astr+" enabled:"+myaction.isEnabled());
     mi.setEnabled(myaction.isEnabled());
   } else {
     System.err.println("Error:TextViewer: createMenuItem: myaction is null: astr:" + astr);
     // causes the item to be greyed out
     mi.setEnabled(false);
   }
   menuItems.put(cmd, mi);
   return mi;
 }
Exemplo n.º 2
0
  public ActionCheckBoxMenuItem(Action action, String text) {
    super(text);
    scriptedAction = action;
    scriptedAction.addActor(this);
    setEnabled(scriptedAction.isEnabled());

    addActionListener(new ActionForwarder());
  }
Exemplo n.º 3
0
 private boolean proceedKeyEvent(KeyEvent event, KeyStroke stroke) {
   if (myInputMap.get(stroke) != null) {
     final Action action = myActionMap.get(myInputMap.get(stroke));
     if (action != null && action.isEnabled()) {
       action.actionPerformed(
           new ActionEvent(
               getContent(), event.getID(), "", event.getWhen(), event.getModifiers()));
       return true;
     }
   }
   return false;
 }
Exemplo n.º 4
0
 /** This is the hook through which all menu items are created. */
 protected JMenuItem createMenuItem(String cmd) {
   JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix));
   URL url = getResource(cmd + imageSuffix);
   if (url != null) {
     mi.setHorizontalTextPosition(JButton.RIGHT);
     mi.setIcon(new ImageIcon(url));
   }
   String astr = getProperty(cmd + actionSuffix);
   if (astr == null) {
     astr = cmd;
   }
   mi.setActionCommand(astr);
   Action a = getAction(astr);
   if (a != null) {
     mi.addActionListener(a);
     a.addPropertyChangeListener(createActionChangeListener(mi));
     mi.setEnabled(a.isEnabled());
   } else {
     mi.setEnabled(false);
   }
   return mi;
 }
  @SuppressWarnings("HardCodedStringLiteral")
  private void processListSelection(final KeyEvent e) {
    if (togglePopup(e)) return;

    if (!isPopupShowing()) return;

    final InputMap map = myPathTextField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    if (map != null) {
      final Object object = map.get(KeyStroke.getKeyStrokeForEvent(e));
      if (object instanceof Action) {
        final Action action = (Action) object;
        if (action.isEnabled()) {
          action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "action"));
          e.consume();
          return;
        }
      }
    }

    final Object action = getAction(e, myList);

    if ("selectNextRow".equals(action)) {
      if (ensureSelectionExists()) {
        ListScrollingUtil.moveDown(myList, e.getModifiersEx());
      }
    } else if ("selectPreviousRow".equals(action)) {
      ListScrollingUtil.moveUp(myList, e.getModifiersEx());
    } else if ("scrollDown".equals(action)) {
      ListScrollingUtil.movePageDown(myList);
    } else if ("scrollUp".equals(action)) {
      ListScrollingUtil.movePageUp(myList);
    } else if (getSelectedFileFromCompletionPopup() != null
        && (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_TAB)
        && e.getModifiers() == 0) {
      hideCurrentPopup();
      e.consume();
      processChosenFromCompletion(e.getKeyCode() == KeyEvent.VK_TAB);
    }
  }
Exemplo n.º 6
0
  public static boolean notifyAction(
      final Action action,
      final KeyStroke keyStroke,
      final KeyEvent keyEvent,
      final Object sender,
      final int modifiers) {
    if (action == null || !action.isEnabled()) {
      return false;
    }
    Object command = action.getValue(Action.ACTION_COMMAND_KEY);
    if (command == null && !(action instanceof ActionProxy)) {
      char keyChar = keyEvent.getKeyChar();
      if (keyChar != KeyEvent.CHAR_UNDEFINED) {
        command = String.valueOf(keyChar);
      }
    }

    action.actionPerformed(
        new ActionEvent(
            sender, ActionEvent.ACTION_PERFORMED, (String) command, keyEvent.getWhen(), modifiers));

    return true;
  }
Exemplo n.º 7
0
 public static boolean areEnabled() {
   return cropAction.isEnabled();
 }
 public boolean isEnabled() {
   return action.isEnabled();
 }
Exemplo n.º 9
0
 void updateAction(Action action) {
   final LinkLabel label = myActions.get(action);
   label.setVisible(action.isEnabled());
   label.setText((String) action.getValue(Action.NAME));
   label.setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION));
 }
Exemplo n.º 10
0
 public boolean isEnabled() {
   return saveHistoryAction.isEnabled();
 }
Exemplo n.º 11
0
 public boolean isEnabled() {
   return loadHistoryAction.isEnabled();
 }
Exemplo n.º 12
0
 public boolean isEnabled() {
   return stopRAction.isEnabled();
 }
Exemplo n.º 13
0
 public boolean isEnabled() {
   return openfunctionAction.isEnabled();
 }
Exemplo n.º 14
0
 public boolean isEnabled() {
   return requesthelpAction.isEnabled();
 }
Exemplo n.º 15
0
 protected void updateState() {
   setEnabled(action.isEnabled());
 }