Java Code Examples for javafx.scene.input.KeyCode#X

The following examples show how to use javafx.scene.input.KeyCode#X . 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: TextEditorPane.java    From logbook-kai with MIT License 6 votes vote down vote up
@FXML
void initialize() {
    WebEngine engine = this.webview.getEngine();
    engine.load(PluginServices.getResource("logbook/gui/text_editor_pane.html").toString());
    engine.getLoadWorker().stateProperty().addListener(
            (ob, o, n) -> {
                if (n == Worker.State.SUCCEEDED) {
                    this.setting();
                }
            });

    KeyCombination copy = new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_DOWN);
    KeyCombination cut = new KeyCodeCombination(KeyCode.X, KeyCombination.CONTROL_DOWN);

    this.webview.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
        if (copy.match(event) || cut.match(event)) {
            String text = String.valueOf(engine.executeScript("getCopyText()"));

            Platform.runLater(() -> {
                ClipboardContent content = new ClipboardContent();
                content.putString(text);
                Clipboard.getSystemClipboard().setContent(content);
            });
        }
    });
}
 
Example 2
Source File: ResourceTree.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
/**
 * Handle hotkeys.
 */
@FxThread
private void processKey(@NotNull KeyEvent event) {

    if (isReadOnly()) {
        return;
    }

    var editorConfig = EditorConfig.getInstance();
    var currentAsset = editorConfig.getCurrentAsset();
    if (currentAsset == null) {
        return;
    }

    updateSelectedElements();

    var selectedElements = getSelectedElements();
    if (selectedElements.isEmpty()) {
        return;
    }

    var firstElement = selectedElements.first();
    if (firstElement instanceof LoadingResourceElement) {
        return;
    }

    boolean onlyFiles = true;
    boolean onlyFolders = true;
    boolean selectedAsset = false;

    for (var element : selectedElements.array()) {

        if (element == null) {
            break;
        }

        if (element instanceof FileResourceElement) {
            onlyFolders = false;
        } else if (element instanceof FolderResourceElement) {
            onlyFiles = false;
        }

        if (Objects.equals(currentAsset, element.getFile())) {
            selectedAsset = true;
        }
    }

    var actionTester = getActionTester();
    var keyCode = event.getCode();
    var controlDown = event.isControlDown();

    if (!currentAsset.equals(firstElement.getFile())) {

        if (controlDown) {

            if (keyCode == KeyCode.C && actionTester.test(CopyFileAction.class) &&
                    !selectedAsset && (onlyFiles || selectedElements.size() == 1)) {

                CopyFileAction.applyFor(selectedElements);

            } else if (keyCode == KeyCode.X && actionTester.test(CutFileAction.class) &&
                    !selectedAsset && (onlyFiles || selectedElements.size() == 1)) {

                CutFileAction.applyFor(selectedElements);
            }

        } else if (keyCode == KeyCode.DELETE && actionTester.test(DeleteFileAction.class) &&
                !selectedAsset && (onlyFiles || selectedElements.size() == 1)) {

            DeleteFileAction.applyFor(selectedElements);
        }
    }

    if (controlDown && keyCode == KeyCode.V && hasFileInClipboard() &&
            actionTester.test(PasteFileAction.class)) {

        PasteFileAction.applyFor(firstElement);
    }
}