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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
package org.litesoft.GWT.forms.client.components.nonpublic;

import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.*;
import org.litesoft.GWT.client.widgets.*;
import org.litesoft.GWT.client.widgets.nonpublic.*;
import org.litesoft.core.*;
import org.litesoft.core.simpletypes.temporal.*;

public class TimePickerFieldsPanel extends HorizontalPanel
{
    private MyTimeField mHrs;
    private MyTimeField mMins = null;
    private MyTimeField mSecs = null;
    private MyTimeField mMilliSecs = null;

    public TimePickerFieldsPanel( String pPanelStyle, int pRequiredParts, HigherOrderAdjustable pAdjustable )
    {
        addStyleName( pPanelStyle );

        add( mHrs = new MyTimeField( 2, 24, pAdjustable ) );
        if ( pRequiredParts > 1 )
        {
            add( new Label( ":" ) );
            add( mMins = new MyTimeField( 2, 60, mHrs ) );
            if ( pRequiredParts > 2 )
            {
                add( new Label( ":" ) );
                add( mSecs = new MyTimeField( 2, 60, mMins ) );
                if ( pRequiredParts > 3 )
                {
                    add( new Label( "." ) );
                    add( mMilliSecs = new MyTimeField( 3, 1000, mSecs ) );
                }
            }
        }
    }

    public SimpleTime getSimpleTime()
    {
        if ( mMilliSecs != null )
        {
            return new SimpleTime( mHrs.getIntValue(), mMins.getIntValue(), mSecs.getIntValue(),
                                   mMilliSecs.getIntValue() );
        }
        if ( mSecs != null )
        {
            return new SimpleTime( mHrs.getIntValue(), mMins.getIntValue(), mSecs.getIntValue() );
        }
        if ( mMins != null )
        {
            return new SimpleTime( mHrs.getIntValue(), mMins.getIntValue() );
        }
        return new SimpleTime( mHrs.getIntValue() );
    }

    public void setTimeFields( UtilDateAdaptor pTime )
    {
        mHrs.setIntValue( pTime.getHour() );
        if ( mMins != null )
        {
            mMins.setIntValue( pTime.getMin() );
            if ( mSecs != null )
            {
                mSecs.setIntValue( pTime.getSec() );
                if ( mMilliSecs != null )
                {
                    mMilliSecs.setIntValue( pTime.getMilliSec() );
                }
            }
        }
    }

    private static class MyTimeField extends Composite implements HigherOrderAdjustable
    {
        private MyTextBox zField;
        private int mUpperLimit;
        private HigherOrderAdjustable mHigherPart;

        public MyTimeField( int pDigits, int pUpperLimit, HigherOrderAdjustable pHigherPart )
        {
            mHigherPart = (pHigherPart != null) ? pHigherPart : HigherOrderAdjustable.NULL;
            mUpperLimit = (pUpperLimit > 0) ? pUpperLimit : 0;

            HorizontalPanel zHpanel = new HorizontalPanel();

            int zUniqueID = StaticSimpleIdSource.getNext();

            String upCellId = "upId" + zUniqueID;
            String downCellId = "downId" + zUniqueID;
            HTMLPanel zButtonsPanel = new HTMLPanel(
                    "<div class='litesoft-TimeFieldUpArrowImageButton_border'><div class='litesoft-TimeFieldUpArrowImageButton' id=" +
                    upCellId +
                    "></div></div><div class='litesoft-TimeFieldUpArrowImageButton_border'><div class='litesoft-TimeFieldUpArrowImageButton' id=" +
                    downCellId + "></div></div>" );

            zButtonsPanel.add( new UpDownButton( 1 ), upCellId );
            zButtonsPanel.add( new UpDownButton( -1 ), downCellId );

            zHpanel.add( zField = new MyTextBox( pDigits ) );
            zHpanel.add( zButtonsPanel );

            initWidget( zHpanel );
        }

        public int getIntValue()
        {
            return zField.getIntValue();
        }

        public void setIntValue( int pValue )
        {
            zField.setIntValue( pValue );
        }

        public void adjustValue( int pAdjustBy )
        {
            int tmp = getIntValue() + pAdjustBy;
            while ( tmp < 0 )
            {
                tmp += mUpperLimit;
                if ( mHigherPart != null )
                {
                    mHigherPart.adjustValue( -1 );
                }
            }
            while ( mUpperLimit <= tmp )
            {
                tmp -= mUpperLimit;
                if ( mHigherPart != null )
                {
                    mHigherPart.adjustValue( 1 );
                }
            }
            setIntValue( tmp );
        }

