diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java index 05fce02..843c3b2 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java @@ -24,7 +24,6 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.logging.Level; @@ -282,12 +281,49 @@ public abstract class ParamField extends JPanel { public static class DataProductTypeField extends ParamField { /** */ private static final long serialVersionUID = -6362359909898369750L; - JComboBox comboBox; + JComboBox comboBox; + + enum DataProductType { + // @noformat + ALL("All", "all"), + IM("Image", "im"), + SP("Spectrum", "sp"), + DS("Dynamic spectrum", "ds"), + SC("Spectral cube", "sc"), + PR("Profile", "pr"), + VO("Volume", "vo"), + MO("Movie", "mo"), + CU("Cube", "cu"), + TS("Time series", "ts"), + CA("Catalog", "ca"), + SV("Spatial vector", "sv"); + // @format + + private String name = ""; + private String id = ""; + + DataProductType(String name, String editor) { + this.name = name; + this.id = editor; + } + + public List query() { + List item = new ArrayList<>(); + item.add(name.replace(" ", "-").toLowerCase()); + item.add(id); + return item; + } + + @Override + public String toString() { + return name; + } + } public DataProductTypeField(EpnTapMainView mainView, String paramName) { super(mainView, paramName); - comboBox = new JComboBox<>((String[]) getItems().keySet().toArray()); - comboBox.setSelectedItem("All"); + comboBox = new JComboBox<>(DataProductType.values()); + comboBox.setSelectedItem(DataProductType.ALL); comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT)); comboBox.addActionListener(new ActionListener() { @Override @@ -298,32 +334,12 @@ public abstract class ParamField extends JPanel { this.add(comboBox); } - private static HashMap getItems() { - HashMap items = new HashMap<>(); - items.put("All", "all"); - items.put("Image", "im"); - items.put("Spectrum", "sp"); - items.put("Dynamic spectrum", "ds"); - items.put("Spectral cube", "sc"); - items.put("Profile", "pr"); - items.put("Volume", "vo"); - items.put("Movie", "mo"); - items.put("Cube", "cu"); - items.put("Time series", "ts"); - items.put("Catalog", "ca"); - items.put("Spatial vector", "sv"); - return items; - } - void onUpdate() { - String key = comboBox.getSelectedItem().toString(); - List item = new ArrayList<>(); - item.add(key.replace(" ", "-").toLowerCase()); - item.add(getItems().get(key)); - if ("All".equals(key)) { + DataProductType item = (DataProductType) comboBox.getSelectedItem(); + if (DataProductType.ALL.equals(item)) { mainView.event(Event.paramRemoved, paramName); } else { - mainView.event(Event.paramChanged, paramName, item); + mainView.event(Event.paramChanged, paramName, item.query()); } } } @@ -331,11 +347,35 @@ public abstract class ParamField extends JPanel { public static class TargetClassField extends ParamField { /** */ private static final long serialVersionUID = 6439475087727685080L; - JComboBox comboBox; + JComboBox comboBox; + + enum TargetClass { + // @noformat + ALL("All"), + COMET("Comet"), + EXOPLANET("Exoplanet"), + INTERPLANETARY_MEDIUM("Interplanetary medium"), + RING("Ring"), SAMPLE("Sample"), + SKY("Sky"), + SPACECRAFT("Spacecraft"), + SPACEJUNK("Spacejunk"), + STAR("Star"); + // @format + + String name; + + TargetClass(String name) { + this.name = name; + } + + String query() { + return name.replace(" ", "_").toLowerCase(); + } + } public TargetClassField(EpnTapMainView mainView, String paramName) { super(mainView, paramName); - comboBox = new JComboBox<>(getItems()); + comboBox = new JComboBox<>(TargetClass.values()); comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT)); comboBox.addActionListener(new ActionListener() { @Override @@ -346,17 +386,12 @@ public abstract class ParamField extends JPanel { this.add(comboBox); } - private static String[] getItems() { - return new String[] { "All", "Comet", "Exoplanet", "Interplanetary medium", "Ring", - "Sample", "Sky", "Spacecraft", "Spacejunk", "Star" }; - } - void onUpdate() { - String value = comboBox.getSelectedItem().toString().replace(" ", "_").toLowerCase(); - if ("All".equals(value)) { + TargetClass value = (TargetClass) comboBox.getSelectedItem(); + if (TargetClass.ALL.equals(value)) { mainView.event(Event.paramRemoved, paramName); } else { - mainView.event(Event.paramChanged, paramName, value); + mainView.event(Event.paramChanged, paramName, value.query()); } } } -- libgit2 0.21.2