1 /* 2 * Copyright (c) 2014, 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 package javafx.scene.control.test.chart.manual; 26 27 import javafx.scene.control.test.utils.ptables.WeakPropertyValueController; 28 import java.util.Arrays; 29 import javafx.collections.FXCollections; 30 import javafx.collections.ObservableList; 31 import javafx.event.ActionEvent; 32 import javafx.event.EventHandler; 33 import javafx.scene.chart.PieChart; 34 import javafx.scene.Scene; 35 import javafx.scene.control.*; 36 import javafx.scene.control.ButtonBuilder; 37 import javafx.scene.control.test.utils.CommonPropertiesScene; 38 import javafx.geometry.Side; 39 import javafx.scene.layout.HBox; 40 import test.javaclient.shared.InteroperabilityApp; 41 import test.javaclient.shared.Utils; 42 import javafx.scene.layout.VBox; 43 import javafx.geometry.Orientation; 44 45 /** 46 * @author Alexander Kirov 47 */ 48 public class PieChartManualApp extends InteroperabilityApp { 49 50 public static void main(String[] args) { 51 Utils.launch(PieChartManualApp.class, args); 52 } 53 54 @Override 55 protected Scene getScene() { 56 Utils.setTitleToStage(stage, "PieChartTestApp"); 57 return new PieChartScene(); 58 } 59 60 class PieChartScene extends CommonPropertiesScene { 61 62 //PieChart to be tested. 63 PieChart testedPieChart; 64 int controlContainerWidth = 400; 65 int controlContainerHeight = 400; 66 ObservableList<PieChart.Data> data; 67 VBox properties; 68 69 public PieChartScene() { 70 super("PieChart", 900, 630); 71 72 prepareScene(); 73 } 74 75 @Override 76 final protected void prepareScene() { 77 testedPieChart = getNewChart(); 78 testedPieChart.setPrefSize(controlContainerHeight, controlContainerWidth); 79 properties = new VBox(10); 80 81 Button addDataButton = new Button("Add data at index 0"); 82 addDataButton.setOnAction(new EventHandler<ActionEvent>() { 83 public void handle(ActionEvent t) { 84 testedPieChart.getData().add(0, new PieChart.Data("Added data", Math.random() * 100)); 85 } 86 }); 87 88 Button removeDataButton = new Button("Remove data from index 0"); 89 removeDataButton.setOnAction(new EventHandler<ActionEvent>() { 90 public void handle(ActionEvent t) { 91 if (testedPieChart.getData().size() > 0) { 92 testedPieChart.getData().remove(0); 93 } 94 } 95 }); 96 97 Button changeDataButton = new Button("Change data at index 0"); 98 changeDataButton.setOnAction(new EventHandler<ActionEvent>() { 99 public void handle(ActionEvent t) { 100 if (testedPieChart.getData().size() > 0) { 101 PieChart.Data data = testedPieChart.getData().get(0); 102 data.setPieValue(Math.max(0, data.getPieValue() + (Math.random() - 0.5) * 200)); 103 } 104 } 105 }); 106 107 Button hardResetButton = ButtonBuilder.create().text("Reset").build(); 108 hardResetButton.setOnAction(new EventHandler<ActionEvent>() { 109 public void handle(ActionEvent t) { 110 HBox hb = (HBox) getRoot(); 111 hb.getChildren().clear(); 112 prepareMainSceneStructure(); 113 prepareScene(); 114 } 115 }); 116 117 VBox vb = new VBox(5); 118 vb.getChildren().addAll(hardResetButton, 119 new Separator(Orientation.HORIZONTAL), new Label("Add new data : "), addDataButton, 120 new Separator(Orientation.HORIZONTAL), new Label("Remove existing data : "), removeDataButton, 121 new Separator(Orientation.HORIZONTAL), new Label("Change existing data : "), changeDataButton); 122 123 addController(new WeakPropertyValueController(testedPieChart.animatedProperty(), testedPieChart)); 124 addController(new WeakPropertyValueController(testedPieChart.clockwiseProperty(), testedPieChart)); 125 addController(new WeakPropertyValueController(testedPieChart.legendVisibleProperty(), testedPieChart)); 126 addController(new WeakPropertyValueController(testedPieChart.startAngleProperty(), testedPieChart, -300.0, 0.0, 300.0)); 127 addController(new WeakPropertyValueController(testedPieChart.labelLineLengthProperty(), testedPieChart, -20.0, 10.0, 30.0)); 128 addController(new WeakPropertyValueController(testedPieChart.labelsVisibleProperty(), testedPieChart)); 129 addController(new WeakPropertyValueController(testedPieChart.titleProperty(), testedPieChart, "New title")); 130 addController(new WeakPropertyValueController(testedPieChart.titleSideProperty(), testedPieChart, Arrays.asList(Side.values()))); 131 addController(new WeakPropertyValueController(testedPieChart.legendSideProperty(), testedPieChart, Arrays.asList(Side.values()))); 132 addController(new WeakPropertyValueController(testedPieChart.prefWidthProperty(), testedPieChart, 100.0, 400.0, 400.0)); 133 addController(new WeakPropertyValueController(testedPieChart.prefHeightProperty(), testedPieChart, 100.0, 400.0, 400.0)); 134 135 setTestedControlContainerSize(400, 400); 136 setTestedControl(testedPieChart); 137 setControllersContent(vb); 138 setPropertiesContent(properties); 139 } 140 141 private void addController(WeakPropertyValueController controller) { 142 properties.getChildren().addAll(new Separator(Orientation.HORIZONTAL), controller); 143 } 144 145 public PieChart getNewChart() { 146 data = FXCollections.<PieChart.Data>observableArrayList(); 147 for (int i = 0; i < 4; i++) { 148 data.add(new PieChart.Data("Data item " + i, 50)); 149 } 150 PieChart chart = new PieChart(data); 151 chart.setTitle("PieChart"); 152 chart.setStyle("-fx-border-color: darkgray;"); 153 return chart; 154 } 155 } 156 }