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

The following examples show how to use java.awt.event.KeyEvent#VK_PERIOD . 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: NewEntryFrameUtil.java    From Zettelkasten with GNU General Public License v3.0 6 votes vote down vote up
public static void checkSpelling(int key, javax.swing.JTextArea ta, Settings settingsObj, AutoKorrektur spellObj) {
    if (KeyEvent.VK_SPACE == key || KeyEvent.VK_PERIOD == key || KeyEvent.VK_COMMA == key || KeyEvent.VK_BRACELEFT == key || KeyEvent.VK_ENTER == key || KeyEvent.VK_OPEN_BRACKET == key || KeyEvent.VK_COLON == key || KeyEvent.VK_QUOTE == key) {
        if (ta != null) {
            try {
                int caret = ta.getCaretPosition();
                String text = ta.getText();
                if (settingsObj.getSpellCorrect()) {
                    if (caret > 2) {
                        int start = text.lastIndexOf(" ", caret - 2);
                        int start2 = text.lastIndexOf(System.lineSeparator(), caret - 2);
                        if (start2 > start) {
                            start = start2;
                        }
                        String wrong = text.substring(start + 1, caret - 1);
                        String correct = spellObj.getCorrectSpelling(wrong);
                        if (correct != null) {
                            StringBuilder sb = new StringBuilder(text);
                            sb.replace(start + 1, caret - 1, correct);
                            ta.setText(sb.toString());
                            caret = caret - wrong.length() + correct.length();
                            ta.setCaretPosition(caret);
                        }
                    }
                }
                if (KeyEvent.VK_QUOTE == key) {
                    // TODO Anfrührungszeichen ersetzen
                    // <ALT>+0132 bzw.
                    // <ALT>+0147 typographische Anführungszeichen oben / unten hin.
                }
            } catch (IndexOutOfBoundsException | IllegalArgumentException ex) {
            }
        }
    }
}
 
Example 2
Source File: Popup.java    From MeteoInfo with GNU Lesser General Public License v3.0 4 votes vote down vote up
public synchronized void type(KeyEvent e) {
    if (!this.isVisible())
        return;
    
    switch (e.getKeyCode()) {
        case KeyEvent.VK_ESCAPE:
            this.setVisible(false);
            break;
        case KeyEvent.VK_ENTER:
        case KeyEvent.VK_TAB:
            this.chooseSelected();
            e.consume();
            break;
        case KeyEvent.VK_SPACE:
            this.chooseSelected();
            break;
        case KeyEvent.VK_PERIOD:
            this.chooseSelected();
            break;
        case KeyEvent.VK_LEFT_PARENTHESIS:
            this.chooseSelected();
            break;
        case KeyEvent.VK_UP:
            this.up();
            e.consume();
            break;
        case KeyEvent.VK_DOWN:
            this.down();
            e.consume();
            break;
        case KeyEvent.VK_PAGE_UP:
            this.pageUp();
            e.consume();
            break;
        case KeyEvent.VK_PAGE_DOWN:
            this.pageDown();
            e.consume();
            break;
        case KeyEvent.VK_BACK_SPACE:
            if (this.typed.isEmpty()){
                this.setVisible(false);
                break;
            }
            this.typed = this.typed.substring(0, this.typed.length() - 1);
            this.data = filter(this.originalData, this.typed);
            this.list.setListData(this.data);
            this.list.setSelectedIndex(0);
            break;
        default:
            char c = e.getKeyChar();
            if (Character.isJavaIdentifierPart(c)){
                this.typed += c; 
                this.data = filter(this.data, this.typed);
                this.list.setListData(this.data);
                this.list.setSelectedIndex(0);
            }
            break;
    }
}
 
Example 3
Source File: MITextEditorPane.java    From MeteoInfo with GNU Lesser General Public License v3.0 4 votes vote down vote up
private synchronized void type(KeyEvent e) {
    if (this.popup.isVisible()) {
        if (e.getID() == KeyEvent.KEY_PRESSED) {
            this.popup.type(e);
        }
        return;
    }

    switch (e.getKeyCode()) {
        case (KeyEvent.VK_PERIOD):
            showPopup();
            e.consume();
            break;
        case (KeyEvent.VK_SPACE):
            String command = getCurrentText();
            Matcher match = FROM_PACKAGE_IMPORT.matcher(command);
            if (match.matches()) {
                showPopup();
            }
            e.consume();
            break;
        case (KeyEvent.VK_9):
            if (e.isShiftDown()) {
                showTip();
            }
            e.consume();
            break;
        case (KeyEvent.VK_0):
            if (e.isShiftDown()) {
                tip.setVisible(false);
            }
            e.consume();
            break;
        case (KeyEvent.VK_LEFT):
        case (KeyEvent.VK_BACK_SPACE):
        case (KeyEvent.VK_DELETE):
            if (tip.isVisible()) {
                tip.setVisible(false);
            }
    }
}
 
