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

The following examples show how to use java.awt.event.KeyEvent#VK_DELETE . 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: Outline.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void keyTyped(KeyEvent event) {
    if (!event.isConsumed() && (event.getModifiersEx() & getToolkit().getMenuShortcutKeyMaskEx()) == 0) {
        char ch = event.getKeyChar();
        if (ch == '\n' || ch == '\r') {
            if (mModel.hasSelection()) {
                notifyActionListeners();
            }
            event.consume();
        } else if (ch == '\b' || ch == KeyEvent.VK_DELETE) {
            if (canDeleteSelection()) {
                deleteSelection();
            }
            event.consume();
        }
    }
}
 
Example 2
Source File: TreePanel.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void keyTyped(KeyEvent event) {
    if (!event.isConsumed() && (event.getModifiersEx() & getToolkit().getMenuShortcutKeyMaskEx()) == 0) {
        char ch = event.getKeyChar();
        if (ch == '\n' || ch == '\r') {
            if (canOpenSelection()) {
                openSelection();
            }
            event.consume();
        } else if (ch == '\b' || ch == KeyEvent.VK_DELETE) {
            if (canDeleteSelection()) {
                deleteSelection();
            }
            event.consume();
        }
    }
}
 
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: FoodPanel.java    From Java-Simple-Hotel-Management with GNU General Public License v3.0 5 votes vote down vote up
private void tf_food_priceKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_food_priceKeyTyped
    char c = evt.getKeyChar();
    
    if(!(Character.isDigit(c) || c== KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE ))
    {
        evt.consume();
    }
}
 
Example 5
Source File: ControlPanel.java    From Java-Simple-Hotel-Management with GNU General Public License v3.0 5 votes vote down vote up
private void tf_contactKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_contactKeyTyped
    char c = evt.getKeyChar();

    if (!(Character.isDigit(c) || c == KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE)) {
        evt.consume();
    }
}
 
Example 6
Source File: CsvTableEditorKeyListener.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
@Override
public void keyReleased(KeyEvent e) {
    switch (e.getKeyCode()) {
        case KeyEvent.VK_LEFT:
            if (e.isControlDown()) {
                csvTableEditor.tableEditorActions.addColumnBefore.actionPerformed(null);
            }
            break;
        case KeyEvent.VK_RIGHT:
            if (e.isControlDown()) {
                csvTableEditor.tableEditorActions.addColumnAfter.actionPerformed(null);
            }
            break;
        case KeyEvent.VK_UP:
            if (e.isControlDown()) {
                csvTableEditor.tableEditorActions.addRowBefore.actionPerformed(null);
            }
            break;
        case KeyEvent.VK_DOWN:
            if (e.isControlDown()) {
                csvTableEditor.tableEditorActions.addRowAfter.actionPerformed(null);
            }
            break;
        case KeyEvent.VK_ENTER:
            if (e.isControlDown() && csvTableEditor.isInCellEditMode()) {
                stopEditing.actionPerformed(null);
            } else if (!csvTableEditor.isInCellEditMode()) {
                startEditing.actionPerformed(null);
            }
            break;
        case KeyEvent.VK_DELETE:
        case KeyEvent.VK_BACK_SPACE:
            if (e.isControlDown() && e.isShiftDown()) {
                csvTableEditor.tableEditorActions.deleteColumn.actionPerformed(null);
            } else if (e.isControlDown()) {
                csvTableEditor.tableEditorActions.deleteRow.actionPerformed(null);
            } else if (!csvTableEditor.isInCellEditMode()) {
                csvTableEditor.tableEditorActions.clearCells.actionPerformed(null);
            }
            break;
        default:
            break;
    }
}
 
Example 7
Source File: TreeElementAttributeListCustomizer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
         */
        public void keyReleased (KeyEvent e) {
            //if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("Event: " + e); // NOI18N
            if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                tableModel.removeRow (table.getSelectedRow());
//                  peer.remove (peer.get (table.getSelectedRow()));
//                  tableModel.fireTableDataChanged();
            }
        }
 
