Commit 411334750a1e6ec57f5fa97b719e9d22501b24eb
1 parent
009a05dd
Exists in
master
build floatRangeFields with JTextFields
Showing
1 changed file
with
21 additions
and
21 deletions
Show diff stats
src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java
@@ -38,16 +38,6 @@ public abstract class ParamField extends JPanel { | @@ -38,16 +38,6 @@ public abstract class ParamField extends JPanel { | ||
38 | protected static RequestView requestView; | 38 | protected static RequestView requestView; |
39 | protected String paramName; | 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 | - | ||
51 | public ParamField(RequestView requestView, String paramName) { | 41 | public ParamField(RequestView requestView, String paramName) { |
52 | super(); | 42 | super(); |
53 | this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); | 43 | this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
@@ -55,6 +45,7 @@ public abstract class ParamField extends JPanel { | @@ -55,6 +45,7 @@ public abstract class ParamField extends JPanel { | ||
55 | JLabel label = new JLabel(strLabel.substring(0, 1).toUpperCase() + strLabel.substring(1)); | 45 | JLabel label = new JLabel(strLabel.substring(0, 1).toUpperCase() + strLabel.substring(1)); |
56 | label.setPreferredSize(new Dimension(140, 15)); | 46 | label.setPreferredSize(new Dimension(140, 15)); |
57 | this.add(label); | 47 | this.add(label); |
48 | + // TODO: Add tooltip text based on rr.table_column.column_description | ||
58 | this.requestView = requestView; | 49 | this.requestView = requestView; |
59 | this.paramName = paramName; | 50 | this.paramName = paramName; |
60 | } | 51 | } |
@@ -77,13 +68,6 @@ public abstract class ParamField extends JPanel { | @@ -77,13 +68,6 @@ public abstract class ParamField extends JPanel { | ||
77 | } | 68 | } |
78 | 69 | ||
79 | public static class FloatField extends ParamField { | 70 | 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 | - | ||
87 | FloatField(RequestView requestView, String paramName) { | 71 | FloatField(RequestView requestView, String paramName) { |
88 | super(requestView, paramName); | 72 | super(requestView, paramName); |
89 | JTextField field = new JTextField(); | 73 | JTextField field = new JTextField(); |
@@ -140,17 +124,33 @@ public abstract class ParamField extends JPanel { | @@ -140,17 +124,33 @@ public abstract class ParamField extends JPanel { | ||
140 | } | 124 | } |
141 | 125 | ||
142 | public static class FloatRangeField extends ParamField { | 126 | public static class FloatRangeField extends ParamField { |
143 | - FloatField fieldMin; | ||
144 | - FloatField fieldMax; | 127 | + JTextField fieldMin; |
128 | + JTextField fieldMax; | ||
145 | 129 | ||
146 | FloatRangeField(RequestView requestView, String paramName) { | 130 | FloatRangeField(RequestView requestView, String paramName) { |
147 | super(requestView, paramName); | 131 | super(requestView, paramName); |
148 | - fieldMin = new FloatField(requestView, paramName + MIN_SUFFIX, "min"); | 132 | + fieldMin = new JTextField(); |
133 | + addChangeListener(fieldMin, e -> onUpdate(fieldMin, MIN_SUFFIX)); | ||
149 | this.add(fieldMin); | 134 | this.add(fieldMin); |
150 | 135 | ||
151 | - fieldMax = new FloatField(requestView, paramName + MAX_SUFFIX, "max"); | 136 | + fieldMax = new JTextField(); |
137 | + addChangeListener(fieldMax, e -> onUpdate(fieldMax, MAX_SUFFIX)); | ||
152 | this.add(fieldMax); | 138 | this.add(fieldMax); |
153 | } | 139 | } |
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 | public static class TargetNameField extends ParamField { | 156 | public static class TargetNameField extends ParamField { |