Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
package org.litesoft.GWT.forms.client.components.nonpublic;

import org.litesoft.GWT.client.*;
import org.litesoft.GWT.client.widgets.*;
import org.litesoft.GWT.client.widgets.nonpublic.*;
import org.litesoft.GWT.forms.client.components.*;

import com.google.gwt.event.dom.client.*;
import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.*;

public abstract class AbstractTextElement extends AbstractFocusWidgetErrorableFormElement implements ISizeableWidget,
                                                                                                     IFormComponentWithRawTextAccess
{
    protected TextBoxBase mTextBoxBase;
    protected ISizeableDimensionHelper mWidthHelper;
    protected ISizeableDimensionHelper mHeightHelper;
//    private HandlerRegistration mChangeHandlerDisposer;

    protected AbstractTextElement( IFocusWidget pTextBoxBase, String pTooltip, String pWidgetStyle )
    {
        this( pTextBoxBase, (TextBoxBase) pTextBoxBase, pTooltip, pWidgetStyle );
    }

    protected AbstractTextElement( IFocusWidget pInputWidget, TextBoxBase pTextBoxBase, String pTooltip, String pWidgetStyle )
    {
        super( pInputWidget, pTooltip, pWidgetStyle, false );
//        mChangeHandlerDisposer =
        (mTextBoxBase = pTextBoxBase).addChangeHandler( new ChangeHandler()
        {
            public void onChange( ChangeEvent event )
            {
                fireChangeListeners();
            }
        } );
    }

    // Example of unregistering
//    public void dispose()
//    {
//        if ( mChangeHandlerDisposer != null )
//        {
//            mChangeHandlerDisposer.removeHandler();
//            mChangeHandlerDisposer = null;
//        }
//    }

    // ISizeableWidget

    public ISizeableDimensionHelper getWidthHelper()
    {
        return mWidthHelper;
    }

    public ISizeableDimensionHelper getHeightHelper()
    {
        return mHeightHelper;
    }

    public void relayout()
    {
    }

    /**
     * Sets the object's width. This width does not include decorations such as
     * border, margin, and padding.
     *
     * @param width the object's new width, in CSS units (e.g. "10px", "1em")
     */
    public void setWidth( String width )
    {
        setDimensionFromWidget( getWidthHelper(), width );
    }

    /**
     * Sets the object's height. This height does not include decorations such as
     * border, margin, and padding.
     *
     * @param height the object's new height, in CSS units (e.g. "10px", "1em")
     */
    public void setHeight( String height )
    {
        setDimensionFromWidget( getHeightHelper(), height );
    }

    // IFormComponent

    public Object getCurrentValue()
    {
        return getCurrentText();
    }

    public void setCurrentValue( Object pNewValue )
    {
        setCurrentText( (pNewValue == null) ? "" : pNewValue.toString() );
    }

    // Support...

    public void simulateUserTextEntry( String pText )
    {
        String zCurrentText = getCurrentText();
        setCurrentText( pText );
        if ( !zCurrentText.equals( getCurrentText() ) )
        {
            fireChangeListeners();
        }
        pullFocusTo( getTextBoxBase() );
    }

    public String getCurrentText()
    {
        return UtilsGwt.deNull( getTextBoxBase().getText() );
    }

    public void setCurrentText( String pNewText )
    {
        getTextBoxBase().setText( UtilsGwt.deNull( pNewText ) );
    }

    public TextBoxBase getTextBoxBase()
    {
        return mTextBoxBase;
    }

    private void setDimensionFromWidget( ISizeableDimensionHelper pDimensionHelper, String pSize_1D )
    {
        int zSize_1D;
        try
        {
            zSize_1D = AbstractSizeableWidget.parse( pSize_1D );
        }
        catch ( NumberFormatException e )
        {
            throw new IllegalArgumentException( "Attempt to set" + pDimensionHelper.getWhat() + "( \"" + pSize_1D + "\" ) on " + getClass().getName() );
        }
        pDimensionHelper.deligateSetDimensionFromWidget( zSize_1D );
    }

    protected static abstract class AbstractHeightHelper extends AbstractDimensionHelper
    {
        protected AbstractHeightHelper( boolean pStretchable )
        {
            super( pStretchable, HeightDimensionHelper.INSTANCE );
        }
    }

    protected static class NullHeightHelper extends AbstractHeightHelper
    {
        public static final NullHeightHelper INSTANCE = new NullHeightHelper();

        private NullHeightHelper()
        {
            super( false );
        }
    }

    private static abstract class AbstractWidthHelper extends AbstractDimensionHelper
    {
        protected AbstractWidthHelper( boolean pStretchable )
        {
            super( pStretchable, WidthDimensionHelper.INSTANCE );
        }
    }

    protected static class NullWidthHelper extends AbstractWidthHelper
    {
        public static final NullWidthHelper INSTANCE = new NullWidthHelper();

        private NullWidthHelper()
        {
            super( false );
        }
    }

    protected static class StretchableWidthHelper extends AbstractWidthHelper
    {
        private AbstractTextElement mOurWidget;

        public StretchableWidthHelper( AbstractTextElement pOurWidget )
        {
            super( true );
            mOurWidget = pOurWidget;
        }

        public void setDimension( int pDimension )
        {
            setDimension( mOurWidget, pDimension );
        }

        public int getDimension()
        {
            return getDimension( mOurWidget );
        }

        public int getDimensionMaxShrinkability()
        {
            return getDimension( mOurWidget.getInjectedInputWidget() ) - 5;
        }

        public int getDecorationSize()
        {
            return getDimension() - getDimension( mOurWidget.getInjectedInputWidget() );
        }

        public void deligateSetDimensionFromWidget( int pDimension )
        {
            int zIndicatorSize = 0;//getDimension( mOurWidget.mIndicatorTd ); // Appears to have been a refactor that eliminated the need for this!
            int zInputDecorationSize = getInputDecorationSize();
            int zOuterSandwichDecorationSize = getOuterSandwichDecorationSize();
            pDimension -= zIndicatorSize + zInputDecorationSize + zOuterSandwichDecorationSize;
            if ( pDimension > 5 )
            {
                setDimension( mOurWidget.getInjectedInputWidget(), pDimension );
            }
        }

        private Integer mInputDecorationSize = null;

        private int getInputDecorationSize()
        {
            if ( mInputDecorationSize == null )
            {
                if ( !mOurWidget.isAttached() )
                {
                    return 9999;
                }
                mInputDecorationSize = (getDimension( getGrandParent( mOurWidget.getInjectedInputWidget() ) ) - //
                                        getDimension( mOurWidget.getInjectedInputWidget() ));
            }
            return mInputDecorationSize;
        }

        private Integer mOuterSandwichDecorationSize = null;

        private int getOuterSandwichDecorationSize()
        {
            if ( mOuterSandwichDecorationSize == null )
            {
                if ( !mOurWidget.isAttached() )
                {
                    return 9999;
                }
                Element zDivOrFS = mOurWidget.mInnerHTMLpanel.getElement();
                int children = DOM.getChildCount( zDivOrFS );
                Element zInnerBread = DOM.getChild( zDivOrFS, children - 1 );
                mOuterSandwichDecorationSize = (getDimension( mOurWidget ) - getDimension( zInnerBread ));
            }
            return mOuterSandwichDecorationSize;
        }

        private Element getGrandParent( Widget pWidget )
        {
            return getGrandParent( pWidget.getElement() );
        }

        private Element getGrandParent( Element pElement )
        {
            return getParent( getParent( pElement ) );
        }

        private Element getParent( Element pElement )
        {
            return DOM.getParent( pElement );
        }
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/forms/client/components/nonpublic/AbstractTextElement.java

Diff revisions: vs.
Revision Author Commited Message
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000