Example 8
Source File: RoomPanel.java    From Java-Simple-Hotel-Management with GNU General Public License v3.0 5 votes vote down vote up
private void tf_priceKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_priceKeyTyped
    char c = evt.getKeyChar();
    
    if(!(Character.isDigit(c) || c== KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE ))
    {
        evt.consume();
    }
}
 
Example 9
Source File: Keyboard.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyPressed(InstanceState state, KeyEvent e) {
	KeyboardData data = getKeyboardState(state);
	boolean changed = false;
	boolean used = true;
	synchronized (data) {
		switch (e.getKeyCode()) {
		case KeyEvent.VK_DELETE:
			changed = data.delete();
			break;
		case KeyEvent.VK_LEFT:
			data.moveCursorBy(-1);
			break;
		case KeyEvent.VK_RIGHT:
			data.moveCursorBy(1);
			break;
		case KeyEvent.VK_HOME:
			data.setCursor(0);
			break;
		case KeyEvent.VK_END:
			data.setCursor(Integer.MAX_VALUE);
			break;
		default:
			used = false;
		}
	}
	if (used)
		e.consume();
	if (changed)
		state.getInstance().fireInvalidated();
}
 
Example 10
Source File: KeyStrokeParser.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static String getTextForKeyChar(char keyChar) {
    int keycode;
    switch (keyChar) {
    case ' ':
        keycode = KeyEvent.VK_SPACE;
        break;
    case '\b':
        keycode = KeyEvent.VK_BACK_SPACE;
        break;
    case '\t':
        keycode = KeyEvent.VK_TAB;
        break;
    case '\n':
        keycode = KeyEvent.VK_ENTER;
        break;
    case '\u0018':
        keycode = KeyEvent.VK_CANCEL;
        break;
    case '\u001b':
        keycode = KeyEvent.VK_ESCAPE;
        break;
    case '\u007f':
        keycode = KeyEvent.VK_DELETE;
        break;
    default:
        return "" + keyChar;
    }
    return (String) keyCodes.get(Integer.valueOf(keycode));
}
 
Example 11
Source File: SwingUtilities2.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the given event is corrent gesture for
 * accessing clipboard
 *
 * @param ie InputEvent to check
 */
@SuppressWarnings("deprecation")
private static boolean isAccessClipboardGesture(InputEvent ie) {
    boolean allowedGesture = false;
    if (ie instanceof KeyEvent) { //we can validate only keyboard gestures
        KeyEvent ke = (KeyEvent)ie;
        int keyCode = ke.getKeyCode();
        int keyModifiers = ke.getModifiers();
        switch(keyCode) {
        case KeyEvent.VK_C:
        case KeyEvent.VK_V:
        case KeyEvent.VK_X:
            allowedGesture = (keyModifiers == InputEvent.CTRL_MASK);
            break;
        case KeyEvent.VK_INSERT:
            allowedGesture = (keyModifiers == InputEvent.CTRL_MASK ||
                              keyModifiers == InputEvent.SHIFT_MASK);
            break;
        case KeyEvent.VK_COPY:
        case KeyEvent.VK_PASTE:
        case KeyEvent.VK_CUT:
            allowedGesture = true;
            break;
        case KeyEvent.VK_DELETE:
            allowedGesture = ( keyModifiers == InputEvent.SHIFT_MASK);
            break;
        }
    }
    return allowedGesture;
}
 
Example 12
Source File: CustomerPanel.java    From Java-Simple-Hotel-Management with GNU General Public License v3.0 5 votes vote down vote up
private void tf_phoneKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_phoneKeyTyped
     char c = evt.getKeyChar();
    
    if(!(Character.isDigit(c) || c== KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE ))
    {
        evt.consume();
    }
}
 
