1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   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.transform;
  27 
  28 import static javafx.scene.transform.TransformTest.assertTx;
  29 import javafx.scene.shape.Rectangle;
  30 
  31 import org.junit.Assert;
  32 import org.junit.Test;
  33 import static org.junit.Assert.*;
  34 
  35 import com.sun.javafx.test.TransformHelper;
  36 import com.sun.javafx.geom.transform.BaseTransform;
  37 
  38 
  39 public class TranslateTest {
  40 
  41     @Test
  42     public void testTranslate() {
  43         final Translate trans = new Translate() {{
  44             setX(25);
  45             setY(52);
  46         }};
  47         final Rectangle n = new Rectangle();
  48         n.getTransforms().add(trans);
  49 
  50         assertTx(n, BaseTransform.getTranslateInstance(25, 52));
  51         TransformHelper.assertMatrix(trans,
  52                 1, 0, 0, 25,
  53                 0, 1, 0, 52,
  54                 0, 0, 1,  0);
  55 
  56         trans.setX(34);
  57         Assert.assertEquals(34, trans.getX(), 1e-100);
  58         assertTx(n, BaseTransform.getTranslateInstance(34, 52));
  59         TransformHelper.assertMatrix(trans,
  60                 1, 0, 0, 34,
  61                 0, 1, 0, 52,
  62                 0, 0, 1,  0);
  63 
  64 
  65         trans.setY(67);
  66         assertTx(n, BaseTransform.getTranslateInstance(34, 67));
  67         TransformHelper.assertMatrix(trans,
  68                 1, 0, 0, 34,
  69                 0, 1, 0, 67,
  70                 0, 0, 1,  0);
  71 
  72         trans.setZ(33);
  73         TransformHelper.assertMatrix(trans,
  74                 1, 0, 0, 34,
  75                 0, 1, 0, 67,
  76                 0, 0, 1, 33);
  77     }
  78 
  79     @Test
  80     public void testCopying() {
  81         final Translate trans = new Translate(34, 67, 33);
  82 
  83         Transform copy = trans.clone();
  84 
  85         TransformHelper.assertMatrix(copy,
  86                 1, 0, 0, 34,
  87                 0, 1, 0, 67,
  88                 0, 0, 1, 33);
  89     }
  90 
  91     @Test public void testToString() {
  92         final Translate trans = new Translate(8, 15);
  93 
  94         String s = trans.toString();
  95 
  96         assertNotNull(s);
  97         assertFalse(s.isEmpty());
  98     }
  99 
 100     @Test public void testBoundPropertySynced_X() throws Exception {
 101         TransformTest.checkDoublePropertySynced(new Translate(3, 3, 0), "x", 22.0);
 102     }
 103 
 104     @Test public void testBoundPropertySynced_Y() throws Exception {
 105         TransformTest.checkDoublePropertySynced(new Translate(3, 3, 0), "y", 33.0);
 106     }
 107 
 108     @Test public void testBoundPropertySynced_Z() throws Exception {
 109         TransformTest.checkDoublePropertySynced(new Translate(3, 3, 0), "z", 44.0);
 110     }
 111 }