Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/forms/client/components/nonpublic/AbstractTextElement.java

Diff revisions: vs.
  @@ -1,238 +1,238 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.forms.client.components.nonpublic;
3 -
4 - import org.litesoft.GWT.client.widgets.*;
5 - import org.litesoft.GWT.client.widgets.nonpublic.*;
6 - import org.litesoft.GWT.forms.client.components.*;
7 - import org.litesoft.commonfoundation.typeutils.*;
8 -
9 - import com.google.gwt.event.dom.client.*;
10 - import com.google.gwt.user.client.*;
11 - import com.google.gwt.user.client.ui.*;
12 -
13 - public abstract class AbstractTextElement extends AbstractFocusWidgetErrorableFormElement implements ISizeableWidget,
14 - IFormComponentWithRawTextAccess {
15 - protected TextBoxBase mTextBoxBase;
16 - protected ISizeableDimensionHelper mWidthHelper;
17 - protected ISizeableDimensionHelper mHeightHelper;
18 - // private HandlerRegistration mChangeHandlerDisposer;
19 -
20 - protected AbstractTextElement( IFocusWidget pTextBoxBase, String pTooltip, String pWidgetStyle ) {
21 - this( pTextBoxBase, (TextBoxBase) pTextBoxBase, pTooltip, pWidgetStyle );
22 - }
23 -
24 - protected AbstractTextElement( IFocusWidget pInputWidget, TextBoxBase pTextBoxBase, String pTooltip, String pWidgetStyle ) {
25 - super( pInputWidget, pTooltip, pWidgetStyle, false );
26 - // mChangeHandlerDisposer =
27 - (mTextBoxBase = pTextBoxBase).addChangeHandler( new ChangeHandler() {
28 - @Override
29 - public void onChange( ChangeEvent event ) {
30 - fireChangeListeners();
31 - }
32 - } );
33 - }
34 -
35 - // Example of unregistering
36 - // public void dispose()
37 - // {
38 - // if ( mChangeHandlerDisposer != null )
39 - // {
40 - // mChangeHandlerDisposer.removeHandler();
41 - // mChangeHandlerDisposer = null;
42 - // }
43 - // }
44 -
45 - // ISizeableWidget
46 -
47 - @Override
48 - public ISizeableDimensionHelper getWidthHelper() {
49 - return mWidthHelper;
50 - }
51 -
52 - @Override
53 - public ISizeableDimensionHelper getHeightHelper() {
54 - return mHeightHelper;
55 - }
56 -
57 - @Override
58 - public void relayout() {
59 - }
60 -
61 - /**
62 - * Sets the object's width. This width does not include decorations such as
63 - * border, margin, and padding.
64 - *
65 - * @param width the object's new width, in CSS units (e.g. "10px", "1em")
66 - */
67 - @Override
68 - public void setWidth( String width ) {
69 - setDimensionFromWidget( getWidthHelper(), width );
70 - }
71 -
72 - /**
73 - * Sets the object's height. This height does not include decorations such as
74 - * border, margin, and padding.
75 - *
76 - * @param height the object's new height, in CSS units (e.g. "10px", "1em")
77 - */
78 - @Override
79 - public void setHeight( String height ) {
80 - setDimensionFromWidget( getHeightHelper(), height );
81 - }
82 -
83 - // IFormComponent
84 -
85 - @Override
86 - public Object getCurrentValue() {
87 - return getCurrentText();
88 - }
89 -
90 - @Override
91 - public void setCurrentValue( Object pNewValue ) {
92 - setCurrentText( (pNewValue == null) ? "" : pNewValue.toString() );
93 - }
94 -
95 - // Support...
96 -
97 - @Override
98 - public void simulateUserTextEntry( String pText ) {
99 - String zCurrentText = getCurrentText();
100 - setCurrentText( pText );
101 - if ( !zCurrentText.equals( getCurrentText() ) ) {
102 - fireChangeListeners();
103 - }
104 - pullFocusTo( getTextBoxBase() );
105 - }
106 -
107 - @Override
108 - public String getCurrentText() {
109 - return Strings.deNull( getTextBoxBase().getText() );
110 - }
111 -
112 - public void setCurrentText( String pNewText ) {
113 - getTextBoxBase().setText( Strings.deNull( pNewText ) );
114 - }
115 -
116 - public TextBoxBase getTextBoxBase() {
117 - return mTextBoxBase;
118 - }
119 -
120 - private void setDimensionFromWidget( ISizeableDimensionHelper pDimensionHelper, String pSize_1D ) {
121 - int zSize_1D;
122 - try {
123 - zSize_1D = AbstractSizeableWidget.parse( pSize_1D );
124 - }
125 - catch ( NumberFormatException e ) {
126 - throw new IllegalArgumentException( "Attempt to set" + pDimensionHelper.getWhat() + "( \"" + pSize_1D + "\" ) on " + getClass().getName() );
127 - }
128 - pDimensionHelper.deligateSetDimensionFromWidget( zSize_1D );
129 - }
130 -
131 - protected static abstract class AbstractHeightHelper extends AbstractDimensionHelper {
132 - protected AbstractHeightHelper( boolean pStretchable ) {
133 - super( pStretchable, HeightDimensionHelper.INSTANCE );
134 - }
135 - }
136 -
137 - protected static class NullHeightHelper extends AbstractHeightHelper {
138 - public static final NullHeightHelper INSTANCE = new NullHeightHelper();
139 -
140 - private NullHeightHelper() {
141 - super( false );
142 - }
143 - }
144 -
145 - private static abstract class AbstractWidthHelper extends AbstractDimensionHelper {
146 - protected AbstractWidthHelper( boolean pStretchable ) {
147 - super( pStretchable, WidthDimensionHelper.INSTANCE );
148 - }
149 - }
150 -
151 - protected static class NullWidthHelper extends AbstractWidthHelper {
152 - public static final NullWidthHelper INSTANCE = new NullWidthHelper();
153 -
154 - private NullWidthHelper() {
155 - super( false );
156 - }
157 - }
158 -
159 - protected static class StretchableWidthHelper extends AbstractWidthHelper {
160 - private AbstractTextElement mOurWidget;
161 -
162 - public StretchableWidthHelper( AbstractTextElement pOurWidget ) {
163 - super( true );
164 - mOurWidget = pOurWidget;
165 - }
166 -
167 - @Override
168 - public void setDimension( int pDimension ) {
169 - setDimension( mOurWidget, pDimension );
170 - }
171 -
172 - @Override
173 - public int getDimension() {
174 - return getDimension( mOurWidget );
175 - }
176 -
177 - @Override
178 - public int getDimensionMaxShrinkability() {
179 - return getDimension( mOurWidget.getInjectedInputWidget() ) - 5;
180 - }
181 -
182 - @Override
183 - public int getDecorationSize() {
184 - return getDimension() - getDimension( mOurWidget.getInjectedInputWidget() );
185 - }
186 -
187 - @Override
188 - public void deligateSetDimensionFromWidget( int pDimension ) {
189 - int zIndicatorSize = 0;//getDimension( mOurWidget.mIndicatorTd ); // Appears to have been a refactor that eliminated the need for this!
190 - int zInputDecorationSize = getInputDecorationSize();
191 - int zOuterSandwichDecorationSize = getOuterSandwichDecorationSize();
192 - pDimension -= zIndicatorSize + zInputDecorationSize + zOuterSandwichDecorationSize;
193 - if ( pDimension > 5 ) {
194 - setDimension( mOurWidget.getInjectedInputWidget(), pDimension );
195 - }
196 - }
197 -
198 - private Integer mInputDecorationSize = null;
199 -
200 - private int getInputDecorationSize() {
201 - if ( mInputDecorationSize == null ) {
202 - if ( !mOurWidget.isAttached() ) {
203 - return 9999;
204 - }
205 - mInputDecorationSize = (getDimension( getGrandParent( mOurWidget.getInjectedInputWidget() ) ) - //
206 - getDimension( mOurWidget.getInjectedInputWidget() ));
207 - }
208 - return mInputDecorationSize;
209 - }
210 -
211 - private Integer mOuterSandwichDecorationSize = null;
212 -
213 - private int getOuterSandwichDecorationSize() {
214 - if ( mOuterSandwichDecorationSize == null ) {
215 - if ( !mOurWidget.isAttached() ) {
216 - return 9999;
217 - }
218 - Element zDivOrFS = mOurWidget.mInnerHTMLpanel.getElement();
219 - int children = DOM.getChildCount( zDivOrFS );
220 - Element zInnerBread = DOM.getChild( zDivOrFS, children - 1 );
221 - mOuterSandwichDecorationSize = (getDimension( mOurWidget ) - getDimension( zInnerBread ));
222 - }
223 - return mOuterSandwichDecorationSize;
224 - }
225 -
226 - private Element getGrandParent( Widget pWidget ) {
227 - return getGrandParent( pWidget.getElement() );
228 - }
229 -
230 - private Element getGrandParent( Element pElement ) {
231 - return getParent( getParent( pElement ) );
232 - }
233 -
234 - private Element getParent( Element pElement ) {
235 - return DOM.getParent( pElement );
236 - }
237 - }
238 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.forms.client.components.nonpublic;
3 +
4 + import org.litesoft.GWT.client.widgets.*;
5 + import org.litesoft.GWT.client.widgets.nonpublic.*;
6 + import org.litesoft.GWT.forms.client.components.*;
7 + import org.litesoft.commonfoundation.base.*;
8 +
9 + import com.google.gwt.event.dom.client.*;
10 + import com.google.gwt.user.client.*;
11 + import com.google.gwt.user.client.ui.*;
12 +
13 + public abstract class AbstractTextElement extends AbstractFocusWidgetErrorableFormElement implements ISizeableWidget,
14 + IFormComponentWithRawTextAccess {
15 + protected TextBoxBase mTextBoxBase;
16 + protected ISizeableDimensionHelper mWidthHelper;
17 + protected ISizeableDimensionHelper mHeightHelper;
18 + // private HandlerRegistration mChangeHandlerDisposer;
19 +
20 + protected AbstractTextElement( IFocusWidget pTextBoxBase, String pTooltip, String pWidgetStyle ) {
21 + this( pTextBoxBase, (TextBoxBase) pTextBoxBase, pTooltip, pWidgetStyle );
22 + }
23 +
24 + protected AbstractTextElement( IFocusWidget pInputWidget, TextBoxBase pTextBoxBase, String pTooltip, String pWidgetStyle ) {
25 + super( pInputWidget, pTooltip, pWidgetStyle, false );
26 + // mChangeHandlerDisposer =
27 + (mTextBoxBase = pTextBoxBase).addChangeHandler( new ChangeHandler() {
28 + @Override
29 + public void onChange( ChangeEvent event ) {
30 + fireChangeListeners();
31 + }
32 + } );
33 + }
34 +
35 + // Example of unregistering
36 + // public void dispose()
37 + // {
38 + // if ( mChangeHandlerDisposer != null )
39 + // {
40 + // mChangeHandlerDisposer.removeHandler();
41 + // mChangeHandlerDisposer = null;
42 + // }
43 + // }
44 +
45 + // ISizeableWidget
46 +
47 + @Override
48 + public ISizeableDimensionHelper getWidthHelper() {
49 + return mWidthHelper;
50 + }
51 +
52 + @Override
53 + public ISizeableDimensionHelper getHeightHelper() {
54 + return mHeightHelper;
55 + }
56 +
57 + @Override
58 + public void relayout() {
59 + }
60 +
61 + /**
62 + * Sets the object's width. This width does not include decorations such as
63 + * border, margin, and padding.
64 + *
65 + * @param width the object's new width, in CSS units (e.g. "10px", "1em")
66 + */
67 + @Override
68 + public void setWidth( String width ) {
69 + setDimensionFromWidget( getWidthHelper(), width );
70 + }
71 +
72 + /**
73 + * Sets the object's height. This height does not include decorations such as
74 + * border, margin, and padding.
75 + *
76 + * @param height the object's new height, in CSS units (e.g. "10px", "1em")
77 + */
78 + @Override
79 + public void setHeight( String height ) {
80 + setDimensionFromWidget( getHeightHelper(), height );
81 + }
82 +
83 + // IFormComponent
84 +
85 + @Override
86 + public Object getCurrentValue() {
87 + return getCurrentText();
88 + }
89 +
90 + @Override
91 + public void setCurrentValue( Object pNewValue ) {
92 + setCurrentText( (pNewValue == null) ? "" : pNewValue.toString() );
93 + }
94 +
95 + // Support...
96 +
97 + @Override
98 + public void simulateUserTextEntry( String pText ) {
99 + String zCurrentText = getCurrentText();
100 + setCurrentText( pText );
101 + if ( !zCurrentText.equals( getCurrentText() ) ) {
102 + fireChangeListeners();
103 + }
104 + pullFocusTo( getTextBoxBase() );
105 + }
106 +
107 + @Override
108 + public String getCurrentText() {
109 + return ConstrainTo.notNull( getTextBoxBase().getText() );
110 + }
111 +
112 + public void setCurrentText( String pNewText ) {
113 + getTextBoxBase().setText( ConstrainTo.notNull( pNewText ) );
114 + }
115 +
116 + public TextBoxBase getTextBoxBase() {
117 + return mTextBoxBase;
118 + }
119 +
120 + private void setDimensionFromWidget( ISizeableDimensionHelper pDimensionHelper, String pSize_1D ) {
121 + int zSize_1D;
122 + try {
123 + zSize_1D = AbstractSizeableWidget.parse( pSize_1D );
124 + }
125 + catch ( NumberFormatException e ) {
126 + throw new IllegalArgumentException( "Attempt to set" + pDimensionHelper.getWhat() + "( \"" + pSize_1D + "\" ) on " + getClass().getName() );
127 + }
128 + pDimensionHelper.deligateSetDimensionFromWidget( zSize_1D );
129 + }
130 +
131 + protected static abstract class AbstractHeightHelper extends AbstractDimensionHelper {
132 + protected AbstractHeightHelper( boolean pStretchable ) {
133 + super( pStretchable, HeightDimensionHelper.INSTANCE );
134 + }
135 + }
136 +
137 + protected static class NullHeightHelper extends AbstractHeightHelper {
138 + public static final NullHeightHelper INSTANCE = new NullHeightHelper();
139 +
140 + private NullHeightHelper() {
141 + super( false );
142 + }
143 + }
144 +
145 + private static abstract class AbstractWidthHelper extends AbstractDimensionHelper {
146 + protected AbstractWidthHelper( boolean pStretchable ) {
147 + super( pStretchable, WidthDimensionHelper.INSTANCE );
148 + }
149 + }
150 +
151 + protected static class NullWidthHelper extends AbstractWidthHelper {
152 + public static final NullWidthHelper INSTANCE = new NullWidthHelper();
153 +
154 + private NullWidthHelper() {
155 + super( false );
156 + }
157 + }
158 +
159 + protected static class StretchableWidthHelper extends AbstractWidthHelper {
160 + private AbstractTextElement mOurWidget;
161 +
162 + public StretchableWidthHelper( AbstractTextElement pOurWidget ) {
163 + super( true );
164 + mOurWidget = pOurWidget;
165 + }
166 +
167 + @Override
168 + public void setDimension( int pDimension ) {
169 + setDimension( mOurWidget, pDimension );
170 + }
171 +
172 + @Override
173 + public int getDimension() {
174 + return getDimension( mOurWidget );
175 + }
176 +
177 + @Override
178 + public int getDimensionMaxShrinkability() {
179 + return getDimension( mOurWidget.getInjectedInputWidget() ) - 5;
180 + }
181 +
182 + @Override
183 + public int getDecorationSize() {
184 + return getDimension() - getDimension( mOurWidget.getInjectedInputWidget() );
185 + }
186 +
187 + @Override
188 + public void deligateSetDimensionFromWidget( int pDimension ) {
189 + int zIndicatorSize = 0;//getDimension( mOurWidget.mIndicatorTd ); // Appears to have been a refactor that eliminated the need for this!
190 + int zInputDecorationSize = getInputDecorationSize();
191 + int zOuterSandwichDecorationSize = getOuterSandwichDecorationSize();
192 + pDimension -= zIndicatorSize + zInputDecorationSize + zOuterSandwichDecorationSize;
193 + if ( pDimension > 5 ) {
194 + setDimension( mOurWidget.getInjectedInputWidget(), pDimension );
195 + }
196 + }
197 +
198 + private Integer mInputDecorationSize = null;
199 +
200 + private int getInputDecorationSize() {
201 + if ( mInputDecorationSize == null ) {
202 + if ( !mOurWidget.isAttached() ) {
203 + return 9999;
204 + }
205 + mInputDecorationSize = (getDimension( getGrandParent( mOurWidget.getInjectedInputWidget() ) ) - //
206 + getDimension( mOurWidget.getInjectedInputWidget() ));
207 + }
208 + return mInputDecorationSize;
209 + }
210 +
211 + private Integer mOuterSandwichDecorationSize = null;
212 +
213 + private int getOuterSandwichDecorationSize() {
214 + if ( mOuterSandwichDecorationSize == null ) {
215 + if ( !mOurWidget.isAttached() ) {
216 + return 9999;
217 + }
218 + Element zDivOrFS = mOurWidget.mInnerHTMLpanel.getElement();
219 + int children = DOM.getChildCount( zDivOrFS );
220 + Element zInnerBread = DOM.getChild( zDivOrFS, children - 1 );
221 + mOuterSandwichDecorationSize = (getDimension( mOurWidget ) - getDimension( zInnerBread ));
222 + }
223 + return mOuterSandwichDecorationSize;
224 + }
225 +
226 + private Element getGrandParent( Widget pWidget ) {
227 + return getGrandParent( pWidget.getElement() );
228 + }
229 +
230 + private Element getGrandParent( Element pElement ) {
231 + return getParent( getParent( pElement ) );
232 + }
233 +
234 + private Element getParent( Element pElement ) {
235 + return DOM.getParent( pElement );
236 + }
237 + }
238 + }