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 static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertNull;
30 import javafx.geometry.HPos;
31 import javafx.geometry.Insets;
32 import javafx.geometry.Orientation;
33 import javafx.geometry.Pos;
34 import javafx.geometry.VPos;
35 import javafx.scene.Node;
36 import javafx.scene.shape.Rectangle;
37 import org.junit.Before;
38
39 import org.junit.Test;
40
41
42 public class FlowPaneTest {
43 FlowPane flowpane;
44
45 @Before public void setUp() {
46 this.flowpane = new FlowPane();
47 }
48
49 @Test public void testFlowPaneDefaults() {
50 assertEquals(Orientation.HORIZONTAL, flowpane.getOrientation());
51 assertEquals(0, flowpane.getHgap(), 1e-100);
52 assertEquals(0, flowpane.getVgap(), 1e-100);
53 assertEquals(Pos.TOP_LEFT, flowpane.getAlignment());
54 assertEquals(VPos.CENTER, flowpane.getRowValignment());
55 assertEquals(HPos.LEFT, flowpane.getColumnHalignment());
63 flowpane.setOrientation(null);
64
65 // this musn't throw NPE
66 flowpane.autosize();
67 flowpane.layout();
68
69 assertNull(flowpane.getOrientation());
70 assertNull(flowpane.getAlignment());
71 assertNull(flowpane.getRowValignment());
72 assertNull(flowpane.getColumnHalignment());
73 assertNull(flowpane.orientationProperty().get());
74 assertNull(flowpane.alignmentProperty().get());
75 assertNull(flowpane.rowValignmentProperty().get());
76 assertNull(flowpane.columnHalignmentProperty().get());
77 }
78
79 @Test public void testSimpleFlowPane() {
80 for(int i = 0; i < 3; i++) { // 6 children
81 MockResizable child1 = new MockResizable(100,200);
82 Rectangle child2 = new Rectangle(100, 100);
83 flowpane.getChildren().addAll(child1, child2);
84 }
85
86 assertEquals(100, flowpane.minWidth(-1), 1e-100);
87 assertEquals(900, flowpane.minHeight(100), 1e-100);
88 assertEquals(400, flowpane.prefWidth(-1), 1e-100);
89 assertEquals(400, flowpane.prefHeight(-1), 1e-100);
90
91 flowpane.autosize();
92 flowpane.layout();
93
94 // test a handful
95 Node first = flowpane.getChildren().get(0);
96 Node last = flowpane.getChildren().get(5);
97
98 assertEquals(0, first.getLayoutX(), 1e-100);
99 assertEquals(0, first.getLayoutY(), 1e-100);
100 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
101 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
102 assertEquals(100, last.getLayoutX(), 1e-100);
103 assertEquals(250, last.getLayoutY(), 1e-100);
104 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
105 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
106
107 flowpane.resize(800,800);
108 flowpane.layout();
109 assertEquals(0, first.getLayoutX(), 1e-100);
110 assertEquals(0, first.getLayoutY(), 1e-100);
111 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
112 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
113 assertEquals(500, last.getLayoutX(), 1e-100);
114 assertEquals(50, last.getLayoutY(), 1e-100);
115 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
116 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
127
128 assertEquals(0, flowpane.minHeight(-1), 0);
129 }
130
131 @Test public void testEmptyVerticalFlowPaneMinWidthIsZero() {
132 FlowPane flowpane = new FlowPane(Orientation.VERTICAL);
133
134 assertEquals(0, flowpane.minWidth(-1), 0);
135 }
136
137 @Test public void testEmptyVerticalFlowPaneMinHeightIsZero() {
138 FlowPane flowpane = new FlowPane(Orientation.VERTICAL);
139
140 assertEquals(0, flowpane.minHeight(-1), 0);
141 }
142
143 @Test public void testHorizontalFlowPaneAlignmentTopLeft() {
144 for(int i = 0; i < 3; i++) {
145 MockResizable child1 = new MockResizable(100,200);
146 Rectangle child2 = new Rectangle(100, 100);
147 flowpane.getChildren().addAll(child1, child2);
148 }
149 flowpane.setAlignment(Pos.TOP_LEFT);
150
151 flowpane.resize(450,450);
152 flowpane.layout();
153
154 // test a handful
155 Node first = flowpane.getChildren().get(0);
156 Node last = flowpane.getChildren().get(5);
157
158 assertEquals(0, first.getLayoutX(), 1e-100);
159 assertEquals(0, first.getLayoutY(), 1e-100);
160 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
161 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
162 assertEquals(100, last.getLayoutX(), 1e-100);
163 assertEquals(250, last.getLayoutY(), 1e-100);
164 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
165 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
166 }
167
168 @Test public void testHorizontalFlowPaneAlignmentTopCenter() {
169 for(int i = 0; i < 3; i++) {
170 MockResizable child1 = new MockResizable(100,200);
171 Rectangle child2 = new Rectangle(100, 100);
172 flowpane.getChildren().addAll(child1, child2);
173 }
174 flowpane.setAlignment(Pos.TOP_CENTER);
175
176 flowpane.resize(450,450);
177 flowpane.layout();
178
179 // test a handful
180 Node first = flowpane.getChildren().get(0);
181 Node last = flowpane.getChildren().get(5);
182
183 assertEquals(25, first.getLayoutX(), 1e-100);
184 assertEquals(0, first.getLayoutY(), 1e-100);
185 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
186 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
187 assertEquals(225, last.getLayoutX(), 1e-100);
188 assertEquals(250, last.getLayoutY(), 1e-100);
189 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
190 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
191 }
192
193 @Test public void testHorizontalFlowPaneAlignmentTopRight() {
194 for(int i = 0; i < 3; i++) {
195 MockResizable child1 = new MockResizable(100,200);
196 Rectangle child2 = new Rectangle(100, 100);
197 flowpane.getChildren().addAll(child1, child2);
198 }
199 flowpane.setAlignment(Pos.TOP_RIGHT);
200
201 flowpane.resize(450,450);
202 flowpane.layout();
203
204 // test a handful
205 Node first = flowpane.getChildren().get(0);
206 Node last = flowpane.getChildren().get(5);
207
208 assertEquals(50, first.getLayoutX(), 1e-100);
209 assertEquals(0, first.getLayoutY(), 1e-100);
210 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
211 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
212 assertEquals(350, last.getLayoutX(), 1e-100);
213 assertEquals(250, last.getLayoutY(), 1e-100);
214 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
215 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
216 }
217
218 @Test public void testHorizontalFlowPaneAlignmentCenterLeft() {
219 for(int i = 0; i < 3; i++) {
220 MockResizable child1 = new MockResizable(100,200);
221 Rectangle child2 = new Rectangle(100, 100);
222 flowpane.getChildren().addAll(child1, child2);
223 }
224 flowpane.setAlignment(Pos.CENTER_LEFT);
225
226 flowpane.resize(450,450);
227 flowpane.layout();
228
229 // test a handful
230 Node first = flowpane.getChildren().get(0);
231 Node last = flowpane.getChildren().get(5);
232
233 assertEquals(0, first.getLayoutX(), 1e-100);
234 assertEquals(25, first.getLayoutY(), 1e-100);
235 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
236 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
237 assertEquals(100, last.getLayoutX(), 1e-100);
238 assertEquals(275, last.getLayoutY(), 1e-100);
239 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
240 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
241 }
242
243 @Test public void testHorizontalFlowPaneAlignmentCenter() {
244 for(int i = 0; i < 3; i++) {
245 MockResizable child1 = new MockResizable(100,200);
246 Rectangle child2 = new Rectangle(100, 100);
247 flowpane.getChildren().addAll(child1, child2);
248 }
249 flowpane.setAlignment(Pos.CENTER);
250
251 flowpane.resize(450,450);
252 flowpane.layout();
253
254 // test a handful
255 Node first = flowpane.getChildren().get(0);
256 Node last = flowpane.getChildren().get(5);
257
258 assertEquals(25, first.getLayoutX(), 1e-100);
259 assertEquals(25, first.getLayoutY(), 1e-100);
260 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
261 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
262 assertEquals(225, last.getLayoutX(), 1e-100);
263 assertEquals(275, last.getLayoutY(), 1e-100);
264 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
265 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
266 }
267
268 @Test public void testHorizontalFlowPaneAlignmentCenterRight() {
269 for(int i = 0; i < 3; i++) {
270 MockResizable child1 = new MockResizable(100,200);
271 Rectangle child2 = new Rectangle(100, 100);
272 flowpane.getChildren().addAll(child1, child2);
273 }
274 flowpane.setAlignment(Pos.CENTER_RIGHT);
275
276 flowpane.resize(450,450);
277 flowpane.layout();
278
279 // test a handful
280 Node first = flowpane.getChildren().get(0);
281 Node last = flowpane.getChildren().get(5);
282
283 assertEquals(50, first.getLayoutX(), 1e-100);
284 assertEquals(25, first.getLayoutY(), 1e-100);
285 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
286 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
287 assertEquals(350, last.getLayoutX(), 1e-100);
288 assertEquals(275, last.getLayoutY(), 1e-100);
289 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
290 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
291 }
292
293 @Test public void testHorizontalFlowPaneAlignmentBottomLeft() {
294 for(int i = 0; i < 3; i++) {
295 MockResizable child1 = new MockResizable(100,200);
296 Rectangle child2 = new Rectangle(100, 100);
297 flowpane.getChildren().addAll(child1, child2);
298 }
299 flowpane.setAlignment(Pos.BOTTOM_LEFT);
300
301 flowpane.resize(450,450);
302 flowpane.layout();
303
304 // test a handful
305 Node first = flowpane.getChildren().get(0);
306 Node last = flowpane.getChildren().get(5);
307
308 assertEquals(0, first.getLayoutX(), 1e-100);
309 assertEquals(50, first.getLayoutY(), 1e-100);
310 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
311 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
312 assertEquals(100, last.getLayoutX(), 1e-100);
313 assertEquals(300, last.getLayoutY(), 1e-100);
314 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
315 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
316 }
317
318 @Test public void testHorizontalFlowPaneAlignmentBottomCenter() {
319 for(int i = 0; i < 3; i++) {
320 MockResizable child1 = new MockResizable(100,200);
321 Rectangle child2 = new Rectangle(100, 100);
322 flowpane.getChildren().addAll(child1, child2);
323 }
324 flowpane.setAlignment(Pos.BOTTOM_CENTER);
325
326 flowpane.resize(450,450);
327 flowpane.layout();
328
329 // test a handful
330 Node first = flowpane.getChildren().get(0);
331 Node last = flowpane.getChildren().get(5);
332
333 assertEquals(25, first.getLayoutX(), 1e-100);
334 assertEquals(50, first.getLayoutY(), 1e-100);
335 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
336 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
337 assertEquals(225, last.getLayoutX(), 1e-100);
338 assertEquals(300, last.getLayoutY(), 1e-100);
339 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
340 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
341 }
342
343 @Test public void testHorizontalFlowPaneAlignmentBottomRight() {
344 for(int i = 0; i < 3; i++) {
345 MockResizable child1 = new MockResizable(100,200);
346 Rectangle child2 = new Rectangle(100, 100);
347 flowpane.getChildren().addAll(child1, child2);
348 }
349 flowpane.setAlignment(Pos.BOTTOM_RIGHT);
350
351 flowpane.resize(450,450);
352 flowpane.layout();
353
354 // test a handful
355 Node first = flowpane.getChildren().get(0);
356 Node last = flowpane.getChildren().get(5);
357
358 assertEquals(50, first.getLayoutX(), 1e-100);
359 assertEquals(50, first.getLayoutY(), 1e-100);
360 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
361 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
362 assertEquals(350, last.getLayoutX(), 1e-100);
363 assertEquals(300, last.getLayoutY(), 1e-100);
364 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
365 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
366 }
367
368 @Test public void testVerticalFlowPaneAlignmentTopLeft() {
369 flowpane.setOrientation(Orientation.VERTICAL);
370
371 for(int i = 0; i < 3; i++) {
372 MockResizable child1 = new MockResizable(200,300);
373 Rectangle child2 = new Rectangle(100, 100);
374 flowpane.getChildren().addAll(child1, child2);
375 }
376 flowpane.setAlignment(Pos.TOP_LEFT);
377
378 flowpane.resize(700,600);
379 flowpane.layout();
380
381 // test a handful
382 Node first = flowpane.getChildren().get(0);
383 Node last = flowpane.getChildren().get(5);
384
385 assertEquals(0, first.getLayoutX(), 1e-100);
386 assertEquals(0, first.getLayoutY(), 1e-100);
387 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
388 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
389 assertEquals(400, last.getLayoutX(), 1e-100);
390 assertEquals(300, last.getLayoutY(), 1e-100);
391 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
392 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
393 }
394
395 @Test public void testVerticalFlowPaneAlignmentTopCenter() {
396 flowpane.setOrientation(Orientation.VERTICAL);
397
398 for(int i = 0; i < 3; i++) {
399 MockResizable child1 = new MockResizable(200,300);
400 Rectangle child2 = new Rectangle(100, 100);
401 flowpane.getChildren().addAll(child1, child2);
402 }
403 flowpane.setAlignment(Pos.TOP_CENTER);
404
405 flowpane.resize(700,600);
406 flowpane.layout();
407
408 // test a handful
409 Node first = flowpane.getChildren().get(0);
410 Node last = flowpane.getChildren().get(5);
411
412 assertEquals(50, first.getLayoutX(), 1e-100);
413 assertEquals(0, first.getLayoutY(), 1e-100);
414 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
415 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
416 assertEquals(450, last.getLayoutX(), 1e-100);
417 assertEquals(300, last.getLayoutY(), 1e-100);
418 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
419 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
420 }
421
422 @Test public void testVerticalFlowPaneAlignmentTopRight() {
423 flowpane.setOrientation(Orientation.VERTICAL);
424
425 for(int i = 0; i < 3; i++) {
426 MockResizable child1 = new MockResizable(200,300);
427 Rectangle child2 = new Rectangle(100, 100);
428 flowpane.getChildren().addAll(child1, child2);
429 }
430 flowpane.setAlignment(Pos.TOP_RIGHT);
431
432 flowpane.resize(700,600);
433 flowpane.layout();
434
435 // test a handful
436 Node first = flowpane.getChildren().get(0);
437 Node last = flowpane.getChildren().get(5);
438
439 assertEquals(100, first.getLayoutX(), 1e-100);
440 assertEquals(0, first.getLayoutY(), 1e-100);
441 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
442 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
443 assertEquals(500, last.getLayoutX(), 1e-100);
444 assertEquals(300, last.getLayoutY(), 1e-100);
445 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
446 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
447 }
448
449 @Test public void testVerticalFlowPaneAlignmentCenterLeft() {
450 flowpane.setOrientation(Orientation.VERTICAL);
451
452 for(int i = 0; i < 3; i++) {
453 MockResizable child1 = new MockResizable(200,300);
454 Rectangle child2 = new Rectangle(100, 100);
455 flowpane.getChildren().addAll(child1, child2);
456 }
457 flowpane.setAlignment(Pos.CENTER_LEFT);
458
459 flowpane.resize(700,600);
460 flowpane.layout();
461
462 // test a handful
463 Node first = flowpane.getChildren().get(0);
464 Node last = flowpane.getChildren().get(5);
465
466 assertEquals(0, first.getLayoutX(), 1e-100);
467 assertEquals(100, first.getLayoutY(), 1e-100);
468 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
469 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
470 assertEquals(400, last.getLayoutX(), 1e-100);
471 assertEquals(400, last.getLayoutY(), 1e-100);
472 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
473 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
474 }
475
476 @Test public void testVerticalFlowPaneAlignmentCenter() {
477 flowpane.setOrientation(Orientation.VERTICAL);
478
479 for(int i = 0; i < 3; i++) {
480 MockResizable child1 = new MockResizable(200,300);
481 Rectangle child2 = new Rectangle(100, 100);
482 flowpane.getChildren().addAll(child1, child2);
483 }
484 flowpane.setAlignment(Pos.CENTER);
485
486 flowpane.resize(700,600);
487 flowpane.layout();
488
489 // test a handful
490 Node first = flowpane.getChildren().get(0);
491 Node last = flowpane.getChildren().get(5);
492
493 assertEquals(50, first.getLayoutX(), 1e-100);
494 assertEquals(100, first.getLayoutY(), 1e-100);
495 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
496 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
497 assertEquals(450, last.getLayoutX(), 1e-100);
498 assertEquals(400, last.getLayoutY(), 1e-100);
499 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
500 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
501 }
502
503 @Test public void testVerticalFlowPaneAlignmentCenterRight() {
504 flowpane.setOrientation(Orientation.VERTICAL);
505
506 for(int i = 0; i < 3; i++) {
507 MockResizable child1 = new MockResizable(200,300);
508 Rectangle child2 = new Rectangle(100, 100);
509 flowpane.getChildren().addAll(child1, child2);
510 }
511 flowpane.setAlignment(Pos.CENTER_RIGHT);
512
513 flowpane.resize(700,600);
514 flowpane.layout();
515
516 // test a handful
517 Node first = flowpane.getChildren().get(0);
518 Node last = flowpane.getChildren().get(5);
519
520 assertEquals(100, first.getLayoutX(), 1e-100);
521 assertEquals(100, first.getLayoutY(), 1e-100);
522 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
523 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
524 assertEquals(500, last.getLayoutX(), 1e-100);
525 assertEquals(400, last.getLayoutY(), 1e-100);
526 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
527 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
528 }
529
530 @Test public void testVerticalFlowPaneAlignmentBottomLeft() {
531 flowpane.setOrientation(Orientation.VERTICAL);
532
533 for(int i = 0; i < 3; i++) {
534 MockResizable child1 = new MockResizable(200,300);
535 Rectangle child2 = new Rectangle(100, 100);
536 flowpane.getChildren().addAll(child1, child2);
537 }
538 flowpane.setAlignment(Pos.BOTTOM_LEFT);
539
540 flowpane.resize(700,600);
541 flowpane.layout();
542
543 // test a handful
544 Node first = flowpane.getChildren().get(0);
545 Node last = flowpane.getChildren().get(5);
546
547 assertEquals(0, first.getLayoutX(), 1e-100);
548 assertEquals(200, first.getLayoutY(), 1e-100);
549 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
550 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
551 assertEquals(400, last.getLayoutX(), 1e-100);
552 assertEquals(500, last.getLayoutY(), 1e-100);
553 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
554 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
555 }
556
557 @Test public void testVerticalFlowPaneAlignmentBottomCenter() {
558 flowpane.setOrientation(Orientation.VERTICAL);
559
560 for(int i = 0; i < 3; i++) {
561 MockResizable child1 = new MockResizable(200,300);
562 Rectangle child2 = new Rectangle(100, 100);
563 flowpane.getChildren().addAll(child1, child2);
564 }
565 flowpane.setAlignment(Pos.BOTTOM_CENTER);
566
567 flowpane.resize(700,600);
568 flowpane.layout();
569
570 // test a handful
571 Node first = flowpane.getChildren().get(0);
572 Node last = flowpane.getChildren().get(5);
573
574 assertEquals(50, first.getLayoutX(), 1e-100);
575 assertEquals(200, first.getLayoutY(), 1e-100);
576 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
577 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
578 assertEquals(450, last.getLayoutX(), 1e-100);
579 assertEquals(500, last.getLayoutY(), 1e-100);
580 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
581 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
582 }
583
584 @Test public void testVerticalFlowPaneAlignmentBottomRight() {
585 flowpane.setOrientation(Orientation.VERTICAL);
586
587 for(int i = 0; i < 3; i++) {
588 MockResizable child1 = new MockResizable(200,300);
589 Rectangle child2 = new Rectangle(100, 100);
590 flowpane.getChildren().addAll(child1, child2);
591 }
592 flowpane.setAlignment(Pos.BOTTOM_RIGHT);
593
594 flowpane.resize(700,600);
595 flowpane.layout();
596
597 // test a handful
598 Node first = flowpane.getChildren().get(0);
599 Node last = flowpane.getChildren().get(5);
600
601 assertEquals(100, first.getLayoutX(), 1e-100);
602 assertEquals(200, first.getLayoutY(), 1e-100);
603 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
604 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
605 assertEquals(500, last.getLayoutX(), 1e-100);
606 assertEquals(500, last.getLayoutY(), 1e-100);
607 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
608 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
609 }
610
611 @Test public void testHorizontalFlowPaneRowVAlignmentTop() {
612 for(int i = 0; i < 3; i++) {
613 MockResizable child1 = new MockResizable(100,200);
614 Rectangle child2 = new Rectangle(100, 100);
615 flowpane.getChildren().addAll(child1, child2);
616 }
617 flowpane.setRowValignment(VPos.TOP);
618
619 flowpane.resize(450,450);
620 flowpane.layout();
621
622 // test a handful
623 Node first = flowpane.getChildren().get(0);
624 Node last = flowpane.getChildren().get(5);
625
626 assertEquals(0, first.getLayoutX(), 1e-100);
627 assertEquals(0, first.getLayoutY(), 1e-100);
628 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
629 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
630 assertEquals(100, last.getLayoutX(), 1e-100);
631 assertEquals(200, last.getLayoutY(), 1e-100);
632 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
633 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
634 }
635
636 @Test public void testHorizontalFlowPaneRowVAlignmentCenter() {
637 for(int i = 0; i < 3; i++) {
638 MockResizable child1 = new MockResizable(100,200);
639 Rectangle child2 = new Rectangle(100, 100);
640 flowpane.getChildren().addAll(child1, child2);
641 }
642 flowpane.setRowValignment(VPos.CENTER);
643
644 flowpane.resize(450,450);
645 flowpane.layout();
646
647 // test a handful
648 Node first = flowpane.getChildren().get(0);
649 Node last = flowpane.getChildren().get(5);
650
651 assertEquals(0, first.getLayoutX(), 1e-100);
652 assertEquals(0, first.getLayoutY(), 1e-100);
653 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
654 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
655 assertEquals(100, last.getLayoutX(), 1e-100);
656 assertEquals(250, last.getLayoutY(), 1e-100);
657 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
658 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
659 }
660
661 @Test public void testHorizontalFlowPaneRowVAlignmentBaseline() {
662 for(int i = 0; i < 3; i++) {
663 MockResizable child1 = new MockResizable(100,200); //baseline=190
664 Rectangle child2 = new Rectangle(100, 100);
665 flowpane.getChildren().addAll(child1, child2);
666 }
667 flowpane.setRowValignment(VPos.BASELINE);
668
669 flowpane.resize(450,450);
670 flowpane.layout();
671
672 // test a handful
673 Node first = flowpane.getChildren().get(0);
674 Node last = flowpane.getChildren().get(5);
675
676 assertEquals(0, first.getLayoutX(), 1e-100);
677 assertEquals(0, first.getLayoutY(), 1e-100);
678 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
679 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
680 assertEquals(100, last.getLayoutX(), 1e-100);
681 assertEquals(290, last.getLayoutY(), 1e-100);
682 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
683 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
684 }
685
686 @Test public void testHorizontalFlowPaneRowVAlignmentBottom() {
687 for(int i = 0; i < 3; i++) {
688 MockResizable child1 = new MockResizable(100,200);
689 Rectangle child2 = new Rectangle(100, 100);
690 flowpane.getChildren().addAll(child1, child2);
691 }
692 flowpane.setRowValignment(VPos.BOTTOM);
693
694 flowpane.resize(450,450);
695 flowpane.layout();
696
697 // test a handful
698 Node first = flowpane.getChildren().get(0);
699 Node last = flowpane.getChildren().get(5);
700
701 assertEquals(0, first.getLayoutX(), 1e-100);
702 assertEquals(0, first.getLayoutY(), 1e-100);
703 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
704 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
705 assertEquals(100, last.getLayoutX(), 1e-100);
706 assertEquals(300, last.getLayoutY(), 1e-100);
707 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
708 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
709 }
710
711 @Test public void testVerticalFlowPaneRowHAlignmentLeft() {
712 flowpane.setOrientation(Orientation.VERTICAL);
713
714 for(int i = 0; i < 3; i++) {
715 MockResizable child1 = new MockResizable(200,300);
716 Rectangle child2 = new Rectangle(100, 100);
717 flowpane.getChildren().addAll(child1, child2);
718 }
719 flowpane.setColumnHalignment(HPos.LEFT);
720
721 flowpane.resize(600,800);
722 flowpane.layout();
723
724 // test a handful
725 Node first = flowpane.getChildren().get(0);
726 Node last = flowpane.getChildren().get(5);
727
728 assertEquals(0, first.getLayoutX(), 1e-100);
729 assertEquals(0, first.getLayoutY(), 1e-100);
730 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
731 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
732 assertEquals(200, last.getLayoutX(), 1e-100);
733 assertEquals(300, last.getLayoutY(), 1e-100);
734 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
735 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
736 }
737
738 @Test public void testVerticalFlowPaneRowHAlignmentCenter() {
739 flowpane.setOrientation(Orientation.VERTICAL);
740
741 for(int i = 0; i < 3; i++) {
742 MockResizable child1 = new MockResizable(200,300);
743 Rectangle child2 = new Rectangle(100, 100);
744 flowpane.getChildren().addAll(child1, child2);
745 }
746 flowpane.setColumnHalignment(HPos.CENTER);
747
748 flowpane.resize(600,800);
749 flowpane.layout();
750
751 // test a handful
752 Node first = flowpane.getChildren().get(0);
753 Node last = flowpane.getChildren().get(5);
754
755 assertEquals(0, first.getLayoutX(), 1e-100);
756 assertEquals(0, first.getLayoutY(), 1e-100);
757 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
758 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
759 assertEquals(250, last.getLayoutX(), 1e-100);
760 assertEquals(300, last.getLayoutY(), 1e-100);
761 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
762 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
763 }
764
765 @Test public void testVerticalFlowPaneRowHAlignmentRight() {
766 flowpane.setOrientation(Orientation.VERTICAL);
767
768 for(int i = 0; i < 3; i++) {
769 MockResizable child1 = new MockResizable(200,300);
770 Rectangle child2 = new Rectangle(100, 100);
771 flowpane.getChildren().addAll(child1, child2);
772 }
773 flowpane.setColumnHalignment(HPos.RIGHT);
774
775 flowpane.resize(600,800);
776 flowpane.layout();
777
778 // test a handful
779 Node first = flowpane.getChildren().get(0);
780 Node last = flowpane.getChildren().get(5);
781
782 assertEquals(0, first.getLayoutX(), 1e-100);
783 assertEquals(0, first.getLayoutY(), 1e-100);
784 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
785 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
786 assertEquals(300, last.getLayoutX(), 1e-100);
787 assertEquals(300, last.getLayoutY(), 1e-100);
788 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
789 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
790 }
791
792 @Test public void testFlowPaneSetMarginConstraint() {
793 MockResizable child1 = new MockResizable(100,200, 300,400, 500,600);
794
795 assertNull(FlowPane.getMargin(child1));
796
797 Insets margin = new Insets(10,20,30,40);
798 FlowPane.setMargin(child1, margin);
799 assertEquals(margin, FlowPane.getMargin(child1));
800
801 FlowPane.setMargin(child1, null);
802 assertNull(FlowPane.getMargin(child1));
803 }
804
805 @Test public void testFlowPaneMarginConstraint() {
806 for(int i = 0; i < 3; i++) {
807 MockResizable child1 = new MockResizable(100,200);
808 Rectangle child2 = new Rectangle(100, 100);
809 flowpane.getChildren().addAll(child1, child2);
810 }
811
812 // test a handful
813 Node first = flowpane.getChildren().get(0);
814 Node last = flowpane.getChildren().get(5);
815
816 FlowPane.setMargin(first, new Insets(10,20,30,40));
817
818 assertEquals(100, flowpane.minWidth(-1), 1e-100);
819 assertEquals(940, flowpane.minHeight(100), 1e-100);
820 assertEquals(400, flowpane.prefWidth(-1), 1e-100);
821 assertEquals(440, flowpane.prefHeight(-1), 1e-100);
822
823 flowpane.autosize();
824 flowpane.layout();
825
826 assertEquals(40, first.getLayoutX(), 1e-100);
827 assertEquals(10, first.getLayoutY(), 1e-100);
828 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
829 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
830 assertEquals(200, last.getLayoutX(), 1e-100);
831 assertEquals(290, last.getLayoutY(), 1e-100);
832 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
833 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
834 }
835
836 // FlowPane does not shrink their children to be smaller than their preferred sizes
837 @Test public void testHorizontalFlowPaneFitsChildWithinHeightIfPossible() {
838 MockResizable child = new MockResizable(10,20, 200,200, 500,500);
839
840 flowpane.getChildren().add(child);
841
842 flowpane.resize(100,100);
843 flowpane.layout();
844
845 assertEquals(200, child.getWidth(), 1e-100);
846 assertEquals(200, child.getHeight(), 1e-100);
847 }
848
849 @Test public void testVerticalFlowPaneFitsChildWithinWidthIfPossible() {
850 flowpane.setOrientation(Orientation.VERTICAL);
851 MockResizable child = new MockResizable(10,20, 200,200, 500,500);
852
853 flowpane.getChildren().add(child);
854
855 flowpane.resize(100,100);
856 System.out.println("******************");
857 flowpane.layout();
858 System.out.println("*****************");
859
860 assertEquals(200, child.getWidth(), 1e-100);
861 assertEquals(200, child.getHeight(), 1e-100);
862 }
863 }
|
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 test.javafx.scene.layout;
27
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertNull;
30 import javafx.geometry.HPos;
31 import javafx.geometry.Insets;
32 import javafx.geometry.Orientation;
33 import javafx.geometry.Pos;
34 import javafx.geometry.VPos;
35 import javafx.scene.Node;
36 import javafx.scene.ParentShim;
37 import javafx.scene.layout.FlowPane;
38 import javafx.scene.shape.Rectangle;
39 import org.junit.Before;
40
41 import org.junit.Test;
42
43
44 public class FlowPaneTest {
45 FlowPane flowpane;
46
47 @Before public void setUp() {
48 this.flowpane = new FlowPane();
49 }
50
51 @Test public void testFlowPaneDefaults() {
52 assertEquals(Orientation.HORIZONTAL, flowpane.getOrientation());
53 assertEquals(0, flowpane.getHgap(), 1e-100);
54 assertEquals(0, flowpane.getVgap(), 1e-100);
55 assertEquals(Pos.TOP_LEFT, flowpane.getAlignment());
56 assertEquals(VPos.CENTER, flowpane.getRowValignment());
57 assertEquals(HPos.LEFT, flowpane.getColumnHalignment());
65 flowpane.setOrientation(null);
66
67 // this musn't throw NPE
68 flowpane.autosize();
69 flowpane.layout();
70
71 assertNull(flowpane.getOrientation());
72 assertNull(flowpane.getAlignment());
73 assertNull(flowpane.getRowValignment());
74 assertNull(flowpane.getColumnHalignment());
75 assertNull(flowpane.orientationProperty().get());
76 assertNull(flowpane.alignmentProperty().get());
77 assertNull(flowpane.rowValignmentProperty().get());
78 assertNull(flowpane.columnHalignmentProperty().get());
79 }
80
81 @Test public void testSimpleFlowPane() {
82 for(int i = 0; i < 3; i++) { // 6 children
83 MockResizable child1 = new MockResizable(100,200);
84 Rectangle child2 = new Rectangle(100, 100);
85 ParentShim.getChildren(flowpane).addAll(child1, child2);
86 }
87
88 assertEquals(100, flowpane.minWidth(-1), 1e-100);
89 assertEquals(900, flowpane.minHeight(100), 1e-100);
90 assertEquals(400, flowpane.prefWidth(-1), 1e-100);
91 assertEquals(400, flowpane.prefHeight(-1), 1e-100);
92
93 flowpane.autosize();
94 flowpane.layout();
95
96 // test a handful
97 Node first = ParentShim.getChildren(flowpane).get(0);
98 Node last = ParentShim.getChildren(flowpane).get(5);
99
100 assertEquals(0, first.getLayoutX(), 1e-100);
101 assertEquals(0, first.getLayoutY(), 1e-100);
102 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
103 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
104 assertEquals(100, last.getLayoutX(), 1e-100);
105 assertEquals(250, last.getLayoutY(), 1e-100);
106 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
107 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
108
109 flowpane.resize(800,800);
110 flowpane.layout();
111 assertEquals(0, first.getLayoutX(), 1e-100);
112 assertEquals(0, first.getLayoutY(), 1e-100);
113 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
114 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
115 assertEquals(500, last.getLayoutX(), 1e-100);
116 assertEquals(50, last.getLayoutY(), 1e-100);
117 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
118 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
129
130 assertEquals(0, flowpane.minHeight(-1), 0);
131 }
132
133 @Test public void testEmptyVerticalFlowPaneMinWidthIsZero() {
134 FlowPane flowpane = new FlowPane(Orientation.VERTICAL);
135
136 assertEquals(0, flowpane.minWidth(-1), 0);
137 }
138
139 @Test public void testEmptyVerticalFlowPaneMinHeightIsZero() {
140 FlowPane flowpane = new FlowPane(Orientation.VERTICAL);
141
142 assertEquals(0, flowpane.minHeight(-1), 0);
143 }
144
145 @Test public void testHorizontalFlowPaneAlignmentTopLeft() {
146 for(int i = 0; i < 3; i++) {
147 MockResizable child1 = new MockResizable(100,200);
148 Rectangle child2 = new Rectangle(100, 100);
149 ParentShim.getChildren(flowpane).addAll(child1, child2);
150 }
151 flowpane.setAlignment(Pos.TOP_LEFT);
152
153 flowpane.resize(450,450);
154 flowpane.layout();
155
156 // test a handful
157 Node first = ParentShim.getChildren(flowpane).get(0);
158 Node last = ParentShim.getChildren(flowpane).get(5);
159
160 assertEquals(0, first.getLayoutX(), 1e-100);
161 assertEquals(0, first.getLayoutY(), 1e-100);
162 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
163 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
164 assertEquals(100, last.getLayoutX(), 1e-100);
165 assertEquals(250, last.getLayoutY(), 1e-100);
166 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
167 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
168 }
169
170 @Test public void testHorizontalFlowPaneAlignmentTopCenter() {
171 for(int i = 0; i < 3; i++) {
172 MockResizable child1 = new MockResizable(100,200);
173 Rectangle child2 = new Rectangle(100, 100);
174 ParentShim.getChildren(flowpane).addAll(child1, child2);
175 }
176 flowpane.setAlignment(Pos.TOP_CENTER);
177
178 flowpane.resize(450,450);
179 flowpane.layout();
180
181 // test a handful
182 Node first = ParentShim.getChildren(flowpane).get(0);
183 Node last = ParentShim.getChildren(flowpane).get(5);
184
185 assertEquals(25, first.getLayoutX(), 1e-100);
186 assertEquals(0, first.getLayoutY(), 1e-100);
187 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
188 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
189 assertEquals(225, last.getLayoutX(), 1e-100);
190 assertEquals(250, last.getLayoutY(), 1e-100);
191 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
192 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
193 }
194
195 @Test public void testHorizontalFlowPaneAlignmentTopRight() {
196 for(int i = 0; i < 3; i++) {
197 MockResizable child1 = new MockResizable(100,200);
198 Rectangle child2 = new Rectangle(100, 100);
199 ParentShim.getChildren(flowpane).addAll(child1, child2);
200 }
201 flowpane.setAlignment(Pos.TOP_RIGHT);
202
203 flowpane.resize(450,450);
204 flowpane.layout();
205
206 // test a handful
207 Node first = ParentShim.getChildren(flowpane).get(0);
208 Node last = ParentShim.getChildren(flowpane).get(5);
209
210 assertEquals(50, first.getLayoutX(), 1e-100);
211 assertEquals(0, first.getLayoutY(), 1e-100);
212 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
213 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
214 assertEquals(350, last.getLayoutX(), 1e-100);
215 assertEquals(250, last.getLayoutY(), 1e-100);
216 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
217 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
218 }
219
220 @Test public void testHorizontalFlowPaneAlignmentCenterLeft() {
221 for(int i = 0; i < 3; i++) {
222 MockResizable child1 = new MockResizable(100,200);
223 Rectangle child2 = new Rectangle(100, 100);
224 ParentShim.getChildren(flowpane).addAll(child1, child2);
225 }
226 flowpane.setAlignment(Pos.CENTER_LEFT);
227
228 flowpane.resize(450,450);
229 flowpane.layout();
230
231 // test a handful
232 Node first = ParentShim.getChildren(flowpane).get(0);
233 Node last = ParentShim.getChildren(flowpane).get(5);
234
235 assertEquals(0, first.getLayoutX(), 1e-100);
236 assertEquals(25, first.getLayoutY(), 1e-100);
237 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
238 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
239 assertEquals(100, last.getLayoutX(), 1e-100);
240 assertEquals(275, last.getLayoutY(), 1e-100);
241 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
242 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
243 }
244
245 @Test public void testHorizontalFlowPaneAlignmentCenter() {
246 for(int i = 0; i < 3; i++) {
247 MockResizable child1 = new MockResizable(100,200);
248 Rectangle child2 = new Rectangle(100, 100);
249 ParentShim.getChildren(flowpane).addAll(child1, child2);
250 }
251 flowpane.setAlignment(Pos.CENTER);
252
253 flowpane.resize(450,450);
254 flowpane.layout();
255
256 // test a handful
257 Node first = ParentShim.getChildren(flowpane).get(0);
258 Node last = ParentShim.getChildren(flowpane).get(5);
259
260 assertEquals(25, first.getLayoutX(), 1e-100);
261 assertEquals(25, first.getLayoutY(), 1e-100);
262 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
263 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
264 assertEquals(225, last.getLayoutX(), 1e-100);
265 assertEquals(275, last.getLayoutY(), 1e-100);
266 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
267 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
268 }
269
270 @Test public void testHorizontalFlowPaneAlignmentCenterRight() {
271 for(int i = 0; i < 3; i++) {
272 MockResizable child1 = new MockResizable(100,200);
273 Rectangle child2 = new Rectangle(100, 100);
274 ParentShim.getChildren(flowpane).addAll(child1, child2);
275 }
276 flowpane.setAlignment(Pos.CENTER_RIGHT);
277
278 flowpane.resize(450,450);
279 flowpane.layout();
280
281 // test a handful
282 Node first = ParentShim.getChildren(flowpane).get(0);
283 Node last = ParentShim.getChildren(flowpane).get(5);
284
285 assertEquals(50, first.getLayoutX(), 1e-100);
286 assertEquals(25, first.getLayoutY(), 1e-100);
287 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
288 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
289 assertEquals(350, last.getLayoutX(), 1e-100);
290 assertEquals(275, last.getLayoutY(), 1e-100);
291 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
292 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
293 }
294
295 @Test public void testHorizontalFlowPaneAlignmentBottomLeft() {
296 for(int i = 0; i < 3; i++) {
297 MockResizable child1 = new MockResizable(100,200);
298 Rectangle child2 = new Rectangle(100, 100);
299 ParentShim.getChildren(flowpane).addAll(child1, child2);
300 }
301 flowpane.setAlignment(Pos.BOTTOM_LEFT);
302
303 flowpane.resize(450,450);
304 flowpane.layout();
305
306 // test a handful
307 Node first = ParentShim.getChildren(flowpane).get(0);
308 Node last = ParentShim.getChildren(flowpane).get(5);
309
310 assertEquals(0, first.getLayoutX(), 1e-100);
311 assertEquals(50, first.getLayoutY(), 1e-100);
312 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
313 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
314 assertEquals(100, last.getLayoutX(), 1e-100);
315 assertEquals(300, last.getLayoutY(), 1e-100);
316 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
317 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
318 }
319
320 @Test public void testHorizontalFlowPaneAlignmentBottomCenter() {
321 for(int i = 0; i < 3; i++) {
322 MockResizable child1 = new MockResizable(100,200);
323 Rectangle child2 = new Rectangle(100, 100);
324 ParentShim.getChildren(flowpane).addAll(child1, child2);
325 }
326 flowpane.setAlignment(Pos.BOTTOM_CENTER);
327
328 flowpane.resize(450,450);
329 flowpane.layout();
330
331 // test a handful
332 Node first = ParentShim.getChildren(flowpane).get(0);
333 Node last = ParentShim.getChildren(flowpane).get(5);
334
335 assertEquals(25, first.getLayoutX(), 1e-100);
336 assertEquals(50, first.getLayoutY(), 1e-100);
337 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
338 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
339 assertEquals(225, last.getLayoutX(), 1e-100);
340 assertEquals(300, last.getLayoutY(), 1e-100);
341 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
342 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
343 }
344
345 @Test public void testHorizontalFlowPaneAlignmentBottomRight() {
346 for(int i = 0; i < 3; i++) {
347 MockResizable child1 = new MockResizable(100,200);
348 Rectangle child2 = new Rectangle(100, 100);
349 ParentShim.getChildren(flowpane).addAll(child1, child2);
350 }
351 flowpane.setAlignment(Pos.BOTTOM_RIGHT);
352
353 flowpane.resize(450,450);
354 flowpane.layout();
355
356 // test a handful
357 Node first = ParentShim.getChildren(flowpane).get(0);
358 Node last = ParentShim.getChildren(flowpane).get(5);
359
360 assertEquals(50, first.getLayoutX(), 1e-100);
361 assertEquals(50, first.getLayoutY(), 1e-100);
362 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
363 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
364 assertEquals(350, last.getLayoutX(), 1e-100);
365 assertEquals(300, last.getLayoutY(), 1e-100);
366 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
367 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
368 }
369
370 @Test public void testVerticalFlowPaneAlignmentTopLeft() {
371 flowpane.setOrientation(Orientation.VERTICAL);
372
373 for(int i = 0; i < 3; i++) {
374 MockResizable child1 = new MockResizable(200,300);
375 Rectangle child2 = new Rectangle(100, 100);
376 ParentShim.getChildren(flowpane).addAll(child1, child2);
377 }
378 flowpane.setAlignment(Pos.TOP_LEFT);
379
380 flowpane.resize(700,600);
381 flowpane.layout();
382
383 // test a handful
384 Node first = ParentShim.getChildren(flowpane).get(0);
385 Node last = ParentShim.getChildren(flowpane).get(5);
386
387 assertEquals(0, first.getLayoutX(), 1e-100);
388 assertEquals(0, first.getLayoutY(), 1e-100);
389 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
390 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
391 assertEquals(400, last.getLayoutX(), 1e-100);
392 assertEquals(300, last.getLayoutY(), 1e-100);
393 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
394 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
395 }
396
397 @Test public void testVerticalFlowPaneAlignmentTopCenter() {
398 flowpane.setOrientation(Orientation.VERTICAL);
399
400 for(int i = 0; i < 3; i++) {
401 MockResizable child1 = new MockResizable(200,300);
402 Rectangle child2 = new Rectangle(100, 100);
403 ParentShim.getChildren(flowpane).addAll(child1, child2);
404 }
405 flowpane.setAlignment(Pos.TOP_CENTER);
406
407 flowpane.resize(700,600);
408 flowpane.layout();
409
410 // test a handful
411 Node first = ParentShim.getChildren(flowpane).get(0);
412 Node last = ParentShim.getChildren(flowpane).get(5);
413
414 assertEquals(50, first.getLayoutX(), 1e-100);
415 assertEquals(0, first.getLayoutY(), 1e-100);
416 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
417 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
418 assertEquals(450, last.getLayoutX(), 1e-100);
419 assertEquals(300, last.getLayoutY(), 1e-100);
420 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
421 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
422 }
423
424 @Test public void testVerticalFlowPaneAlignmentTopRight() {
425 flowpane.setOrientation(Orientation.VERTICAL);
426
427 for(int i = 0; i < 3; i++) {
428 MockResizable child1 = new MockResizable(200,300);
429 Rectangle child2 = new Rectangle(100, 100);
430 ParentShim.getChildren(flowpane).addAll(child1, child2);
431 }
432 flowpane.setAlignment(Pos.TOP_RIGHT);
433
434 flowpane.resize(700,600);
435 flowpane.layout();
436
437 // test a handful
438 Node first = ParentShim.getChildren(flowpane).get(0);
439 Node last = ParentShim.getChildren(flowpane).get(5);
440
441 assertEquals(100, first.getLayoutX(), 1e-100);
442 assertEquals(0, first.getLayoutY(), 1e-100);
443 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
444 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
445 assertEquals(500, last.getLayoutX(), 1e-100);
446 assertEquals(300, last.getLayoutY(), 1e-100);
447 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
448 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
449 }
450
451 @Test public void testVerticalFlowPaneAlignmentCenterLeft() {
452 flowpane.setOrientation(Orientation.VERTICAL);
453
454 for(int i = 0; i < 3; i++) {
455 MockResizable child1 = new MockResizable(200,300);
456 Rectangle child2 = new Rectangle(100, 100);
457 ParentShim.getChildren(flowpane).addAll(child1, child2);
458 }
459 flowpane.setAlignment(Pos.CENTER_LEFT);
460
461 flowpane.resize(700,600);
462 flowpane.layout();
463
464 // test a handful
465 Node first = ParentShim.getChildren(flowpane).get(0);
466 Node last = ParentShim.getChildren(flowpane).get(5);
467
468 assertEquals(0, first.getLayoutX(), 1e-100);
469 assertEquals(100, first.getLayoutY(), 1e-100);
470 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
471 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
472 assertEquals(400, last.getLayoutX(), 1e-100);
473 assertEquals(400, last.getLayoutY(), 1e-100);
474 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
475 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
476 }
477
478 @Test public void testVerticalFlowPaneAlignmentCenter() {
479 flowpane.setOrientation(Orientation.VERTICAL);
480
481 for(int i = 0; i < 3; i++) {
482 MockResizable child1 = new MockResizable(200,300);
483 Rectangle child2 = new Rectangle(100, 100);
484 ParentShim.getChildren(flowpane).addAll(child1, child2);
485 }
486 flowpane.setAlignment(Pos.CENTER);
487
488 flowpane.resize(700,600);
489 flowpane.layout();
490
491 // test a handful
492 Node first = ParentShim.getChildren(flowpane).get(0);
493 Node last = ParentShim.getChildren(flowpane).get(5);
494
495 assertEquals(50, first.getLayoutX(), 1e-100);
496 assertEquals(100, first.getLayoutY(), 1e-100);
497 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
498 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
499 assertEquals(450, last.getLayoutX(), 1e-100);
500 assertEquals(400, last.getLayoutY(), 1e-100);
501 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
502 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
503 }
504
505 @Test public void testVerticalFlowPaneAlignmentCenterRight() {
506 flowpane.setOrientation(Orientation.VERTICAL);
507
508 for(int i = 0; i < 3; i++) {
509 MockResizable child1 = new MockResizable(200,300);
510 Rectangle child2 = new Rectangle(100, 100);
511 ParentShim.getChildren(flowpane).addAll(child1, child2);
512 }
513 flowpane.setAlignment(Pos.CENTER_RIGHT);
514
515 flowpane.resize(700,600);
516 flowpane.layout();
517
518 // test a handful
519 Node first = ParentShim.getChildren(flowpane).get(0);
520 Node last = ParentShim.getChildren(flowpane).get(5);
521
522 assertEquals(100, first.getLayoutX(), 1e-100);
523 assertEquals(100, first.getLayoutY(), 1e-100);
524 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
525 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
526 assertEquals(500, last.getLayoutX(), 1e-100);
527 assertEquals(400, last.getLayoutY(), 1e-100);
528 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
529 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
530 }
531
532 @Test public void testVerticalFlowPaneAlignmentBottomLeft() {
533 flowpane.setOrientation(Orientation.VERTICAL);
534
535 for(int i = 0; i < 3; i++) {
536 MockResizable child1 = new MockResizable(200,300);
537 Rectangle child2 = new Rectangle(100, 100);
538 ParentShim.getChildren(flowpane).addAll(child1, child2);
539 }
540 flowpane.setAlignment(Pos.BOTTOM_LEFT);
541
542 flowpane.resize(700,600);
543 flowpane.layout();
544
545 // test a handful
546 Node first = ParentShim.getChildren(flowpane).get(0);
547 Node last = ParentShim.getChildren(flowpane).get(5);
548
549 assertEquals(0, first.getLayoutX(), 1e-100);
550 assertEquals(200, first.getLayoutY(), 1e-100);
551 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
552 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
553 assertEquals(400, last.getLayoutX(), 1e-100);
554 assertEquals(500, last.getLayoutY(), 1e-100);
555 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
556 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
557 }
558
559 @Test public void testVerticalFlowPaneAlignmentBottomCenter() {
560 flowpane.setOrientation(Orientation.VERTICAL);
561
562 for(int i = 0; i < 3; i++) {
563 MockResizable child1 = new MockResizable(200,300);
564 Rectangle child2 = new Rectangle(100, 100);
565 ParentShim.getChildren(flowpane).addAll(child1, child2);
566 }
567 flowpane.setAlignment(Pos.BOTTOM_CENTER);
568
569 flowpane.resize(700,600);
570 flowpane.layout();
571
572 // test a handful
573 Node first = ParentShim.getChildren(flowpane).get(0);
574 Node last = ParentShim.getChildren(flowpane).get(5);
575
576 assertEquals(50, first.getLayoutX(), 1e-100);
577 assertEquals(200, first.getLayoutY(), 1e-100);
578 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
579 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
580 assertEquals(450, last.getLayoutX(), 1e-100);
581 assertEquals(500, last.getLayoutY(), 1e-100);
582 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
583 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
584 }
585
586 @Test public void testVerticalFlowPaneAlignmentBottomRight() {
587 flowpane.setOrientation(Orientation.VERTICAL);
588
589 for(int i = 0; i < 3; i++) {
590 MockResizable child1 = new MockResizable(200,300);
591 Rectangle child2 = new Rectangle(100, 100);
592 ParentShim.getChildren(flowpane).addAll(child1, child2);
593 }
594 flowpane.setAlignment(Pos.BOTTOM_RIGHT);
595
596 flowpane.resize(700,600);
597 flowpane.layout();
598
599 // test a handful
600 Node first = ParentShim.getChildren(flowpane).get(0);
601 Node last = ParentShim.getChildren(flowpane).get(5);
602
603 assertEquals(100, first.getLayoutX(), 1e-100);
604 assertEquals(200, first.getLayoutY(), 1e-100);
605 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
606 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
607 assertEquals(500, last.getLayoutX(), 1e-100);
608 assertEquals(500, last.getLayoutY(), 1e-100);
609 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
610 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
611 }
612
613 @Test public void testHorizontalFlowPaneRowVAlignmentTop() {
614 for(int i = 0; i < 3; i++) {
615 MockResizable child1 = new MockResizable(100,200);
616 Rectangle child2 = new Rectangle(100, 100);
617 ParentShim.getChildren(flowpane).addAll(child1, child2);
618 }
619 flowpane.setRowValignment(VPos.TOP);
620
621 flowpane.resize(450,450);
622 flowpane.layout();
623
624 // test a handful
625 Node first = ParentShim.getChildren(flowpane).get(0);
626 Node last = ParentShim.getChildren(flowpane).get(5);
627
628 assertEquals(0, first.getLayoutX(), 1e-100);
629 assertEquals(0, first.getLayoutY(), 1e-100);
630 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
631 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
632 assertEquals(100, last.getLayoutX(), 1e-100);
633 assertEquals(200, last.getLayoutY(), 1e-100);
634 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
635 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
636 }
637
638 @Test public void testHorizontalFlowPaneRowVAlignmentCenter() {
639 for(int i = 0; i < 3; i++) {
640 MockResizable child1 = new MockResizable(100,200);
641 Rectangle child2 = new Rectangle(100, 100);
642 ParentShim.getChildren(flowpane).addAll(child1, child2);
643 }
644 flowpane.setRowValignment(VPos.CENTER);
645
646 flowpane.resize(450,450);
647 flowpane.layout();
648
649 // test a handful
650 Node first = ParentShim.getChildren(flowpane).get(0);
651 Node last = ParentShim.getChildren(flowpane).get(5);
652
653 assertEquals(0, first.getLayoutX(), 1e-100);
654 assertEquals(0, first.getLayoutY(), 1e-100);
655 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
656 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
657 assertEquals(100, last.getLayoutX(), 1e-100);
658 assertEquals(250, last.getLayoutY(), 1e-100);
659 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
660 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
661 }
662
663 @Test public void testHorizontalFlowPaneRowVAlignmentBaseline() {
664 for(int i = 0; i < 3; i++) {
665 MockResizable child1 = new MockResizable(100,200); //baseline=190
666 Rectangle child2 = new Rectangle(100, 100);
667 ParentShim.getChildren(flowpane).addAll(child1, child2);
668 }
669 flowpane.setRowValignment(VPos.BASELINE);
670
671 flowpane.resize(450,450);
672 flowpane.layout();
673
674 // test a handful
675 Node first = ParentShim.getChildren(flowpane).get(0);
676 Node last = ParentShim.getChildren(flowpane).get(5);
677
678 assertEquals(0, first.getLayoutX(), 1e-100);
679 assertEquals(0, first.getLayoutY(), 1e-100);
680 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
681 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
682 assertEquals(100, last.getLayoutX(), 1e-100);
683 assertEquals(290, last.getLayoutY(), 1e-100);
684 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
685 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
686 }
687
688 @Test public void testHorizontalFlowPaneRowVAlignmentBottom() {
689 for(int i = 0; i < 3; i++) {
690 MockResizable child1 = new MockResizable(100,200);
691 Rectangle child2 = new Rectangle(100, 100);
692 ParentShim.getChildren(flowpane).addAll(child1, child2);
693 }
694 flowpane.setRowValignment(VPos.BOTTOM);
695
696 flowpane.resize(450,450);
697 flowpane.layout();
698
699 // test a handful
700 Node first = ParentShim.getChildren(flowpane).get(0);
701 Node last = ParentShim.getChildren(flowpane).get(5);
702
703 assertEquals(0, first.getLayoutX(), 1e-100);
704 assertEquals(0, first.getLayoutY(), 1e-100);
705 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
706 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
707 assertEquals(100, last.getLayoutX(), 1e-100);
708 assertEquals(300, last.getLayoutY(), 1e-100);
709 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
710 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
711 }
712
713 @Test public void testVerticalFlowPaneRowHAlignmentLeft() {
714 flowpane.setOrientation(Orientation.VERTICAL);
715
716 for(int i = 0; i < 3; i++) {
717 MockResizable child1 = new MockResizable(200,300);
718 Rectangle child2 = new Rectangle(100, 100);
719 ParentShim.getChildren(flowpane).addAll(child1, child2);
720 }
721 flowpane.setColumnHalignment(HPos.LEFT);
722
723 flowpane.resize(600,800);
724 flowpane.layout();
725
726 // test a handful
727 Node first = ParentShim.getChildren(flowpane).get(0);
728 Node last = ParentShim.getChildren(flowpane).get(5);
729
730 assertEquals(0, first.getLayoutX(), 1e-100);
731 assertEquals(0, first.getLayoutY(), 1e-100);
732 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
733 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
734 assertEquals(200, last.getLayoutX(), 1e-100);
735 assertEquals(300, last.getLayoutY(), 1e-100);
736 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
737 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
738 }
739
740 @Test public void testVerticalFlowPaneRowHAlignmentCenter() {
741 flowpane.setOrientation(Orientation.VERTICAL);
742
743 for(int i = 0; i < 3; i++) {
744 MockResizable child1 = new MockResizable(200,300);
745 Rectangle child2 = new Rectangle(100, 100);
746 ParentShim.getChildren(flowpane).addAll(child1, child2);
747 }
748 flowpane.setColumnHalignment(HPos.CENTER);
749
750 flowpane.resize(600,800);
751 flowpane.layout();
752
753 // test a handful
754 Node first = ParentShim.getChildren(flowpane).get(0);
755 Node last = ParentShim.getChildren(flowpane).get(5);
756
757 assertEquals(0, first.getLayoutX(), 1e-100);
758 assertEquals(0, first.getLayoutY(), 1e-100);
759 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
760 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
761 assertEquals(250, last.getLayoutX(), 1e-100);
762 assertEquals(300, last.getLayoutY(), 1e-100);
763 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
764 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
765 }
766
767 @Test public void testVerticalFlowPaneRowHAlignmentRight() {
768 flowpane.setOrientation(Orientation.VERTICAL);
769
770 for(int i = 0; i < 3; i++) {
771 MockResizable child1 = new MockResizable(200,300);
772 Rectangle child2 = new Rectangle(100, 100);
773 ParentShim.getChildren(flowpane).addAll(child1, child2);
774 }
775 flowpane.setColumnHalignment(HPos.RIGHT);
776
777 flowpane.resize(600,800);
778 flowpane.layout();
779
780 // test a handful
781 Node first = ParentShim.getChildren(flowpane).get(0);
782 Node last = ParentShim.getChildren(flowpane).get(5);
783
784 assertEquals(0, first.getLayoutX(), 1e-100);
785 assertEquals(0, first.getLayoutY(), 1e-100);
786 assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
787 assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
788 assertEquals(300, last.getLayoutX(), 1e-100);
789 assertEquals(300, last.getLayoutY(), 1e-100);
790 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
791 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
792 }
793
794 @Test public void testFlowPaneSetMarginConstraint() {
795 MockResizable child1 = new MockResizable(100,200, 300,400, 500,600);
796
797 assertNull(FlowPane.getMargin(child1));
798
799 Insets margin = new Insets(10,20,30,40);
800 FlowPane.setMargin(child1, margin);
801 assertEquals(margin, FlowPane.getMargin(child1));
802
803 FlowPane.setMargin(child1, null);
804 assertNull(FlowPane.getMargin(child1));
805 }
806
807 @Test public void testFlowPaneMarginConstraint() {
808 for(int i = 0; i < 3; i++) {
809 MockResizable child1 = new MockResizable(100,200);
810 Rectangle child2 = new Rectangle(100, 100);
811 ParentShim.getChildren(flowpane).addAll(child1, child2);
812 }
813
814 // test a handful
815 Node first = ParentShim.getChildren(flowpane).get(0);
816 Node last = ParentShim.getChildren(flowpane).get(5);
817
818 FlowPane.setMargin(first, new Insets(10,20,30,40));
819
820 assertEquals(100, flowpane.minWidth(-1), 1e-100);
821 assertEquals(940, flowpane.minHeight(100), 1e-100);
822 assertEquals(400, flowpane.prefWidth(-1), 1e-100);
823 assertEquals(440, flowpane.prefHeight(-1), 1e-100);
824
825 flowpane.autosize();
826 flowpane.layout();
827
828 assertEquals(40, first.getLayoutX(), 1e-100);
829 assertEquals(10, first.getLayoutY(), 1e-100);
830 assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
831 assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
832 assertEquals(200, last.getLayoutX(), 1e-100);
833 assertEquals(290, last.getLayoutY(), 1e-100);
834 assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
835 assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
836 }
837
838 // FlowPane does not shrink their children to be smaller than their preferred sizes
839 @Test public void testHorizontalFlowPaneFitsChildWithinHeightIfPossible() {
840 MockResizable child = new MockResizable(10,20, 200,200, 500,500);
841
842 ParentShim.getChildren(flowpane).add(child);
843
844 flowpane.resize(100,100);
845 flowpane.layout();
846
847 assertEquals(200, child.getWidth(), 1e-100);
848 assertEquals(200, child.getHeight(), 1e-100);
849 }
850
851 @Test public void testVerticalFlowPaneFitsChildWithinWidthIfPossible() {
852 flowpane.setOrientation(Orientation.VERTICAL);
853 MockResizable child = new MockResizable(10,20, 200,200, 500,500);
854
855 ParentShim.getChildren(flowpane).add(child);
856
857 flowpane.resize(100,100);
858 System.out.println("******************");
859 flowpane.layout();
860 System.out.println("*****************");
861
862 assertEquals(200, child.getWidth(), 1e-100);
863 assertEquals(200, child.getHeight(), 1e-100);
864 }
865 }
|