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

The following examples show how to use javafx.scene.input.KeyEvent#consume() . 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: 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 2
Source File: MainController.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 3
Source File: ShowPanel.java    From oim-fx with MIT License 6 votes vote down vote up
public void processKeyEvent(KeyEvent ev) {
	if (webPage == null)
		return;
	ev.consume();
	String text = null;
	String keyIdentifier = null;
	int windowsVirtualKeyCode = 0;
	if (ev.getEventType() == KeyEvent.KEY_TYPED) {
		text = ev.getCharacter();
	} else {
		KeyCodeMap.Entry keyCodeEntry = KeyCodeMap.lookup(ev.getCode());
		keyIdentifier = keyCodeEntry.getKeyIdentifier();
		windowsVirtualKeyCode = keyCodeEntry.getWindowsVirtualKeyCode();
	}

	WCKeyEvent keyEvent = new WCKeyEvent(
			idMap.get(ev.getEventType()),
			text,
			keyIdentifier,
			windowsVirtualKeyCode,
			ev.isShiftDown(), ev.isControlDown(),
			ev.isAltDown(), ev.isMetaDown(), System.currentTimeMillis());
	if (webPage.dispatchKeyEvent(keyEvent)) {
		ev.consume();
	}
}
 
Example 4
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)
    {
        // Commit value from combo's text field into combo's value...
        combo.commitValue();
        // .. and use that for the cell
        commitEdit(combo.getValue());

        // 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 5
Source File: EcoController.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: 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 7
Source File: TextAreaReadline.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
protected void enterAction(KeyEvent event) {
    event.consume();
    if (functionText.length() > 0) {
        String function = functionText.toString();
        append(">> ", promptStyle);
        append(function, inputStyle);
        inputJoin.send(Channel.LINE, function);
    } else {
        String text = area.getText();
        append(">> ", promptStyle);
        append(text, inputStyle);
        append("\n", inputStyle);
        String line = getLine();
        inputJoin.send(Channel.LINE, line);
    }
    functionText = new StringBuffer();
    area.clear();
}
 
Example 8
Source File: TableAutoCommitCell.java    From MyBox with Apache License 2.0 5 votes vote down vote up
protected void onKeyPrs(final KeyEvent e) {
    switch (e.getCode()) {
        case ESCAPE:
            isEdit = false;
            cancelEdit(); // see CellUtils#createTextField(...)
            e.consume();
            break;
        case TAB:
            if (e.isShiftDown()) {
                getTableView().getSelectionModel().selectPrevious();
            } else {
                getTableView().getSelectionModel().selectNext();
            }
            e.consume();
            break;
        case UP:
            getTableView().getSelectionModel().selectAboveCell();
            e.consume();
            break;
        case DOWN:
            getTableView().getSelectionModel().selectBelowCell();
            e.consume();
            break;
        default:
            break;
    }
}
 
Example 9
Source File: TableUtils.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public void handle(final KeyEvent keyEvent) {
  if (keyCodeCompination.match(keyEvent)) {
    if (keyEvent.getSource() instanceof TreeTableView) {
      // Copy to clipboard
      copySelectionToClipboard((TreeTableView<?>) keyEvent.getSource());

      // Event is handled, consume it
      keyEvent.consume();
    }
  }
}
 
Example 10
Source File: TextAreaReadline.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
protected void downAction(KeyEvent event) {
    event.consume();
    if (!readline.getHistory().next()) {
        return;
    }
    String oldLine;
    if (!readline.getHistory().next()) {
        oldLine = currentLine;
    } else {
        readline.getHistory().previous(); // undo check
        oldLine = readline.getHistory().current().trim();
    }
    replaceText(oldLine);
}
 
Example 11
Source File: TextAreaReadline.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
protected void upAction(KeyEvent event) {
    event.consume();
    if (!readline.getHistory().next()) {
        currentLine = getLine();
    } else {
        readline.getHistory().previous(); // undo check
    }
    if (!readline.getHistory().previous()) {
        return;
    }
    String oldLine = readline.getHistory().current().trim();
    replaceText(oldLine);
}
 
Example 12
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 13
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 14
Source File: SpatialInformation.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private static void submitOnKeyPressed(StringProperty text, DoubleProperty number, KeyEvent event, KeyCode key)
{
	if (event.getCode().equals(key))
	{
		LOG.debug("submitting {} to {}", text, number);
		event.consume();
		submitIfValid(text, number);
	}
}
 
Example 15
Source File: WordStateHandler.java    From VocabHunter with Apache License 2.0 5 votes vote down vote up
public void processKeyPress(final KeyEvent event) {
    KeyCode key = event.getCode();

    if (EventHandlerTool.isWithoutModifier(event) && keyHandlers.containsKey(key)) {
        event.consume();
        keyHandlers.get(key).run();
    }
}
 
Example 16
Source File: TextAreaReadline.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(KeyEvent event) {
    if (event.getEventType() != KeyEvent.KEY_PRESSED) {
        return;
    }
    KeyCode code = event.getCode();
    switch (code) {
    case ENTER:
        positionToLastLine();
        boolean collect = false;
        if (area.getText().toString().endsWith(";")) {
            collect = true;
            area.setText(area.getText().substring(0, area.getText().length() - 1));
        }
        if (collect || event.isShiftDown()) {
            collectAction();
        } else {
            if (functionText.length() > 0) {
                collectAction();
            }
            enterAction(event);
            area.setEditable(false);
        }
        break;
    case UP:
        positionToLastLine();
        upAction(event);
        break;
    case DOWN:
        positionToLastLine();
        downAction(event);
        break;
    case LEFT:
    case D:
        if (event.isControlDown()) {
            event.consume();
            inputJoin.send(Channel.LINE, EMPTY_LINE);
        }
        break;
    default:
        break;
    }
}
 
Example 17
Source File: WordNoteHandler.java    From VocabHunter with Apache License 2.0 4 votes vote down vote up
public void processKeyPress(final KeyEvent event) {
    if (EventHandlerTool.isSimpleKeyPress(event, KeyCode.N)) {
        event.consume();
        show();
    }
}
 
Example 18
Source File: StreamPropertiesViewController.java    From trex-stateless-gui with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(KeyEvent event) {
    if (!event.getCharacter().matches("[0-9]") && event.getCode() != KeyCode.BACK_SPACE) {
        event.consume();
    }
}
 
Example 19
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();
    }
}
 
