本文整理匯總了Java中javax.swing.KeyStroke類的典型用法代碼示例。如果您正苦於以下問題:Java KeyStroke類的具體用法?Java KeyStroke怎麽用?Java KeyStroke使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
KeyStroke類屬於javax.swing包,在下文中一共展示了KeyStroke類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initialize
import javax.swing.KeyStroke; //導入依賴的package包/類
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
setLayout(new BorderLayout());
this.setSize(581, 39);
this.add(getJPanel(), java.awt.BorderLayout.WEST);
setFocusable(true);
final AbstractAction aa = new AbstractAction() {
/**
*
*/
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent e) {
findNext(jTextField.getText(), jCheckBox.isSelected());
}
};
this.getInputMap().put(KeyStroke.getKeyStroke("F3"), "FindNext");
this.getActionMap().put("FindNext", aa);
getJTextField().getInputMap().put(KeyStroke.getKeyStroke("F3"),
"FindNext");
getJTextField().getActionMap().put("FindNext", aa);
}
示例2: makeMenuItem
import javax.swing.KeyStroke; //導入依賴的package包/類
public void makeMenuItem(JFrame frame, JMenu menu) {
if ("-".equals(name)) {
menu.addSeparator();
return;
}
JMenuItem menuItem = new JMenuItem(com.myster.util.I18n.tr(name));
if (shortcut != -1) {
int shiftMask = useShift ? InputEvent.SHIFT_DOWN_MASK : 0;
menuItem.setAccelerator(KeyStroke.getKeyStroke(shortcut, InputEvent.CTRL_DOWN_MASK|shiftMask));
}
if (action != null) {
menuItem.addActionListener(action);
}
menuItem.setEnabled(!isDisabled);
menu.add(menuItem);
return;
}
示例3: getLayerWithMatchingActivateCommand
import javax.swing.KeyStroke; //導入依賴的package包/類
/**
* If the argument GamePiece contains a Layer whose "activate" command matches
* the given keystroke, and whose active status matches the boolean argument,
* return that Layer
*/
public static Embellishment getLayerWithMatchingActivateCommand(GamePiece piece, KeyStroke stroke, boolean active) {
for (Embellishment layer = (Embellishment) Decorator.getDecorator(piece, Embellishment.class); layer != null; layer = (Embellishment) Decorator
.getDecorator(layer.piece, Embellishment.class)) {
for (int i = 0; i < layer.activateKey.length(); ++i) {
if (stroke.equals(KeyStroke.getKeyStroke(layer.activateKey.charAt(i), layer.activateModifiers))) {
if (active && layer.isActive()) {
return layer;
}
else if (!active && !layer.isActive()) {
return layer;
}
break;
}
}
}
return null;
}
示例4: getHiddenDecorator
import javax.swing.KeyStroke; //導入依賴的package包/類
@Override
public Obscurable getHiddenDecorator() throws IOException {
Obscurable p;
SequenceEncoder se = new SequenceEncoder(';');
se.append(new NamedKeyStroke(KeyStroke.getKeyStroke('H', InputEvent.CTRL_MASK))); // key command
se.append(getHiddenSymbol().getFileName()); // hide image
se.append("Hide Piece"); // menu name
BufferedImage image = getSymbol().getImage();
se.append("G" + getFlagLayer(new Dimension(image.getWidth(), image.getHeight()), StateFlag.MARKER)); // display style
se.append(getHiddenName()); // mask name
if (getOwner() == Player.NO_PLAYERS || getOwner() == Player.ALL_PLAYERS) {
se.append("side:");
}
else {
se.append("sides:" + getOwner().getName()); // owning player
}
p = new Obscurable();
p.mySetType(Obscurable.ID + se.getValue());
return p;
}
示例5: configureMenuItem
import javax.swing.KeyStroke; //導入依賴的package包/類
private void configureMenuItem(JMenuItem item, String resource, ActionListener listener) {
configureAbstractButton(item, resource);
item.addActionListener(listener);
try {
String accel = resources.getString(resource + ".accel");
String metaPrefix = "@";
if (accel.startsWith(metaPrefix)) {
int menuMask = getToolkit().getMenuShortcutKeyMask();
KeyStroke key = KeyStroke.getKeyStroke(
KeyStroke.getKeyStroke(accel.substring(metaPrefix.length())).getKeyCode(), menuMask);
item.setAccelerator(key);
} else {
item.setAccelerator(KeyStroke.getKeyStroke(accel));
}
} catch (MissingResourceException ex) {
// no accelerator
}
}
示例6: GlazeToggleMenuItem
import javax.swing.KeyStroke; //導入依賴的package包/類
public GlazeToggleMenuItem(final FlagFrame frame) {
setText("Glaze");
if (!OSUtils.isMacOS()) setMnemonic(KeyEvent.VK_G);
setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SLASH, 0));
if (frame == null) {
setEnabled(false);
} else {
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
boolean g = !frame.isGlazed();
frame.setGlaze(g);
setSelected(g);
}
});
}
}
示例7: afterLoad
import javax.swing.KeyStroke; //導入依賴的package包/類
@Override
public void afterLoad(Map<Collection<KeyStroke>, MultiKeyBinding> map, MimePath mimePath, String profile, boolean defaults) {
Map<String, MacroDescription> macros = new HashMap<String, MacroDescription>();
if (!collectMacroActions(mimePath, macros)) {
return;
}
for(MacroDescription macro : macros.values()) {
List<? extends MultiKeyBinding> shortcuts = macro.getShortcuts();
for(MultiKeyBinding shortcut : shortcuts) {
Collection<KeyStroke> keys = shortcut.getKeyStrokeList();
// A macro shortcut never replaces shortcuts for ordinary editor actions
if (!map.containsKey(keys)) {
map.put(keys, shortcut);
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("afterLoad: injecting " + keys + " for macro '" //NOI18N
+ macro.getName() + "'; mimePath='" + mimePath.getPath() + "'"); //NOI18N
}
} else {
LOG.warning("Shortcut " + keys + " is bound to '" + map.get(keys).getActionName() //NOI18N
+ "' for '" + mimePath.getPath() + "' and will not be assigned to '" + macro.getName() + "' macro!"); //NOI18N
}
}
}
}
示例8: showPopup
import javax.swing.KeyStroke; //導入依賴的package包/類
private void showPopup() {
hidePopup();
if (completionListModel.getSize() == 0) {
return;
}
// figure out where the text field is,
// and where its bottom left is
java.awt.Point los = field.getLocationOnScreen();
int popX = los.x;
int popY = los.y + field.getHeight();
popup = PopupFactory.getSharedInstance().getPopup(field, listScroller, popX, popY);
field.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),ACTION_HIDEPOPUP);
field.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),ACTION_FILLIN);
popup.show();
if (completionList.getSelectedIndex() != -1) {
completionList.ensureIndexIsVisible(completionList.getSelectedIndex());
}
}
示例9: findActionKey
import javax.swing.KeyStroke; //導入依賴的package包/類
Object findActionKey(JTextComponent component) {
KeyStroke keyStroke;
switch (actionType) {
case TAB:
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
break;
case SHIFT_TAB:
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_MASK);
break;
case ENTER:
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
break;
default:
throw new IllegalArgumentException();
}
// Assume the 'a' character will trigger defaultKeyTypedAction
Object key = component.getInputMap().get(keyStroke);
return key;
}
示例10: appendKeyMnemonic
import javax.swing.KeyStroke; //導入依賴的package包/類
public static String appendKeyMnemonic(StringBuilder sb, KeyStroke key) {
String sk = org.openide.util.Utilities.keyToString(key);
int mods = key.getModifiers();
if ((mods & KeyEvent.CTRL_MASK) != 0) {
sb.append("Ctrl+"); // NOI18N
}
if ((mods & KeyEvent.ALT_MASK) != 0) {
sb.append("Alt+"); // NOI18N
}
if ((mods & KeyEvent.SHIFT_MASK) != 0) {
sb.append("Shift+"); // NOI18N
}
if ((mods & KeyEvent.META_MASK) != 0) {
sb.append("Meta+"); // NOI18N
}
int i = sk.indexOf('-'); //NOI18N
if (i != -1) {
sk = sk.substring(i + 1);
}
sb.append(sk);
return sb.toString();
}
示例11: 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;
}
示例12: ClassChooserDialog
import javax.swing.KeyStroke; //導入依賴的package包/類
/** Creates new model dialog ClassChooserDialog.
* @param parent parent Frame
@param subclassOf a Class that will be used to search the classpath for sublasses of this class; these class names are displayed on the left.
@param classNames a list of class names that are already chosen, displayed on the right.
@param defaultClassNames the defaults passed to ClassChooserPanel which replace the chosen list if the Defaults button is pressed.
*/
public ClassChooserDialog(Frame parent, Class subclassOf, ArrayList<String> classNames, ArrayList<String> defaultClassNames) {
super(parent, true);
initComponents();
// cancelButton.requestFocusInWindow();
chooserPanel=new ClassChooserPanel(subclassOf,classNames,defaultClassNames);
businessPanel.add(chooserPanel,BorderLayout.CENTER);
pack();
// Handle escape key to close the dialog
// from http://forum.java.sun.com/thread.jspa?threadID=462776&messageID=2123119
KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
Action escapeAction = new AbstractAction() {
@Override public void actionPerformed(ActionEvent e) {
dispose();
}
};
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
getRootPane().getActionMap().put("ESCAPE", escapeAction);
}
示例13: recreateStateMenu
import javax.swing.KeyStroke; //導入依賴的package包/類
private void recreateStateMenu(JMenu menu, ArrayList<CircuitStateMenuItem> items, int code) {
menu.removeAll();
menu.setEnabled(items.size() > 0);
boolean first = true;
int mask = getToolkit().getMenuShortcutKeyMask();
for (int i = items.size() - 1; i >= 0; i--) {
JMenuItem item = items.get(i);
menu.add(item);
if (first) {
item.setAccelerator(KeyStroke.getKeyStroke(code, mask));
first = false;
} else {
item.setAccelerator(null);
}
}
}
示例14: setActionProperties
import javax.swing.KeyStroke; //導入依賴的package包/類
/**
* Sets the properties of one of the actions this text area owns.
*
* @param action The action to modify; for example, {@link #CUT_ACTION}.
* @param name The new name for the action.
* @param mnemonic The new mnemonic for the action.
* @param accelerator The new accelerator key for the action.
*/
public static void setActionProperties(int action, String name,
Integer mnemonic, KeyStroke accelerator) {
Action tempAction = null;
switch (action) {
case CUT_ACTION:
tempAction = cutAction;
break;
case COPY_ACTION:
tempAction = copyAction;
break;
case PASTE_ACTION:
tempAction = pasteAction;
break;
case DELETE_ACTION:
tempAction = deleteAction;
break;
case SELECT_ALL_ACTION:
tempAction = selectAllAction;
break;
case UNDO_ACTION:
case REDO_ACTION:
default:
return;
}
tempAction.putValue(Action.NAME, name);
tempAction.putValue(Action.SHORT_DESCRIPTION, name);
tempAction.putValue(Action.ACCELERATOR_KEY, accelerator);
tempAction.putValue(Action.MNEMONIC_KEY, mnemonic);
}
示例15: UndoAction
import javax.swing.KeyStroke; //導入依賴的package包/類
public UndoAction() {
super(Local.getString("Undo"));
setEnabled(false);
putValue(
Action.SMALL_ICON,
new ImageIcon(cl.getResource("resources/icons/undo16.png")));
putValue(
Action.ACCELERATOR_KEY,
KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.CTRL_MASK));
}