Example usage for javax.swing Action ACTION_COMMAND_KEY

List of usage examples for javax.swing Action ACTION_COMMAND_KEY

Introduction

In this page you can find the example usage for javax.swing Action ACTION_COMMAND_KEY.

Prototype

String ACTION_COMMAND_KEY

To view the source code for javax.swing Action ACTION_COMMAND_KEY.

Click Source Link

Document

The key used to determine the command String for the ActionEvent that will be created when an Action is going to be notified as the result of residing in a Keymap associated with a JComponent.

Usage

From source file:ca.phon.app.project.ProjectWindow.java

private MultiActionButton createSessionButton() {
    MultiActionButton retVal = new MultiActionButton();

    ImageIcon newIcn = IconManager.getInstance().getIcon("mimetypes/text-xml", IconSize.SMALL);

    String s1 = "Session";
    String s2 = "Enter session name and press enter.  Press escape to cancel.";

    retVal.getTopLabel().setText(WorkspaceTextStyler.toHeaderText(s1));
    retVal.getTopLabel().setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
    retVal.getTopLabel().setFont(FontPreferences.getTitleFont());
    retVal.getTopLabel().setIcon(newIcn);
    retVal.setAlwaysDisplayActions(true);

    retVal.setOpaque(false);//from ww w  . j a va2 s.co  m

    ImageIcon cancelIcn = IconManager.getInstance().getIcon("actions/button_cancel", IconSize.SMALL);
    ImageIcon cancelIcnL = cancelIcn;

    PhonUIAction btnSwapAct = new PhonUIAction(this, "onSwapNewAndCreateSession", retVal);
    btnSwapAct.putValue(Action.ACTION_COMMAND_KEY, "CANCEL_CREATE_ITEM");
    btnSwapAct.putValue(Action.NAME, "Cancel create");
    btnSwapAct.putValue(Action.SHORT_DESCRIPTION, "Cancel create");
    btnSwapAct.putValue(Action.SMALL_ICON, cancelIcn);
    btnSwapAct.putValue(Action.LARGE_ICON_KEY, cancelIcnL);
    retVal.addAction(btnSwapAct);

    JPanel sessionNamePanel = new JPanel(new BorderLayout());
    sessionNamePanel.setOpaque(false);

    final JTextField sessionNameField = new JTextField();
    sessionNameField.setDocument(new NameDocument());
    sessionNameField.setText("Session Name");
    sessionNamePanel.add(sessionNameField, BorderLayout.CENTER);

    ActionMap actionMap = retVal.getActionMap();
    actionMap.put(btnSwapAct.getValue(Action.ACTION_COMMAND_KEY), btnSwapAct);
    InputMap inputMap = retVal.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);

    inputMap.put(ks, btnSwapAct.getValue(Action.ACTION_COMMAND_KEY));

    retVal.setActionMap(actionMap);
    retVal.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);

    PhonUIAction createNewSessionAct = new PhonUIAction(this, "onCreateSession", sessionNameField);
    createNewSessionAct.putValue(Action.SHORT_DESCRIPTION, "Create new session in selected corpus");
    createNewSessionAct.putValue(Action.SMALL_ICON,
            IconManager.getInstance().getIcon("actions/list-add", IconSize.SMALL));

    JButton createBtn = new JButton(createNewSessionAct);
    sessionNamePanel.add(createBtn, BorderLayout.EAST);

    sessionNameField.setAction(createNewSessionAct);

    // swap bottom component in new project button
    retVal.setBottomLabelText(WorkspaceTextStyler.toDescText(s2));
    retVal.add(sessionNamePanel, BorderLayout.CENTER);

    retVal.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {

        }

        @Override
        public void focusGained(FocusEvent e) {
            sessionNameField.requestFocus();
        }
    });

    return retVal;
}

From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java

