Spec-Zone .ru
спецификации, руководства, описания, API
|
001/* 002 * Copyright (c) 2010, 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.control; 027 028import java.util.ArrayList; 029import java.util.Collections; 030import java.util.List; 031 032import javafx.beans.property.BooleanProperty; 033import javafx.beans.property.BooleanPropertyBase; 034import javafx.beans.property.ObjectProperty; 035import javafx.beans.property.SimpleObjectProperty; 036import javafx.scene.Node; 037 038import javafx.css.PseudoClass; 039import javafx.css.StyleableBooleanProperty; 040import javafx.css.CssMetaData; 041import com.sun.javafx.css.converters.BooleanConverter; 042import com.sun.javafx.scene.control.skin.TitledPaneSkin; 043import javafx.beans.DefaultProperty; 044import javafx.css.Styleable; 045import javafx.css.StyleableProperty; 046 047/** 048 * <p>A TitledPane is a panel with a title that can be opened and closed.</p> 049 * 050 * <p>The panel in a TitledPane can be any {@link Node} such as UI controls or groups 051 * of nodes added to a layout container.</p> 052 * 053 * <p>It is not recommended to set the MinHeight, PrefHeight, or MaxHeight 054 * for this control. Unexpected behavior will occur because the 055 * TitledPane's height changes when it is opened or closed.</p> 056 * 057 * <p>Example:</p> 058 * <pre><code> 059 * TitledPane t1 = new TitledPane("T1", new Button("B1")); 060 * t1.setMode(TitledPaneMode.FADE); 061 * </code></pre> 062 * 063 */ 064@DefaultProperty("content") 065public class TitledPane extends Labeled { 066 067 /*************************************************************************** 068 * * 069 * Constructors * 070 * * 071 **************************************************************************/ 072 073 /** 074 * Creates a new TitledPane with no title or content. 075 */ 076 public TitledPane() { 077 getStyleClass().setAll(DEFAULT_STYLE_CLASS); 078 079 // initialize pseudo-class state 080 pseudoClassStateChanged(PSEUDO_CLASS_EXPANDED, true); 081 } 082 083 /** 084 * Creates a new TitledPane with a title and content. 085 * @param title The title of the TitledPane. 086 * @param content The content of the TitledPane. 087 */ 088 public TitledPane(String title, Node content) { 089 this(); 090 setText(title); 091 setContent(content); 092 } 093 094 095 /*************************************************************************** 096 * * 097 * Properties * 098 * * 099 **************************************************************************/ 100 101 // --- Content 102 private ObjectProperty<Node> content; 103 104 /** 105 * <p> The content of the TitlePane which can be any Node 106 * such as UI controls or groups of nodes added to a layout container. 107 * 108 * @param value The content for this TitlePane. 109 */ 110 public final void setContent(Node value) { 111 contentProperty().set(value); 112 } 113 114 /** 115 * The content of the TitledPane. {@code Null} is returned when 116 * if there is no content. 117 * 118 * @return The content of this TitledPane. 119 */ 120 public final Node getContent() { 121 return content == null ? null : content.get(); 122 } 123 124 /** 125 * The content of the TitledPane. 126 * 127 * @return The content of the TitlePane. 128 */ 129 public final ObjectProperty<Node> contentProperty() { 130 if (content == null) { 131 content = new SimpleObjectProperty<Node>(this, "content"); 132 } 133 return content; 134 } 135 136 137 // --- Expanded 138 private BooleanProperty expanded = new BooleanPropertyBase(true) { 139 @Override protected void invalidated() { 140 final boolean active = get(); 141 pseudoClassStateChanged(PSEUDO_CLASS_EXPANDED, active); 142 pseudoClassStateChanged(PSEUDO_CLASS_COLLAPSED, !active); 143 } 144 145 @Override 146 public Object getBean() { 147 return TitledPane.this; 148 } 149 150 @Override 151 public String getName() { 152 return "expanded"; 153 } 154 }; 155 156 /** 157 * Sets the expanded state of the TitledPane. The default is {@code true}. 158 * 159 */ 160 public final void setExpanded(boolean value) { expandedProperty().set(value); } 161 162 /* 163 * Returns the expanded state of the TitledPane. 164 * 165 * @return The expanded state of the TitledPane. 166 */ 167 public final boolean isExpanded() { return expanded.get(); } 168 169 /** 170 * The expanded state of the TitledPane. 171 */ 172 public final BooleanProperty expandedProperty() { return expanded; } 173 174 175 // --- Animated 176 private BooleanProperty animated = new StyleableBooleanProperty(true) { 177 178 @Override 179 public Object getBean() { 180 return TitledPane.this; 181 } 182 183 @Override 184 public String getName() { 185 return "animated"; 186 } 187 188 @Override 189 public CssMetaData<TitledPane,Boolean> getCssMetaData() { 190 return StyleableProperties.ANIMATED; 191 } 192 193 }; 194 195 /** 196 * Specifies how the TitledPane should open and close. The panel will be 197 * animated out when this value is set to {@code true}. The default is {@code true}. 198 * 199 */ 200 public final void setAnimated(boolean value) { animatedProperty().set(value); } 201 202 /** 203 * Returns the animated state of the TitledPane. 204 * 205 * @return The animated state of the TitledPane. 206 */ 207 public final boolean isAnimated() { return animated.get(); } 208 209 /** 210 * The animated state of the TitledPane. 211 */ 212 public final BooleanProperty animatedProperty() { return animated; } 213 214 215 // --- Collapsible 216 private BooleanProperty collapsible = new StyleableBooleanProperty(true) { 217 218 @Override 219 public Object getBean() { 220 return TitledPane.this; 221 } 222 223 @Override 224 public String getName() { 225 return "collapsible"; 226 } 227 228 @Override 229 public CssMetaData<TitledPane,Boolean> getCssMetaData() { 230 return StyleableProperties.COLLAPSIBLE; 231 } 232 233 }; 234 235 /** 236 * Specifies if the TitledPane can be collapsed. The default is {@code true}. 237 * 238 */ 239 public final void setCollapsible(boolean value) { collapsibleProperty().set(value); } 240 241 /** 242 * Returns the collapsible state of the TitlePane. 243 * 244 * @return The collapsible state of the TitledPane. 245 */ 246 public final boolean isCollapsible() { return collapsible.get(); } 247 248 /** 249 * The collapsible state of the TitledPane. 250 */ 251 public final BooleanProperty collapsibleProperty() { return collapsible; } 252 253 /*************************************************************************** 254 * * 255 * Methods * 256 * * 257 **************************************************************************/ 258 259 /** {@inheritDoc} */ 260 @Override protected Skin<?> createDefaultSkin() { 261 return new TitledPaneSkin(this); 262 } 263 264 /*************************************************************************** 265 * * 266 * Stylesheet Handling * 267 * * 268 **************************************************************************/ 269 270 private static final String DEFAULT_STYLE_CLASS = "titled-pane"; 271 272 private static final PseudoClass PSEUDO_CLASS_EXPANDED = 273 PseudoClass.getPseudoClass("expanded"); 274 private static final PseudoClass PSEUDO_CLASS_COLLAPSED = 275 PseudoClass.getPseudoClass("collapsed"); 276 277 278 private static class StyleableProperties { 279 280 private static final CssMetaData<TitledPane,Boolean> COLLAPSIBLE = 281 new CssMetaData<TitledPane,Boolean>("-fx-collapsible", 282 BooleanConverter.getInstance(), Boolean.TRUE) { 283 284 @Override 285 public boolean isSettable(TitledPane n) { 286 return n.collapsible == null || !n.collapsible.isBound(); 287 } 288 289 @Override 290 public StyleableProperty<Boolean> getStyleableProperty(TitledPane n) { 291 return (StyleableProperty<Boolean>)n.collapsibleProperty(); 292 } 293 }; 294 295 private static final CssMetaData<TitledPane,Boolean> ANIMATED = 296 new CssMetaData<TitledPane,Boolean>("-fx-animated", 297 BooleanConverter.getInstance(), Boolean.TRUE) { 298 299 @Override 300 public boolean isSettable(TitledPane n) { 301 return n.animated == null || !n.animated.isBound(); 302 } 303 304 @Override 305 public StyleableProperty<Boolean> getStyleableProperty(TitledPane n) { 306 return (StyleableProperty<Boolean>)n.animatedProperty(); 307 } 308 }; 309 310 private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES; 311 static { 312 final List<CssMetaData<? extends Styleable, ?>> styleables = 313 new ArrayList<CssMetaData<? extends Styleable, ?>>(Labeled.getClassCssMetaData()); 314 styleables.add(COLLAPSIBLE); 315 styleables.add(ANIMATED); 316 STYLEABLES = Collections.unmodifiableList(styleables); 317 } 318 } 319 320 /** 321 * @return The CssMetaData associated with this class, which may include the 322 * CssMetaData of its super classes. 323 */ 324 public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() { 325 return StyleableProperties.STYLEABLES; 326 } 327 328 /** 329 * {@inheritDoc} 330 */ 331 @Override 332 public List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData() { 333 return getClassCssMetaData(); 334 } 335 336}