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

The following examples show how to use java.awt.event.KeyEvent#VK_END . 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: JPanel_FileBrowser.java    From MobyDroid with Apache License 2.0 6 votes vote down vote up
private void jTable_BrowserKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable_BrowserKeyReleased
    switch (evt.getKeyCode()) {
        case KeyEvent.VK_ENTER:
            //if(currentFile.type.equalsIgnoreCase("desktop") || currentFile.type.equalsIgnoreCase("computer") || currentFile.type.equalsIgnoreCase("hdd") || currentFile.type.equalsIgnoreCase("fdd") || currentFile.type.equalsIgnoreCase("cd") || currentFile.type.equalsIgnoreCase("home") || currentFile.type.equalsIgnoreCase("dir")){
            //    getChildren();
            //}
            int row = jTable_Browser.getSelectedRow();
            MyFile file = fileTableModel.getFile(jTable_Browser.convertRowIndexToModel(row));
            if (file.isDirectory()) {
                updateFilesList(file.getPath());
            }
            break;
        case KeyEvent.VK_BACK_SPACE:
            goUpHandle();
            break;
        case KeyEvent.VK_HOME:
            jTable_Browser.changeSelection(0, 0, false, false);
            break;
        case KeyEvent.VK_END:
            jTable_Browser.changeSelection(jTable_Browser.getRowCount() - 1, 0, false, false);
            break;
        default:
            break;
    }
}
 
Example 2
Source File: TreePanel.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent event) {
    if (!event.isConsumed() && (event.getModifiersEx() & getToolkit().getMenuShortcutKeyMaskEx()) == 0) {
        switch (event.getKeyCode()) {
        case KeyEvent.VK_LEFT:
            setOpen(false, getTreeContainerRows(mSelectedRows, event.isAltDown()));
            break;
        case KeyEvent.VK_RIGHT:
            setOpen(true, getTreeContainerRows(mSelectedRows, event.isAltDown()));
            break;
        case KeyEvent.VK_UP:
            keyScroll(selectUp(event.isShiftDown()));
            break;
        case KeyEvent.VK_DOWN:
            keyScroll(selectDown(event.isShiftDown()));
            break;
        case KeyEvent.VK_HOME:
            keyScroll(selectToHome(event.isShiftDown()));
            break;
        case KeyEvent.VK_END:
            keyScroll(selectToEnd(event.isShiftDown()));
            break;
        default:
            return;
        }
        event.consume();
    }
}
 
Example 3
Source File: ShortcutOptionsPanel.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * Action triggered when keyboard is used.
 * 
 * @param e Event.
 * @return True if processing should end.
 * @see java.awt.KeyEventDispatcher#dispatchKeyEvent(java.awt.event.KeyEvent)
 */
@Override
public boolean dispatchKeyEvent(KeyEvent e) {
  int key = e.getKeyCode();
  if ((key == KeyEvent.VK_ALT) ||
      (key == KeyEvent.VK_ALT_GRAPH) ||
      (key == KeyEvent.VK_BACK_SPACE) ||
      (key == KeyEvent.VK_BEGIN) ||
      (key == KeyEvent.VK_CANCEL) ||
      (key == KeyEvent.VK_CAPS_LOCK) ||
      (key == KeyEvent.VK_CONTROL) ||
      (key == KeyEvent.VK_DELETE) ||
      (key == KeyEvent.VK_DOWN) ||
      (key == KeyEvent.VK_END) ||
      (key == KeyEvent.VK_ENTER) ||
      (key == KeyEvent.VK_LEFT) ||
      (key == KeyEvent.VK_PAGE_DOWN) ||
      (key == KeyEvent.VK_PAGE_UP) ||
      (key == KeyEvent.VK_RIGHT) ||
      (key == KeyEvent.VK_SHIFT) ||
      (key == KeyEvent.VK_TAB) ||
      (key == KeyEvent.VK_UP) ||
      (key == KeyEvent.VK_SHIFT)) {
    return false;
  }
  if (key != KeyEvent.VK_ESCAPE) {
    setKeyCode(key);
  }
  showNotice(false);
  KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(this);
  return false;
}
 
