import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.PerspectiveCamera; import javafx.scene.PointLight; import javafx.scene.Scene; import javafx.scene.SubScene; import javafx.scene.control.ColorPicker; import javafx.scene.control.ScrollBar; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.paint.PhongMaterial; import javafx.scene.shape.Box; import javafx.scene.shape.Sphere; import javafx.stage.Stage; /* * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. */ /** * * @author Andrew Glushchenko */ public class SubSceneSetFillTestApp extends Application { protected static int WIDTH = 600; protected static int HEIGHT = 600; protected static int SS_WIDTH = 300; protected static int SS_HEIGHT = 300; protected static int SCALE = 100; private static int scenesCount = 3; private Scene scene; private GridPane gridRoot; private SubScene[] scenes = new SubScene[scenesCount]; private AnchorPane controlsBox; private Group rootTL; private Group rootTR; private Group rootDL; private Stage stage; @Override public void start(Stage stage) throws Exception { this.stage = stage; reinitScene(); stage.show(); } public void reinitScene(){ initScene(); stage.setScene(scene); } protected SubScene getTopLeftScene() { rootTL = new Group(buildGroup()); rootTL.translateXProperty().set(SS_WIDTH / 2); rootTL.translateYProperty().set(SS_HEIGHT / 2); SubScene ss = new SubScene(rootTL, SS_WIDTH, SS_HEIGHT, true, true); ss.setCamera(new PerspectiveCamera()); return ss; } protected SubScene getTopRightScene() { rootTR = new Group(buildGroup()); rootTR.translateXProperty().set(SS_WIDTH / 2); rootTR.translateYProperty().set(SS_HEIGHT / 2); SubScene ss = new SubScene(rootTR, SS_WIDTH, SS_HEIGHT, true, true); ss.setCamera(new PerspectiveCamera()); return ss; } protected SubScene getDownLeftScene() { rootDL = new Group(buildGroup()); rootDL.translateXProperty().set(SS_WIDTH / 2); rootDL.translateYProperty().set(SS_HEIGHT / 2); SubScene ss = new SubScene(rootDL, SS_WIDTH, SS_HEIGHT, true, true); ss.setCamera(new PerspectiveCamera()); return ss; } private static Group buildGroup() { Group grp = new Group(); Sphere s = new Sphere(); Box b = new Box(); s.setScaleX(SCALE); s.setScaleY(SCALE); s.setScaleZ(SCALE); s.setTranslateX(-100); b.setScaleX(SCALE); b.setScaleY(SCALE); b.setScaleZ(SCALE); b.setTranslateX(100); PhongMaterial material = new PhongMaterial(); material.setDiffuseColor(Color.LIGHTGRAY); material.setSpecularColor(Color.rgb(30, 30, 30)); s.setMaterial(material); b.setMaterial(material); PointLight pl = new PointLight(Color.AQUA); pl.setTranslateZ(-1000); grp.getChildren().addAll(s, b, pl); return grp; } protected void initScene() { gridRoot = new GridPane(); scenes[0] = getTopLeftScene(); scenes[1] = getTopRightScene(); scenes[2] = getDownLeftScene(); gridRoot.add(scenes[0], 0, 0); gridRoot.add(scenes[1], 0, 1); gridRoot.add(scenes[2], 1, 0); gridRoot.add(buildControlsBox(), 1, 1); scene = new Scene(gridRoot, WIDTH, HEIGHT, true); } private Node buildControlsBox() { controlsBox = new AnchorPane(); TabPane tp = new TabPane(); AnchorPane.setTopAnchor(tp, 0D); AnchorPane.setRightAnchor(tp, 0D); AnchorPane.setLeftAnchor(tp, 0D); AnchorPane.setBottomAnchor(tp, 0D); controlsBox.getChildren().add(tp); for (int i = 0; i < 3; i++) { tp.getTabs().add(buildTab(i)); } return controlsBox; } private Tab buildTab(final int i) { Tab tab = new Tab("SubScene" + i); ColorPicker fillPicker = new ColorPicker(); fillPicker.setValue((Color) scenes[i].getFill()); fillPicker.valueProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue ov, Color t, Color t1) { scenes[i].setFill(t1); } }); VBox content = new VBox(); content.getChildren().addAll(fillPicker); tab.setContent(content); return tab; } public static void main(String[] args) { launch(args); } }