Commit 77184f226268e9a75179090e330c4269c6f96413
1 parent
53d49e83
Exists in
master
Use enums for DataProductTypeField and TargetClassField
Showing
1 changed file
with
72 additions
and
37 deletions
Show diff stats
src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java
... | ... | @@ -24,7 +24,6 @@ import java.text.DateFormat; |
24 | 24 | import java.text.ParseException; |
25 | 25 | import java.text.SimpleDateFormat; |
26 | 26 | import java.util.ArrayList; |
27 | -import java.util.HashMap; | |
28 | 27 | import java.util.List; |
29 | 28 | import java.util.Locale; |
30 | 29 | import java.util.logging.Level; |
... | ... | @@ -282,12 +281,49 @@ public abstract class ParamField extends JPanel { |
282 | 281 | public static class DataProductTypeField extends ParamField { |
283 | 282 | /** */ |
284 | 283 | private static final long serialVersionUID = -6362359909898369750L; |
285 | - JComboBox<String> comboBox; | |
284 | + JComboBox<DataProductType> comboBox; | |
285 | + | |
286 | + enum DataProductType { | |
287 | + // @noformat | |
288 | + ALL("All", "all"), | |
289 | + IM("Image", "im"), | |
290 | + SP("Spectrum", "sp"), | |
291 | + DS("Dynamic spectrum", "ds"), | |
292 | + SC("Spectral cube", "sc"), | |
293 | + PR("Profile", "pr"), | |
294 | + VO("Volume", "vo"), | |
295 | + MO("Movie", "mo"), | |
296 | + CU("Cube", "cu"), | |
297 | + TS("Time series", "ts"), | |
298 | + CA("Catalog", "ca"), | |
299 | + SV("Spatial vector", "sv"); | |
300 | + // @format | |
301 | + | |
302 | + private String name = ""; | |
303 | + private String id = ""; | |
304 | + | |
305 | + DataProductType(String name, String editor) { | |
306 | + this.name = name; | |
307 | + this.id = editor; | |
308 | + } | |
309 | + | |
310 | + public List<String> query() { | |
311 | + List<String> item = new ArrayList<>(); | |
312 | + item.add(name.replace(" ", "-").toLowerCase()); | |
313 | + item.add(id); | |
314 | + return item; | |
315 | + } | |
316 | + | |
317 | + @Override | |
318 | + public String toString() { | |
319 | + return name; | |
320 | + } | |
321 | + } | |
286 | 322 | |
287 | 323 | public DataProductTypeField(EpnTapMainView mainView, String paramName) { |
288 | 324 | super(mainView, paramName); |
289 | - comboBox = new JComboBox<>((String[]) getItems().keySet().toArray()); | |
290 | - comboBox.setSelectedItem("All"); | |
325 | + comboBox = new JComboBox<>(DataProductType.values()); | |
326 | + comboBox.setSelectedItem(DataProductType.ALL); | |
291 | 327 | comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT)); |
292 | 328 | comboBox.addActionListener(new ActionListener() { |
293 | 329 | @Override |
... | ... | @@ -298,32 +334,12 @@ public abstract class ParamField extends JPanel { |
298 | 334 | this.add(comboBox); |
299 | 335 | } |
300 | 336 | |
301 | - private static HashMap<String, String> getItems() { | |
302 | - HashMap<String, String> items = new HashMap<>(); | |
303 | - items.put("All", "all"); | |
304 | - items.put("Image", "im"); | |
305 | - items.put("Spectrum", "sp"); | |
306 | - items.put("Dynamic spectrum", "ds"); | |
307 | - items.put("Spectral cube", "sc"); | |
308 | - items.put("Profile", "pr"); | |
309 | - items.put("Volume", "vo"); | |
310 | - items.put("Movie", "mo"); | |
311 | - items.put("Cube", "cu"); | |
312 | - items.put("Time series", "ts"); | |
313 | - items.put("Catalog", "ca"); | |
314 | - items.put("Spatial vector", "sv"); | |
315 | - return items; | |
316 | - } | |
317 | - | |
318 | 337 | void onUpdate() { |
319 | - String key = comboBox.getSelectedItem().toString(); | |
320 | - List<String> item = new ArrayList<>(); | |
321 | - item.add(key.replace(" ", "-").toLowerCase()); | |
322 | - item.add(getItems().get(key)); | |
323 | - if ("All".equals(key)) { | |
338 | + DataProductType item = (DataProductType) comboBox.getSelectedItem(); | |
339 | + if (DataProductType.ALL.equals(item)) { | |
324 | 340 | mainView.event(Event.paramRemoved, paramName); |
325 | 341 | } else { |
326 | - mainView.event(Event.paramChanged, paramName, item); | |
342 | + mainView.event(Event.paramChanged, paramName, item.query()); | |
327 | 343 | } |
328 | 344 | } |
329 | 345 | } |
... | ... | @@ -331,11 +347,35 @@ public abstract class ParamField extends JPanel { |
331 | 347 | public static class TargetClassField extends ParamField { |
332 | 348 | /** */ |
333 | 349 | private static final long serialVersionUID = 6439475087727685080L; |
334 | - JComboBox<String> comboBox; | |
350 | + JComboBox<TargetClass> comboBox; | |
351 | + | |
352 | + enum TargetClass { | |
353 | + // @noformat | |
354 | + ALL("All"), | |
355 | + COMET("Comet"), | |
356 | + EXOPLANET("Exoplanet"), | |
357 | + INTERPLANETARY_MEDIUM("Interplanetary medium"), | |
358 | + RING("Ring"), SAMPLE("Sample"), | |
359 | + SKY("Sky"), | |
360 | + SPACECRAFT("Spacecraft"), | |
361 | + SPACEJUNK("Spacejunk"), | |
362 | + STAR("Star"); | |
363 | + // @format | |
364 | + | |
365 | + String name; | |
366 | + | |
367 | + TargetClass(String name) { | |
368 | + this.name = name; | |
369 | + } | |
370 | + | |
371 | + String query() { | |
372 | + return name.replace(" ", "_").toLowerCase(); | |
373 | + } | |
374 | + } | |
335 | 375 | |
336 | 376 | public TargetClassField(EpnTapMainView mainView, String paramName) { |
337 | 377 | super(mainView, paramName); |
338 | - comboBox = new JComboBox<>(getItems()); | |
378 | + comboBox = new JComboBox<>(TargetClass.values()); | |
339 | 379 | comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT)); |
340 | 380 | comboBox.addActionListener(new ActionListener() { |
341 | 381 | @Override |
... | ... | @@ -346,17 +386,12 @@ public abstract class ParamField extends JPanel { |
346 | 386 | this.add(comboBox); |
347 | 387 | } |
348 | 388 | |
349 | - private static String[] getItems() { | |
350 | - return new String[] { "All", "Comet", "Exoplanet", "Interplanetary medium", "Ring", | |
351 | - "Sample", "Sky", "Spacecraft", "Spacejunk", "Star" }; | |
352 | - } | |
353 | - | |
354 | 389 | void onUpdate() { |
355 | - String value = comboBox.getSelectedItem().toString().replace(" ", "_").toLowerCase(); | |
356 | - if ("All".equals(value)) { | |
390 | + TargetClass value = (TargetClass) comboBox.getSelectedItem(); | |
391 | + if (TargetClass.ALL.equals(value)) { | |
357 | 392 | mainView.event(Event.paramRemoved, paramName); |
358 | 393 | } else { |
359 | - mainView.event(Event.paramChanged, paramName, value); | |
394 | + mainView.event(Event.paramChanged, paramName, value.query()); | |
360 | 395 | } |
361 | 396 | } |
362 | 397 | } | ... | ... |