Example 13
Source File: ProfilingPointsWindowUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void keyPressed(KeyEvent e) {
    if ((e.getKeyCode() == KeyEvent.VK_CONTEXT_MENU)
            || ((e.getKeyCode() == KeyEvent.VK_F10) && (e.getModifiers() == InputEvent.SHIFT_MASK))) {
        int[] selectedRows = profilingPointsTable.getSelectedRows();

        if (selectedRows.length != 0) {
            Rectangle rowBounds = profilingPointsTable.getCellRect(selectedRows[0], 1, true);
            showProfilingPointsPopup(e.getComponent(), rowBounds.x + 20,
                                     rowBounds.y + (profilingPointsTable.getRowHeight() / 2));
        }
    } else if (e.getKeyCode() == KeyEvent.VK_DELETE) {
        deletePPs();
    }
}
 
Example 14
Source File: MasterCli.java    From brModelo with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public void keyPressed(KeyEvent e) {
        if (isControlDown()) {
            if (processeAtalhos(e.getKeyCode())) {
                e.consume();
            }
        } else {
            switch (e.getKeyCode()) {
                case KeyEvent.VK_ENTER:
                    doEnter(palavra);
                    e.consume();
                    break;
                case KeyEvent.VK_UP:
                    posicioneHistorico(+1);
                    e.consume();
                    break;
                case KeyEvent.VK_DOWN:
                    posicioneHistorico(-1);
                    e.consume();
                    break;
                case KeyEvent.VK_LEFT:
                    movimenteCursor(-1);
                    e.consume();
                    break;
                case KeyEvent.VK_RIGHT:
                    movimenteCursor(+1);
                    e.consume();
                    break;
//                case KeyEvent.VK_TAB:
//                    break;
                case KeyEvent.VK_DELETE:
                    apagarLetra(posCursor);
                    e.consume();
                    break;
                case KeyEvent.VK_BACK_SPACE:
                    apagarLetra(posCursor - 1);
                    e.consume();
                    break;
            }
        }
        repaint();
    }
 
Example 15
Source File: InstantRenamePerformerTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testCancel5() throws Exception {
    KeyEvent ke = new KeyEvent(new JFrame(), KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_DELETE, '\0');
    performTest("package test; public class Test { public void test() {int x|xx = 0; int y = xxx; } }", 79 - 22, ke, "package test; public class Test { public void test() {intxxx = 0; int y = xxx; } }", false);
}
 
Example 16
Source File: GUILabelingTool.java    From Pixie with MIT License 4 votes vote down vote up
/**
 * Handling of the keyboard events.
 *
 * @param key the key code
 */
private void handleNormalKey(int key) {
    switch (key) {
        case KeyEvent.VK_LEFT:
            if (!jTFJumpFrame.isFocusOwner()) {
                getFrame(Constants.PREV_FRAME);
            }
            break;

        case KeyEvent.VK_RIGHT:
            if (!jTFJumpFrame.isFocusOwner()) {
                // get the next frame; save the data and load other data if there exists any
                getFrame(Constants.NEXT_FRAME);
            }
            break;

        case KeyEvent.VK_A:
            // move the crop to the left                            
            gc.moveSelection(-1, 0);
            break;

        case KeyEvent.VK_D:
            // move the crop to the right
            gc.moveSelection(1, 0);
            break;

        case KeyEvent.VK_W:
            // move the crop up
            gc.moveSelection(0, -1);
            break;

        case KeyEvent.VK_S:
            // move the crop down
            gc.moveSelection(0, 1);
            break;

        case KeyEvent.VK_DELETE:
            gc.removeSelection();
            break;

        case KeyEvent.VK_ESCAPE:
            cancelCurrentObject();
            break;

        default:
            // do nothing
            break;
    }
}
 
