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.bounds;
27
28 import static test.com.sun.javafx.test.TestHelper.assertBoundsEqual;
29 import static test.com.sun.javafx.test.TestHelper.assertGroupBounds;
30 import static test.com.sun.javafx.test.TestHelper.box;
31 import static test.com.sun.javafx.test.TestHelper.formatBounds;
32 import static junit.framework.Assert.assertEquals;
33
34 import java.util.LinkedList;
35
36 import javafx.geometry.Bounds;
37 import javafx.scene.Group;
38 import javafx.scene.shape.Rectangle;
39
40 import org.junit.Test;
41
42 public class GroupBoundsTest {
43
44 /***************************************************************************
45 * * Group Tests * * These are tests related to transforming the basic node
46 * types including * * /
47 **************************************************************************/
451 + "boundsInParent " + formatBounds(rect.getBoundsInParent())+ " to the group. The "
452 + "layoutBounds of the Group was " + formatBounds(layoutBounds)+ " and is now "
453 + "" + formatBounds(g.getLayoutBounds())+ " and had " + numChildren+ " number of "
454 + "child nodes";
455 whatHappenedStack.add(whatHappened);
456 }
457 try {
458 assertGroupBounds(g);
459 } catch (Exception any) {
460 System.out.println("Something went wrong. Here's what happened:");
461 for (String item : whatHappenedStack) {
462 System.out.println("{item}");
463 }
464 throw new RuntimeException(any);
465 }
466 }
467 }
468 }
469 }
470
471 // here is a special test for impl_getPivotX and impl_getPivotY
472 @Test
473 public void testPivotXAndPivotY() {
474 Rectangle rect = new Rectangle(100, 100);
475 assertEquals(50.0f, (float) rect.impl_getPivotX());
476 assertEquals(50.0f, (float) rect.impl_getPivotY());
477 rect.setWidth(70.0f);
478 assertEquals(35.0f, (float) rect.impl_getPivotX());
479 assertEquals(50.0f, (float) rect.impl_getPivotY());
480 }
481
482 /***************************************************************************
483 * Group Bounds Sanity Tests * * These tests are for Group
484 * to make sure that their * bounds are reported correctly
485 * before effects or clips or transforms * are taken into account. * * The
486 * group tests here are just basic tests, a full set of Group bounds * tests
487 * are included in their own section later in this file. There are * many
488 * edge cases to group bounds. The primary purpose of these next * few tests
489 * are just to make sure that group's bounds are correct in the * simple
490 * case. * *
491 **************************************************************************/
492
493 public @Test
494 void testBoundsForGroup() {
495 Rectangle r1 = new Rectangle(20, 20, 50, 50);
496 Rectangle r2 = new Rectangle(90, 20, 50, 50);
497 Group group = new Group(r1, r2);
498
499 assertEquals(box(20, 20, 120, 50), group.getBoundsInLocal());
|
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.bounds;
27
28 import com.sun.javafx.scene.NodeHelper;
29 import static test.com.sun.javafx.test.TestHelper.assertBoundsEqual;
30 import static test.com.sun.javafx.test.TestHelper.assertGroupBounds;
31 import static test.com.sun.javafx.test.TestHelper.box;
32 import static test.com.sun.javafx.test.TestHelper.formatBounds;
33 import static junit.framework.Assert.assertEquals;
34
35 import java.util.LinkedList;
36
37 import javafx.geometry.Bounds;
38 import javafx.scene.Group;
39 import javafx.scene.shape.Rectangle;
40
41 import org.junit.Test;
42
43 public class GroupBoundsTest {
44
45 /***************************************************************************
46 * * Group Tests * * These are tests related to transforming the basic node
47 * types including * * /
48 **************************************************************************/
452 + "boundsInParent " + formatBounds(rect.getBoundsInParent())+ " to the group. The "
453 + "layoutBounds of the Group was " + formatBounds(layoutBounds)+ " and is now "
454 + "" + formatBounds(g.getLayoutBounds())+ " and had " + numChildren+ " number of "
455 + "child nodes";
456 whatHappenedStack.add(whatHappened);
457 }
458 try {
459 assertGroupBounds(g);
460 } catch (Exception any) {
461 System.out.println("Something went wrong. Here's what happened:");
462 for (String item : whatHappenedStack) {
463 System.out.println("{item}");
464 }
465 throw new RuntimeException(any);
466 }
467 }
468 }
469 }
470 }
471
472 // here is a special test for getPivotX and getPivotY
473 @Test
474 public void testPivotXAndPivotY() {
475 Rectangle rect = new Rectangle(100, 100);
476 assertEquals(50.0f, (float) NodeHelper.getPivotX(rect));
477 assertEquals(50.0f, (float) NodeHelper.getPivotY(rect));
478 rect.setWidth(70.0f);
479 assertEquals(35.0f, (float) NodeHelper.getPivotX(rect));
480 assertEquals(50.0f, (float) NodeHelper.getPivotY(rect));
481 }
482
483 /***************************************************************************
484 * Group Bounds Sanity Tests * * These tests are for Group
485 * to make sure that their * bounds are reported correctly
486 * before effects or clips or transforms * are taken into account. * * The
487 * group tests here are just basic tests, a full set of Group bounds * tests
488 * are included in their own section later in this file. There are * many
489 * edge cases to group bounds. The primary purpose of these next * few tests
490 * are just to make sure that group's bounds are correct in the * simple
491 * case. * *
492 **************************************************************************/
493
494 public @Test
495 void testBoundsForGroup() {
496 Rectangle r1 = new Rectangle(20, 20, 50, 50);
497 Rectangle r2 = new Rectangle(90, 20, 50, 50);
498 Group group = new Group(r1, r2);
499
500 assertEquals(box(20, 20, 120, 50), group.getBoundsInLocal());
|