Example usage for javafx.scene.input ScrollEvent SCROLL

List of usage examples for javafx.scene.input ScrollEvent SCROLL

Introduction

In this page you can find the example usage for javafx.scene.input ScrollEvent SCROLL.

Prototype

EventType SCROLL

To view the source code for javafx.scene.input ScrollEvent SCROLL.

Click Source Link

Document

This event occurs when user performs a scrolling action such as rotating mouse wheel or dragging a finger over touch screen.

Usage

From source file:com.heliosdecompiler.helios.gui.view.editors.DisassemblerView.java

@Override
protected Node createView0(OpenedFile file, String path) {
    CodeArea codeArea = new CodeArea();

    if (controller instanceof KrakatauDisassemblerController) {
        ContextMenu contextMenu = new ContextMenu();

        MenuItem save = new MenuItem("Assemble");
        save.setOnAction(e -> {/* w ww. ja v a  2 s .  c  o m*/
            save(codeArea).whenComplete((res, err) -> {
                if (err != null) {
                    if (err instanceof KrakatauException) {
                        StringBuilder message = new StringBuilder();
                        message.append("stdout:\r\n").append(((KrakatauException) err).getStdout())
                                .append("\r\n\r\nstderr:\r\n").append(((KrakatauException) err).getStderr());

                        messageHandler.handleLongMessage(Message.ERROR_FAILED_TO_ASSEMBLE_KRAKATAU,
                                message.toString());
                    } else {
                        messageHandler.handleException(Message.ERROR_UNKNOWN_ERROR.format(), err);
                    }
                } else {
                    file.putContent(path, res);
                    messageHandler.handleMessage(Message.GENERIC_ASSEMBLED.format());
                }
            });
        });

        contextMenu.getItems().add(save);
        codeArea.setContextMenu(contextMenu);
    }

    codeArea.setStyle("-fx-font-size: 1em");
    codeArea.getProperties().put("fontSize", 1);

    codeArea.setParagraphGraphicFactory(line -> {
        Node label = LineNumberFactory.get(codeArea, (digits) -> "%1$" + digits + "d").apply(line);
        label.styleProperty().bind(codeArea.styleProperty());
        return label;
    });
    codeArea.replaceText("Disassembling... this may take a while");
    codeArea.getUndoManager().forgetHistory();

    codeArea.richChanges().filter(ch -> !ch.getInserted().equals(ch.getRemoved())) // XXX
            .successionEnds(Duration.ofMillis(500)).supplyTask(() -> computeHighlightingAsync(codeArea))
            .awaitLatest(codeArea.richChanges()).filterMap(t -> {
                if (t.isSuccess()) {
                    return Optional.of(t.get());
                } else {
                    t.getFailure().printStackTrace();
                    return Optional.empty();
                }
            }).subscribe(f -> applyHighlighting(codeArea, f));
    codeArea.getStylesheets().add(getClass().getResource("/java-keywords.css").toExternalForm());

    codeArea.addEventFilter(ScrollEvent.SCROLL, e -> {
        if (e.isShortcutDown()) {
            if (e.getDeltaY() > 0) {
                int size = (int) codeArea.getProperties().get("fontSize") + 1;
                codeArea.setStyle("-fx-font-size: " + size + "em");
                codeArea.getProperties().put("fontSize", size);
            } else {
                int size = (int) codeArea.getProperties().get("fontSize") - 1;
                if (size > 0) {
                    codeArea.setStyle("-fx-font-size: " + size + "em");
                    codeArea.getProperties().put("fontSize", size);
                }
            }
            e.consume();
        }
    });

    controller.disassemble(file, path, (success, text) -> {
        Platform.runLater(() -> {
            codeArea.replaceText(text);
            codeArea.getUndoManager().forgetHistory();
        });
    });

    return new VirtualizedScrollPane<>(codeArea);
}