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