Java Code Examples for java.awt.event.InputEvent.META_DOWN_MASK

The following are Jave code examples for showing how to use META_DOWN_MASK of the java.awt.event.InputEvent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Logisim   File: TextFieldCaret.java   View Source Code Vote up 6 votes
@Override
public void keyTyped(KeyEvent e) {
	int ign = InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.META_DOWN_MASK;
	if ((e.getModifiersEx() & ign) != 0)
		return;

	char c = e.getKeyChar();
	if (c == '\n') {
		stopEditing();
	} else if (c != KeyEvent.CHAR_UNDEFINED && !Character.isISOControl(c)) {
		if (pos < curText.length()) {
			curText = curText.substring(0, pos) + c + curText.substring(pos);
		} else {
			curText += c;
		}
		++pos;
		field.setText(curText);
	}
}
 
Example 2
Project: Logisim   File: InputEventUtil.java   View Source Code Vote up 6 votes
public static String toKeyDisplayString(int mods) {
	ArrayList<String> arr = new ArrayList<String>();
	if ((mods & InputEvent.META_DOWN_MASK) != 0)
		arr.add(Strings.get("metaMod"));
	if ((mods & InputEvent.CTRL_DOWN_MASK) != 0)
		arr.add(Strings.get("ctrlMod"));
	if ((mods & InputEvent.ALT_DOWN_MASK) != 0)
		arr.add(Strings.get("altMod"));
	if ((mods & InputEvent.SHIFT_DOWN_MASK) != 0)
		arr.add(Strings.get("shiftMod"));

	Iterator<String> it = arr.iterator();
	if (it.hasNext()) {
		StringBuilder ret = new StringBuilder();
		ret.append(it.next());
		while (it.hasNext()) {
			ret.append(" ");
			ret.append(it.next());
		}
		return ret.toString();
	} else {
		return "";
	}
}
 
Example 3
Project: incubator-netbeans   File: WizardUtils.java   View Source Code Vote up 6 votes
public static String keyStrokeToString(KeyStroke keyStroke) {
    int modifiers = keyStroke.getModifiers();
    StringBuffer sb = new StringBuffer();
    if ((modifiers & InputEvent.CTRL_DOWN_MASK) > 0) {
        sb.append("Ctrl+"); // NOI18N
    }
    if ((modifiers & InputEvent.ALT_DOWN_MASK) > 0) {
        sb.append("Alt+"); // NOI18N
    }
    if ((modifiers & InputEvent.SHIFT_DOWN_MASK) > 0) {
        sb.append("Shift+"); // NOI18N
    }
    if ((modifiers & InputEvent.META_DOWN_MASK) > 0) {
        sb.append("Meta+"); // NOI18N
    }
    if (keyStroke.getKeyCode() != KeyEvent.VK_SHIFT &&
            keyStroke.getKeyCode() != KeyEvent.VK_CONTROL &&
            keyStroke.getKeyCode() != KeyEvent.VK_META &&
            keyStroke.getKeyCode() != KeyEvent.VK_ALT &&
            keyStroke.getKeyCode() != KeyEvent.VK_ALT_GRAPH) {
        sb.append(Utilities.keyToString(
                KeyStroke.getKeyStroke(keyStroke.getKeyCode(), 0)));
    }
    return sb.toString();
}
 
Example 4
Project: incubator-netbeans   File: WizardUtils.java   View Source Code Vote up 6 votes
public static KeyStroke stringToKeyStroke(String keyStroke) {
    int modifiers = 0;
    if (keyStroke.startsWith("Ctrl+")) { // NOI18N
        modifiers |= InputEvent.CTRL_DOWN_MASK;
        keyStroke = keyStroke.substring(5);
    }
    if (keyStroke.startsWith("Alt+")) { // NOI18N
        modifiers |= InputEvent.ALT_DOWN_MASK;
        keyStroke = keyStroke.substring(4);
    }
    if (keyStroke.startsWith("Shift+")) { // NOI18N
        modifiers |= InputEvent.SHIFT_DOWN_MASK;
        keyStroke = keyStroke.substring(6);
    }
    if (keyStroke.startsWith("Meta+")) { // NOI18N
        modifiers |= InputEvent.META_DOWN_MASK;
        keyStroke = keyStroke.substring(5);
    }
    KeyStroke ks = Utilities.stringToKey(keyStroke);
    if (ks == null) {
        return null;
    }
    KeyStroke result = KeyStroke.getKeyStroke(ks.getKeyCode(), modifiers);
    return result;
}
 
