Java Code Examples for java.awt.event.KeyEvent#SHIFT_MASK

The following examples show how to use java.awt.event.KeyEvent#SHIFT_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: KeyShortcutTest.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testIsEvent() {
  final KeyShortcut shortcut = new KeyShortcut("some", KeyEvent.VK_UP, 0);

  final KeyEvent eventShift = new KeyEvent(Mockito.mock(Component.class), 1, 0L, KeyEvent.SHIFT_MASK, KeyEvent.VK_UP, ' ');
  final KeyEvent eventShiftCtrl = new KeyEvent(Mockito.mock(Component.class), 1, 0L, KeyEvent.SHIFT_MASK | KeyEvent.CTRL_MASK, KeyEvent.VK_UP, ' ');

  assertFalse(shortcut.isEvent(eventShift));
  assertFalse(shortcut.isEvent(eventShift, KeyShortcut.ALL_MODIFIERS_MASK ^ KeyEvent.CTRL_MASK));
  assertTrue(shortcut.isEvent(eventShift, KeyShortcut.ALL_MODIFIERS_MASK ^ KeyEvent.SHIFT_MASK));

  assertFalse(shortcut.isEvent(eventShiftCtrl));
  assertFalse(shortcut.isEvent(eventShiftCtrl, KeyShortcut.ALL_MODIFIERS_MASK ^ KeyEvent.CTRL_MASK));
  assertFalse(shortcut.isEvent(eventShiftCtrl, KeyShortcut.ALL_MODIFIERS_MASK ^ KeyEvent.SHIFT_MASK));
  assertTrue(shortcut.isEvent(eventShiftCtrl, KeyShortcut.ALL_MODIFIERS_MASK ^ KeyEvent.SHIFT_MASK ^ KeyEvent.CTRL_MASK));
}
 
Example 2
Source File: EditorActionUtilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 vote down vote up
/** 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: DefaultKeyboardHandler.java    From tn5250j with GNU General Public License v2.0 5 votes vote down vote up
private void processVTKeyTyped(KeyEvent e) {

    char kc = e.getKeyChar();
//      displayInfo(e,"Typed processed " + keyProcessed);
    // Hack to make german umlauts work under Linux
    // The problem is that these umlauts don't generate a keyPressed event
    // and so keyProcessed is true (even if is hasn't been processed)
    // so we check if it's a letter (with or without shift) and skip return
    if (isLinux) {

      if (!((Character.isLetter(kc) || kc == '\u20AC') && (e.getModifiers() == 0
          || e.getModifiers() == KeyEvent.SHIFT_MASK))) {

        if (Character.isISOControl(kc) || keyProcessed) {
          return;
        }
      }
    } else {
      if (Character.isISOControl(kc) || keyProcessed) {
        return;
      }
    }
    if (!session.isConnected())
      return;
    screen.sendKeys(Character.toString(kc));
    if (recording)
      recordBuffer.append(kc);
    keyProcessed = true;
    e.consume();
  }
 
Example 5
Source File: ResourceBundleSupport.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 6
Source File: KeyShortCutEditPanel.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
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 vote down vote up
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: BaseTable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    setFocusCycleRoot(false);

    try {
        Container con = BaseTable.this.getFocusCycleRootAncestor();

        if (con != null) {
            Component target = BaseTable.this;

            if (getParent() instanceof JViewport) {
                target = getParent().getParent();

                if (target == con) {
                    target = BaseTable.this;
                }
            }

            EventObject eo = EventQueue.getCurrentEvent();
            boolean backward = false;

            if (eo instanceof KeyEvent) {
                backward = ((((KeyEvent) eo).getModifiers() & KeyEvent.SHIFT_MASK) != 0) &&
                    ((((KeyEvent) eo).getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) != 0);
            }

            Component to = backward ? con.getFocusTraversalPolicy().getComponentAfter(con, BaseTable.this)
                                    : con.getFocusTraversalPolicy().getComponentAfter(con, BaseTable.this);

            if (to == BaseTable.this) {
                to = backward ? con.getFocusTraversalPolicy().getFirstComponent(con)
                              : con.getFocusTraversalPolicy().getLastComponent(con);
            }

            to.requestFocus();
        }
    } finally {
        setFocusCycleRoot(true);
    }
}
 
Example 9
Source File: TreeTable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    setFocusCycleRoot(false);

    try {
        Container con = TreeTable.this.getFocusCycleRootAncestor();

        if (con != null) {
            Component target = TreeTable.this;

            if (getParent() instanceof JViewport) {
                target = getParent().getParent();

                if (target == con) {
                    target = TreeTable.this;
                }
            }

            EventObject eo = EventQueue.getCurrentEvent();
            boolean backward = false;

            if (eo instanceof KeyEvent) {
                backward = ((((KeyEvent) eo).getModifiers() & KeyEvent.SHIFT_MASK) != 0) &&
                    ((((KeyEvent) eo).getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) != 0);
            }

            Component to = backward ? con.getFocusTraversalPolicy().getComponentAfter(con, TreeTable.this)
                                    : con.getFocusTraversalPolicy().getComponentAfter(con, TreeTable.this);

            if (to == TreeTable.this) {
                to = backward ? con.getFocusTraversalPolicy().getFirstComponent(con)
                              : con.getFocusTraversalPolicy().getLastComponent(con);
            }

            to.requestFocus();
        }
    } finally {
        setFocusCycleRoot(true);
    }
}
 
Example 10
Source File: Utilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 11
Source File: CycleFocusAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public State keyTyped (Widget widget, WidgetKeyEvent event) {
    boolean state = false;
    if (event.getKeyChar () == KeyEvent.VK_TAB) {
        if ((event.getModifiers () & KeyEvent.SHIFT_MASK) == KeyEvent.SHIFT_MASK)
            state = provider.switchPreviousFocus (widget);
        else
            state = provider.switchNextFocus (widget);
    }
    return state ? State.CONSUMED : State.REJECTED;
}
 
Example 12
Source File: BaseTable.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Overridden to allow standard keybinding processing of VK_TAB and
 * abort any pending drag operation on the vertical grid. */
