Java Code Examples for javafx.scene.input.KeyEvent#getCode()

The following examples show how to use javafx.scene.input.KeyEvent#getCode() . 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: StringTable.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private void handleKey(final KeyEvent event)
{
    if (event.getCode() == KeyCode.TAB)
    {
        // Save the current text field content, since lost focus would otherwise restore previous value
        commitEdit(getConverter().fromString(editor.getText()));

        // Edit next/prev column in same row
        final ObservableList<TableColumn<List<ObservableCellValue>, ?>> columns = getTableView().getColumns();
        final int col = columns.indexOf(getTableColumn());
        final int next = event.isShiftDown()
                       ? (col + columns.size() - 1) % columns.size()
                       : (col + 1) % columns.size();
        editCell(getIndex(), columns.get(next));
        event.consume();
    }
}
 
Example 2
Source File: AutocompleteMenu.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Toggle menu on Ctrl-Space
 *
 *  <p>Called by both the text field and the context menu
 */
private void toggleMenu(final KeyEvent event)
{
    // For Mac, isShortcutDown() to detect Command-SPACE
    // seemed natural, but that is already captured by OS
    // for 'Spotlight Search',
    // so use Ctrl-Space on all OS
    if (event.isControlDown()  &&  event.getCode() == KeyCode.SPACE)
    {
        if (menu.isShowing())
            menu.hide();
        else if (event.getSource() instanceof TextField)
        {
            final TextInputControl field = (TextInputControl) event.getSource();
            // Show menu with current content,
            // in case we were hiding and are now showing the menu
            // for the same field, not loosing focus,
            // menu already populated
            showMenuForField(field);
            // Certainly need to perform lookup if menu is empty.
            // Otherwise, cannot hurt to 'refresh'
            lookup(field);
        }
        event.consume();
    }
}
 
Example 3
Source File: RTImagePlot.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** onKeyPressed */
private void keyPressed(final KeyEvent event)
{
    if (! handle_keys || axisLimitsField.isVisible())
        return;
    if (event.getCode() == KeyCode.Z)
        plot.getUndoableActionManager().undoLast();
    else if (event.getCode() == KeyCode.Y)
        plot.getUndoableActionManager().redoLast();
    else if (event.getCode() == KeyCode.O)
        showConfigurationDialog();
    else if (event.getCode() == KeyCode.C)
        toolbar.toggleCrosshair();
    else if (event.getCode() == KeyCode.T)
        showToolbar(! isToolbarVisible());
    else if (event.isControlDown())
        toolbar.selectMouseMode(MouseMode.ZOOM_IN);
    else if (event.isAltDown())
        toolbar.selectMouseMode(MouseMode.ZOOM_OUT);
    else if (event.isShiftDown())
        toolbar.selectMouseMode(MouseMode.PAN);
    else
        toolbar.selectMouseMode(MouseMode.NONE);
    event.consume();
}
 
Example 4
Source File: CircuitManager.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void keyReleased(KeyEvent e) {
	switch(e.getCode()) {
		case CONTROL:
			isCtrlDown = false;
			setNeedsRepaint();
			break;
		case SHIFT:
			simulatorWindow.setClickMode(false);
			isShiftDown = false;
			setNeedsRepaint();
			break;
	}
	
	if(lastPressed != null && lastPressedKeyCode == e.getCode()) {
		lastPressed.keyReleased(this, circuitBoard.getCurrentState(), e.getCode(), e.getText());
		lastPressed = null;
		lastPressedKeyCode = null;
		setNeedsRepaint();
	}
}
 
Example 5
Source File: ConversationController.java    From BetonQuest-Editor with GNU General Public License v3.0 6 votes vote down vote up
private void keyAction(KeyEvent event, Action add, Action edit, Action delete) {
	if (event.getCode() == KeyCode.DELETE) {
		if (delete != null) {
			delete.act();
		}
		event.consume();
		return;
	}
	if (event.getCode() == KeyCode.ENTER) {
		if (edit != null) {
			edit.act();
		}
		event.consume();
		return;
	}
	KeyCombination combintation = new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN);
	if (combintation.match(event)) {
		if (add != null) {
			add.act();
		}
		event.consume();
		return;
	}
}
 
