comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java @ 2490:4d93f9255caa

Improve km-Spinner behaviour, allow text input (alpha). flys-client/trunk@4283 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 20 Apr 2012 09:29:03 +0000
parents 8d27d2d33d70
children 18e59b0b4a71
comparison
equal deleted inserted replaced
2489:2a504b6d9a1b 2490:4d93f9255caa
11 11
12 import com.google.gwt.user.client.rpc.AsyncCallback; 12 import com.google.gwt.user.client.rpc.AsyncCallback;
13 13
14 import com.smartgwt.client.util.SC; 14 import com.smartgwt.client.util.SC;
15 15
16 //import com.smartgwt.client.types.Alignment;
17 import com.smartgwt.client.types.ListGridFieldType; 16 import com.smartgwt.client.types.ListGridFieldType;
18 17
19 import com.smartgwt.client.widgets.Button; 18 import com.smartgwt.client.widgets.Button;
20 import com.smartgwt.client.widgets.Canvas; 19 import com.smartgwt.client.widgets.Canvas;
21 import com.smartgwt.client.widgets.Label; 20 import com.smartgwt.client.widgets.Label;
26 import com.smartgwt.client.widgets.layout.VLayout; 25 import com.smartgwt.client.widgets.layout.VLayout;
27 import com.smartgwt.client.widgets.form.fields.SpinnerItem; 26 import com.smartgwt.client.widgets.form.fields.SpinnerItem;
28 import com.smartgwt.client.widgets.form.DynamicForm; 27 import com.smartgwt.client.widgets.form.DynamicForm;
29 28
30 import com.smartgwt.client.widgets.form.fields.SelectItem; 29 import com.smartgwt.client.widgets.form.fields.SelectItem;
31 //import com.smartgwt.client.widgets.form.fields.events.BlurEvent; 30 import com.smartgwt.client.widgets.form.fields.TextItem;
32 //import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
33 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; 31 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent;
34 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; 32 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
35 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; 33 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
36 import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; 34 import com.smartgwt.client.widgets.form.fields.events.ChangeHandler;
37 //import com.smartgwt.client.widgets.form.fields.events.KeyPressEvent;
38 //import com.smartgwt.client.widgets.form.fields.events.KeyPressHandler;
39 35
40 import com.smartgwt.client.widgets.menu.Menu; 36 import com.smartgwt.client.widgets.menu.Menu;
41 import com.smartgwt.client.widgets.menu.MenuItem; 37 import com.smartgwt.client.widgets.menu.MenuItem;
42 38
43 import com.smartgwt.client.widgets.events.ClickEvent; 39 import com.smartgwt.client.widgets.events.ClickEvent;
534 this.facetRecord = facetRecord; 530 this.facetRecord = facetRecord;
535 final FacetRecord _facetRecord = facetRecord; 531 final FacetRecord _facetRecord = facetRecord;
536 currentValue = Double.valueOf(facetRecord.getTheme() 532 currentValue = Double.valueOf(facetRecord.getTheme()
537 .getCollectionItem().getData().get(CS_KM)); 533 .getCollectionItem().getData().get(CS_KM));
538 // Buttons and labels. 534 // Buttons and labels.
539 int height = 10; 535 int height = 18;
540 // MinusButton shall ask service for previous available cs. 536 // minusButton shall ask service for previous available cs.
541 Button minusButton = new Button("-"); 537 Button minusButton = new Button("-");
542 minusButton.setWidth(10); 538 minusButton.setWidth(10);
543 minusButton.setHeight(height); 539 minusButton.setHeight(height);
544 minusButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() { 540 minusButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
545 public void onClick(ClickEvent evt) { 541 public void onClick(ClickEvent evt) {
546 spinnerValueEntered(null, currentValue - 0.1d, _facetRecord); 542 spinnerValueEntered(null, currentValue - 0.1d, _facetRecord);
547 } 543 }
548 }); 544 });
549 // TODO i18n 545 // TODO i18n
550 label = new Label(Double.toString(currentValue)); 546 DynamicForm form = new DynamicForm();
551 label.setWidth(10); 547 final TextItem kmField = new TextItem();
552 label.setHeight(height); 548 kmField.setValue(currentValue);
549 kmField.setWidth(35);
550 kmField.setTitle("");
551 kmField.setHeight(height);
552 // Update on focus lost and enter-pressed.
553 kmField.addBlurHandler(new BlurHandler() {
554 @Override
555 public void onBlur(BlurEvent be) {
556 spinnerValueEntered(null,
557 Double.parseDouble(kmField.getValue().toString()),
558 _facetRecord);
559 }
560 });
561 kmField.addKeyPressHandler(new KeyPressHandler(){
562 @Override
563 public void onKeyPress(KeyPressEvent kpe) {
564 if (kpe.getKeyName().equals("Enter")) {
565 kmField.blurItem();
566 }
567 }
568 });
569 // TODO: i18n Now add all the validators, formatters, editors/parsers etc.
570 form.setFields(kmField);
571 form.setTitle("");
572 form.setTitlePrefix("");
573 form.setTitleSuffix("");
574 form.setTitleWidth(0);
575 form.setWidth(40);
576 form.setHeight(height);
553 // PlusButton shall ask service for next available cs. 577 // PlusButton shall ask service for next available cs.
554 Button plusButton = new Button("+"); 578 Button plusButton = new Button("+");
555 plusButton.setWidth(10); 579 plusButton.setWidth(10);
556 plusButton.setHeight(height); 580 plusButton.setHeight(height);
557 plusButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() { 581 plusButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
558 public void onClick(ClickEvent evt) { 582 public void onClick(ClickEvent evt) {
559 spinnerValueEntered(null, currentValue + 0.1d, _facetRecord); 583 spinnerValueEntered(null, currentValue + 0.1d, _facetRecord);
560 } 584 }
561 }); 585 });
562 this.addMember(minusButton); 586 this.addMember(minusButton);
563 this.addMember(label); 587 this.addMember(form);
564 this.addMember(plusButton); 588 this.addMember(plusButton);
565 589
566 this.setHeight(height*2); 590 this.setHeight(height*2);
567 } 591 }
568
569 } 592 }
570 593
571 594
572 /** 595 /**
573 * Create and configure the Grid to display. 596 * Create and configure the Grid to display.
591 614
592 String fieldName = this.getFieldName(colNum); 615 String fieldName = this.getFieldName(colNum);
593 616
594 if (fieldName.equals(GRID_FIELD_ACTIONS)) { 617 if (fieldName.equals(GRID_FIELD_ACTIONS)) {
595 /* 618 /*
596 HLayout recordCanvas = new HLayout(3); 619 TODO:
597 recordCanvas.setHeight(22);
598 recordCanvas.setAlign(Alignment.CENTER);
599
600 // When losing focus, update values.
601 final SpinnerItem spinnerItem = createSpinnerItem(facetRecord);
602 spinnerItem.addBlurHandler(new BlurHandler() {
603 @Override
604 public void onBlur(BlurEvent be) {
605 spinnerValueEntered(spinnerItem,
606 Double.parseDouble(spinnerItem.getValue().toString()),
607 facetRecord);
608 }
609 });
610
611 // Add KeyPressHandler to lose focus when Enter key is pressed.
612 spinnerItem.addKeyPressHandler(new KeyPressHandler(){
613 @Override
614 public void onKeyPress(KeyPressEvent kpe) {
615 if (kpe.getKeyName().equals("Enter")) {
616 spinnerItem.blurItem();
617 }
618 }
619 });
620
621 if (facetRecord.getTheme().getActive() != 1) { 620 if (facetRecord.getTheme().getActive() != 1) {
622 spinnerItem.disable(); 621 spinnerItem.disable();
623 } 622 }
624 */ 623 */
625 624
630 (facetRecord.getTheme()))) { 629 (facetRecord.getTheme()))) {
631 spinnerItem.setTextBoxStyle("bgBlueDark"); 630 spinnerItem.setTextBoxStyle("bgBlueDark");
632 } 631 }
633 */ 632 */
634 633
635 /*
636 DynamicForm formWrap = new DynamicForm();
637 formWrap.setFields(spinnerItem);
638 formWrap.setTitlePrefix("");
639 formWrap.setTitleSuffix("");
640 */
641 return new KmSpinner(facetRecord); 634 return new KmSpinner(facetRecord);
642 } 635 }
643 else { 636 else {
644 return null; 637 return null;
645 } 638 }

http://dive4elements.wald.intevation.org