Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java @ 2513:89814cc6e922
Fix issue652: spinner input.
flys-client/trunk@4371 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 09 May 2012 21:44:54 +0000 |
parents | 18e59b0b4a71 |
children | 902526c9efd4 |
comparison
equal
deleted
inserted
replaced
2512:72266675b351 | 2513:89814cc6e922 |
---|---|
7 import java.util.LinkedHashMap; | 7 import java.util.LinkedHashMap; |
8 import java.util.List; | 8 import java.util.List; |
9 | 9 |
10 import com.google.gwt.core.client.GWT; | 10 import com.google.gwt.core.client.GWT; |
11 | 11 |
12 import com.google.gwt.i18n.client.NumberFormat; | |
13 | |
12 import com.google.gwt.user.client.rpc.AsyncCallback; | 14 import com.google.gwt.user.client.rpc.AsyncCallback; |
13 | 15 |
14 import com.smartgwt.client.util.SC; | 16 import com.smartgwt.client.util.SC; |
15 | 17 |
16 import com.smartgwt.client.types.ListGridFieldType; | 18 import com.smartgwt.client.types.ListGridFieldType; |
17 | 19 |
20 import com.smartgwt.client.data.Record; | |
18 import com.smartgwt.client.widgets.Button; | 21 import com.smartgwt.client.widgets.Button; |
19 import com.smartgwt.client.widgets.Canvas; | 22 import com.smartgwt.client.widgets.Canvas; |
20 import com.smartgwt.client.widgets.Label; | 23 import com.smartgwt.client.widgets.Label; |
21 import com.smartgwt.client.widgets.grid.ListGrid; | 24 import com.smartgwt.client.widgets.grid.ListGrid; |
22 import com.smartgwt.client.widgets.grid.ListGridField; | 25 import com.smartgwt.client.widgets.grid.ListGridField; |
23 import com.smartgwt.client.widgets.grid.ListGridRecord; | 26 import com.smartgwt.client.widgets.grid.ListGridRecord; |
24 import com.smartgwt.client.widgets.layout.HLayout; | 27 import com.smartgwt.client.widgets.layout.HLayout; |
25 import com.smartgwt.client.widgets.layout.VLayout; | 28 import com.smartgwt.client.widgets.layout.VLayout; |
29 import com.smartgwt.client.widgets.form.fields.FormItem; | |
26 import com.smartgwt.client.widgets.form.fields.SpinnerItem; | 30 import com.smartgwt.client.widgets.form.fields.SpinnerItem; |
27 import com.smartgwt.client.widgets.form.DynamicForm; | 31 import com.smartgwt.client.widgets.form.DynamicForm; |
32 import com.smartgwt.client.widgets.form.FormItemValueFormatter; | |
33 import com.smartgwt.client.widgets.form.FormItemValueParser; | |
28 | 34 |
29 import com.smartgwt.client.widgets.form.fields.SelectItem; | 35 import com.smartgwt.client.widgets.form.fields.SelectItem; |
30 import com.smartgwt.client.widgets.form.fields.TextItem; | 36 import com.smartgwt.client.widgets.form.fields.TextItem; |
31 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; | 37 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; |
32 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; | 38 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; |
544 minusButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() { | 550 minusButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() { |
545 public void onClick(ClickEvent evt) { | 551 public void onClick(ClickEvent evt) { |
546 spinnerValueEntered(null, currentValue - 0.1d, _facetRecord); | 552 spinnerValueEntered(null, currentValue - 0.1d, _facetRecord); |
547 } | 553 } |
548 }); | 554 }); |
549 // TODO i18n | 555 |
550 DynamicForm form = new DynamicForm(); | 556 DynamicForm form = new DynamicForm(); |
551 final TextItem kmField = new TextItem(); | 557 final TextItem kmField = new TextItem(); |
552 kmField.setValue(currentValue); | 558 kmField.setValue(currentValue); |
553 kmField.setWidth(35); | 559 kmField.setWidth(35); |
554 kmField.setTitle(""); | 560 kmField.setTitle(""); |
555 kmField.setHeight(height); | 561 kmField.setHeight(height); |
562 | |
563 FormItemValueFormatter doubleFormat = new FormItemValueFormatter() { | |
564 public String formatValue(Object value, Record record, | |
565 DynamicForm form, FormItem item) { | |
566 if (value != null) { | |
567 NumberFormat nf = NumberFormat.getDecimalFormat(); | |
568 try { | |
569 double d = Double.valueOf(value.toString()).doubleValue(); | |
570 return nf.format(d); | |
571 } catch (Exception e) { | |
572 return value.toString(); | |
573 } | |
574 } | |
575 else { | |
576 return null; | |
577 } | |
578 } | |
579 }; | |
580 kmField.setEditorValueFormatter(doubleFormat); | |
581 | |
582 FormItemValueParser doubleParser = new FormItemValueParser() { | |
583 public Object parseValue(String value, | |
584 DynamicForm form, | |
585 FormItem item) { | |
586 if (value == null) | |
587 return null; | |
588 try { | |
589 NumberFormat nf = NumberFormat.getDecimalFormat(); | |
590 double d = nf.parse(value.toString()); | |
591 return (new Double(d)).toString(); | |
592 } | |
593 catch(NumberFormatException nfe) { | |
594 return value; | |
595 } | |
596 } | |
597 }; | |
598 kmField.setEditorValueParser(doubleParser); | |
599 | |
556 // Update on focus lost and enter-pressed. | 600 // Update on focus lost and enter-pressed. |
557 kmField.addBlurHandler(new BlurHandler() { | 601 kmField.addBlurHandler(new BlurHandler() { |
558 @Override | 602 @Override |
559 public void onBlur(BlurEvent be) { | 603 public void onBlur(BlurEvent be) { |
604 if(kmField.getValue() != null) | |
560 spinnerValueEntered(null, | 605 spinnerValueEntered(null, |
561 Double.parseDouble(kmField.getValue().toString()), | 606 Double.parseDouble(kmField.getValue().toString()), |
562 _facetRecord); | 607 _facetRecord); |
563 } | 608 } |
564 }); | 609 }); |