Example 6
Source File: TableTextFieldListener.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
public void escListener(KeyEvent event) {
    KeyCode code = event.getCode();
    if (KeyCode.ESCAPE.equals(code)) {
        mainController.getTableFindTextField().setText("");
        mainController.getTreeViewDataSource().requestFocus();
    }
}
 
Example 7
Source File: MainController.java    From dev-tools with Apache License 2.0 5 votes vote down vote up
@FXML
private void handleKeyInput(final InputEvent event) {
    if (event instanceof KeyEvent) {
        final KeyEvent keyEvent = (KeyEvent) event;
        if (keyEvent.isControlDown() && keyEvent.getCode() == KeyCode.A) {
            debug("handleKeyInput");
        }
    }
}
 
Example 8
Source File: DemoBrowser.java    From FxDock with Apache License 2.0 5 votes vote down vote up
protected void handleKeyTyped(KeyEvent ev)
{
	KeyCode c = ev.getCode();
	switch(c)
	{
	case ENTER:
		openPage(addressField.getText());
		break;
	default:
		return;
	}
	
	ev.consume();
}
 
Example 9
Source File: AbstractFileEditor.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Handle the key released event.
 *
 * @param event the event
 */
@FxThread
protected void processKeyReleased(@NotNull final KeyEvent event) {

    final KeyCode code = event.getCode();

    if (handleKeyActionImpl(code, false, event.isControlDown(), event.isShiftDown(), false)) {
        event.consume();
    }
}
 
Example 10
Source File: ProjectorArenaPane.java    From ShootOFF with GNU General Public License v3.0 5 votes vote down vote up
public void canvasKeyPressed(KeyEvent event) {
	final boolean macFullscreen = event.getCode() == KeyCode.F && event.isControlDown() && event.isShortcutDown();
	if (event.getCode() == KeyCode.F11 || macFullscreen) {
		toggleFullScreen();

		// Manually going full screen with an arena that was manually
		// moved to another screen
		final Optional<Screen> currentArenaScreen = getStageHomeScreen(arenaStage);

		if (!currentArenaScreen.isPresent()) return;

		arenaHome = currentArenaScreen.get();

		setArenaScreenOrigin(arenaHome);

		final boolean fullyManual = !detectedProjectorScreen.isPresent() && !arenaStage.isFullScreen()
				&& !originalArenaHomeScreen.equals(currentArenaScreen.get());
		final boolean movedAfterAuto = detectedProjectorScreen.isPresent() && !arenaStage.isFullScreen()
				&& !detectedProjectorScreen.equals(currentArenaScreen.get());

		if (fullyManual || movedAfterAuto) {
			final double dpiScaleFactor = ShootOFFController.getDpiScaleFactorForScreen();

			config.setArenaPosition(arenaStage.getX() / dpiScaleFactor, arenaStage.getY() / dpiScaleFactor);
			try {
				config.writeConfigurationFile();
			} catch (ConfigurationException | IOException e) {
				logger.error("Error writing configuration with arena location", e);
			}
		}

	}
}
 
Example 11
Source File: Vector2fPropertyControl.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Update the vector.
 *
 * @param event the event
 */
@FxThread
private void updateVector(@Nullable KeyEvent event) {
    if (!isIgnoreListener() && (event == null || event.getCode() == KeyCode.ENTER)) {
        apply();
    }
}
 
Example 12
Source File: DataAnalysisController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
@Override
public void keyHandler(KeyEvent event) {
    KeyCode code = event.getCode();
    if (code != null) {
        switch (code) {
            case F1:
                queryData();
                return;
            case F3:
                exportData();
        }
    }
    super.keyHandler(event);
}
 
Example 13
Source File: ConfirmDialog.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected void processKey(@NotNull final KeyEvent event) {
    if (event.getCode() == KeyCode.ENTER) {
        processClose();
    }
}
 
Example 14
Source File: ChatController.java    From JavaFX-Chat with GNU General Public License v3.0 4 votes vote down vote up
public void sendMethod(KeyEvent event) throws IOException {
    if (event.getCode() == KeyCode.ENTER) {
        sendButtonAction();
    }
}
 
