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.effect;
  27 
  28 import static com.sun.javafx.test.TestHelper.box;
  29 
  30 import java.util.ArrayList;
  31 import java.util.Collection;
  32 
  33 import javafx.scene.Node;
  34 import javafx.scene.shape.Rectangle;
  35 
  36 import org.junit.runner.RunWith;
  37 import org.junit.runners.Parameterized;
  38 import org.junit.runners.Parameterized.Parameters;
  39 
  40 import com.sun.javafx.test.BBoxComparator;
  41 import com.sun.javafx.test.PropertiesTestBase;
  42 
  43 @RunWith(Parameterized.class)
  44 public final class PerspectiveTransform_properties_Test extends PropertiesTestBase {
  45 
  46     @Parameters
  47     public static Collection data() {
  48         ArrayList array = new ArrayList();
  49 
  50         // simple property tests
  51         final PerspectiveTransform testPerspectiveTransform =
  52                 new PerspectiveTransform();
  53 
  54         array.add(config(testPerspectiveTransform, "input",
  55                          null, new BoxBlur()));
  56         array.add(config(testPerspectiveTransform, "ulx", 0.0, 10.0));
  57         array.add(config(testPerspectiveTransform, "uly", 0.0, 10.0));
  58         array.add(config(testPerspectiveTransform, "urx", 0.0, 310.0));
  59         array.add(config(testPerspectiveTransform, "ury", 0.0, 40.0));
  60         array.add(config(testPerspectiveTransform, "lrx", 0.0, 310.0));
  61         array.add(config(testPerspectiveTransform, "lry", 0.0, 60.0));
  62         array.add(config(testPerspectiveTransform, "llx", 0.0, 10.0));
  63         array.add(config(testPerspectiveTransform, "lly", 0.0, 90.0));
  64 
  65         // bounding box calculation tests
  66 
  67         Node testNode = createTestNode();
  68         array.add(config(testNode.getEffect(),
  69                 "llx", 10.0, 20.0,
  70                 testNode,
  71                 "boundsInLocal",
  72                 box(0.0, 0.0, 10.0, 0.0),
  73                 box(0.0, 0.0, 20.0, 0.0),
  74                 new BBoxComparator(0.01)));
  75 
  76         testNode = createTestNode();
  77         array.add(config(testNode.getEffect(),
  78                 "lly", 10.0, 20.0,
  79                 testNode,
  80                 "boundsInLocal",
  81                 box(0.0, 0.0, 0.0, 10.0),
  82                 box(0.0, 0.0, 0.0, 20.0),
  83                 new BBoxComparator(0.01)));
  84 
  85         testNode = createTestNode();
  86         array.add(config(testNode.getEffect(),
  87                 "lrx", 10.0, 20.0,
  88                 testNode,
  89                 "boundsInLocal",
  90                 box(0.0, 0.0, 10.0, 0.0),
  91                 box(0.0, 0.0, 20.0, 0.0),
  92                 new BBoxComparator(0.01)));
  93 
  94         testNode = createTestNode();
  95         array.add(config(testNode.getEffect(),
  96                 "lry", 10.0, 20.0,
  97                 testNode,
  98                 "boundsInLocal",
  99                 box(0.0, 0.0, 0.0, 10.0),
 100                 box(0.0, 0.0, 0.0, 20.0),
 101                 new BBoxComparator(0.01)));
 102 
 103         testNode = createTestNode();
 104         array.add(config(testNode.getEffect(),
 105                 "ulx", 10.0, 20.0,
 106                 testNode,
 107                 "boundsInLocal",
 108                 box(0.0, 0.0, 10.0, 0.0),
 109                 box(0.0, 0.0, 20.0, 0.0),
 110                 new BBoxComparator(0.01)));
 111 
 112         testNode = createTestNode();
 113         array.add(config(testNode.getEffect(),
 114                 "uly", 10.0, 20.0,
 115                 testNode,
 116                 "boundsInLocal",
 117                 box(0.0, 0.0, 0.0, 10.0),
 118                 box(0.0, 0.0, 0.0, 20.0),
 119                 new BBoxComparator(0.01)));
 120 
 121         testNode = createTestNode();
 122         array.add(config(testNode.getEffect(),
 123                 "urx", 10.0, 20.0,
 124                 testNode,
 125                 "boundsInLocal",
 126                 box(0.0, 0.0, 10.0, 0.0),
 127                 box(0.0, 0.0, 20.0, 0.0),
 128                 new BBoxComparator(0.01)));
 129 
 130         testNode = createTestNode();
 131         array.add(config(testNode.getEffect(),
 132                 "ury", 10.0, 20.0,
 133                 testNode,
 134                 "boundsInLocal",
 135                 box(0.0, 0.0, 0.0, 10.0),
 136                 box(0.0, 0.0, 0.0, 20.0),
 137                 new BBoxComparator(0.01)));
 138 
 139         testNode = createTestNode();
 140         PerspectiveTransform pt = (PerspectiveTransform)testNode.getEffect();
 141         pt.setLlx(0); pt.setLly(0);
 142         pt.setLrx(100); pt.setLly(0);
 143         pt.setUlx(0); pt.setUly(100);
 144         pt.setUrx(100); pt.setUly(100);
 145         array.add(config(testNode.getEffect(),
 146                 "input", null, new BoxBlur(),
 147                 testNode,
 148                 "boundsInLocal",
 149                 box(0.0, 0.0, 100.0, 100.0),
 150                 box(0.0, 0.0, 100.0, 100.0),
 151                 new BBoxComparator(0.01)));
 152 
 153         testNode = createTestNodeWithChainedEffect();
 154         array.add(config(((ColorAdjust)testNode.getEffect()).getInput(),
 155                 "llx", 10.0, 20.0,
 156                 testNode,
 157                 "boundsInLocal",
 158                 box(0.0, 0.0, 10.0, 0.0),
 159                 box(0.0, 0.0, 20.0, 0.0),
 160                 new BBoxComparator(0.01)));
 161 
 162         testNode = createTestNodeWithChainedEffect();
 163         array.add(config(((ColorAdjust)testNode.getEffect()).getInput(),
 164                 "lly", 10.0, 20.0,
 165                 testNode,
 166                 "boundsInLocal",
 167                 box(0.0, 0.0, 0.0, 10.0),
 168                 box(0.0, 0.0, 0.0, 20.0),
 169                 new BBoxComparator(0.01)));
 170 
 171         testNode = createTestNodeWithChainedEffect();
 172         array.add(config(((ColorAdjust)testNode.getEffect()).getInput(),
 173                 "lrx", 10.0, 20.0,
 174                 testNode,
 175                 "boundsInLocal",
 176                 box(0.0, 0.0, 10.0, 0.0),
 177                 box(0.0, 0.0, 20.0, 0.0),
 178                 new BBoxComparator(0.01)));
 179 
 180         testNode = createTestNodeWithChainedEffect();
 181         array.add(config(((ColorAdjust)testNode.getEffect()).getInput(),
 182                 "lry", 10.0, 20.0,
 183                 testNode,
 184                 "boundsInLocal",
 185                 box(0.0, 0.0, 0.0, 10.0),
 186                 box(0.0, 0.0, 0.0, 20.0),
 187                 new BBoxComparator(0.01)));
 188 
 189         testNode = createTestNodeWithChainedEffect();
 190         array.add(config(((ColorAdjust)testNode.getEffect()).getInput(),
 191                 "ulx", 10.0, 20.0,
 192                 testNode,
 193                 "boundsInLocal",
 194                 box(0.0, 0.0, 10.0, 0.0),
 195                 box(0.0, 0.0, 20.0, 0.0),
 196                 new BBoxComparator(0.01)));
 197 
 198         testNode = createTestNodeWithChainedEffect();
 199         array.add(config(((ColorAdjust)testNode.getEffect()).getInput(),
 200                 "uly", 10.0, 20.0,
 201                 testNode,
 202                 "boundsInLocal",
 203                 box(0.0, 0.0, 0.0, 10.0),
 204                 box(0.0, 0.0, 0.0, 20.0),
 205                 new BBoxComparator(0.01)));
 206 
 207         testNode = createTestNodeWithChainedEffect();
 208         array.add(config(((ColorAdjust)testNode.getEffect()).getInput(),
 209                 "urx", 10.0, 20.0,
 210                 testNode,
 211                 "boundsInLocal",
 212                 box(0.0, 0.0, 10.0, 0.0),
 213                 box(0.0, 0.0, 20.0, 0.0),
 214                 new BBoxComparator(0.01)));
 215 
 216         testNode = createTestNodeWithChainedEffect();
 217         array.add(config(((ColorAdjust)testNode.getEffect()).getInput(),
 218                 "ury", 10.0, 20.0,
 219                 testNode,
 220                 "boundsInLocal",
 221                 box(0.0, 0.0, 0.0, 10.0),
 222                 box(0.0, 0.0, 0.0, 20.0),
 223                 new BBoxComparator(0.01)));
 224 
 225         testNode = createTestNodeWithChainedEffect();
 226         pt = (PerspectiveTransform)(((ColorAdjust)testNode.getEffect()).getInput());
 227         pt.setLlx(0); pt.setLly(0);
 228         pt.setLrx(100); pt.setLly(0);
 229         pt.setUlx(0); pt.setUly(100);
 230         pt.setUrx(100); pt.setUly(100);
 231         array.add(config(pt,
 232                 "input", null, new BoxBlur(),
 233                 testNode,
 234                 "boundsInLocal",
 235                 box(0.0, 0.0, 100.0, 100.0),
 236                 box(0.0, 0.0, 100.0, 100.0),
 237                 new BBoxComparator(0.01)));
 238         return array;
 239     }
 240 
 241     public PerspectiveTransform_properties_Test(final Configuration configuration) {
 242         super(configuration);
 243     }
 244 
 245     private static Rectangle createTestNode() {
 246         Rectangle r = new Rectangle(100, 100);
 247         r.setEffect(new PerspectiveTransform());
 248         return r;
 249     }
 250 
 251 
 252     private static Rectangle createTestNodeWithChainedEffect() {
 253         Rectangle r = new Rectangle(100, 100);
 254         ColorAdjust c = new ColorAdjust();
 255         c.setInput(new PerspectiveTransform());
 256         r.setEffect(c);
 257         return r;
 258     }
 259 }