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 static javafx.scene.layout.Region.USE_COMPUTED_SIZE; 029import static javafx.scene.layout.Region.USE_PREF_SIZE; 030import javafx.beans.property.BooleanProperty; 031import javafx.beans.property.BooleanPropertyBase; 032import javafx.beans.property.DoubleProperty; 033import javafx.beans.property.DoublePropertyBase; 034import javafx.beans.property.ObjectProperty; 035import javafx.beans.property.ObjectPropertyBase; 036import javafx.geometry.VPos; 037 038 039/** 040 * Defines optional layout constraints for a row in a {@link GridPane}. 041 * If a RowConstraints object is added for a row in a gridpane, the gridpane 042 * will use those constraint values when computing the row's height and layout. 043 * <p> 044 * For example, to create a GridPane with 10 rows 50 pixels tall: 045 * <pre><code> 046 * GridPane gridpane = new GridPane(); 047 * for (int i = 0; i < 10; i++) { 048 * RowConstraints row = new RowConstraints(50); 049 * gridpane.getRowConstraints().add(row); 050 * } 051 * </code></pre> 052 * Or, to create a GridPane where rows take 25%, 50%, 25% of its width: 053 * <pre><code> 054 * GridPane gridpane = new GridPane(); 055 * RowConstraints row1 = new RowConstraints(); 056 * row1.setPercentWidth(25); 057 * RowConstraints row2 = new RowConstraints(); 058 * row2.setPercentWidth(50); 059 * RowConstraints row3 = new RowConstraints(); 060 * row3.setPercentWidth(25); 061 * gridpane.getRowConstraints().addAll(row1,row2,row3); 062 * </code></pre> 063 * 064 * Note that adding an empty RowConstraints object has the effect of not setting 065 * any constraints, leaving the GridPane to compute the row's layout based 066 * solely on its content's size preferences and constraints. 067 * 068 */ 069public class RowConstraints extends ConstraintsBase { 070 071 /** 072 * Creates a row constraints object with no properties set. 073 */ 074 public RowConstraints() { 075 super(); 076 } 077 078 /** 079 * Creates a row constraint object with a fixed height. 080 * This is a convenience for setting the preferred height constraint to the 081 * fixed value and the minHeight and maxHeight constraints to the USE_PREF_SIZE 082 * flag to ensure the row is always that height. 083 * 084 * @param height the height of the row 085 */ 086 public RowConstraints(double height) { 087 this(); 088 setMinHeight(USE_PREF_SIZE); 089 setPrefHeight(height); 090 setMaxHeight(USE_PREF_SIZE); 091 } 092 093 /** 094 * Creates a row constraint object with a fixed size range. 095 * This is a convenience for setting the minimum, preferred, and maximum 096 * height constraints. 097 * 098 */ 099 public RowConstraints(double minHeight, double prefHeight, double maxHeight) { 100 this(); 101 setMinHeight(minHeight); 102 setPrefHeight(prefHeight); 103 setMaxHeight(maxHeight); 104 } 105 106 /** 107 * Creates a row constraint object with a fixed size range, vertical 108 * grow priority, vertical alignment, and vertical fill behavior. 109 * 110 */ 111 public RowConstraints(double minHeight, double prefHeight, double maxHeight, Priority vgrow, VPos valignment, boolean fillHeight) { 112 this(minHeight, prefHeight, maxHeight); 113 setVgrow(vgrow); 114 setValignment(valignment); 115 setFillHeight(fillHeight); 116 } 117 118 /** 119 * The minimum height for the row. 120 * This property is ignored if percentHeight is set. 121 * <p> 122 * The default value is USE_COMPUTED_SIZE, which means the minimum height 123 * will be computed to be the largest minimum height of the row's content. 124 */ 125 private DoubleProperty minHeight; 126 127 public final void setMinHeight(double value) { 128 minHeightProperty().set(value); 129 } 130 131 public final double getMinHeight() { 132 return minHeight == null ? USE_COMPUTED_SIZE : minHeight.get(); 133 } 134 135 public final DoubleProperty minHeightProperty() { 136 if (minHeight == null) { 137 minHeight = new DoublePropertyBase(USE_COMPUTED_SIZE) { 138 139 @Override 140 protected void invalidated() { 141 requestLayout(); 142 } 143 144 @Override 145 public Object getBean() { 146 return RowConstraints.this; 147 } 148 149 @Override 150 public String getName() { 151 return "minHeight"; 152 } 153 }; 154 } 155 return minHeight; 156 } 157 158 /** 159 * The preferred height for the row. 160 * This property is ignored if percentHeight is set. 161 * <p> 162 * The default value is USE_COMPUTED_SIZE, which means the preferred height 163 * will be computed to be the largest preferred height of the row's content. 164 */ 165 private DoubleProperty prefHeight; 166 167 public final void setPrefHeight(double value) { 168 prefHeightProperty().set(value); 169 } 170 171 public final double getPrefHeight() { 172 return prefHeight == null ? USE_COMPUTED_SIZE : prefHeight.get(); 173 } 174 175 public final DoubleProperty prefHeightProperty() { 176 if (prefHeight == null) { 177 prefHeight = new DoublePropertyBase(USE_COMPUTED_SIZE) { 178 179 @Override 180 protected void invalidated() { 181 requestLayout(); 182 } 183 184 @Override 185 public Object getBean() { 186 return RowConstraints.this; 187 } 188 189 @Override 190 public String getName() { 191 return "prefHeight"; 192 } 193 }; 194 } 195 return prefHeight; 196 } 197 198 /** 199 * The maximum height for the row. 200 * This property is ignored if percentHeight is set. 201 * <p> 202 * The default value is USE_COMPUTED_SIZE, which means the maximum height 203 * will be computed to be the smallest maximum height of the row's content. 204 */ 205 private DoubleProperty maxHeight; 206 207 public final void setMaxHeight(double value) { 208 maxHeightProperty().set(value); 209 } 210 211 public final double getMaxHeight() { 212 return maxHeight == null ? USE_COMPUTED_SIZE : maxHeight.get(); 213 } 214 215 public final DoubleProperty maxHeightProperty() { 216 if (maxHeight == null) { 217 maxHeight = new DoublePropertyBase(USE_COMPUTED_SIZE) { 218 219 @Override 220 protected void invalidated() { 221 requestLayout(); 222 } 223 224 @Override 225 public Object getBean() { 226 return RowConstraints.this; 227 } 228 229 @Override 230 public String getName() { 231 return "maxHeight"; 232 } 233 }; 234 } 235 return maxHeight; 236 } 237 238 /** 239 * The height percentage of the row. If set to a value greater than 0, the 240 * row will be resized to that percentage of the available gridpane height and 241 * the other size constraints (minHeight, prefHeight, maxHeight, vgrow) will 242 * be ignored. 243 * 244 * The default value is -1, which means the percentage will be ignored. 245 */ 246 private DoubleProperty percentHeight; 247 248 public final void setPercentHeight(double value) { 249 percentHeightProperty().set(value); 250 } 251 252 public final double getPercentHeight() { 253 return percentHeight == null ? -1 : percentHeight.get(); 254 } 255 256 public final DoubleProperty percentHeightProperty() { 257 if (percentHeight == null) { 258 percentHeight = new DoublePropertyBase(-1) { 259 260 @Override 261 protected void invalidated() { 262 requestLayout(); 263 } 264 265 @Override 266 public Object getBean() { 267 return RowConstraints.this; 268 } 269 270 @Override 271 public String getName() { 272 return "percentHeight"; 273 } 274 }; 275 } 276 return percentHeight; 277 } 278 279 /** 280 * The vertical grow priority for the row. If set, the gridpane will 281 * use this priority to determine whether the row should be given any 282 * additional height if the gridpane is resized larger than its preferred height. 283 * This property is ignored if percentHeight is set. 284 * <p> 285 * This default value is null, which means that the row's grow priority 286 * will be derived from largest grow priority set on a content node. 287 */ 288 private ObjectProperty<Priority> vgrow; 289 290 public final void setVgrow(Priority value) { 291 vgrowProperty().set(value); 292 } 293 294 public final Priority getVgrow() { 295 return vgrow == null ? null : vgrow.get(); 296 } 297 298 public final ObjectProperty<Priority> vgrowProperty() { 299 if (vgrow == null) { 300 vgrow = new ObjectPropertyBase<Priority>() { 301 302 @Override 303 protected void invalidated() { 304 requestLayout(); 305 } 306 307 @Override 308 public Object getBean() { 309 return RowConstraints.this; 310 } 311 312 @Override 313 public String getName() { 314 return "vgrow"; 315 } 316 }; 317 } 318 return vgrow; 319 } 320 321 /** 322 * The vertical alignment for the row. If set, will be the default 323 * vertical alignment for nodes contained within the row. 324 * If this property is set to VPos.BASELINE, then the fillHeight property 325 * will be ignored and nodes will always be resized to their preferred heights. 326 */ 327 private ObjectProperty<VPos> valignment; 328 329 public final void setValignment(VPos value) { 330 valignmentProperty().set(value); 331 } 332 333 public final VPos getValignment() { 334 return valignment == null ? null : valignment.get(); 335 } 336 337 public final ObjectProperty<VPos> valignmentProperty() { 338 if (valignment == null) { 339 valignment = new ObjectPropertyBase<VPos>() { 340 341 @Override 342 protected void invalidated() { 343 requestLayout(); 344 } 345 346 @Override 347 public Object getBean() { 348 return RowConstraints.this; 349 } 350 351 @Override 352 public String getName() { 353 return "valignment"; 354 } 355 }; 356 } 357 return valignment; 358 } 359 360 /** 361 * The vertical fill policy for the row. The gridpane will 362 * use this property to determine whether nodes contained within the row 363 * should be expanded to fill the row's height or kept to their preferred heights. 364 * <p> 365 * The default value is true. 366 */ 367 private BooleanProperty fillHeight; 368 369 public final void setFillHeight(boolean value) { 370 fillHeightProperty().set(value); 371 } 372 373 public final boolean isFillHeight() { 374 return fillHeight == null ? true : fillHeight.get(); 375 } 376 377 public final BooleanProperty fillHeightProperty() { 378 if (fillHeight == null) { 379 fillHeight = new BooleanPropertyBase(true) { 380 @Override 381 protected void invalidated() { 382 requestLayout(); 383 } 384 385 @Override 386 public Object getBean() { 387 return RowConstraints.this; 388 } 389 390 @Override 391 public String getName() { 392 return "fillHeight"; 393 } 394 }; 395 } 396 return fillHeight; 397 } 398 399 /** 400 * Returns a string representation of this {@code RowConstraints} object. 401 * @return a string representation of this {@code RowConstraints} object. 402 */ 403 @Override public String toString() { 404 return "RowConstraints percentHeight="+getPercentHeight()+ 405 " minHeight="+getMinHeight()+ 406 " prefHeight="+getPrefHeight()+ 407 " maxHeight="+getMaxHeight()+ 408 " vgrow="+getVgrow()+ 409 " fillHeight="+isFillHeight()+ 410 " valignment="+getValignment(); 411 } 412}