Example 4
Source File: JRViewer.java    From nordpos with GNU General Public License v3.0 5 votes vote down vote up
protected void keyNavigate(KeyEvent evt)
{
	boolean refresh = true;
	switch (evt.getKeyCode())
	{
	case KeyEvent.VK_DOWN:
	case KeyEvent.VK_PAGE_DOWN:
		dnNavigate(evt);
		break;
	case KeyEvent.VK_UP:
	case KeyEvent.VK_PAGE_UP:
		upNavigate(evt);
		break;
	case KeyEvent.VK_HOME:
		homeEndNavigate(0);
		break;
	case KeyEvent.VK_END:
		homeEndNavigate(jasperPrint.getPages().size() - 1);
		break;
	default:
		refresh = false;
	}
	
	if (refresh)
	{
		refreshPage();
	}
}
 
Example 5
Source File: TypeInstanceTableDatamodel.java    From binnavi with Apache License 2.0 5 votes vote down vote up
@Override
public void keyPressedOrTyped(CodeDisplayCoordinate coordinate, KeyEvent event) {
  if (!isEditable(coordinate)) {
    return;
  }
  // Deal with key events in the name or comments fields. These have to be handled differently.

  if (coordinate.getColumn() == COMMENTS_INDEX) {
  } else if (coordinate.getColumn() == NAME_INDEX) {
    if (coordinate.getLine() != 0) {
      // There are no multi-line names, so just bare essential keys are supported here.
      switch (event.getKeyCode()) {
        case 0:
        case KeyEvent.VK_HOME:
          coordinate.setFieldIndex(0);
          break;
        case KeyEvent.VK_END:
          coordinate.setFieldIndex(columns[coordinate.getColumn()].getWidth() - 1);
          break;
        default:
          // No special handling in the default case.
          break;
      }
    } else {
      // In the first line, the name can be changed. Allow this to occur if the caret is next
      // to an existing letter of the name.
      // TODO(thomasdullien): Implement.
    }
  }
}
 
Example 6
Source File: JRViewerPanel.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void keyNavigate(KeyEvent evt)
{
	boolean refresh = true;
	switch (evt.getKeyCode())
	{
	case KeyEvent.VK_DOWN:
	case KeyEvent.VK_PAGE_DOWN:
		dnNavigate(evt);
		break;
	case KeyEvent.VK_UP:
	case KeyEvent.VK_PAGE_UP:
		upNavigate(evt);
		break;
	case KeyEvent.VK_HOME:
		homeEndNavigate(0);
		break;
	case KeyEvent.VK_END:
		homeEndNavigate(viewerContext.getPageCount() - 1);
		break;
	default:
		refresh = false;
	}
	
	if (refresh)
	{
		viewerContext.refreshPage();
	}
}
 
