Example usage for javafx.scene SubScene SubScene

List of usage examples for javafx.scene SubScene SubScene

Introduction

In this page you can find the example usage for javafx.scene SubScene SubScene.

Prototype

public SubScene(@NamedArg("root") Parent root, @NamedArg("width") double width,
        @NamedArg("height") double height, @NamedArg("depthBuffer") boolean depthBuffer,
        @NamedArg("antiAliasing") SceneAntialiasing antiAliasing) 

Source Link

Document

Constructs a SubScene consisting of a root, with a dimension of width and height, specifies whether a depth buffer is created for this scene and specifies whether scene anti-aliasing is requested.

Usage

From source file:eu.mihosoft.vrl.fxscad.MainController.java

/**
 * Initializes the controller class.//ww  w .j a  v a  2s.com
 *
 * @param url
 * @param rb
 */
@Override
public void initialize(URL url, ResourceBundle rb) {

    //
    codeArea.textProperty().addListener((ov, oldText, newText) -> {
        Matcher matcher = KEYWORD_PATTERN.matcher(newText);
        int lastKwEnd = 0;
        StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
        while (matcher.find()) {
            spansBuilder.add(Collections.emptyList(), matcher.start() - lastKwEnd);
            spansBuilder.add(Collections.singleton("keyword"), matcher.end() - matcher.start());
            lastKwEnd = matcher.end();
        }
        spansBuilder.add(Collections.emptyList(), newText.length() - lastKwEnd);
        codeArea.setStyleSpans(0, spansBuilder.create());
    });

    EventStream<Change<String>> textEvents = EventStreams.changesOf(codeArea.textProperty());

    textEvents.reduceSuccessions((a, b) -> b, Duration.ofMillis(500)).subscribe(code -> {
        if (autoCompile) {
            compile(code.getNewValue());
        }
    });

    codeArea.replaceText("CSG cube = new Cube(2).toCSG()\n" + "CSG sphere = new Sphere(1.25).toCSG()\n" + "\n"
            + "cube.difference(sphere)");

    editorContainer.setContent(codeArea);

    subScene = new SubScene(viewGroup, 100, 100, true, SceneAntialiasing.BALANCED);

    subScene.widthProperty().bind(viewContainer.widthProperty());
    subScene.heightProperty().bind(viewContainer.heightProperty());

    PerspectiveCamera subSceneCamera = new PerspectiveCamera(false);
    subScene.setCamera(subSceneCamera);

    viewContainer.getChildren().add(subScene);
}

From source file:be.makercafe.apps.makerbench.editors.JFXScadEditor.java

public JFXScadEditor(String tabText, Path path) {
    super(tabText);

    this.viewGroup = new Group();
    this.editorContainer = new BorderPane();
    this.viewContainer = new Pane();

    this.caCodeArea = new CodeArea("");
    this.caCodeArea.setEditable(true);
    this.caCodeArea.setParagraphGraphicFactory(LineNumberFactory.get(caCodeArea));
    this.caCodeArea.setPrefSize(Double.MAX_VALUE, Double.MAX_VALUE);

    this.caCodeArea.getStylesheets().add(this.getClass().getResource("java-keywords.css").toExternalForm());
    this.caCodeArea.richChanges().subscribe(change -> {
        caCodeArea.setStyleSpans(0, computeHighlighting(caCodeArea.getText()));
    });// w w  w  . j  a v  a  2  s. c o  m

    addContextMenu(this.caCodeArea);
    EventStream<Change<String>> textEvents = EventStreams.changesOf(caCodeArea.textProperty());

    textEvents.reduceSuccessions((a, b) -> b, Duration.ofMillis(3000)).subscribe(code -> {
        if (autoCompile) {
            compile(code.getNewValue());
        }
    });

    if (path == null) {
        this.caCodeArea.replaceText("CSG cube = new Cube(2).toCSG()\n"
                + "CSG sphere = new Sphere(1.25).toCSG()\n" + "\n" + "cube.difference(sphere)");
    } else {
        try {
            this.caCodeArea.replaceText(FileUtils.readFileToString(path.toFile()));
        } catch (IOException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error reading file.", ex);
        }

    }

    //editorContainer.setCenter(this.codeArea);

    subScene = new SubScene(viewGroup, 100, 100, true, SceneAntialiasing.BALANCED);

    subScene.widthProperty().bind(viewContainer.widthProperty());
    subScene.heightProperty().bind(viewContainer.heightProperty());

    PerspectiveCamera subSceneCamera = new PerspectiveCamera(false);
    subScene.setCamera(subSceneCamera);

    viewContainer.getChildren().add(subScene);

    SplitPane editorPane = new SplitPane(caCodeArea, viewContainer);
    editorPane.setOrientation(Orientation.HORIZONTAL);
    BorderPane rootPane = new BorderPane();

    BorderPane pane = (BorderPane) this.getTab().getContent();
    toolBar = createToolBar();
    rootPane.setTop(toolBar);
    rootPane.setCenter(editorPane);
    this.getTab().setContent(rootPane);

    subScene.setOnScroll(new EventHandler<ScrollEvent>() {
        @Override
        public void handle(ScrollEvent event) {
            System.out
                    .println(String.format("deltaX: %.3f deltaY: %.3f", event.getDeltaX(), event.getDeltaY()));

            double z = subSceneCamera.getTranslateZ();
            double newZ = z + event.getDeltaY();
            subSceneCamera.setTranslateZ(newZ);

        }
    });

}

