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

The following examples show how to use java.awt.event.KeyEvent#VK_SPACE . 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: JCheckTree.java    From visualvm with GNU General Public License v2.0 7 votes vote down vote up
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_SPACE) {
        TreePath[] paths = getSelectionPaths();

        if ((paths != null) && (paths.length > 0)) {
            Collection changedNodes = new ArrayList();

            for (int i = 0; i < paths.length; i++) {
                TreePath path = paths[i];

                if ((path != null) && (path.getPathCount() > 0) && path.getLastPathComponent() instanceof CheckTreeNode
                        && (((CheckTreeNode) path.getLastPathComponent()).isLeaf() || (i == (paths.length - 1)))) {
                    fireNodeToggled(path, true);
                }

                changedNodes.addAll(togglePathState(path));
                fireNodeToggled(path, false);
            }

            treeDidChange();
            fireCheckTreeChanged(changedNodes);
        }
    }
}
 
Example 2
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 3
Source File: JCheckTree.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_SPACE) {
        TreePath[] paths = getSelectionPaths();

        if ((paths != null) && (paths.length > 0)) {
            Collection changedNodes = new ArrayList();

            for (int i = 0; i < paths.length; i++) {
                TreePath path = paths[i];

                if ((path != null) && (path.getPathCount() > 0) && path.getLastPathComponent() instanceof CheckTreeNode
                        && (((CheckTreeNode) path.getLastPathComponent()).isLeaf() || (i == (paths.length - 1)))) {
                    fireNodeToggled(path, true);
                }

                changedNodes.addAll(togglePathState(path));
                fireNodeToggled(path, false);
            }

            treeDidChange();
            fireCheckTreeChanged(changedNodes);
        }
    }
}
 
Example 4
Source File: KeyEventCodeToString.java    From Repeat with Apache License 2.0 5 votes vote down vote up
/**
 * Convert from code from KeyEvent.VK_* to a human friendly string.
 * This is needed because in some OSes the KeyEvent utility does
 * not work properly.
 */
public static String codeToString(int code) {
	switch (code) {
	case KeyEvent.VK_CONTROL:
		return "Ctrl";
	case KeyEvent.VK_ALT:
		if (OSIdentifier.IS_OSX) {
			return "Option";
		}
		return "Alt";
	case KeyEvent.VK_WINDOWS:
		return "Windows";
	case KeyEvent.VK_META:
		if (OSIdentifier.IS_LINUX) {
			return "Meta";
		}
		if (OSIdentifier.IS_OSX) {
			return "Command";
		}
		break;
	case KeyEvent.VK_SHIFT:
		return "Shift";
	case KeyEvent.VK_TAB:
		return "Tab";
	case KeyEvent.VK_SPACE:
		return "Space";
	}
	return KeyEvent.getKeyText(code);
}
 
Example 5
Source File: MainPanel.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyReleased(KeyEvent e) {
    int key = e.getKeyCode();

    if (key == KeyEvent.VK_LEFT) {
        leftPressed = false;
    }
    if (key == KeyEvent.VK_RIGHT) {
        rightPressed = false;
    }
    if (key == KeyEvent.VK_SPACE) {
        firePressed = false;
    }
}
 
Example 6
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 7
Source File: WButtonPeer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean handleJavaKeyEvent(KeyEvent e) {
     switch (e.getID()) {
        case KeyEvent.KEY_RELEASED:
            if (e.getKeyCode() == KeyEvent.VK_SPACE){
                handleAction(e.getWhen(), e.getModifiers());
            }
        break;
     }
     return false;
}
 
Example 8
Source File: HintsPanelLogic.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_SPACE) {

        if ( e.getSource() instanceof JTree ) {
            JTree tree = (JTree) e.getSource();
            TreePath path = tree.getSelectionPath();

            if ( toggle( path )) {
                e.consume();
            }
        }
    }
}
 
