-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfirmScenesDialog.java
executable file
·236 lines (207 loc) · 8.3 KB
/
ConfirmScenesDialog.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
// ConfirmScenesDialog.java implements a dialog that warns the user of scenes
// of questionable quality and allows them to specify which scenes to order
// anyway.
//
//---------------------------------------------------------------------------
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 javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class ConfirmScenesDialog extends JDialog implements WindowListener,
ActionListener
{
private Metadata[] scenes; // scenes that need to be confirmed
private boolean cancelled; // flag to indicate the dialog was cancelled
private JCheckBox[] checkBoxes; // checkbox for each scene
private int goodSceneCount; // count of good scenes that can be ordered
private JButton orderButton; // button for ordering the scenes
// Constructor for the scene list dialog
//--------------------------------------
public ConfirmScenesDialog(Metadata[] badScenes,
int goodSceneCount)
{
super(new JFrame(), "Include Low Quality Scenes?", true);
// save the list of poor quality scenes
this.scenes = badScenes;
this.goodSceneCount = goodSceneCount;
cancelled = false;
// use a border layout for the dialog box
getContentPane().setLayout(new BorderLayout());
// set up the panel for the scenes to confirm
JPanel scenePanel = new JPanel();
scenePanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.anchor = GridBagConstraints.WEST;
int displayLine = 0; // track the current line for the layout
// add an explanation message to the dialog
String[] message =
{"The following scenes have excessive cloud cover or poor quality."
+ " Do you really",
"want to include them?",
" ",
"Select the scenes you want to include and press the "
+ "Continue button to proceed ",
"with the selected scenes plus any scenes from your "
+ "original list that are not",
"listed below. Unselected scenes will remain in the "
+ "scene list. Pressing the",
"Cancel button will cancel all scenes and leave all "
+ "scenes in the scene list.",
" "};
for (int i = 0; i < message.length; i++)
{
JLabel line = new JLabel(message[i]);
gbc.gridy = displayLine;
scenePanel.add(line, gbc);
displayLine++;
}
// create a checkbox for each scene
boolean hasCloudCover = scenes[0].getSensor().hasCloudCover;
checkBoxes = new JCheckBox[scenes.length];
for (int i = 0; i < scenes.length; i++)
{
Metadata scene = scenes[i];
String entry = "Scene ID: " + scene.entityID;
// include cloud cover if the sensor has it
if (hasCloudCover)
entry += ", " + scene.cloudCover + "% Cloud Cover";
// include the quality values if present
if (scene.quality != null)
{
int numQuality = scene.quality.length;
for (int qual = 0; qual < numQuality; qual++)
{
if (numQuality > 1)
{
entry += ", Quality " + (qual + 1) + ": "
+ scene.quality[qual];
}
else
entry += ", Quality: " + scene.quality[qual];
}
}
// create and add the checkbox
checkBoxes[i] = new JCheckBox(entry);
checkBoxes[i].setToolTipText("Confirm "+ scene.entityID);
gbc.gridy = displayLine;
scenePanel.add(checkBoxes[i], gbc);
displayLine++;
// if no good scenes exist, sign up for action events on the
// checkboxes so the order button can be properly enabled only
// when scenes will be ordered
if (goodSceneCount == 0)
checkBoxes[i].addActionListener(this);
}
// put the scene panel in a scrollpane
JScrollPane scrollArea = new JScrollPane(scenePanel);
// set up the buttons
JPanel buttonPanel = new JPanel();
GridBagLayout gridbag = new GridBagLayout();
buttonPanel.setLayout(gridbag);
orderButton = new JButton("Continue");
orderButton.setMnemonic(KeyEvent.VK_O);
orderButton.setToolTipText("Continue with selected scenes");
orderButton.addActionListener(this);
if (goodSceneCount == 0)
orderButton.setEnabled(false);
JButton cancelButton = new JButton("Cancel");
cancelButton.setMnemonic(KeyEvent.VK_C);
cancelButton.setToolTipText("Cancel all scenes");
cancelButton.addActionListener(this);
gbc = new GridBagConstraints();
gbc.weighty = 0;
gbc.weightx = 20;
gbc.fill = GridBagConstraints.BOTH;
buttonPanel.add(orderButton,gbc);
// 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(cancelButton,gbc);
// add the scene list and button panels to the dialog
getContentPane().add(scrollArea,"Center");
getContentPane().add(buttonPanel,"South");
// hack to get IE to size the dialog box - TBD find a good way that
// sizes it correctly
setSize(520,350);
// request the window events
addWindowListener(this);
}
// method to handle the windowClosing event
//-----------------------------------------
public void windowClosing(WindowEvent e)
{
// if the window is closed without hitting the order/cancel buttons,
// consider the operation cancelled
cancelled = true;
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) { }
// method to indicate if the dialog box was cancelled
//---------------------------------------------------
public boolean wasCancelled()
{
return cancelled;
}
// action performed event handler
//-------------------------------
public void actionPerformed(ActionEvent e)
{
String command = e.getActionCommand();
if (command.equals("Continue"))
{
// update the visible state of the scenes based on which ones the
// user checked
for (int i = 0; i < scenes.length; i++)
{
if (checkBoxes[i].isSelected())
scenes[i].visible = true;
}
// hide the dialog box
setVisible(false);
}
else if (command.equals("Cancel"))
{
cancelled = true;
// hide the dialog box
setVisible(false);
}
else
{
// a checkbox must have changed state, so decide whether to
// enable the order button
if (goodSceneCount == 0)
{
boolean sceneSelected = false;
for (int i = 0; i < scenes.length; i++)
{
if (checkBoxes[i].isSelected())
{
sceneSelected = true;
break;
}
}
orderButton.setEnabled(sceneSelected);
}
}
}
}