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 javafx.geometry.HPos;
29 import javafx.geometry.Insets;
30 import javafx.geometry.Orientation;
31 import javafx.geometry.VPos;
32 import javafx.scene.image.Image;
33 import javafx.scene.image.ImageForTesting;
34 import javafx.scene.image.WritableImage;
35 import javafx.scene.paint.Color;
36 import javafx.scene.shape.ClosePath;
37 import javafx.scene.shape.LineTo;
38 import javafx.scene.shape.MoveTo;
39 import javafx.scene.shape.Path;
40 import java.util.concurrent.atomic.AtomicBoolean;
41 import com.sun.javafx.scene.DirtyBits;
42 import com.sun.javafx.sg.prism.NGRegion;
43 import org.junit.Test;
44 import static org.junit.Assert.assertEquals;
45 import static org.junit.Assert.assertFalse;
46 import static org.junit.Assert.assertTrue;
47 import static org.junit.Assert.fail;
48
49 /**
50 *
51 */
52 public class RegionTest {
53
54 @Test public void testPaddingEmptyByDefault() {
55 Region region = new Region();
56
57 assertEquals(Insets.EMPTY, region.getPadding());
58 }
59
60 @Test public void testPaddingCannotBeSetToNull() {
61 Region region = new Region();
62
65 fail("NullPointerException expected if padding set to null.");
66 } catch (Exception e) {
67 // expected
68 }
69
70 try {
71 region.paddingProperty().set(null);
72 fail("NullPointerException expected if padding set to null.");
73 } catch (Exception e) {
74 // expected
75 }
76 }
77
78 @Test public void testInsetsEqualsPaddingByDefault() {
79 Region region = new Region();
80
81 assertEquals(region.getInsets(), region.getPadding());
82 }
83
84 @Test public void testBoundedSizeReturnsPrefWhenPrefBetweenMinAndMax() {
85 assertEquals(200, Region.boundedSize(100, 200, 300), 0);
86 }
87
88 @Test public void testBoundedSizeReturnsMinWhenMinGreaterThanPrefButLessThanMax() {
89 assertEquals(200, Region.boundedSize(200, 100, 300), 0);
90 }
91
92 @Test public void testBoundedSizeReturnsMinWhenMinGreaterThanPrefAndMax() {
93 assertEquals(300, Region.boundedSize(300, 100, 200), 0);
94 }
95
96 @Test public void testBoundedSizeReturnsMaxWhenMaxLessThanPrefButGreaterThanMin() {
97 assertEquals(200, Region.boundedSize(100, 300, 200), 0);
98 }
99
100 @Test public void testBoundedSizeReturnsMinWhenMaxLessThanPrefAndMin() {
101 assertEquals(200, Region.boundedSize(200, 300, 100), 0);
102 }
103
104 @Test public void testBoundedSizeReturnsMinWhenMaxLessThanPrefAndMinAndPrefLessThanMin() {
105 assertEquals(300, Region.boundedSize(300, 200, 100), 0);
106 }
107
108 @Test public void testMinWidthOverride() {
109 Region region = new MockRegion(10,20, 100,200, 500,600);
110 assertEquals(10, region.minWidth(-1), 1e-100);
111 region.setMinWidth(25.0);
112 assertEquals(25, region.getMinWidth(), 1e-100);
113 assertEquals(25, region.minWidth(-1), 1e-100);
114 }
115
116 @Test public void testMinWidthOverrideThenRestoreComputedSize() {
117 Region region = new MockRegion(10,20, 100,200, 500,600);
118 region.setMinWidth(75.0);
119 region.setMinWidth(Region.USE_COMPUTED_SIZE); // reset
120 assertEquals(Region.USE_COMPUTED_SIZE, region.getMinWidth(), 1e-100);
121 assertEquals(10, region.minWidth(-1), 1e-100);
122 }
123
124 @Test public void testMinWidthNaNTreatedAsZero() {
125 Region region = new Region();
307 region.setMaxWidth(Region.USE_PREF_SIZE);
308 assertEquals(Region.USE_PREF_SIZE, region.getMaxWidth(), 0);
309 assertEquals(100, region.maxWidth(-1), 1e-100);
310 }
311
312 @Test public void testMaxHeightOverrideSetToPref() {
313 Region region = new MockRegion(10,20, 100,200, 500,600);
314 assertEquals(600, region.maxHeight(-1), 1e-100);
315 region.setMaxHeight(Region.USE_PREF_SIZE);
316 assertEquals(Region.USE_PREF_SIZE, region.getMaxHeight(), 0);
317 assertEquals(200, region.maxHeight(-1), 1e-100);
318 }
319
320 @Test public void testPositionInAreaForResizableForResizableTopLeft() {
321 Pane pane = new Pane(); // Region extension which makes children sequence public
322
323 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
324 pane.getChildren().add(child);
325
326 child.autosize();
327 pane.positionInArea(child, 10, 10, 100, 100, 0, HPos.LEFT, VPos.TOP);
328
329 assertEquals(30, child.getWidth(), 1e-100);
330 assertEquals(40, child.getHeight(), 1e-100);
331 assertEquals(10, child.getLayoutX(), 1e-100);
332 assertEquals(10, child.getLayoutY(), 1e-100);
333 }
334
335 @Test public void testPositionInAreaForResizableTopCenter() {
336 Pane pane = new Pane(); // Region extension which makes children sequence public
337
338 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
339 pane.getChildren().add(child);
340
341 child.autosize();
342 pane.positionInArea(child, 10, 10, 100, 100, 0, HPos.CENTER, VPos.TOP);
343
344 assertEquals(30, child.getWidth(), 1e-100);
345 assertEquals(40, child.getHeight(), 1e-100);
346 assertEquals(45, child.getLayoutX(), 1e-100);
347 assertEquals(10, child.getLayoutY(), 1e-100);
348 }
349
350 @Test public void testPositionInAreaForResizableTopRight() {
351 Pane pane = new Pane(); // Region extension which makes children sequence public
352
353 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
354 pane.getChildren().add(child);
355
356 child.autosize();
357 pane.positionInArea(child, 10, 10, 100, 100, 0, HPos.RIGHT, VPos.TOP);
358
359 assertEquals(30, child.getWidth(), 1e-100);
360 assertEquals(40, child.getHeight(), 1e-100);
361 assertEquals(80, child.getLayoutX(), 1e-100);
362 assertEquals(10, child.getLayoutY(), 1e-100);
363 }
364
365 @Test public void testPositionInAreaForResizableCenterLeft() {
366 Pane pane = new Pane(); // Region extension which makes children sequence public
367
368 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
369 pane.getChildren().add(child);
370
371 child.autosize();
372 pane.positionInArea(child, 10, 10, 100, 100, 0, HPos.LEFT, VPos.CENTER);
373
374 assertEquals(30, child.getWidth(), 1e-100);
375 assertEquals(40, child.getHeight(), 1e-100);
376 assertEquals(10, child.getLayoutX(), 1e-100);
377 assertEquals(40, child.getLayoutY(), 1e-100);
378 }
379
380 // // See RT-19282
381 // @Test public void testPositionInAreaForNONResizableCenterLeft() {
382 // Pane pane = new Pane(); // Region extension which makes children sequence public
383 //
384 // Rectangle child = new Rectangle(50.4, 50.4);
385 // pane.getChildren().add(child);
386 //
387 // pane.positionInArea(child, 10, 10, 100, 100, 0, HPos.LEFT, VPos.CENTER);
388 //
389 // assertEquals(10, child.getLayoutX(), .01);
390 // assertEquals(34.8, child.getLayoutY(), .01);
391 // }
392
393
394 @Test public void testPositionInAreaForResizableCenter() {
395 Pane pane = new Pane(); // Region extension which makes children sequence public
396
397 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
398 pane.getChildren().add(child);
399
400 child.autosize();
401 pane.positionInArea(child, 10, 10, 100, 100, 0, HPos.CENTER, VPos.CENTER);
402
403 assertEquals(30, child.getWidth(), 1e-100);
404 assertEquals(40, child.getHeight(), 1e-100);
405 assertEquals(45, child.getLayoutX(), 1e-100);
406 assertEquals(40, child.getLayoutY(), 1e-100);
407 }
408
409 // // See RT-19282
410 // @Test public void testPositionInAreaForNONResizableCenter() {
411 // Pane pane = new Pane(); // Region extension which makes children sequence public
412 //
413 // Rectangle child = new Rectangle(50.4, 50.4);
414 // pane.getChildren().add(child);
415 //
416 // pane.positionInArea(child, 10, 10, 100, 100, 0, HPos.CENTER, VPos.CENTER);
417 //
418 // assertEquals(34.8, child.getLayoutX(), .01);
419 // assertEquals(34.8, child.getLayoutY(), .01);
420 // }
421
422 @Test public void testPositionInAreaForResizableCenterRight() {
423 Pane pane = new Pane(); // Region extension which makes children sequence public
424
425 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
426 pane.getChildren().add(child);
427
428 child.autosize();
429 pane.positionInArea(child, 10, 10, 100, 100, 0, HPos.RIGHT, VPos.CENTER);
430
431 assertEquals(30, child.getWidth(), 1e-100);
432 assertEquals(40, child.getHeight(), 1e-100);
433 assertEquals(80, child.getLayoutX(), 1e-100);
434 assertEquals(40, child.getLayoutY(), 1e-100);
435 }
436
437 @Test public void testPositionInAreaForResizableBottomLeft() {
438 Pane pane = new Pane(); // Region extension which makes children sequence public
439
440 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
441 pane.getChildren().add(child);
442
443 child.autosize();
444 pane.positionInArea(child, 10, 10, 100, 100, 0, HPos.LEFT, VPos.BOTTOM);
445
446 assertEquals(30, child.getWidth(), 1e-100);
447 assertEquals(40, child.getHeight(), 1e-100);
448 assertEquals(10, child.getLayoutX(), 1e-100);
449 assertEquals(70, child.getLayoutY(), 1e-100);
450 }
451
452 // // See RT-19282
453 // @Test public void testPositionInAreaForNONResizableBottomLeft() {
454 // Pane pane = new Pane(); // Region extension which makes children sequence public
455 //
456 // Rectangle child = new Rectangle(50.4, 50.4);
457 // pane.getChildren().add(child);
458 //
459 // pane.positionInArea(child, 10, 10, 100, 100, 0, HPos.LEFT, VPos.BOTTOM);
460 //
461 // assertEquals(10, child.getLayoutX(), .01);
462 // assertEquals(59.6, child.getLayoutY(), .01);
463 // }
464
465 @Test public void testPositionInAreaForResizableBottomCenter() {
466 Pane pane = new Pane(); // Region extension which makes children sequence public
467
468 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
469 pane.getChildren().add(child);
470
471 child.autosize();
472 pane.positionInArea(child, 10, 10, 100, 100, 0, HPos.CENTER, VPos.BOTTOM);
473
474 assertEquals(30, child.getWidth(), 1e-100);
475 assertEquals(40, child.getHeight(), 1e-100);
476 assertEquals(45, child.getLayoutX(), 1e-100);
477 assertEquals(70, child.getLayoutY(), 1e-100);
478 }
479
480 // // See RT-19282
481 // @Test public void testPositionInAreaForNONResizableBottomCenter() {
482 // Pane pane = new Pane(); // Region extension which makes children sequence public
483 //
484 // Rectangle child = new Rectangle(50.4, 50.4);
485 // pane.getChildren().add(child);
486 //
487 // pane.positionInArea(child, 10, 10, 100, 100, 0, HPos.CENTER, VPos.BOTTOM);
488 //
489 // assertEquals(34.8, child.getLayoutX(), .01);
490 // assertEquals(59.6, child.getLayoutY(), .01);
491 // }
492
493 @Test public void testPositionInAreaForResizableBottomRight() {
494 Pane pane = new Pane(); // Region extension which makes children sequence public
495
496 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
497 pane.getChildren().add(child);
498
499 child.autosize();
500 pane.positionInArea(child, 10, 10, 100, 100, 0, HPos.RIGHT, VPos.BOTTOM);
501
502 assertEquals(30, child.getWidth(), 1e-100);
503 assertEquals(40, child.getHeight(), 1e-100);
504 assertEquals(80, child.getLayoutX(), 1e-100);
505 assertEquals(70, child.getLayoutY(), 1e-100);
506 }
507
508 // // See RT-19282
509 // @Test public void testPositionInAreaForNONResizableBottomRight() {
510 // Pane pane = new Pane(); // Region extension which makes children sequence public
511 //
512 // Rectangle child = new Rectangle(50.4, 50.4);
513 // pane.getChildren().add(child);
514 //
515 // pane.positionInArea(child, 10, 10, 100, 100, 0, HPos.RIGHT, VPos.BOTTOM);
516 //
517 // assertEquals(59.6, child.getLayoutX(), .01);
518 // assertEquals(59.6, child.getLayoutY(), .01);
519 // }
520
521 @Test public void testPositionInAreaForResizableBaselineLeft() {
522 Pane pane = new Pane(); // Region extension which makes children sequence public
523
524 MockResizable child = new MockResizable(10,20, 30,40, 50,60); //baseline = 30
525 pane.getChildren().add(child);
526
527 child.autosize();
528 pane.positionInArea(child, 10, 10, 100, 100, 50, HPos.LEFT, VPos.BASELINE);
529
530 assertEquals(30, child.getWidth(), 1e-100);
531 assertEquals(40, child.getHeight(), 1e-100);
532 assertEquals(10, child.getLayoutX(), 1e-100);
533 assertEquals(30, child.getLayoutY(), 1e-100);
534 }
535
536 // // See RT-19282
537 // @Test public void testPositionInAreaForNONResizableBaselineLeft() {
538 // Pane pane = new Pane(); // Region extension which makes children sequence public
539 //
540 // Rectangle child = new Rectangle(50.4, 50.4);
541 // pane.getChildren().add(child);
542 //
543 // pane.positionInArea(child, 10, 10, 100, 100, 60, HPos.LEFT, VPos.BASELINE);
544 //
545 // assertEquals(10, child.getLayoutX(), .01);
546 // assertEquals(19.6, child.getLayoutY(), .01);
547 // }
548
549 @Test public void testPositionInAreaForResizableBaselineCenter() {
550 Pane pane = new Pane(); // Region extension which makes children sequence public
551
552 MockResizable child = new MockResizable(10,20, 30,40, 50,60); //baseline = 30
553 pane.getChildren().add(child);
554
555 child.autosize();
556 pane.positionInArea(child, 10, 10, 100, 100, 50, HPos.CENTER, VPos.BASELINE);
557
558 assertEquals(30, child.getWidth(), 1e-100);
559 assertEquals(40, child.getHeight(), 1e-100);
560 assertEquals(45, child.getLayoutX(), 1e-100);
561 assertEquals(30, child.getLayoutY(), 1e-100);
562 }
563
564 // // See RT-19282
565 // @Test public void testPositionInAreaForNONResizableBaselineCenter() {
566 // Pane pane = new Pane(); // Region extension which makes children sequence public
567 //
568 // Rectangle child = new Rectangle(50.4, 50.4);
569 // pane.getChildren().add(child);
570 //
571 // pane.positionInArea(child, 10, 10, 100, 100, 60, HPos.CENTER, VPos.BASELINE);
572 //
573 // assertEquals(34.8, child.getLayoutX(), .01);
574 // assertEquals(19.6, child.getLayoutY(), .01);
575 // }
576
577 @Test public void testPositionInAreaForResizableBaselineRight() {
578 Pane pane = new Pane(); // Region extension which makes children sequence public
579
580 MockResizable child = new MockResizable(10,20, 30,40, 50,60); //baseline = 30
581 pane.getChildren().add(child);
582
583 child.autosize();
584 pane.positionInArea(child, 10, 10, 100, 100, 50, HPos.RIGHT, VPos.BASELINE);
585
586 assertEquals(30, child.getWidth(), 1e-100);
587 assertEquals(40, child.getHeight(), 1e-100);
588 assertEquals(80, child.getLayoutX(), 1e-100);
589 assertEquals(30, child.getLayoutY(), 1e-100);
590 }
591
592 // // See RT-19282
593 // @Test public void testPositionInAreaForNONResizableBaselineRight() {
594 // Pane pane = new Pane(); // Region extension which makes children sequence public
595 //
596 // Rectangle child = new Rectangle(50.4, 50.4);
597 // pane.getChildren().add(child);
598 //
599 // pane.positionInArea(child, 10, 10, 100, 100, 60, HPos.RIGHT, VPos.BASELINE);
600 //
601 // assertEquals(59.6, child.getLayoutX(), .01);
602 // assertEquals(19.6, child.getLayoutY(), .01);
603 // }
604
605 @Test public void testLayoutInAreaWithLargerMax() {
606 Pane pane = new Pane(); // Region extension which makes children sequence public
607
608 MockResizable child = new MockResizable(10,20, 30,40, 300,300);
609 pane.getChildren().add(child);
610
611 pane.layoutInArea(child, 10, 10, 100, 100, 0, HPos.CENTER, VPos.CENTER);
612
613 assertEquals(100, child.getWidth(), 1e-100);
614 assertEquals(100, child.getHeight(), 1e-100);
615 assertEquals(10, child.getLayoutX(), 1e-100);
616 assertEquals(10, child.getLayoutY(), 1e-100);
617
618 }
619
620 @Test public void testLayoutInAreaWithSmallerMax() {
621 Pane pane = new Pane(); // Region extension which makes children sequence public
622
623 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
624 pane.getChildren().add(child);
625
626 pane.layoutInArea(child, 10, 10, 100, 100, 0, HPos.CENTER, VPos.CENTER);
627
628 assertEquals(50, child.getWidth(), 1e-100);
629 assertEquals(60, child.getHeight(), 1e-100);
630 assertEquals(35, child.getLayoutX(), 1e-100);
631 assertEquals(30, child.getLayoutY(), 1e-100);
632
633 }
634
635 @Test public void testLayoutInAreaWithLargerMin() {
636 Pane pane = new Pane(); // Region extension which makes children sequence public
637
638 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
639 pane.getChildren().add(child);
640
641 pane.layoutInArea(child, 10, 10, 5, 5, 0, HPos.CENTER, VPos.CENTER);
642
643 assertEquals(10, child.getWidth(), 1e-100);
644 assertEquals(20, child.getHeight(), 1e-100);
645 assertEquals(8, child.getLayoutX(), 1e-100);
646 assertEquals(3, child.getLayoutY(), 1e-100);
647
648 }
649
650 @Test public void testLayoutInAreaWithSizeOverrides() {
651 Pane pane = new Pane(); // Region extension which makes children sequence public
652
653 MockRegion child = new MockRegion(10,20, 30,40, 50,60);
654 child.setMinSize(50,60);
655 child.setPrefSize(100,200);
656 child.setMaxSize(500, 500);
657 pane.getChildren().add(child);
658
659 pane.layoutInArea(child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);
660
661 assertEquals(300, child.getWidth(), 1e-100);
662 assertEquals(300, child.getHeight(), 1e-100);
663 assertEquals(10, child.getLayoutX(), 1e-100);
664 assertEquals(10, child.getLayoutY(), 1e-100);
665
666 }
667
668 @Test public void testLayoutInAreaWithMaxConstrainedToPref() {
669 Pane pane = new Pane(); // Region extension which makes children sequence public
670
671 MockRegion child = new MockRegion(10,20, 30,40, 500,500);
672 child.setMinSize(50,60);
673 child.setPrefSize(100,200);
674 child.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
675 pane.getChildren().add(child);
676
677 pane.layoutInArea(child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);
678
679 assertEquals(100, child.getWidth(), 1e-100);
680 assertEquals(200, child.getHeight(), 1e-100);
681 assertEquals(110, child.getLayoutX(), 1e-100);
682 assertEquals(60, child.getLayoutY(), 1e-100);
683
684 }
685
686 @Test public void testLayoutInAreaHonorsMaxWidthOverPref() {
687 Pane pane = new Pane(); // Region extension which makes children sequence public
688
689 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
690 child.setMaxWidth(100); // max less than pref
691 pane.getChildren().add(child);
692
693 pane.layoutInArea(child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);
694
695 assertEquals(100, child.getWidth(), 1e-100);
696 assertEquals(300, child.getHeight(), 1e-100);
697 assertEquals(110, child.getLayoutX(), 1e-100);
698 assertEquals(10, child.getLayoutY(), 1e-100);
699
700 }
701
702 @Test public void testLayoutInAreaHonorsMaxHeightOverPref() {
703 Pane pane = new Pane(); // Region extension which makes children sequence public
704
705 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
706 child.setMaxHeight(100); // max less than pref
707 pane.getChildren().add(child);
708
709 pane.layoutInArea(child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);
710
711 assertEquals(300, child.getWidth(), 1e-100);
712 assertEquals(100, child.getHeight(), 1e-100);
713 assertEquals(10, child.getLayoutX(), 1e-100);
714 assertEquals(110, child.getLayoutY(), 1e-100);
715
716 }
717
718 @Test public void testLayoutInAreaHonorsMinWidthOverPref() {
719 Pane pane = new Pane(); // Region extension which makes children sequence public
720
721 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
722 child.setMinWidth(400); // max less than pref
723 pane.getChildren().add(child);
724
725 pane.layoutInArea(child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);
726
727 assertEquals(400, child.getWidth(), 1e-100);
728 assertEquals(300, child.getHeight(), 1e-100);
729 assertEquals(-40, child.getLayoutX(), 1e-100);
730 assertEquals(10, child.getLayoutY(), 1e-100);
731 }
732
733 @Test public void testLayoutInAreaHonorsMinHeightOverPref() {
734 Pane pane = new Pane(); // Region extension which makes children sequence public
735
736 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
737 child.setMinHeight(400); // max less than pref
738 pane.getChildren().add(child);
739
740 pane.layoutInArea(child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);
741
742 assertEquals(300, child.getWidth(), 1e-100);
743 assertEquals(400, child.getHeight(), 1e-100);
744 assertEquals(10, child.getLayoutX(), 1e-100);
745 assertEquals(-40, child.getLayoutY(), 1e-100);
746 }
747
748 @Test public void testLayoutInAreaHonorsMinWidthOverMax() {
749 Pane pane = new Pane(); // Region extension which makes children sequence public
750
751 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
752 child.setMinWidth(600); // max less than min
753 pane.getChildren().add(child);
754
755 pane.layoutInArea(child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);
756
757 assertEquals(600, child.getWidth(), 1e-100);
758 assertEquals(300, child.getHeight(), 1e-100);
759 assertEquals(-140, child.getLayoutX(), 1e-100);
760 assertEquals(10, child.getLayoutY(), 1e-100);
761 }
762
763 @Test public void testLayoutInAreaHonorsMinHeightOverMax() {
764 Pane pane = new Pane(); // Region extension which makes children sequence public
765
766 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
767 child.setMinHeight(600); // max less than min
768 pane.getChildren().add(child);
769
770 pane.layoutInArea(child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);
771
772 assertEquals(300, child.getWidth(), 1e-100);
773 assertEquals(600, child.getHeight(), 1e-100);
774 assertEquals(10, child.getLayoutX(), 1e-100);
775 assertEquals(-140, child.getLayoutY(), 1e-100);
776 }
777
778 @Test public void testLayoutInAreaHonorsAreaWidthOverPrefWithFillWidth() {
779 Pane pane = new Pane(); // Region extension which makes children sequence public
780
781 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
782 pane.getChildren().add(child);
783
784 pane.layoutInArea(child, 10, 10, 100, 400, 0, Insets.EMPTY, true, true, HPos.CENTER, VPos.CENTER);
785
786 assertEquals(100, child.getWidth(), 1e-100);
787 assertEquals(400, child.getHeight(), 1e-100);
788 assertEquals(10, child.getLayoutX(), 1e-100);
789 assertEquals(10, child.getLayoutY(), 1e-100);
790 }
791
792 @Test public void testLayoutInAreaHonorsAreaHeightOverPrefWithFillHeight() {
793 Pane pane = new Pane(); // Region extension which makes children sequence public
794
795 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
796 pane.getChildren().add(child);
797
798 pane.layoutInArea(child, 10, 10, 300, 100, 0, Insets.EMPTY, true, true, HPos.CENTER, VPos.CENTER);
799
800 assertEquals(300, child.getWidth(), 1e-100);
801 assertEquals(100, child.getHeight(), 1e-100);
802 assertEquals(10, child.getLayoutX(), 1e-100);
803 assertEquals(10, child.getLayoutY(), 1e-100);
804 }
805
806 @Test public void testLayoutInAreaHonorsAreaWidthOverPrefWithNOFill() {
807 Pane pane = new Pane(); // Region extension which makes children sequence public
808
809 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
810 pane.getChildren().add(child);
811
812 pane.layoutInArea(child, 10, 10, 100, 400, 0, Insets.EMPTY, false, false, HPos.CENTER, VPos.CENTER);
813
814 assertEquals(100, child.getWidth(), 1e-100);
815 assertEquals(300, child.getHeight(), 1e-100);
816 assertEquals(10, child.getLayoutX(), 1e-100);
817 assertEquals(60, child.getLayoutY(), 1e-100);
818 }
819
820 @Test public void testLayoutInAreaHonorsAreaHeightOverPrefWithNOFill() {
821 Pane pane = new Pane(); // Region extension which makes children sequence public
822
823 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
824 pane.getChildren().add(child);
825
826 pane.layoutInArea(child, 10, 10, 300, 100, 0, Insets.EMPTY, false, false, HPos.CENTER, VPos.CENTER);
827
828 assertEquals(200, child.getWidth(), 1e-100);
829 assertEquals(100, child.getHeight(), 1e-100);
830 assertEquals(60, child.getLayoutX(), 1e-100);
831 assertEquals(10, child.getLayoutY(), 1e-100);
832 }
833
834 @Test public void testLayoutInAreaWithBaselineOffset() {
835 Pane pane = new Pane(); // Region extension which makes children sequence public
836
837 Region c1 = new MockBiased(Orientation.HORIZONTAL, 100, 100);
838 Region c2 = new MockBiased(Orientation.VERTICAL, 100, 100);
839 Region c3 = new MockRegion(10, 10, 100, 100, 1000, 1000);
840
841 pane.getChildren().addAll(c1, c2, c3);
842 pane.layoutInArea(c1, 10, 10, 300, 100, 20, Insets.EMPTY, false, false, HPos.CENTER, VPos.BASELINE);
843 pane.layoutInArea(c2, 10, 10, 300, 100, 20, Insets.EMPTY, false, false, HPos.CENTER, VPos.BASELINE);
844 pane.layoutInArea(c3, 10, 10, 300, 100, 20, Insets.EMPTY, false, false, HPos.CENTER, VPos.BASELINE);
845
846 assertEquals(100, c1.getHeight(), 1e-100); // min height == pref height
847 // As the other 2 Regions don't have a baseline offset, their baseline offset is "same as height", therefore
848 // they can be max 20px tall
849 assertEquals(20, c2.getHeight(), 1e-100);
850 assertEquals(20, c3.getHeight(), 1e-100);
851 }
852
853 @Test public void testComputeChildPrefAreaWidthHonorsMaxWidthOverPref() {
854 Pane pane = new Pane(); // Region extension which makes children sequence public
855
856 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
857 child.setMaxWidth(100); // max less than pref
858 pane.getChildren().add(child);
859
860 assertEquals(100, pane.computeChildPrefAreaWidth(child, Insets.EMPTY), 1e-100);
861 }
862
863 @Test public void testComputeChildPrefAreaHeightHonorsMaxWidthOverPref() {
864 Pane pane = new Pane(); // Region extension which makes children sequence public
865
866 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
867 child.setMaxHeight(100); // max less than pref
868 pane.getChildren().add(child);
869
870 assertEquals(100, pane.computeChildPrefAreaHeight(child, Insets.EMPTY), 1e-100);
871 }
872
873 @Test public void testComputeChildPrefAreaWidthHonorsMinWidthOverPref() {
874 Pane pane = new Pane(); // Region extension which makes children sequence public
875
876 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
877 child.setMinWidth(400); // max less than pref
878 pane.getChildren().add(child);
879
880 assertEquals(400, pane.computeChildPrefAreaWidth(child, Insets.EMPTY), 1e-100);
881 }
882
883 @Test public void testComputeChildPrefAreaHeightHonorsMinWidthOverPref() {
884 Pane pane = new Pane(); // Region extension which makes children sequence public
885
886 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
887 child.setMinHeight(400); // max less than pref
888 pane.getChildren().add(child);
889
890 assertEquals(400, pane.computeChildPrefAreaHeight(child, Insets.EMPTY), 1e-100);
891 }
892
893 @Test public void testComputeChildPrefAreaWidthHonorsMinWidthOverMax() {
894 Pane pane = new Pane(); // Region extension which makes children sequence public
895
896 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
897 child.setMinWidth(600); // max less than pref
898 pane.getChildren().add(child);
899
900 assertEquals(600, pane.computeChildPrefAreaWidth(child, Insets.EMPTY), 1e-100);
901 }
902
903 @Test public void testComputeChildPrefAreaHeightHonorsMinWidthOverMax() {
904 Pane pane = new Pane(); // Region extension which makes children sequence public
905
906 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
907 child.setMinHeight(600); // max less than pref
908 pane.getChildren().add(child);
909
910 assertEquals(600, pane.computeChildPrefAreaHeight(child, Insets.EMPTY), 1e-100);
911 }
912
913 @Test public void testChildMinAreaWidth() {
914 Pane pane = new Pane();
915
916 Region c1 = new MockBiased(Orientation.HORIZONTAL, 100, 100);
917 Region c2 = new MockBiased(Orientation.VERTICAL, 100, 100);
918 Region c3 = new MockRegion(10, 10, 100, 100, 1000, 1000);
919
920 pane.getChildren().addAll(c1, c2, c3);
921
922 assertEquals(12, pane.computeChildMinAreaWidth(c1, new Insets(1)), 1e-100);
923 assertEquals(12, pane.computeChildMinAreaWidth(c1, 0, new Insets(1), 50, false), 1e-100);
924 assertEquals(102, pane.computeChildMinAreaWidth(c2, new Insets(1)), 1e-100);
925 assertEquals(2 + Math.ceil(100*100/48.0), pane.computeChildMinAreaWidth(c2, -1, new Insets(1), 50, false), 1e-100); // vertically biased, effective height is 49
926 assertEquals(2 + Math.ceil(100*100/38.0), pane.computeChildMinAreaWidth(c2, 10, new Insets(1), 50, false), 1e-100); // vertically biased, effective height is 49
927 assertEquals(12, pane.computeChildMinAreaWidth(c3, new Insets(1)), 1e-100);
928 assertEquals(12, pane.computeChildMinAreaWidth(c3, 0, new Insets(1), 50, false), 1e-100);
929
930 }
931
932 @Test public void testChildMinAreaHeight() {
933 Pane pane = new Pane();
934
935 Region c1 = new MockBiased(Orientation.HORIZONTAL, 100, 100);
936 Region c2 = new MockBiased(Orientation.VERTICAL, 100, 100);
937 Region c3 = new MockRegion(10, 10, 100, 100, 1000, 1000);
938
939 pane.getChildren().addAll(c1, c2, c3);
940
941 assertEquals(3, pane.computeChildMinAreaHeight(c1, -1, new Insets(1), -1), 1e-100); /*Insets + minimal for biased is 1 */
942 assertEquals(2 + Math.ceil(100*100/48.0), pane.computeChildMinAreaHeight(c1, -1, new Insets(1), 50), 1e-100);
943 assertEquals(12 + Math.ceil(100*100/48.0), pane.computeChildMinAreaHeight(c1, 10, new Insets(1), 50), 1e-100);
944 assertEquals(12, pane.computeChildMinAreaHeight(c2, -1, new Insets(1), -1), 1e-100);
945 assertEquals(12, pane.computeChildMinAreaHeight(c2, -1, new Insets(1), 50), 1e-100);
946 assertEquals(12, pane.computeChildMinAreaHeight(c3, -1, new Insets(1), -1), 1e-100);
947 assertEquals(12, pane.computeChildMinAreaHeight(c3, -1, new Insets(1), 50), 1e-100);
948 }
949
950 @Test public void testChildMaxAreaWidth() {
951 Pane pane = new Pane();
952
953 Region c1 = new MockBiased(Orientation.HORIZONTAL, 100, 100);
954 Region c2 = new MockBiased(Orientation.VERTICAL, 100, 100);
955 Region c3 = new MockRegion(10, 10, 100, 100, 1000, 1000);
956
957 pane.getChildren().addAll(c1, c2, c3);
958
959 assertEquals(10002, pane.computeChildMaxAreaWidth(c1, -1, new Insets(1), -1, false), 1e-100);
960 assertEquals(10002, pane.computeChildMaxAreaWidth(c1, -1, new Insets(1), 50, false), 1e-100);
961 assertEquals(102, pane.computeChildMaxAreaWidth(c2, -1, new Insets(1), -1, false), 1e-100); // Vertival bias is not applied when no height/baseline offset is set
962 assertEquals(2 + Math.ceil(100*100/48.0), pane.computeChildMaxAreaWidth(c2, -1, new Insets(1), 50, false), 1e-100);
963 assertEquals(2 + Math.ceil(100*100/38.0), pane.computeChildMaxAreaWidth(c2, 10, new Insets(1), 50, false), 1e-100);
964 assertEquals(1002, pane.computeChildMaxAreaWidth(c3, -1, new Insets(1), -1, false), 1e-100);
965 assertEquals(1002, pane.computeChildMaxAreaWidth(c3, -1, new Insets(1), 50, false), 1e-100);
966 }
967
968 @Test public void testChildMaxAreaHeight() {
969 Pane pane = new Pane();
970
971 Region c1 = new MockBiased(Orientation.HORIZONTAL, 100, 100);
972 Region c2 = new MockBiased(Orientation.VERTICAL, 100, 100);
973 Region c3 = new MockRegion(10, 10, 100, 100, 1000, 1000);
974
975 pane.getChildren().addAll(c1, c2, c3);
976
977 assertEquals(1002, pane.computeChildMaxAreaHeight(c1, -1, new Insets(1), -1), 1e-100);
978 assertEquals(2 + Math.ceil(100*100/48.0), pane.computeChildMaxAreaHeight(c1, -1, new Insets(1), 50), 1e-100);
979 assertEquals(12 + Math.ceil(100*100/48.0), pane.computeChildMaxAreaHeight(c1, 10, new Insets(1), 50), 1e-100);
980 assertEquals(10002, pane.computeChildMaxAreaHeight(c2, -1, new Insets(1), -1), 1e-100);
981 assertEquals(10002, pane.computeChildMaxAreaHeight(c2, -1, new Insets(1), 50), 1e-100);
982 assertEquals(1002, pane.computeChildMaxAreaHeight(c3, -1, new Insets(1), -1), 1e-100);
983 assertEquals(1002, pane.computeChildMaxAreaHeight(c3, -1, new Insets(1), 50), 1e-100);
984 }
985
986 /**************************************************************************
987 * *
988 * Test that images which are background loaded, or images which can *
989 * change (such as WritableImage or animated gif) will cause a *
990 * listener to be installed. Also that a non-animating background *
991 * loaded image will have the listener removed when the image *
992 * finishes loading, and that all listeners are removed from images *
993 * which have been removed from the Region. Also that any animating *
994 * or background loaded image will cause a repaint to happen when the *
995 * underlying platform image changes. *
996 * *
997 *************************************************************************/
998
999 @Test public void testBackgroundLoadedBackgroundImageHasListenerInstalled() {
1000 final ImageForTesting image = new ImageForTesting("http://something.png", true);
1001 assertTrue(image.getProgress() < 1);
1002
1003 ImageRegion r = new ImageRegion();
1148 ImageRegion r = new ImageRegion();
1149 final Border border = new Border(new BorderImage(image, null, null, null, false, null, null));
1150 r.setBorder(border);
1151 r.clearDirty();
1152 assertFalse(r.willBeRepainted());
1153 image.getPixelWriter().setArgb(0, 0, 100);
1154 assertTrue(r.willBeRepainted());
1155 }
1156
1157 @Test public void testBorderChangeUpdatesTheInsets() {
1158 Region r = new Region();
1159
1160 r.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, BorderWidths.DEFAULT, new Insets(10))));
1161 assertEquals(new Insets(11), r.getInsets());
1162
1163 r.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, null, new Insets(20))));
1164
1165 assertEquals(new Insets(21), r.getInsets());
1166 }
1167
1168 static final class ImageRegion extends Region {
1169 AtomicBoolean listenerAdded = new AtomicBoolean(false);
1170
1171 @Override void addImageListener(Image image) {
1172 super.addImageListener(image);
1173 listenerAdded.set(true);
1174 }
1175
1176 @Override void removeImageListener(Image image) {
1177 super.removeImageListener(image);
1178 listenerAdded.set(false);
1179 }
1180
1181 public boolean willBeRepainted() {
1182 return impl_isDirty(DirtyBits.NODE_CONTENTS);
1183 }
1184
1185 public void clearDirty() {
1186 super.impl_clearDirty(DirtyBits.NODE_CONTENTS);
1187 }
1188 };
1189
1190 // Test for RT-13820
1191 @Test public void changingShapeElementsShouldResultInRender() {
1192 Region r = new Region();
1193 r.setPrefWidth(640);
1194 r.setPrefHeight(480);
1195 LineTo lineTo;
1196 Path p = new Path(
1197 new MoveTo(0, 0),
1198 lineTo = new LineTo(100, 0),
1199 new LineTo(50, 100),
1200 new ClosePath()
1201 );
1202 r.setBackground(new Background(new BackgroundFill(Color.BLUE, null, null)));
1203 r.setCenterShape(true);
1204 r.setScaleShape(true);
1205 r.setShape(p);
1206 r.impl_syncPeer();
|
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 test.javafx.scene.layout.MockBiased;
29 import test.javafx.scene.layout.MockRegion;
30 import javafx.geometry.HPos;
31 import javafx.geometry.Insets;
32 import javafx.geometry.Orientation;
33 import javafx.geometry.VPos;
34 import javafx.scene.image.Image;
35 import test.javafx.scene.image.ImageForTesting;
36 import javafx.scene.image.WritableImage;
37 import javafx.scene.paint.Color;
38 import javafx.scene.shape.ClosePath;
39 import javafx.scene.shape.LineTo;
40 import javafx.scene.shape.MoveTo;
41 import javafx.scene.shape.Path;
42 import java.util.concurrent.atomic.AtomicBoolean;
43 import com.sun.javafx.scene.DirtyBits;
44 import com.sun.javafx.sg.prism.NGRegion;
45 import javafx.scene.NodeShim;
46 import javafx.scene.layout.Background;
47 import javafx.scene.layout.BackgroundFill;
48 import javafx.scene.layout.BackgroundImage;
49 import javafx.scene.layout.Border;
50 import javafx.scene.layout.BorderImage;
51 import javafx.scene.layout.BorderStroke;
52 import javafx.scene.layout.BorderStrokeStyle;
53 import javafx.scene.layout.BorderWidths;
54 import javafx.scene.layout.Pane;
55 import javafx.scene.layout.Region;
56 import javafx.scene.layout.RegionShim;
57 import org.junit.Test;
58 import static org.junit.Assert.assertEquals;
59 import static org.junit.Assert.assertFalse;
60 import static org.junit.Assert.assertTrue;
61 import static org.junit.Assert.fail;
62
63 /**
64 *
65 */
66 public class RegionTest {
67
68 @Test public void testPaddingEmptyByDefault() {
69 Region region = new Region();
70
71 assertEquals(Insets.EMPTY, region.getPadding());
72 }
73
74 @Test public void testPaddingCannotBeSetToNull() {
75 Region region = new Region();
76
79 fail("NullPointerException expected if padding set to null.");
80 } catch (Exception e) {
81 // expected
82 }
83
84 try {
85 region.paddingProperty().set(null);
86 fail("NullPointerException expected if padding set to null.");
87 } catch (Exception e) {
88 // expected
89 }
90 }
91
92 @Test public void testInsetsEqualsPaddingByDefault() {
93 Region region = new Region();
94
95 assertEquals(region.getInsets(), region.getPadding());
96 }
97
98 @Test public void testBoundedSizeReturnsPrefWhenPrefBetweenMinAndMax() {
99 assertEquals(200, RegionShim.boundedSize(100, 200, 300), 0);
100 }
101
102 @Test public void testBoundedSizeReturnsMinWhenMinGreaterThanPrefButLessThanMax() {
103 assertEquals(200, RegionShim.boundedSize(200, 100, 300), 0);
104 }
105
106 @Test public void testBoundedSizeReturnsMinWhenMinGreaterThanPrefAndMax() {
107 assertEquals(300, RegionShim.boundedSize(300, 100, 200), 0);
108 }
109
110 @Test public void testBoundedSizeReturnsMaxWhenMaxLessThanPrefButGreaterThanMin() {
111 assertEquals(200, RegionShim.boundedSize(100, 300, 200), 0);
112 }
113
114 @Test public void testBoundedSizeReturnsMinWhenMaxLessThanPrefAndMin() {
115 assertEquals(200, RegionShim.boundedSize(200, 300, 100), 0);
116 }
117
118 @Test public void testBoundedSizeReturnsMinWhenMaxLessThanPrefAndMinAndPrefLessThanMin() {
119 assertEquals(300, RegionShim.boundedSize(300, 200, 100), 0);
120 }
121
122 @Test public void testMinWidthOverride() {
123 Region region = new MockRegion(10,20, 100,200, 500,600);
124 assertEquals(10, region.minWidth(-1), 1e-100);
125 region.setMinWidth(25.0);
126 assertEquals(25, region.getMinWidth(), 1e-100);
127 assertEquals(25, region.minWidth(-1), 1e-100);
128 }
129
130 @Test public void testMinWidthOverrideThenRestoreComputedSize() {
131 Region region = new MockRegion(10,20, 100,200, 500,600);
132 region.setMinWidth(75.0);
133 region.setMinWidth(Region.USE_COMPUTED_SIZE); // reset
134 assertEquals(Region.USE_COMPUTED_SIZE, region.getMinWidth(), 1e-100);
135 assertEquals(10, region.minWidth(-1), 1e-100);
136 }
137
138 @Test public void testMinWidthNaNTreatedAsZero() {
139 Region region = new Region();
321 region.setMaxWidth(Region.USE_PREF_SIZE);
322 assertEquals(Region.USE_PREF_SIZE, region.getMaxWidth(), 0);
323 assertEquals(100, region.maxWidth(-1), 1e-100);
324 }
325
326 @Test public void testMaxHeightOverrideSetToPref() {
327 Region region = new MockRegion(10,20, 100,200, 500,600);
328 assertEquals(600, region.maxHeight(-1), 1e-100);
329 region.setMaxHeight(Region.USE_PREF_SIZE);
330 assertEquals(Region.USE_PREF_SIZE, region.getMaxHeight(), 0);
331 assertEquals(200, region.maxHeight(-1), 1e-100);
332 }
333
334 @Test public void testPositionInAreaForResizableForResizableTopLeft() {
335 Pane pane = new Pane(); // Region extension which makes children sequence public
336
337 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
338 pane.getChildren().add(child);
339
340 child.autosize();
341 RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 0, HPos.LEFT, VPos.TOP);
342
343 assertEquals(30, child.getWidth(), 1e-100);
344 assertEquals(40, child.getHeight(), 1e-100);
345 assertEquals(10, child.getLayoutX(), 1e-100);
346 assertEquals(10, child.getLayoutY(), 1e-100);
347 }
348
349 @Test public void testPositionInAreaForResizableTopCenter() {
350 Pane pane = new Pane(); // Region extension which makes children sequence public
351
352 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
353 pane.getChildren().add(child);
354
355 child.autosize();
356 RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 0, HPos.CENTER, VPos.TOP);
357
358 assertEquals(30, child.getWidth(), 1e-100);
359 assertEquals(40, child.getHeight(), 1e-100);
360 assertEquals(45, child.getLayoutX(), 1e-100);
361 assertEquals(10, child.getLayoutY(), 1e-100);
362 }
363
364 @Test public void testPositionInAreaForResizableTopRight() {
365 Pane pane = new Pane(); // Region extension which makes children sequence public
366
367 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
368 pane.getChildren().add(child);
369
370 child.autosize();
371 RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 0, HPos.RIGHT, VPos.TOP);
372
373 assertEquals(30, child.getWidth(), 1e-100);
374 assertEquals(40, child.getHeight(), 1e-100);
375 assertEquals(80, child.getLayoutX(), 1e-100);
376 assertEquals(10, child.getLayoutY(), 1e-100);
377 }
378
379 @Test public void testPositionInAreaForResizableCenterLeft() {
380 Pane pane = new Pane(); // Region extension which makes children sequence public
381
382 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
383 pane.getChildren().add(child);
384
385 child.autosize();
386 RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 0, HPos.LEFT, VPos.CENTER);
387
388 assertEquals(30, child.getWidth(), 1e-100);
389 assertEquals(40, child.getHeight(), 1e-100);
390 assertEquals(10, child.getLayoutX(), 1e-100);
391 assertEquals(40, child.getLayoutY(), 1e-100);
392 }
393
394 // // See RT-19282
395 // @Test public void testPositionInAreaForNONResizableCenterLeft() {
396 // Pane pane = new Pane(); // Region extension which makes children sequence public
397 //
398 // Rectangle child = new Rectangle(50.4, 50.4);
399 // pane.getChildren().add(child);
400 //
401 // RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 0, HPos.LEFT, VPos.CENTER);
402 //
403 // assertEquals(10, child.getLayoutX(), .01);
404 // assertEquals(34.8, child.getLayoutY(), .01);
405 // }
406
407
408 @Test public void testPositionInAreaForResizableCenter() {
409 Pane pane = new Pane(); // Region extension which makes children sequence public
410
411 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
412 pane.getChildren().add(child);
413
414 child.autosize();
415 RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 0, HPos.CENTER, VPos.CENTER);
416
417 assertEquals(30, child.getWidth(), 1e-100);
418 assertEquals(40, child.getHeight(), 1e-100);
419 assertEquals(45, child.getLayoutX(), 1e-100);
420 assertEquals(40, child.getLayoutY(), 1e-100);
421 }
422
423 // // See RT-19282
424 // @Test public void testPositionInAreaForNONResizableCenter() {
425 // Pane pane = new Pane(); // Region extension which makes children sequence public
426 //
427 // Rectangle child = new Rectangle(50.4, 50.4);
428 // pane.getChildren().add(child);
429 //
430 // RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 0, HPos.CENTER, VPos.CENTER);
431 //
432 // assertEquals(34.8, child.getLayoutX(), .01);
433 // assertEquals(34.8, child.getLayoutY(), .01);
434 // }
435
436 @Test public void testPositionInAreaForResizableCenterRight() {
437 Pane pane = new Pane(); // Region extension which makes children sequence public
438
439 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
440 pane.getChildren().add(child);
441
442 child.autosize();
443 RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 0, HPos.RIGHT, VPos.CENTER);
444
445 assertEquals(30, child.getWidth(), 1e-100);
446 assertEquals(40, child.getHeight(), 1e-100);
447 assertEquals(80, child.getLayoutX(), 1e-100);
448 assertEquals(40, child.getLayoutY(), 1e-100);
449 }
450
451 @Test public void testPositionInAreaForResizableBottomLeft() {
452 Pane pane = new Pane(); // Region extension which makes children sequence public
453
454 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
455 pane.getChildren().add(child);
456
457 child.autosize();
458 RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 0, HPos.LEFT, VPos.BOTTOM);
459
460 assertEquals(30, child.getWidth(), 1e-100);
461 assertEquals(40, child.getHeight(), 1e-100);
462 assertEquals(10, child.getLayoutX(), 1e-100);
463 assertEquals(70, child.getLayoutY(), 1e-100);
464 }
465
466 // // See RT-19282
467 // @Test public void testPositionInAreaForNONResizableBottomLeft() {
468 // Pane pane = new Pane(); // Region extension which makes children sequence public
469 //
470 // Rectangle child = new Rectangle(50.4, 50.4);
471 // pane.getChildren().add(child);
472 //
473 // RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 0, HPos.LEFT, VPos.BOTTOM);
474 //
475 // assertEquals(10, child.getLayoutX(), .01);
476 // assertEquals(59.6, child.getLayoutY(), .01);
477 // }
478
479 @Test public void testPositionInAreaForResizableBottomCenter() {
480 Pane pane = new Pane(); // Region extension which makes children sequence public
481
482 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
483 pane.getChildren().add(child);
484
485 child.autosize();
486 RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 0, HPos.CENTER, VPos.BOTTOM);
487
488 assertEquals(30, child.getWidth(), 1e-100);
489 assertEquals(40, child.getHeight(), 1e-100);
490 assertEquals(45, child.getLayoutX(), 1e-100);
491 assertEquals(70, child.getLayoutY(), 1e-100);
492 }
493
494 // // See RT-19282
495 // @Test public void testPositionInAreaForNONResizableBottomCenter() {
496 // Pane pane = new Pane(); // Region extension which makes children sequence public
497 //
498 // Rectangle child = new Rectangle(50.4, 50.4);
499 // pane.getChildren().add(child);
500 //
501 // RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 0, HPos.CENTER, VPos.BOTTOM);
502 //
503 // assertEquals(34.8, child.getLayoutX(), .01);
504 // assertEquals(59.6, child.getLayoutY(), .01);
505 // }
506
507 @Test public void testPositionInAreaForResizableBottomRight() {
508 Pane pane = new Pane(); // Region extension which makes children sequence public
509
510 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
511 pane.getChildren().add(child);
512
513 child.autosize();
514 RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 0, HPos.RIGHT, VPos.BOTTOM);
515
516 assertEquals(30, child.getWidth(), 1e-100);
517 assertEquals(40, child.getHeight(), 1e-100);
518 assertEquals(80, child.getLayoutX(), 1e-100);
519 assertEquals(70, child.getLayoutY(), 1e-100);
520 }
521
522 // // See RT-19282
523 // @Test public void testPositionInAreaForNONResizableBottomRight() {
524 // Pane pane = new Pane(); // Region extension which makes children sequence public
525 //
526 // Rectangle child = new Rectangle(50.4, 50.4);
527 // pane.getChildren().add(child);
528 //
529 // RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 0, HPos.RIGHT, VPos.BOTTOM);
530 //
531 // assertEquals(59.6, child.getLayoutX(), .01);
532 // assertEquals(59.6, child.getLayoutY(), .01);
533 // }
534
535 @Test public void testPositionInAreaForResizableBaselineLeft() {
536 Pane pane = new Pane(); // Region extension which makes children sequence public
537
538 MockResizable child = new MockResizable(10,20, 30,40, 50,60); //baseline = 30
539 pane.getChildren().add(child);
540
541 child.autosize();
542 RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 50, HPos.LEFT, VPos.BASELINE);
543
544 assertEquals(30, child.getWidth(), 1e-100);
545 assertEquals(40, child.getHeight(), 1e-100);
546 assertEquals(10, child.getLayoutX(), 1e-100);
547 assertEquals(30, child.getLayoutY(), 1e-100);
548 }
549
550 // // See RT-19282
551 // @Test public void testPositionInAreaForNONResizableBaselineLeft() {
552 // Pane pane = new Pane(); // Region extension which makes children sequence public
553 //
554 // Rectangle child = new Rectangle(50.4, 50.4);
555 // pane.getChildren().add(child);
556 //
557 // RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 60, HPos.LEFT, VPos.BASELINE);
558 //
559 // assertEquals(10, child.getLayoutX(), .01);
560 // assertEquals(19.6, child.getLayoutY(), .01);
561 // }
562
563 @Test public void testPositionInAreaForResizableBaselineCenter() {
564 Pane pane = new Pane(); // Region extension which makes children sequence public
565
566 MockResizable child = new MockResizable(10,20, 30,40, 50,60); //baseline = 30
567 pane.getChildren().add(child);
568
569 child.autosize();
570 RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 50, HPos.CENTER, VPos.BASELINE);
571
572 assertEquals(30, child.getWidth(), 1e-100);
573 assertEquals(40, child.getHeight(), 1e-100);
574 assertEquals(45, child.getLayoutX(), 1e-100);
575 assertEquals(30, child.getLayoutY(), 1e-100);
576 }
577
578 // // See RT-19282
579 // @Test public void testPositionInAreaForNONResizableBaselineCenter() {
580 // Pane pane = new Pane(); // Region extension which makes children sequence public
581 //
582 // Rectangle child = new Rectangle(50.4, 50.4);
583 // pane.getChildren().add(child);
584 //
585 // RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 60, HPos.CENTER, VPos.BASELINE);
586 //
587 // assertEquals(34.8, child.getLayoutX(), .01);
588 // assertEquals(19.6, child.getLayoutY(), .01);
589 // }
590
591 @Test public void testPositionInAreaForResizableBaselineRight() {
592 Pane pane = new Pane(); // Region extension which makes children sequence public
593
594 MockResizable child = new MockResizable(10,20, 30,40, 50,60); //baseline = 30
595 pane.getChildren().add(child);
596
597 child.autosize();
598 RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 50, HPos.RIGHT, VPos.BASELINE);
599
600 assertEquals(30, child.getWidth(), 1e-100);
601 assertEquals(40, child.getHeight(), 1e-100);
602 assertEquals(80, child.getLayoutX(), 1e-100);
603 assertEquals(30, child.getLayoutY(), 1e-100);
604 }
605
606 // // See RT-19282
607 // @Test public void testPositionInAreaForNONResizableBaselineRight() {
608 // Pane pane = new Pane(); // Region extension which makes children sequence public
609 //
610 // Rectangle child = new Rectangle(50.4, 50.4);
611 // pane.getChildren().add(child);
612 //
613 // RegionShim.positionInArea(pane,child, 10, 10, 100, 100, 60, HPos.RIGHT, VPos.BASELINE);
614 //
615 // assertEquals(59.6, child.getLayoutX(), .01);
616 // assertEquals(19.6, child.getLayoutY(), .01);
617 // }
618
619 @Test public void testLayoutInAreaWithLargerMax() {
620 Pane pane = new Pane(); // Region extension which makes children sequence public
621
622 MockResizable child = new MockResizable(10,20, 30,40, 300,300);
623 pane.getChildren().add(child);
624
625 RegionShim.layoutInArea(pane, child, 10, 10, 100, 100, 0, HPos.CENTER, VPos.CENTER);
626
627 assertEquals(100, child.getWidth(), 1e-100);
628 assertEquals(100, child.getHeight(), 1e-100);
629 assertEquals(10, child.getLayoutX(), 1e-100);
630 assertEquals(10, child.getLayoutY(), 1e-100);
631
632 }
633
634 @Test public void testLayoutInAreaWithSmallerMax() {
635 Pane pane = new Pane(); // Region extension which makes children sequence public
636
637 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
638 pane.getChildren().add(child);
639
640 RegionShim.layoutInArea(pane, child, 10, 10, 100, 100, 0, HPos.CENTER, VPos.CENTER);
641
642 assertEquals(50, child.getWidth(), 1e-100);
643 assertEquals(60, child.getHeight(), 1e-100);
644 assertEquals(35, child.getLayoutX(), 1e-100);
645 assertEquals(30, child.getLayoutY(), 1e-100);
646
647 }
648
649 @Test public void testLayoutInAreaWithLargerMin() {
650 Pane pane = new Pane(); // Region extension which makes children sequence public
651
652 MockResizable child = new MockResizable(10,20, 30,40, 50,60);
653 pane.getChildren().add(child);
654
655 RegionShim.layoutInArea(pane, child, 10, 10, 5, 5, 0, HPos.CENTER, VPos.CENTER);
656
657 assertEquals(10, child.getWidth(), 1e-100);
658 assertEquals(20, child.getHeight(), 1e-100);
659 assertEquals(8, child.getLayoutX(), 1e-100);
660 assertEquals(3, child.getLayoutY(), 1e-100);
661
662 }
663
664 @Test public void testLayoutInAreaWithSizeOverrides() {
665 Pane pane = new Pane(); // Region extension which makes children sequence public
666
667 MockRegion child = new MockRegion(10,20, 30,40, 50,60);
668 child.setMinSize(50,60);
669 child.setPrefSize(100,200);
670 child.setMaxSize(500, 500);
671 pane.getChildren().add(child);
672
673 RegionShim.layoutInArea(pane, child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);
674
675 assertEquals(300, child.getWidth(), 1e-100);
676 assertEquals(300, child.getHeight(), 1e-100);
677 assertEquals(10, child.getLayoutX(), 1e-100);
678 assertEquals(10, child.getLayoutY(), 1e-100);
679
680 }
681
682 @Test public void testLayoutInAreaWithMaxConstrainedToPref() {
683 Pane pane = new Pane(); // Region extension which makes children sequence public
684
685 MockRegion child = new MockRegion(10,20, 30,40, 500,500);
686 child.setMinSize(50,60);
687 child.setPrefSize(100,200);
688 child.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
689 pane.getChildren().add(child);
690
691 RegionShim.layoutInArea(pane, child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);
692
693 assertEquals(100, child.getWidth(), 1e-100);
694 assertEquals(200, child.getHeight(), 1e-100);
695 assertEquals(110, child.getLayoutX(), 1e-100);
696 assertEquals(60, child.getLayoutY(), 1e-100);
697
698 }
699
700 @Test public void testLayoutInAreaHonorsMaxWidthOverPref() {
701 Pane pane = new Pane(); // Region extension which makes children sequence public
702
703 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
704 child.setMaxWidth(100); // max less than pref
705 pane.getChildren().add(child);
706
707 RegionShim.layoutInArea(pane, child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);
708
709 assertEquals(100, child.getWidth(), 1e-100);
710 assertEquals(300, child.getHeight(), 1e-100);
711 assertEquals(110, child.getLayoutX(), 1e-100);
712 assertEquals(10, child.getLayoutY(), 1e-100);
713
714 }
715
716 @Test public void testLayoutInAreaHonorsMaxHeightOverPref() {
717 Pane pane = new Pane(); // Region extension which makes children sequence public
718
719 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
720 child.setMaxHeight(100); // max less than pref
721 pane.getChildren().add(child);
722
723 RegionShim.layoutInArea(pane, child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);
724
725 assertEquals(300, child.getWidth(), 1e-100);
726 assertEquals(100, child.getHeight(), 1e-100);
727 assertEquals(10, child.getLayoutX(), 1e-100);
728 assertEquals(110, child.getLayoutY(), 1e-100);
729
730 }
731
732 @Test public void testLayoutInAreaHonorsMinWidthOverPref() {
733 Pane pane = new Pane(); // Region extension which makes children sequence public
734
735 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
736 child.setMinWidth(400); // max less than pref
737 pane.getChildren().add(child);
738
739 RegionShim.layoutInArea(pane, child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);
740
741 assertEquals(400, child.getWidth(), 1e-100);
742 assertEquals(300, child.getHeight(), 1e-100);
743 assertEquals(-40, child.getLayoutX(), 1e-100);
744 assertEquals(10, child.getLayoutY(), 1e-100);
745 }
746
747 @Test public void testLayoutInAreaHonorsMinHeightOverPref() {
748 Pane pane = new Pane(); // Region extension which makes children sequence public
749
750 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
751 child.setMinHeight(400); // max less than pref
752 pane.getChildren().add(child);
753
754 RegionShim.layoutInArea(pane, child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);
755
756 assertEquals(300, child.getWidth(), 1e-100);
757 assertEquals(400, child.getHeight(), 1e-100);
758 assertEquals(10, child.getLayoutX(), 1e-100);
759 assertEquals(-40, child.getLayoutY(), 1e-100);
760 }
761
762 @Test public void testLayoutInAreaHonorsMinWidthOverMax() {
763 Pane pane = new Pane(); // Region extension which makes children sequence public
764
765 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
766 child.setMinWidth(600); // max less than min
767 pane.getChildren().add(child);
768
769 RegionShim.layoutInArea(pane, child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);
770
771 assertEquals(600, child.getWidth(), 1e-100);
772 assertEquals(300, child.getHeight(), 1e-100);
773 assertEquals(-140, child.getLayoutX(), 1e-100);
774 assertEquals(10, child.getLayoutY(), 1e-100);
775 }
776
777 @Test public void testLayoutInAreaHonorsMinHeightOverMax() {
778 Pane pane = new Pane(); // Region extension which makes children sequence public
779
780 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
781 child.setMinHeight(600); // max less than min
782 pane.getChildren().add(child);
783
784 RegionShim.layoutInArea(pane, child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);
785
786 assertEquals(300, child.getWidth(), 1e-100);
787 assertEquals(600, child.getHeight(), 1e-100);
788 assertEquals(10, child.getLayoutX(), 1e-100);
789 assertEquals(-140, child.getLayoutY(), 1e-100);
790 }
791
792 @Test public void testLayoutInAreaHonorsAreaWidthOverPrefWithFillWidth() {
793 Pane pane = new Pane(); // Region extension which makes children sequence public
794
795 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
796 pane.getChildren().add(child);
797
798 RegionShim.layoutInArea(pane, child, 10, 10, 100, 400, 0, Insets.EMPTY, true, true, HPos.CENTER, VPos.CENTER);
799
800 assertEquals(100, child.getWidth(), 1e-100);
801 assertEquals(400, child.getHeight(), 1e-100);
802 assertEquals(10, child.getLayoutX(), 1e-100);
803 assertEquals(10, child.getLayoutY(), 1e-100);
804 }
805
806 @Test public void testLayoutInAreaHonorsAreaHeightOverPrefWithFillHeight() {
807 Pane pane = new Pane(); // Region extension which makes children sequence public
808
809 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
810 pane.getChildren().add(child);
811
812 RegionShim.layoutInArea(pane, child, 10, 10, 300, 100, 0, Insets.EMPTY, true, true, HPos.CENTER, VPos.CENTER);
813
814 assertEquals(300, child.getWidth(), 1e-100);
815 assertEquals(100, child.getHeight(), 1e-100);
816 assertEquals(10, child.getLayoutX(), 1e-100);
817 assertEquals(10, child.getLayoutY(), 1e-100);
818 }
819
820 @Test public void testLayoutInAreaHonorsAreaWidthOverPrefWithNOFill() {
821 Pane pane = new Pane(); // Region extension which makes children sequence public
822
823 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
824 pane.getChildren().add(child);
825
826 RegionShim.layoutInArea(pane, child, 10, 10, 100, 400, 0, Insets.EMPTY, false, false, HPos.CENTER, VPos.CENTER);
827
828 assertEquals(100, child.getWidth(), 1e-100);
829 assertEquals(300, child.getHeight(), 1e-100);
830 assertEquals(10, child.getLayoutX(), 1e-100);
831 assertEquals(60, child.getLayoutY(), 1e-100);
832 }
833
834 @Test public void testLayoutInAreaHonorsAreaHeightOverPrefWithNOFill() {
835 Pane pane = new Pane(); // Region extension which makes children sequence public
836
837 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
838 pane.getChildren().add(child);
839
840 RegionShim.layoutInArea(pane, child, 10, 10, 300, 100, 0, Insets.EMPTY, false, false, HPos.CENTER, VPos.CENTER);
841
842 assertEquals(200, child.getWidth(), 1e-100);
843 assertEquals(100, child.getHeight(), 1e-100);
844 assertEquals(60, child.getLayoutX(), 1e-100);
845 assertEquals(10, child.getLayoutY(), 1e-100);
846 }
847
848 @Test public void testLayoutInAreaWithBaselineOffset() {
849 Pane pane = new Pane(); // Region extension which makes children sequence public
850
851 Region c1 = new MockBiased(Orientation.HORIZONTAL, 100, 100);
852 Region c2 = new MockBiased(Orientation.VERTICAL, 100, 100);
853 Region c3 = new MockRegion(10, 10, 100, 100, 1000, 1000);
854
855 pane.getChildren().addAll(c1, c2, c3);
856 RegionShim.layoutInArea(pane, c1, 10, 10, 300, 100, 20, Insets.EMPTY, false, false, HPos.CENTER, VPos.BASELINE);
857 RegionShim.layoutInArea(pane, c2, 10, 10, 300, 100, 20, Insets.EMPTY, false, false, HPos.CENTER, VPos.BASELINE);
858 RegionShim.layoutInArea(pane, c3, 10, 10, 300, 100, 20, Insets.EMPTY, false, false, HPos.CENTER, VPos.BASELINE);
859
860 assertEquals(100, c1.getHeight(), 1e-100); // min height == pref height
861 // As the other 2 Regions don't have a baseline offset, their baseline offset is "same as height", therefore
862 // they can be max 20px tall
863 assertEquals(20, c2.getHeight(), 1e-100);
864 assertEquals(20, c3.getHeight(), 1e-100);
865 }
866
867 @Test public void testComputeChildPrefAreaWidthHonorsMaxWidthOverPref() {
868 Pane pane = new Pane(); // Region extension which makes children sequence public
869
870 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
871 child.setMaxWidth(100); // max less than pref
872 pane.getChildren().add(child);
873
874 assertEquals(100, RegionShim.computeChildPrefAreaWidth(pane, child, Insets.EMPTY), 1e-100);
875 }
876
877 @Test public void testComputeChildPrefAreaHeightHonorsMaxWidthOverPref() {
878 Pane pane = new Pane(); // Region extension which makes children sequence public
879
880 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
881 child.setMaxHeight(100); // max less than pref
882 pane.getChildren().add(child);
883
884 assertEquals(100, RegionShim.computeChildPrefAreaHeight(pane, child, Insets.EMPTY), 1e-100);
885 }
886
887 @Test public void testComputeChildPrefAreaWidthHonorsMinWidthOverPref() {
888 Pane pane = new Pane(); // Region extension which makes children sequence public
889
890 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
891 child.setMinWidth(400); // max less than pref
892 pane.getChildren().add(child);
893
894 assertEquals(400, RegionShim.computeChildPrefAreaWidth(pane, child, Insets.EMPTY), 1e-100);
895 }
896
897 @Test public void testComputeChildPrefAreaHeightHonorsMinWidthOverPref() {
898 Pane pane = new Pane(); // Region extension which makes children sequence public
899
900 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
901 child.setMinHeight(400); // max less than pref
902 pane.getChildren().add(child);
903
904 assertEquals(400, RegionShim.computeChildPrefAreaHeight(pane, child, Insets.EMPTY), 1e-100);
905 }
906
907 @Test public void testComputeChildPrefAreaWidthHonorsMinWidthOverMax() {
908 Pane pane = new Pane(); // Region extension which makes children sequence public
909
910 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
911 child.setMinWidth(600); // max less than pref
912 pane.getChildren().add(child);
913
914 assertEquals(600, RegionShim.computeChildPrefAreaWidth(pane, child, Insets.EMPTY), 1e-100);
915 }
916
917 @Test public void testComputeChildPrefAreaHeightHonorsMinWidthOverMax() {
918 Pane pane = new Pane(); // Region extension which makes children sequence public
919
920 MockRegion child = new MockRegion(10,20, 200,300, 500,500);
921 child.setMinHeight(600); // max less than pref
922 pane.getChildren().add(child);
923
924 assertEquals(600, RegionShim.computeChildPrefAreaHeight(pane, child, Insets.EMPTY), 1e-100);
925 }
926
927 @Test public void testChildMinAreaWidth() {
928 Pane pane = new Pane();
929
930 Region c1 = new MockBiased(Orientation.HORIZONTAL, 100, 100);
931 Region c2 = new MockBiased(Orientation.VERTICAL, 100, 100);
932 Region c3 = new MockRegion(10, 10, 100, 100, 1000, 1000);
933
934 pane.getChildren().addAll(c1, c2, c3);
935
936 assertEquals(12, RegionShim.computeChildMinAreaWidth(pane, c1, new Insets(1)), 1e-100);
937 assertEquals(12, RegionShim.computeChildMinAreaWidth(pane, c1, 0, new Insets(1), 50, false), 1e-100);
938 assertEquals(102, RegionShim.computeChildMinAreaWidth(pane, c2, new Insets(1)), 1e-100);
939 assertEquals(2 + Math.ceil(100*100/48.0), RegionShim.computeChildMinAreaWidth(pane, c2, -1, new Insets(1), 50, false), 1e-100); // vertically biased, effective height is 49
940 assertEquals(2 + Math.ceil(100*100/38.0), RegionShim.computeChildMinAreaWidth(pane, c2, 10, new Insets(1), 50, false), 1e-100); // vertically biased, effective height is 49
941 assertEquals(12, RegionShim.computeChildMinAreaWidth(pane, c3, new Insets(1)), 1e-100);
942 assertEquals(12, RegionShim.computeChildMinAreaWidth(pane, c3, 0, new Insets(1), 50, false), 1e-100);
943
944 }
945
946 @Test public void testChildMinAreaHeight() {
947 Pane pane = new Pane();
948
949 Region c1 = new MockBiased(Orientation.HORIZONTAL, 100, 100);
950 Region c2 = new MockBiased(Orientation.VERTICAL, 100, 100);
951 Region c3 = new MockRegion(10, 10, 100, 100, 1000, 1000);
952
953 pane.getChildren().addAll(c1, c2, c3);
954
955 assertEquals(3, RegionShim.computeChildMinAreaHeight(pane, c1, -1, new Insets(1), -1), 1e-100); /*Insets + minimal for biased is 1 */
956 assertEquals(2 + Math.ceil(100*100/48.0), RegionShim.computeChildMinAreaHeight(pane, c1, -1, new Insets(1), 50), 1e-100);
957 assertEquals(12 + Math.ceil(100*100/48.0), RegionShim.computeChildMinAreaHeight(pane, c1, 10, new Insets(1), 50), 1e-100);
958 assertEquals(12, RegionShim.computeChildMinAreaHeight(pane, c2, -1, new Insets(1), -1), 1e-100);
959 assertEquals(12, RegionShim.computeChildMinAreaHeight(pane, c2, -1, new Insets(1), 50), 1e-100);
960 assertEquals(12, RegionShim.computeChildMinAreaHeight(pane, c3, -1, new Insets(1), -1), 1e-100);
961 assertEquals(12, RegionShim.computeChildMinAreaHeight(pane, c3, -1, new Insets(1), 50), 1e-100);
962 }
963
964 @Test public void testChildMaxAreaWidth() {
965 Pane pane = new Pane();
966
967 Region c1 = new MockBiased(Orientation.HORIZONTAL, 100, 100);
968 Region c2 = new MockBiased(Orientation.VERTICAL, 100, 100);
969 Region c3 = new MockRegion(10, 10, 100, 100, 1000, 1000);
970
971 pane.getChildren().addAll(c1, c2, c3);
972
973 assertEquals(10002, RegionShim.computeChildMaxAreaWidth(pane,c1, -1, new Insets(1), -1, false), 1e-100);
974 assertEquals(10002, RegionShim.computeChildMaxAreaWidth(pane,c1, -1, new Insets(1), 50, false), 1e-100);
975 assertEquals(102, RegionShim.computeChildMaxAreaWidth(pane,c2, -1, new Insets(1), -1, false), 1e-100); // Vertival bias is not applied when no height/baseline offset is set
976 assertEquals(2 + Math.ceil(100*100/48.0), RegionShim.computeChildMaxAreaWidth(pane,c2, -1, new Insets(1), 50, false), 1e-100);
977 assertEquals(2 + Math.ceil(100*100/38.0), RegionShim.computeChildMaxAreaWidth(pane,c2, 10, new Insets(1), 50, false), 1e-100);
978 assertEquals(1002, RegionShim.computeChildMaxAreaWidth(pane,c3, -1, new Insets(1), -1, false), 1e-100);
979 assertEquals(1002, RegionShim.computeChildMaxAreaWidth(pane,c3, -1, new Insets(1), 50, false), 1e-100);
980 }
981
982 @Test public void testChildMaxAreaHeight() {
983 Pane pane = new Pane();
984
985 Region c1 = new MockBiased(Orientation.HORIZONTAL, 100, 100);
986 Region c2 = new MockBiased(Orientation.VERTICAL, 100, 100);
987 Region c3 = new MockRegion(10, 10, 100, 100, 1000, 1000);
988
989 pane.getChildren().addAll(c1, c2, c3);
990
991 assertEquals(1002, RegionShim.computeChildMaxAreaHeight(pane,c1, -1, new Insets(1), -1), 1e-100);
992 assertEquals(2 + Math.ceil(100*100/48.0), RegionShim.computeChildMaxAreaHeight(pane,c1, -1, new Insets(1), 50), 1e-100);
993 assertEquals(12 + Math.ceil(100*100/48.0), RegionShim.computeChildMaxAreaHeight(pane,c1, 10, new Insets(1), 50), 1e-100);
994 assertEquals(10002, RegionShim.computeChildMaxAreaHeight(pane,c2, -1, new Insets(1), -1), 1e-100);
995 assertEquals(10002, RegionShim.computeChildMaxAreaHeight(pane,c2, -1, new Insets(1), 50), 1e-100);
996 assertEquals(1002, RegionShim.computeChildMaxAreaHeight(pane,c3, -1, new Insets(1), -1), 1e-100);
997 assertEquals(1002, RegionShim.computeChildMaxAreaHeight(pane,c3, -1, new Insets(1), 50), 1e-100);
998 }
999
1000 /**************************************************************************
1001 * *
1002 * Test that images which are background loaded, or images which can *
1003 * change (such as WritableImage or animated gif) will cause a *
1004 * listener to be installed. Also that a non-animating background *
1005 * loaded image will have the listener removed when the image *
1006 * finishes loading, and that all listeners are removed from images *
1007 * which have been removed from the Region. Also that any animating *
1008 * or background loaded image will cause a repaint to happen when the *
1009 * underlying platform image changes. *
1010 * *
1011 *************************************************************************/
1012
1013 @Test public void testBackgroundLoadedBackgroundImageHasListenerInstalled() {
1014 final ImageForTesting image = new ImageForTesting("http://something.png", true);
1015 assertTrue(image.getProgress() < 1);
1016
1017 ImageRegion r = new ImageRegion();
1162 ImageRegion r = new ImageRegion();
1163 final Border border = new Border(new BorderImage(image, null, null, null, false, null, null));
1164 r.setBorder(border);
1165 r.clearDirty();
1166 assertFalse(r.willBeRepainted());
1167 image.getPixelWriter().setArgb(0, 0, 100);
1168 assertTrue(r.willBeRepainted());
1169 }
1170
1171 @Test public void testBorderChangeUpdatesTheInsets() {
1172 Region r = new Region();
1173
1174 r.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, BorderWidths.DEFAULT, new Insets(10))));
1175 assertEquals(new Insets(11), r.getInsets());
1176
1177 r.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, null, new Insets(20))));
1178
1179 assertEquals(new Insets(21), r.getInsets());
1180 }
1181
1182 static final class ImageRegion extends RegionShim {
1183 AtomicBoolean listenerAdded = new AtomicBoolean(false);
1184
1185 @Override public void addImageListener(Image image) {
1186 super.addImageListener(image);
1187 listenerAdded.set(true);
1188 }
1189
1190 @Override public void removeImageListener(Image image) {
1191 super.removeImageListener(image);
1192 listenerAdded.set(false);
1193 }
1194
1195 public boolean willBeRepainted() {
1196 return NodeShim.impl_isDirty(this, DirtyBits.NODE_CONTENTS);
1197 }
1198
1199 public void clearDirty() {
1200 NodeShim.impl_clearDirty(this, DirtyBits.NODE_CONTENTS);
1201 }
1202 };
1203
1204 // Test for RT-13820
1205 @Test public void changingShapeElementsShouldResultInRender() {
1206 Region r = new Region();
1207 r.setPrefWidth(640);
1208 r.setPrefHeight(480);
1209 LineTo lineTo;
1210 Path p = new Path(
1211 new MoveTo(0, 0),
1212 lineTo = new LineTo(100, 0),
1213 new LineTo(50, 100),
1214 new ClosePath()
1215 );
1216 r.setBackground(new Background(new BackgroundFill(Color.BLUE, null, null)));
1217 r.setCenterShape(true);
1218 r.setScaleShape(true);
1219 r.setShape(p);
1220 r.impl_syncPeer();
|