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.shape;
  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.paint.Color;
  34 
  35 import org.junit.Test;
  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 import javafx.collections.ListChangeListener;
  43 import javafx.collections.ListChangeListener.Change;
  44 import javafx.collections.ObservableList;
  45 
  46 @RunWith(Parameterized.class)
  47 public final class Shape_properties_Test extends PropertiesTestBase {
  48 
  49     @Parameters
  50     public static Collection data() {
  51         ArrayList array = new ArrayList();        
  52 
  53         // simple property tests
  54         Shape testShape = createTestRectangle();
  55 
  56         array.add(config(testShape, "strokeType",
  57                   StrokeType.CENTERED, StrokeType.INSIDE));
  58         array.add(config(testShape, "strokeWidth", 1.0, 2.0));
  59         array.add(config(testShape, "strokeLineJoin",
  60                   StrokeLineJoin.MITER, StrokeLineJoin.BEVEL));
  61         array.add(config(testShape, "strokeLineCap",
  62                   StrokeLineCap.ROUND,  StrokeLineCap.SQUARE));
  63         array.add(config(testShape, "strokeMiterLimit", 0.0, 10.0));
  64         array.add(config(testShape, "strokeDashOffset", 0.0, 3.0));
  65         array.add(config(testShape, "fill", Color.BLACK, null));
  66         array.add(config(testShape, "stroke", null, Color.BLACK));
  67         array.add(config(testShape, "smooth", true, false));
  68 
  69         // bounding box calculation tests
  70         array.add(config(createTestRectangle(),
  71                     "strokeWidth", 0.0, 20.0,
  72                     "boundsInLocal",
  73                     box(0, 0, 100, 100), box(-10, -10, 120, 120)));
  74 
  75         testShape = createTestTriangle();
  76         array.add(config(testShape,
  77                     "strokeLineJoin", StrokeLineJoin.MITER, StrokeLineJoin.BEVEL,
  78                     testShape,
  79                     "boundsInLocal",
  80                     box(192.562, 33.68, 114.874, 171.811), 
  81                     box(194.756, 47.918, 110.486, 157.581),
  82                     new BBoxComparator(0.01)));
  83 
  84         testShape = createTestTriangle();
  85         array.add(config(testShape,
  86                     "strokeMiterLimit", 100.0, 0.0,
  87                     testShape,
  88                     "boundsInLocal",
  89                     box(192.562, 33.68, 114.874, 171.811),
  90                     box(194.756, 47.918, 110.486, 157.581),
  91                     new BBoxComparator(0.01)));
  92 
  93         testShape = createTestTriangle();
  94         array.add(config(testShape,
  95                     "strokeType", StrokeType.INSIDE, StrokeType.OUTSIDE,
  96                     testShape,
  97                     "boundsInLocal",
  98                     box(200, 50, 100, 150),
  99                     box(185.625, 17.877, 128.748, 192.622),
 100                     new BBoxComparator(0.01)));
 101 
 102         testShape = createTestLine();
 103         array.add(config(testShape,
 104                     "strokeLineCap", StrokeLineCap.BUTT, StrokeLineCap.SQUARE,
 105                     testShape,
 106                     "boundsInLocal",
 107                     box(195, 100, 10, 100),
 108                     box(195, 95, 10, 110),
 109                     new BBoxComparator(0.001)));
 110 
 111         return array;
 112     }
 113 
 114     public Shape_properties_Test(final Configuration configuration) {
 115         super(configuration);
 116     }
 117 
 118     private static Rectangle createTestRectangle() {
 119         Rectangle r = new Rectangle(100, 100);
 120         r.setStroke(Color.BLACK);
 121         return r;
 122     }
 123 
 124     private static Polygon createTestTriangle() {
 125         Polygon p = new Polygon(new double[]{200, 200, 250, 50, 300, 200});
 126         p.setStroke(Color.BLACK);
 127         p.setStrokeWidth(10);
 128         p.setStrokeMiterLimit(100);
 129         return p;
 130     }
 131 
 132     private static Line createTestLine() {
 133         Line l = new Line(200, 100, 200, 200);
 134         l.setStroke(Color.BLACK);
 135         l.setStrokeWidth(10);
 136         return l;
 137     }
 138     
 139 }