本文整理匯總了Java中java.awt.AWTKeyStroke類的典型用法代碼示例。如果您正苦於以下問題:Java AWTKeyStroke類的具體用法?Java AWTKeyStroke怎麽用?Java AWTKeyStroke使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AWTKeyStroke類屬於java.awt包,在下文中一共展示了AWTKeyStroke類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: install
import java.awt.AWTKeyStroke; //導入依賴的package包/類
public static synchronized void install() {
if(installed) {
return;
}
ShortcutAndMenuKeyEventProcessor instance = getDefault();
KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
keyboardFocusManager.addKeyEventDispatcher(instance);
keyboardFocusManager.addKeyEventPostProcessor(instance);
// #63252: Disable focus traversal functionality of Ctrl+Tab and Ctrl+Shift+Tab,
// to allow our own document switching (RecentViewListAction)
defaultForward = keyboardFocusManager.getDefaultFocusTraversalKeys(
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
defaultBackward = keyboardFocusManager.getDefaultFocusTraversalKeys(
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
keyboardFocusManager.setDefaultFocusTraversalKeys(
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
Collections.singleton(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0))
);
keyboardFocusManager.setDefaultFocusTraversalKeys(
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
Collections.singleton(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK))
);
}
示例2: ShortcutEnterPanel
import java.awt.AWTKeyStroke; //導入依賴的package包/類
/** Creates new form ShortcutCustomizerPanel */
public ShortcutEnterPanel() {
initComponents();
bTab = new JButton();
bClear = new JButton();
loc(bTab, "CTL_Tab");
loc(bClear, "CTL_Clear");
tfShortcut.setFocusTraversalKeys(
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
Collections.<AWTKeyStroke>emptySet()
);
tfShortcut.setFocusTraversalKeys(
KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS,
Collections.<AWTKeyStroke>emptySet()
);
tfShortcut.setFocusTraversalKeys(
KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS,
Collections.<AWTKeyStroke>emptySet()
);
tfShortcut.addKeyListener(listener);
}
示例3: getKeyStrokeForKeySym
import java.awt.AWTKeyStroke; //導入依賴的package包/類
AWTKeyStroke getKeyStrokeForKeySym(long keysym, long state) {
XBaseWindow.checkSecurity();
int keycode;
XToolkit.awtLock();
try {
XKeysym.Keysym2JavaKeycode kc = XKeysym.getJavaKeycode( keysym );
if(kc == null) {
keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
}else{
keycode = kc.getJavaKeycode();
}
} finally {
XToolkit.awtUnlock();
}
int modifiers = getModifiers((int)state);
return AWTKeyStroke.getAWTKeyStroke(keycode, modifiers);
}
示例4: checkAWTKeyStroke
import java.awt.AWTKeyStroke; //導入依賴的package包/類
private static void checkAWTKeyStroke(int keyCode, int modifiers,
boolean onKeyRelease) throws Exception {
AWTKeyStroke awtKeyStroke1 = AWTKeyStroke.getAWTKeyStroke(
keyCode, modifiers, onKeyRelease);
checkAWTKeyStroke(awtKeyStroke1, keyCode, modifiers, onKeyRelease);
AWTKeyStroke awtKeyStroke2 = AWTKeyStroke.getAWTKeyStroke(
keyCode, modifiers, onKeyRelease);
if (awtKeyStroke1 != awtKeyStroke2) {
throw new RuntimeException("AWTKeyStroke is not cached!");
}
checkSerializedKeyStroke(awtKeyStroke1);
}
示例5: checkSerializedKeyStrokes
import java.awt.AWTKeyStroke; //導入依賴的package包/類
private static void checkSerializedKeyStrokes(int keyCode, int modifiers,
boolean onKeyRelease) throws Exception {
AWTKeyStroke awtKeyStroke = AWTKeyStroke.getAWTKeyStroke(
keyCode, modifiers, onKeyRelease);
KeyStroke keyStroke = KeyStroke.getKeyStroke(
keyCode, modifiers, onKeyRelease);
if (awtKeyStroke != getSerializedAWTKeyStroke(awtKeyStroke)) {
throw new RuntimeException("Serialized AWTKeyStroke is not cached!");
}
awtKeyStroke = AWTKeyStroke.getAWTKeyStroke(
keyCode, modifiers, !onKeyRelease);
if (!keyStroke.equals(getSerializedAWTKeyStroke(keyStroke))) {
throw new RuntimeException("Serialized KeyStroke is not cached!");
}
}
示例6: considerarEnterComoTab
import java.awt.AWTKeyStroke; //導入依賴的package包/類
/**
* Este método faz com que o ENTER seja considerado como TAB, em componentes
* como um JTextField. Além disso, permite a navegação com as setas para
* cima e para baixo.
*
* @param comp O componente.
*/
public static void considerarEnterComoTab(Component comp) {
Set<AWTKeyStroke> newKeystrokes;
newKeystrokes = new HashSet<AWTKeyStroke>(
comp.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, 0));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_KP_DOWN, 0));
comp.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
newKeystrokes);
newKeystrokes = new HashSet<AWTKeyStroke>(
comp.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER,
InputEvent.SHIFT_DOWN_MASK));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_UP, 0));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_KP_UP, 0));
comp.setFocusTraversalKeys(
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, newKeystrokes);
}
示例7: considerarSetaComoTab
import java.awt.AWTKeyStroke; //導入依賴的package包/類
/**
* Este método faz com que as setas sejam consideradas como TAB, e deve ser
* usado em um botão qualquer.
*
* @param comp O componente.
*/
public static void considerarSetaComoTab(JButton comp) {
Set<AWTKeyStroke> newKeystrokes;
newKeystrokes = new HashSet<AWTKeyStroke>(
comp.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_KP_DOWN, 0));
comp.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
newKeystrokes);
newKeystrokes = new HashSet<AWTKeyStroke>(
comp.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_UP, 0));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_KP_UP, 0));
comp.setFocusTraversalKeys(
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, newKeystrokes);
}
示例8: considerarEnterComoTab
import java.awt.AWTKeyStroke; //導入依賴的package包/類
/**
* Este método faz com que o ENTER seja considerado como TAB, em componentes
* como um JTextField. Além disso, permite a navegação com as setas para
* esquerda e para direita.
*
* @param comp O componente.
*/
public static void considerarEnterComoTab(Component comp) {
Set<AWTKeyStroke> newKeystrokes;
newKeystrokes = new HashSet<AWTKeyStroke>(
comp.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, 0));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_RIGHT, 0));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_KP_RIGHT, 0));
comp.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
newKeystrokes);
newKeystrokes = new HashSet<AWTKeyStroke>(
comp.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER,
InputEvent.SHIFT_DOWN_MASK));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_LEFT, 0));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_KP_LEFT, 0));
comp.setFocusTraversalKeys(
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, newKeystrokes);
}
示例9: considerarSetaComoTab
import java.awt.AWTKeyStroke; //導入依賴的package包/類
/**
* Este método faz com que as setas sejam consideradas como TAB, e deve ser
* usado em um botão qualquer.
*
* @param comp O componente.
*/
public static void considerarSetaComoTab(JButton comp) {
Set<AWTKeyStroke> newKeystrokes;
newKeystrokes = new HashSet<AWTKeyStroke>(
comp.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_RIGHT, 0));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_KP_RIGHT, 0));
comp.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
newKeystrokes);
newKeystrokes = new HashSet<AWTKeyStroke>(
comp.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_LEFT, 0));
newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_KP_LEFT, 0));
comp.setFocusTraversalKeys(
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, newKeystrokes);
}
示例10: bindArrowKeys
import java.awt.AWTKeyStroke; //導入依賴的package包/類
private void bindArrowKeys(JDialog dialog) {
{
Set<AWTKeyStroke> forwardKeys = dialog.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
Set<AWTKeyStroke> newForwardKeys = new HashSet<>(forwardKeys);
newForwardKeys.add(KeyStroke.getKeyStroke("DOWN"));
newForwardKeys.add(KeyStroke.getKeyStroke("RIGHT"));
dialog.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, newForwardKeys);
}
{
Set<AWTKeyStroke> backwardKeys = dialog.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
Set<AWTKeyStroke> newBackwardKeys = new HashSet<>(backwardKeys);
newBackwardKeys.add(KeyStroke.getKeyStroke("UP"));
newBackwardKeys.add(KeyStroke.getKeyStroke("LEFT"));
dialog.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, newBackwardKeys);
}
}
示例11: getDefaultFocusTraversalKeys
import java.awt.AWTKeyStroke; //導入依賴的package包/類
final Set<AWTKeyStroke> getDefaultFocusTraversalKeys(final int mode) {
Set<AWTKeyStroke> result = component.getFocusTraversalKeys(mode);
if (result == null) {
result = new LinkedHashSet<AWTKeyStroke>();
if (mode == KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS) {
result.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
InputEvent.CTRL_DOWN_MASK));
} else {
result.add(KeyStroke
.getKeyStroke(KeyEvent.VK_TAB,
InputEvent.CTRL_DOWN_MASK
| InputEvent.SHIFT_DOWN_MASK));
}
} else {
result = new LinkedHashSet<AWTKeyStroke>(result);
}
return result;
}
示例12: initialize
import java.awt.AWTKeyStroke; //導入依賴的package包/類
public void initialize() {
this.addMouseListener(this);
// this.setFocusTraversalKeysEnabled(false);
this.addKeyListener(this);
this.setFocusable(true);
this.addFocusListener(this);
this.setFocusTraversalKeysEnabled(true);
this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,new HashSet(new EasyVector(new Object[]{AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,0)})));
this.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,new HashSet(new EasyVector(new Object[]{AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,InputEvent.SHIFT_DOWN_MASK)})));
this.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
// undoManager = new UndoManager();
// Document document = this.getDocument();
// document.addUndoableEditListener(undoManager);
this.setMargin(defaultMargins);
this.setDragEnabled(true);
dt = new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, this);
setPopupMenu();
}
示例13: init
import java.awt.AWTKeyStroke; //導入依賴的package包/類
void init(ShortcutsFinder f) {
this.f = f;
loc (lShortcut, "Shortcut"); //NOI18N
lConflict.setForeground (Color.red);
loc (bTab, "CTL_Tab"); //NOI18N
bTab.getAccessibleContext().setAccessibleName(loc("AN_Tab")); //NOI18N
bTab.getAccessibleContext().setAccessibleDescription(loc("AD_Tab")); //NOI18N
loc (bClear, "CTL_Clear"); //NOI18N
bClear.getAccessibleContext().setAccessibleName(loc("AN_Clear")); //NOI18N
bClear.getAccessibleContext().setAccessibleDescription(loc("AD_Clear")); //NOI18N
tfShortcut.setFocusTraversalKeys (
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
Collections.<AWTKeyStroke>emptySet()
);
tfShortcut.setFocusTraversalKeys (
KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS,
Collections.<AWTKeyStroke>emptySet()
);
tfShortcut.getAccessibleContext().setAccessibleName(loc("AN_Shortcut")); //NOI18N
tfShortcut.getAccessibleContext().setAccessibleDescription(loc("AD_Shortcut")); //NOI18N
lShortcut.setDisplayedMnemonic(loc("CTL_Shortcut_Mnemonic").charAt(0));
// tfShortcut.setFocusTraversalKeys (
// KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
// Collections.EMPTY_SET
// );
tfShortcut.setFocusTraversalKeys (
KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS,
Collections.<AWTKeyStroke>emptySet()
);
listener = new Listener ();
tfShortcut.addKeyListener(listener);
}
示例14: setTabTraversalEnabled
import java.awt.AWTKeyStroke; //導入依賴的package包/類
private void setTabTraversalEnabled(boolean enabled) {
Set<AWTKeyStroke> tKeys = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
Set<AWTKeyStroke> newTKeys = new HashSet<>(tKeys);
if (enabled) {
newTKeys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0));
} else {
newTKeys.remove(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0));
}
setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, newTKeys);
}
示例15: instantiate
import java.awt.AWTKeyStroke; //導入依賴的package包/類
protected Expression instantiate(Object oldInstance, Encoder out) {
AWTKeyStroke key = (AWTKeyStroke) oldInstance;
char ch = key.getKeyChar();
int code = key.getKeyCode();
int mask = key.getModifiers();
boolean onKeyRelease = key.isOnKeyRelease();
Object[] args = null;
if (ch == KeyEvent.CHAR_UNDEFINED) {
args = !onKeyRelease
? new Object[]{code, mask}
: new Object[]{code, mask, onKeyRelease};
} else if (code == KeyEvent.VK_UNDEFINED) {
if (!onKeyRelease) {
args = (mask == 0)
? new Object[]{ch}
: new Object[]{ch, mask};
} else if (mask == 0) {
args = new Object[]{ch, onKeyRelease};
}
}
if (args == null) {
throw new IllegalStateException("Unsupported KeyStroke: " + key);
}
Class<?> type = key.getClass();
String name = type.getName();
// get short name of the class
int index = name.lastIndexOf('.') + 1;
if (index > 0) {
name = name.substring(index);
}
return new Expression( key, type, "get" + name, args );
}