Java Code Examples for javax.swing.KeyStroke#getKeyStroke()

The following examples show how to use javax.swing.KeyStroke#getKeyStroke() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShowSQLDialog.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ShowSQLDialog() {
    super(WindowManager.getDefault().getMainWindow(), true);
    initComponents();

    jEditorPane1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ShowSQLDialog.class, "showsql.editorpane.accessibleName"));
    jEditorPane1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ShowSQLDialog.class, "ShowSQLDialog.jEditorPane1.AccessibleContext.accessibleDescription"));

    KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
    Action escapeAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    };
    getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ShowSQLDialog.class, "ShowSQLDialog.title"));
    getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ShowSQLDialog.class, "ShowSQLDialog.AccessibleContext.accessibleDescription"));

    getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE"); // NOI18N
    getRootPane().getActionMap().put("ESCAPE", escapeAction); // NOI18N  
}
 
Example 2
Source File: EditPresetDialog.java    From portmapper with GNU General Public License v3.0 6 votes vote down vote up
public EditPresetDialog(final PortMapperApp app, final PortMappingPreset portMappingPreset) {
    super(app.getMainFrame(), true);
    this.app = app;
    this.editedPreset = portMappingPreset;
    this.ports = new LinkedList<>();
    this.setName(DIALOG_NAME);
    initComponents();
    copyValuesFromPreset();
    this.propertyChangeSupport = new PropertyChangeSupport(ports);
    propertyChangeSupport.addPropertyChangeListener(PROPERTY_PORTS, tableModel);

    // Register an action listener that closes the window when the ESC
    // button is pressed
    final KeyStroke escKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true);
    final ActionListener windowCloseActionListener = e -> cancel();
    getRootPane().registerKeyboardAction(windowCloseActionListener, escKeyStroke,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}
 
Example 3
Source File: SharedKeyBindingDockingActionTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSharedKeyBinding_AddActionAfterOptionHasChanged_RepeatAddRemove() {

	TestAction action1 = new TestAction(OWNER_1, DEFAULT_KS_1);
	TestAction action2 = new TestAction(OWNER_2, DEFAULT_KS_1);

	tool.addAction(action1);
	KeyStroke newKs = KeyStroke.getKeyStroke(KeyEvent.VK_Z, 0);
	setSharedKeyBinding(newKs);

	assertKeyBinding(action1, newKs);

	// verify the newly added keybinding gets the newly changed option
	tool.addAction(action2);
	assertKeyBinding(action2, newKs);
	assertNoLoggedMessages();

	tool.removeAction(action2);
	assertActionNotInTool(action2);

	tool.addAction(action2);
	assertKeyBinding(action2, newKs);
	assertNoLoggedMessages();
}
 
Example 4
Source File: SearchUtils.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public KeyStroke registerAction(String actionKey, Action action, ActionMap actionMap, InputMap inputMap) {
    KeyStroke ks = null;
    
    if (FIND_ACTION_KEY.equals(actionKey)) {
        ks = KeyStroke.getKeyStroke(KeyEvent.VK_G, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    } else if (FIND_NEXT_ACTION_KEY.equals(actionKey)) {
        ks = KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0);
    } else if (FIND_PREV_ACTION_KEY.equals(actionKey)) {
        ks = KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.SHIFT_MASK);
    } else if (FIND_SEL_ACTION_KEY.equals(actionKey)) {
        ks = KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.CTRL_MASK);
    }
    
    if (ks != null) {
        actionMap.put(actionKey, action);
        inputMap.put(ks, actionKey);
    }

    return ks;
}
 
Example 5
Source File: TabsComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void startTogglingSplit() {
    ActionMap map = barSplit.getActionMap();
    Action act = new TogglesGoEastAction();
    // JToolbar action name
    map.put("navigateRight", act);//NOI18N
    InputMap input = barSplit.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    act = new TogglesGoWestAction();
    // JToolbar action name
    map.put("navigateLeft", act);//NOI18N

    act = new TogglesGoDownAction();
    map.put("TogglesGoDown", act);//NOI18N
    // JToolbar action name
    map.put("navigateUp", act);//NOI18N
    KeyStroke stroke = KeyStroke.getKeyStroke("ESCAPE"); //NOI18N
    input.put(stroke, "TogglesGoDown");//NOI18N
}
 
Example 6
Source File: CutAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public CutAction(SymbolTreePlugin plugin, SymbolTreeProvider provider) {
	super("Cut SymbolTree Node", plugin.getName());
	this.provider = provider;
	setEnabled(false);
	setPopupMenuData(new MenuData(new String[] { "Cut" }, CUT_ICON, "cut/paste"));
	KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_DOWN_MASK);
	setKeyBindingData(new KeyBindingData(keyStroke, ActionMapLevel));

	clipboardOwner = (currentClipboard, transferable) -> {
		GTreeNodeTransferable gtTransferable = (GTreeNodeTransferable) transferable;
		List<GTreeNode> nodeList = gtTransferable.getAllData();
		setNodesCut(nodeList, false);
	};
}
 
