functional/ControlsTests/src/javafx/scene/control/test/chart/apps/NewLineChartApp.java

Print this page




  81 
  82         //LineChart to be tested.
  83         LineChart testedLineChart;
  84         NumberAxis axis1;
  85         NumberAxis axis2;
  86         TabPaneWithControl pane;
  87 
  88         public LineChartScene() {
  89             super("LineChart", 1300, 800);
  90         }
  91 
  92         @Override
  93         final protected void prepareScene() {
  94             Utils.addBrowser(this);
  95 
  96             axis1 = new NumberAxis(0, 100, 10);
  97             axis2 = new NumberAxis(0, 100, 10);
  98             testedLineChart = getNewChart();
  99             testedLineChart.setId(TESTED_CHART_ID);
 100 
 101             Button hardResetButton = ButtonBuilder.create().id(HARD_RESET_BUTTON_ID).text("Hard reset").build();

 102             hardResetButton.setOnAction(new EventHandler<ActionEvent>() {
 103                 public void handle(ActionEvent t) {
 104                     HBox hb = (HBox) getRoot();
 105                     hb.getChildren().clear();
 106                     prepareMainSceneStructure();
 107                     prepareScene();
 108                 }
 109             });
 110 
 111             Button softResetButton = ButtonBuilder.create().id(SOFT_RESET_BUTTON_ID).text("Soft reset").build();

 112             softResetButton.setOnAction(new EventHandler<ActionEvent>() {
 113                 public void handle(ActionEvent t) {
 114                     //throw new UnsupportedOperationException("Not supported yet.");
 115                 }
 116             });
 117 
 118             HBox resetButtonsHBox = new HBox();
 119             resetButtonsHBox.getChildren().addAll(hardResetButton, softResetButton);
 120 
 121             VBox vb = new VBox(5);
 122             vb.getChildren().addAll(resetButtonsHBox, getAddLineHBox(), getAddPointToDataDialog(), getRemoveDataDialog(), getRemovePointFromDataDialog());
 123 
 124             pane = getPaneFor(testedLineChart, CHART_TAB_NAME, axis1, AXIS_1_TAB_NAME, axis2, AXIS_2_TAB_NAME);
 125 
 126             setTestedControlContainerSize(500, 500);
 127             setTestedControl(testedLineChart);
 128             setPropertiesContent(pane);
 129             setControllersContent(vb);
 130         }
 131 
 132         public HBox getAddPointToDataDialog() {
 133             HBox hb = new HBox();
 134 
 135             Label lb1 = new Label("To area");
 136             final TextField tf1 = TextFieldBuilder.create().text("0").prefWidth(50).id(ADD_LINE_POS_TEXT_FIELD_ID).build();


 137 
 138             Label lb2 = new Label("to index");
 139             final TextField tf2 = TextFieldBuilder.create().text("0").prefWidth(50).id(ADD_INDEX_TEXT_FIELD_ID).build();


 140 
 141             Label lb3 = new Label("value");
 142             final TextField tf3 = TextFieldBuilder.create().text("0").prefWidth(50).id(ADD_VALUE_TEXT_FIELD_ID).build();


 143 
 144             Button bt = ButtonBuilder.create().text("add point!").id(REMOVE_BUTTON_ID).build();

 145             bt.setOnAction(new EventHandler() {
 146                 public void handle(Event t) {
 147                     int area = Integer.parseInt(tf1.getText());
 148                     int point = Integer.parseInt(tf2.getText());
 149                     double value = Double.parseDouble(tf3.getText());
 150 
 151                     XYChart.Data newData = new XYChart.Data();
 152                     newData.setXValue((((Double) ((XYChart.Data) (((XYChart.Series) testedLineChart.getData().get(area)).getData().get(point))).getXValue()) + ((Double) ((XYChart.Data) (((XYChart.Series) testedLineChart.getData().get(area)).getData().get(point - 1))).getXValue())) / 2);
 153                     newData.setYValue(value);
 154 
 155                     ((XYChart.Series) testedLineChart.getData().get(area)).getData().add(point, newData);
 156                 }
 157             });
 158             hb.getChildren().addAll(lb1, tf1, lb2, tf2, lb3, tf3, bt);
 159             return hb;
 160         }
 161 
 162         public HBox getRemovePointFromDataDialog() {
 163             HBox hb = new HBox();
 164 
 165             Label lb1 = new Label("From area");
 166             final TextField tf1 = TextFieldBuilder.create().text("0").prefWidth(50).id(REMOVE_LINE_FROM_POS_TEXT_FIELD_ID).build();


 167 
 168             Label lb2 = new Label("From index");
 169             final TextField tf2 = TextFieldBuilder.create().text("0").prefWidth(50).id(REMOVE_INDEX_TEXT_FIELD_ID).build();


 170 
 171             Button bt = ButtonBuilder.create().text("remove point!").id(REMOVE_BUTTON_ID).build();

 172             bt.setOnAction(new EventHandler() {
 173                 public void handle(Event t) {
 174                     int area = Integer.parseInt(tf1.getText());
 175                     int point = Integer.parseInt(tf2.getText());
 176                     ((XYChart.Series) testedLineChart.getData().get(area)).getData().remove(point);
 177                 }
 178             });
 179             hb.getChildren().addAll(lb1, tf1, lb2, tf2, bt);
 180             return hb;
 181         }
 182 
 183         public HBox getRemoveDataDialog() {
 184             HBox hb = new HBox();
 185             Label lb = new Label("From index");
 186             final TextField tf = TextFieldBuilder.create().text("0").prefWidth(50).id(REMOVE_ITEM_POS_TEXT_FIELD_ID).build();
 187             Button bt = ButtonBuilder.create().text("remove line!").id(REMOVE_BUTTON_ID).build();



 188             bt.setOnAction(new EventHandler() {
 189                 public void handle(Event t) {
 190                     int index = Integer.parseInt(tf.getText());
 191                     testedLineChart.getData().remove(index);
 192                 }
 193             });
 194             hb.getChildren().addAll(lb, tf, bt);
 195             return hb;
 196         }
 197 
 198         public HBox getAddLineHBox() {
 199             HBox hb = new HBox();
 200             Label lb = new Label("Add series named ");
 201             final TextField tf = TextFieldBuilder.create().prefWidth(50).id(ADDED_SERIES_NAME_TEXTFIELD_ID).build();


 202 
 203             Label minLabel = new Label(" minX ");
 204             final TextField minText = TextFieldBuilder.create().prefWidth(50).id(ADDED_SERIES_MIN_VALUE_TEXTFIELD_ID).build();


 205 
 206             Label maxLabel = new Label(" maxX ");
 207             final TextField maxText = TextFieldBuilder.create().prefWidth(50).id(ADDED_SERIES_MAX_VALUE_TEXTFIELD_ID).build();


 208 
 209             Label amountLabel = new Label(" with ");
 210             final TextField amountText = TextFieldBuilder.create().prefWidth(50).id(ADDED_SERIES_DOTS_COUNT_TEXTFIELD_ID).build();


 211 
 212             Button bt = ButtonBuilder.create().text(" points add!").id(ADD_SERIES_COMMAND_BUTTON_ID).build();

 213             bt.setOnAction(new EventHandler() {
 214                 public void handle(Event t) {
 215                     String serieName = tf.getText();
 216                     double min = Double.parseDouble(minText.getText());
 217                     double max = Double.parseDouble(maxText.getText());
 218                     int amount = Integer.parseInt(amountText.getText());
 219 
 220                     ObservableList list = FXCollections.observableArrayList();
 221 
 222                     for (int i = 0; i < amount; i++) {
 223                         XYChart.Data newData = new XYChart.Data();
 224                         newData.setXValue(new Random().nextDouble() * (max - min) + min);
 225                         newData.setYValue(new Random().nextDouble() * (max - min) + min);
 226                         list.add(newData);
 227                     }
 228                     Object[] array = list.toArray();
 229                     Arrays.sort(array, new Comparator() {
 230                         public int compare(Object t, Object t1) {
 231                             return (int) Math.round(((Double) ((XYChart.Data) t).getXValue()) - ((Double) ((XYChart.Data) t1).getXValue()));
 232                         }




  81 
  82         //LineChart to be tested.
  83         LineChart testedLineChart;        
  84         NumberAxis axis1;
  85         NumberAxis axis2;
  86         TabPaneWithControl pane;
  87 
  88         public LineChartScene() {
  89             super("LineChart", 1300, 800);
  90         }
  91 
  92         @Override
  93         final protected void prepareScene() {
  94             Utils.addBrowser(this);
  95 
  96             axis1 = new NumberAxis(0, 100, 10);
  97             axis2 = new NumberAxis(0, 100, 10);
  98             testedLineChart = getNewChart();
  99             testedLineChart.setId(TESTED_CHART_ID);
 100 
 101             Button hardResetButton = new Button("Hard reset");

 102             hardResetButton.setId(HARD_RESET_BUTTON_ID);

 103             hardResetButton.setOnAction(new EventHandler<ActionEvent>() {
 104                 public void handle(ActionEvent t) {
 105                     HBox hb = (HBox) getRoot();
 106                     hb.getChildren().clear();
 107                     prepareMainSceneStructure();
 108                     prepareScene();
 109                 }
 110             });
 111 
 112             Button softResetButton = new Button("Soft reset");

 113             softResetButton.setId(SOFT_RESET_BUTTON_ID);

 114             softResetButton.setOnAction(new EventHandler<ActionEvent>() {
 115                 public void handle(ActionEvent t) {
 116                     //throw new UnsupportedOperationException("Not supported yet.");
 117                 }
 118             });
 119 
 120             HBox resetButtonsHBox = new HBox();
 121             resetButtonsHBox.getChildren().addAll(hardResetButton, softResetButton);
 122 
 123             VBox vb = new VBox(5);
 124             vb.getChildren().addAll(resetButtonsHBox, getAddLineHBox(), getAddPointToDataDialog(), getRemoveDataDialog(), getRemovePointFromDataDialog());
 125 
 126             pane = getPaneFor(testedLineChart, CHART_TAB_NAME, axis1, AXIS_1_TAB_NAME, axis2, AXIS_2_TAB_NAME);
 127 
 128             setTestedControlContainerSize(500, 500);
 129             setTestedControl(testedLineChart);
 130             setPropertiesContent(pane);
 131             setControllersContent(vb);
 132         }
 133 
 134         public HBox getAddPointToDataDialog() {
 135             HBox hb = new HBox();
 136 
 137             Label lb1 = new Label("To area");
 138             final TextField tf1 = new TextField("0");

 139             tf1.setPrefWidth(50);

 140             tf1.setId(ADD_LINE_POS_TEXT_FIELD_ID);

 141 
 142             Label lb2 = new Label("to index");
 143             final TextField tf2 = new TextField("0");

 144             tf2.setPrefWidth(50);

 145             tf2.setId(ADD_INDEX_TEXT_FIELD_ID);

 146 
 147             Label lb3 = new Label("value");
 148             final TextField tf3 = new TextField("0");

 149             tf3.setPrefWidth(50);

 150             tf3.setId(ADD_VALUE_TEXT_FIELD_ID);

 151 
 152             Button bt = new Button("add point!");

 153             bt.setId(REMOVE_BUTTON_ID);

 154             bt.setOnAction(new EventHandler() {
 155                 public void handle(Event t) {
 156                     int area = Integer.parseInt(tf1.getText());
 157                     int point = Integer.parseInt(tf2.getText());
 158                     double value = Double.parseDouble(tf3.getText());
 159 
 160                     XYChart.Data newData = new XYChart.Data();
 161                     newData.setXValue((((Double) ((XYChart.Data) (((XYChart.Series) testedLineChart.getData().get(area)).getData().get(point))).getXValue()) + ((Double) ((XYChart.Data) (((XYChart.Series) testedLineChart.getData().get(area)).getData().get(point - 1))).getXValue())) / 2);
 162                     newData.setYValue(value);
 163 
 164                     ((XYChart.Series) testedLineChart.getData().get(area)).getData().add(point, newData);
 165                 }
 166             });
 167             hb.getChildren().addAll(lb1, tf1, lb2, tf2, lb3, tf3, bt);
 168             return hb;
 169         }
 170 
 171         public HBox getRemovePointFromDataDialog() {
 172             HBox hb = new HBox();
 173 
 174             Label lb1 = new Label("From area");
 175             final TextField tf1 = new TextField("0");

 176             tf1.setPrefWidth(50);

 177             tf1.setId(REMOVE_LINE_FROM_POS_TEXT_FIELD_ID);

 178 
 179             Label lb2 = new Label("From index");
 180             final TextField tf2 = new TextField("0");

 181             tf2.setPrefWidth(50);

 182             tf2.setId(REMOVE_INDEX_TEXT_FIELD_ID);

 183 
 184             Button bt = new Button("remove point!");

 185             bt.setId(REMOVE_BUTTON_ID);

 186             bt.setOnAction(new EventHandler() {
 187                 public void handle(Event t) {
 188                     int area = Integer.parseInt(tf1.getText());
 189                     int point = Integer.parseInt(tf2.getText());
 190                     ((XYChart.Series) testedLineChart.getData().get(area)).getData().remove(point);
 191                 }
 192             });
 193             hb.getChildren().addAll(lb1, tf1, lb2, tf2, bt);
 194             return hb;
 195         }
 196 
 197         public HBox getRemoveDataDialog() {
 198             HBox hb = new HBox();
 199             Label lb = new Label("From index");
 200             final TextField tf = new TextField("0");

 201             tf.setPrefWidth(50);

 202             tf.setId(REMOVE_ITEM_POS_TEXT_FIELD_ID);

 203             Button bt = new Button("remove line!");

 204             bt.setId(REMOVE_BUTTON_ID);

 205             bt.setOnAction(new EventHandler() {
 206                 public void handle(Event t) {
 207                     int index = Integer.parseInt(tf.getText());
 208                     testedLineChart.getData().remove(index);
 209                 }
 210             });
 211             hb.getChildren().addAll(lb, tf, bt);
 212             return hb;
 213         }
 214 
 215         public HBox getAddLineHBox() {
 216             HBox hb = new HBox();
 217             Label lb = new Label("Add series named ");
 218             final TextField tf = new TextField();

 219             tf.setPrefWidth(50);

 220             tf.setId(ADDED_SERIES_NAME_TEXTFIELD_ID);

 221 
 222             Label minLabel = new Label(" minX ");
 223             final TextField minText = new TextField();

 224             minText.setPrefWidth(50);

 225             minText.setId(ADDED_SERIES_MIN_VALUE_TEXTFIELD_ID);

 226 
 227             Label maxLabel = new Label(" maxX ");
 228             final TextField maxText = new TextField();

 229             maxText.setPrefWidth(50);

 230             maxText.setId(ADDED_SERIES_MAX_VALUE_TEXTFIELD_ID);

 231 
 232             Label amountLabel = new Label(" with ");
 233             final TextField amountText = new TextField();

 234             amountText.setPrefWidth(50);

 235             amountText.setId(ADDED_SERIES_DOTS_COUNT_TEXTFIELD_ID);

 236 
 237             Button bt = new Button(" points add!");

 238             bt.setId(ADD_SERIES_COMMAND_BUTTON_ID);

 239             bt.setOnAction(new EventHandler() {
 240                 public void handle(Event t) {
 241                     String serieName = tf.getText();
 242                     double min = Double.parseDouble(minText.getText());
 243                     double max = Double.parseDouble(maxText.getText());
 244                     int amount = Integer.parseInt(amountText.getText());
 245 
 246                     ObservableList list = FXCollections.observableArrayList();
 247 
 248                     for (int i = 0; i < amount; i++) {
 249                         XYChart.Data newData = new XYChart.Data();
 250                         newData.setXValue(new Random().nextDouble() * (max - min) + min);
 251                         newData.setYValue(new Random().nextDouble() * (max - min) + min);
 252                         list.add(newData);
 253                     }
 254                     Object[] array = list.toArray();
 255                     Arrays.sort(array, new Comparator() {
 256                         public int compare(Object t, Object t1) {
 257                             return (int) Math.round(((Double) ((XYChart.Data) t).getXValue()) - ((Double) ((XYChart.Data) t1).getXValue()));
 258                         }