Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/widgets/KMSpinner.java @ 8856:5e38e2924c07 3.2.x
Fix code style.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 18 Jan 2018 20:12:01 +0100 |
parents | f7f86f4e4c8d |
children |
comparison
equal
deleted
inserted
replaced
8855:d7c005e12af0 | 8856:5e38e2924c07 |
---|---|
34 | 34 |
35 /** | 35 /** |
36 * SpinnerItem-like element with text label and up/down buttons. | 36 * SpinnerItem-like element with text label and up/down buttons. |
37 */ | 37 */ |
38 public class KMSpinner extends HLayout { | 38 public class KMSpinner extends HLayout { |
39 protected List<KMSpinnerChangeListener> listeners = new ArrayList<KMSpinnerChangeListener>(); | 39 protected List<KMSpinnerChangeListener> listeners = |
40 new ArrayList<KMSpinnerChangeListener>(); | |
40 | 41 |
41 protected Label label; | 42 protected Label label; |
42 protected FacetRecord facetRecord; | 43 protected FacetRecord facetRecord; |
43 protected double value; | 44 protected double value; |
44 | 45 |
53 // minusButton shall ask service for previous available cs. | 54 // minusButton shall ask service for previous available cs. |
54 Button minusButton = new Button("-"); | 55 Button minusButton = new Button("-"); |
55 minusButton.setWidth(18); | 56 minusButton.setWidth(18); |
56 minusButton.setHeight(22); | 57 minusButton.setHeight(22); |
57 minusButton.setValign(VerticalAlignment.CENTER); | 58 minusButton.setValign(VerticalAlignment.CENTER); |
58 minusButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() { | 59 minusButton.addClickHandler( |
60 new com.smartgwt.client.widgets.events.ClickHandler() { | |
59 public void onClick(ClickEvent evt) { | 61 public void onClick(ClickEvent evt) { |
60 fireChangedEvent(value - 0.1d, false); | 62 fireChangedEvent(value - 0.1d, false); |
61 } | 63 } |
62 }); | 64 }); |
63 | 65 |
67 kmField.setWidth("*"); | 69 kmField.setWidth("*"); |
68 kmField.setTitle(""); | 70 kmField.setTitle(""); |
69 kmField.setHeight(20); | 71 kmField.setHeight(20); |
70 | 72 |
71 FormItemValueFormatter doubleFormat = new FormItemValueFormatter() { | 73 FormItemValueFormatter doubleFormat = new FormItemValueFormatter() { |
72 public String formatValue(Object value, Record record, DynamicForm form, FormItem item) { | 74 public String formatValue( |
75 Object value, Record record, DynamicForm form, FormItem item) { | |
73 if (value != null) { | 76 if (value != null) { |
74 NumberFormat nf = NumberFormat.getDecimalFormat(); | 77 NumberFormat nf = NumberFormat.getDecimalFormat(); |
75 try { | 78 try { |
76 double d = Double.valueOf(value.toString()).doubleValue(); | 79 double d = Double.valueOf( |
80 value.toString()).doubleValue(); | |
77 return nf.format(d); | 81 return nf.format(d); |
78 } | 82 } |
79 catch (Exception e) { | 83 catch (Exception e) { |
80 GWT.log("EditorValueFormatter exception: " + e.toString()); | 84 GWT.log("EditorValueFormatter exception: " |
85 + e.toString()); | |
81 | 86 |
82 // Remove junk chars from input string | 87 // Remove junk chars from input string |
83 return doublefyString(value.toString()); | 88 return doublefyString(value.toString()); |
84 } | 89 } |
85 } | 90 } |
89 } | 94 } |
90 }; | 95 }; |
91 kmField.setEditorValueFormatter(doubleFormat); | 96 kmField.setEditorValueFormatter(doubleFormat); |
92 | 97 |
93 FormItemValueParser doubleParser = new FormItemValueParser() { | 98 FormItemValueParser doubleParser = new FormItemValueParser() { |
94 public Object parseValue(String value, DynamicForm form, FormItem item) { | 99 public Object parseValue( |
100 String value, DynamicForm form, FormItem item) { | |
95 if (value == null) | 101 if (value == null) |
96 return null; | 102 return null; |
97 try { | 103 try { |
98 NumberFormat nf = NumberFormat.getDecimalFormat(); | 104 NumberFormat nf = NumberFormat.getDecimalFormat(); |
99 double d = nf.parse(value.toString()); | 105 double d = nf.parse(value.toString()); |
110 kmField.addBlurHandler(new BlurHandler() { | 116 kmField.addBlurHandler(new BlurHandler() { |
111 @Override | 117 @Override |
112 public void onBlur(BlurEvent be) { | 118 public void onBlur(BlurEvent be) { |
113 if (kmField.getValue() != null) { | 119 if (kmField.getValue() != null) { |
114 try { | 120 try { |
115 fireChangedEvent(Double.parseDouble(kmField.getValue().toString()), true); | 121 fireChangedEvent(Double.parseDouble( |
122 kmField.getValue().toString()), true); | |
116 } | 123 } |
117 catch(NumberFormatException nfe) { | 124 catch(NumberFormatException nfe) { |
118 GWT.log("entered string cannot be parsed to double."); | 125 GWT.log("entered string cannot be parsed to double."); |
119 } | 126 } |
120 } | 127 } |
127 kmField.blurItem(); | 134 kmField.blurItem(); |
128 } | 135 } |
129 } | 136 } |
130 }); | 137 }); |
131 | 138 |
132 // TODO: i18n Now add all the validators, formatters, editors/parsers etc. | 139 // TODO: i18n Now add all the validators, formatters, |
140 // editors/parsers etc. | |
133 form.setFields(kmField); | 141 form.setFields(kmField); |
134 form.setTitle(""); | 142 form.setTitle(""); |
135 form.setTitlePrefix(""); | 143 form.setTitlePrefix(""); |
136 form.setTitleSuffix(""); | 144 form.setTitleSuffix(""); |
137 form.setTitleWidth(0); | 145 form.setTitleWidth(0); |
140 // PlusButton shall ask service for next available cs. | 148 // PlusButton shall ask service for next available cs. |
141 Button plusButton = new Button("+"); | 149 Button plusButton = new Button("+"); |
142 plusButton.setWidth(18); | 150 plusButton.setWidth(18); |
143 plusButton.setHeight(22); | 151 plusButton.setHeight(22); |
144 plusButton.setValign(VerticalAlignment.CENTER); | 152 plusButton.setValign(VerticalAlignment.CENTER); |
145 plusButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() { | 153 plusButton.addClickHandler( |
154 new com.smartgwt.client.widgets.events.ClickHandler() { | |
146 public void onClick(ClickEvent evt) { | 155 public void onClick(ClickEvent evt) { |
147 fireChangedEvent(value + 0.1d, true); | 156 fireChangedEvent(value + 0.1d, true); |
148 } | 157 } |
149 }); | 158 }); |
150 | 159 |