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 controls to 44 * change opacity or horizontal position. 45 * 46 * @sampleName Node Properties 47 * @preview preview.png 48 * @see javafx.scene.Node 49 * @see javafx.scene.layout.Pane 50 * @see javafx.scene.paint.Color 51 * @see javafx.scene.shape.Rectangle 52 * @playground rectA.translateX (name="Rectangle A translate X", min=0, max=50) 53 * @playground rectB.translateX (name="Rectangle B translate X", min=0, max=50) 54 * @playground rectC.translateX (name="Rectangle C translate X", min=0, max=50) 55 * @playground rectA.opacity (name="Rectangle A Opacity", min=0, max=1) 56 * @playground rectB.opacity (name="Rectangle B Opacity", min=0, max=1) 57 * @playground rectC.opacity (name="Rectangle C Opacity", min=0, max=1) 58 * 59 * @related /Scenegraph/Custom Node 60 * @related /Graphics 2d/Shapes/Rectangle 61 * @related /Scenegraph/Stage 62 */ 63 public class NodePropertiesApp extends Application { 64 65 private Rectangle rectA; 66 private Rectangle rectB; 67 private Rectangle rectC; 68 69 public Parent createContent() { 70 71 //X position of node = X + LayoutX + TranslateX 72 rectA = new Rectangle(50, 50, Color.LIGHTSALMON); 73 //set position of node temporary (can be changed after) 74 rectA.setTranslateX(10); 75 76 rectB = new Rectangle(50, 50, Color.LIGHTGREEN); 77 //set position of node when addinf to some layout 78 rectB.setLayoutX(20); 79 rectB.setLayoutY(10); 80 81 rectC = new Rectangle(50, 50, Color.DODGERBLUE); 82 //last posibility of setting X position of node 83 rectC.setX(30); 84 rectC.setY(20); 85 //opacity of node can be set 86 rectC.setOpacity(0.8); 87 88 Pane root = new Pane(rectA, rectB, rectC); 89 root.setPrefSize(130, 100); 90 root.setMinSize(130, 100); 91 root.setMaxSize(130, 100); 92 93 return root; 94 } 95 96 @Override 97 public void start(Stage primaryStage) throws Exception { 98 primaryStage.setScene(new Scene(createContent())); 99 primaryStage.show(); 100 } 101 102 /** 103 * Java main for when running without JavaFX launcher 104 * @param args command line arguments 105 */ 106 public static void main(String[] args) { 107 launch(args); 108 } 109 }