javax.swing.KeyStroke#getKeyStroke ( )源码实例Demo

下面列出了javax.swing.KeyStroke#getKeyStroke ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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();
}
 
源代码2 项目: visualvm   文件: SearchUtils.java
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;
}
 
源代码3 项目: netbeans   文件: TabsComponent.java
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
}
 
源代码4 项目: portmapper   文件: EditPresetDialog.java
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);
}
 
源代码5 项目: netbeans   文件: ShowSQLDialog.java
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  
}
 
源代码6 项目: SubTitleSearcher   文件: AboutDialog.java
@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;
}
 
源代码7 项目: arcusplatform   文件: FormattedTextField.java
@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);
   }
}
 
源代码8 项目: marathonv5   文件: EscapeDialog.java
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);
}
 
源代码9 项目: IrScrutinizer   文件: TableUtils.java
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);
}
 
源代码10 项目: nextreports-designer   文件: SyntaxEditorKit.java
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)
	};
}
 
源代码11 项目: ghidra   文件: CutAction.java
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);
	};
}
 
源代码12 项目: netbeans   文件: CodeTemplateManagerOperation.java
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;
   }
 
源代码13 项目: FancyBing   文件: GuiUtil.java
/** 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);
    }
}
 
源代码14 项目: ghidra   文件: CycleGroup.java
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);

}
 
源代码15 项目: jplag   文件: RequestDialog.java
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;
}
 
源代码16 项目: ghidra   文件: CycleGroup.java
public StringCycleGroup() {
	super("Cycle: char,string,unicode");
	addDataType(new CharDataType());
	addDataType(new StringDataType());
	addDataType(new UnicodeDataType());

	defaultKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_QUOTE, 0);
}
 
源代码17 项目: ghidra   文件: NextPreviousLabelAction.java
@Override
protected KeyStroke getKeyStroke() {
	return KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_DOWN_MASK |
		InputEvent.ALT_DOWN_MASK);
}
 
源代码18 项目: keystore-explorer   文件: TableColumnAdjuster.java
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);
}
 
源代码19 项目: ghidra   文件: NextPreviousDefinedDataAction.java
@Override
protected KeyStroke getKeyStroke() {
	return KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK |
		InputEvent.ALT_DOWN_MASK);
}
 
源代码20 项目: jdk8u_jdk   文件: javax_swing_KeyStroke.java
protected KeyStroke getObject() {
    return KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.SHIFT_DOWN_MASK, true);
}