Example 5
Project: openjdk-jdk10   File: bug7170657.java   View Source Code Vote up 6 votes
public static void main(final String[] args) {
    final int mask = InputEvent.META_DOWN_MASK | InputEvent.CTRL_MASK;

    Frame f = new Frame();

    MouseEvent mwe = new MouseWheelEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                         1, 1, 1);
    MouseEvent mdme = new MenuDragMouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1,
                                             true, null, null);
    MouseEvent me = new MouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                   MouseEvent.NOBUTTON);

    test(f, mwe);
    test(f, mdme);
    test(f, me);

    if (FAILED) {
        throw new RuntimeException("Wrong mouse event");
    }
}
 
Example 6
Project: openjdk-jdk10   File: AWTKeyStroke.java   View Source Code Vote up 6 votes
@SuppressWarnings("deprecation")
private static int mapNewModifiers(int modifiers) {
    if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
        modifiers |= InputEvent.SHIFT_MASK;
    }
    if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0) {
        modifiers |= InputEvent.ALT_MASK;
    }
    if ((modifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
        modifiers |= InputEvent.ALT_GRAPH_MASK;
    }
    if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
        modifiers |= InputEvent.CTRL_MASK;
    }
    if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
        modifiers |= InputEvent.META_MASK;
    }

    return modifiers;
}
 
Example 7
Project: marathonv5   File: EventQueueDevice.java   View Source Code Vote up 6 votes
public int getModifierEx() {
    int modifiersEx = 0;
    if (isShiftPressed()) {
        modifiersEx |= InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK;
    }
    if (isCtrlPressed()) {
        modifiersEx |= InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK;
    }
    if (isAltPressed()) {
        modifiersEx |= InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK;
    }
    if (isMetaPressed()) {
        modifiersEx |= InputEvent.META_DOWN_MASK | InputEvent.META_MASK;
    }
    return modifiersEx;
}
 
Example 8
Project: jdk8u-jdk   File: bug7170657.java   View Source Code Vote up 6 votes
public static void main(final String[] args) {
    final int mask = InputEvent.META_DOWN_MASK | InputEvent.CTRL_MASK;

    Frame f = new Frame();

    MouseEvent mwe = new MouseWheelEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                         1, 1, 1);
    MouseEvent mdme = new MenuDragMouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1,
                                             true, null, null);
    MouseEvent me = new MouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                   MouseEvent.NOBUTTON);

    test(f, mwe);
    test(f, mdme);
    test(f, me);

    if (FAILED) {
        throw new RuntimeException("Wrong mouse event");
    }
}
 
Example 9
Project: jdk8u-jdk   File: AWTKeyStroke.java   View Source Code Vote up 6 votes
private static int mapNewModifiers(int modifiers) {
    if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
        modifiers |= InputEvent.SHIFT_MASK;
    }
    if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0) {
        modifiers |= InputEvent.ALT_MASK;
    }
    if ((modifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
        modifiers |= InputEvent.ALT_GRAPH_MASK;
    }
    if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
        modifiers |= InputEvent.CTRL_MASK;
    }
    if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
        modifiers |= InputEvent.META_MASK;
    }

    return modifiers;
}
 