Example 7
Source File: IPV4Field.java    From lippen-network-tool with Apache License 2.0 5 votes vote down vote up
public void keyPressed(KeyEvent e) {
    JTextComponent field = (JTextComponent) e.getComponent();
    int keyCode = e.getKeyCode();
    char keyChar = e.getKeyChar();
    String text = field.getText();
    String selText = field.getSelectedText();
    int caretPos = field.getCaretPosition();
    int textLength = text.length();
    if ((keyCode == KeyEvent.VK_LEFT) && (caretPos == 0)
            && (selText == null)) {
        field.firePropertyChange("Left", 0, 1);
    } else if (((keyCode == KeyEvent.VK_RIGHT)
            && (caretPos == textLength) && (selText == null))
            || ((keyChar == '.') && (!text.isEmpty()) && (selText == null))) {
        field.firePropertyChange("Right", 0, 1);
    } else if ((keyCode == KeyEvent.VK_BACK_SPACE) && (caretPos == 0)
            && (selText == null)) {
        field.firePropertyChange("BackSpace", 0, 1);
    } else if ((keyCode == KeyEvent.VK_DELETE)
            && (caretPos == textLength) && (selText == null)) {
        field.firePropertyChange("Delete", 0, 1);
    } else if (keyCode == KeyEvent.VK_HOME) {
        IPV4Field.this.ipFields[0].unSelectAllWhenFocusGained();
        IPV4Field.this.ipFields[0].requestFocus();
        IPV4Field.this.ipFields[0].setCaretPosition(0);
    } else if (keyCode == KeyEvent.VK_END) {
        int last = IPV4Field.this.ipFields.length - 1;
        textLength = IPV4Field.this.ipFields[last].getText()
                .length();
        IPV4Field.this.ipFields[last]
                .unSelectAllWhenFocusGained();
        IPV4Field.this.ipFields[last].requestFocus();
        IPV4Field.this.ipFields[last]
                .setCaretPosition(textLength);
    } else if ((keyCode == KeyEvent.VK_0 || keyCode == KeyEvent.VK_NUMPAD0) && (caretPos == 0 || (text != null && text.equals(selText)))) {
        field.firePropertyChange("Right", 0, 1);
    } else if (("0123456789".indexOf(keyChar) >= 0)) {
        if (selText == null) {
            int ipInt = (text.length() == 0 ? 0 : Integer
                    .parseInt(text));

            if (ipInt > 25) {
                field.firePropertyChange("Right", 0, 1);
            }
        } else {
            if (field.getSelectionStart() == 2
                    && field.getSelectionEnd() == 3) {
                field.firePropertyChange("Right", 0, 1);
            }
        }
    }
}
 
Example 8
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 9
Source File: SwingTextKeyboardDriver.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public NavigationKey[] getKeys(ComponentOperator oper) {
    boolean multiString
            = oper instanceof JTextAreaOperator
            || oper instanceof JEditorPaneOperator;
    NavigationKey[] result = new NavigationKey[multiString ? 8 : 4];
    result[0] = new UpKey(KeyEvent.VK_LEFT, 0);
    result[1] = new DownKey(KeyEvent.VK_RIGHT, 0);
    ((UpKey) result[0]).setDownKey((DownKey) result[1]);
    ((DownKey) result[1]).setUpKey((UpKey) result[0]);
    if (multiString) {
        result[2] = new UpKey(KeyEvent.VK_UP, 0);
        result[3] = new DownKey(KeyEvent.VK_DOWN, 0);
        ((UpKey) result[2]).setDownKey((DownKey) result[3]);
        ((DownKey) result[3]).setUpKey((UpKey) result[2]);
        result[4] = new UpKey(KeyEvent.VK_PAGE_UP, 0);
        result[5] = new DownKey(KeyEvent.VK_PAGE_DOWN, 0);
        ((UpKey) result[4]).setDownKey((DownKey) result[5]);
        ((DownKey) result[5]).setUpKey((UpKey) result[4]);
        result[6] = new HomeKey(KeyEvent.VK_HOME, InputEvent.CTRL_MASK);
        result[7] = new EndKey(KeyEvent.VK_END, InputEvent.CTRL_MASK, this, oper);
    } else {
        result[2] = new HomeKey(KeyEvent.VK_HOME, 0);
        result[3] = new EndKey(KeyEvent.VK_END, 0, this, oper);
    }
    return result;
}
 
Example 10
Source File: TableTabCaret.java    From Logisim with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
	if (cursorRow < 0)
		return;
	TruthTable model = table.getTruthTable();
	int rows = model.getRowCount();
	int inputs = model.getInputColumnCount();
	int outputs = model.getOutputColumnCount();
	int cols = inputs + outputs;
	boolean shift = (e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0;
	switch (e.getKeyCode()) {
	case KeyEvent.VK_UP:
		setCursor(cursorRow - 1, cursorCol, shift);
		break;
	case KeyEvent.VK_LEFT:
		setCursor(cursorRow, cursorCol - 1, shift);
		break;
	case KeyEvent.VK_DOWN:
		setCursor(cursorRow + 1, cursorCol, shift);
		break;
	case KeyEvent.VK_RIGHT:
		setCursor(cursorRow, cursorCol + 1, shift);
		break;
	case KeyEvent.VK_HOME:
		if (cursorCol == 0)
			setCursor(0, 0, shift);
		else
			setCursor(cursorRow, 0, shift);
		break;
	case KeyEvent.VK_END:
		if (cursorCol == cols - 1)
			setCursor(rows - 1, cols - 1, shift);
		else
			setCursor(cursorRow, cols - 1, shift);
		break;
	case KeyEvent.VK_PAGE_DOWN:
		rows = table.getVisibleRect().height / table.getCellHeight();
		if (rows > 2)
			rows--;
		setCursor(cursorRow + rows, cursorCol, shift);
		break;
	case KeyEvent.VK_PAGE_UP:
		rows = table.getVisibleRect().height / table.getCellHeight();
		if (rows > 2)
			rows--;
		setCursor(cursorRow - rows, cursorCol, shift);
		break;
	}
}
 