Example 15
Source File: KeyButtonEventHandler.java    From jfxvnc with Apache License 2.0 4 votes vote down vote up
private boolean sendSpecialKeyEvents(KeyEvent event, boolean isDown) {
  switch (event.getCode()) {
    case PRINTSCREEN:
      fire(new KeyButtonEvent(isDown, RFB_Print));
      return true;
    case INSERT:
      fire(new KeyButtonEvent(isDown, RFB_Insert));
      return true;
    case UNDO:
      fire(new KeyButtonEvent(isDown, RFB_Undo));
      return true;
    case AGAIN:
      fire(new KeyButtonEvent(isDown, RFB_Redo));
      return true;
    case FIND:
      fire(new KeyButtonEvent(isDown, RFB_Find));
      return true;
    case CANCEL:
      fire(new KeyButtonEvent(isDown, RFB_Cancel));
      return true;
    case HELP:
      fire(new KeyButtonEvent(isDown, RFB_Help));
      return true;
    case STOP:
      fire(new KeyButtonEvent(isDown, RFB_Break));
      return true;
    case MODECHANGE:
      fire(new KeyButtonEvent(isDown, RFB_Mode_switch));
      return true;
    case NUM_LOCK:
      fire(new KeyButtonEvent(isDown, RFB_Num_Lock));
      return true;
    case BACK_SPACE:
      fire(new KeyButtonEvent(isDown, RFB_BackSpace));
      return true;
    case TAB:
      fire(new KeyButtonEvent(isDown, RFB_Tab));
      return true;
    case CLEAR:
      fire(new KeyButtonEvent(isDown, RFB_Clear));
      return true;
    case ENTER:
      fire(new KeyButtonEvent(isDown, RFB_Return));
      return true;
    case PAUSE:
      fire(new KeyButtonEvent(isDown, RFB_Pause));
      return true;
    case SCROLL_LOCK:
      fire(new KeyButtonEvent(isDown, RFB_Scroll_Lock));
      return true;
    case ESCAPE:
      fire(new KeyButtonEvent(isDown, RFB_Escape));
      return true;
    case DELETE:
      fire(new KeyButtonEvent(isDown, RFB_Delete));
      return true;
    case SPACE:
      fire(new KeyButtonEvent(isDown, RFB_space));
      return true;
    case CAPS:
      fire(new KeyButtonEvent(isDown, RFB_Caps_Lock));
      return true;
    case CHANNEL_DOWN:
      fire(new KeyButtonEvent(isDown, RFB_N));
      return true;
    case NUMPAD0:
      fire(new KeyButtonEvent(isDown, RFB_KP_0));
      return true;
    case NUMPAD1:
      fire(new KeyButtonEvent(isDown, RFB_KP_1));
      return true;
    case NUMPAD2:
      fire(new KeyButtonEvent(isDown, RFB_KP_2));
      return true;
    case NUMPAD3:
      fire(new KeyButtonEvent(isDown, RFB_KP_3));
      return true;
    case NUMPAD4:
      fire(new KeyButtonEvent(isDown, RFB_KP_4));
      return true;
    case NUMPAD5:
      fire(new KeyButtonEvent(isDown, RFB_KP_5));
      return true;
    case NUMPAD6:
      fire(new KeyButtonEvent(isDown, RFB_KP_6));
      return true;
    case NUMPAD7:
      fire(new KeyButtonEvent(isDown, RFB_KP_7));
      return true;
    case NUMPAD8:
      fire(new KeyButtonEvent(isDown, RFB_KP_8));
      return true;
    case NUMPAD9:
      fire(new KeyButtonEvent(isDown, RFB_KP_9));
      return true;
    default:
      return false;
  }
}
 
Example 16
Source File: ChatBox.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Processes the textfield in the chat box and saves a history of input
 * 
 * @param keyEvent
 */
