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 | 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 | - | |
51 | 41 | public ParamField(RequestView requestView, String paramName) { |
52 | 42 | super(); |
53 | 43 | this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
... | ... | @@ -55,6 +45,7 @@ public abstract class ParamField extends JPanel { |
55 | 45 | JLabel label = new JLabel(strLabel.substring(0, 1).toUpperCase() + strLabel.substring(1)); |
56 | 46 | label.setPreferredSize(new Dimension(140, 15)); |
57 | 47 | this.add(label); |
48 | + // TODO: Add tooltip text based on rr.table_column.column_description | |
58 | 49 | this.requestView = requestView; |
59 | 50 | this.paramName = paramName; |
60 | 51 | } |
... | ... | @@ -77,13 +68,6 @@ public abstract class ParamField extends JPanel { |
77 | 68 | } |
78 | 69 | |
79 | 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 | 71 | FloatField(RequestView requestView, String paramName) { |
88 | 72 | super(requestView, paramName); |
89 | 73 | JTextField field = new JTextField(); |
... | ... | @@ -140,17 +124,33 @@ public abstract class ParamField extends JPanel { |
140 | 124 | } |
141 | 125 | |
142 | 126 | public static class FloatRangeField extends ParamField { |
143 | - FloatField fieldMin; | |
144 | - FloatField fieldMax; | |
127 | + JTextField fieldMin; | |
128 | + JTextField fieldMax; | |
145 | 129 | |
146 | 130 | FloatRangeField(RequestView requestView, String paramName) { |
147 | 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 | 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 | 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 | 156 | public static class TargetNameField extends ParamField { | ... | ... |