-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHideSceneDialog.java
executable file
·264 lines (225 loc) · 9.04 KB
/
HideSceneDialog.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
261
262
263
264
// HideSceneDialog.java implements a dialog for a more functional scene list
// that the one that fits in the main applet.
//
//---------------------------------------------------------------------------
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.Observable;
import java.util.Observer;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class HideSceneDialog extends JDialog implements WindowListener,
ActionListener, Observer, ListEntryBuilder, ListDataListener
{
private SceneListList sceneListList;
private JPanel buttonPanel; // panel for action buttons
private JButton hideButton; // button to hide the applet selected scene
private JButton unhideButton; // button to unhide the selected scene
private JButton closeButton; // button to close the dialog box
// TBD - use the observer pattern instead?
private MosaicData md; // reference to the MosaicData object
private imgViewer applet; // reference to the main applet
// Constructor for the scene list dialog
//--------------------------------------
public HideSceneDialog(JFrame parent, imgViewer applet, MosaicData md)
{
super(parent,"Hidden Scene List",false);
this.applet = applet;
this.md = md;
getContentPane().setLayout(new BorderLayout());
Sensor[] sensors = applet.getSensors();
SceneList[] sceneList = new SceneList[sensors.length];
// build an array of hidden scene lists
for (int i = 0; i < sensors.length; i++)
{
sceneList[i] = sensors[i].hiddenSceneList;
}
// set up the scene list panel
sceneListList = new SceneListList(applet,this,null,applet.normalFont,
6,this,false,false,"Hidden Scene List",sceneList,false);
// set up the buttons
buttonPanel = new JPanel();
GridBagLayout gridbag = new GridBagLayout();
buttonPanel.setLayout(gridbag);
hideButton = new JButton("Hide");
hideButton.setMnemonic(KeyEvent.VK_H);
hideButton.setToolTipText("Hide scene");
hideButton.addActionListener(this);
unhideButton = new JButton("Unhide");
unhideButton.setMnemonic(KeyEvent.VK_U);
unhideButton.setToolTipText("Unhide scene");
unhideButton.addActionListener(this);
closeButton = new JButton("Close");
closeButton.setMnemonic(KeyEvent.VK_C);
closeButton.setToolTipText("Close hidden scene list");
closeButton.addActionListener(this);
GridBagConstraints gbc = new GridBagConstraints();
gbc.weighty = 0;
gbc.weightx = 20;
gbc.fill = GridBagConstraints.BOTH;
buttonPanel.add(hideButton,gbc);
buttonPanel.add(unhideButton,gbc);
// make the order button the last one in this row
gbc.gridwidth = GridBagConstraints.REMAINDER;
// reset the width to one column
gbc.gridwidth = 1;
// make the close button the last one in this row
gbc.gridwidth = GridBagConstraints.REMAINDER;
buttonPanel.add(closeButton,gbc);
// add the scene list and button panels to the dialog
getContentPane().add(sceneListList,"Center");
getContentPane().add(buttonPanel,"South");
// hack to get IE to size the dialog box - TBD find a good way that
// sizes it correctly
setSize(450,200);
// disable the buttons by default
disableButtons();
// request the window events
addWindowListener(this);
// make sure the dialog starts configured for the correct sensor
setSensor(applet.sensorMenu.getCurrentSensor());
}
// method to handle the windowClosing event
//-----------------------------------------
public void windowClosing(WindowEvent e)
{
setVisible(false);
}
// dummy window event handlers for events that do not need handling
//-----------------------------------------------------------------
public void windowActivated(WindowEvent e) { }
public void windowClosed(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowOpened(WindowEvent e) { }
// helper method to enable buttons that depend on data in the list
//----------------------------------------------------------------
private void enableButtons()
{
unhideButton.setEnabled(true);
}
// helper method to disable buttons that depend on data in the list
//-----------------------------------------------------------------
private void disableButtons()
{
unhideButton.setEnabled(false);
}
// method for the ListEntryBuilder interface to provide the contents for
// the scene list
//----------------------------------------------------------------------
public String getEntry(Metadata scene)
{
// get the cloud cover to display, if the sensor has cloud cover values
String cloudCover;
String quality;
String acquiredDate;
int sceneQuality;
Sensor sensor = scene.getSensor();
if (sensor.hasCloudCover)
cloudCover = new String(", " + scene.cloudCover + "% Cloud");
else
cloudCover = new String("");
// if the sensor supports quality, add it to the entry to display
sceneQuality = scene.getQuality();
if (sceneQuality >= 0)
quality = new String(", Quality: " + sceneQuality);
else
quality = new String("");
// if the sensor has an acquired date, add it to the entry to display
if (sensor.hasCloudCover)
acquiredDate = new String(", Acquired: " + scene.getDateString());
else
acquiredDate = new String("");
return scene.getEntityIDForDisplay() + cloudCover + quality
+ acquiredDate;
}
// hide the image currently displayed
//-----------------------------------
public void hideScene(Metadata scene)
{
sceneListList.add(scene);
}
// method to set the currently displayed sensor
//---------------------------------------------
public void setSensor(Sensor newSensor)
{
sceneListList.setSensor(newSensor);
// make sure the buttons are the correct state for the displayed
// scene list
if (sceneListList.getSceneCount() > 0)
enableButtons();
else
disableButtons();
}
// action performed event handler
//-------------------------------
public void actionPerformed(ActionEvent e)
{
String command = e.getActionCommand();
if (command.equals("Hide"))
{
sceneListList.addActiveScene();
}
else if (command.equals("Unhide"))
{
sceneListList.remove();
}
else if (command.equals("Close"))
{
// hide the dialog box
setVisible(false);
}
}
// update method for the observer interface. This handles updates from
// both the MosaicData class and the SceneList class.
//---------------------------------------------------------------------
public void update(Observable ob, Object arg)
{
if (ob == applet.md)
{
// the selected scene was updated, so enable/disable
Metadata scene = applet.md.getCurrentScene();
if (scene != null)
hideButton.setEnabled(true);
else
hideButton.setEnabled(false);
}
}
// method to handle data being added to the scene list
//----------------------------------------------------
public void intervalAdded(ListDataEvent event)
{
// update the search limit filters whenever the state of the
// scene list changes
applet.searchLimitDialog.applyFilter();
enableButtons();
}
// method to handle data being removed from the scene list
//--------------------------------------------------------
public void intervalRemoved(ListDataEvent event)
{
// update the search limit filters whenever the state of the
// scene list changes
applet.searchLimitDialog.applyFilter();
// enable the buttons if there are scenes in the list, otherwise
// disable them
if (sceneListList.getSceneCount() > 0)
enableButtons();
else
disableButtons();
}
// dummy method for the list data listener since nothing needs to be done
//-----------------------------------------------------------------------
public void contentsChanged(ListDataEvent event) { }
}