List of usage examples for javax.swing Action ACCELERATOR_KEY
String ACCELERATOR_KEY
To view the source code for javax.swing Action ACCELERATOR_KEY.
Click Source Link
KeyStroke
to be used as the accelerator for the action. From source file:burlov.ultracipher.swing.MainPanel.java
public Action getDeleteEntryAction() { Action ret = new AbstractAction("deleteEntryAction") { /**//from w w w . j a va 2s. c o m * */ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { deleteCurrentEntry(); } }; ret.putValue(Action.NAME, "Delete entry"); ret.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control D")); return ret; }
From source file:com.intuit.tank.tools.debugger.ActionProducer.java
/** * /*from w w w. j ava2 s . c om*/ * @return */ public Action getFindAction() { Action ret = actionMap.get(ACTION_FIND); if (ret == null) { ret = new AbstractAction(ACTION_FIND, getIcon("find.png", IconSize.SMALL)) { private static final long serialVersionUID = 1L; private FindReplaceDialog dialog; @Override public void actionPerformed(ActionEvent event) { try { if (dialog == null) { dialog = new FindReplaceDialog(debuggerFrame, DialogType.SEARCH); } dialog.setVisible(true); } catch (HeadlessException e) { showError("Error opening file: " + e); } } }; ret.putValue(Action.SHORT_DESCRIPTION, "Find in script."); ret.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('F', menuActionMods)); ret.putValue(Action.MNEMONIC_KEY, new Integer('F')); ret.setEnabled(false); actionMap.put(ACTION_FIND, ret); } return ret; }
From source file:burlov.ultracipher.swing.MainPanel.java
public Action getNewEntryAction() { Action ret = new AbstractAction("deleteEntryAction") { /**/*from w w w .j a v a2 s.c o m*/ * */ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { getEditDataPanel().setEditable(true); newEntry(); } }; ret.putValue(Action.NAME, "New entry"); ret.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control N")); return ret; }
From source file:de.ailis.xadrian.utils.SwingUtils.java
/** * Adds a component action./*from w ww . j a v a 2 s.c o m*/ * * @param component * The compoenet to add the action to * @param action * The action to add */ public static void addComponentAction(final JComponent component, final Action action) { final InputMap imap = component .getInputMap(component.isFocusable() ? JComponent.WHEN_FOCUSED : JComponent.WHEN_IN_FOCUSED_WINDOW); final ActionMap amap = component.getActionMap(); final KeyStroke ks = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY); imap.put(ks, action.getValue(Action.NAME)); amap.put(action.getValue(Action.NAME), action); }
From source file:net.pandoragames.far.ui.swing.component.UndoHistory.java
/** * Registers the specified text component for the undo history. * This enables the <code>ctrl + z</code> and <code>ctrl + y</code> shortcuts. * @param component to be registered for undos. *//* ww w . j a va2s. c o m*/ public void registerUndoHistory(JTextComponent component) { // Create an undo action and add it to the text component undoAction = new AbstractAction("Undo") { public void actionPerformed(ActionEvent evt) { if (UndoHistory.this.canUndo()) { UndoHistory.this.undo(); } } }; undoAction.setEnabled(false); component.getActionMap().put(ACTION_KEY_UNDO, undoAction); // Create a redo action and add it to the text component redoAction = new AbstractAction("Redo") { public void actionPerformed(ActionEvent evt) { if (UndoHistory.this.canRedo()) { UndoHistory.this.redo(); } } }; redoAction.setEnabled(false); component.getActionMap().put(ACTION_KEY_REDO, redoAction); // Bind the actions to ctl-Z and ctl-Y component.getInputMap().put(KeyStroke.getKeyStroke("control Z"), ACTION_KEY_UNDO); undoAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control Z")); component.getInputMap().put(KeyStroke.getKeyStroke("control Y"), ACTION_KEY_REDO); redoAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control Y")); // registers this UndoHistory as an UndoableEditListener component.getDocument().addUndoableEditListener(this); }
From source file:com.intuit.tank.tools.debugger.ActionProducer.java
/** * /*from w ww . j a v a 2 s .com*/ * @return */ public Action getOpenAction() { Action ret = actionMap.get(ACTION_OPEN); if (ret == null) { ret = new AbstractAction(ACTION_OPEN, getIcon("script_go.png", IconSize.SMALL)) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { try { int option = jFileChooser.showOpenDialog(debuggerFrame); if (option != JFileChooser.CANCEL_OPTION) { File selectedFile = jFileChooser.getSelectedFile(); try { String scriptXml = FileUtils.readFileToString(selectedFile); setFromString(scriptXml); debuggerFrame.setScriptSource( new ScriptSource(selectedFile.getAbsolutePath(), SourceType.file)); } catch (Exception e) { LOG.error("Error reading file " + selectedFile.getName() + ": " + e); JOptionPane.showMessageDialog(debuggerFrame, e.getMessage(), "Error unmarshalling xml", JOptionPane.ERROR_MESSAGE); } } } catch (HeadlessException e) { showError("Error opening file: " + e); } } }; ret.putValue(Action.SHORT_DESCRIPTION, "Open Agent xml from filesystem."); ret.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('O', menuActionMods)); ret.putValue(Action.MNEMONIC_KEY, new Integer('O')); actionMap.put(ACTION_OPEN, ret); } return ret; }
From source file:net.pandoragames.far.ui.swing.component.UndoHistory.java
/** * Registers the specified text component for the snapshot history. * This enables the <code>alt + ←</code> and <code>ctrl + →</code> shortcuts. * @param component to be registered for snapshots. *//*from w ww .ja v a 2 s . c o m*/ public void registerSnapshotHistory(JTextComponent component) { snapshots = new SnapshotHistory(component); // Create a previous action and add it to the text component previousAction = new AbstractAction("Previous") { public void actionPerformed(ActionEvent evt) { UndoHistory.this.previous(); } }; previousAction.setEnabled(false); component.getActionMap().put(ACTION_KEY_PREVIOUS, previousAction); // Create a next action and add it to the text component nextAction = new AbstractAction("Next") { public void actionPerformed(ActionEvent evt) { UndoHistory.this.next(); } }; nextAction.setEnabled(false); component.getActionMap().put(ACTION_KEY_NEXT, nextAction); // Bind the actions to alt-left-arrow and alt-right arrow previousAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("alt LEFT")); component.getInputMap().put(KeyStroke.getKeyStroke("alt LEFT"), ACTION_KEY_PREVIOUS); component.getInputMap().put(KeyStroke.getKeyStroke("alt KP_LEFT"), ACTION_KEY_PREVIOUS); nextAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("alt RIGHT")); component.getInputMap().put(KeyStroke.getKeyStroke("alt RIGHT"), ACTION_KEY_NEXT); component.getInputMap().put(KeyStroke.getKeyStroke("alt KP_RIGHT"), ACTION_KEY_NEXT); }
From source file:com.intuit.tank.tools.debugger.ActionProducer.java
/** * //from w w w. j a v a 2 s .co m * @return */ public Action getReloadAction() { Action ret = actionMap.get(ACTION_RELOAD); if (ret == null) { ret = new AbstractAction(ACTION_RELOAD, getIcon("refresh.png", IconSize.SMALL)) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { try { final ScriptSource scriptSource = debuggerFrame.getScriptSource(); if (scriptSource != null) { debuggerFrame.startWaiting(); setFromString(null); // get script in thread new Thread(new Runnable() { public void run() { try { String scriptXml = null; if (scriptSource.getSource() == SourceType.file) { scriptXml = FileUtils.readFileToString(new File(scriptSource.getId())); } else if (scriptSource.getSource() == SourceType.script) { scriptXml = scriptServiceClient .downloadHarnessXml(Integer.parseInt(scriptSource.getId())); } else if (scriptSource.getSource() == SourceType.project) { scriptXml = projectServiceClient.downloadTestScriptForProject( Integer.parseInt(scriptSource.getId())); } if (scriptXml != null) { setFromString(scriptXml); } } catch (Exception e1) { e1.printStackTrace(); debuggerFrame.stopWaiting(); showError("Error opening from source: " + e1); } finally { debuggerFrame.stopWaiting(); } } }).start(); } else { JOptionPane.showMessageDialog(debuggerFrame, "Scripts can only be reloaded if they have been loaded first.", "Load Script from source", JOptionPane.ERROR_MESSAGE); } } catch (HeadlessException e) { showError("Error opening file: " + e); } } }; ret.putValue(Action.SHORT_DESCRIPTION, "Reload scrpt from source."); ret.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('R', menuActionMods)); ret.putValue(Action.MNEMONIC_KEY, new Integer('R')); ret.setEnabled(false); actionMap.put(ACTION_RELOAD, ret); } return ret; }
From source file:net.schweerelos.parrot.CombinedParrotApp.java
@SuppressWarnings("serial") private JToggleButton setupNavigatorButton(final String name, final String accelerator, final NavigatorComponent navigator) { final Component component = navigator.asJComponent(); AbstractAction showNavigatorAction = new AbstractAction(name) { @Override// ww w .j av a 2s . com public void actionPerformed(ActionEvent e) { if (!(e.getSource() instanceof JToggleButton)) { return; } final Window window; if (component instanceof Window) { window = (Window) component; } else { window = SwingUtilities.getWindowAncestor(component); } JToggleButton button = (JToggleButton) e.getSource(); boolean show = button.isSelected(); if (show) { if (window != CombinedParrotApp.this && preferredFrameLocations.containsKey(window)) { window.setLocation(preferredFrameLocations.get(window)); } } if (navigator.tellSelectionWhenShown()) { Collection<NodeWrapper> selectedNodes = activeMainView.getSelectedNodes(); navigator.setSelectedNodes(selectedNodes); } component.setVisible(show); if (show) { window.setVisible(true); } else if (window != CombinedParrotApp.this) { window.setVisible(false); } } }; showNavigatorAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control " + accelerator)); final JToggleButton button = new JToggleButton(showNavigatorAction); button.setToolTipText("Show " + name.toLowerCase()); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button.setToolTipText((button.isSelected() ? "Hide " : "Show ") + name.toLowerCase()); } }); final Window window; if (component instanceof Window) { window = (Window) component; } else { window = SwingUtilities.getWindowAncestor(component); } if (window != null) { window.addComponentListener(new ComponentAdapter() { @Override public void componentHidden(ComponentEvent e) { button.setSelected(false); if (window != CombinedParrotApp.this) { preferredFrameLocations.put(window, window.getLocation()); } } @Override public void componentShown(ComponentEvent e) { button.setSelected(true); } }); } return button; }
From source file:net.sf.jabref.gui.groups.GroupSelector.java
/** * The first element for each group defines which field to use for the quicksearch. The next two define the name and * regexp for the group.// ww w . j a v a 2s.c o m */ public GroupSelector(JabRefFrame frame, SidePaneManager manager) { super(manager, IconTheme.JabRefIcon.TOGGLE_GROUPS.getIcon(), Localization.lang("Groups")); this.frame = frame; hideNonHits = new JRadioButtonMenuItem(Localization.lang("Hide non-hits"), !Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS)); grayOut = new JRadioButtonMenuItem(Localization.lang("Gray out non-hits"), Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS)); ButtonGroup nonHits = new ButtonGroup(); nonHits.add(hideNonHits); nonHits.add(grayOut); floatCb.addChangeListener( event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS, floatCb.isSelected())); andCb.addChangeListener(event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS, andCb.isSelected())); invCb.addChangeListener( event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS, invCb.isSelected())); showOverlappingGroups.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING, showOverlappingGroups.isSelected()); if (!showOverlappingGroups.isSelected()) { groupsTree.setOverlappingGroups(Collections.emptyList()); } } }); grayOut.addChangeListener( event -> Globals.prefs.putBoolean(JabRefPreferences.GRAY_OUT_NON_HITS, grayOut.isSelected())); JRadioButtonMenuItem highlCb = new JRadioButtonMenuItem(Localization.lang("Highlight"), false); if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS)) { floatCb.setSelected(true); highlCb.setSelected(false); } else { highlCb.setSelected(true); floatCb.setSelected(false); } JRadioButtonMenuItem orCb = new JRadioButtonMenuItem(Localization.lang("Union"), false); if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS)) { andCb.setSelected(true); orCb.setSelected(false); } else { orCb.setSelected(true); andCb.setSelected(false); } showNumberOfElements.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS, showNumberOfElements.isSelected()); if (groupsTree != null) { groupsTree.invalidate(); groupsTree.repaint(); } } }); autoAssignGroup.addChangeListener(event -> Globals.prefs.putBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP, autoAssignGroup.isSelected())); invCb.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS)); showOverlappingGroups.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING)); editModeIndicator = Globals.prefs.getBoolean(JabRefPreferences.EDIT_GROUP_MEMBERSHIP_MODE); editModeCb.setSelected(editModeIndicator); showNumberOfElements.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS)); autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)); JButton openSettings = new JButton(IconTheme.JabRefIcon.PREFERENCES.getSmallIcon()); settings.add(andCb); settings.add(orCb); settings.addSeparator(); settings.add(invCb); settings.addSeparator(); settings.add(editModeCb); settings.addSeparator(); settings.add(grayOut); settings.add(hideNonHits); settings.addSeparator(); settings.add(showOverlappingGroups); settings.addSeparator(); settings.add(showNumberOfElements); settings.add(autoAssignGroup); openSettings.addActionListener(e -> { if (!settings.isVisible()) { JButton src = (JButton) e.getSource(); showNumberOfElements .setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS)); autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)); settings.show(src, 0, openSettings.getHeight()); } }); editModeCb.addActionListener(e -> setEditMode(editModeCb.getState())); JButton newButton = new JButton(IconTheme.JabRefIcon.ADD_NOBOX.getSmallIcon()); int butSize = newButton.getIcon().getIconHeight() + 5; Dimension butDim = new Dimension(butSize, butSize); newButton.setPreferredSize(butDim); newButton.setMinimumSize(butDim); JButton helpButton = new HelpAction(Localization.lang("Help on groups"), HelpFile.GROUP).getHelpButton(); helpButton.setPreferredSize(butDim); helpButton.setMinimumSize(butDim); JButton autoGroup = new JButton(IconTheme.JabRefIcon.AUTO_GROUP.getSmallIcon()); autoGroup.setPreferredSize(butDim); autoGroup.setMinimumSize(butDim); openSettings.setPreferredSize(butDim); openSettings.setMinimumSize(butDim); Insets butIns = new Insets(0, 0, 0, 0); helpButton.setMargin(butIns); openSettings.setMargin(butIns); newButton.addActionListener(e -> { GroupDialog gd = new GroupDialog(frame, panel, null); gd.setVisible(true); if (gd.okPressed()) { AbstractGroup newGroup = gd.getResultingGroup(); groupsRoot.addNewGroup(newGroup, panel.getUndoManager()); panel.markBaseChanged(); frame.output(Localization.lang("Created group \"%0\".", newGroup.getName())); } }); andCb.addActionListener(e -> valueChanged(null)); orCb.addActionListener(e -> valueChanged(null)); invCb.addActionListener(e -> valueChanged(null)); showOverlappingGroups.addActionListener(e -> valueChanged(null)); autoGroup.addActionListener(e -> { AutoGroupDialog gd = new AutoGroupDialog(frame, panel, groupsRoot, Globals.prefs.get(JabRefPreferences.GROUPS_DEFAULT_FIELD), " .,", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); gd.setVisible(true); // gd does the operation itself }); floatCb.addActionListener(e -> valueChanged(null)); highlCb.addActionListener(e -> valueChanged(null)); hideNonHits.addActionListener(e -> valueChanged(null)); grayOut.addActionListener(e -> valueChanged(null)); newButton.setToolTipText(Localization.lang("New group")); andCb.setToolTipText(Localization.lang("Display only entries belonging to all selected groups.")); orCb.setToolTipText( Localization.lang("Display all entries belonging to one or more of the selected groups.")); autoGroup.setToolTipText(Localization.lang("Automatically create groups for database.")); openSettings.setToolTipText(Localization.lang("Settings")); invCb.setToolTipText( "<html>" + Localization.lang("Show entries <b>not</b> in group selection") + "</html>"); showOverlappingGroups.setToolTipText(Localization .lang("Highlight groups that contain entries contained in any currently selected group")); floatCb.setToolTipText(Localization.lang("Move entries in group selection to the top")); highlCb.setToolTipText(Localization.lang("Gray out entries not in group selection")); editModeCb.setToolTipText(Localization.lang("Click group to toggle membership of selected entries")); ButtonGroup bgr = new ButtonGroup(); bgr.add(andCb); bgr.add(orCb); ButtonGroup visMode = new ButtonGroup(); visMode.add(floatCb); visMode.add(highlCb); JPanel rootPanel = new JPanel(); GridBagLayout gbl = new GridBagLayout(); rootPanel.setLayout(gbl); GridBagConstraints con = new GridBagConstraints(); con.fill = GridBagConstraints.BOTH; con.weightx = 1; con.gridwidth = 1; con.gridy = 0; con.gridx = 0; gbl.setConstraints(newButton, con); rootPanel.add(newButton); con.gridx = 1; gbl.setConstraints(autoGroup, con); rootPanel.add(autoGroup); con.gridx = 2; gbl.setConstraints(openSettings, con); rootPanel.add(openSettings); con.gridx = 3; con.gridwidth = GridBagConstraints.REMAINDER; gbl.setConstraints(helpButton, con); rootPanel.add(helpButton); groupsTree = new GroupsTree(this); groupsTree.addTreeSelectionListener(this); JScrollPane groupsTreePane = new JScrollPane(groupsTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); groupsTreePane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); con.gridwidth = GridBagConstraints.REMAINDER; con.weighty = 1; con.gridx = 0; con.gridwidth = 4; con.gridy = 1; gbl.setConstraints(groupsTreePane, con); rootPanel.add(groupsTreePane); add(rootPanel, BorderLayout.CENTER); setEditMode(editModeIndicator); definePopup(); NodeAction moveNodeUpAction = new MoveNodeUpAction(); moveNodeUpAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.CTRL_MASK)); NodeAction moveNodeDownAction = new MoveNodeDownAction(); moveNodeDownAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.CTRL_MASK)); NodeAction moveNodeLeftAction = new MoveNodeLeftAction(); moveNodeLeftAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.CTRL_MASK)); NodeAction moveNodeRightAction = new MoveNodeRightAction(); moveNodeRightAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.CTRL_MASK)); setGroups(GroupTreeNode.fromGroup(new AllEntriesGroup())); }