Java Code Examples for java.awt.event.KeyEvent#getModifiersEx()
The following examples show how to use
java.awt.event.KeyEvent#getModifiersEx() .
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: MenuBar.java From Bytecoder with Apache License 2.0 | 6 votes |
boolean handleShortcut(KeyEvent e) { // Is it a key event? int id = e.getID(); if (id != KeyEvent.KEY_PRESSED && id != KeyEvent.KEY_RELEASED) { return false; } // Is the accelerator modifier key pressed? int accelKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(); if ((e.getModifiersEx() & accelKey) == 0) { return false; } // Pass MenuShortcut on to child menus. int nmenus = getMenuCount(); for (int i = 0 ; i < nmenus ; i++) { Menu m = getMenu(i); if (m.handleShortcut(e)) { return true; } } return false; }
Example 2
Source File: PdfPanel.java From gcs with Mozilla Public License 2.0 | 6 votes |
@Override public void keyPressed(KeyEvent event) { if (!event.isConsumed() && (event.getModifiersEx() & getToolkit().getMenuShortcutKeyMaskEx()) == 0) { switch (event.getKeyCode()) { case KeyEvent.VK_UP: previousPage(); break; case KeyEvent.VK_DOWN: nextPage(); break; default: return; } event.consume(); } }
Example 3
Source File: PdfPanel.java From gcs with Mozilla Public License 2.0 | 6 votes |
@Override public void keyTyped(KeyEvent event) { if (!event.isConsumed() && (event.getModifiersEx() & getToolkit().getMenuShortcutKeyMaskEx()) == 0) { char ch = event.getKeyChar(); switch (ch) { case '-': zoomOut(); break; case '=': zoomIn(); break; case '1': actualSize(); break; default: return; } event.consume(); } }
Example 4
Source File: ModifierListEditor.java From gcs with Mozilla Public License 2.0 | 6 votes |
@Override public void keyPressed(KeyEvent event) { super.keyPressed(event); if (!event.isConsumed() && (event.getModifiersEx() & getToolkit().getMenuShortcutKeyMaskEx()) == 0 && event.getKeyCode() == KeyEvent.VK_SPACE) { boolean doNotify = false; OutlineModel model = getModel(); if (mAddButton.isEnabled() && model.hasSelection()) { for (Modifier modifier : new FilteredIterator<>(model.getSelectionAsList(), Modifier.class)) { if (!modifier.isReadOnly()) { modifier.setEnabled(!modifier.isEnabled()); mModified = true; doNotify = true; } } repaintSelection(); } event.consume(); if (doNotify) { ModifierListEditor.this.notifyActionListeners(); } } }
Example 5
Source File: DirectionConfigurator.java From Logisim with GNU General Public License v3.0 | 5 votes |
@Override public KeyConfigurationResult keyEventReceived(KeyConfigurationEvent event) { if (event.getType() == KeyConfigurationEvent.KEY_PRESSED) { KeyEvent e = event.getKeyEvent(); if (e.getModifiersEx() == modsEx) { Direction value = null; switch (e.getKeyCode()) { case KeyEvent.VK_UP: value = Direction.NORTH; break; case KeyEvent.VK_DOWN: value = Direction.SOUTH; break; case KeyEvent.VK_LEFT: value = Direction.WEST; break; case KeyEvent.VK_RIGHT: value = Direction.EAST; break; } if (value != null) { event.consume(); return new KeyConfigurationResult(event, attr, value); } } } return null; }
Example 6
Source File: Keybind.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
protected boolean matches(KeyEvent e, boolean ignoreModifiers) { if (NOT_SET.equals(this)) { return false; } int keyCode = e.getExtendedKeyCode(); int modifiers = e.getModifiersEx() & KEYBOARD_MODIFIER_MASK; Integer mf = getModifierForKeyCode(keyCode); if (mf != null) { modifiers |= mf; keyCode = KeyEvent.VK_UNDEFINED; } if (e.getID() == KeyEvent.KEY_RELEASED && keyCode != KeyEvent.VK_UNDEFINED) { return this.keyCode == keyCode; } if (ignoreModifiers && keyCode != KeyEvent.VK_UNDEFINED) { return this.keyCode == keyCode; } return this.keyCode == keyCode && this.modifiers == modifiers; }
Example 7
Source File: WalletListPanel.java From bither-desktop-java with Apache License 2.0 | 5 votes |
public final void selectAdjacentWallet(KeyEvent e, String keyStatus) { int keyCode = e.getKeyCode(); int modifiersEx = e.getModifiersEx(); boolean moveToNextWallet = ((keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_KP_DOWN) && modifiersEx == KeyEvent.SHIFT_DOWN_MASK); boolean moveToPreviousWallet = ((keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_KP_UP) && modifiersEx == KeyEvent.SHIFT_DOWN_MASK); if (walletPanels != null) { synchronized (walletPanels) { int currentlySelectedWalletIndex = 0; int nextSelectedWalletIndex = -1; for (IAddressForm loopSingleWalletPanel : walletPanels) { // Found the currently selected panel. if (moveToNextWallet && currentlySelectedWalletIndex < walletPanels.size() - 1) { nextSelectedWalletIndex = currentlySelectedWalletIndex + 1; break; } else { if (moveToPreviousWallet && currentlySelectedWalletIndex > 0) { nextSelectedWalletIndex = currentlySelectedWalletIndex - 1; break; } } currentlySelectedWalletIndex++; } if (nextSelectedWalletIndex > -1) { Bither.getCoreController().fireDataChangedUpdateNow(); } } } }
Example 8
Source File: FormDateHandler.java From javamoney-examples with Apache License 2.0 | 5 votes |
@Override public void keyPressed(KeyEvent event) { JTextField field = (JTextField)event.getSource(); int key = event.getKeyCode(); if(key == VK_DOWN || key == VK_UP) { GregorianCalendar calendar = createCalendar(getDate(field)); int modifier = event.getModifiersEx(); int dateField = 0; if(modifier == ALT_DOWN_MASK) { dateField = YEAR; } else if(modifier == SHIFT_DOWN_MASK) { dateField = MONTH; } else { dateField = DAY_OF_MONTH; } if(key == VK_UP) { calendar.set(dateField, calendar.get(dateField) + 1); } else { calendar.set(dateField, calendar.get(dateField) - 1); } field.setText(UI_DATE_FORMAT.format(calendar.getTime())); } }
Example 9
Source File: NumericConfigurator.java From Logisim with GNU General Public License v3.0 | 5 votes |
@Override public KeyConfigurationResult keyEventReceived(KeyConfigurationEvent event) { if (event.getType() == KeyConfigurationEvent.KEY_TYPED) { KeyEvent e = event.getKeyEvent(); int digit = Character.digit(e.getKeyChar(), radix); if (digit >= 0 && e.getModifiersEx() == modsEx) { long now = System.currentTimeMillis(); long sinceLast = now - whenTyped; AttributeSet attrs = event.getAttributeSet(); int min = getMinimumValue(attrs); int max = getMaximumValue(attrs); int val = 0; if (sinceLast < MAX_TIME_KEY_LASTS) { val = radix * curValue; if (val > max) { val = 0; } } val += digit; if (val > max) { val = digit; if (val > max) { return null; } } event.consume(); whenTyped = now; curValue = val; if (val >= min) { Object valObj = createValue(val); return new KeyConfigurationResult(event, attr, valObj); } } } return null; }
Example 10
Source File: TextEditor.java From groovy with Apache License 2.0 | 5 votes |
protected void processKeyEvent(KeyEvent e) { super.processKeyEvent(e); // Handle release of Insert key to toggle overtype/insert mode // unless a modifier is active (eg Shift+Insert for paste or // Ctrl+Insert for Copy) if (e.getID() == KeyEvent.KEY_RELEASED && e.getKeyCode() == KeyEvent.VK_INSERT && e.getModifiersEx() == 0) { setOvertypeMode(!isOvertypeMode()); } }
Example 11
Source File: Caret.java From Logisim with GNU General Public License v3.0 | 5 votes |
@Override public void keyTyped(KeyEvent e) { int mask = e.getModifiersEx(); if ((mask & ~InputEvent.SHIFT_DOWN_MASK) != 0) return; char c = e.getKeyChar(); int cols = hex.getMeasures().getColumnCount(); switch (c) { case ' ': if (cursor >= 0) setDot(cursor + 1, (mask & InputEvent.SHIFT_DOWN_MASK) != 0); break; case '\n': if (cursor >= 0) setDot(cursor + cols, (mask & InputEvent.SHIFT_DOWN_MASK) != 0); break; case '\u0008': case '\u007f': hex.delete(); // setDot(cursor - 1, (mask & InputEvent.SHIFT_MASK) != 0); break; default: int digit = Character.digit(e.getKeyChar(), 16); if (digit >= 0) { HexModel model = hex.getModel(); if (model != null && cursor >= model.getFirstOffset() && cursor <= model.getLastOffset()) { int curValue = model.get(cursor); int newValue = 16 * curValue + digit; model.set(cursor, newValue); } } } }
Example 12
Source File: Search.java From gcs with Mozilla Public License 2.0 | 5 votes |
private boolean redirectKeyEventToFloater(KeyEvent event) { if (mFloater != null && !event.isConsumed() && (event.getModifiersEx() & getToolkit().getMenuShortcutKeyMaskEx()) == 0) { int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN) { mFloater.handleKeyPressed(event); return true; } } return false; }
Example 13
Source File: Debug.java From Pixelitor with GNU General Public License v3.0 | 5 votes |
public static String keyEvent(KeyEvent e) { String keyText = KeyEvent.getKeyText(e.getKeyCode()); int modifiers = e.getModifiersEx(); if (modifiers != 0) { String modifiersText = InputEvent.getModifiersExText(modifiers); if (keyText.equals(modifiersText)) { // the key itself is the modifier return modifiersText; } return modifiersText + "+" + keyText; } return keyText; }
Example 14
Source File: AddTool.java From Logisim with GNU General Public License v3.0 | 4 votes |
@Override public void keyPressed(Canvas canvas, KeyEvent event) { processKeyEvent(canvas, event, KeyConfigurationEvent.KEY_PRESSED); if (!event.isConsumed() && event.getModifiersEx() == 0) { switch (event.getKeyCode()) { case KeyEvent.VK_UP: setFacing(canvas, Direction.NORTH); break; case KeyEvent.VK_DOWN: setFacing(canvas, Direction.SOUTH); break; case KeyEvent.VK_LEFT: setFacing(canvas, Direction.WEST); break; case KeyEvent.VK_RIGHT: setFacing(canvas, Direction.EAST); break; case KeyEvent.VK_BACK_SPACE: if (lastAddition != null && canvas.getProject().getLastAction() == lastAddition) { canvas.getProject().undoAction(); lastAddition = null; } break; case KeyEvent.VK_DELETE: case KeyEvent.VK_ESCAPE: if (state == SHOW_GHOST) { Project proj = canvas.getProject(); Tool next = determineNext(proj); if (next != null) { proj.setTool(next); Action act = SelectionActions.dropAll(canvas.getSelection()); if (act != null) { proj.doAction(act); } } } break; } } }
Example 15
Source File: MainPanel.java From java-swing-tips with MIT License | 4 votes |
@Override public void keyReleased(KeyEvent e) { shiftActive = (e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0; if (!shiftActive) { fire(e.getSource()); } }
Example 16
Source File: MainPanel.java From java-swing-tips with MIT License | 4 votes |
@Override public void keyPressed(KeyEvent e) { shiftActive = (e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0; }
Example 17
Source File: TextFieldCaret.java From Logisim with GNU General Public License v3.0 | 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 18
Source File: NumberFilter.java From gcs with Mozilla Public License 2.0 | 4 votes |
@Override public void keyTyped(KeyEvent event) { if (!event.isConsumed() && (event.getModifiersEx() & mField.getToolkit().getMenuShortcutKeyMaskEx()) == 0) { char ch = event.getKeyChar(); if (ch != '\n' && ch != '\r' && ch != '\t' && ch != '\b' && ch != KeyEvent.VK_DELETE) { if (mAllowGroup && ch == GROUP_CHAR || ch >= '0' && ch <= '9' || mAllowSign && (ch == '-' || ch == '+') || mAllowDecimal && ch == DECIMAL_CHAR || mIsHeightFilter && (ch == '\'' || ch == '"' || ch == ' ')) { StringBuilder buffer = new StringBuilder(mField.getText()); int start = mField.getSelectionStart(); int end = mField.getSelectionEnd(); if (start != end) { buffer.delete(start, end); } if (ch >= '0' && ch <= '9') { int length = buffer.length(); int count = 0; for (int i = 0; i < length; i++) { char one = buffer.charAt(i); if (one >= '0' && one <= '9') { count++; } } if (count >= mMaxDigits) { filter(event); return; } } if (ch == GROUP_CHAR || ch >= '0' && ch <= '9') { if (mAllowSign && start == 0 && buffer.length() > 0 && (buffer.charAt(0) == '-' || buffer.charAt(0) == '+')) { filter(event); } } else if (ch == '-' || ch == '+') { if (start != 0) { filter(event); } } else if (ch == DECIMAL_CHAR) { if (buffer.indexOf("" + DECIMAL_CHAR) != -1 || mAllowSign && start == 0 && buffer.length() > 0 && (buffer.charAt(0) == '-' || buffer.charAt(0) == '+')) { filter(event); } } else if (ch == '\'') { if (buffer.indexOf("'") != -1) { filter(event); } } else if (ch == '"') { if (buffer.indexOf("\"") != -1) { filter(event); } } } else { filter(event); } } } }
Example 19
Source File: MergedPanel.java From Briss-2.0 with GNU General Public License v3.0 | 4 votes |
@Override public void keyPressed(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_C: if (e.getModifiersEx() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()) { copyToClipBoard(); } break; case KeyEvent.VK_V: if (e.getModifiersEx() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()) { pasteFromClipBoard(); } break; case KeyEvent.VK_DELETE: deleteAllSelected(); break; case KeyEvent.VK_LEFT: case KeyEvent.VK_RIGHT: case KeyEvent.VK_UP: case KeyEvent.VK_DOWN: int x = 0; int y = 0; switch (e.getKeyCode()) { case KeyEvent.VK_LEFT: x = -1; break; case KeyEvent.VK_RIGHT: x = 1; break; case KeyEvent.VK_UP: y = -1; break; case KeyEvent.VK_DOWN: y = 1; break; } if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0) { x *= 10; y *= 10; } if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) { briss.resizeSelRects(x, y); } else { briss.moveSelectedRects(x, y); } break; default: } }
Example 20
Source File: MouseModifiersInKeyEvent.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public void keyPressed(final KeyEvent e) { modifiersEX = e.getModifiersEx(); modifiers = e.getModifiers(); }