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

The following examples show how to use java.awt.event.KeyEvent#CTRL_DOWN_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 vote down vote up
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: CsvTableEditorKeyListenerTest.java    From intellij-csv-validator with Apache License 2.0 6 votes vote down vote up
public void testDeleteColumnActionByBackspace() {
    KeyEvent keyEvent = new KeyEvent(fileEditor.getTable(), KeyEvent.KEY_RELEASED, JComponent.WHEN_FOCUSED,
            KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK, KeyEvent.VK_BACK_SPACE, KeyEvent.CHAR_UNDEFINED);

    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    assertTrue(fileEditor.getDataHandler().equalsCurrentState(initialState));

    fileEditor.getTable().setRowSelectionInterval(1, 1);
    fileEditor.getTable().setColumnSelectionInterval(1, 1);
    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    Object[][] newState = fileEditor.getDataHandler().getCurrentState();
    assertEquals(1, newState[0].length);
    assertEquals(1, newState[1].length);
    assertEquals("Header1", newState[0][0]);
    assertEquals("this is column \"Header1\"", newState[1][0]);
}
 
Example 3
Source File: CsvTableEditorKeyListenerTest.java    From intellij-csv-validator with Apache License 2.0 6 votes vote down vote up
public void testDeleteColumnActionByDelete() {
    KeyEvent keyEvent = new KeyEvent(fileEditor.getTable(), KeyEvent.KEY_RELEASED, JComponent.WHEN_FOCUSED,
            KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK, KeyEvent.VK_DELETE, KeyEvent.CHAR_UNDEFINED);

    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    assertTrue(fileEditor.getDataHandler().equalsCurrentState(initialState));

    fileEditor.getTable().setRowSelectionInterval(1, 1);
    fileEditor.getTable().setColumnSelectionInterval(1, 1);
    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    Object[][] newState = fileEditor.getDataHandler().getCurrentState();
    assertEquals(1, newState[0].length);
    assertEquals(1, newState[1].length);
    assertEquals("Header1", newState[0][0]);
    assertEquals("this is column \"Header1\"", newState[1][0]);
}
 
Example 4
Source File: CsvTableEditorKeyListenerTest.java    From intellij-csv-validator with Apache License 2.0 6 votes vote down vote up
public void testAddColumnAfterAction() {
    KeyEvent keyEvent = new KeyEvent(fileEditor.getTable(), KeyEvent.KEY_RELEASED, JComponent.WHEN_FOCUSED,
            KeyEvent.CTRL_DOWN_MASK, KeyEvent.VK_RIGHT, KeyEvent.CHAR_UNDEFINED);

    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    Object[][] newState = fileEditor.getDataHandler().getCurrentState();
    assertEquals("", newState[0][2]);
    assertEquals("", newState[1][2]);

    fileEditor.tableEditorActions.undo.actionPerformed(null);

    fileEditor.getTable().setRowSelectionInterval(1, 1);
    fileEditor.getTable().setColumnSelectionInterval(1, 1);
    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    newState = fileEditor.getDataHandler().getCurrentState();
    assertEquals("", newState[0][2]);
    assertEquals("", newState[1][2]);
    assertEquals(1, fileEditor.getTable().getSelectedRow());
    assertEquals(1, fileEditor.getTable().getSelectedColumn());
}
 
Example 5
Source File: CsvTableEditorKeyListenerTest.java    From intellij-csv-validator with Apache License 2.0 6 votes vote down vote up
public void testAddColumnBeforeAction() {
    KeyEvent keyEvent = new KeyEvent(fileEditor.getTable(), KeyEvent.KEY_RELEASED, JComponent.WHEN_FOCUSED,
            KeyEvent.CTRL_DOWN_MASK, KeyEvent.VK_LEFT, KeyEvent.CHAR_UNDEFINED);

    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    Object[][] newState = fileEditor.getDataHandler().getCurrentState();
    assertEquals("header 2", newState[0][2]);
    assertEquals("this is column header 2", newState[1][2]);
    assertEquals("", newState[0][0]);
    assertEquals("", newState[1][0]);

    fileEditor.tableEditorActions.undo.actionPerformed(null);

    fileEditor.getTable().setRowSelectionInterval(1, 1);
    fileEditor.getTable().setColumnSelectionInterval(1, 1);
    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    newState = fileEditor.getDataHandler().getCurrentState();
    assertEquals("", newState[0][1]);
    assertEquals("", newState[1][1]);
    assertEquals(1, fileEditor.getTable().getSelectedRow());
    assertEquals(2, fileEditor.getTable().getSelectedColumn());
}
 
