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 com.sun.javafx.scene.layout.PaneHelper; 29 import javafx.beans.DefaultProperty; 30 import javafx.collections.ObservableList; 31 import javafx.scene.Node; 32 33 /** 34 * Base class for layout panes which need to expose the children list as public 35 * so that users of the subclass can freely add/remove children. 36 * <p> 37 * This class may be used directly in cases where absolute positioning of children 38 * is required since it does not perform layout beyond resizing resizable children 39 * to their preferred sizes. It is the application's responsibility to position the 40 * children since the pane leaves the positions alone during layout. 41 * For example: 42 * <pre><code> 43 * Pane canvas = new Pane(); 44 * canvas.setStyle("-fx-background-color: black;"); 45 * canvas.setPrefSize(200,200); 46 * Circle circle = new Circle(50,Color.BLUE); 47 * circle.relocate(20, 20); 48 * Rectangle rectangle = new Rectangle(100,100,Color.RED); 49 * rectangle.relocate(70,70); 50 * canvas.getChildren().addAll(circle,rectangle); 51 * </code></pre> 52 * <p> 53 * Note: if an application needs children to be kept aligned within a parent (centered, 54 * positioned at top-left, etc), it should use a {@link javafx.scene.layout.StackPane StackPane} 55 * instead.</p> 56 * 57 * <p> 58 * Pane resizes each managed child regardless of the child's visible property value; 59 * unmanaged children are ignored for all layout calculations.</p> 60 * 61 * <h4>Resizable Range</h4> 62 * 63 * A pane's parent will resize the pane within the pane's resizable range 64 * during layout. By default the pane computes this range based on its content 65 * as outlined in the tables below: 66 * 67 * <table border="1"> 68 * <tr><td></td><th>width</th><th>height</th></tr> 69 * <tr><th>minimum</th> 70 * <td>left plus right insets.</td> 71 * <td>top plus bottom insets.</td></tr> 72 * <tr><th>preferred</th> 73 * <td>width required to encompass each child at its current x location and preferred width.</td> 74 * <td>height required to encompass each child at its current y location and preferred height.</td></tr> 75 * <tr><th>maximum</th> 76 * <td>Double.MAX_VALUE</td><td>Double.MAX_VALUE</td></tr> 77 * </table> 78 * <p> 79 * A pane's unbounded maximum width and height are an indication to the parent that 80 * it may be resized beyond its preferred size to fill whatever space is assigned to it. 81 * <p> 82 * Pane provides properties for setting the size range directly. These 83 * properties default to the sentinel value Region.USE_COMPUTED_SIZE, however the 84 * application may set them to other values as needed: 85 * <pre><code> 86 * <b>pane.setPrefSize(500,400);</b> 87 * </code></pre> 88 * Applications may restore the computed values by setting these properties back 89 * to Region.USE_COMPUTED_SIZE. 90 * <p> 91 * Pane does not clip its content by default, so it is possible that childrens' 92 * bounds may extend outside its own bounds, either if children are positioned 93 * at negative coordinates or the pane is resized smaller than its preferred size.</p> 94 * 95 * @since JavaFX 2.0 96 */ 97 @DefaultProperty("children") 98 public class Pane extends Region { 99 static { 100 PaneHelper.setPaneAccessor(new PaneHelper.PaneAccessor() { 101 }); 102 } 103 104 static void setConstraint(Node node, Object key, Object value) { 105 if (value == null) { 106 node.getProperties().remove(key); 107 } else { 108 node.getProperties().put(key, value); 109 } 110 if (node.getParent() != null) { 111 node.getParent().requestLayout(); 112 } 113 } 114 115 static Object getConstraint(Node node, Object key) { 116 if (node.hasProperties()) { 117 Object value = node.getProperties().get(key); 118 if (value != null) { 119 return value; 120 } 121 } 122 return null; 123 } 124 125 { 126 // To initialize the class helper at the begining each constructor of this class 127 PaneHelper.initHelper(this); 128 } 129 /** 130 * Creates a Pane layout. 131 */ 132 public Pane() { 133 super(); 134 } 135 136 /** 137 * Creates a Pane layout. 138 * @param children The initial set of children for this pane. 139 * @since JavaFX 8.0 140 */ 141 public Pane(Node... children) { 142 super(); 143 getChildren().addAll(children); 144 } 145 146 /** 147 * 148 * @return modifiable list of children. 149 */ 150 @Override public ObservableList<Node> getChildren() { 151 return super.getChildren(); 152 } 153 154 }