Example 4
Source File: Visualization.java    From whyline with MIT License 4 votes vote down vote up
public boolean handleKeyPressed(KeyEvent event) {

		updateMeta();
		
		switch(event.getKeyCode()) {

		case KeyEvent.VK_T :
			whylineUI.getActions().showHideThreads.actionPerformed(null);
			return true;

		case KeyEvent.VK_B :
			
			EventView view = getSelectedEventView();
			if(view != null) {
				Instruction inst = trace.getInstruction(view.getEventID());
				if(inst != null) {
					Line line = inst.getLine();
					if(line != null) {
						boolean wasNew = whylineUI.getPersistentState().addRelevantLine(line);
						if(wasNew)
							return true;
					}
				}
			}
			Toolkit.getDefaultToolkit().beep();
			return true;

		case KeyEvent.VK_ESCAPE :
			getWhylineUI().getActions().collapseBlock.execute();
			return true;

		case KeyEvent.VK_ENTER :
			getWhylineUI().getActions().addToExplanation.execute();
			return true;

		case KeyEvent.VK_COMMA :

			if(!showPreviousOrNextEventInThreadOrMethod(true, true))
				Toolkit.getDefaultToolkit().beep();
			return true;

		case KeyEvent.VK_PERIOD :

			if(!showPreviousOrNextEventInThreadOrMethod(false, true))
				Toolkit.getDefaultToolkit().beep();
			return true;

		case KeyEvent.VK_LEFT :
			
			if(isMetaDown) {
				if(!showPreviousOrNextEventInThreadOrMethod(true, false))
					Toolkit.getDefaultToolkit().beep();
			}
			else
				getWhylineUI().getActions().goToPreviousEvent.execute();
			return true;

		case KeyEvent.VK_RIGHT :
			
			if(isMetaDown) {
				if(!showPreviousOrNextEventInThreadOrMethod(false, false))
					Toolkit.getDefaultToolkit().beep();
			}
			else
				getWhylineUI().getActions().goToNextEvent.execute();
			return true;

		case KeyEvent.VK_UP :
			getWhylineUI().getActions().goToPreviousBlock.execute();
			return true;

		case KeyEvent.VK_DOWN : 
			getWhylineUI().getActions().goToNextBlock.execute();
			return true;

		}
		
		if(Character.isLetterOrDigit(event.getKeyChar()))
			return goToDataDependency(event.getKeyChar(), !isMetaDown);

		return false;
		
	}
 
Example 5
Source File: SkillLevelDecrementCommand.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
private SkillLevelDecrementCommand() {
    super(I18n.Text("Decrease Skill Level"), CMD_DECREASE_LEVEL, KeyEvent.VK_PERIOD);
}
 
Example 6
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 7
Source File: Robot.java    From xnx3 with Apache License 2.0 4 votes vote down vote up
/**
 * 将字符型转换为按键码,可直接使用 {@link #press(int)}调用
 * @param key 字符型文字,包含 0~9 a~z .
 * @return 按键码
 */