Example 7
Source File: CycleGroup.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public StringCycleGroup() {
	super("Cycle: char,string,unicode");
	addDataType(new CharDataType());
	addDataType(new StringDataType());
	addDataType(new UnicodeDataType());

	defaultKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_QUOTE, 0);
}
 
Example 8
Source File: RequestDialog.java    From jplag with GNU General Public License v3.0 5 votes vote down vote up
protected JRootPane createRootPane() {
	KeyStroke stroke=KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
	JRootPane rootPane=new JRootPane();
	rootPane.registerKeyboardAction(new ActionListener() {
			public void actionPerformed(ActionEvent actionEvent) {
                   doClose();
			}
		}, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
	
	return rootPane;
}
 
Example 9
Source File: CycleGroup.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public ByteCycleGroup() {
	super("Cycle: byte,word,dword,qword");
	addDataType(new ByteDataType());
	addDataType(new WordDataType());
	addDataType(new DWordDataType());
	addDataType(new QWordDataType());

	defaultKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_B, 0);

}
 
Example 10
Source File: GuiUtil.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
/** Parse text that has the mnemonic marked with a preceding'&amp;'
    (like in Qt) and set the text and mnemonic of the button. */
public static void setTextAndMnemonic(AbstractButton button, String text)
{
    int pos = text.indexOf('&');
    text = text.replace("&", "");
    button.setText(text);
    if (pos >= 0 && pos < text.length())
    {
        String mnemonic = text.substring(pos, pos + 1).toUpperCase();
        KeyStroke keyStroke = KeyStroke.getKeyStroke(mnemonic);
        int code = keyStroke.getKeyCode();
        button.setMnemonic(code);
        button.setDisplayedMnemonicIndex(pos);
    }
}
 
Example 11
Source File: CodeTemplateManagerOperation.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static KeyStroke patchExpansionKey(KeyStroke eks) {
// Patch the keyPressed => keyTyped to prevent insertion of expand chars into editor
       if (eks.equals(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0))) {
           eks = KeyStroke.getKeyStroke(' ');
       } else if (eks.equals(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_MASK))) {
           eks = KeyStroke.getKeyStroke(new Character(' '), InputEvent.SHIFT_MASK);
       } else if (eks.equals(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0))) {
       } else if (eks.equals(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0))) {
       }
return eks;
   }
 
Example 12
Source File: SyntaxEditorKit.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
private JTextComponent.KeyBinding[] getDefaultKeyBindings() {
	return new JTextComponent.KeyBinding[] {
			new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("control Z"), undoAction),
			new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("control Y"), redoAction),
			new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("TAB"), indentAction),
			new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("shift TAB"), unindentAction)
	};
}
 
Example 13
Source File: TableUtils.java    From IrScrutinizer with GNU General Public License v3.0 5 votes vote down vote up
private void addKey(JTable table, String name, int key, int mask, Action action) {
    InputMap inputMap = table.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap actionMap = table.getActionMap();
    KeyStroke keyStroke = KeyStroke.getKeyStroke(key, mask);
    inputMap.put(keyStroke, name);
    actionMap.put(name, action);
}
 
Example 14
Source File: EscapeDialog.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void setCloseButton(final JButton button) {
    if (button == null)
        return;
    Action action = new AbstractAction() {
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent e) {
            button.doClick();
        }
    };
    KeyStroke escapeStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke, "ESCAPE");
    getRootPane().getActionMap().put("ESCAPE", action);
}
 
Example 15
Source File: FormattedTextField.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
   if (validateContent()) {
      return super.processKeyBinding(ks, e, condition, pressed)
            && ks != KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
   }
   else {
      return super.processKeyBinding(ks, e, condition, pressed);
   }
}
 
Example 16
Source File: AboutDialog.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
@Override
protected JRootPane createRootPane() {
	KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
	JRootPane rootPane = new JRootPane();
	rootPane.registerKeyboardAction(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			escapeKeyProc();
		}
	}, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);

	return rootPane;
}
 
Example 17
Source File: javax_swing_KeyStroke.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected KeyStroke getObject() {
    return KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.SHIFT_DOWN_MASK, true);
}
 
Example 18
Source File: NextPreviousLabelAction.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
protected KeyStroke getKeyStroke() {
	return KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_DOWN_MASK |
		InputEvent.ALT_DOWN_MASK);
}
 
Example 19
Source File: NextPreviousDefinedDataAction.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
protected KeyStroke getKeyStroke() {
	return KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK |
		InputEvent.ALT_DOWN_MASK);
}
 
Example 20
Source File: TableColumnAdjuster.java    From keystore-explorer with GNU General Public License v3.0 4 votes vote down vote up
private void installToggleAction(boolean isToggleDynamic, boolean isToggleLarger, String key, String keyStroke) {
	Action action = new ToggleAction(isToggleDynamic, isToggleLarger);
	KeyStroke ks = KeyStroke.getKeyStroke(keyStroke);
	table.getInputMap().put(ks, key);
	table.getActionMap().put(key, action);
}