Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/GWT_Sandbox/FormEngine/src/com/temp/client/foundation/widget/input/support/TextBoxBaseChangeListenableHelper.java

Diff revisions: vs.
  @@ -9,9 +9,9 @@
9 9
10 10 public class TextBoxBaseChangeListenableHelper {
11 11 public interface Participant {
12 - public HandlerRegistration addFocusHandler(FocusHandler handler);
12 + public HandlerRegistration addFocusHandler( FocusHandler handler );
13 13
14 - public HandlerRegistration addBlurHandler(BlurHandler handler);
14 + public HandlerRegistration addBlurHandler( BlurHandler handler );
15 15
16 16 String getText();
17 17
  @@ -23,40 +23,41 @@
23 23 private TextBoxBaseChangeListenableHelper() {
24 24 }
25 25
26 - private class Control implements FocusHandler, BlurHandler {
26 + private class Control implements FocusHandler,
27 + BlurHandler {
27 28 private final Participant participant;
28 29 private final HandlerRegistration focus, blur;
29 30 private boolean participantIsFocused = false;
30 31 private String currentText = "";
31 32
32 - public Control(Participant participant) {
33 + public Control( Participant participant ) {
33 34 this.participant = participant;
34 - focus = participant.addFocusHandler(this);
35 - blur = participant.addBlurHandler(this);
35 + focus = participant.addFocusHandler( this );
36 + blur = participant.addBlurHandler( this );
36 37 }
37 38
38 39 private void detach() {
39 - remove(focus);
40 - remove(blur);
40 + remove( focus );
41 + remove( blur );
41 42 }
42 43
43 - private void remove(HandlerRegistration handler) {
44 - if (handler != null) {
44 + private void remove( HandlerRegistration handler ) {
45 + if ( handler != null ) {
45 46 handler.removeHandler();
46 47 }
47 48 }
48 49
49 50 @Override
50 - public void onFocus(FocusEvent event) {
51 + public void onFocus( FocusEvent event ) {
51 52 participantIsFocused = true;
52 53 currentText = getCurrentText();
53 - setCurrentControl(this); // Enable polling
54 + setCurrentControl( this ); // Enable polling
54 55 }
55 56
56 57 @Override
57 - public void onBlur(BlurEvent event) {
58 - clearCurrentControl(this); // Disable polling
59 - if (participantIsFocused) {
58 + public void onBlur( BlurEvent event ) {
59 + clearCurrentControl( this ); // Disable polling
60 + if ( participantIsFocused ) {
60 61 checkForChange();
61 62 participantIsFocused = false;
62 63 currentText = "";
  @@ -65,7 +66,7 @@
65 66
66 67 private boolean participantTextChanged() {
67 68 String value = getCurrentText();
68 - if (!currentText.equals(value)) {
69 + if ( !currentText.equals( value ) ) {
69 70 currentText = value;
70 71 return true;
71 72 }
  @@ -73,11 +74,11 @@
73 74 }
74 75
75 76 private String getCurrentText() {
76 - return StringUtils.deNull(participant.getText());
77 + return StringUtils.deNull( participant.getText() );
77 78 }
78 79
79 80 private void checkForChange() {
80 - if (participantIsFocused && participantTextChanged()) {
81 + if ( participantIsFocused && participantTextChanged() ) {
81 82 participant.fireChangeListeners();
82 83 }
83 84 }
  @@ -87,31 +88,31 @@
87 88 private Timer timer = null;
88 89 private Control currentControl;
89 90
90 - public void attach(Participant participant) {
91 + public void attach( Participant participant ) {
91 92 boolean wasEmpty = participantControl.isEmpty();
92 - participantControl.put(participant, new Control(participant));
93 - if (wasEmpty) {
93 + participantControl.put( participant, new Control( participant ) );
94 + if ( wasEmpty ) {
94 95 startTimer();
95 96 }
96 97 }
97 98
98 - public void detach(Participant participant) {
99 - Control control = participantControl.remove(participant);
100 - if (control != null) {
99 + public void detach( Participant participant ) {
100 + Control control = participantControl.remove( participant );
101 + if ( control != null ) {
101 102 control.detach();
102 - if (participantControl.isEmpty()) {
103 + if ( participantControl.isEmpty() ) {
103 104 stopTimer();
104 105 }
105 106 }
106 107 }
107 108
108 - private void setCurrentControl(Control control) {
109 + private void setCurrentControl( Control control ) {
109 110 currentControl = control;
110 111 }
111 112
112 - private void clearCurrentControl(Control control) {
113 - if (control == currentControl) {
114 - setCurrentControl(null);
113 + private void clearCurrentControl( Control control ) {
114 + if ( control == currentControl ) {
115 + setCurrentControl( null );
115 116 }
116 117 }
117 118
  @@ -121,16 +122,16 @@
121 122 @Override
122 123 public void run() {
123 124 Control control = currentControl;
124 - if (control != null) {
125 + if ( control != null ) {
125 126 control.checkForChange();
126 127 }
127 128 }
128 129 };
129 - timer.scheduleRepeating(250);
130 + timer.scheduleRepeating( 250 );
130 131 }
131 132
132 133 private void stopTimer() {
133 - if (timer != null) {
134 + if ( timer != null ) {
134 135 timer.cancel();
135 136 timer = null;
136 137 }