Java Code Examples for java.awt.event.KeyEvent#META_MASK
The following examples show how to use
java.awt.event.KeyEvent#META_MASK .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utilities.java From netbeans with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: EditorActionUtilities.java From netbeans with Apache License 2.0 | 6 votes |
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(); }
Example 3
Source File: Utilities.java From netbeans with Apache License 2.0 | 5 votes |
/** 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; }
Example 4
Source File: Utilities.java From netbeans with Apache License 2.0 | 5 votes |
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; }
Example 5
Source File: ShortcutListener.java From netbeans with Apache License 2.0 | 5 votes |
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(); } }
Example 6
Source File: KeyShortCutEditPanel.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
private void updateCurrentSelectedForKey (final KeyEvent evt) { final int index = this.tableKeyShortcuts.getSelectedRow(); if (index>=0){ final KeyShortcut oldShortcut = this.listOfKeys.get(index); final int keyCode = evt.getKeyCode(); final int modifiers = evt.getModifiers() & (KeyEvent.META_MASK | KeyEvent.SHIFT_MASK | KeyEvent.CTRL_MASK | KeyEvent.ALT_MASK); final KeyShortcut newShortCut = new KeyShortcut(oldShortcut.getID(),keyCode,modifiers); this.listOfKeys.set(index, newShortCut); for(final TableModelListener l:this.listeners){ l.tableChanged(new TableModelEvent(this,index)); } } updateForSelected(); }
Example 7
Source File: KeyShortCutEditPanel.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
private void updateCurrentSelectedForKey(final KeyEvent evt) { final int index = this.tableKeyShortcuts.getSelectedRow(); if (index >= 0) { final KeyShortcut oldShortcut = this.listOfKeys.get(index); final int keyCode = evt.getKeyCode(); final int modifiers = evt.getModifiers() & (KeyEvent.META_MASK | KeyEvent.SHIFT_MASK | KeyEvent.CTRL_MASK | KeyEvent.ALT_MASK); final KeyShortcut newShortCut = new KeyShortcut(oldShortcut.getID(), keyCode, modifiers); this.listOfKeys.set(index, newShortCut); for (final TableModelListener l : this.listeners) { l.tableChanged(new TableModelEvent(this, index)); } } updateForSelected(); }
Example 8
Source File: KeyShortCutEditPanel.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
private void updateCurrentSelectedForKey (final KeyEvent evt) { final int index = this.tableKeyShortcuts.getSelectedRow(); if (index>=0){ final KeyShortcut oldShortcut = this.listOfKeys.get(index); final int keyCode = evt.getKeyCode(); final int modifiers = evt.getModifiers() & (KeyEvent.META_MASK | KeyEvent.SHIFT_MASK | KeyEvent.CTRL_MASK | KeyEvent.ALT_MASK); final KeyShortcut newShortCut = new KeyShortcut(oldShortcut.getID(),keyCode,modifiers); this.listOfKeys.set(index, newShortCut); for(final TableModelListener l:this.listeners){ l.tableChanged(new TableModelEvent(this,index)); } } updateForSelected(); }
Example 9
Source File: ResourceBundleSupport.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Returns the keystroke stored at the given resourcebundle key. * <p/> * The keystroke will be composed of a simple key press and the plattform's MenuKeyMask. * <p/> * The keystrokes character key should be either the symbolic name of one of the KeyEvent.VK_* constants or the * character for that key. * <p/> * For the 'A' key, the resource bundle would therefore either contain "VK_A" or "a". * <pre> * a.resourcebundle.key=VK_A * an.other.resourcebundle.key=a * </pre> * * @param key the resourcebundle key * @return the keystroke * @see java.awt.Toolkit#getMenuShortcutKeyMask() */ public KeyStroke getKeyStroke( final String key ) { String name = strictString( key ); if ( StringUtils.isEmpty( name ) ) { return null; } boolean explicitNone = false; int mask = 0; final StringTokenizer strtok = new StringTokenizer( name ); while ( strtok.hasMoreTokens() ) { final String token = strtok.nextToken(); if ( "shift".equals( token ) ) { mask |= KeyEvent.SHIFT_MASK; } else if ( "alt".equals( token ) ) { mask |= KeyEvent.ALT_MASK; } else if ( "ctrl".equals( token ) ) { mask |= KeyEvent.CTRL_MASK; } else if ( "meta".equals( token ) ) { mask |= KeyEvent.META_MASK; } else if ( "menu".equals( token ) ) { mask |= getMenuKeyMask(); } else if ( "none".equals( token ) ) { explicitNone = true; } else { name = token; } } if ( explicitNone == true ) { mask = 0; } else if ( mask == 0 ) { mask = getMenuKeyMask(); } //noinspection MagicConstant return KeyStroke.getKeyStroke( createMnemonic( name ).intValue(), mask ); }
Example 10
Source File: ResourceBundleSupport.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Returns the keystroke stored at the given resourcebundle key. * <p/> * The keystroke will be composed of a simple key press and a keystroke mask pattern. The pattern should be specified * via the words "shift", "alt", "ctrl", "meta" or "menu". Menu should be used to reference the platform specific menu * shortcut. For the sake of safety, menu should only be combined with "shift" and/or "alt" for menu keystrokes. * <p/> * The keystrokes character key should be either the symbolic name of one of the KeyEvent.VK_* constants or the * character for that key. * <p/> * For the 'A' key, the resource bundle would therefore either contain "VK_A" or "a". * <pre> * a.resourcebundle.key=VK_A * an.other.resourcebundle.key=a * </pre> * * @param key the resourcebundle key * @return the keystroke * @see java.awt.Toolkit#getMenuShortcutKeyMask() */ public KeyStroke getOptionalKeyStroke( final String key ) { try { String name = getOptionalString( key ); if ( StringUtils.isEmpty( name ) ) { return null; } boolean noneSelected = false; int mask = 0; final StringTokenizer strtok = new StringTokenizer( name ); while ( strtok.hasMoreTokens() ) { final String token = strtok.nextToken(); if ( "shift".equals( token ) ) { mask |= KeyEvent.SHIFT_MASK; } else if ( "alt".equals( token ) ) { mask |= KeyEvent.ALT_MASK; } else if ( "ctrl".equals( token ) ) { mask |= KeyEvent.CTRL_MASK; } else if ( "meta".equals( token ) ) { mask |= KeyEvent.META_MASK; } else if ( "menu".equals( token ) ) { mask |= getMenuKeyMask(); } else if ( "none".equals( token ) ) { noneSelected = true; } else { name = token; } } if ( noneSelected ) { mask = 0; } else if ( mask == 0 ) { mask = getMenuKeyMask(); } //noinspection MagicConstant return KeyStroke.getKeyStroke( createMnemonic( name ).intValue(), mask ); } catch ( MissingResourceException mre ) { return null; } }
Example 11
Source File: GUIMain.java From PacketProxy with Apache License 2.0 | 4 votes |
/** * JTextPane上でCommand+Cとかでコピペをできるようにする */ private void addShortcutForMac() { if (!PacketProxyUtility.getInstance().isMac()) { return; } JPanel p = (JPanel) getContentPane(); InputMap im = p.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap am = p.getActionMap(); int hotkey = (KeyEvent.CTRL_MASK | KeyEvent.META_MASK); registerTabShortcut(KeyEvent.VK_H, hotkey, im, am, Panes.HISTORY.ordinal()); registerTabShortcut(KeyEvent.VK_I, hotkey, im, am, Panes.INTERCEPT.ordinal()); registerTabShortcut(KeyEvent.VK_R, hotkey, im, am, Panes.REPEATER.ordinal()); registerTabShortcut(KeyEvent.VK_B, hotkey, im, am, Panes.BULKSENDER.ordinal()); registerTabShortcut(KeyEvent.VK_O, hotkey, im, am, Panes.OPTIONS.ordinal()); registerTabShortcut(KeyEvent.VK_L, hotkey, im, am, Panes.LOG.ordinal()); JTextComponent.KeyBinding[] bindings1 = { new JTextComponent.KeyBinding( KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), DefaultEditorKit.copyAction), new JTextComponent.KeyBinding( KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), DefaultEditorKit.pasteAction), new JTextComponent.KeyBinding( KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), DefaultEditorKit.cutAction), new JTextComponent.KeyBinding( KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), DefaultEditorKit.selectAllAction), }; JTextPane component_tp = new JTextPane(); Keymap keymap_tp = component_tp.getKeymap(); JTextComponent.loadKeymap(keymap_tp, bindings1, component_tp.getActions()); JTextField component_tf = new JTextField(); Keymap keymap_tf = component_tf.getKeymap(); JTextComponent.loadKeymap(keymap_tf, bindings1, component_tf.getActions()); JTextArea component_ta = new JTextArea(); Keymap keymap_ta = component_ta.getKeymap(); JTextComponent.loadKeymap(keymap_ta, bindings1, component_ta.getActions()); }
Example 12
Source File: Catbert.java From sagetv with Apache License 2.0 | 4 votes |
public static int[] getKeystrokeFromString(String s) { if (s == null || s.length() == 0) return new int[] { 0, 0 }; if ("+".equals(s)) return new int[] { KeyEvent.VK_PLUS, 0 }; int code = 0; int mods = 0; if (s.endsWith("+")) { code = KeyEvent.VK_PLUS; s = s.substring(0, s.length() - 1); } else { int lastPlus = s.lastIndexOf('+'); String codestr; if (lastPlus != -1) { codestr = s.substring(lastPlus + 1); s = s.substring(0, lastPlus); } else { codestr = s; s = ""; } Integer o = keystrokeNameMap.get(codestr); if (o != null) { code = o.intValue(); } else { code = codestr.toUpperCase().charAt(0); } } String ctrlName = KeyEvent.getKeyModifiersText(KeyEvent.CTRL_MASK); String altName = KeyEvent.getKeyModifiersText(KeyEvent.ALT_MASK); String shiftName = KeyEvent.getKeyModifiersText(KeyEvent.SHIFT_MASK); String metaName = KeyEvent.getKeyModifiersText(KeyEvent.META_MASK); StringTokenizer toker = new StringTokenizer(s, "+"); while (toker.hasMoreTokens()) { String modName = toker.nextToken(); if (modName.equalsIgnoreCase(ctrlName)) mods = mods | KeyEvent.CTRL_MASK; else if (modName.equalsIgnoreCase(altName)) mods = mods | KeyEvent.ALT_MASK; else if (modName.equalsIgnoreCase(shiftName)) mods = mods | KeyEvent.SHIFT_MASK; else if (modName.equalsIgnoreCase(metaName)) mods = mods | KeyEvent.META_MASK; } return new int[] { code, mods }; }
Example 13
Source File: KeyShortcut.java From netbeans-mmd-plugin with Apache License 2.0 | 4 votes |
public boolean isMeta() { return (this.modifiers & KeyEvent.META_MASK) != 0; }
Example 14
Source File: MindMapSettingsPanel.java From netbeans-mmd-plugin with Apache License 2.0 | 4 votes |
public MindMapPanelConfig makeConfig() { final MindMapPanelConfig result = new MindMapPanelConfig(this.etalon, false); result.setPaperColor(this.colorButtonBackgroundColor.getValue()); result.setGridColor(this.colorButtonGridColor.getValue()); result.setCollapsatorBackgroundColor(this.colorButtonCollapsatorFill.getValue()); result.setCollapsatorBorderColor(this.colorButtonCollapsatorBorder.getValue()); result.setConnectorColor(this.colorButtonConnectorColor.getValue()); result.setJumpLinkColor(this.colorButtonJumpLink.getValue()); result.setSelectLineColor(this.colorButtonSelectFrameColor.getValue()); result.setRootBackgroundColor(this.colorButtonRootFill.getValue()); result.setRootTextColor(this.colorButtonRootText.getValue()); result.setFirstLevelBackgroundColor(this.colorButton1stLevelFill.getValue()); result.setFirstLevelTextColor(this.colorButton1stLevelText.getValue()); result.setOtherLevelBackgroundColor(this.colorButton2ndLevelFill.getValue()); result.setOtherLevelTextColor(this.colorButton2ndLevelText.getValue()); result.setGridStep(getInt(this.spinnerGridStep)); result.setConnectorWidth(getFloat(this.spinnerConnectorWidth)); result.setCollapsatorSize(getInt(this.spinnerCollapsatorSize)); result.setCollapsatorBorderWidth(getFloat(this.spinnerCollapsatorWidth)); result.setJumpLinkWidth(getFloat(this.spinnerJumpLinkWidth)); result.setSelectLineWidth(getFloat(this.spinnerSelectionFrameWidth)); result.setSelectLineGap(getInt(this.spinnerSelectionFrameGap)); result.setElementBorderWidth(getFloat(this.spinnerBorderWidth)); result.setShowGrid(this.checkBoxShowGrid.isSelected()); result.setDropShadow(this.checkBoxDropShadow.isSelected()); result.setSmartTextPaste(this.checkBoxSmartTextPaste.isSelected()); result.setFirstLevelHorizontalInset(this.slider1stLevelHorzGap.getValue()); result.setFirstLevelVerticalInset(this.slider1stLevelVertGap.getValue()); result.setOtherLevelHorizontalInset(this.slider2ndLevelHorzGap.getValue()); result.setOtherLevelVerticalInset(this.slider2ndLevelVertGap.getValue()); result.setRenderQuality(GetUtils.ensureNonNull((RenderQuality) comboBoxRenderQuality.getSelectedItem(), RenderQuality.DEFAULT)); result.setFont(this.theFont); final int scaleModifier = (this.checkBoxScalingModifierALT.isSelected() ? KeyEvent.ALT_MASK : 0) | (this.checkBoxScalingModifierCTRL.isSelected() ? KeyEvent.CTRL_MASK : 0) | (this.checkBoxScalingModifierSHFT.isSelected() ? KeyEvent.SHIFT_MASK : 0) | (this.checkBoxScalingModifierMETA.isSelected() ? KeyEvent.META_MASK : 0); result.setScaleModifiers(scaleModifier); for (final Map.Entry<String, KeyShortcut> e : this.mapKeyShortCuts.entrySet()) { result.setKeyShortCut(e.getValue()); } return result; }
Example 15
Source File: Utilities.java From netbeans with Apache License 2.0 | 2 votes |
/** Reads for modifiers and creates integer with required mask. * @param s string with modifiers * @return integer with mask * @exception NoSuchElementException if some letter is not modifier */ private static int readModifiers(String s) throws NoSuchElementException { int m = 0; for (int i = 0; i < s.length(); i++) { switch (s.charAt(i)) { case 'C': m |= KeyEvent.CTRL_MASK; break; case 'A': m |= KeyEvent.ALT_MASK; break; case 'M': m |= KeyEvent.META_MASK; break; case 'S': m |= KeyEvent.SHIFT_MASK; break; case 'D': m |= CTRL_WILDCARD_MASK; break; case 'O': m |= ALT_WILDCARD_MASK; break; default: throw new NoSuchElementException(s); } } return m; }