Example 17
Source File: Get2FACode.java    From megabasterd with GNU General Public License v3.0 4 votes vote down vote up
private void current_code_textfieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_current_code_textfieldKeyTyped

        if (current_code_textfield.getText().length() == MAX_CODE_LENGTH || (!Character.isDigit(evt.getKeyChar()) && evt.getKeyCode() != KeyEvent.VK_BACK_SPACE && evt.getKeyCode() != KeyEvent.VK_DELETE)) {
            evt.consume();
        }
    }
 
Example 18
Source File: ActiveBagContentPreviewPanel.java    From jclic with GNU General Public License v2.0 4 votes vote down vote up
public boolean processKey(KeyEvent e) {
  boolean consumed = false;
  if (cgrid >= 0 && grid[cgrid] != null && tgc[cgrid] != null) {
    int dx = 0, dy = 0;
    boolean delete = false, moveFirst = false;
    Point cur = grid[cgrid].getCursor();
    char ch1 = 0;

    switch (e.getID()) {
    case KeyEvent.KEY_PRESSED:
      switch (e.getKeyCode()) {
      case KeyEvent.VK_RIGHT:
        dx = 1;
        break;
      case KeyEvent.VK_LEFT:
        dx = -1;
        break;
      case KeyEvent.VK_DOWN:
        dy = 1;
        break;
      case KeyEvent.VK_UP:
        dy = -1;
        break;
      case KeyEvent.VK_BACK_SPACE:
        dx = -1;
        delete = true;
        moveFirst = true;
        break;
      case KeyEvent.VK_DELETE:
        delete = true;
        break;
      }
      break;

    case KeyEvent.KEY_TYPED:
      char ch0 = e.getKeyChar();
      int kk = e.getKeyCode();
      if (cur != null) {
        dx = 1;
        if (Character.isLetterOrDigit(ch0))
          ch1 = Character.toUpperCase(ch0);
        else if (ch0 == tgc[cgrid].wild || Character.isSpaceChar(ch0))
          delete = true;
        else
          dx = 0;
      }
      break;
    }
    if (moveFirst && (dx != 0 || dy != 0)) {
      moveCursor(dx, dy);
      cur = grid[cgrid].getCursor();
      consumed = true;
    }
    if (delete)
      ch1 = tgc[cgrid].wild;
    if (ch1 != 0 && cur != null) {
      if (crossWord) {
        checkWildChanges(cur, ch1);
      }
      grid[cgrid].setCharAt(cur.x, cur.y, ch1);
      tgc[cgrid].setCharAt(cur.x, cur.y, ch1);
      setModified(true);
      consumed = true;
    }
    if (!moveFirst && (dx != 0 || dy != 0)) {
      moveCursor(dx, dy);
      consumed = true;
    }
  }
  return consumed;
}
 
Example 19
Source File: VncClientPacketSender.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
private int mapAwtKeyToVncKey(int key) {
    switch (key) {
        case KeyEvent.VK_BACK_SPACE:
            return 0xff08;
        case KeyEvent.VK_TAB:
            return 0xff09;
        case KeyEvent.VK_ENTER:
            return 0xff0d;
        case KeyEvent.VK_ESCAPE:
            return 0xff1b;
        case KeyEvent.VK_INSERT:
            return 0xff63;
        case KeyEvent.VK_DELETE:
            return 0xffff;
        case KeyEvent.VK_HOME:
            return 0xff50;
        case KeyEvent.VK_END:
            return 0xff57;
        case KeyEvent.VK_PAGE_UP:
            return 0xff55;
        case KeyEvent.VK_PAGE_DOWN:
            return 0xff56;
        case KeyEvent.VK_LEFT:
            return 0xff51;
        case KeyEvent.VK_UP:
            return 0xff52;
        case KeyEvent.VK_RIGHT:
            return 0xff53;
        case KeyEvent.VK_DOWN:
            return 0xff54;
        case KeyEvent.VK_F1:
            return 0xffbe;
        case KeyEvent.VK_F2:
            return 0xffbf;
        case KeyEvent.VK_F3:
            return 0xffc0;
        case KeyEvent.VK_F4:
            return 0xffc1;
        case KeyEvent.VK_F5:
            return 0xffc2;
        case KeyEvent.VK_F6:
            return 0xffc3;
        case KeyEvent.VK_F7:
            return 0xffc4;
        case KeyEvent.VK_F8:
            return 0xffc5;
        case KeyEvent.VK_F9:
            return 0xffc6;
        case KeyEvent.VK_F10:
            return 0xffc7;
        case KeyEvent.VK_F11:
            return 0xffc8;
        case KeyEvent.VK_F12:
            return 0xffc9;
        case KeyEvent.VK_SHIFT:
            return 0xffe1;
        case KeyEvent.VK_CONTROL:
            return 0xffe3;
        case KeyEvent.VK_META:
            return 0xffe7;
        case KeyEvent.VK_ALT:
            return 0xffe9;
        case KeyEvent.VK_ALT_GRAPH:
            return 0xffea;
        case KeyEvent.VK_BACK_QUOTE:
            return 0x0060;
    }

    return key;
}
 
