Commit a99d92fa850d8cce41953cc83031189a0e5f9449
1 parent
05b140ed
Exists in
master
Add JComboBox for dataProductType and targetClass
Showing
1 changed file
with
36 additions
and
22 deletions
Show diff stats
src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java
... | ... | @@ -2,6 +2,8 @@ package eu.omp.irap.vespa.epntapclient.view; |
2 | 2 | |
3 | 3 | import java.awt.Color; |
4 | 4 | import java.awt.Dimension; |
5 | +import java.awt.event.ActionEvent; | |
6 | +import java.awt.event.ActionListener; | |
5 | 7 | import java.beans.PropertyChangeEvent; |
6 | 8 | import java.text.DateFormat; |
7 | 9 | import java.text.ParseException; |
... | ... | @@ -184,7 +186,7 @@ public abstract class ParamField extends JPanel { |
184 | 186 | this.add(comboBox); |
185 | 187 | } |
186 | 188 | |
187 | - private String[] getTargetNames(String begining) { | |
189 | + private String[] getItems(String begining) { | |
188 | 190 | StringBuilder resolverResult = null; |
189 | 191 | try { |
190 | 192 | resolverResult = VOTableConnection.sendGet(RESOLVER_URL, "q=\"" + begining + "\""); |
... | ... | @@ -209,7 +211,7 @@ public abstract class ParamField extends JPanel { |
209 | 211 | lastContent = content; |
210 | 212 | int nbItems = comboBox.getItemCount(); |
211 | 213 | comboBox.removeAllItems(); |
212 | - for (String s : getTargetNames(content)) { | |
214 | + for (String s : getItems(content)) { | |
213 | 215 | comboBox.addItem(s); |
214 | 216 | } |
215 | 217 | field.setText(content); |
... | ... | @@ -219,42 +221,54 @@ public abstract class ParamField extends JPanel { |
219 | 221 | } |
220 | 222 | |
221 | 223 | public static class DataProductTypeField extends ParamField { |
222 | - JTextField field; | |
224 | + JComboBox<String> comboBox; | |
223 | 225 | |
224 | 226 | DataProductTypeField(RequestView requestView, String paramName) { |
225 | 227 | super(requestView, paramName); |
226 | - JTextField field = new JTextField(); | |
227 | - // TODO: listbox with enumerated values instead of JTextField | |
228 | - addChangeListener(field, e -> onUpdate()); | |
229 | - this.add(field); | |
228 | + comboBox = new JComboBox(getItems()); | |
229 | + comboBox.addActionListener(new ActionListener() { | |
230 | + @Override | |
231 | + public void actionPerformed(ActionEvent e) { | |
232 | + onUpdate(); | |
233 | + } | |
234 | + }); | |
235 | + this.add(comboBox); | |
236 | + } | |
237 | + | |
238 | + private String[] getItems() { | |
239 | + return new String[] { "All", "Image", "Spectrum", "Dynamic spectrum", "Spectral cube", | |
240 | + "Profile", "Volume", "Movie", "Cube" }; | |
230 | 241 | } |
231 | 242 | |
232 | 243 | private void onUpdate() { |
233 | - if ("".equals(field.getText())) { | |
234 | - requestView.updateParam(paramName, null); | |
235 | - } else { | |
236 | - requestView.updateParam(paramName, field.getText()); | |
237 | - } | |
244 | + String value = comboBox.getSelectedItem().toString().replace(" ", "-").toLowerCase(); | |
245 | + requestView.updateParam(paramName, "All".equals(value) ? null : value); | |
238 | 246 | } |
239 | 247 | } |
240 | 248 | |
241 | 249 | public static class TargetClassField extends ParamField { |
242 | - JTextField field; | |
250 | + JComboBox<String> comboBox; | |
243 | 251 | |
244 | 252 | TargetClassField(RequestView requestView, String paramName) { |
245 | 253 | super(requestView, paramName); |
246 | - JTextField field = new JTextField(); | |
247 | - // TODO: listbox with enumerated values instead of JTextField | |
248 | - addChangeListener(field, e -> onUpdate()); | |
249 | - this.add(field); | |
254 | + comboBox = new JComboBox(getItems()); | |
255 | + comboBox.addActionListener(new ActionListener() { | |
256 | + @Override | |
257 | + public void actionPerformed(ActionEvent e) { | |
258 | + onUpdate(); | |
259 | + } | |
260 | + }); | |
261 | + this.add(comboBox); | |
262 | + } | |
263 | + | |
264 | + private String[] getItems() { | |
265 | + return new String[] { "All", "Comet", "Exoplanet", "Interplanetary medium", "Ring", | |
266 | + "Sample", "Sky", "Spacecraft", "Spacejunk", "Star" }; | |
250 | 267 | } |
251 | 268 | |
252 | 269 | private void onUpdate() { |
253 | - if ("".equals(field.getText())) { | |
254 | - requestView.updateParam(paramName, null); | |
255 | - } else { | |
256 | - requestView.updateParam(paramName, field.getText()); | |
257 | - } | |
270 | + String value = comboBox.getSelectedItem().toString().replace(" ", "_").toLowerCase(); | |
271 | + requestView.updateParam(paramName, "All".equals(value) ? null : value); | |
258 | 272 | } |
259 | 273 | } |
260 | 274 | ... | ... |