        private class UpDownButton extends TransparentImage implements MouseListener
        {
            private int mAdjustBy;
            private String mTimeFieldArrowImageButton_over, mTimeFieldArrowImageButton_border_over, //
                    mTimeFieldArrowImageButton, mTimeFieldArrowImageButton_border;

            public UpDownButton( int pAdjustBy )
            {
                mAdjustBy = pAdjustBy;
                String zBaseStyle;
                if ( mAdjustBy < 0 )
                {
                    zBaseStyle = "litesoft-TimeFieldDownArrowImage";
                    mTimeFieldArrowImageButton_over = "litesoft-TimeFieldDownArrowImageButton-over";
                    mTimeFieldArrowImageButton_border_over = "litesoft-TimeFieldDownArrowImageButton_border-over";
                    mTimeFieldArrowImageButton = "litesoft-TimeFieldDownArrowImageButton";
                    mTimeFieldArrowImageButton_border = "litesoft-TimeFieldDownArrowImageButton_border";
                }
                else
                {
                    zBaseStyle = "litesoft-TimeFieldUpArrowImage";
                    mTimeFieldArrowImageButton_over = "litesoft-TimeFieldUpArrowImageButton-over";
                    mTimeFieldArrowImageButton_border_over = "litesoft-TimeFieldUpArrowImageButton_border-over";
                    mTimeFieldArrowImageButton = "litesoft-TimeFieldUpArrowImageButton";
                    mTimeFieldArrowImageButton_border = "litesoft-TimeFieldUpArrowImageButton_border";
                }
                setStyleName( zBaseStyle );
                setWidth( "11" );
                setHeight( "6" );
                addMouseListener( this );
            }

            public void onMouseDown( Widget sender, int x, int y )
            {
                Element innerBorderBox = DOM.getParent( getElement() );
                Element outerBorderBox = DOM.getParent( innerBorderBox );

                CommonElementHelper.setStyleClass( innerBorderBox, mTimeFieldArrowImageButton_over );
                CommonElementHelper.setStyleClass( outerBorderBox, mTimeFieldArrowImageButton_border_over );

                adjustValue( mAdjustBy );
                startTimer();
            }

            public void onMouseEnter( Widget sender )
            {
            }

            public void onMouseLeave( Widget sender )
            {
            }

            public void onMouseMove( Widget sender, int x, int y )
            {
            }

            public void onMouseUp( Widget sender, int x, int y )
            {
                Element innerBorderBox = DOM.getParent( getElement() );
                Element outerBorderBox = DOM.getParent( innerBorderBox );

                CommonElementHelper.setStyleClass( innerBorderBox, mTimeFieldArrowImageButton );
                CommonElementHelper.setStyleClass( outerBorderBox, mTimeFieldArrowImageButton_border );

                stopTimer();
            }

            protected void onDetach()
            {
                stopTimer();
                super.onDetach();
            }

            private MyTimer mTimer = null;

            private void startTimer()
            {
                if ( mTimer == null )
                {
                    mTimer = new MyTimer();
                }
                mTimer.init();
            }

            private void stopTimer()
            {
                if ( mTimer != null )
                {
                    mTimer.cancel();
                }
            }

            private class MyTimer extends Timer
            {
                public static final int MIN_DELAY = 25;
                public static final int DELAY_ADJUST = 10;

                private int mDelay;

                public void init()
                {
                    schedule( mDelay = 200 );
                }

                public void run()
                {
                    adjustValue( mAdjustBy );
                    if ( (mDelay -= DELAY_ADJUST) < MIN_DELAY )
                    {
                        mDelay = MIN_DELAY;
                    }
                    schedule( mDelay );
                }
            }
        }
    }

    private static class MyTextBox extends TextBox
    {
        private int mDigits;

        public MyTextBox( int pDigits )
        {
            mDigits = pDigits;
            setWidth( mDigits + "em" );
            setEnabled( false );
            //noinspection GWTStyleCheck
            addStyleName( "litesoft-TimeField" );
            setIntValue( 0 );
        }

        public int getIntValue()
        {
            return Integer.parseInt( getText() );
        }

        public void setIntValue( int pValue )
        {
            String zText = Integer.toString( pValue );
            while ( mDigits > zText.length() )
            {
                zText = "0" + zText;
            }
            setText( zText );
        }
    }
}

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

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