1 /* 2 * Copyright (c) 2012, 2015, 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 test.javafx.scene.chart; 27 28 import org.junit.Before; 29 30 import test.com.sun.javafx.pgstub.StubToolkit; 31 import com.sun.javafx.tk.Toolkit; 32 import java.util.Arrays; 33 import javafx.scene.Node; 34 import javafx.scene.Scene; 35 import javafx.scene.chart.Chart; 36 import javafx.stage.Stage; 37 import javafx.scene.layout.Region; 38 import javafx.scene.shape.*; 39 import static org.junit.Assert.assertTrue; 40 41 public abstract class ChartTestBase { 42 private Scene scene; 43 private Stage stage; 44 StubToolkit toolkit = (StubToolkit) Toolkit.getToolkit(); 45 private Chart chart; 46 47 @Before 48 public void setUp() { 49 chart = createChart(); 50 chart.setAnimated(false); 51 } 52 53 protected void startApp() { 54 scene = new Scene(chart,800,600); 55 stage = new Stage(); 56 stage.setScene(scene); 57 stage.show(); 58 toolkit.setAnimationTime(0); 59 pulse(); 60 } 61 62 protected void pulse() { 63 toolkit.fireTestPulse(); 64 } 65 66 protected Scene getTestScene() { 67 return this.scene; 68 } 69 70 protected void setTestScene(Scene scene) { 71 this.scene = scene; 72 } 73 74 protected Stage getTestStage() { 75 return this.stage; 76 } 77 78 protected void setTestStage(Stage stage) { 79 this.stage = stage; 80 } 81 82 protected abstract Chart createChart(); 83 84 String computeSVGPath(Path line) { 85 StringBuilder str = new StringBuilder(); 86 for (PathElement pe : line.getElements()) { 87 if (pe instanceof LineTo) { 88 str.append("L").append(((LineTo)pe).getX()).append(" ") 89 .append(((LineTo)pe).getY()).append(" "); 90 } 91 } 92 return str.toString(); 93 } 94 95 String computeBoundsString(Region r1, Region r2, Region r3) { 96 StringBuilder str = new StringBuilder(); 97 str.append(Math.round(r1.getLayoutX())).append(" ") 98 .append(Math.round(r1.getLayoutY())).append(" ") 99 .append(Math.round(r1.getWidth())).append(" ") 100 .append(Math.round(r1.getHeight())).append(" "); 101 str.append(Math.round(r2.getLayoutX())).append(" ") 102 .append(Math.round(r2.getLayoutY())).append(" ") 103 .append(Math.round(r2.getWidth())).append(" ") 104 .append(Math.round(r2.getHeight())).append(" "); 105 str.append(Math.round(r3.getLayoutX())).append(" ") 106 .append(Math.round(r3.getLayoutY())).append(" ") 107 .append(Math.round(r3.getWidth())).append(" ") 108 .append(Math.round(r3.getHeight())).append(" "); 109 return str.toString(); 110 } 111 112 void checkStyleClass(Node item, String... styleClass) { 113 assertTrue("\"" + item.getStyleClass() + "\" doesn't contain all of the " + 114 Arrays.toString(styleClass), 115 item.getStyleClass().containsAll(Arrays.asList(styleClass))); 116 } 117 }