List of usage examples for javax.swing Action ACTION_COMMAND_KEY
String ACTION_COMMAND_KEY
To view the source code for javax.swing Action ACTION_COMMAND_KEY.
Click Source Link
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
. From source file:com.stonelion.zooviewer.ui.JZVNodePanel.java
@SuppressWarnings("serial") private Action getEditableAction() { if (editableAction == null) { String actionCommand = bundle.getString(EDITABLE_NODE_KEY); String actionKey = bundle.getString(EDITABLE_NODE_KEY + ".action"); editableAction = new AbstractAction(actionCommand) { @Override//from w w w .j a v a 2s . c o m public void actionPerformed(ActionEvent e) { if (editCheckboxEnable) { editable = !editable; updateView(); } } }; editableAction.setEnabled(editCheckboxEnable); editableAction.putValue(Action.ACTION_COMMAND_KEY, actionKey); } return this.editableAction; }
From source file:com.stonelion.zooviewer.ui.JZVNodePanel.java
/** * Returns the 'Add child' action.//from w w w .ja v a2 s . c o m * * @return the action */ @SuppressWarnings("serial") private Action getAddChildAction() { if (addChildAction == null) { String actionCommand = bundle.getString(ADD_CHILD_NODE_KEY); String actionKey = bundle.getString(ADD_CHILD_NODE_KEY + ".action"); addChildAction = new AbstractAction(actionCommand, Icons.ADD) { @Override public void actionPerformed(ActionEvent e) { System.out.println("actionPerformed(): action = " + e.getActionCommand()); if (checkAction()) { model.addNode(StringUtils.removeEnd(nodes[0].getPath(), "/") + "/" + childName, childText.getBytes()); } childName = childText = ""; } private boolean checkAction() { JDialog dlg = createAddChildDialog(); dlg.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); dlg.setSize(800, 600); dlg.setLocationRelativeTo(null); dlg.setVisible(true); boolean nameIsEmpty = childName == null || childName.isEmpty(); boolean dataIsEmpty = childText == null; return !nameIsEmpty && !dataIsEmpty; } }; addChildAction.putValue(Action.ACTION_COMMAND_KEY, actionKey); } return this.addChildAction; }
From source file:com.stonelion.zooviewer.ui.JZVNodePanel.java
/** * Returns the 'Update' action.//w w w. j av a 2 s .c om * * @return the action */ @SuppressWarnings("serial") private Action getUpdateAction() { if (updateAction == null) { String actionCommand = bundle.getString(UPDATE_NODE_KEY); String actionKey = bundle.getString(UPDATE_NODE_KEY + ".action"); updateAction = new AbstractAction(actionCommand, Icons.UPDATE) { @Override public void actionPerformed(ActionEvent e) { System.out.println("actionPerformed(): action = " + e.getActionCommand()); if (checkAction()) { model.updateData(nodes[0].getPath(), taUpdate.getText().getBytes(getCharset())); } } private boolean checkAction() { // No node or several nodes selected if (nodes == null || nodes.length > 1) { return false; } // No parent if (nodes == null || nodes.length != 1) { JOptionPane.showMessageDialog(JZVNodePanel.this, bundle.getString("dlg.error.updateWithoutParent"), bundle.getString("dlg.error.title"), JOptionPane.ERROR_MESSAGE); return false; } return (JOptionPane.showConfirmDialog(JZVNodePanel.this, bundle.getString("dlg.confirm.update")) == JOptionPane.YES_OPTION); } }; updateAction.putValue(Action.ACTION_COMMAND_KEY, actionKey); } return updateAction; }
From source file:com.stonelion.zooviewer.ui.JZVNodePanel.java
/** * Returns the 'Delete node(s)' action./*ww w.j av a 2 s.co m*/ * <p> * The action is created and mapped to the [Delete] key stroke * </p> * * @return the action */ @SuppressWarnings("serial") private Action getDeleteAction() { if (this.deleteAction == null) { String actionCommand = bundle.getString(DELETE_NODE_KEY); String actionKey = bundle.getString(DELETE_NODE_KEY + ".action"); this.deleteAction = new AbstractAction(actionCommand, Icons.DELETE) { @Override public void actionPerformed(ActionEvent e) { System.out.println("actionPerformed(): action = " + e.getActionCommand()); if (checkAction()) { // Checks if several nodes will be deleted if (nodes.length > 1) { model.deleteNodes(nodes); } else { model.deleteNode(nodes[0]); } } } private boolean checkAction() { // No node selected if (nodes == null) { JOptionPane.showMessageDialog(JZVNodePanel.this, bundle.getString("dlg.error.deleteWithoutSelection"), bundle.getString("dlg.error.title"), JOptionPane.ERROR_MESSAGE); return false; } return (JOptionPane.showConfirmDialog(JZVNodePanel.this, bundle.getString("dlg.confirm.update")) == JOptionPane.YES_OPTION); } }; this.deleteAction.putValue(Action.ACTION_COMMAND_KEY, actionKey); this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), actionKey); this.getActionMap().put(actionKey, this.deleteAction); } return this.deleteAction; }
From source file:com.stonelion.zooviewer.ui.JZVNodePanel.java
private Action getRefreshAction() { if (this.refreshAction == null) { String actionCommand = bundle.getString(REFRESH_NODE_KEY); String actionKey = bundle.getString(REFRESH_NODE_KEY + ".action"); this.refreshAction = new AbstractAction(actionCommand, Icons.REFRESH) { /**/*from w ww . j av a2 s. c o m*/ * */ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { model.refresh(nodes[0].getPath(), true); } }; this.refreshAction.putValue(Action.ACTION_COMMAND_KEY, actionKey); this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), actionKey); this.getActionMap().put(actionKey, this.refreshAction); } return this.refreshAction; }
From source file:net.sf.vfsjfilechooser.filepane.VFSFilePane.java
/** * Fetches the command list for the FilePane. These commands * are useful for binding to events, such as in a keymap. * * @return the command list//w ww .ja va2s . c om */ public Action[] getActions() { if (actions == null) { class FilePaneAction extends AbstractAction { FilePaneAction(String name) { this(name, name); } FilePaneAction(String name, String cmd) { super(name); putValue(Action.ACTION_COMMAND_KEY, cmd); } public void actionPerformed(ActionEvent e) { String cmd = (String) getValue(Action.ACTION_COMMAND_KEY); if (cmd.equals(ACTION_CANCEL)) { if (editFile != null) { cancelEdit(); } else { getFileChooser().cancelSelection(); } } else if (cmd.equals(ACTION_EDIT_FILE_NAME)) { VFSJFileChooser fc = getFileChooser(); int index = listSelectionModel.getMinSelectionIndex(); if ((index >= 0) && (editFile == null) && (!fc.isMultiSelectionEnabled() || (fc.getSelectedFiles().length <= 1))) { editFileName(index); } } else if (cmd.equals(ACTION_REFRESH)) { getFileChooser().rescanCurrentDirectory(); } } @Override public boolean isEnabled() { String cmd = (String) getValue(Action.ACTION_COMMAND_KEY); if (cmd.equals(ACTION_CANCEL)) { return getFileChooser().isEnabled(); } else if (cmd.equals(ACTION_EDIT_FILE_NAME)) { return !readOnly && getFileChooser().isEnabled(); } else { return true; } } } ArrayList<Action> actionList = new ArrayList<Action>(8); Action action; actionList.add(new FilePaneAction(ACTION_CANCEL)); actionList.add(new FilePaneAction(ACTION_EDIT_FILE_NAME)); actionList.add(new FilePaneAction(refreshActionLabelText, ACTION_REFRESH)); action = fileChooserUIAccessor.getApproveSelectionAction(); if (action != null) { actionList.add(action); } action = fileChooserUIAccessor.getChangeToParentDirectoryAction(); if (action != null) { actionList.add(action); } action = getNewFolderAction(); if (action != null) { actionList.add(action); } action = getViewTypeAction(VIEWTYPE_LIST); if (action != null) { actionList.add(action); } actions = actionList.toArray(new Action[actionList.size()]); } return actions.clone(); }
From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java
/** * Fetches the command list for the FilePane. These commands * are useful for binding to events, such as in a keymap. * * @return the command list/*from ww w.j a v a 2 s . co m*/ */ public Action[] getActions() { if (actions == null) { class FilePaneAction extends AbstractAction { FilePaneAction(String name) { this(name, name); } FilePaneAction(String name, String cmd) { super(name); putValue(Action.ACTION_COMMAND_KEY, cmd); } public void actionPerformed(ActionEvent e) { String cmd = (String) getValue(Action.ACTION_COMMAND_KEY); if (cmd.equals(ACTION_CANCEL)) { if (editFile != null) { cancelEdit(); } else { getFileChooser().cancelSelection(); } } else if (cmd.equals(ACTION_EDIT_FILE_NAME)) { VFSJFileChooser fc = getFileChooser(); int index = listSelectionModel.getMinSelectionIndex(); if ((index >= 0) && (editFile == null) && (!fc.isMultiSelectionEnabled() || (fc.getSelectedFiles().length <= 1))) { editFileName(index); } } else if (cmd.equals(ACTION_REFRESH)) { getFileChooser().rescanCurrentDirectory(); } else if (cmd.equals(ACTION_VIEW_HIDDEN)) { getFileChooser().setFileHidingEnabled(!getFileChooser().isFileHidingEnabled()); } } @Override public boolean isEnabled() { String cmd = (String) getValue(Action.ACTION_COMMAND_KEY); if (cmd.equals(ACTION_CANCEL)) { return getFileChooser().isEnabled(); } else if (cmd.equals(ACTION_EDIT_FILE_NAME)) { return !readOnly && getFileChooser().isEnabled(); } else { return true; } } } ArrayList<Action> actionList = new ArrayList<Action>(8); Action action; actionList.add(new FilePaneAction(ACTION_CANCEL)); actionList.add(new FilePaneAction(ACTION_EDIT_FILE_NAME)); FilePaneAction showHidden = new FilePaneAction(showHiddenFilesLabelText, ACTION_VIEW_HIDDEN); showHidden.putValue(Action.SELECTED_KEY, false); actionList.add(showHidden); actionList.add(new FilePaneAction(refreshActionLabelText, ACTION_REFRESH)); action = fileChooserUIAccessor.getApproveSelectionAction(); if (action != null) { actionList.add(action); } action = fileChooserUIAccessor.getChangeToParentDirectoryAction(); if (action != null) { actionList.add(action); } action = getNewFolderAction(); if (action != null) { actionList.add(action); } action = getViewTypeAction(VIEWTYPE_LIST); if (action != null) { actionList.add(action); } actions = actionList.toArray(new Action[actionList.size()]); } return actions.clone(); }
From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java
/** * @param map/*from ww w. j av a 2 s. c o m*/ * @param actions */ public static void addActionsToMap(ActionMap map, Action[] actions) { if ((map != null) && (actions != null)) { for (Action a : actions) { String cmd = (String) a.getValue(Action.ACTION_COMMAND_KEY); if (cmd == null) { cmd = (String) a.getValue(Action.NAME); } map.put(cmd, a); } } }
From source file:ca.phon.app.project.ProjectWindow.java
private MultiActionButton createCorpusButton() { MultiActionButton retVal = new MultiActionButton(); ImageIcon newIcn = IconManager.getInstance().getIcon("places/folder", IconSize.SMALL); String s1 = "Corpus"; String s2 = "Enter corpus 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 w w w .j av a 2s. com*/ ImageIcon cancelIcn = IconManager.getInstance().getIcon("actions/button_cancel", IconSize.SMALL); ImageIcon cancelIcnL = cancelIcn; PhonUIAction btnSwapAct = new PhonUIAction(this, "onSwapNewAndCreateCorpus", 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 corpusNamePanel = new JPanel(new BorderLayout()); corpusNamePanel.setOpaque(false); final JTextField corpusNameField = new JTextField(); corpusNameField.setDocument(new NameDocument()); corpusNameField.setText("Corpus Name"); corpusNamePanel.add(corpusNameField, 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 createNewCorpusAct = new PhonUIAction(this, "onCreateCorpus", corpusNameField); createNewCorpusAct.putValue(Action.SHORT_DESCRIPTION, "Create new corpus folder"); createNewCorpusAct.putValue(Action.SMALL_ICON, IconManager.getInstance().getIcon("actions/list-add", IconSize.SMALL)); JButton createBtn = new JButton(createNewCorpusAct); corpusNamePanel.add(createBtn, BorderLayout.EAST); corpusNameField.setAction(createNewCorpusAct); // swap bottom component in new project button retVal.setBottomLabelText(WorkspaceTextStyler.toDescText(s2)); retVal.add(corpusNamePanel, BorderLayout.CENTER); retVal.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { } @Override public void focusGained(FocusEvent e) { corpusNameField.requestFocus(); } }); return retVal; }
From source file:net.sf.vfsjfilechooser.filepane.VFSFilePane.java
public Action getNewFolderAction() { if (!readOnly && (newFolderAction == null)) { newFolderAction = new AbstractAction(newFolderActionLabelText) { private Action basicNewFolderAction; {/*from w w w . j a v a 2 s .com*/ putValue(Action.ACTION_COMMAND_KEY, VFSFilePane.ACTION_NEW_FOLDER); FileObject currentDirectory = getFileChooser().getCurrentDirectory(); if (currentDirectory != null) { setEnabled(canWrite(currentDirectory)); } } public void actionPerformed(ActionEvent ev) { if (basicNewFolderAction == null) { basicNewFolderAction = fileChooserUIAccessor.getNewFolderAction(); } VFSJFileChooser fc = getFileChooser(); FileObject oldFile = fc.getSelectedFile(); basicNewFolderAction.actionPerformed(ev); FileObject newFile = fc.getSelectedFile(); if ((newFile != null) && !newFile.equals(oldFile) && VFSUtils.isDirectory(newFile)) { newFolderFile = newFile; } } }; } return newFolderAction; }