Example 11
Source File: DQ.java    From javagame with MIT License 4 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyPressed(KeyEvent e) {
    int keyCode = e.getKeyCode();

    // �I������
    if (keyCode == KeyEvent.VK_ESCAPE || keyCode == KeyEvent.VK_Q ||
            keyCode == KeyEvent.VK_END ||
            (keyCode == KeyEvent.VK_C && e.isControlDown())) {
        running = false;
    }

    if (keyCode == KeyEvent.VK_LEFT) {
        if (commandWindow.isVisible()) {
            cmdLeftKey.press();
        } else {
            leftKey.press();
        }
    }
    if (keyCode == KeyEvent.VK_RIGHT) {
        if (commandWindow.isVisible()) {
            cmdRightKey.press();
        } else {
            rightKey.press();
        }
    }
    if (keyCode == KeyEvent.VK_UP) {
        if (commandWindow.isVisible()) {
            cmdUpKey.press();
        } else {
            upKey.press();
        }
    }
    if (keyCode == KeyEvent.VK_DOWN) {
        if (commandWindow.isVisible()) {
            cmdDownKey.press();
        } else {
            downKey.press();
        }
    }
    if (keyCode == KeyEvent.VK_SPACE) {
        spaceKey.press();
    }
}
 
Example 12
Source File: Caret.java    From Logisim with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
	int cols = hex.getMeasures().getColumnCount();
	int rows;
	boolean shift = (e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0;
	switch (e.getKeyCode()) {
	case KeyEvent.VK_UP:
		if (cursor >= cols)
			setDot(cursor - cols, shift);
		break;
	case KeyEvent.VK_LEFT:
		if (cursor >= 1)
			setDot(cursor - 1, shift);
		break;
	case KeyEvent.VK_DOWN:
		if (cursor >= hex.getModel().getFirstOffset() && cursor <= hex.getModel().getLastOffset() - cols) {
			setDot(cursor + cols, shift);
		}
		break;
	case KeyEvent.VK_RIGHT:
		if (cursor >= hex.getModel().getFirstOffset() && cursor <= hex.getModel().getLastOffset() - 1) {
			setDot(cursor + 1, shift);
		}
		break;
	case KeyEvent.VK_HOME:
		if (cursor >= 0) {
			int dist = (int) (cursor % cols);
			if (dist == 0)
				setDot(0, shift);
			else
				setDot(cursor - dist, shift);
			break;
		}
	case KeyEvent.VK_END:
		if (cursor >= 0) {
			HexModel model = hex.getModel();
			long dest = (cursor / cols * cols) + cols - 1;
			if (model != null) {
				long end = model.getLastOffset();
				if (dest > end || dest == cursor)
					dest = end;
				setDot(dest, shift);
			} else {
				setDot(dest, shift);
			}
		}
		break;
	case KeyEvent.VK_PAGE_DOWN:
		rows = hex.getVisibleRect().height / hex.getMeasures().getCellHeight();
		if (rows > 2)
			rows--;
		if (cursor >= 0) {
			long max = hex.getModel().getLastOffset();
			if (cursor + rows * cols <= max) {
				setDot(cursor + rows * cols, shift);
			} else {
				long n = cursor;
				while (n + cols < max)
					n += cols;
				setDot(n, shift);
			}
		}
		break;
	case KeyEvent.VK_PAGE_UP:
		rows = hex.getVisibleRect().height / hex.getMeasures().getCellHeight();
		if (rows > 2)
			rows--;
		if (cursor >= rows * cols)
			setDot(cursor - rows * cols, shift);
		else if (cursor >= cols)
			setDot(cursor % cols, shift);
		break;
	}
}
 