From source file:be.makercafe.apps.makerbench.editors.GCodeEditor.java

public GCodeEditor(String tabText, Path path) {
    super(tabText);

    this.viewGroup = new Group();
    this.editorContainer = new BorderPane();
    this.viewContainer = new Pane();

    this.caCodeArea = new CodeArea("");
    this.caCodeArea.setEditable(true);
    this.caCodeArea.setParagraphGraphicFactory(LineNumberFactory.get(caCodeArea));
    this.caCodeArea.setPrefSize(Double.MAX_VALUE, Double.MAX_VALUE);

    // this.caCodeArea.getStylesheets().add(this.getClass().getResource("java-keywords.css").toExternalForm());
    // this.caCodeArea.richChanges().subscribe(change -> {
    // caCodeArea.setStyleSpans(0,
    // computeHighlighting(caCodeArea.getText()));
    // });//from ww  w . j  a va2 s. co  m

    addContextMenu(this.caCodeArea);
    EventStream<Change<String>> textEvents = EventStreams.changesOf(caCodeArea.textProperty());

    textEvents.reduceSuccessions((a, b) -> b, Duration.ofMillis(3000)).subscribe(code -> {
        if (autoCompile) {
            compile(code.getNewValue());
        }
    });

    if (path == null) {
        this.caCodeArea.replaceText("#empty");
    } else {
        try {
            this.caCodeArea.replaceText(FileUtils.readFileToString(path.toFile()));
        } catch (IOException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error reading file.", ex);
        }

    }

    // editorContainer.setCenter(this.codeArea);

    subScene = new SubScene(viewGroup, 100, 100, true, SceneAntialiasing.BALANCED);

    subScene.widthProperty().bind(viewContainer.widthProperty());
    subScene.heightProperty().bind(viewContainer.heightProperty());

    PerspectiveCamera subSceneCamera = new PerspectiveCamera(false);
    subScene.setCamera(subSceneCamera);

    viewContainer.getChildren().add(subScene);

    SplitPane editorPane = new SplitPane(caCodeArea, viewContainer);
    editorPane.setOrientation(Orientation.HORIZONTAL);
    BorderPane rootPane = new BorderPane();

    BorderPane pane = (BorderPane) this.getTab().getContent();
    toolBar = createToolBar();
    rootPane.setTop(toolBar);
    rootPane.setCenter(editorPane);
    this.getTab().setContent(rootPane);

    subScene.setOnScroll(new EventHandler<ScrollEvent>() {
        @Override
        public void handle(ScrollEvent event) {
            System.out
                    .println(String.format("deltaX: %.3f deltaY: %.3f", event.getDeltaX(), event.getDeltaY()));

            double z = subSceneCamera.getTranslateZ();
            double newZ = z + event.getDeltaY();
            subSceneCamera.setTranslateZ(newZ);

        }
    });

}