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 javafx.scene.Scene; 33 import javafx.scene.chart.Chart; 34 import javafx.stage.Stage; 35 import javafx.scene.layout.Region; 36 import javafx.scene.shape.*; 37 38 39 public abstract class ChartTestBase { 40 private Scene scene; 41 private Stage stage; 42 StubToolkit toolkit = (StubToolkit) Toolkit.getToolkit(); 43 private Chart chart; 44 45 @Before 46 public void setUp() { 47 chart = createChart(); 48 chart.setAnimated(false); 49 } 50 51 protected void startApp() { 52 scene = new Scene(chart,800,600); 53 stage = new Stage(); 54 stage.setScene(scene); 55 stage.show(); 56 toolkit.setAnimationTime(0); 57 pulse(); 58 } 59 60 protected void pulse() { 61 toolkit.fireTestPulse(); 62 } 63 64 protected Scene getTestScene() { 65 return this.scene; 66 } 67 68 protected void setTestScene(Scene scene) { 69 this.scene = scene; 70 } 71 72 protected Stage getTestStage() { 73 return this.stage; 74 } 75 76 protected void setTestStage(Stage stage) { 77 this.stage = stage; 78 } 79 80 protected abstract Chart createChart(); 81 82 StringBuffer computeSVGPath(Path line) { 83 StringBuffer str = new StringBuffer(); 84 for(PathElement pe : line.getElements()) { 85 if (pe instanceof LineTo) { 86 str.append("L"+((LineTo)pe).getX()+" "+((LineTo)pe).getY()+" "); 87 } 88 } 89 return str; 90 } 91 92 StringBuffer computeBoundsString(Region r1, Region r2, Region r3) { 93 StringBuffer str = new StringBuffer(); 94 str.append(Math.round(r1.getLayoutX()) 95 +" "+Math.round(r1.getLayoutY())+" "+Math.round(r1.getWidth())+ 96 " "+Math.round(r1.getHeight())+" "); 97 str.append(Math.round(r2.getLayoutX()) 98 +" "+Math.round(r2.getLayoutY())+" "+Math.round(r2.getWidth())+ 99 " "+Math.round(r2.getHeight())+" "); 100 str.append(Math.round(r3.getLayoutX()) 101 +" "+Math.round(r3.getLayoutY())+" "+Math.round(r3.getWidth())+ 102 " "+Math.round(r3.getHeight())+" "); 103 return str; 104 } 105 }