-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathTDControlFX.java
More file actions
414 lines (346 loc) · 12.5 KB
/
TDControlFX.java
File metadata and controls
414 lines (346 loc) · 12.5 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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
package dataPlotsFX;
import java.io.Serializable;
import java.util.ArrayList;
import PamController.PamController;
import PamguardMVC.PamDataBlock;
import PamguardMVC.PamDataUnit;
import PamguardMVC.PamObservable;
import PamguardMVC.PamObserverAdapter;
import PamguardMVC.PamRawDataBlock;
import dataPlotsFX.data.TDDataInfoFX;
import dataPlotsFX.data.TDDataProviderFX;
import dataPlotsFX.data.TDDataProviderRegisterFX;
import dataPlotsFX.layout.TDDisplayFX;
import dataPlotsFX.layout.TDGraphFX;
import detectiongrouplocaliser.DetectionGroupSummary;
import javafx.application.Platform;
import javafx.scene.layout.Region;
import pamViewFX.fxNodes.internalNode.PamInternalPane;
import userDisplayFX.UserDisplayControlFX;
import userDisplayFX.UserDisplayNodeFX;
import userDisplayFX.UserDisplayNodeParams;
/**
*
* The controller for the display if the main PAMGuard GUI is in JavaFX mode.
*
* @author Jamie Macaulay
*
*/
public class TDControlFX extends TDControl implements UserDisplayNodeFX {
/**
* The control FX.
*/
private TDControlFX tdControlfx;
/**
* Checks for incoming data.
*/
private DataObserver dataObserver;
/**
* Reference to the display controller.
*/
private TDDisplayController tdDisplayController;
/**
*
* The internal frame holding the display.
*/
private PamInternalPane internalFrame;
/**
* Constructor for the TDControlFX.
* @param tdDisplayController - reference to the display controller.
* @param uniqueDisplayName - the unique display name
*/
public TDControlFX(TDDisplayController tdDisplayController, String uniqueDisplayName){
super(uniqueDisplayName);
this.setUniqueName(uniqueDisplayName);
this.tdDisplayController=tdDisplayController;
tdControlfx=this;
// this.getTdParameters().print(); //PRINT
create();
}
/**
* Create the vital components for the display.
*/
private void create(){
dataObserver = new DataObserver();
}
@Override
public Region getNode() {
if (tdMainDisplay==null) {
tdMainDisplay=new TDDisplayFX(tdControlfx);
dataModelToDisplay(); //make sure data model shows the display- otherwise on the
//next notification the display will be overwritten with parent data blocks form the
//data model.
}
return tdMainDisplay;
}
public double getScrollableRange(){
return tdMainDisplay.getTDParams().scrollableTimeRange;
}
public double getVisibleRange(){
return tdMainDisplay.getTDParams().visibleTimeRange;
}
public void scrollDisplayEnd(final long milliSeconds) {
if (tdMainDisplay!=null){
tdMainDisplay.scrollDisplayEnd(milliSeconds);
}
}
/**
* Get all parent data blocks- that is parent data blocks currently in the
* process. The first data block in the list is the main parent data block. The
* rest are multiplex data blocks. (For this module this difference is
* irrelevant).
*
* @return list of PamDataBlocks for the display. Element(0) might be null.
*/
@SuppressWarnings("rawtypes")
private ArrayList<PamDataBlock> getParentDataBlocks(){
// so if the process has changed need to check that the display has been set up properly.
ArrayList<PamDataBlock> dataBlocks=new ArrayList<PamDataBlock>();
PamDataBlock dataBlock=this.tdDisplayController.getUserDisplayProcess().getParentDataBlock();
if (TDDataProviderRegisterFX.getInstance().findDataProvider(dataBlock)!=null) dataBlocks.add(dataBlock);
if (dataBlock!=null) {
// System.out.println("TDControldFX: parent datablock "+dataBlock.getDataName());
}
else{
// System.out.println("TDControldFX: parent datablock null");
return dataBlocks;
}
for (int i=0; i<tdDisplayController.getUserDisplayProcess().getNumMuiltiplexDataBlocks(); i++){
dataBlock=this.tdDisplayController.getUserDisplayProcess().getMuiltiplexDataBlock(i);
if (TDDataProviderRegisterFX.getInstance().findDataProvider(dataBlock)!=null){
dataBlocks.add(dataBlock);
}
}
return dataBlocks;
}
/**
* Get all data blocks which are currently being displayed.
* @return all TDDataInfoFX (which wrap a PamDataBlock) which are currently being displayed.
*/
private ArrayList<TDDataInfoFX> getDisplayTDDataInfos(){
ArrayList<TDDataInfoFX> dataInfoList=new ArrayList<TDDataInfoFX>();
ArrayList<TDDataInfoFX> dataInfos;
for (int i=0; i<this.getTDDisplay().getTDGraphs().size(); i++){
dataInfos=this.getTDDisplay().getTDGraphs().get(i).getDataList();
for (int j=0; j<dataInfos.size(); j++){
dataInfoList.add(dataInfos.get(j));
}
}
return dataInfoList;
}
/**
* Get currently displayed data blocks in the display and set them as the parent
* data blocks in the display process.
*/
@Override
public void dataModelToDisplay() {
//
// System.out.println("TDControlFX: dataModelToDisplay: " + tdDisplayController.allowProcessNotify);
if (this.tdMainDisplay==null) return;
/**
* BUG: 13/07/2015- needed to add line below to stop weird loop which meant a node in the data model would connect,
* disconnect and then connect.
*/
if (!tdDisplayController.allowProcessNotify) return;
ArrayList<TDDataInfoFX> displayDataBlocks=getDisplayTDDataInfos();
// for (int i=0; i<displayDataBlocks.size(); i++){
// System.out.println("TDControlFX:+ Current display datablocks: "+displayDataBlocks.get(i).getDataName());
// }
tdDisplayController.setParentDataBlocks(displayDataBlocks);
// PamController.getInstance().notifyModelChanged(PamControllerInterface.UPDATE_DATA_MODEL);
}
/**
* Set the display to show data blocks set in the data model- i.e. show it's
* parent data blocks. Iterates through all TDDataInfoFX (a PamDataBlock
* wrapper) currently displayed. If any TDDataInfo does not have a data block in
* the displayDataBlocks it is deleted. If any PamDataBlock in the list does not
* have a corresponding TDDataInfoFX then a new TDDataINfoFX is created and
* added to a new TDGraphFX in the main display.
*/
protected void displayToDataModel(ArrayList<PamDataBlock> displayDataBlocks){
// System.out.println("TDControlFX: displayToDataModel");
// System.out.println("*****************");
// for (int i=0; i<displayDataBlocks.size(); i++) {
// System.out.println(displayDataBlocks.get(i).getDataName());
// }
// System.out.println("*****************");
//remove any TDDataInfos which are not present in the data block list
boolean found=false;
ArrayList<TDDataInfoFX> dataInfos=getDisplayTDDataInfos();
for (int i=0;i<dataInfos.size(); i++){
found=false;
for (int j=0; j<displayDataBlocks.size(); j++){
if (dataInfos.get(i).getDataBlock()==displayDataBlocks.get(j)){
found=true;
continue;
}
}
if (!found){
removeTDDataInfo(dataInfos.get(i));
}
}
//now add any data blocks which are not present in TDDataInfo
for (int i=0; i<displayDataBlocks.size(); i++){
found=false;
for (int j=0; j<dataInfos.size(); j++){
if (dataInfos.get(j).getDataBlock()==displayDataBlocks.get(i)){
found=true;
continue;
}
}
if (!found) addDataBlock(displayDataBlocks.get(i));
}
// tdDisplayController.printParentDataBlocks();
// System.out.println("TDControlFX: displayToDataModel: finished: " + getParentDataBlocks().size());
// for (int i=0; i<tdMainDisplay.getTDGraphs().size(); i++) {
// tdMainDisplay.getTDGraphs().get(i).printDataInfos();
// }
}
/**
* Called whenever process settings have changed
*/
public void processSettingsChanged() {
//make sure display shows correct data blocks
if (tdMainDisplay!=null) displayToDataModel(getParentDataBlocks());
}
/**
* The data observer monitors only the raw data source in real time
* so that scrolling can take place. Need to set up a different
* set of observers to monitor data, primarily to set correct
* data history requirements.
* @author Doug Gillespie and Jamie Macaulay
*
*/
private class DataObserver extends PamObserverAdapter {
@Override
public long getRequiredDataHistory(PamObservable o, Object arg) {
if (PamRawDataBlock.class == o.getClass()) {
return 0;
}
//System.out.println("TDControlFX: Get required data history: "+ Math.max(getScrollableRange(), getVisibleRange()));
long nomTime = (long) Math.max(getScrollableRange(), getVisibleRange());
return nomTime;
}
@Override
public void addData(PamObservable o, PamDataUnit arg) {
// scrollDisplayEnd(arg.getTimeMilliseconds());
// System.out.println("Observer: " + o);
}
@Override
public String getObserverName() {
return tdControlfx.getUniqueName();
}
@Override
public void masterClockUpdate(long milliSeconds, long sampleNumber) {
// System.out.println("TDControlFX: masterClockUpdate");
Platform.runLater(() -> {
scrollDisplayEnd(milliSeconds);
});
}
}
/**
* Get the data observer- monitors incoming real time data an updates graphs.
* @return data observer
*/
@Override
public DataObserver getDataObserver() {
return dataObserver;
}
@Override
public void openNode() {
// TODO Auto-generated method stub
}
@Override
public void closeNode() {
}
@Override
public void notifyModelChanged(int changeType) {
if (tdMainDisplay!=null){
tdMainDisplay.notifyModelChanged(changeType);
}
}
/**
* In real time mode check if PAMGUARD is paused.
* @return true if paused.
*/
@Override
public boolean isPaused(){
if (PamController.getInstance().getPamStatus()==PamController.PAM_RUNNING) return false;
else return true;
}
@Override
public boolean requestNodeSettingsPane() {
/**
* Open all hiding tabs to show user where everything is.
*/
//show the control pane.
tdMainDisplay.showControlPane(true);
//expand all settings panes.
for (int i=0; i<tdMainDisplay.getTDGraphs().size(); i++){
tdMainDisplay.getTDGraphs().get(i).showSettingsPane(true);
tdMainDisplay.getTDGraphs().get(i).showAxisSettingsPane(true);
}
return true;
}
@Override
public boolean isStaticDisplay() {
return false;
}
@Override
public boolean isResizeableDisplay() {
return true;
}
@Override
public String getName() {
return "Time Base Display";
}
@Override
public boolean isMinorDisplay() {
// these are generally smaller minor displays- only used for automatic resize.
return false;
}
/**
* Called just before settings are saved. Will have to go
* through all the graphs and get them to provide updated settings
* information to add to this since it's not kept up to date on the fly.
* @return object to serialise.
*/
@Override
protected Serializable prepareSerialisedSettings() {
super.prepareSerialisedSettings();
//prepare the serialised settings.
// System.out.println("TDControlFX: Saving the position of the display: "
// + internalFrame.getInternalRegion().getLayoutX() + " " + internalFrame.getInternalRegion().getLayoutY());
//need to use the parent node because inside an internal pane.
this.getTdParameters().displayProviderParams.positionX=internalFrame.getInternalRegion().getLayoutX();
this.getTdParameters().displayProviderParams.positionY=internalFrame.getInternalRegion().getLayoutY();
this.getTdParameters().displayProviderParams.sizeX=internalFrame.getInternalRegion().getWidth();
this.getTdParameters().displayProviderParams.sizeY=internalFrame.getInternalRegion().getHeight();
return this.getTdParameters();
}
@Override
public UserDisplayNodeParams getDisplayParams() {
//the display provider params are stored in the settings.
return this.getTdParameters().displayProviderParams;
}
@Override
public void setFrameHolder(PamInternalPane internalFrame) {
this.internalFrame=internalFrame;
}
@Override
public void newSelectedDetectionGroup(DetectionGroupSummary detectionGroup, TDGraphFX tdGraph) {
// System.out.println("New selected detection group: " + detectionGroup);
tdDisplayController.getDisplayDataBlock().clearAll();
if (detectionGroup==null || detectionGroup.getDataList().size()<=0) return;
// System.out.println("Add pam data: " + detectionGroup + " " + tdDisplayController.getDisplayDataBlock().countObservers());
// for (int i=0; i<tdDisplayController.getDisplayDataBlock().countObservers() ; i++) {
// System.out.println("Observer : " + tdDisplayController.getDisplayDataBlock().getPamObserver(i));
// }
tdDisplayController.getDisplayDataBlock().addPamData(detectionGroup.getDataList().get(detectionGroup.getFocusedIndex()));
if (isViewer()) tdDisplayController.getDisplayDataBlock().notifyNornalObservers(detectionGroup.getDataList().get(detectionGroup.getFocusedIndex()));
}
@Override
public UserDisplayControlFX getUserDisplayControl() {
return this.tdDisplayController;
}
}