Commit 009a05ddde73456d2c8579b57e53dd35b658120a

Authored by Nathanael Jourdane
1 parent 76db66a0
Exists in master

build floatRangeFields with FloatFields

src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java
... ... @@ -38,6 +38,16 @@ public abstract class ParamField extends JPanel {
38 38 protected static RequestView requestView;
39 39 protected String paramName;
40 40  
  41 + // TODO: Add tooltip text based on rr.table_column.column_description
  42 + public ParamField(RequestView requestView, String paramName, String strLabel) {
  43 + super();
  44 + this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
  45 + JLabel label = new JLabel(strLabel + " ");
  46 + this.add(label);
  47 + this.requestView = requestView;
  48 + this.paramName = paramName;
  49 + }
  50 +
41 51 public ParamField(RequestView requestView, String paramName) {
42 52 super();
43 53 this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
... ... @@ -45,7 +55,6 @@ public abstract class ParamField extends JPanel {
45 55 JLabel label = new JLabel(strLabel.substring(0, 1).toUpperCase() + strLabel.substring(1));
46 56 label.setPreferredSize(new Dimension(140, 15));
47 57 this.add(label);
48   - // TODO: Add tooltip text based on rr.table_column.column_description
49 58 this.requestView = requestView;
50 59 this.paramName = paramName;
51 60 }
... ... @@ -68,6 +77,13 @@ public abstract class ParamField extends JPanel {
68 77 }
69 78  
70 79 public static class FloatField extends ParamField {
  80 + FloatField(RequestView requestView, String paramName, String strLabel) {
  81 + super(requestView, paramName, strLabel);
  82 + JTextField field = new JTextField();
  83 + addChangeListener(field, e -> onUpdate(field));
  84 + this.add(field);
  85 + }
  86 +
71 87 FloatField(RequestView requestView, String paramName) {
72 88 super(requestView, paramName);
73 89 JTextField field = new JTextField();
... ... @@ -124,33 +140,17 @@ public abstract class ParamField extends JPanel {
124 140 }
125 141  
126 142 public static class FloatRangeField extends ParamField {
127   - JTextField fieldMin;
128   - JTextField fieldMax;
  143 + FloatField fieldMin;
  144 + FloatField fieldMax;
129 145  
130 146 FloatRangeField(RequestView requestView, String paramName) {
131 147 super(requestView, paramName);
132   - fieldMin = new JTextField();
133   - addChangeListener(fieldMin, e -> onUpdate(fieldMin, MIN_SUFFIX));
  148 + fieldMin = new FloatField(requestView, paramName + MIN_SUFFIX, "min");
134 149 this.add(fieldMin);
135 150  
136   - fieldMax = new JTextField();
137   - addChangeListener(fieldMax, e -> onUpdate(fieldMax, MAX_SUFFIX));
  151 + fieldMax = new FloatField(requestView, paramName + MAX_SUFFIX, "max");
138 152 this.add(fieldMax);
139 153 }
140   -
141   - private void onUpdate(JTextField field, String suffix) {
142   - if ("".equals(field.getText())) {
143   - field.setBackground(Color.WHITE);
144   - requestView.updateParam(paramName + suffix, null);
145   - } else {
146   - try {
147   - requestView.updateParam(paramName + suffix, Float.parseFloat(field.getText()));
148   - field.setBackground(Color.WHITE);
149   - } catch (NumberFormatException e) {
150   - field.setBackground(Color.PINK);
151   - }
152   - }
153   - }
154 154 }
155 155  
156 156 public static class TargetNameField extends ParamField {
... ...