-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCombinedSceneList.java
executable file
·260 lines (227 loc) · 9.46 KB
/
CombinedSceneList.java
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
// CombinedSceneList.java implements a class to track the list of scenes for
// a dataset that is composed of multiple other datasets.
//
// Implementation Notes:
// - This class keeps synchronized with the included scene lists by
// becoming a list data listener of those scene lists. When a scene is
// added or removed from a related list, this class receives a notification
// and does the proper thing to keep the combined list in agreement.
// - Even when the combined dataset is shown, the add, remove, and order
// methods in this class operate by manipulating the correct related
// scene list and then update the list for the combined scene list in
// the list data listener methods.
//--------------------------------------------------------------------------
import javax.swing.DefaultListModel;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
public class CombinedSceneList extends SceneList implements ListDataListener
{
private imgViewer applet; // reference to main applet
private SceneList[] relatedSceneLists; // array of scene lists from the
// the contained datasets
private boolean ignoreRemoves; // flag to ignore remove messages in
// the intervalRemoved method
// Constructor for the CombinedSceneList
//--------------------------------------
CombinedSceneList(imgViewer applet, Sensor sensor,
SceneList[] relatedSceneLists)
{
super(applet, sensor);
this.applet = applet;
this.relatedSceneLists = relatedSceneLists;
ignoreRemoves = false;
// request to be notified of changes in related scene lists
for (int i = 0; i < relatedSceneLists.length; i++)
relatedSceneLists[i].addListDataListener(this);
}
// helper method to return the scene list that a scene belongs to
//---------------------------------------------------------------
private SceneList findSceneList(Metadata scene)
{
Sensor sceneSensor = scene.getSensor();
// find the correct related list
SceneList relatedList = null;
for (int i = 0; i < relatedSceneLists.length; i++)
{
if (sceneSensor == relatedSceneLists[i].sensor)
{
relatedList = relatedSceneLists[i];
break;
}
}
return relatedList;
}
// Add a specific scene to the scene list
//---------------------------------------
public void add(Metadata scene)
{
// find the correct related scene list
SceneList relatedList = findSceneList(scene);
if (relatedList == null)
return;
// add the scene to the related list, which will notify this class to
// add it to this list
relatedList.add(scene);
// make sure the search limits are kept in sync
if (applet.searchLimitDialog.isSceneListFilterEnabled())
applet.searchLimitDialog.applyFilter();
}
// method to remove the indicated scene from the scene list
//---------------------------------------------------------
public void remove(Metadata scene)
{
// find the correct related scene list
SceneList relatedList = findSceneList(scene);
// remove the scene from the related list, which will notify this
// class to remove it from this list
relatedList.remove(scene);
// make sure the search limits are kept in sync
if (applet.searchLimitDialog.isSceneListFilterEnabled())
applet.searchLimitDialog.applyFilter();
}
// method to remove ALL scenes from the scene list
//------------------------------------------------
public void clear()
{
// similar to the order function but we know everything was removed
super.clear();
for (int i = 0; i < relatedSceneLists.length; i++)
relatedSceneLists[i].list.removeAllElements();
}
// Order the contents of the scene list
//-------------------------------------
public void order()
{
super.order();
if (list.size() == 0)
{
// no scenes left in the list, so remove all the scenes from the
// related lists
for (int i = 0; i < relatedSceneLists.length; i++)
relatedSceneLists[i].list.removeAllElements();
}
else
{
// flag that the intervalRemoved method should ignore messages.
// This is needed to prevent things from getting out of sync if
// things are ordering results in only some of the scenes being
// ordered
ignoreRemoves = true;
// only part of the scenes could be ordered, so remove the scenes
// from the related lists that no longer are in the combined list
for (int i = 0; i < relatedSceneLists.length; i++)
{
DefaultListModel relatedList = relatedSceneLists[i].list;
for (int j = relatedList.size() - 1; j >= 0; j--)
{
Metadata scene = (Metadata)relatedList.elementAt(j);
int index = find(scene);
if (index == -1)
{
relatedList.removeElementAt(j);
}
}
}
// the intervalRemoved method should no longer ignore removes
ignoreRemoves = false;
}
// update filter if needed
if (applet.searchLimitDialog.isSceneListFilterEnabled())
applet.searchLimitDialog.applyFilter();
}
// method to return whether the scene list contains scenes with gaps
// in the data (i.e. Landsat 7 SLC-off)
//------------------------------------------------------------------
public boolean containsGapData()
{
// if any of the scenes in the list have gaps, return true
for (int i = list.size() - 1; i >= 0; i--)
{
Metadata scene = (Metadata)list.elementAt(i);
if (scene.getSensor().dataHasGaps)
return true;
}
return false;
}
// method to handle the event of data being added to a related list
//-----------------------------------------------------------------
public void intervalAdded(ListDataEvent event)
{
DefaultListModel sourceList = (DefaultListModel)event.getSource();
int startIndex = event.getIndex0();
int endIndex = event.getIndex1();
// any time something is added, the restore option is no longer
// available (Note make sure to set this before manipulating the list)
restoreEnabledFlag = false;
// add all the scenes added to the related list to the combined list
for (int i = startIndex; i <= endIndex; i++)
{
Metadata scene = (Metadata)sourceList.elementAt(i);
list.addElement(new Metadata(scene));
}
}
// method to handle the event of data being removed from a related list
//---------------------------------------------------------------------
public void intervalRemoved(ListDataEvent event)
{
// do not process removes if they are currently being ignored since
// the data has already been removed by the order method
if (ignoreRemoves)
return;
DefaultListModel sourceList = (DefaultListModel)event.getSource();
Sensor sensor = null;
SceneList relatedList = null;
// find the correct scene list
for (int i = 0; i < relatedSceneLists.length; i++)
{
if (sourceList == relatedSceneLists[i].list)
{
sensor = relatedSceneLists[i].sensor;
relatedList = relatedSceneLists[i];
break;
}
}
if (sensor != null)
{
// detect when a related list is ordered and enable restore on the
// combined list
if (!restoreEnabledFlag && relatedList.restoreEnabledFlag)
{
// this is the first remove to be received, so save the scene
// list so it can be restored
savedList.removeAllElements();
Object[] listContents = list.toArray();
for (int i = 0; i < listContents.length; i++)
savedList.add(listContents[i]);
restoreEnabledFlag = true;
}
// delete the correct scenes for the sensor from the combined list
int startIndex = event.getIndex0();
int endIndex = event.getIndex1();
int count = 0;
int i = 0;
while (i < list.size())
{
Metadata scene = (Metadata)list.elementAt(i);
if (scene.getSensor() == sensor)
{
if ((count >= startIndex) && (count <= endIndex))
list.removeElementAt(i);
else
i++;
count++;
if (count > endIndex)
break;
}
else
i++;
}
}
}
// method to handle the event of data being changed in a related list
//---------------------------------------------------------------------
public void contentsChanged(ListDataEvent event)
{
/* nothing to do for this event */
}
}