Example 6
Source File: CsvTableEditorKeyListenerTest.java    From intellij-csv-validator with Apache License 2.0 6 votes vote down vote up
public void testAddRowAfterAction() {
    KeyEvent keyEvent = new KeyEvent(fileEditor.getTable(), KeyEvent.KEY_RELEASED, JComponent.WHEN_FOCUSED,
            KeyEvent.CTRL_DOWN_MASK, KeyEvent.VK_DOWN, KeyEvent.CHAR_UNDEFINED);

    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    Object[][] newState = fileEditor.getDataHandler().getCurrentState();
    assertEquals(initialState.length + 1, newState.length);
    assertEquals("Header1", newState[0][0]);
    assertEquals("header 2", newState[0][1]);
    assertEquals("", newState[4][0]);
    assertEquals("", newState[4][1]);

    fileEditor.tableEditorActions.undo.actionPerformed(null);

    fileEditor.getTable().setRowSelectionInterval(1, 1);
    fileEditor.getTable().setColumnSelectionInterval(1, 1);
    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    newState = fileEditor.getDataHandler().getCurrentState();
    assertEquals(initialState.length + 1, newState.length);
    assertEquals("", newState[2][0]);
    assertEquals("", newState[2][1]);
    assertEquals(1, fileEditor.getTable().getSelectedRow());
    assertEquals(1, fileEditor.getTable().getSelectedColumn());
}
 
Example 7
Source File: CommandDispatcher.java    From ib-controller with GNU General Public License v3.0 5 votes vote down vote up
private void handleReconnectAccountCommand() {
    JFrame jf = MainWindowManager.mainWindowManager().getMainWindow();

    int modifiers = KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK;
    KeyEvent pressed=new KeyEvent(jf,  KeyEvent.KEY_PRESSED, System.currentTimeMillis(), modifiers, KeyEvent.VK_R, KeyEvent.CHAR_UNDEFINED);
    KeyEvent typed=new KeyEvent(jf, KeyEvent.KEY_TYPED, System.currentTimeMillis(), modifiers, KeyEvent.VK_UNDEFINED, 'R' );
    KeyEvent released=new KeyEvent(jf, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), modifiers, KeyEvent.VK_R,  KeyEvent.CHAR_UNDEFINED );
    jf.dispatchEvent(pressed);
    jf.dispatchEvent(typed);
    jf.dispatchEvent(released);

    mChannel.writeAck("");
}
 
Example 8
Source File: GPAction.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
private static KeyStroke parseKeyStroke(String keystrokeText) {
  KeyStroke keyStroke = KeyStroke.getKeyStroke(keystrokeText);
  if (keyStroke == null) {
    return null;
  }
  if ((keyStroke.getModifiers() & KeyEvent.CTRL_MASK) == KeyEvent.CTRL_MASK
      || (keyStroke.getModifiers() & KeyEvent.CTRL_DOWN_MASK) == KeyEvent.CTRL_DOWN_MASK) {
    int modifiers = keyStroke.getModifiers() & (0xffffffff ^ KeyEvent.CTRL_MASK) & (0xffffffff ^ KeyEvent.CTRL_DOWN_MASK) | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    keyStroke = KeyStroke.getKeyStroke(keyStroke.getKeyCode(), modifiers, keyStroke.isOnKeyRelease());
  }
  return keyStroke;
}
 
Example 9
Source File: CommandDispatcher.java    From ib-controller with GNU General Public License v3.0 5 votes vote down vote up
private void handleReconnectDataCommand() {
     JFrame jf = MainWindowManager.mainWindowManager().getMainWindow(1, TimeUnit.MILLISECONDS);

     int modifiers = KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK;
     KeyEvent pressed=new KeyEvent(jf,  KeyEvent.KEY_PRESSED, System.currentTimeMillis(), modifiers, KeyEvent.VK_F, KeyEvent.CHAR_UNDEFINED);
     KeyEvent typed=new KeyEvent(jf, KeyEvent.KEY_TYPED, System.currentTimeMillis(), modifiers, KeyEvent.VK_UNDEFINED, 'F' );
     KeyEvent released=new KeyEvent(jf, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), modifiers, KeyEvent.VK_F,  KeyEvent.CHAR_UNDEFINED );
     jf.dispatchEvent(pressed);
     jf.dispatchEvent(typed);
     jf.dispatchEvent(released);
   
     mChannel.writeAck("");
}
 
Example 10
Source File: CsvTableEditorKeyListenerTest.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
public void testDeleteRowActionByBackSpace() {
    KeyEvent keyEvent = new KeyEvent(fileEditor.getTable(), KeyEvent.KEY_RELEASED, JComponent.WHEN_FOCUSED,
            KeyEvent.CTRL_DOWN_MASK, KeyEvent.VK_BACK_SPACE, KeyEvent.CHAR_UNDEFINED);

    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    assertTrue(fileEditor.getDataHandler().equalsCurrentState(initialState));

    fileEditor.getTable().setRowSelectionInterval(1, 1);
    fileEditor.getTable().setColumnSelectionInterval(1, 1);
    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    Object[][] newState = fileEditor.getDataHandler().getCurrentState();
    assertEquals(3, newState.length);
    assertEquals("just another line with leading and trailing whitespaces", newState[1][0]);
    assertEquals("  and one more value  ", newState[1][1]);
}
 
