-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathFormsDataUnit.java
More file actions
174 lines (151 loc) · 4.36 KB
/
FormsDataUnit.java
File metadata and controls
174 lines (151 loc) · 4.36 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
package loggerForms;
import GPS.GpsData;
import PamUtils.PamCalendar;
import PamguardMVC.PamDataUnit;
import generalDatabase.SQLTypes;
import loggerForms.controlDescriptions.ControlDescription;
/**
*
* @author Graham Weatherup
*
* ID
* UTC
* UTCmillisecond
* PCLocalTime
*
*/
public class FormsDataUnit extends PamDataUnit {
private LoggerForm loggerForm;
public static final int currentXMLFormat = 1;
/**
* This Array is based around the inputControlDescriptions ArrayList in formDescriptions.
* is is of same length and order matches
*/
private Object[] formData;
private FormDescription formDescription;
private GpsData formOriginLatLong;
/**
* Constructor for a form data unit.
* @param loggerForm
* @param timeMilliseconds
* @param formDescription
* @param formData
*/
public FormsDataUnit(LoggerForm loggerForm,long timeMilliseconds,FormDescription formDescription, Object[] formData) {
super(timeMilliseconds);
this.loggerForm=loggerForm;
this.formDescription = formDescription;
this.formData = formData;
}
/**
* This formData Array is based around the inputControlDescriptions ArrayList in formDescriptions. is is of same length and order matches
* @return the formData
*/
public Object[] getFormData() {
return formData;
}
public LoggerForm getLoggerForm() {
return loggerForm;
}
/**
* @return the formDescription
*/
public FormDescription getFormDescription() {
return formDescription;
}
/**
* used for updating data units(editing forms)
*/
public void setFormsData(LoggerForm loggerForm,Object[] formData) {
this.loggerForm=loggerForm;
this.formData=formData;
this.updateDataUnit(PamCalendar.getTimeInMillis());
}
@Override
public GpsData getOriginLatLong(boolean recalculate) {
/**
* Need to do something a bit different here since Logger form data is generally
* not associated with a hydrophone (though that may change in the future).
* All we really want is the primary origin method, which is either GPS data
* or static data and then get the value. mostly people will want the GPS position
* for the time of the logger data, though really we should make a much better way
* of doing this, including offsets from GPS, options to use the hydrophones if
* we want to as a reference, etc.
*/
if (recalculate || formOriginLatLong == null) {
if (formDescription != null) {
formOriginLatLong = formDescription.getOriginLatLong(this);
}
}
return formOriginLatLong;
}
@Override
public long getTimeMilliseconds() {
Long time = findTimeValue(PropertyTypes.STARTTIME);
if (time != null) {
return time;
}
return super.getTimeMilliseconds();
}
/**
* Find one of the time property controls and get its value.
* @param timeProperty
* @return
*/
public Long findTimeValue(PropertyTypes timeProperty) {
if (formData == null) {
return null;
}
PropertyDescription prop = formDescription.findProperty(timeProperty);
if (prop == null) {
return null;
}
String ctrlTitle = prop.getItemInformation().getStringProperty("Title");
if (ctrlTitle == null) {
return null;
}
int timeControlIndex = formDescription.findInputControlByName(ctrlTitle);
if (timeControlIndex < 0 || timeControlIndex >= formData.length) {
return null;
}
Object timeObj = formData[timeControlIndex];
/*
* this should have found the time contol in the form of a string from the database.
* try to unpack it.
*/
Long timeMillis = SQLTypes.millisFromTimeStamp(timeObj);
return timeMillis;
}
/**
* find a correctly set property value for the end time (if set).
* @return
*/
public Long getSetEndTime() {
return findTimeValue(PropertyTypes.ENDTIME);
}
@Override
public long getEndTimeInMilliseconds() {
Long time = findTimeValue(PropertyTypes.ENDTIME);
if (time != null) {
return time;
}
return super.getEndTimeInMilliseconds();
}
@Override
public String getSummaryString() {
String str = String.format("<html><b>%s</b>", formDescription.getFormNiceName());
Object[] data = getFormData();
int iDat = 0;
for (ControlDescription cd:formDescription.getInputControlDescriptions()) {
if (data[iDat] == null) {
str += String.format("<p>%s: -", cd.getTitle());
}
else {
str += String.format("<p>%s: %s", cd.getTitle(), data[iDat].toString());
}
iDat++;
}
str += "</html>";
return str;
}
}