Example 13
Source File: ActionUtils.java    From workcraft with MIT License 4 votes vote down vote up
public static String getKeyString(int keyCode) {
    // Letters and numbers
    if (((keyCode >= KeyEvent.VK_0) && (keyCode <= KeyEvent.VK_9))
            || ((keyCode >= KeyEvent.VK_A) && (keyCode <= KeyEvent.VK_Z))) {
        return String.valueOf((char) keyCode);
    }
    switch (keyCode) {
    // Navigation keys
    case KeyEvent.VK_LEFT: return "Left";
    case KeyEvent.VK_UP: return "Up";
    case KeyEvent.VK_RIGHT: return "Right";
    case KeyEvent.VK_DOWN: return "Down";
    // Extra navigation keys
    case KeyEvent.VK_INSERT: return "Insert";
    case KeyEvent.VK_DELETE: return "Delete";
    case KeyEvent.VK_END: return "End";
    case KeyEvent.VK_HOME: return "Home";
    case KeyEvent.VK_PAGE_UP: return "PgUp";
    case KeyEvent.VK_PAGE_DOWN: return "PgDn";
    // Function keys
    case KeyEvent.VK_F1: return "F1";
    case KeyEvent.VK_F2: return "F2";
    case KeyEvent.VK_F3: return "F3";
    case KeyEvent.VK_F4: return "F4";
    case KeyEvent.VK_F5: return "F5";
    case KeyEvent.VK_F6: return "F6";
    case KeyEvent.VK_F7: return "F7";
    case KeyEvent.VK_F8: return "F8";
    case KeyEvent.VK_F9: return "F9";
    case KeyEvent.VK_F10: return "F10";
    case KeyEvent.VK_F11: return "F11";
    case KeyEvent.VK_F12: return "F12";
    // Symbols
    case KeyEvent.VK_EXCLAMATION_MARK: return "!";
    case KeyEvent.VK_QUOTEDBL: return "\"";
    case KeyEvent.VK_EURO_SIGN: return "€";
    case KeyEvent.VK_DOLLAR: return "$";
    case KeyEvent.VK_CIRCUMFLEX: return "^";
    case KeyEvent.VK_AMPERSAND: return "&";
    case KeyEvent.VK_ASTERISK: return "*";
    case KeyEvent.VK_UNDERSCORE: return "_";
    case KeyEvent.VK_MINUS: return "-";
    case KeyEvent.VK_PLUS: return "+";
    case KeyEvent.VK_EQUALS: return "=";
    case KeyEvent.VK_AT: return "@";
    case KeyEvent.VK_NUMBER_SIGN: return "#";
    case KeyEvent.VK_COLON: return ":";
    case KeyEvent.VK_SEMICOLON: return ";";
    case KeyEvent.VK_COMMA: return ",";
    case KeyEvent.VK_PERIOD: return ".";
    case KeyEvent.VK_SLASH: return "/";
    case KeyEvent.VK_BACK_SLASH: return "\\";
    case KeyEvent.VK_DEAD_TILDE: return "~";
    // Parenthesis and brackets
    case KeyEvent.VK_LEFT_PARENTHESIS: return "(";
    case KeyEvent.VK_RIGHT_PARENTHESIS: return ")";
    case KeyEvent.VK_OPEN_BRACKET: return "[";
    case KeyEvent.VK_CLOSE_BRACKET: return "]";
    case KeyEvent.VK_BRACELEFT: return "{";
    case KeyEvent.VK_BRACERIGHT: return "}";
    case KeyEvent.VK_LESS: return "<";
    case KeyEvent.VK_GREATER: return ">";
    // Formatting keys
    case KeyEvent.VK_SPACE: return "Space";
    case KeyEvent.VK_TAB: return "Tab";
    case KeyEvent.VK_ENTER: return "Enter";
    case KeyEvent.VK_BACK_SPACE: return "Backspace";
    case KeyEvent.VK_ESCAPE: return "Esc";
    }
    return "0x" + Integer.toString(keyCode, 16);
}
 