Example 11
Source File: CsvTableEditorKeyListenerTest.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
public void testDeleteRowActionByDelete() {
    KeyEvent keyEvent = new KeyEvent(fileEditor.getTable(), KeyEvent.KEY_RELEASED, JComponent.WHEN_FOCUSED,
            KeyEvent.CTRL_DOWN_MASK, KeyEvent.VK_DELETE, KeyEvent.CHAR_UNDEFINED);

    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    assertTrue(fileEditor.getDataHandler().equalsCurrentState(initialState));

    fileEditor.getTable().setRowSelectionInterval(1, 1);
    fileEditor.getTable().setColumnSelectionInterval(1, 1);
    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    Object[][] newState = fileEditor.getDataHandler().getCurrentState();
    assertEquals(3, newState.length);
    assertEquals("just another line with leading and trailing whitespaces", newState[1][0]);
    assertEquals("  and one more value  ", newState[1][1]);
}
 
Example 12
Source File: CommandDispatcher.java    From IBC with GNU General Public License v3.0 5 votes vote down vote up
private void handleReconnectDataCommand() {
     JFrame jf = MainWindowManager.mainWindowManager().getMainWindow(1, TimeUnit.MILLISECONDS);

     int modifiers = KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK;
     KeyEvent pressed=new KeyEvent(jf,  KeyEvent.KEY_PRESSED, System.currentTimeMillis(), modifiers, KeyEvent.VK_F, KeyEvent.CHAR_UNDEFINED);
     KeyEvent typed=new KeyEvent(jf, KeyEvent.KEY_TYPED, System.currentTimeMillis(), modifiers, KeyEvent.VK_UNDEFINED, 'F' );
     KeyEvent released=new KeyEvent(jf, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), modifiers, KeyEvent.VK_F,  KeyEvent.CHAR_UNDEFINED );
     jf.dispatchEvent(pressed);
     jf.dispatchEvent(typed);
     jf.dispatchEvent(released);
   
     mChannel.writeAck("");
}
 
Example 13
Source File: TextAreaReadline.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
public void keyPressed(KeyEvent event) {
    int code = event.getKeyCode();
    switch (code) {
        case KeyEvent.VK_TAB:
            completeAction(event);
            break;
        case KeyEvent.VK_LEFT:
        case KeyEvent.VK_BACK_SPACE:
            backAction(event);
            break;
        case KeyEvent.VK_UP:
            upAction(event);
            break;
        case KeyEvent.VK_DOWN:
            downAction(event);
            break;
        case KeyEvent.VK_ENTER:
            enterAction(event);
            break;
        case KeyEvent.VK_HOME:
            event.consume();
            area.setCaretPosition(startPos);
            break;
        case KeyEvent.VK_D:
            if ((event.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0) {
                event.consume();
                inputJoin.send(Channel.LINE, EMPTY_LINE);
            }
            break;
    }

    if (completePopup.isVisible() && code != KeyEvent.VK_TAB
            && code != KeyEvent.VK_UP && code != KeyEvent.VK_DOWN)
        completePopup.setVisible(false);
}
 
Example 14
Source File: KeyMapOperator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private int buildKeyModifierMask(boolean ctrl, boolean alt, boolean shift) {
    int _mask = 0;
    if (ctrl) {
        _mask = _mask | KeyEvent.CTRL_DOWN_MASK;
    }
    if (alt) {
        _mask = _mask | KeyEvent.ALT_DOWN_MASK;
    }
    if (shift) {
        _mask = _mask | KeyEvent.SHIFT_DOWN_MASK;
    }
    return _mask;
}
 
Example 15
Source File: JBossValidation.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setUp() {
    System.out.println("########  "+getName()+"  #######");
    if (System.getProperty("os.name").startsWith("Mac OS X")) {
        modifiers = KeyEvent.META_DOWN_MASK;
    } else {
        modifiers = KeyEvent.CTRL_DOWN_MASK;
    }
}
 
Example 16
Source File: JBossValidation.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setUp() {
    System.out.println("########  "+getName()+"  #######");
    if (System.getProperty("os.name").startsWith("Mac OS X")) {
        modifiers = KeyEvent.META_DOWN_MASK;
    } else {
        modifiers = KeyEvent.CTRL_DOWN_MASK;
    }
}
 
Example 17
Source File: MainUtils.java    From PhotonFileValidator with MIT License 5 votes vote down vote up
public static int getSystemDefaultModifierMask() {
    int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    if (mask == Event.META_MASK) {
        return KeyEvent.META_DOWN_MASK;
    } else if (mask == Event.ALT_MASK) {
        return KeyEvent.ALT_DOWN_MASK;
    }
    return KeyEvent.CTRL_DOWN_MASK;
}
 
Example 18
Source File: CommandDispatcher.java    From IBC with GNU General Public License v3.0 5 votes vote down vote up
private void handleReconnectAccountCommand() {
    JFrame jf = MainWindowManager.mainWindowManager().getMainWindow();

    int modifiers = KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK;
    KeyEvent pressed=new KeyEvent(jf,  KeyEvent.KEY_PRESSED, System.currentTimeMillis(), modifiers, KeyEvent.VK_R, KeyEvent.CHAR_UNDEFINED);
    KeyEvent typed=new KeyEvent(jf, KeyEvent.KEY_TYPED, System.currentTimeMillis(), modifiers, KeyEvent.VK_UNDEFINED, 'R' );
    KeyEvent released=new KeyEvent(jf, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), modifiers, KeyEvent.VK_R,  KeyEvent.CHAR_UNDEFINED );
    jf.dispatchEvent(pressed);
    jf.dispatchEvent(typed);
    jf.dispatchEvent(released);

    mChannel.writeAck("");
}
 