public Action getNewFolderAction() {
    if (!readOnly && (newFolderAction == null)) {
        newFolderAction = new AbstractAction(newFolderActionLabelText) {
            private Action basicNewFolderAction;

            {/* w w w  . java 2s.c  o  m*/
                putValue(Action.ACTION_COMMAND_KEY, VFSFilePane.ACTION_NEW_FOLDER);

                FileObject currentDirectory = getFileChooser().getCurrentDirectoryObject();

                if (currentDirectory != null) {
                    setEnabled(canWrite(currentDirectory));
                }
            }

            public void actionPerformed(ActionEvent ev) {
                if (basicNewFolderAction == null) {
                    basicNewFolderAction = fileChooserUIAccessor.getNewFolderAction();
                }

                VFSJFileChooser fc = getFileChooser();
                FileObject oldFile = fc.getSelectedFileObject();
                basicNewFolderAction.actionPerformed(ev);

                FileObject newFile = fc.getSelectedFileObject();

                if ((newFile != null) && !newFile.equals(oldFile) && VFSUtils.isDirectory(newFile)) {
                    newFolderFile = newFile;
                }
            }
        };
    }

    return newFolderAction;
}

From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java

public static void addDoubleClickAction(JComponent component, final Action action) {
    component.addMouseListener(new MouseAdapter() {
        @Override/*w  ww.  j a v a2  s.co m*/
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == DOUBLE_CLICK_COUNT && e.getButton() == MouseEvent.BUTTON1) {
                action.actionPerformed(new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED,
                        (String) action.getValue(Action.ACTION_COMMAND_KEY), e.getWhen(), e.getModifiers()));
            }
        }
    });
}

From source file:org.nuclos.client.explorer.ExplorerNode.java

/**
 * finds the default action for this node by searching the tree node actions
 * (as specified in <code>getTreeNodeActions()</code>) for an enabled tree node action with the default tree node action
 * command (as specified in <code>getDefaultTreeNodeActionCommand()</code>). Note that this method
 * doesn't have to be overridden in subclasses.
 * @param tree the tree where the action is about to take place.
 * @return the default action for this node, if any.
 * @postcondition result != null --> result.isEnabled()
 *///w  w w. j av a 2s .  c  o  m
public TreeNodeAction getDefaultTreeNodeAction(JTree tree) {
    TreeNodeAction result = null;

    final String sDefaultTreeActionCommmand = this.getDefaultTreeNodeActionCommand(tree);
    if (sDefaultTreeActionCommmand != null) {
        for (TreeNodeAction action : this.getTreeNodeActions(tree)) {
            if (action.isEnabled() && LangUtils.equals(sDefaultTreeActionCommmand,
                    action.getValue(Action.ACTION_COMMAND_KEY))) {
                result = action;
                break;
            }
        }
    }
    assert result == null || result.isEnabled();
    return result;
}

From source file:org.nuclos.client.main.MainController.java

private Action createEntityAction(EntityMetaDataVO entitymetavo, String label, final boolean isNew,
        final Long processId, final String customUsage) {
    String entity = entitymetavo.getEntity();
    if (!getSecurityCache().isReadAllowedForEntity(entity)) {
        return null;
    }//from  www.  jav a2 s . co m

    if (isNew && entitymetavo.isStateModel()
            && !getSecurityCache().isNewAllowedForModuleAndProcess(IdUtils.unsafeToId(entitymetavo.getId()),
                    IdUtils.unsafeToId(processId))) {
        return null;
    }

    Action action = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            cmdCollectMasterData(evt, isNew, processId, customUsage);
        }
    };
    Pair<String, Character> nameAndMnemonic = MenuGenerator.getMnemonic(label);
    action.putValue(Action.NAME,
            customUsage == null ? nameAndMnemonic.x : String.format("%s (%s)", nameAndMnemonic.x, customUsage));
    if (nameAndMnemonic.y != null) {
        action.putValue(Action.MNEMONIC_KEY, (int) nameAndMnemonic.y.charValue());
    }
    action.setEnabled(true);
    action.putValue(Action.SMALL_ICON,
            MainFrame.resizeAndCacheTabIcon(Main.getInstance().getMainFrame().getEntityIcon(entity)));
    action.putValue(Action.ACTION_COMMAND_KEY, entity);
    if (!isNew && processId == null) {
        if (!StringUtils.isNullOrEmpty(entitymetavo.getAccelerator())
                && entitymetavo.getAcceleratorModifier() != null) {
            int keycode = entitymetavo.getAccelerator().charAt(0);
            if (keycode > 90)
                keycode -= 32;

            action.putValue(Action.ACCELERATOR_KEY,
                    KeyStroke.getKeyStroke(keycode, entitymetavo.getAcceleratorModifier().intValue()));
        } else if (!StringUtils.isNullOrEmpty(entitymetavo.getAccelerator())) {
            action.putValue(Action.ACCELERATOR_KEY,
                    KeyStroke.getKeyStroke(entitymetavo.getAccelerator().charAt(0)));
        }
    }

    return action;
}

