Subversion Repository Public Repository

litesoft

Diff Revisions 948 vs 950 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/TextBoxBaseChangeListenableHelper.java

Diff revisions: vs.
  @@ -1,95 +1,95 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.client.widgets.nonpublic;
3 -
4 - import org.litesoft.commonfoundation.typeutils.*;
5 -
6 - import com.google.gwt.dom.client.*;
7 - import com.google.gwt.event.dom.client.*;
8 - import com.google.gwt.user.client.*;
9 - import com.google.gwt.user.client.ui.*;
10 -
11 - public class TextBoxBaseChangeListenableHelper implements FocusHandler,
12 - BlurHandler {
13 - private Timer mTimer = null;
14 - private String mText = "";
15 - private TextBoxBase mTextBoxBase;
16 -
17 - public TextBoxBaseChangeListenableHelper( TextBoxBase pTextBoxBase ) {
18 - mTextBoxBase = pTextBoxBase;
19 - pTextBoxBase.addFocusHandler( this );
20 - pTextBoxBase.addBlurHandler( this );
21 - }
22 -
23 - public void setText( String pText ) {
24 - mText = Strings.deNull( pText );
25 - }
26 -
27 - private void captureFieldValue() {
28 - mText = getCurrentText();
29 - }
30 -
31 - private boolean textBoxBaseTextChanged() {
32 - String value = getCurrentText();
33 - if ( !mText.equals( value ) ) {
34 - mText = value;
35 - return true;
36 - }
37 - return false;
38 - }
39 -
40 - private String getCurrentText() {
41 - return Strings.deNull( mTextBoxBase.getText() );
42 - }
43 -
44 - private void checkForChange() {
45 - if ( textBoxBaseTextChanged() ) {
46 - fireChangeListeners();
47 - }
48 - }
49 -
50 - @Override
51 - public void onBlur( BlurEvent event ) {
52 - if ( mWidgetIsFocused ) {
53 - mWidgetIsFocused = false;
54 - checkForChange();
55 - stopTimer();
56 - }
57 - }
58 -
59 - private boolean mWidgetIsFocused = false;
60 -
61 - @Override
62 - public void onFocus( FocusEvent event ) {
63 - mWidgetIsFocused = true;
64 - captureFieldValue();
65 - startTimer();
66 - }
67 -
68 - private void fireChangeListeners() {
69 - NativeEvent zEvent = Document.get().createChangeEvent();
70 - mTextBoxBase.getElement().dispatchEvent( zEvent );
71 - }
72 -
73 - public void onDetach() {
74 - stopTimer();
75 - }
76 -
77 - private void startTimer() {
78 - stopTimer();
79 - mTimer = new Timer() {
80 - @Override
81 - public void run() {
82 - checkForChange();
83 - }
84 - };
85 -
86 - mTimer.scheduleRepeating( 250 );
87 - }
88 -
89 - private void stopTimer() {
90 - if ( mTimer != null ) {
91 - mTimer.cancel();
92 - mTimer = null;
93 - }
94 - }
95 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.client.widgets.nonpublic;
3 +
4 + import org.litesoft.commonfoundation.base.*;
5 +
6 + import com.google.gwt.dom.client.*;
7 + import com.google.gwt.event.dom.client.*;
8 + import com.google.gwt.user.client.*;
9 + import com.google.gwt.user.client.ui.*;
10 +
11 + public class TextBoxBaseChangeListenableHelper implements FocusHandler,
12 + BlurHandler {
13 + private Timer mTimer = null;
14 + private String mText = "";
15 + private TextBoxBase mTextBoxBase;
16 +
17 + public TextBoxBaseChangeListenableHelper( TextBoxBase pTextBoxBase ) {
18 + mTextBoxBase = pTextBoxBase;
19 + pTextBoxBase.addFocusHandler( this );
20 + pTextBoxBase.addBlurHandler( this );
21 + }
22 +
23 + public void setText( String pText ) {
24 + mText = ConstrainTo.notNull( pText );
25 + }
26 +
27 + private void captureFieldValue() {
28 + mText = getCurrentText();
29 + }
30 +
31 + private boolean textBoxBaseTextChanged() {
32 + String value = getCurrentText();
33 + if ( !mText.equals( value ) ) {
34 + mText = value;
35 + return true;
36 + }
37 + return false;
38 + }
39 +
40 + private String getCurrentText() {
41 + return ConstrainTo.notNull( mTextBoxBase.getText() );
42 + }
43 +
44 + private void checkForChange() {
45 + if ( textBoxBaseTextChanged() ) {
46 + fireChangeListeners();
47 + }
48 + }
49 +
50 + @Override
51 + public void onBlur( BlurEvent event ) {
52 + if ( mWidgetIsFocused ) {
53 + mWidgetIsFocused = false;
54 + checkForChange();
55 + stopTimer();
56 + }
57 + }
58 +
59 + private boolean mWidgetIsFocused = false;
60 +
61 + @Override
62 + public void onFocus( FocusEvent event ) {
63 + mWidgetIsFocused = true;
64 + captureFieldValue();
65 + startTimer();
66 + }
67 +
68 + private void fireChangeListeners() {
69 + NativeEvent zEvent = Document.get().createChangeEvent();
70 + mTextBoxBase.getElement().dispatchEvent( zEvent );
71 + }
72 +
73 + public void onDetach() {
74 + stopTimer();
75 + }
76 +
77 + private void startTimer() {
78 + stopTimer();
79 + mTimer = new Timer() {
80 + @Override
81 + public void run() {
82 + checkForChange();
83 + }
84 + };
85 +
86 + mTimer.scheduleRepeating( 250 );
87 + }
88 +
89 + private void stopTimer() {
90 + if ( mTimer != null ) {
91 + mTimer.cancel();
92 + mTimer = null;
93 + }
94 + }
95 + }