From 009a05ddde73456d2c8579b57e53dd35b658120a Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Wed, 9 Mar 2016 18:54:37 +0100 Subject: [PATCH] build floatRangeFields with FloatFields --- src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) 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 1917476..42f11a8 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,6 +38,16 @@ 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)); @@ -45,7 +55,6 @@ 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; } @@ -68,6 +77,13 @@ 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(); @@ -124,33 +140,17 @@ public abstract class ParamField extends JPanel { } public static class FloatRangeField extends ParamField { - JTextField fieldMin; - JTextField fieldMax; + FloatField fieldMin; + FloatField fieldMax; FloatRangeField(RequestView requestView, String paramName) { super(requestView, paramName); - fieldMin = new JTextField(); - addChangeListener(fieldMin, e -> onUpdate(fieldMin, MIN_SUFFIX)); + fieldMin = new FloatField(requestView, paramName + MIN_SUFFIX, "min"); this.add(fieldMin); - fieldMax = new JTextField(); - addChangeListener(fieldMax, e -> onUpdate(fieldMax, MAX_SUFFIX)); + fieldMax = new FloatField(requestView, paramName + MAX_SUFFIX, "max"); 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