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 42f11a8..1917476 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 @@ -38,16 +38,6 @@ public abstract class ParamField extends JPanel { protected static RequestView requestView; protected String paramName; - // TODO: Add tooltip text based on rr.table_column.column_description - public ParamField(RequestView requestView, String paramName, String strLabel) { - super(); - this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); - JLabel label = new JLabel(strLabel + " "); - this.add(label); - this.requestView = requestView; - this.paramName = paramName; - } - public ParamField(RequestView requestView, String paramName) { super(); this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); @@ -55,6 +45,7 @@ public abstract class ParamField extends JPanel { JLabel label = new JLabel(strLabel.substring(0, 1).toUpperCase() + strLabel.substring(1)); label.setPreferredSize(new Dimension(140, 15)); this.add(label); + // TODO: Add tooltip text based on rr.table_column.column_description this.requestView = requestView; this.paramName = paramName; } @@ -77,13 +68,6 @@ public abstract class ParamField extends JPanel { } public static class FloatField extends ParamField { - FloatField(RequestView requestView, String paramName, String strLabel) { - super(requestView, paramName, strLabel); - JTextField field = new JTextField(); - addChangeListener(field, e -> onUpdate(field)); - this.add(field); - } - FloatField(RequestView requestView, String paramName) { super(requestView, paramName); JTextField field = new JTextField(); @@ -140,17 +124,33 @@ public abstract class ParamField extends JPanel { } public static class FloatRangeField extends ParamField { - FloatField fieldMin; - FloatField fieldMax; + JTextField fieldMin; + JTextField fieldMax; FloatRangeField(RequestView requestView, String paramName) { super(requestView, paramName); - fieldMin = new FloatField(requestView, paramName + MIN_SUFFIX, "min"); + fieldMin = new JTextField(); + addChangeListener(fieldMin, e -> onUpdate(fieldMin, MIN_SUFFIX)); this.add(fieldMin); - fieldMax = new FloatField(requestView, paramName + MAX_SUFFIX, "max"); + fieldMax = new JTextField(); + addChangeListener(fieldMax, e -> onUpdate(fieldMax, MAX_SUFFIX)); this.add(fieldMax); } + + private void onUpdate(JTextField field, String suffix) { + if ("".equals(field.getText())) { + field.setBackground(Color.WHITE); + requestView.updateParam(paramName + suffix, null); + } else { + try { + requestView.updateParam(paramName + suffix, Float.parseFloat(field.getText())); + field.setBackground(Color.WHITE); + } catch (NumberFormatException e) { + field.setBackground(Color.PINK); + } + } + } } public static class TargetNameField extends ParamField { -- libgit2 0.21.2