Example 9
Source File: HintsPanelLogic.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_SPACE || e.getKeyCode() == KeyEvent.VK_ENTER ) {

        if ( e.getSource() instanceof JTree ) {
            JTree tree = (JTree) e.getSource();
            TreePath path = tree.getSelectionPath();

            if ( toggle( path )) {
                e.consume();
            }
        }
    }
}
 
Example 10
Source File: Frame.java    From A-Pathfinding-Visualization with MIT License 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
	char key = e.getKeyChar();
	currentKey = key;

	// Start if space is pressed
	if (currentKey == KeyEvent.VK_SPACE) {
		ch.getB("run").setText("stop");
		start();
	}
}
 
Example 11
Source File: WButtonPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean handleJavaKeyEvent(KeyEvent e) {
     switch (e.getID()) {
        case KeyEvent.KEY_RELEASED:
            if (e.getKeyCode() == KeyEvent.VK_SPACE){
                handleAction(e.getWhen(), e.getModifiers());
            }
        break;
     }
     return false;
}
 
Example 12
Source File: XButtonPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
void handleJavaKeyEvent(KeyEvent e) {
    int id = e.getID();
    switch (id) {
      case KeyEvent.KEY_PRESSED:
          if (e.getKeyCode() == KeyEvent.VK_SPACE)
          {
              pressed=true;
              armed=true;
              repaint();
              action(e.getWhen(),e.getModifiers());
          }

          break;

      case KeyEvent.KEY_RELEASED:
          if (e.getKeyCode() == KeyEvent.VK_SPACE)
          {
              pressed = false;
              armed = false;
              repaint();
          }

          break;


    }
}
 
Example 13
Source File: MainPanel.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyReleased(KeyEvent e) {
    int key = e.getKeyCode();

    if (key == KeyEvent.VK_LEFT) {
        leftPressed = false;
    }
    if (key == KeyEvent.VK_RIGHT) {
        rightPressed = false;
    }
    if (key == KeyEvent.VK_SPACE) {
        firePressed = false;
    }
}
 
Example 14
Source File: MainPanel.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyPressed(KeyEvent e) {
    int key = e.getKeyCode();

    if (key == KeyEvent.VK_LEFT) {
        leftPressed = true;
    }
    if (key == KeyEvent.VK_RIGHT) {
        rightPressed = true;
    }
    if (key == KeyEvent.VK_SPACE) {
        firePressed = true;
    }
}
 
Example 15
Source File: XButtonPeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
void handleJavaKeyEvent(KeyEvent e) {
    int id = e.getID();
    switch (id) {
      case KeyEvent.KEY_PRESSED:
          if (e.getKeyCode() == KeyEvent.VK_SPACE)
          {
              pressed=true;
              armed=true;
              repaint();
              action(e.getWhen(),e.getModifiers());
          }

          break;

      case KeyEvent.KEY_RELEASED:
          if (e.getKeyCode() == KeyEvent.VK_SPACE)
          {
              pressed = false;
              armed = false;
              repaint();
          }

          break;


    }
}
 
Example 16
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 17
Source File: MaterialButtonV.java    From MobyDroid with Apache License 2.0 4 votes vote down vote up
private void formKeyPressed(java.awt.event.KeyEvent evt) {
    if (action != null && (evt.getKeyCode() == KeyEvent.VK_ENTER || evt.getKeyCode() == KeyEvent.VK_SPACE) && enabled) {
        action.Action();
    }
}
 
Example 18
Source File: StayOpenPopupMenu.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isReturnAction(KeyEvent e) {
    int keyCode = e.getKeyCode();
    return keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_SPACE;
}
 
Example 19
Source File: StayOpenPopupMenu.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static boolean isReturnAction(KeyEvent e) {
    int keyCode = e.getKeyCode();
    return keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_SPACE;
}
 
Example 20
Source File: CheckboxTreeTable.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean isToggleEvent(KeyEvent e) {
  return e.getKeyCode() == KeyEvent.VK_SPACE;
}