Example 19
Source File: TrayIconEventModifiersTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (! SystemTray.isSupported()) {
        System.out.println("SystemTray not supported on the platform under test. " +
                "Marking the test passed");
    } else {
        if (System.getProperty("os.name").toLowerCase().startsWith("win"))
            System.err.println("Test can fail if the icon hides to a tray icons pool" +
                    "in Windows 7, which is behavior by default.\n" +
                    "Set \"Right mouse click\" -> \"Customize notification icons\" -> " +
                    "\"Always show all icons and notifications on the taskbar\" true " +
                    "to avoid this problem. Or change behavior only for Java SE tray " +
                    "icon and rerun test.");

        System.out.println(System.getProperty("os.arch"));
        if (System.getProperty("os.name").indexOf("Sun") != -1 &&
                System.getProperty("os.arch").indexOf("sparc") != -1) {
            keyTypes = new int[]{
                    KeyEvent.VK_SHIFT,
                    KeyEvent.VK_CONTROL,
                    KeyEvent.VK_META
            };

            keyNames = new String[]{
                    "SHIFT",
                    "CONTROL",
                    "META"
            };
            keyMasks = new int[]{
                    KeyEvent.SHIFT_DOWN_MASK,
                    KeyEvent.CTRL_DOWN_MASK,
                    KeyEvent.META_DOWN_MASK
            };
        }

        if (SystemTrayIconHelper.isOel7()) {
            System.out.println("OEL 7 doesn't support click modifiers in " +
                    "systray. Skipped");
            return;
        }

        new TrayIconEventModifiersTest().doTest();
    }
}
 
Example 20
Source File: MenuBar.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected @Override boolean processKeyBinding(KeyStroke ks,
                                KeyEvent e,
                                int condition,
                                boolean pressed) {
    if (Utilities.isMac()) {
        int mods = e.getModifiers();
        boolean isCtrl = (mods & KeyEvent.CTRL_MASK) != 0;
        boolean isAlt = (mods & KeyEvent.ALT_MASK) != 0;
        if (isAlt && (e instanceof MarkedKeyEvent)) {
            mods = mods & ~ KeyEvent.CTRL_MASK;
            mods = mods & ~ KeyEvent.CTRL_DOWN_MASK;
            mods |= KeyEvent.ALT_MASK;
            mods |= KeyEvent.ALT_DOWN_MASK;
            
            KeyEvent newEvent = new MarkedKeyEvent (
                (Component) e.getSource(), e.getID(), 
                e.getWhen(), mods, e.getKeyCode(), e.getKeyChar(), 
                e.getKeyLocation());
            
            KeyStroke newStroke = null;
            if( null != ks ) {
                newStroke = e.getID() == KeyEvent.KEY_TYPED ?
                    KeyStroke.getKeyStroke (ks.getKeyChar(), mods) :
                    KeyStroke.getKeyStroke (ks.getKeyCode(), mods,
                    !ks.isOnKeyRelease());
            }
            
            boolean result = super.processKeyBinding (newStroke, 
                newEvent, condition, pressed);
            
            if (newEvent.isConsumed()) {
                e.consume();
            }
            return result;
        } else if (!isAlt) {
            return super.processKeyBinding (ks, e, condition, pressed);
        } else {
            return false;
        }
    } else {
        return super.processKeyBinding (ks, e, condition, pressed);
    }                     
}