Example 20
Source File: DragSupport.java    From scenic-view with GNU General Public License v3.0 4 votes vote down vote up
public DragSupport(Node target, final KeyCode modifier, final MouseButton mouseButton, final Orientation orientation, final Property<Number> property, final double factor) {
    this.target = target;
    mouseEventHandler = new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent t) {
            if (t.getEventType() != MouseEvent.MOUSE_ENTERED_TARGET
                    && t.getEventType() != MouseEvent.MOUSE_EXITED_TARGET) {
                lastMouseEvent = t;
            }
            if (t.getEventType() == MouseEvent.MOUSE_PRESSED) {
                if (t.getButton() == mouseButton
                        && isModifierCorrect(t, modifier)) {
                    anchor = property.getValue();
                    dragAnchor = getCoord(t, orientation);
                    t.consume();
                }
            } else if (t.getEventType() == MouseEvent.MOUSE_DRAGGED) {
                if (t.getButton() == mouseButton
                        && isModifierCorrect(t, modifier)) {
                    property.setValue(anchor.doubleValue()
                            + (getCoord(t, orientation) - dragAnchor) * factor);
                    t.consume();
                }
            }
        }
    };
    keyboardEventHandler = (KeyEvent t) -> {
        if (t.getEventType() == KeyEvent.KEY_PRESSED) {
            if (t.getCode() == modifier) {
                anchor = property.getValue();
                if (lastMouseEvent != null) {
                    dragAnchor = getCoord(lastMouseEvent, orientation);
                }
                t.consume();
            }
        } else if (t.getEventType() == KeyEvent.KEY_RELEASED) {
            if (t.getCode() != modifier && isModifierCorrect(t, modifier)) {
                anchor = property.getValue();
                if (lastMouseEvent != null) {
                    dragAnchor = getCoord(lastMouseEvent, orientation);
                }
                t.consume();
            }
        }
    };
    target.addEventHandler(MouseEvent.ANY, mouseEventHandler);
    target.addEventHandler(KeyEvent.ANY, keyboardEventHandler);
}