Example 10
Project: incubator-netbeans   File: KeyStrokeUtils.java   View Source Code Vote up 5 votes
/**
 * 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;
    }
}
 
Example 11
Project: incubator-netbeans   File: InstantRefactoringPerformer.java   View Source Code Vote up 5 votes
private static String getKeyStrokeAsText(KeyStroke keyStroke) {
    int modifiers = keyStroke.getModifiers();
    StringBuilder sb = new StringBuilder();
    sb.append('\'');
    if ((modifiers & InputEvent.CTRL_DOWN_MASK) > 0) {
        sb.append("Ctrl+"); //NOI18N
    }
    if ((modifiers & InputEvent.ALT_DOWN_MASK) > 0) {
        sb.append("Alt+"); //NOI18N
    }
    if ((modifiers & InputEvent.SHIFT_DOWN_MASK) > 0) {
        sb.append("Shift+"); //NOI18N
    }
    if ((modifiers & InputEvent.META_DOWN_MASK) > 0) {
        sb.append("Meta+"); //NOI18N
    }
    if (keyStroke.getKeyCode() != KeyEvent.VK_SHIFT
            && keyStroke.getKeyCode() != KeyEvent.VK_CONTROL
            && keyStroke.getKeyCode() != KeyEvent.VK_META
            && keyStroke.getKeyCode() != KeyEvent.VK_ALT
            && keyStroke.getKeyCode() != KeyEvent.VK_ALT_GRAPH) {
        sb.append(org.openide.util.Utilities.keyToString(
                KeyStroke.getKeyStroke(keyStroke.getKeyCode(), 0)
        ));
    }
    sb.append('\'');
    return sb.toString();
}
 
Example 12
Project: openjdk-jdk10   File: AWTKeyStroke.java   View Source Code Vote up 5 votes
@SuppressWarnings("deprecation")
private static int mapOldModifiers(int modifiers) {
    if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
        modifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((modifiers & InputEvent.ALT_MASK) != 0) {
        modifiers |= InputEvent.ALT_DOWN_MASK;
    }
    if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
        modifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
    }
    if ((modifiers & InputEvent.CTRL_MASK) != 0) {
        modifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((modifiers & InputEvent.META_MASK) != 0) {
        modifiers |= InputEvent.META_DOWN_MASK;
    }

    modifiers &= InputEvent.SHIFT_DOWN_MASK
        | InputEvent.ALT_DOWN_MASK
        | InputEvent.ALT_GRAPH_DOWN_MASK
        | InputEvent.CTRL_DOWN_MASK
        | InputEvent.META_DOWN_MASK
        | InputEvent.BUTTON1_DOWN_MASK
        | InputEvent.BUTTON2_DOWN_MASK
        | InputEvent.BUTTON3_DOWN_MASK;

    return modifiers;
}
 
Example 13
Project: openjdk-jdk10   File: AWTKeyStroke.java   View Source Code Vote up 5 votes
static String getModifiersText(int modifiers) {
    StringBuilder buf = new StringBuilder();

    if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0 ) {
        buf.append("shift ");
    }
    if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0 ) {
        buf.append("ctrl ");
    }
    if ((modifiers & InputEvent.META_DOWN_MASK) != 0 ) {
        buf.append("meta ");
    }
    if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0 ) {
        buf.append("alt ");
    }
    if ((modifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0 ) {
        buf.append("altGraph ");
    }
    if ((modifiers & InputEvent.BUTTON1_DOWN_MASK) != 0 ) {
        buf.append("button1 ");
    }
    if ((modifiers & InputEvent.BUTTON2_DOWN_MASK) != 0 ) {
        buf.append("button2 ");
    }
    if ((modifiers & InputEvent.BUTTON3_DOWN_MASK) != 0 ) {
        buf.append("button3 ");
    }

    return buf.toString();
}
 
Example 14
Project: marathonv5   File: Marathon.java   View Source Code Vote up 5 votes
public String getCharSequence(String keys) {
    StringBuilder sb = new StringBuilder();
    if (keys.length() == 1) {
        sb.append(keys);
    } else {
        KeyStrokeParser ksp = new KeyStrokeParser(keys);
        KeyStroke ks = ksp.getKeyStroke();
        CharSequence keys2 = keyMapping.get(ks.getKeyCode());
        if (keys2 == null) {
            String keysText = KeyEvent.getKeyText(ks.getKeyCode());
            if (keysText.length() == 1 && Character.isUpperCase(keysText.charAt(0))) {
                keysText = keysText.toLowerCase();
            }
            keys2 = keysText;
        }
        int modifiers = ks.getModifiers();
        if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
            sb.append(Keys.SHIFT);
        }
        if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
            sb.append(Keys.CONTROL);
        }
        if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
            sb.append(Keys.META);
        }
        if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0) {
            sb.append(Keys.ALT);
        }
        sb.append(keys2);
    }
    return sb.toString();
}
 
Example 15
Project: marathonv5   File: DeviceTest.java   View Source Code Vote up 5 votes
protected String getModifiersExText(int modifiers) {

        StringBuffer buf = new StringBuffer();
        if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
            buf.append("Meta");
            buf.append("+");
        }
        if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
            buf.append("Ctrl");
            buf.append("+");
        }
        if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0) {
            buf.append("Alt");
            buf.append("+");
        }
        if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
            buf.append("Shift");
            buf.append("+");
        }
        if ((modifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
            buf.append("Alt Graph");
            buf.append("+");
        }
        if ((modifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
            buf.append("Button1");
            buf.append("+");
        }
        if ((modifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
            buf.append("Button2");
            buf.append("+");
        }
        if ((modifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
            buf.append("Button3");
            buf.append("+");
        }
        return buf.toString();
    }
 
Example 16
Project: incubator-netbeans   File: GlassPane.java   View Source Code Vote up 4 votes
private static boolean ctrlOrCmdModifier(MouseEvent e) {
    if (Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() == InputEvent.META_MASK) { // on Mac
        return (e.getModifiersEx() & InputEvent.META_DOWN_MASK) == InputEvent.META_DOWN_MASK;
    }
    return (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK;
}
 
Example 17
Project: incubator-netbeans   File: BaseCaret.java   View Source Code Vote up 4 votes
private boolean isMiddleMouseButtonExt(MouseEvent evt) {
    return (evt.getButton() == MouseEvent.BUTTON2) &&
            (evt.getModifiersEx() & (InputEvent.CTRL_DOWN_MASK | InputEvent.META_DOWN_MASK | /* cannot be tested bcs of bug in JDK InputEvent.ALT_DOWN_MASK | */ InputEvent.ALT_GRAPH_DOWN_MASK)) == 0;
}
 
