Spec-Zone .ru
спецификации, руководства, описания, API
001/*
002 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025
026package javafx.scene.layout;
027
028import javafx.beans.DefaultProperty;
029import javafx.collections.ObservableList;
030import javafx.scene.Node;
031
032/**
033 * Base class for layout panes which need to expose the children list as public
034 * so that users of the subclass can freely add/remove children.
035 * <p>
036 * This class may be used directly in cases where absolute positioning of children 
037 * is required since it does not perform layout beyond resizing resizable children
038 * to their preferred sizes. It is the application's responsibility to position the
039 * children since the pane leaves the positions alone during layout.
040 * For example:
041 * <pre><code>
042 *     Pane canvas = new Pane();
043 *     canvas.setStyle("-fx-background-color: black;");
044 *     canvas.setPrefSize(200,200);
045 *     Circle circle = new Circle(50,Color.BLUE);
046 *     circle.relocate(20, 20);
047 *     Rectangle rectangle = new Rectangle(100,100,Color.RED);
048 *     rectangle.relocate(70,70);
049 *     canvas.getChildren().addAll(circle,rectangle);
050 * </code></pre>
051 * <p>
052 * Note: if an application needs children to be kept aligned within a parent (centered,
053 * positioned at top-left, etc), it should use a {@link javafx.scene.layout.StackPane StackPane}
054 * instead.</p>
055 *
056 * <p>
057 * Pane resizes each managed child regardless of the child's visible property value;
058 * unmanaged children are ignored for all layout calculations.</p>
059 * 
060 * <h4>Resizable Range</h4>
061 * 
062 * A pane's parent will resize the pane within the pane's resizable range
063 * during layout.   By default the pane computes this range based on its content
064 * as outlined in the tables below:
065 *
066 * <table border="1">
067 * <tr><td></td><th>width</th><th>height</th></tr>
068 * <tr><th>minimum</th>
069 * <td>left plus right insets.</td>
070 * <td>top plus bottom insets.</td></tr>
071 * <tr><th>preferred</th>
072 * <td>width required to encompass each child at its current x location and preferred width.</td>
073 * <td>height required to encompass each child at its current y location and preferred height.</td></tr>
074 * <tr><th>maximum</th>
075 * <td>Double.MAX_VALUE</td><td>Double.MAX_VALUE</td></tr>
076 * </table>
077 * <p>
078 * A pane's unbounded maximum width and height are an indication to the parent that
079 * it may be resized beyond its preferred size to fill whatever space is assigned to it.
080 * <p>
081 * Pane provides properties for setting the size range directly.  These
082 * properties default to the sentinel value Region.USE_COMPUTED_SIZE, however the
083 * application may set them to other values as needed:
084 * <pre><code>
085 *     <b>pane.setPrefSize(500,400);</b>
086 * </code></pre>
087 * Applications may restore the computed values by setting these properties back
088 * to Region.USE_COMPUTED_SIZE.
089 * <p>
090 * Pane does not clip its content by default, so it is possible that childrens'
091 * bounds may extend outside its own bounds, either if children are positioned
092 * at negative coordinates or the pane is resized smaller than its preferred size.</p>
093 * 
094 */
095@DefaultProperty("children")
096public class Pane extends Region {
097
098    static void setConstraint(Node node, Object key, Object value) {
099        if (value == null) {
100            node.getProperties().remove(key);
101        } else {
102            node.getProperties().put(key, value);
103        }
104        if (node.getParent() != null) {
105            node.getParent().requestLayout();
106        }
107    }
108
109    static Object getConstraint(Node node, Object key) {
110        if (node.hasProperties()) {
111            Object value = node.getProperties().get(key);
112            if (value != null) {
113                return value;
114            }
115        }
116        return null;
117    }
118
119    /**
120     * Creates a Pane layout.
121     */
122    public Pane() {
123        super();
124    }
125
126    /**
127     * Creates a Pane layout.
128     * @param children The initial set of children for this pane.
129     */
130    public Pane(Node... children) {
131        super();
132        getChildren().addAll(children);
133    }
134
135    /**
136     *
137     * @return modifiable list of children.
138     */
139    @Override public ObservableList<Node> getChildren() {
140        return super.getChildren();
141    }
142
143}