1 /* 2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javafx.scene.layout; 27 28 import javafx.beans.DefaultProperty; 29 import javafx.collections.ObservableList; 30 import javafx.scene.Node; 31 32 /** 33 * Base class for layout panes which need to expose the children list as public 34 * so that users of the subclass can freely add/remove children. 35 * <p> 36 * This class may be used directly in cases where absolute positioning of children 37 * is required since it does not perform layout beyond resizing resizable children 38 * to their preferred sizes. It is the application's responsibility to position the 39 * children since the pane leaves the positions alone during layout. 40 * For example: 41 * <pre><code> 42 * Pane canvas = new Pane(); 43 * canvas.setStyle("-fx-background-color: black;"); 44 * canvas.setPrefSize(200,200); 45 * Circle circle = new Circle(50,Color.BLUE); 46 * circle.relocate(20, 20); 47 * Rectangle rectangle = new Rectangle(100,100,Color.RED); 48 * rectangle.relocate(70,70); 49 * canvas.getChildren().addAll(circle,rectangle); 50 * </code></pre> 51 * <p> 52 * Note: if an application needs children to be kept aligned within a parent (centered, 53 * positioned at top-left, etc), it should use a {@link javafx.scene.layout.StackPane StackPane} 54 * instead.</p> 55 * 56 * <p> 57 * Pane resizes each managed child regardless of the child's visible property value; 58 * unmanaged children are ignored for all layout calculations.</p> 59 * 60 * <h4>Resizable Range</h4> 61 * 62 * A pane's parent will resize the pane within the pane's resizable range 63 * during layout. By default the pane computes this range based on its content 64 * as outlined in the tables below: 65 * 66 * <table border="1"> 67 * <tr><td></td><th>width</th><th>height</th></tr> 68 * <tr><th>minimum</th> 69 * <td>left plus right insets.</td> 70 * <td>top plus bottom insets.</td></tr> 71 * <tr><th>preferred</th> 72 * <td>width required to encompass each child at its current x location and preferred width.</td> 73 * <td>height required to encompass each child at its current y location and preferred height.</td></tr> 74 * <tr><th>maximum</th> 75 * <td>Double.MAX_VALUE</td><td>Double.MAX_VALUE</td></tr> 76 * </table> 77 * <p> 78 * A pane's unbounded maximum width and height are an indication to the parent that 79 * it may be resized beyond its preferred size to fill whatever space is assigned to it. 80 * <p> 81 * Pane provides properties for setting the size range directly. These 82 * properties default to the sentinel value Region.USE_COMPUTED_SIZE, however the 83 * application may set them to other values as needed: 84 * <pre><code> 85 * <b>pane.setPrefSize(500,400);</b> 86 * </code></pre> 87 * Applications may restore the computed values by setting these properties back 88 * to Region.USE_COMPUTED_SIZE. 89 * <p> 90 * Pane does not clip its content by default, so it is possible that childrens' 91 * bounds may extend outside its own bounds, either if children are positioned 92 * at negative coordinates or the pane is resized smaller than its preferred size.</p> 93 * 94 * @since JavaFX 2.0 95 */ 96 @DefaultProperty("children") 97 public class Pane extends Region { 98 99 static void setConstraint(Node node, Object key, Object value) { 100 if (value == null) { 101 node.getProperties().remove(key); 102 } else { 103 node.getProperties().put(key, value); 104 } 105 if (node.getParent() != null) { 106 node.getParent().requestLayout(); 107 } 108 } 109 110 static Object getConstraint(Node node, Object key) { 111 if (node.hasProperties()) { 112 Object value = node.getProperties().get(key); 113 if (value != null) { 114 return value; 115 } 116 } 117 return null; 118 } 119 120 /** 121 * Creates a Pane layout. 122 */ 123 public Pane() { 124 super(); 125 } 126 127 /** 128 * Creates a Pane layout. 129 * @param children The initial set of children for this pane. 130 * @since JavaFX 8.0 131 */ 132 public Pane(Node... children) { 133 super(); 134 getChildren().addAll(children); 135 } 136 137 /** 138 * 139 * @return modifiable list of children. 140 */ 141 @Override public ObservableList<Node> getChildren() { 142 return super.getChildren(); 143 } 144 145 }