From source file:org.nuclos.client.ui.collect.searcheditor.SearchConditionTreeNode.java

/**
 * finds the default action for this node by searching the tree actions
 * (as specified in <code>getExplorerActions()</code>) for a tree action with the default tree action
 * command (as specified in <code>getDefaultExplorerActionCommand()</code>). Note that this method
 * doesn't have to be overridden in subclasses.
 * @param tree the tree where the action is about to take place.
 * @param clcteRoot the <code>CollectableEntity</code> for the whole search condition.
 * @return the default action for this node, if any.
 *//*  w ww  .j av a 2 s  .  co m*/
public TreeNodeAction getDefaultTreeNodeAction(JTree tree, CollectableEntity clcteRoot,
        CollectableFieldsProviderFactory clctfproviderfactory,
        Collection<CollectableEntityField> additionalFields) {
    TreeNodeAction result = null;

    final String sDefaultTreeActionCommmand = this.getDefaultTreeNodeActionCommand();
    if (sDefaultTreeActionCommmand != null) {
        for (TreeNodeAction action : this.getTreeNodeActions(tree, clcteRoot, clctfproviderfactory,
                additionalFields)) {
            if (action != null) {
                if (sDefaultTreeActionCommmand.equals(action.getValue(Action.ACTION_COMMAND_KEY))) {
                    result = action;
                    break;
                }
            }
        }
    }
    return result;
}

From source file:org.nuclos.client.ui.collect.searcheditor.SearchEditorController.java

/**
 * @param treenode//from w  w w.  jav a  2s  .c om
 * @param tree the tree that is to contain the popup menu
 * @return the popupmenu, if any, for the given treenode
 * @precondition treenode != null
 */
private JPopupMenu getPopupMenu(SearchConditionTreeNode treenode, JTree tree) {
    if (treenode == null) {
        throw new NullArgumentException("treenode");
    }
    if (this.clctfproviderfactory == null) {
        throw new IllegalStateException(
                "No CollectableFieldsProviderFactory was defined for the search editor.");
    }

    final List<TreeNodeAction> lstaction = treenode.getTreeNodeActions(tree, this.clcteRoot,
            this.clctfproviderfactory, this.additionalFields);
    final JPopupMenu result = lstaction.isEmpty() ? null : new JPopupMenu();
    if (result != null) {
        final String sDefaultTreeNodeActionCommand = treenode.getDefaultTreeNodeActionCommand();
        for (TreeNodeAction action : lstaction) {
            if (action == null) {
                Logger.getLogger(SearchEditorController.class).warn("exploreraction == null");
            } else {
                final boolean bDefault = (sDefaultTreeNodeActionCommand != null)
                        && sDefaultTreeNodeActionCommand.equals(action.getValue(Action.ACTION_COMMAND_KEY));
                action.addToMenu(result, bDefault);
            }
        }
    }
    return result;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java

/**
 * Creates the action for the inplace import icon tooltip
 * @return//from  w w  w. j  ava  2s.com
 */
private Action createInplaceIconAction() {
    Action inplaceIconAction = new AbstractAction(INPLACE_IMPORT_TOOLTIP_ACTION_TEXT) {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            // Just pass this on to the controller
            controller.actionPerformed(arg0);
        }
    };
    inplaceIconAction.putValue(Action.ACTION_COMMAND_KEY, "" + EditorControl.FILE_PATH_INPLACE_ICON);
    return inplaceIconAction;
}

From source file:verdandi.ui.action.EditUsersAction.java

public EditUsersAction() {
    super(rb.getString("main.menu.edit.menuitem.users.name"));
    putValue(Action.MNEMONIC_KEY,
            new Integer(rb.getString("main.menu.edit.menuitem.users.mnemonic").charAt(0)));
    putValue(Action.ACTION_COMMAND_KEY, "CMD_EDIT_USERS");
    //initially disabled
    setEnabled(false);//from  w  w w  .j ava  2  s . c  o m
}