本文整理汇总了Java中java.awt.event.KeyEvent.CTRL_MASK属性的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.CTRL_MASK属性的具体用法?Java KeyEvent.CTRL_MASK怎么用?Java KeyEvent.CTRL_MASK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.awt.event.KeyEvent
的用法示例。
在下文中一共展示了KeyEvent.CTRL_MASK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: appendKeyMnemonic
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();
}
示例2: usableKeyOnMac
private static boolean usableKeyOnMac(int key, int mask) {
//All permutations fail for Q except ctrl
if (key == KeyEvent.VK_Q) {
return false;
}
boolean isMeta = ((mask & KeyEvent.META_MASK) != 0) || ((mask & KeyEvent.CTRL_DOWN_MASK) != 0);
boolean isAlt = ((mask & KeyEvent.ALT_MASK) != 0) || ((mask & KeyEvent.ALT_DOWN_MASK) != 0);
boolean isOnlyMeta = isMeta && ((mask & ~(KeyEvent.META_DOWN_MASK | KeyEvent.META_MASK)) == 0);
//Mac OS consumes keys Command+ these keys - the app will never see
//them, so CTRL should not be remapped for these
if (isOnlyMeta) {
return (key != KeyEvent.VK_H) && (key != KeyEvent.VK_SPACE) && (key != KeyEvent.VK_TAB);
}
if ((key == KeyEvent.VK_D) && isMeta && isAlt) {
return false;
}
if (key == KeyEvent.VK_SPACE && isMeta && ((mask & KeyEvent.CTRL_MASK) != 0)) {
// http://lists.apple.com/archives/java-dev/2010/Aug/msg00002.html
return false;
}
return true;
}
示例3: processKeyEvent
@Override
public void processKeyEvent(KeyEvent e) {
//Manually hook in the bindings for tab - does not seem to get called
//automatically
if (isEditing() && ((e.getKeyCode() == KeyEvent.VK_DOWN) || (e.getKeyCode() == KeyEvent.VK_UP))) {
return; //XXX
}
//Bypass standard tab and escape handling, and use our registered
//actions instead
if (
!isEditing() ||
(((e.getKeyCode() != KeyEvent.VK_TAB) && (e.getKeyCode() != KeyEvent.VK_ESCAPE)) ||
((e.getModifiers() & KeyEvent.CTRL_MASK) != 0))
) {
super.processKeyEvent(e);
} else {
processKeyBinding(
KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiersEx(), e.getID() == KeyEvent.KEY_RELEASED), e,
JComponent.WHEN_FOCUSED, e.getID() == KeyEvent.KEY_PRESSED
);
}
}
示例4: getString
/**
* A plain text representation of a KeyStroke. Doesn't differ much
* from {@link KeyEvent#getKeyText}
*/
public static String getString(KeyStroke k) {
if (k == null) {
return null;
}
String s = KeyEvent.getKeyText(k.getKeyCode());
s = s.replace(' ', '_');
if ((k.getModifiers() & KeyEvent.SHIFT_MASK) > 0) {
s = Resources.getString("Keys.shift") + " " + s; //$NON-NLS-1$ //$NON-NLS-2$
}
if ((k.getModifiers() & KeyEvent.CTRL_MASK) > 0) {
s = Resources.getString("Keys.ctrl") + " " + s; //$NON-NLS-1$ //$NON-NLS-2$
}
if ((k.getModifiers() & KeyEvent.META_MASK) > 0) {
s = Resources.getString("Keys.meta") + " " + s; //$NON-NLS-1$ //$NON-NLS-2$
}
if ((k.getModifiers() & KeyEvent.ALT_MASK) > 0) {
s = Resources.getString("Keys.alt") + " " + s; //$NON-NLS-1$ //$NON-NLS-2$
}
return s.toUpperCase();
}
示例5: getString
public static String getString(KeyStroke k) {
String s = KeyEvent.getKeyText(k.getKeyCode());
if ((k.getModifiers() & KeyEvent.SHIFT_MASK) > 0) {
s = KeyEvent.getKeyText(KeyEvent.VK_SHIFT) + "+" + s;
}
if ((k.getModifiers() & KeyEvent.CTRL_MASK) > 0) {
s = KeyEvent.getKeyText(KeyEvent.VK_CONTROL) + "+" + s;
}
if ((k.getModifiers() & KeyEvent.META_MASK) > 0) {
s = KeyEvent.getKeyText(KeyEvent.VK_META) + "+" + s;
}
if ((k.getModifiers() & KeyEvent.ALT_MASK) > 0) {
s = KeyEvent.getKeyText(KeyEvent.VK_ALT) + "+" + s;
}
return s;
}
示例6: keyTyped
@Override
public void keyTyped(KeyEvent e) {
key = e.getKeyChar();
if (key == (char) 127 || key == '\b' || key == '\n') {
e.consume();
return;
}
if (e.getModifiers() == KeyEvent.CTRL_MASK) {
return;
}
palavra = insertChar(palavra, key);
posCursor++;
}
示例7: addModifiers
/** Adds characters for modifiers to the buffer.
* @param buf buffer to add to
* @param modif modifiers to add (KeyEvent.XXX_MASK)
* @return true if something has been added
*/
private static boolean addModifiers(StringBuilder buf, int modif) {
boolean b = false;
if ((modif & KeyEvent.CTRL_MASK) != 0) {
buf.append("C"); // NOI18N
b = true;
}
if ((modif & KeyEvent.ALT_MASK) != 0) {
buf.append("A"); // NOI18N
b = true;
}
if ((modif & KeyEvent.SHIFT_MASK) != 0) {
buf.append("S"); // NOI18N
b = true;
}
if ((modif & KeyEvent.META_MASK) != 0) {
buf.append("M"); // NOI18N
b = true;
}
if ((modif & CTRL_WILDCARD_MASK) != 0) {
buf.append("D");
b = true;
}
if ((modif & ALT_WILDCARD_MASK) != 0) {
buf.append("O");
b = true;
}
return b;
}
示例8: addModifiersPortable
private static boolean addModifiersPortable(StringBuilder buf, int modifiers) {
boolean b = false;
if ((modifiers & KeyEvent.SHIFT_MASK) != 0) {
buf.append('S');
b = true;
}
if (Utilities.isMac() && ((modifiers & KeyEvent.META_MASK) != 0) || !Utilities.isMac() && ((modifiers & KeyEvent.CTRL_MASK) != 0)) {
buf.append('D');
b = true;
}
if (Utilities.isMac() && ((modifiers & KeyEvent.CTRL_MASK) != 0) || !Utilities.isMac() && ((modifiers & KeyEvent.ALT_MASK) != 0)) {
buf.append('O');
b = true;
}
// mac alt fallback
if (Utilities.isMac() && ((modifiers & KeyEvent.ALT_MASK) != 0)) {
buf.append('A');
b = true;
}
// META fallback, see issue #224362
if (!Utilities.isMac() && ((modifiers & KeyEvent.META_MASK) != 0)) {
buf.append('M');
b = true;
}
return b;
}
示例9: ctrlPressKey
private void ctrlPressKey(final Component target, final int key) throws Exception {
if (SwingUtilities.isEventDispatchThread()) {
KeyEvent k = new KeyEvent(target, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), KeyEvent.CTRL_MASK, key, (char) key);
target.dispatchEvent(k);
} else {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
KeyEvent ke = new KeyEvent(target, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), KeyEvent.CTRL_MASK, key, (char) key);
target.dispatchEvent(ke);
}
});
sleep();
}
}
示例10: keyPressed
public void keyPressed(KeyEvent e) {
assert (e.getSource() instanceof JTextField);
if(((e.getModifiers() & (KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK | KeyEvent.CTRL_MASK | KeyEvent.META_MASK)) == 0) &&
(e.getKeyCode() == KeyEvent.VK_DOWN ||
e.getKeyCode() == KeyEvent.VK_UP ||
e.getKeyCode() == KeyEvent.VK_ESCAPE)) {
return ;
}
textField = (JTextField) e.getSource();
KeyStroke keyStroke = createKeyStroke(e);
boolean add = e.getKeyCode() != KeyEvent.VK_SHIFT &&
e.getKeyCode() != KeyEvent.VK_CONTROL &&
e.getKeyCode() != KeyEvent.VK_ALT &&
e.getKeyCode() != KeyEvent.VK_META &&
e.getKeyCode() != KeyEvent.VK_ALT_GRAPH;
if (!(enterConfirms && keyStroke.equals(enterKS))) {
if (keyStroke.equals(backspaceKS) && !key.equals("")) {
// delete last key
int i = key.lastIndexOf(' '); //NOI18N
if (i < 0) {
key = ""; //NOI18N
} else {
key = key.substring(0, i);
}
textField.setText(key);
} else {
// add key
addKeyStroke(keyStroke, add);
}
e.consume();
}
}
示例11: testToStringOfDelegateContainsNameOfOriginalAction
public void testToStringOfDelegateContainsNameOfOriginalAction() throws Exception {
SaveAction sa = SaveAction.get(SaveAction.class);
Action a = sa.createContextAwareInstance(Lookup.EMPTY);
if (a.toString().indexOf("SaveAction") == -1) {
fail("We need name of the original action:\n" + a.toString());
}
SaveAction.cnt = 0;
CharSequence log = Log.enable("org.netbeans.ui", Level.FINER);
final TopComponent tc = new TopComponent();
final KeyEvent ke = new KeyEvent(tc, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), KeyEvent.CTRL_MASK, 0, 'S');
final KeyStroke ks = KeyStroke.getKeyStrokeForEvent(ke);
MockServices.setServices(MyKM.class);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
tc.setActivatedNodes( new Node[0] );
tc.processKeyBinding(ks, ke, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, true);
}
});
if (log.toString().indexOf("SaveAction") == -1
&& SaveAction.cnt == 1 ) { //make sure the action was actually invoked
fail(log.toString());
}
}
示例12: PrintPreviewComponent
public PrintPreviewComponent(RamusPrintable printable, int columnCount,
GUIFramework framework) {
this.printable = printable;
this.columnCount = columnCount;
this.framework = framework;
MouseWheelListener l = new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
if (e.getModifiers() == KeyEvent.CTRL_MASK) {
double r = e.getWheelRotation();
double zoom = getZoom() - 0.2 * r;
setCurrentZoom(zoom);
} else {
Rectangle rect = getVisibleRect();
scrollRectToVisible(new Rectangle(rect.x, rect.y
+ e.getWheelRotation() * 150, rect.width,
rect.height));
}
}
}
};
this.addMouseWheelListener(l);
layout = Options.getInteger("PREVIW_LAYOUT", PREV_LAYOUT_GRID);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setCurrentZoom(Options.getDouble("PREV_ZOOM", 1d));
}
});
setCurrentZoom(Options.getDouble("PREV_ZOOM", 1d));
}
示例13: doCtrlPressKey
private void doCtrlPressKey(final Component target, final int key) throws Exception {
KeyEvent k = new KeyEvent(target, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), KeyEvent.CTRL_MASK, key, (char) key);
target.dispatchEvent(k);
}
示例14: ExecuteTestAction
/** creates new ExecuteTestAction instance */
public ExecuteTestAction() {
super(MENU, MENU, new Action.Shortcut(KeyEvent.CTRL_MASK|KeyEvent.ALT_MASK, KeyEvent.VK_L));
}
示例15: OpenTestAction
/** creates new OpenTestAction instance */
public OpenTestAction() {
super(MENU, MENU, new Action.Shortcut(KeyEvent.CTRL_MASK|KeyEvent.ALT_MASK, KeyEvent.VK_K));
}