本文整理匯總了Java中javax.swing.KeyStroke.getKeyStroke方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyStroke.getKeyStroke方法的具體用法?Java KeyStroke.getKeyStroke怎麽用?Java KeyStroke.getKeyStroke使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.KeyStroke
的用法示例。
在下文中一共展示了KeyStroke.getKeyStroke方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getKeyStroke
import javax.swing.KeyStroke; //導入方法依賴的package包/類
/**
* Return the generated KeyStroke associated with the NamedKeyStroke
* @param vkey
* @return generated KeyStroke
*/
public KeyStroke getKeyStroke(NamedKeyStroke vkey) {
// No name means it is just a standard keystroke
if (!vkey.isNamed()) {
return vkey.getStroke();
}
// Look up the name in the cache and allocate the next
// available KeyStroke if required.
KeyStroke stroke = strokes.get(vkey.getName());
if (stroke == null) {
stroke = KeyStroke.getKeyStroke(getNextStroke(), 0);
strokes.put(vkey.getName(), stroke);
}
return stroke;
}
示例2: getDynamicPropertyDecorator
import javax.swing.KeyStroke; //導入方法依賴的package包/類
public DynamicProperty getDynamicPropertyDecorator() {
SequenceEncoder type = new SequenceEncoder(';');
type.append("Layer");
SequenceEncoder constraints = new SequenceEncoder(',');
constraints.append(true).append(0).append(1).append(true);
type.append(constraints.getValue());
SequenceEncoder command = new SequenceEncoder(':');
KeyStroke stroke = KeyStroke.getKeyStroke('=', InputEvent.SHIFT_DOWN_MASK);
SequenceEncoder change = new SequenceEncoder(',');
change.append('I').append(1);
command.append("Draw on top").append(stroke.getKeyCode() + "," + stroke.getModifiers()).append(change.getValue());
type.append(new SequenceEncoder(command.getValue(), ',').getValue());
DynamicProperty dp = new DynamicProperty();
dp.mySetType(DynamicProperty.ID + type.getValue());
return dp;
}
示例3: getKeyStroke
import javax.swing.KeyStroke; //導入方法依賴的package包/類
/**
* Convert human-readable keystroke name to {@link KeyStroke} object.
*/
public static @CheckForNull KeyStroke getKeyStroke(
@NonNull String keyStroke) {
int modifiers = 0;
while (true) {
if (keyStroke.startsWith(EMACS_CTRL)) {
modifiers |= InputEvent.CTRL_DOWN_MASK;
keyStroke = keyStroke.substring(EMACS_CTRL.length());
} else if (keyStroke.startsWith(EMACS_ALT)) {
modifiers |= InputEvent.ALT_DOWN_MASK;
keyStroke = keyStroke.substring(EMACS_ALT.length());
} else if (keyStroke.startsWith(EMACS_SHIFT)) {
modifiers |= InputEvent.SHIFT_DOWN_MASK;
keyStroke = keyStroke.substring(EMACS_SHIFT.length());
} else if (keyStroke.startsWith(EMACS_META)) {
modifiers |= InputEvent.META_DOWN_MASK;
keyStroke = keyStroke.substring(EMACS_META.length());
} else if (keyStroke.startsWith(STRING_ALT)) {
modifiers |= InputEvent.ALT_DOWN_MASK;
keyStroke = keyStroke.substring(STRING_ALT.length());
} else if (keyStroke.startsWith(STRING_META)) {
modifiers |= InputEvent.META_DOWN_MASK;
keyStroke = keyStroke.substring(STRING_META.length());
} else {
break;
}
}
KeyStroke ks = Utilities.stringToKey (keyStroke);
if (ks == null) { // Return null to indicate an invalid keystroke
return null;
} else {
KeyStroke result = KeyStroke.getKeyStroke (ks.getKeyCode (), modifiers);
return result;
}
}
示例4: putIntoActionMap
import javax.swing.KeyStroke; //導入方法依賴的package包/類
private void putIntoActionMap (JComponent component) {
KeyStroke ks = (KeyStroke)getValue (ACCELERATOR_KEY);
Object key = getValue (NAME);
if (ks == null) {
ks = KeyStroke.getKeyStroke ((Integer)getValue (MNEMONIC_KEY), KeyEvent.ALT_DOWN_MASK);
}
if (ks != null && key != null) {
component.getInputMap (JComponent.WHEN_FOCUSED).put (ks, key);
component.getActionMap ().put (key,this);
}
}
示例5: ClassMemberPanelUI
import javax.swing.KeyStroke; //導入方法依賴的package包/類
/** Creates new form ClassMemberPanelUi */
public ClassMemberPanelUI(final Language language) {
initComponents();
// Tree view of the elements
elementView = createBeanTreeView();
add(elementView, BorderLayout.CENTER);
filters = new ClassMemberFilters( this );
filters.getInstance().hookChangeListener(this);
// See http://www.netbeans.org/issues/show_bug.cgi?id=186407
// Making the calls to getStructure() out of AWT EDT
RP.post(new UpdateFilterState(language));
// filters
filtersPanel = new TapPanel();
filtersLbl = new JLabel(NbBundle.getMessage(ClassMemberPanelUI.class, "LBL_Filter")); //NOI18N
filtersLbl.setBorder(new EmptyBorder(0, 5, 5, 0));
filtersPanel.add(filtersLbl);
filtersPanel.setOrientation(TapPanel.DOWN);
// tooltip
KeyStroke toggleKey = KeyStroke.getKeyStroke(KeyEvent.VK_T,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
String keyText = Utilities.keyToString(toggleKey);
filtersPanel.setToolTipText(NbBundle.getMessage(ClassMemberPanelUI.class, "TIP_TapPanel", keyText));
filtersPanel.add(filters.getComponent());
add(filtersPanel, BorderLayout.SOUTH);
manager.setRootContext(ElementNode.getWaitNode());
lookup = ExplorerUtils.createLookup(manager, getActionMap());
}
示例6: keyReleased
import javax.swing.KeyStroke; //導入方法依賴的package包/類
@Override
public void keyReleased(KeyEvent e) {
KeyStroke ks = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers());
if (FreeColActionUI.this.optionGroupUI != null) {
FreeColActionUI.this.optionGroupUI.removeKeyStroke(ks);
}
keyStroke = ks;
//keyStroke = KeyStroke.getKeyStroke(new Character(e.getKeyChar()), e.getModifiers());
stopBlinking();
setText(getHumanKeyStrokeText(keyStroke));
recordButton.requestFocus();
}
示例7: fixCtrlH
import javax.swing.KeyStroke; //導入方法依賴的package包/類
/**
* Removes the "Ctrl+H <=> Backspace" behavior that Java shows, for some
* odd reason...
*/
private void fixCtrlH() {
InputMap inputMap = getInputMap();
KeyStroke char010 = KeyStroke.getKeyStroke("typed \010");
InputMap parent = inputMap;
while (parent != null) {
parent.remove(char010);
parent = parent.getParent();
}
if (inputMap != null) { // Just for Sonar
KeyStroke backspace = KeyStroke.getKeyStroke("BACK_SPACE");
inputMap.put(backspace, DefaultEditorKit.deletePrevCharAction);
}
}
示例8: getStopEvents
import javax.swing.KeyStroke; //導入方法依賴的package包/類
public KeyStroke[] getStopEvents() {
return new KeyStroke[] {
KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0),
KeyStroke.getKeyStroke(KeyEvent.VK_F7, KeyEvent.SHIFT_DOWN_MASK),
KeyStroke.getKeyStroke(KeyEvent.VK_F7, KeyEvent.CTRL_DOWN_MASK)
};
}
示例9: testSpecialKeyworksOn14AsWell15
import javax.swing.KeyStroke; //導入方法依賴的package包/類
public void testSpecialKeyworksOn14AsWell15 () throws Exception {
KeyStroke ks = Utilities.stringToKey("C-CONTEXT_MENU");
assertNotNull ("key stroke created", ks);
KeyStroke alt = KeyStroke.getKeyStroke(ks.getKeyCode(), KeyEvent.ALT_MASK);
String s = Utilities.keyToString(alt);
assertEquals ("Correctly converted", "A-CONTEXT_MENU", s);
}
示例10: buildFileMenu
import javax.swing.KeyStroke; //導入方法依賴的package包/類
private void buildFileMenu() {
setFileMenu(new JMenu());
fileMenu.setMnemonic(KeyEvent.VK_F);
newDatabase = new JMenuItem("New Database");
newDatabase.setMnemonic(KeyEvent.VK_N);
openDatabase = new JMenuItem("Open...");
openDatabase.setMnemonic(KeyEvent.VK_O);
saveDatabase = new JMenuItem("Save");
saveDatabase.setMnemonic(KeyEvent.VK_S);
saveDatabaseAs = new JMenuItem("Save As...");
importOption = new JMenu("Import");
importRelAlgQuery = new JMenuItem("Relational Algebra Query");
importOption.add(importRelAlgQuery);
exportOption = new JMenu("Export");
exportRelAlgQuery = new JMenuItem("Relational Algebra Query");
exportSqlQuery = new JMenuItem("SQL Query");
exportParseTree = new JMenuItem("Parse Tree (.png)");
exportQueryResultTable = new JMenuItem("Result Table (.csv)");
exportOption.add(exportRelAlgQuery);
exportOption.add(exportSqlQuery);
exportOption.add(exportParseTree);
exportOption.add(exportQueryResultTable);
exitOption = new JMenuItem("Exit");
//getFileMenu().add(newDatabase);
getFileMenu().add(openDatabase);
getFileMenu().add(new JSeparator());
getFileMenu().add(saveDatabase);
getFileMenu().add(saveDatabaseAs);
getFileMenu().add(new JSeparator());
getFileMenu().add(importOption);
getFileMenu().add(exportOption);
getFileMenu().add(new JSeparator());
getFileMenu().add(exitOption);
saveDatabase.setEnabled(false);
saveDatabaseAs.setEnabled(false);
importOption.setEnabled(false);
exportOption.setEnabled(false);
KeyStroke ctrlN = KeyStroke.getKeyStroke(
KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
KeyStroke ctrlO = KeyStroke.getKeyStroke(
KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
KeyStroke ctrlS = KeyStroke.getKeyStroke(
KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
newDatabase.setAccelerator(ctrlN);
openDatabase.setAccelerator(ctrlO);
saveDatabase.setAccelerator(ctrlS);
}
示例11: CheckAction
import javax.swing.KeyStroke; //導入方法依賴的package包/類
public CheckAction () {
super ("UnitTab_CheckAction", KeyStroke.getKeyStroke (KeyEvent.VK_SPACE, 0), null);
}
示例12: getAccelerator
import javax.swing.KeyStroke; //導入方法依賴的package包/類
@Override
public KeyStroke getAccelerator() {
return KeyStroke.getKeyStroke(KeyEvent.VK_O, ACCELERATOR_MODIFIER);
}
示例13: zoomMenuCommands
import javax.swing.KeyStroke; //導入方法依賴的package包/類
/**
* Adds support for plus and minus menu commands, typically for zooming in
* and out. This is designed for menu items with key accelerators using
* KeyEvent.VK_ADD and KeyEvent.VK_SUBTRACT (which are typically on the
* numerical key pad). It adds support for KeyEvent.VK_MINUS and
* KeyEvent.VK_PLUS, and KeyEvent.VK_EQUALS for keyboard layouts with the
* plus sign as secondary key for the equals.
*
* @param inputMap add key event to this InputMap
* @param actionMap add action to this ActionMap
* @param zoomInAction action to call when the + key and the menu shortcut
* key are pressed
* @param zoomOutAction action to call when the - key and the menu shortcut
* key are pressed
*/
public static void zoomMenuCommands(InputMap inputMap, ActionMap actionMap, Action zoomInAction, Action zoomOutAction) {
int menuKeyMask = java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
// add support for minus key
KeyStroke minusMenueKeyStroke = KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_MINUS, menuKeyMask);
inputMap.put(minusMenueKeyStroke, "zoomOutWithMinusKey");
actionMap.put("zoomOutWithMinusKey", zoomOutAction);
// add support for plus key to zoom in. This only works if the keyboard
// layout allows access to the plus character without pressing the shift
// key, which is not the case for US and UK keyboards.
KeyStroke plusMenuKeyStroke = KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_PLUS, menuKeyMask);
inputMap.put(plusMenuKeyStroke, "zoomInWithPlusKey");
actionMap.put("zoomInWithPlusKey", zoomInAction);
// add support for cases where the plus character is the secondary
// character for the equal sign key. That is, plus is accessed by pressing
// the shift key and the equal key. This is the case for US and UK
// keyboard layouts, which are also used in Ireland, India, Australia, Canada,
// Hong Kong, New Zealand, South Africa, Malaysia, Singapore and Philippines.
// See https://stackoverflow.com/questions/15605109/java-keybinding-plus-key
// and https://en.wikipedia.org/wiki/QWERTY
// The French Canadian keyboard also has = and + on the same key.
Locale locale = InputContext.getInstance().getLocale();
String isoCountry = locale.getISO3Country();
// https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
if ("USA".equals(isoCountry)
|| "GBR".equals(isoCountry)
|| "IRL".equals(isoCountry)
|| "IND".equals(isoCountry)
|| "AUS".equals(isoCountry)
|| "CAN".equals(isoCountry)
|| "HKG".equals(isoCountry)
|| "NZL".equals(isoCountry)
|| "ZAF".equals(isoCountry)
|| "MYS".equals(isoCountry)
|| "SGP".equals(isoCountry)
|| "PHL".equals(isoCountry)) {
KeyStroke euqalsMenuKeyStroke = KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_EQUALS, menuKeyMask);
inputMap.put(euqalsMenuKeyStroke, "zoomInWithEqualsKey");
actionMap.put("zoomInWithEqualsKey", zoomInAction);
}
}
示例14: TablePasteAdapter
import javax.swing.KeyStroke; //導入方法依賴的package包/類
/**
* The TablePasteAdapter is constructed with a JTable on which it enables
* Paste and acts as a Clipboard listener.
*/
private TablePasteAdapter(final JTable table)
{
this.table = table;
// Try getting the table model
TableModel theirModel = table.getModel();
if( theirModel instanceof TablePasteModel )
{
model = (TablePasteModel) theirModel;
}
else if( theirModel instanceof DefaultTableModel )
{
model = new DefaultTableModelAdapter((DefaultTableModel) theirModel);
}
else
{
throw new ClassCastException("Table model must implement TablePasteModel or extend DefaultTableModel"); //$NON-NLS-1$
}
// Register [Ctrl] + [C] for copy.
KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
false);
table.registerKeyboardAction(this, "Copy", copy, JComponent.WHEN_FOCUSED); //$NON-NLS-1$
// Register [Ctrl] + [V] for paste.
KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
false);
table.registerKeyboardAction(this, "Paste", paste, JComponent.WHEN_FOCUSED); //$NON-NLS-1$
// Get a reference to the clipboard
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
// Set some defaults..
setSelectOnPaste(true);
// Setup converters.
converters = new HashMap<Class<?>, DataConverter>();
register(Boolean.class, new BooleanConverter());
// Ensure that we can still paste into empty tables
table.addMouseListener(new MouseAdapter()
{
@Override
public void mousePressed(MouseEvent e)
{
if( e.isConsumed() || !table.isEnabled() || !SwingUtilities.isLeftMouseButton(e) )
{
return;
}
// if the UI ignores our desparate plea for focus when
// the table is clicked beyond the last row or last column,
// we'll try to grab focus anyway so that CTRL-V works
int row = table.rowAtPoint(e.getPoint());
int column = table.columnAtPoint(e.getPoint());
if( row == -1 || column == -1 )
{
if( !table.hasFocus() && table.isRequestFocusEnabled() )
{
table.requestFocus();
}
}
}
});
}
示例15: OptionsAction
import javax.swing.KeyStroke; //導入方法依賴的package包/類
public OptionsAction() {
super("Options");
KeyStroke accelerator = KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.ALT_MASK);
putValue(ACCELERATOR_KEY, accelerator);
}