68 * of the tiles directly by setting prefTileWidth/prefTileHeight
69 * properties to a value other than USE_COMPUTED_SIZE (the default).
70 * <p>
71 * Applications should initialize either <code>prefColumns</code> (for horizontal)
72 * or <code>prefRows</code> (for vertical) to establish the tilepane's preferred
73 * size (the arbitrary default is 5). Note that prefColumns/prefRows
74 * is used only for calculating the preferred size and may not reflect the actual
75 * number of rows or columns, which may change as the tilepane is resized and
76 * the tiles are wrapped at its actual boundaries.
77 * <p>
78 * The alignment property controls how the rows and columns are aligned
79 * within the bounds of the tilepane and defaults to Pos.TOP_LEFT. It is also possible
80 * to control the alignment of nodes within the individual tiles by setting
81 * {@link #tileAlignmentProperty() tileAlignment}, which defaults to Pos.CENTER.
82 * <p>
83 * A horizontal tilepane example:
84 * <pre><code>
85 * TilePane tile = new TilePane();
86 * tile.setHgap(8);
87 * tile.setPrefColumns(4);
88 * for (int i = 0; i < 20; i++) {
89 * tile.getChildren().add(new ImageView(...));
90 * }
91 * </code></pre>
92 * <p>
93 * A vertical TilePane example:
94 * <pre><code>
95 * TilePane tile = new TilePane(Orientation.VERTICAL);
96 * tile.setTileAlignment(Pos.CENTER_LEFT);
97 * tile.setPrefRows(10);
98 * for (int i = 0; i < 50; i++) {
99 * tile.getChildren().add(new ImageView(...));
100 * }
101 * </code></pre>
102 *
103 * The TilePane will attempt to resize each child to fill its tile.
104 * If the child could not be sized to fill the tile (either because it was not
105 * resizable or its size limits prevented it) then it will be aligned within the
106 * tile using tileAlignment.
107 *
108 * <h4>Resizable Range</h4>
109 *
110 * A tilepane's parent will resize the tilepane within the tilepane's resizable range
111 * during layout. By default the tilepane computes this range based on its content
112 * as outlined in the tables below.
113 * <p>
114 * Horizontal:
115 * <table border="1">
116 * <tr><td></td><th>width</th><th>height</th></tr>
117 * <tr><th>minimum</th>
118 * <td>left/right insets plus the tile width.</td>
152 * TilePane does not clip its content by default, so it is possible that childrens'
153 * bounds may extend outside the tiles (and possibly the tilepane bounds) if a
154 * child's pref size prevents it from being fit within its tile. Also, if the tilepane
155 * is resized smaller than its preferred size, it may not be able to fit all the
156 * tiles within its bounds and the content will extend outside.
157 *
158 * <h4>Optional Layout Constraints</h4>
159 *
160 * An application may set constraints on individual children to customize TilePane's layout.
161 * For each constraint, TilePane provides a static method for setting it on the child.
162 * <p>
163 * <table border="1">
164 * <tr><th>Constraint</th><th>Type</th><th>Description</th></tr>
165 * <tr><td>alignment</td><td>javafx.geometry.Pos</td><td>The alignment of the child within its tile.</td></tr>
166 * <tr><td>margin</td><td>javafx.geometry.Insets</td><td>Margin space around the outside of the child.</td></tr>
167 * </table>
168 * <p>
169 * Example:
170 * <pre><code>
171 * TilePane tilepane = new TilePane();
172 * for (int i = 0; i < 20; i++) {
173 * Label title = new Label(imageTitle[i]):
174 * Imageview imageview = new ImageView(new Image(imageName[i]));
175 * TilePane.setAlignment(label, Pos.BOTTOM_RIGHT);
176 * tilepane.getChildren().addAll(title, imageview);
177 * }
178 * </code></pre>
179 * @since JavaFX 2.0
180 */
181 public class TilePane extends Pane {
182
183 /********************************************************************
184 * BEGIN static methods
185 ********************************************************************/
186
187 private static final String MARGIN_CONSTRAINT = "tilepane-margin";
188 private static final String ALIGNMENT_CONSTRAINT = "tilepane-alignment";
189
190 /**
191 * Sets the alignment for the child when contained by a tilepane.
192 * If set, will override the tilepane's default alignment for children
239 setMargin(child, null);
240 }
241
242 /********************************************************************
243 * END static methods
244 ********************************************************************/
245
246 private double _tileWidth = -1;
247 private double _tileHeight = -1;
248
249 /**
250 * Creates a horizontal TilePane layout with prefColumn = 5 and hgap/vgap = 0.
251 */
252 public TilePane() {
253 super();
254 }
255
256 /**
257 * Creates a TilePane layout with the specified orientation,
258 * prefColumn/prefRows = 5 and hgap/vgap = 0.
259 * @param orientation the direction the tiles should flow & wrap
260 */
261 public TilePane(Orientation orientation) {
262 super();
263 setOrientation(orientation);
264 }
265
266 /**
267 * Creates a horizontal TilePane layout with prefColumn = 5 and the specified
268 * hgap/vgap.
269 * @param hgap the amount of horizontal space between each tile
270 * @param vgap the amount of vertical space between each tile
271 */
272 public TilePane(double hgap, double vgap) {
273 super();
274 setHgap(hgap);
275 setVgap(vgap);
276 }
277
278 /**
279 * Creates a TilePane layout with the specified orientation, hgap/vgap,
280 * and prefRows/prefColumns = 5.
281 * @param orientation the direction the tiles should flow & wrap
282 * @param hgap the amount of horizontal space between each tile
283 * @param vgap the amount of vertical space between each tile
284 */
285 public TilePane(Orientation orientation, double hgap, double vgap) {
286 this();
287 setOrientation(orientation);
288 setHgap(hgap);
289 setVgap(vgap);
290 }
291
292 /**
293 * Creates a horizontal TilePane layout with prefColumn = 5 and hgap/vgap = 0.
294 * @param children The initial set of children for this pane.
295 * @since JavaFX 8.0
296 */
297 public TilePane(Node... children) {
298 super();
299 getChildren().addAll(children);
300 }
301
302 /**
303 * Creates a TilePane layout with the specified orientation,
304 * prefColumn/prefRows = 5 and hgap/vgap = 0.
305 * @param orientation the direction the tiles should flow & wrap
306 * @param children The initial set of children for this pane.
307 * @since JavaFX 8.0
308 */
309 public TilePane(Orientation orientation, Node... children) {
310 super();
311 setOrientation(orientation);
312 getChildren().addAll(children);
313 }
314
315 /**
316 * Creates a horizontal TilePane layout with prefColumn = 5 and the specified
317 * hgap/vgap.
318 * @param hgap the amount of horizontal space between each tile
319 * @param vgap the amount of vertical space between each tile
320 * @param children The initial set of children for this pane.
321 * @since JavaFX 8.0
322 */
323 public TilePane(double hgap, double vgap, Node... children) {
324 super();
325 setHgap(hgap);
326 setVgap(vgap);
327 getChildren().addAll(children);
328 }
329
330 /**
331 * Creates a TilePane layout with the specified orientation, hgap/vgap,
332 * and prefRows/prefColumns = 5.
333 * @param orientation the direction the tiles should flow & wrap
334 * @param hgap the amount of horizontal space between each tile
335 * @param vgap the amount of vertical space between each tile
336 * @param children The initial set of children for this pane.
337 * @since JavaFX 8.0
338 */
339 public TilePane(Orientation orientation, double hgap, double vgap, Node... children) {
340 this();
341 setOrientation(orientation);
342 setHgap(hgap);
343 setVgap(vgap);
344 getChildren().addAll(children);
345 }
346
347 /**
348 * The orientation of this tilepane.
349 * A horizontal tilepane lays out children in tiles, left to right, wrapping
350 * tiles at the tilepane's width boundary. A vertical tilepane lays out
351 * children in tiles, top to bottom, wrapping at the tilepane's height.
352 * The default is horizontal.
353 */
|
68 * of the tiles directly by setting prefTileWidth/prefTileHeight
69 * properties to a value other than USE_COMPUTED_SIZE (the default).
70 * <p>
71 * Applications should initialize either <code>prefColumns</code> (for horizontal)
72 * or <code>prefRows</code> (for vertical) to establish the tilepane's preferred
73 * size (the arbitrary default is 5). Note that prefColumns/prefRows
74 * is used only for calculating the preferred size and may not reflect the actual
75 * number of rows or columns, which may change as the tilepane is resized and
76 * the tiles are wrapped at its actual boundaries.
77 * <p>
78 * The alignment property controls how the rows and columns are aligned
79 * within the bounds of the tilepane and defaults to Pos.TOP_LEFT. It is also possible
80 * to control the alignment of nodes within the individual tiles by setting
81 * {@link #tileAlignmentProperty() tileAlignment}, which defaults to Pos.CENTER.
82 * <p>
83 * A horizontal tilepane example:
84 * <pre><code>
85 * TilePane tile = new TilePane();
86 * tile.setHgap(8);
87 * tile.setPrefColumns(4);
88 * for (int i = 0; i < 20; i++) {
89 * tile.getChildren().add(new ImageView(...));
90 * }
91 * </code></pre>
92 * <p>
93 * A vertical TilePane example:
94 * <pre><code>
95 * TilePane tile = new TilePane(Orientation.VERTICAL);
96 * tile.setTileAlignment(Pos.CENTER_LEFT);
97 * tile.setPrefRows(10);
98 * for (int i = 0; i < 50; i++) {
99 * tile.getChildren().add(new ImageView(...));
100 * }
101 * </code></pre>
102 *
103 * The TilePane will attempt to resize each child to fill its tile.
104 * If the child could not be sized to fill the tile (either because it was not
105 * resizable or its size limits prevented it) then it will be aligned within the
106 * tile using tileAlignment.
107 *
108 * <h4>Resizable Range</h4>
109 *
110 * A tilepane's parent will resize the tilepane within the tilepane's resizable range
111 * during layout. By default the tilepane computes this range based on its content
112 * as outlined in the tables below.
113 * <p>
114 * Horizontal:
115 * <table border="1">
116 * <tr><td></td><th>width</th><th>height</th></tr>
117 * <tr><th>minimum</th>
118 * <td>left/right insets plus the tile width.</td>
152 * TilePane does not clip its content by default, so it is possible that childrens'
153 * bounds may extend outside the tiles (and possibly the tilepane bounds) if a
154 * child's pref size prevents it from being fit within its tile. Also, if the tilepane
155 * is resized smaller than its preferred size, it may not be able to fit all the
156 * tiles within its bounds and the content will extend outside.
157 *
158 * <h4>Optional Layout Constraints</h4>
159 *
160 * An application may set constraints on individual children to customize TilePane's layout.
161 * For each constraint, TilePane provides a static method for setting it on the child.
162 * <p>
163 * <table border="1">
164 * <tr><th>Constraint</th><th>Type</th><th>Description</th></tr>
165 * <tr><td>alignment</td><td>javafx.geometry.Pos</td><td>The alignment of the child within its tile.</td></tr>
166 * <tr><td>margin</td><td>javafx.geometry.Insets</td><td>Margin space around the outside of the child.</td></tr>
167 * </table>
168 * <p>
169 * Example:
170 * <pre><code>
171 * TilePane tilepane = new TilePane();
172 * for (int i = 0; i < 20; i++) {
173 * Label title = new Label(imageTitle[i]):
174 * Imageview imageview = new ImageView(new Image(imageName[i]));
175 * TilePane.setAlignment(label, Pos.BOTTOM_RIGHT);
176 * tilepane.getChildren().addAll(title, imageview);
177 * }
178 * </code></pre>
179 * @since JavaFX 2.0
180 */
181 public class TilePane extends Pane {
182
183 /********************************************************************
184 * BEGIN static methods
185 ********************************************************************/
186
187 private static final String MARGIN_CONSTRAINT = "tilepane-margin";
188 private static final String ALIGNMENT_CONSTRAINT = "tilepane-alignment";
189
190 /**
191 * Sets the alignment for the child when contained by a tilepane.
192 * If set, will override the tilepane's default alignment for children
239 setMargin(child, null);
240 }
241
242 /********************************************************************
243 * END static methods
244 ********************************************************************/
245
246 private double _tileWidth = -1;
247 private double _tileHeight = -1;
248
249 /**
250 * Creates a horizontal TilePane layout with prefColumn = 5 and hgap/vgap = 0.
251 */
252 public TilePane() {
253 super();
254 }
255
256 /**
257 * Creates a TilePane layout with the specified orientation,
258 * prefColumn/prefRows = 5 and hgap/vgap = 0.
259 * @param orientation the direction the tiles should flow & wrap
260 */
261 public TilePane(Orientation orientation) {
262 super();
263 setOrientation(orientation);
264 }
265
266 /**
267 * Creates a horizontal TilePane layout with prefColumn = 5 and the specified
268 * hgap/vgap.
269 * @param hgap the amount of horizontal space between each tile
270 * @param vgap the amount of vertical space between each tile
271 */
272 public TilePane(double hgap, double vgap) {
273 super();
274 setHgap(hgap);
275 setVgap(vgap);
276 }
277
278 /**
279 * Creates a TilePane layout with the specified orientation, hgap/vgap,
280 * and prefRows/prefColumns = 5.
281 * @param orientation the direction the tiles should flow & wrap
282 * @param hgap the amount of horizontal space between each tile
283 * @param vgap the amount of vertical space between each tile
284 */
285 public TilePane(Orientation orientation, double hgap, double vgap) {
286 this();
287 setOrientation(orientation);
288 setHgap(hgap);
289 setVgap(vgap);
290 }
291
292 /**
293 * Creates a horizontal TilePane layout with prefColumn = 5 and hgap/vgap = 0.
294 * @param children The initial set of children for this pane.
295 * @since JavaFX 8.0
296 */
297 public TilePane(Node... children) {
298 super();
299 getChildren().addAll(children);
300 }
301
302 /**
303 * Creates a TilePane layout with the specified orientation,
304 * prefColumn/prefRows = 5 and hgap/vgap = 0.
305 * @param orientation the direction the tiles should flow & wrap
306 * @param children The initial set of children for this pane.
307 * @since JavaFX 8.0
308 */
309 public TilePane(Orientation orientation, Node... children) {
310 super();
311 setOrientation(orientation);
312 getChildren().addAll(children);
313 }
314
315 /**
316 * Creates a horizontal TilePane layout with prefColumn = 5 and the specified
317 * hgap/vgap.
318 * @param hgap the amount of horizontal space between each tile
319 * @param vgap the amount of vertical space between each tile
320 * @param children The initial set of children for this pane.
321 * @since JavaFX 8.0
322 */
323 public TilePane(double hgap, double vgap, Node... children) {
324 super();
325 setHgap(hgap);
326 setVgap(vgap);
327 getChildren().addAll(children);
328 }
329
330 /**
331 * Creates a TilePane layout with the specified orientation, hgap/vgap,
332 * and prefRows/prefColumns = 5.
333 * @param orientation the direction the tiles should flow & wrap
334 * @param hgap the amount of horizontal space between each tile
335 * @param vgap the amount of vertical space between each tile
336 * @param children The initial set of children for this pane.
337 * @since JavaFX 8.0
338 */
339 public TilePane(Orientation orientation, double hgap, double vgap, Node... children) {
340 this();
341 setOrientation(orientation);
342 setHgap(hgap);
343 setVgap(vgap);
344 getChildren().addAll(children);
345 }
346
347 /**
348 * The orientation of this tilepane.
349 * A horizontal tilepane lays out children in tiles, left to right, wrapping
350 * tiles at the tilepane's width boundary. A vertical tilepane lays out
351 * children in tiles, top to bottom, wrapping at the tilepane's height.
352 * The default is horizontal.
353 */
|