1 /* 2 * Copyright (c) 2008, 2014, Oracle and/or its affiliates. 3 * All rights reserved. Use is subject to license terms. 4 * 5 * This file is available and licensed under the following license: 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * - Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * - Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the distribution. 16 * - Neither the name of Oracle Corporation nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 package ensemble.samples.scenegraph.nodeproperties; 33 34 import javafx.application.Application; 35 import javafx.scene.Parent; 36 import javafx.scene.Scene; 37 import javafx.scene.layout.Pane; 38 import javafx.scene.paint.Color; 39 import javafx.scene.shape.Rectangle; 40 import javafx.stage.Stage; 41 42 /** 43 * A sample that demonstrates some properties of nodes. Use the radio buttons 44 * to send any of the rectangles to the front or back. Use the controls to 45 * change opacity or horizontal position. 46 * 47 * @sampleName Node Properties 48 * @preview preview.png 49 * @see javafx.scene.Node 50 * @see javafx.scene.layout.Pane 51 * @see javafx.scene.paint.Color 52 * @see javafx.scene.shape.Rectangle 53 * @playground rectA.translateX (name="Rectangle A translate X", min=0, max=50) 54 * @playground rectB.translateX (name="Rectangle B translate X", min=0, max=50) 55 * @playground rectC.translateX (name="Rectangle C translate X", min=0, max=50) 56 * @playground rectA.opacity (name="Rectangle A Opacity", min=0, max=1) 57 * @playground rectB.opacity (name="Rectangle B Opacity", min=0, max=1) 58 * @playground rectC.opacity (name="Rectangle C Opacity", min=0, max=1) 59 * 60 * @related /Scenegraph/Custom Node 61 * @related /Graphics 2d/Shapes/Rectangle 62 * @related /Scenegraph/Stage 63 */ 64 public class NodePropertiesApp extends Application { 65 66 private Rectangle rectA; 67 private Rectangle rectB; 68 private Rectangle rectC; 69 70 public Parent createContent() { 71 72 //X position of node = X + LayoutX + TranslateX 73 rectA = new Rectangle(50, 50, Color.LIGHTSALMON); 74 //set position of node temporary (can be changed after) 75 rectA.setTranslateX(10); 76 77 rectB = new Rectangle(50, 50, Color.LIGHTGREEN); 78 //set position of node when addinf to some layout 79 rectB.setLayoutX(20); 80 rectB.setLayoutY(10); 81 82 rectC = new Rectangle(50, 50, Color.DODGERBLUE); 83 //last posibility of setting X position of node 84 rectC.setX(30); 85 rectC.setY(20); 86 //opacity of node can be set 87 rectC.setOpacity(0.8); 88 89 Pane root = new Pane(rectA, rectB, rectC); 90 root.setPrefSize(130, 100); 91 root.setMinSize(130, 100); 92 root.setMaxSize(130, 100); 93 94 return root; 95 } 96 97 @Override 98 public void start(Stage primaryStage) throws Exception { 99 primaryStage.setScene(new Scene(createContent())); 100 primaryStage.show(); 101 } 102 103 /** 104 * Java main for when running without JavaFX launcher 105 * @param args command line arguments 106 */ 107 public static void main(String[] args) { 108 launch(args); 109 } 110 }