Example 14
Source File: VncClientPacketSender.java    From cosmic with Apache License 2.0 4 votes vote down vote up
private int mapAwtKeyToVncKey(final 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 15
Source File: ReflectCompletionDialog.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
private void jTxtItemKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxtItemKeyPressed

		int i = jLstItems.getSelectedIndex();
		switch (evt.getKeyCode()) {
			case KeyEvent.VK_ESCAPE:
				target.setCaretPosition(target.getSelectionEnd());
				setVisible(false);
				return;
			case KeyEvent.VK_DOWN:
				i++;
				break;
			case KeyEvent.VK_UP:
				i--;
				break;
			case KeyEvent.VK_HOME:
				i = 0;
				break;
			case KeyEvent.VK_END:
				i = jLstItems.getModel().getSize() - 1;
				break;
			case KeyEvent.VK_PAGE_DOWN:
				i += jLstItems.getVisibleRowCount();
				break;
			case KeyEvent.VK_PAGE_UP:
				i -= jLstItems.getVisibleRowCount();
				break;
		}

		if (escapeChars.indexOf(evt.getKeyChar()) >= 0) {
			String result = getSelection();
			char pressed = evt.getKeyChar();
			// we need to just accept ENTER, and replace the tab with a single
			// space
			if (pressed != '\n') {
				result += (pressed == '\t') ? ' ' : pressed;
			}
			target.replaceSelection(result);
			setVisible(false);
		} else {
			// perform bounds checks for i
			if (i >= jLstItems.getModel().getSize()) {
				i = jLstItems.getModel().getSize() - 1;
			}
			if (i < 0) {
				i = 0;
			}
			jLstItems.setSelectedIndex(i);
			jLstItems.ensureIndexIsVisible(i);
		}
    }
 
Example 16
Source File: MacKeymapUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static String getKeyText(int code) {
  switch (code) {
    case KeyEvent.VK_BACK_SPACE:     return BACKSPACE;
    case KeyEvent.VK_ESCAPE:         return ESCAPE;
    case KeyEvent.VK_CAPS_LOCK:      return CAPS_LOCK;
    case KeyEvent.VK_TAB:            return TAB;
    case KeyEvent.VK_SPACE:          return SPACE;
    case KeyEvent.VK_DELETE:         return DELETE;
    case KeyEvent.VK_HOME:           return HOME;
    case KeyEvent.VK_END:            return END;
    case KeyEvent.VK_PAGE_UP:        return PAGE_UP;
    case KeyEvent.VK_PAGE_DOWN:      return PAGE_DOWN;
    case KeyEvent.VK_UP:             return UP;
    case KeyEvent.VK_DOWN:           return DOWN;
    case KeyEvent.VK_LEFT:           return LEFT;
    case KeyEvent.VK_RIGHT:          return RIGHT;
    case KeyEvent.VK_NUM_LOCK:       return NUMBER_LOCK;
    case KeyEvent.VK_ENTER:          return RETURN;
    case KeyEvent.VK_BACK_QUOTE:     return "`";
    case KeyEvent.VK_NUMBER_SIGN:    return NUM_PAD;
    case KeyEvent.VK_MULTIPLY:       return NUM_PAD + " *";
    case KeyEvent.VK_ADD:            return "+";
    case KeyEvent.VK_SEPARATOR:      return ",";
    case KeyEvent.VK_SUBTRACT:       return "-";
    case KeyEvent.VK_DECIMAL:        return ".";
    case KeyEvent.VK_DIVIDE:         return "/";
    case KeyEvent.VK_NUMPAD0:        return "0";
    case KeyEvent.VK_NUMPAD1:        return "1";
    case KeyEvent.VK_NUMPAD2:        return "2";
    case KeyEvent.VK_NUMPAD3:        return "3";
    case KeyEvent.VK_NUMPAD4:        return "4";
    case KeyEvent.VK_NUMPAD5:        return "5";
    case KeyEvent.VK_NUMPAD6:        return "6";
    case KeyEvent.VK_NUMPAD7:        return "7";
    case KeyEvent.VK_NUMPAD8:        return "8";
    case KeyEvent.VK_NUMPAD9:        return "9";
    case KeyEvent.VK_SLASH:          return "/";
    case KeyEvent.VK_BACK_SLASH:     return "\\";
    case KeyEvent.VK_PERIOD:         return ".";
    case KeyEvent.VK_SEMICOLON:      return ";";
    case KeyEvent.VK_CLOSE_BRACKET:  return "]";
    case KeyEvent.VK_OPEN_BRACKET:   return "[";
    case KeyEvent.VK_EQUALS:         return "=";
    case KeyEvent.VK_MINUS:          return "-";
    case KeyEvent.VK_PLUS:           return "+";
    case 0:                          return "fn";
  }
  return KeyEvent.getKeyText(code);
}
 