public int StringToKey(String key){
	switch (key) {
	case "a":
		return KeyEvent.VK_A;
	case "b":
		return KeyEvent.VK_B;
	case "c":
		return KeyEvent.VK_C;
	case "d":
		return KeyEvent.VK_D;
	case "e":
		return KeyEvent.VK_E;
	case "f":
		return KeyEvent.VK_F;
	case "g":
		return KeyEvent.VK_G;
	case "h":
		return KeyEvent.VK_H;
	case "i":
		return KeyEvent.VK_I;
	case "j":
		return KeyEvent.VK_J;
	case "k":
		return KeyEvent.VK_K;
	case "l":
		return KeyEvent.VK_L;
	case "m":
		return KeyEvent.VK_M;
	case "n":
		return KeyEvent.VK_N;
	case "o":
		return KeyEvent.VK_O;
	case "p":
		return KeyEvent.VK_P;
	case "q":
		return KeyEvent.VK_Q;
	case "r":
		return KeyEvent.VK_R;
	case "s":
		return KeyEvent.VK_S;
	case "t":
		return KeyEvent.VK_T;
	case "u":
		return KeyEvent.VK_U;
	case "v":
		return KeyEvent.VK_V;
	case "w":
		return KeyEvent.VK_W;
	case "x":
		return KeyEvent.VK_X;
	case "y":
		return KeyEvent.VK_Y;
	case "z":
		return KeyEvent.VK_Z;
	case "0":
		return KeyEvent.VK_0;
	case "1":
		return KeyEvent.VK_1;
	case "2":
		return KeyEvent.VK_2;
	case "3":
		return KeyEvent.VK_3;
	case "4":
		return KeyEvent.VK_4;
	case "5":
		return KeyEvent.VK_5;
	case "6":
		return KeyEvent.VK_6;
	case "7":
		return KeyEvent.VK_7;
	case "8":
		return KeyEvent.VK_8;
	case "9":
		return KeyEvent.VK_9;
	case ".":
		return KeyEvent.VK_PERIOD;
	default:
		break;
	}
	
	return 0;
}
 
Example 8
Source File: KeyCodeToChar.java    From Repeat with Apache License 2.0 4 votes vote down vote up
private static String getNonAlphaCharWithoutShift(int code) {
	switch (code) {
	case KeyEvent.VK_BACK_QUOTE:
		return "`";
	case KeyEvent.VK_1:
		return "1";
	case KeyEvent.VK_2:
		return "2";
	case KeyEvent.VK_3:
		return "3";
	case KeyEvent.VK_4:
		return "4";
	case KeyEvent.VK_5:
		return "5";
	case KeyEvent.VK_6:
		return "6";
	case KeyEvent.VK_7:
		return "7";
	case KeyEvent.VK_8:
		return "8";
	case KeyEvent.VK_9:
		return "9";
	case KeyEvent.VK_0:
		return "0";
	case KeyEvent.VK_MINUS:
		return "-";
	case KeyEvent.VK_EQUALS:
		return "=";
	case KeyEvent.VK_OPEN_BRACKET:
		return "[";
	case KeyEvent.VK_CLOSE_BRACKET:
		return "]";
	case KeyEvent.VK_SEMICOLON:
		return ";";
	case KeyEvent.VK_QUOTE:
		return "'";
	case KeyEvent.VK_BACK_SLASH:
		return "\\";
	case KeyEvent.VK_COMMA:
		return ",";
	case KeyEvent.VK_PERIOD:
		return ".";
	case KeyEvent.VK_SLASH:
		return "/";
	case KeyEvent.VK_TAB:
		return "\t";
	case KeyEvent.VK_ENTER:
		return "\n";
	case KeyEvent.VK_SPACE:
		return " ";
	default:
		return "";
	}
}
 
Example 9
Source File: KeyCodeToChar.java    From Repeat with Apache License 2.0 4 votes vote down vote up
private static String getNonAlphaCharWithShift(int code) {
	switch (code) {
	case KeyEvent.VK_BACK_QUOTE:
		return "~";
	case KeyEvent.VK_1:
		return "!";
	case KeyEvent.VK_2:
		return "@";
	case KeyEvent.VK_3:
		return "#";
	case KeyEvent.VK_4:
		return "$";
	case KeyEvent.VK_5:
		return "%";
	case KeyEvent.VK_6:
		return "^";
	case KeyEvent.VK_7:
		return "&";
	case KeyEvent.VK_8:
		return "*";
	case KeyEvent.VK_9:
		return "(";
	case KeyEvent.VK_0:
		return ")";
	case KeyEvent.VK_MINUS:
		return "_";
	case KeyEvent.VK_EQUALS:
		return "+";
	case KeyEvent.VK_OPEN_BRACKET:
		return "{";
	case KeyEvent.VK_CLOSE_BRACKET:
		return "}";
	case KeyEvent.VK_SEMICOLON:
		return ":";
	case KeyEvent.VK_QUOTE:
		return "\"";
	case KeyEvent.VK_BACK_SLASH:
		return "|";
	case KeyEvent.VK_COMMA:
		return "<";
	case KeyEvent.VK_PERIOD:
		return ">";
	case KeyEvent.VK_SLASH:
		return "?";
	case KeyEvent.VK_TAB:
		return "\t";
	case KeyEvent.VK_ENTER:
		return "\n";
	case KeyEvent.VK_SPACE:
		return " ";
	default:
		return "";
	}
}
 
Example 10
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);
}