public void processKeyEvent(KeyEvent e) {
    if (dragListener.isArmed()) {
        dragListener.setArmed(false);
    }

    boolean suppressDefaultHandling = ((searchField != null) && searchField.isShowing()) &&
        ((e.getKeyCode() == KeyEvent.VK_UP) || (e.getKeyCode() == KeyEvent.VK_DOWN));

    //Manually hook in the bindings for tab - does not seem to get called
    //automatically
    if (e.getKeyCode() != KeyEvent.VK_TAB) {
        if (!suppressDefaultHandling) {
            //Either the search field or the table should handle up/down, not both
            super.processKeyEvent(e);
        }

        if (!e.isConsumed()) {
            if ((e.getID() == KeyEvent.KEY_PRESSED) && !isEditing()) {
                int modifiers = e.getModifiers();
                int keyCode = e.getKeyCode();

                if (((modifiers > 0) && (modifiers != KeyEvent.SHIFT_MASK)) || e.isActionKey()) {
                    return;
                }

                char c = e.getKeyChar();

                if (!Character.isISOControl(c) && (keyCode != KeyEvent.VK_SHIFT) &&
                        (keyCode != KeyEvent.VK_ESCAPE)) {
                    searchArmed = true;
                    e.consume();
                }
            } else if (searchArmed && (e.getID() == KeyEvent.KEY_TYPED)) {
                passToSearchField(e);
                e.consume();
                searchArmed = false;
            } else {
                searchArmed = false;
            }
        }
    } else {
        processKeyBinding(
            KeyStroke.getKeyStroke(e.VK_TAB, e.getModifiersEx(), e.getID() == e.KEY_RELEASED), e,
            JComponent.WHEN_FOCUSED, e.getID() == e.KEY_PRESSED
        );
    }
}
 