Example 18
Project: incubator-netbeans   File: EditorCaret.java   View Source Code Vote up 4 votes
private boolean isMiddleMouseButtonExt(MouseEvent evt) {
    return (evt.getButton() == MouseEvent.BUTTON2) &&
            (evt.getModifiersEx() & (InputEvent.CTRL_DOWN_MASK | InputEvent.META_DOWN_MASK | /* cannot be tested bcs of bug in JDK InputEvent.ALT_DOWN_MASK | */ InputEvent.ALT_GRAPH_DOWN_MASK)) == 0;
}
 
Example 19
Project: Logisim   File: TextFieldCaret.java   View Source Code Vote up 4 votes
@Override
public void keyPressed(KeyEvent e) {
	int ign = InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.META_DOWN_MASK;
	if ((e.getModifiersEx() & ign) != 0)
		return;
	switch (e.getKeyCode()) {
	case KeyEvent.VK_LEFT:
	case KeyEvent.VK_KP_LEFT:
		if (pos > 0)
			--pos;
		break;
	case KeyEvent.VK_RIGHT:
	case KeyEvent.VK_KP_RIGHT:
		if (pos < curText.length())
			++pos;
		break;
	case KeyEvent.VK_HOME:
		pos = 0;
		break;
	case KeyEvent.VK_END:
		pos = curText.length();
		break;
	case KeyEvent.VK_ESCAPE:
	case KeyEvent.VK_CANCEL:
		cancelEditing();
		break;
	case KeyEvent.VK_CLEAR:
		curText = "";
		pos = 0;
		break;
	case KeyEvent.VK_ENTER:
		stopEditing();
		break;
	case KeyEvent.VK_BACK_SPACE:
		if (pos > 0) {
			curText = curText.substring(0, pos - 1) + curText.substring(pos);
			--pos;
			field.setText(curText);
		}
		break;
	case KeyEvent.VK_DELETE:
		if (pos < curText.length()) {
			curText = curText.substring(0, pos) + curText.substring(pos + 1);
			field.setText(curText);
		}
		break;
	case KeyEvent.VK_INSERT:
	case KeyEvent.VK_COPY:
	case KeyEvent.VK_CUT:
	case KeyEvent.VK_PASTE:
		// TODO: enhance label editing
		break;
	default:
		; // ignore
	}
}
 
Example 20
Project: powertext   File: RSyntaxTextArea.java   View Source Code Vote up 3 votes
/**
 * Sets the mask for the key used to toggle whether we are scanning for
 * hyperlinks with mouse hovering.  The default value is
 * <code>CTRL_DOWN_MASK</code>.
 *
 * @param mask The mask to use.  This should be some bitwise combination of
 *        {@link InputEvent#CTRL_DOWN_MASK},
 *        {@link InputEvent#ALT_DOWN_MASK},
 *        {@link InputEvent#SHIFT_DOWN_MASK} or
 *        {@link InputEvent#META_DOWN_MASK}.
 *        For invalid values, behavior is undefined.
 * @see InputEvent
 */
public void setLinkScanningMask(int mask) {
	mask &= (InputEvent.CTRL_DOWN_MASK|InputEvent.META_DOWN_MASK|
			InputEvent.ALT_DOWN_MASK|InputEvent.SHIFT_DOWN_MASK);
	if (mask==0) {
		throw new IllegalArgumentException("mask argument should be " +
				"some combination of InputEvent.*_DOWN_MASK fields");
	}
	linkScanningMask = mask;
}