List of usage examples for javax.swing KeyStroke getKeyStroke
public static KeyStroke getKeyStroke(String s)
KeyStroke
. From source file:com.t3.client.ui.T3Frame.java
private void removeWindowsF10() { InputMap imap = menuBar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); Object action = imap.get(KeyStroke.getKeyStroke("F10")); if (log.isInfoEnabled()) log.info("Removing the F10 key from the menuBar's InputMap; it did " + (action == null ? "not" : "") + " exist"); ActionMap amap = menuBar.getActionMap(); amap.getParent().remove(action);/*from w w w .j av a 2s . com*/ }
From source file:edu.ucla.stat.SOCR.chart.demo.SOCR_EM_MixtureModelChartDemo.java
private void addKeyEventListener() { // add key listener for press alt key event InputMap inputMap = chartPaneltest.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke metaPressedStroke = KeyStroke.getKeyStroke("alt ALT"); Action metaPressedAction = new AbstractAction() { public void actionPerformed(ActionEvent actionEvent) { if (!isPressingAlt) { isPressingAlt = true;//www. j a va 2 s . c o m chartPaneltest.setIsPressingAlt(true); //System.out.println("key Event EMDemo set " + isPressingAlt); } } }; inputMap.put(metaPressedStroke, "alt ALT"); chartPaneltest.getActionMap().put("alt ALT", metaPressedAction); //System.out.println("binding EMDemo alt ALT key Event"); KeyStroke metaReleasedStroke = KeyStroke.getKeyStroke("released ALT"); Action metaReleasedAction = new AbstractAction() { public void actionPerformed(ActionEvent actionEvent) { //System.out.println("reseting " + isPressingAlt); if (isPressingAlt) { isPressingAlt = false; chartPaneltest.setIsPressingAlt(false); // System.out.println("key Event EMDemo reset " + isPressingAlt); } } }; inputMap.put(metaReleasedStroke, "released ALT"); chartPaneltest.getActionMap().put("released ALT", metaReleasedAction); //System.out.println("binding EMDemo released ALT key Event"); }
From source file:edmondskarp.Gui.EdmondsKarpGui.java
private void setupUndoHotkeys() { String UNDO = "Undo action key"; String REDO = "Redo action key"; Action undoAction = new AbstractAction() { @Override/* w ww . j a v a 2 s . c o m*/ public void actionPerformed(ActionEvent e) { controller.restoreState(true); } }; Action redoAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { controller.restoreState(false); } }; myPanel.getActionMap().put(UNDO, undoAction); myPanel.getActionMap().put(REDO, redoAction); InputMap[] inputMaps = new InputMap[] { myPanel.getInputMap(JComponent.WHEN_FOCUSED), myPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT), myPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW), }; for (InputMap i : inputMaps) { i.put(KeyStroke.getKeyStroke("control Z"), UNDO); i.put(KeyStroke.getKeyStroke("control Y"), REDO); i.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), UNDO); } }
From source file:GUI.MainWindow.java
private void setupUndoListeners() { undo_manager.setLimit(-1);// www . j a v a 2 s. c o m this.VulnTitleTextField.getDocument().addUndoableEditListener(this.undo_manager); this.VulnDescriptionTextPane.getDocument().addUndoableEditListener(this.undo_manager); this.VulnRecommendationTextPane.getDocument().addUndoableEditListener(this.undo_manager); // Add actions into the Action Map. VulnDescriptionTextPane.getActionMap().put("Undo", new AbstractAction("Undo") { public void actionPerformed(ActionEvent evt) { try { if (undo_manager.canUndo()) { undo_manager.undo(); } } catch (CannotUndoException e) { } } }); VulnDescriptionTextPane.getActionMap().put("Redo", new AbstractAction("Redo") { public void actionPerformed(ActionEvent evt) { try { if (undo_manager.canRedo()) { undo_manager.redo(); } } catch (CannotRedoException e) { } } }); VulnRecommendationTextPane.getActionMap().put("Undo", new AbstractAction("Undo") { public void actionPerformed(ActionEvent evt) { try { if (undo_manager.canUndo()) { undo_manager.undo(); } } catch (CannotUndoException e) { } } }); VulnRecommendationTextPane.getActionMap().put("Redo", new AbstractAction("Redo") { public void actionPerformed(ActionEvent evt) { try { if (undo_manager.canRedo()) { undo_manager.redo(); } } catch (CannotRedoException e) { } } }); VulnTitleTextField.getActionMap().put("Undo", new AbstractAction("Undo") { public void actionPerformed(ActionEvent evt) { try { if (undo_manager.canUndo()) { undo_manager.undo(); } } catch (CannotUndoException e) { } } }); VulnTitleTextField.getActionMap().put("Redo", new AbstractAction("Redo") { public void actionPerformed(ActionEvent evt) { try { if (undo_manager.canRedo()) { undo_manager.redo(); } } catch (CannotRedoException e) { } } }); // Add the key mappings VulnDescriptionTextPane.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo"); VulnDescriptionTextPane.getInputMap().put(KeyStroke.getKeyStroke("control Y"), "Redo"); VulnRecommendationTextPane.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo"); VulnRecommendationTextPane.getInputMap().put(KeyStroke.getKeyStroke("control Y"), "Redo"); VulnTitleTextField.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo"); VulnTitleTextField.getInputMap().put(KeyStroke.getKeyStroke("control Y"), "Redo"); }
From source file:edu.ku.brc.ui.UIHelper.java
public static JTextArea createTextArea() { final JTextArea text = new JTextArea(); setControlSize(text);/*from www. j a v a 2 s .c o m*/ // Enable being able to TAB out of TextArea text.getInputMap().put(KeyStroke.getKeyStroke("TAB"), "none"); text.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent event) { if (event.getKeyCode() == VK_TAB) { if (event.isShiftDown()) { text.transferFocusBackward(); } else { text.transferFocus(); } } } }); return text; }
From source file:net.sourceforge.pmd.util.designer.Designer.java
private static void makeTextComponentUndoable(JTextComponent textConponent) { final UndoManager undoManager = new UndoManager(); textConponent.getDocument().addUndoableEditListener(new UndoableEditListener() { @Override/*ww w.jav a2 s .c o m*/ public void undoableEditHappened(UndoableEditEvent evt) { undoManager.addEdit(evt.getEdit()); } }); ActionMap actionMap = textConponent.getActionMap(); InputMap inputMap = textConponent.getInputMap(); actionMap.put("Undo", new AbstractAction("Undo") { @Override public void actionPerformed(ActionEvent evt) { try { if (undoManager.canUndo()) { undoManager.undo(); } } catch (CannotUndoException e) { throw new RuntimeException(e); } } }); inputMap.put(KeyStroke.getKeyStroke("control Z"), "Undo"); actionMap.put("Redo", new AbstractAction("Redo") { @Override public void actionPerformed(ActionEvent evt) { try { if (undoManager.canRedo()) { undoManager.redo(); } } catch (CannotRedoException e) { throw new RuntimeException(e); } } }); inputMap.put(KeyStroke.getKeyStroke("control Y"), "Redo"); }
From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java
public static void bindKeyFocused(JComponent component, String key, String actionKey, Action action) { component.getInputMap().put(KeyStroke.getKeyStroke(key), actionKey); component.getActionMap().put(actionKey, action); }
From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java
/** * Creates a wrapper around an existing action of the component to be used * in menus./*from w ww . java 2 s .com*/ * * @param c * base component * @param actionKey * key in the component's ActionMap * @param caption * caption of the action wrapper * @param acceleratorKey * accelerator key of the action wrapper * @return action that translates its * {@link Action#actionPerformed(ActionEvent)} to the underlaying * existing action. */ public static Action createActionWrapper(final JComponent c, final String actionKey, String caption, final String acceleratorKey) { final Action baseAction = c.getActionMap().get(actionKey); Action result = new AbstractAction(caption) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(acceleratorKey)); } @Override public void actionPerformed(ActionEvent e) { ActionEvent newEvent = new ActionEvent(c, e.getID(), actionKey, e.getWhen(), e.getModifiers()); baseAction.actionPerformed(newEvent); } @Override public void setEnabled(boolean newValue) { super.setEnabled(newValue); baseAction.setEnabled(newValue); } }; return result; }
From source file:org.colombbus.tangara.EditorFrame.java
/** * Returns the cut action/*from ww w .j a v a 2 s . c om*/ * * @return */ public Action getCutAction() { if (cutAction == null) { cutAction = new AbstractAction(Messages.getString("Banner.menu.cut")) { //$NON-NLS-1$ @Override public void actionPerformed(ActionEvent e) { cut(); } }; cutAction.setEnabled(false); cutAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control X")); } return cutAction; }
From source file:org.colombbus.tangara.EditorFrame.java
/** * Returns the copy action/*from ww w .j av a2 s.c o m*/ * * @return */ public Action getCopyAction() { if (copyAction == null) { copyAction = new AbstractAction(Messages.getString("Banner.menu.copy")) { //$NON-NLS-1$ @Override public void actionPerformed(ActionEvent e) { copy(); } }; copyAction.setEnabled(false); copyAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control C")); } return copyAction; }