1 /* 2 * Copyright (c) 2011, 2017, 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 * }</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 * <h3>Resizable Range</h3> 62 * 63 * <p> 64 * A pane's parent will resize the pane within the pane's resizable range 65 * during layout. By default the pane computes this range based on its content 66 * as outlined in the table below: 67 * </p> 68 * 69 * <table border="1"> 70 * <caption>Pane Resize Table</caption> 71 * <tr><td></td><th scope="col">width</th><th scope="col">height</th></tr> 72 * <tr><th scope="row">minimum</th> 73 * <td>left plus right insets.</td> 74 * <td>top plus bottom insets.</td></tr> 75 * <tr><th scope="row">preferred</th> 76 * <td>width required to encompass each child at its current x location and preferred width.</td> 77 * <td>height required to encompass each child at its current y location and preferred height.</td></tr> 78 * <tr><th scope="row">maximum</th> 79 * <td>Double.MAX_VALUE</td><td>Double.MAX_VALUE</td></tr> 80 * </table> 81 * <p> 82 * A pane's unbounded maximum width and height are an indication to the parent that 83 * it may be resized beyond its preferred size to fill whatever space is assigned to it. 84 * <p> 85 * Pane provides properties for setting the size range directly. These 86 * properties default to the sentinel value Region.USE_COMPUTED_SIZE, however the 87 * application may set them to other values as needed: 88 * <pre><code> 89 * <b>pane.setPrefSize(500,400);</b> 90 * </code></pre> 91 * Applications may restore the computed values by setting these properties back 92 * to Region.USE_COMPUTED_SIZE. 93 * <p> 94 * Pane does not clip its content by default, so it is possible that children's 95 * bounds may extend outside its own bounds, either if children are positioned 96 * at negative coordinates or the pane is resized smaller than its preferred size.</p> 97 * 98 * @since JavaFX 2.0 99 */ 100 @DefaultProperty("children") 101 public class Pane extends Region { 102 static { 103 PaneHelper.setPaneAccessor(new PaneHelper.PaneAccessor() { 104 }); 105 } 106 107 static void setConstraint(Node node, Object key, Object value) { 108 if (value == null) { 109 node.getProperties().remove(key); 110 } else { 111 node.getProperties().put(key, value); 112 } 113 if (node.getParent() != null) { 114 node.getParent().requestLayout(); 115 } 116 } 117 118 static Object getConstraint(Node node, Object key) { 119 if (node.hasProperties()) { 120 Object value = node.getProperties().get(key); 121 if (value != null) { 122 return value; 123 } 124 } 125 return null; 126 } 127 128 { 129 // To initialize the class helper at the begining each constructor of this class 130 PaneHelper.initHelper(this); 131 } 132 /** 133 * Creates a Pane layout. 134 */ 135 public Pane() { 136 super(); 137 } 138 139 /** 140 * Creates a Pane layout. 141 * @param children The initial set of children for this pane. 142 * @since JavaFX 8.0 143 */ 144 public Pane(Node... children) { 145 super(); 146 getChildren().addAll(children); 147 } 148 149 /** 150 * 151 * @return modifiable list of children. 152 */ 153 @Override public ObservableList<Node> getChildren() { 154 return super.getChildren(); 155 } 156 157 }