Example 17
Source File: ItemPanelKeyboardListener.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
	if (this.pane == null) {
		if (e.getSource() instanceof ItemPanel) {
			this.pane = ((ItemPanel) e.getSource());
		} else if (e.getSource() instanceof Item) {
			this.pane = ((ItemPanel) ((JComponent) e.getSource()).getParent());
		}
	}

	if (e.getKeyCode() == KeyEvent.VK_DELETE) {
	} else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
		if ((this.pane != null) && (this.pane.getFilePane().lastSelected != null)) {
			this.pane.getFilePane().filechooserUI.setCurrentDirectoryOfFileChooser(this.pane.getFilePane().lastSelected
					.getFile());
		}
	} else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
		this.pane.useKeyMoves("SPACE", e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK);
	} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
		this.pane.useKeyMoves("RIGHT", e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK);
	} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
		this.pane.useKeyMoves("LEFT", e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK);
	} else if (e.getKeyCode() == KeyEvent.VK_UP) {
		this.pane.useKeyMoves("UP", e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK);
	} else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
		this.pane.useKeyMoves("DOWN", e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK);
	} else if (e.getKeyCode() == KeyEvent.VK_HOME) {
		this.pane.useKeyMoves("HOME", e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK);
	} else if (e.getKeyCode() == KeyEvent.VK_END) {
		this.pane.useKeyMoves("END", e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK);
	} else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
		// ignore enter here!
	} else if (e.getKeyCode() == KeyEvent.VK_PAGE_UP) {
		this.pane.useKeyMoves("PAGE_UP", e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK);
	} else if (e.getKeyCode() == KeyEvent.VK_PAGE_DOWN) {
		this.pane.useKeyMoves("PAGE_DOWN", e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK);
	} else {
		if (KeyEvent.getKeyText(e.getKeyCode()).toLowerCase().equals("a")
				&& (e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK)) {
			this.pane.getFilePane().selectAll();
		}
		if (e.getModifiersEx() == 0) {
			this.pane.forwardToNearestFor(String.valueOf(e.getKeyChar()).toLowerCase());
		}
	}
}
 
Example 18
Source File: MethodChooser.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    int code = e.getKeyCode();
    boolean consumeEvent = true;
    switch (code) {
        case KeyEvent.VK_ENTER:
        case KeyEvent.VK_SPACE:
            // selection confirmed
            releaseUI(true);
            break;
        case KeyEvent.VK_ESCAPE:
            // action canceled
            releaseUI(false);
            break;
        case KeyEvent.VK_RIGHT:
        case KeyEvent.VK_DOWN:
        case KeyEvent.VK_TAB:
            selectedIndex++;
            if (selectedIndex == segments.length) {
                selectedIndex = 0;
            }
            requestRepaint();
            break;
        case KeyEvent.VK_LEFT:
        case KeyEvent.VK_UP:
            selectedIndex--;
            if (selectedIndex < 0) {
                selectedIndex = segments.length - 1;
            }
            requestRepaint();
            break;
        case KeyEvent.VK_HOME:
            selectedIndex = 0;
            requestRepaint();
            break;
        case KeyEvent.VK_END:
            selectedIndex = segments.length - 1;
            requestRepaint();
            break;
        default:
            int mods = e.getModifiersEx();
            for (int x = 0; x < stopEvents.length; x++) {
                if (stopEvents[x].getKeyCode() == code &&
                        (stopEvents[x].getModifiers() & mods) == stopEvents[x].getModifiers()) {
                    releaseUI(false);
                    consumeEvent = false;
                    break;
                }
            }
            for (int x = 0; x < confirmEvents.length; x++) {
                if (confirmEvents[x].getKeyCode() == code &&
                        (confirmEvents[x].getModifiers() & mods) == confirmEvents[x].getModifiers()) {
                    releaseUI(true);
                    break;
                }
            }
    }
    if (consumeEvent) {
        e.consume();
    }
}
 