Example 13
Source File: RecentViewListAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt) {
    boolean editors = true;
    boolean views = !documentsOnly;
    if( "immediately".equals( evt.getActionCommand() ) ) {
        TopComponent activeTc = TopComponent.getRegistry().getActivated();
        if( null != activeTc ) {
            if( TopComponentTracker.getDefault().isEditorTopComponent( activeTc ) ) {
                //switching in a document, go to some other document
                views = false;
            } else {
                //switching in a view, go to some other view
                editors = false;
                views = true;
            }
        }
    }
    
    TopComponent[] documents = getRecentWindows(editors, views);
    
    if (documents.length < 2) {
        return;
    }
    
    if(!"immediately".equals(evt.getActionCommand()) && // NOI18N
            !(evt.getSource() instanceof javax.swing.JMenuItem)) {
        // #46800: fetch key directly from action command
        KeyStroke keyStroke = Utilities.stringToKey(evt.getActionCommand());
        
        if(keyStroke != null) {
            int triggerKey = keyStroke.getKeyCode();
            int reverseKey = KeyEvent.VK_SHIFT;
            int releaseKey = 0;
            
            int modifiers = keyStroke.getModifiers();
            if((InputEvent.CTRL_MASK & modifiers) != 0) {
                releaseKey = KeyEvent.VK_CONTROL;
            } else if((InputEvent.ALT_MASK & modifiers) != 0) {
                releaseKey = KeyEvent.VK_ALT;
            } else if((InputEvent.META_MASK & modifiers) != 0) {
                releaseKey = KeyEvent.VK_META;
            }
            
            if(releaseKey != 0) {
                if (!KeyboardPopupSwitcher.isShown()) {
                    KeyboardPopupSwitcher.showPopup(documentsOnly, releaseKey, triggerKey, (evt.getModifiers() & KeyEvent.SHIFT_MASK) == 0);
                }
                return;
            }
        }
    }

    int documentIndex = (evt.getModifiers() & KeyEvent.SHIFT_MASK) == 0 ? 1 : documents.length-1;
    TopComponent tc = documents[documentIndex];
    // #37226 Unmaximized the other mode if needed.
    WindowManagerImpl wm = WindowManagerImpl.getInstance();
    ModeImpl mode = (ModeImpl) wm.findMode(tc);
    if(mode != null && mode != wm.getCurrentMaximizedMode()) {
        wm.switchMaximizedMode(null);
    }
    
    tc.requestActive();
}
 
Example 14
Source File: ThreadsHistoryAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt) {
    List<DVThread> threads = getThreads();
    int threadsCount = threads.size();
    if (threadsCount < 1) {
        Toolkit.getDefaultToolkit().beep();
        return;
    }
    
    if(!"immediately".equals(evt.getActionCommand()) && // NOI18N
            !(evt.getSource() instanceof javax.swing.JMenuItem)) {
        // #46800: fetch key directly from action command
        KeyStroke keyStroke = Utilities.stringToKey(evt.getActionCommand());
        
        if(keyStroke != null) {
            int triggerKey = keyStroke.getKeyCode();
            int releaseKey = 0;
            
            int modifiers = keyStroke.getModifiers();
            if((InputEvent.CTRL_MASK & modifiers) != 0) {
                releaseKey = KeyEvent.VK_CONTROL;
            } else if((InputEvent.ALT_MASK & modifiers) != 0) {
                releaseKey = KeyEvent.VK_ALT;
            } else if((InputEvent.META_MASK & modifiers) != 0) {
                releaseKey = InputEvent.META_MASK;
            }
            
            if(releaseKey != 0) {
                if (!KeyboardPopupSwitcher.isShown()) {
                    KeyboardPopupSwitcher.selectItem(
                            createSwitcherItems(threads),
                            releaseKey, triggerKey, true, true); // (evt.getModifiers() & KeyEvent.SHIFT_MASK) == 0
                }
                return;
            }
        }
    }
    
    if (threadsCount == 1) {
        threads.get(0).makeCurrent();
    } else {
        int index = (evt.getModifiers() & KeyEvent.SHIFT_MASK) == 0 ? 1 : threadsCount - 1;
        threads.get(index).makeCurrent();
    }
}
 
Example 15
Source File: JDA.java    From java-disassembler with GNU General Public License v3.0 4 votes vote down vote up
private static boolean isShiftDown(KeyEvent e) {
    return ((e.getModifiers() & KeyEvent.SHIFT_MASK) != 0);
}
 
Example 16
Source File: MindMapSettingsPanel.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
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 17
Source File: KeyShortcut.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
public boolean isShift() {
  return (this.modifiers & KeyEvent.SHIFT_MASK) != 0;
}
 
Example 18
Source File: MenuBuilder.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
public int getModifier() {
    return (shiftDown ? KeyEvent.SHIFT_MASK : 0) + (ctrlDown ? KeyEvent.CTRL_MASK : 0) + (altDown ? KeyEvent.ALT_MASK : 0);
}
 
Example 19
Source File: PreferencesPanel.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
private int getScalingModifiers() {
  return (this.checkBoxScalingALT.isSelected() ? KeyEvent.ALT_MASK : 0)
          | (this.checkBoxScalingCTRL.isSelected() ? KeyEvent.CTRL_MASK : 0)
          | (this.checkBoxScalingMETA.isSelected() ? KeyEvent.ALT_MASK : 0)
          | (this.checkBoxScalingSHIFT.isSelected() ? KeyEvent.SHIFT_MASK : 0);
}
 
Example 20
Source File: Utilities.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/** 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;
}