public void keyHandler(final KeyEvent keyEvent) {
	switch (keyEvent.getCode()) {
	case ENTER:
		String text = autoFillTextBox.getTextbox().getText();
		if (text != "" && text != null && !text.trim().isEmpty()) {
			hitEnter();
		} else {
			autoFillTextBox.getTextbox().clear();
		}
		break;

	case UP:
		if (historyPointer == 0) {
			break;
		}

		historyPointer--;
		// System.out.println("historyPointer is " + historyPointer);
		ChatSafe.runSafe(() -> {
			/// textField.setText(history.get(historyPointer));
			// textField.selectAll();
			autoFillTextBox.getTextbox().setText(history.get(historyPointer));
			autoFillTextBox.getTextbox().selectAll();
		});

		break;

	case DOWN:
		if (historyPointer >= history.size() - 1) {
			break;
		}

		historyPointer++;
		// System.out.println("historyPointer is " + historyPointer);
		ChatSafe.runSafe(() -> {
			// textField.setText(history.get(historyPointer));
			// textField.selectAll();
			autoFillTextBox.getTextbox().setText(history.get(historyPointer));
			autoFillTextBox.getTextbox().selectAll();
		});

		break;

	default:
		break;
	}

}
 
Example 17
Source File: NBTTreeView.java    From mcaselector with MIT License 4 votes vote down vote up
private void onKeyReleased(KeyEvent event) {
	if (event.getCode() == KeyCode.ENTER) {
		commitEdit(getItem());
		updateItem(getItem(), false);
	}
}
 
Example 18
Source File: AutoCompleteComboBoxListener.java    From Path-of-Leveling with MIT License 4 votes vote down vote up
@Override
public void handle(KeyEvent event) {

    if(event.getCode() == KeyCode.UP) {
        caretPos = -1;
        moveCaret(comboBox.getEditor().getText().length());
        return;
    } else if(event.getCode() == KeyCode.DOWN) {
        if(!comboBox.isShowing()) {
            comboBox.show();
        }
        caretPos = -1;
        moveCaret(comboBox.getEditor().getText().length());
        return;
    } else if(event.getCode() == KeyCode.BACK_SPACE) {
        moveCaretToPos = true;
        caretPos = comboBox.getEditor().getCaretPosition();
    } else if(event.getCode() == KeyCode.DELETE) {
        moveCaretToPos = true;
        caretPos = comboBox.getEditor().getCaretPosition();
    }

    if(event.getCharacter().matches("[a-z]"))
        comboBox.setValue(
                (T) String.valueOf(comboBox.getValue()).toUpperCase()
        );

    if (event.getCode() == KeyCode.RIGHT || event.getCode() == KeyCode.LEFT
            || event.isControlDown() || event.getCode() == KeyCode.HOME
            || event.getCode() == KeyCode.END || event.getCode() == KeyCode.TAB) {
        return;
    }

    //if(comboBox.getItems().isEmpty()) comboBox.getItems().addAll(data);
    
   ObservableList<T> list = FXCollections.observableArrayList();
    for (T aData : data) {
        if(sc.toString(aData).toLowerCase().contains
                    (AutoCompleteComboBoxListener.this.comboBox
                    .getEditor().getText().toLowerCase())
                ){
            list.add(aData);
        }
        /*
        if (String.valueOf(aData).toLowerCase().startsWith(
                AutoCompleteComboBoxListener.this.comboBox
                        .getEditor().getText().toLowerCase())) {
            list.add(aData);
        }*/
    }
    String t = comboBox.getEditor().getText();
    comboBox.getItems().clear();
    comboBox.getItems().addAll(list);
    comboBox.getEditor().setText(t);
    if(!moveCaretToPos) {
        caretPos = -1;
    }
    moveCaret(t.length());
    if(!list.isEmpty()) {
        comboBox.show();
    }
}
 
Example 19
Source File: KeyHelper.java    From AsciidocFX with Apache License 2.0 4 votes vote down vote up
public static boolean isWord(KeyEvent event) {
    KeyCode keyCode = event.getCode();

    return keyCode.isLetterKey() || keyCode.isDigitKey() || FILE_LEGALS.match(event) || keyCode == KeyCode.UNDEFINED;
}
 
Example 20
Source File: CreateNewAccount.java    From ChatRoomFX with MIT License 4 votes vote down vote up
@FXML
private void intRestriction(KeyEvent key){
    if(!"0123456789".contains(key.getCharacter())&&(key.getCode()!= KeyCode.BACK_SPACE)){
        key.consume();
    }
}