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
|
package org.litesoft.GWT.forms.client.components.impls.input;
import java.util.*;
import org.litesoft.GWT.forms.client.components.nonpublic.*;
import org.litesoft.core.simpletypes.temporal.*;
import org.litesoft.core.simpletypes.temporal.nonpublic.*;
import org.litesoft.uispecification.*;
public class FormTimePicker extends AbstractTextFieldWithPicker
{
public FormTimePicker( String pLabel, UiFont pLabelFont, String pTooltip, TimeRes pTimeRes, String pCancelText, String pOKText )
{
super( pTooltip, false, calcLength( pTimeRes ), "Time", new MyPicker( pCancelText, pOKText, deNull( pTimeRes ) ) );
initialize( pLabel, pLabelFont, pTooltip );
}
private static TimeRes deNull( TimeRes pTimeRes )
{
return (pTimeRes != null) ? pTimeRes : TimeRes.ToSEC;
}
private static int calcLength( TimeRes pTimeRes )
{
switch ( deNull( pTimeRes ).getIndex() )
{
default:
case TimeRes.MSECindex: // 13:32:59.999
return 12; // .........1234567-1012
case TimeRes.SECindex: //. 13:32:59
return 8; // ..........12345678
case TimeRes.MINindex: //. 13:32
return 5; // ..........12345
case TimeRes.HOURindex: // 13
return 2; // ..........12
}
}
protected Object parseNotEmptyTextFieldToInternalForm( String pText, Object pLastValidInternalFormValue )
{
UtilDateAdaptor zInadequatePartsSource =
(pLastValidInternalFormValue instanceof SimpleTime) ? ((SimpleTime) pLastValidInternalFormValue).getUtilDateAdaptor() : null;
return TemporalParser.YMD.parseTime( pText, getPicker().getTimeFields(), zInadequatePartsSource );
}
protected void pickerClosed( boolean autoClosed )
{
super.pickerClosed( autoClosed );
SimpleTime value = getPicker().getExitValue();
if ( value != null )
{
setTextValueFromPicker( value.toString() );
}
}
protected void showPicker( int pAbsoluteLeft, int pAbsoluteTop, Object pCurrentValue, Object pLastValidInternalFormValue )
{
SimpleTime zTime;
if ( pCurrentValue instanceof SimpleTime )
{
zTime = (SimpleTime) pCurrentValue;
}
else if ( pLastValidInternalFormValue instanceof SimpleTime )
{
zTime = (SimpleTime) pLastValidInternalFormValue;
}
else
{
zTime = SimpleTime.timeComponents( new Date() );
}
getPicker().setInitialValues( zTime );
super.showPicker( pAbsoluteLeft, pAbsoluteTop, pCurrentValue, pLastValidInternalFormValue );
}
private MyPicker getPicker()
{
return (MyPicker) mPicker;
}
private static class MyPicker extends ExtendableDialogPicker
{
private SimpleTime mExitValue = null;
private int mTimeFields;
public MyPicker( String pCancelText, String pOKText, TimeRes pTimeRes )
{
mTimeFields = pTimeRes.getIndex() + 1;
mTimeFieldsPanel = new TimePickerFieldsPanel( "litesoft-TimePickerFieldsPanel", mTimeFields, null );
addExtensionPanel( mTimeFieldsPanel );
addDialogButtonPanel( pCancelText, pOKText );
}
public int getTimeFields()
{
return mTimeFields;
}
protected void dialogButtonPanelClicked( int pButtonIndex )
{
if ( pButtonIndex == 0 ) // 'OK' button
{
mExitValue = mTimeFieldsPanel.getSimpleTime();
}
hide();
}
public SimpleTime getExitValue()
{
return mExitValue;
}
public void show()
{
mExitValue = null;
super.show();
}
private TimePickerFieldsPanel mTimeFieldsPanel;
public void setInitialValues( SimpleTime pTime )
{
mTimeFieldsPanel.setTimeFields( pTime.getUtilDateAdaptor() );
}
}
}
|