-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonitorController.java
More file actions
354 lines (257 loc) · 10.7 KB
/
Copy pathMonitorController.java
File metadata and controls
354 lines (257 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
package wf.view;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.control.Slider;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.util.StringConverter;
import wf.util.ComboBoxChLabels;
import wf.util.DataHistoHandler;
import wf.util.NiceAxisScale;
public class MonitorController {
@FXML private AnchorPane monitor_ap;
@FXML private AnchorPane bottom_ap;
@FXML private AnchorPane top_ap;
@FXML private Button next_bt;
@FXML private Button previous_bt;
@FXML private Button close_bt;
@FXML private ButtonBar bar_bb;
@FXML private LineChart<Number, Number> chartLineLeft;
@FXML private LineChart<Number, Number> chartLineRight;
@FXML private NumberAxis leftXAxis;
@FXML private NumberAxis leftYAxis;
@FXML private NumberAxis rightXAxis;
@FXML private NumberAxis rightYAxis;
@FXML private ComboBoxChLabels chNumber_cb;
//@FXML private ComboBox<Label> chNumber_cb;
@FXML private GridPane grid1_gr;
@FXML private HBox monitor_hb;
@FXML private Label title_lb;
@FXML private Label chNumber_lb;
@FXML private Label wfNumber_lb;
@FXML private Label next_lb;
@FXML private Label previous_lb;
@FXML private Separator north_sp;
@FXML private Separator south_sp;
@FXML private Slider wfSlider_sl;
@FXML private StackPane lineChartLeftContainer_sp;
@FXML private StackPane lineChartRightContainer_sp;
@FXML private VBox monitor_vb;
private ChangeListener<Number> slider_cl;
private boolean isSliderListenerCreated = false;
private double min;
private double max;
private int dataSize;
private int selectedChannel;
private int size;
private static DataHistoHandler dataHistoHandler = DataHistoHandler.getInstance();
private static NiceAxisScale nas = NiceAxisScale.getInstance();
@FXML
public void initialize() {
initStyle();
initButtons();
initComboBoxes();
initHistograms();
}
@FXML
private void exitAction() {
chNumber_cb.removeCellFactoryButtonCell();
chartLineLeft.getData().clear();
chartLineRight.getData().clear();
wfSlider_sl.valueProperty().removeListener(slider_cl);
monitor_ap.getScene().getWindow().hide();
}
private void initButtons() {
previous_bt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if((wfSlider_sl.getValue() - 1 >= 0)) {
wfSlider_sl.setValue(wfSlider_sl.getValue() - 1);
}
}
});
next_bt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if((wfSlider_sl.getValue() + 1 <= wfSlider_sl.getMax())) {
wfSlider_sl.setValue(wfSlider_sl.getValue() + 1);
}
}
});
}
private void initHistograms() {
chartLineLeft.setLegendVisible(false);
chartLineLeft.setAnimated(false);
leftYAxis.setAutoRanging(false);
leftXAxis.setAutoRanging(true);
chartLineRight.setLegendVisible(false);
chartLineRight.setAnimated(false);
rightYAxis.setAutoRanging(false);
rightXAxis.setAutoRanging(true);
}
public void setChannel() {
chNumber_cb.getSelectionModel().select(dataHistoHandler.getChannelWithData());
chNumber_cb.setCellFactoryButtonCell();
}
private void initComboBoxes() {
chNumber_cb.setMinWidth(80);
chNumber_cb.valueProperty().addListener(new ChangeListener<Label>() {
@Override
public void changed(ObservableValue<? extends Label> observable, Label oldValue, Label newValue) {
if(!newValue.isDisabled()) {
selectedChannel = chNumber_cb.getSelectionModel().getSelectedIndex();
if (newValue != oldValue) {
chartLineLeft.getData().clear();
chartLineRight.getData().clear();
if(wfSlider_sl.getValue() == 0) {
wfNumber_lb.textProperty().setValue("Waveform [0]");
if(dataHistoHandler.getSeriesValues().get(selectedChannel).size() > 0) {
chartLineLeft.getData().add(dataHistoHandler.getSeriesValues().get(selectedChannel).get(0));
setYAxisLeftChart();
}
if(dataHistoHandler.getSeriesValuesProc().get(selectedChannel).size() > 0) {
chartLineRight.getData().add(dataHistoHandler.getSeriesValuesProc().get(selectedChannel).get(0));
setYAxisRightChart();
}
} else {
wfSlider_sl.setValue(0);
}
}
} else {
chNumber_cb.getSelectionModel().select(oldValue);
}
}
});
}
private void setYAxisLeftChart() {
size = dataHistoHandler.getSeriesValues().get(selectedChannel).get((int)wfSlider_sl.getValue()).getData().size();
min = 0;
max = 0;
for(int i = 0; i < size; i++) {
if ( (double) dataHistoHandler.getSeriesValues().get(selectedChannel).get((int)wfSlider_sl.getValue()).getData().get(i).getYValue() > max)
{
max = (double) dataHistoHandler.getSeriesValues().get(selectedChannel).get((int)wfSlider_sl.getValue()).getData().get(i).getYValue();
}
if ( (double) dataHistoHandler.getSeriesValues().get(selectedChannel).get((int)wfSlider_sl.getValue()).getData().get(i).getYValue() < min)
{
min = (double) dataHistoHandler.getSeriesValues().get(selectedChannel).get((int)wfSlider_sl.getValue()).getData().get(i).getYValue();
}
}
nas.setAxisValues(min, max, 10);
leftYAxis.setLowerBound(nas.getNiceMin());
leftYAxis.setUpperBound(nas.getNiceMax());
leftYAxis.setTickUnit(nas.getTickSpacing());
}
private void setYAxisRightChart() {
//uncomment if indipendent axis scaling is required
/*
size = dataHistoHandler.getSeriesValuesProc().get(selectedChannel).get((int)wfSlider_sl.getValue()).getData().size();
min = 0;
max = 0;
for(int i = 0; i < size; i++) {
if ( (double) dataHistoHandler.getSeriesValuesProc().get(selectedChannel).get((int)wfSlider_sl.getValue()).getData().get(i).getYValue() > max)
{
max = (double) dataHistoHandler.getSeriesValuesProc().get(selectedChannel).get((int)wfSlider_sl.getValue()).getData().get(i).getYValue();
}
if ( (double) dataHistoHandler.getSeriesValuesProc().get(selectedChannel).get((int)wfSlider_sl.getValue()).getData().get(i).getYValue() < min)
{
min = (double) dataHistoHandler.getSeriesValuesProc().get(selectedChannel).get((int)wfSlider_sl.getValue()).getData().get(i).getYValue();
}
} */
nas.setAxisValues(min, max, 10);
rightYAxis.setLowerBound(nas.getNiceMin());
rightYAxis.setUpperBound(nas.getNiceMax());
rightYAxis.setTickUnit(nas.getTickSpacing());
}
public void initSlider() {
dataSize = dataHistoHandler.getSeriesValues().get(dataHistoHandler.getChannelWithData()).size();
wfSlider_sl.setMin(1); //dummy value
if(!isSliderListenerCreated) {
slider_cl = new ChangeListener<Number>() {
@Override
public void changed(
ObservableValue<? extends Number> observableValue,
Number oldValue,
Number newValue) {
selectedChannel = chNumber_cb.getSelectionModel().getSelectedIndex();
//wfNumberDisplay_lb.textProperty().setValue(String.valueOf(newValue.intValue()));
wfNumber_lb.textProperty().setValue("Waveform [" + String.valueOf(newValue.intValue() + "]"));
chartLineLeft.getData().clear();
//check if data exists then add to chart
if(dataHistoHandler.getSeriesValues().get(selectedChannel).size() > 0) {
chartLineLeft.getData().add(dataHistoHandler.getSeriesValues().get(selectedChannel).get((int)wfSlider_sl.getValue()));
//lineChart.setTitle("Waveform [" + String.valueOf(wfNumber_cb.getSelectionModel().getSelectedIndex()) + "]");
setYAxisLeftChart();
}
chartLineRight.getData().clear();
//check if data exists then add to chart
if(dataHistoHandler.getSeriesValuesProc().get(selectedChannel).size() > 0) {
chartLineRight.getData().add(dataHistoHandler.getSeriesValuesProc().get(selectedChannel).get((int)wfSlider_sl.getValue()));
setYAxisRightChart();
}
}
};
isSliderListenerCreated = true;
}
wfSlider_sl.valueProperty().addListener(slider_cl);
wfSlider_sl.setMin(0);
wfSlider_sl.setMax(dataSize-1);
wfSlider_sl.setValue(0);
wfSlider_sl.setMinorTickCount(0);
wfSlider_sl.setMajorTickUnit(10);
wfSlider_sl.setSnapToTicks(true);
wfSlider_sl.setShowTickMarks(false);
wfSlider_sl.setShowTickLabels(true);
wfSlider_sl.setLabelFormatter(new StringConverter<Double>() {
@Override
public String toString(Double n) {
if (n == 0) return "0";
if (n == dataSize-1) return String.valueOf(dataSize-1);
//if (n == value) return String.valueOf(value);
return "";
}
@Override
public Double fromString(String s) {
switch (s) {
case "0":
return 0d;
default:
return 3d;
}
}
});
}
private void initStyle() {
chartLineLeft.setId("chart1");
chartLineRight.setId("chart2");
//grid_container_vb.setStyle(" -fx-background-color: FloralWhite;");
monitor_vb.setStyle(" -fx-background-color: FloralWhite;");
monitor_hb.setStyle(" -fx-background-color: FloralWhite;");
next_bt.setId("button_bevel-grey");
previous_bt.setId("button_bevel-grey");
close_bt.setId("button_bevel-grey");
title_lb.setId("appTitle");
chNumber_lb.setId("labelDecoratedNoBkG");
wfNumber_lb.setId("labelDecoratedNoBkG");
top_ap.setId("topLayoutContainer");
bottom_ap.setId("bottomLayoutContainer");
monitor_ap.setId("appBackground");
chNumber_cb.setId("textField3");
lineChartLeftContainer_sp.setStyle("-fx-border-color: gray; -fx-border-width: 1; -fx-background-color: FloralWhite;");
lineChartRightContainer_sp.setStyle("-fx-border-color: gray; -fx-border-width: 1; -fx-background-color: FloralWhite;");
north_sp.setStyle("-fx-border-style: solid; -fx-border-width: 0.1px;");
south_sp.setStyle("-fx-border-style: solid; -fx-border-width: 0.1px;");
}
}