Example 20
Source File: StaffApplication.java    From RemoteSupportTool with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("Duplicates")
protected synchronized void doHandleKeyPress(KeyEvent e) {
    if (handler == null) return;
    //LOGGER.debug("key pressed: " + e.paramString());

    // Get code of the pressed key.
    // Keypad arrows are translated to regular arrow keys.
    final int keyCode;
    switch (e.getKeyCode()) {
        case KeyEvent.VK_KP_DOWN:
            keyCode = KeyEvent.VK_DOWN;
            break;
        case KeyEvent.VK_KP_LEFT:
            keyCode = KeyEvent.VK_LEFT;
            break;
        case KeyEvent.VK_KP_RIGHT:
            keyCode = KeyEvent.VK_RIGHT;
            break;
        case KeyEvent.VK_KP_UP:
            keyCode = KeyEvent.VK_UP;
            break;
        default:
            keyCode = e.getKeyCode();
            break;
    }

    // Never press undefined key codes.
    if (keyCode == KeyEvent.VK_UNDEFINED) {
        return;
    }

    // Never send caps lock, num lock and scroll lock key.
    if (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK || keyCode == KeyEvent.VK_SCROLL_LOCK) {
        return;
    }

    // Detect, if a control key was pressed.
    final boolean isControlKey = e.isActionKey() ||
            keyCode == KeyEvent.VK_BACK_SPACE ||
            keyCode == KeyEvent.VK_DELETE ||
            keyCode == KeyEvent.VK_ENTER ||
            keyCode == KeyEvent.VK_SPACE ||
            keyCode == KeyEvent.VK_TAB ||
            keyCode == KeyEvent.VK_ESCAPE ||
            keyCode == KeyEvent.VK_ALT ||
            keyCode == KeyEvent.VK_ALT_GRAPH ||
            keyCode == KeyEvent.VK_CONTROL ||
            keyCode == KeyEvent.VK_SHIFT ||
            keyCode == KeyEvent.VK_META;

    // Press control keys.
    if (isControlKey) {
        //LOGGER.debug("press key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode));
        handler.sendKeyPress(keyCode);
        e.consume();
    }

    // Press other keys, if they are pressed together with a modifier key.
    else if (e.isControlDown() || e.isMetaDown() || windowsKeyDown || (!SystemUtils.IS_OS_MAC && e.isAltDown())) {
        //LOGGER.debug("press key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode));
        handler.sendKeyPress(keyCode);
        if (!pressedKeys.contains(keyCode))
            pressedKeys.add(keyCode);
        e.consume();
    }

    // Remember, that the Windows key was pressed.
    if (keyCode == KeyEvent.VK_WINDOWS) {
        synchronized (Frame.this) {
            windowsKeyDown = true;
        }
    }
}