Example 19
Source File: OSUtils.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public static String keyEventGetKeyText(int keycode) {
    if (keycode == KeyEvent.VK_TAB) {
        return "Tab";
    }
    if (keycode == KeyEvent.VK_CONTROL) {
        return "Ctrl";
    }
    if (keycode == KeyEvent.VK_ALT) {
        return "Alt";
    }
    if (keycode == KeyEvent.VK_SHIFT) {
        return "Shift";
    }
    if (keycode == KeyEvent.VK_META) {
        return "Meta";
    }
    if (keycode == KeyEvent.VK_SPACE) {
        return "Space";
    }
    if (keycode == KeyEvent.VK_BACK_SPACE) {
        return "Backspace";
    }
    if (keycode == KeyEvent.VK_HOME) {
        return "Home";
    }
    if (keycode == KeyEvent.VK_END) {
        return "End";
    }
    if (keycode == KeyEvent.VK_DELETE) {
        return "Delete";
    }
    if (keycode == KeyEvent.VK_PAGE_UP) {
        return "Pageup";
    }
    if (keycode == KeyEvent.VK_PAGE_DOWN) {
        return "Pagedown";
    }
    if (keycode == KeyEvent.VK_UP) {
        return "Up";
    }
    if (keycode == KeyEvent.VK_DOWN) {
        return "Down";
    }
    if (keycode == KeyEvent.VK_LEFT) {
        return "Left";
    }
    if (keycode == KeyEvent.VK_RIGHT) {
        return "Right";
    }
    if (keycode == KeyEvent.VK_ENTER) {
        return "Enter";
    }
    return KeyEvent.getKeyText(keycode);
}
 
Example 20
Source File: JavaRecorderHook.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public static String keyEventGetKeyText(int keycode) {
    if (keycode == KeyEvent.VK_TAB) {
        return "Tab";
    }
    if (keycode == KeyEvent.VK_CONTROL) {
        return "Ctrl";
    }
    if (keycode == KeyEvent.VK_ALT) {
        return "Alt";
    }
    if (keycode == KeyEvent.VK_SHIFT) {
        return "Shift";
    }
    if (keycode == KeyEvent.VK_META) {
        return "Meta";
    }
    if (keycode == KeyEvent.VK_SPACE) {
        return "Space";
    }
    if (keycode == KeyEvent.VK_BACK_SPACE) {
        return "Backspace";
    }
    if (keycode == KeyEvent.VK_HOME) {
        return "Home";
    }
    if (keycode == KeyEvent.VK_END) {
        return "End";
    }
    if (keycode == KeyEvent.VK_DELETE) {
        return "Delete";
    }
    if (keycode == KeyEvent.VK_PAGE_UP) {
        return "Pageup";
    }
    if (keycode == KeyEvent.VK_PAGE_DOWN) {
        return "Pagedown";
    }
    if (keycode == KeyEvent.VK_UP) {
        return "Up";
    }
    if (keycode == KeyEvent.VK_DOWN) {
        return "Down";
    }
    if (keycode == KeyEvent.VK_LEFT) {
        return "Left";
    }
    if (keycode == KeyEvent.VK_RIGHT) {
        return "Right";
    }
    if (keycode == KeyEvent.VK_ENTER) {
        return "Enter";
    }
    return KeyEvent.getKeyText(keycode);
}