Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 183177 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/RWTHostTestSuite.java (+1 lines)
Lines 146-151 Link Here
146
    suite.addTestSuite( ExternalBrowser_Test.class );
146
    suite.addTestSuite( ExternalBrowser_Test.class );
147
    suite.addTestSuite( ProgressBar_Test.class );
147
    suite.addTestSuite( ProgressBar_Test.class );
148
    suite.addTestSuite( BusyIndicator_Test.class );
148
    suite.addTestSuite( BusyIndicator_Test.class );
149
    suite.addTestSuite( DateTime_Test.class );
149
150
150
    suite.addTestSuite( Image_Test.class );
151
    suite.addTestSuite( Image_Test.class );
151
    suite.addTestSuite( ImageData_Test.class );
152
    suite.addTestSuite( ImageData_Test.class );
(-)src/org/eclipse/swt/widgets/DateTime_Test.java (+167 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Innoopract Informationssysteme GmbH. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html Contributors:
6
 * Innoopract Informationssysteme GmbH - initial API and implementation
7
 ******************************************************************************/
8
package org.eclipse.swt.widgets;
9
10
import java.util.Calendar;
11
12
import junit.framework.TestCase;
13
14
import org.eclipse.swt.RWTFixture;
15
import org.eclipse.swt.SWT;
16
17
public class DateTime_Test extends TestCase {
18
19
  protected void setUp() throws Exception {
20
    RWTFixture.setUp();
21
  }
22
23
  protected void tearDown() throws Exception {
24
    RWTFixture.tearDown();
25
  }
26
27
  public void testInitialValues() {
28
    Display display = new Display();
29
    Shell shell = new Shell( display, SWT.NONE );
30
    Calendar rightNow = Calendar.getInstance();
31
    DateTime dateTime = new DateTime( shell, SWT.DATE | SWT.MEDIUM );
32
    assertEquals( rightNow.get( Calendar.DATE ), dateTime.getDay() );
33
    assertEquals( rightNow.get( Calendar.MONTH ), dateTime.getMonth() );
34
    assertEquals( rightNow.get( Calendar.YEAR ), dateTime.getYear() );
35
    assertEquals( rightNow.get( Calendar.HOUR_OF_DAY ), dateTime.getHours() );
36
    assertEquals( rightNow.get( Calendar.MINUTE ), dateTime.getMinutes() );
37
    assertEquals( rightNow.get( Calendar.SECOND ), dateTime.getSeconds() );
38
  }
39
40
  public void testInvalidValues() {
41
    Display display = new Display();
42
    Shell shell = new Shell( display, SWT.NONE );    
43
    DateTime dateTime = new DateTime( shell, SWT.NONE );
44
    dateTime.setDay( 1 );
45
    dateTime.setMonth( 0 );
46
    dateTime.setYear( 2008 );
47
    dateTime.setHours( 0 );
48
    dateTime.setMinutes( 0 );
49
    dateTime.setSeconds( 0 );
50
    assertEquals( 1, dateTime.getDay() );
51
    assertEquals( 0, dateTime.getMonth() );
52
    assertEquals( 2008, dateTime.getYear() );
53
    assertEquals( 0, dateTime.getHours() );
54
    assertEquals( 0, dateTime.getMinutes() );
55
    assertEquals( 0, dateTime.getSeconds() );
56
    // Test day
57
    dateTime.setDay( 61 );
58
    assertEquals( 1, dateTime.getDay() );
59
    dateTime.setDay( 0 );
60
    assertEquals( 1, dateTime.getDay() );
61
    dateTime.setDay( -5 );
62
    assertEquals( 1, dateTime.getDay() );
63
    dateTime.setMonth( 1 );
64
    dateTime.setDay( 29 );
65
    assertEquals( 29, dateTime.getDay() );
66
    dateTime.setDay( 30 );
67
    assertEquals( 29, dateTime.getDay() );    
68
    // Test month
69
    dateTime.setMonth( 12 );
70
    assertEquals( 1, dateTime.getMonth() );
71
    dateTime.setMonth( -5 );
72
    assertEquals( 1, dateTime.getMonth() );    
73
    dateTime.setMonth( 0 );
74
    dateTime.setDay( 31 );
75
    dateTime.setMonth( 1 );
76
    assertEquals( 0, dateTime.getMonth() );
77
    // Test year
78
    dateTime.setYear( 12345 );
79
    assertEquals( 2008, dateTime.getYear() );
80
    dateTime.setYear( 123 );
81
    assertEquals( 2008, dateTime.getYear() );
82
    dateTime.setDay( 29 );
83
    dateTime.setMonth( 1 );    
84
    dateTime.setYear( 2007 );
85
    assertEquals( 2008, dateTime.getYear() );
86
    // Test hours
87
    dateTime.setHours( 24 );
88
    assertEquals( 0, dateTime.getHours() );
89
    dateTime.setHours( -3 );
90
    assertEquals( 0, dateTime.getHours() );
91
    // Test minutes
92
    dateTime.setMinutes( 65 );
93
    assertEquals( 0, dateTime.getMinutes() );
94
    dateTime.setMinutes( -7 );
95
    assertEquals( 0, dateTime.getMinutes() );
96
    // Test seconds
97
    dateTime.setSeconds( 89 );
98
    assertEquals( 0, dateTime.getSeconds() );
99
    dateTime.setSeconds( -1 );
100
    assertEquals( 0, dateTime.getSeconds() );
101
  }
102
103
  public void testStyle() {
104
    Display display = new Display();
105
    Shell shell = new Shell( display, SWT.NONE );    
106
    // Test SWT.NONE
107
    DateTime dateTime = new DateTime( shell, SWT.NONE );
108
    assertTrue( ( dateTime.getStyle() & SWT.DATE ) != 0 );
109
    assertTrue( ( dateTime.getStyle() & SWT.MEDIUM ) != 0 );
110
    // Test SWT.BORDER
111
    dateTime = new DateTime( shell, SWT.BORDER );
112
    assertTrue( ( dateTime.getStyle() & SWT.DATE ) != 0 );
113
    assertTrue( ( dateTime.getStyle() & SWT.MEDIUM ) != 0 );
114
    assertTrue( ( dateTime.getStyle() & SWT.BORDER ) != 0 );
115
    // Test combination of SWT.DATE | SWT.TIME | SWT.CALENDAR
116
    dateTime = new DateTime( shell, SWT.DATE | SWT.TIME | SWT.CALENDAR );
117
    assertTrue( ( dateTime.getStyle() & SWT.DATE ) != 0 );
118
    assertTrue( ( dateTime.getStyle() & SWT.TIME ) == 0 );
119
    assertTrue( ( dateTime.getStyle() & SWT.CALENDAR ) == 0 );
120
    dateTime = new DateTime( shell, SWT.DATE | SWT.TIME );
121
    assertTrue( ( dateTime.getStyle() & SWT.DATE ) != 0 );
122
    assertTrue( ( dateTime.getStyle() & SWT.TIME ) == 0 );
123
    dateTime = new DateTime( shell, SWT.DATE | SWT.CALENDAR );
124
    assertTrue( ( dateTime.getStyle() & SWT.DATE ) != 0 );
125
    assertTrue( ( dateTime.getStyle() & SWT.CALENDAR ) == 0 );
126
    dateTime = new DateTime( shell, SWT.TIME | SWT.CALENDAR );
127
    assertTrue( ( dateTime.getStyle() & SWT.TIME ) != 0 );
128
    assertTrue( ( dateTime.getStyle() & SWT.CALENDAR ) == 0 );
129
    dateTime = new DateTime( shell, SWT.CALENDAR );
130
    assertTrue( ( dateTime.getStyle() & SWT.CALENDAR ) != 0 );
131
    // Test combination of SWT.MEDIUM | SWT.SHORT | SWT.LONG
132
    dateTime = new DateTime( shell, SWT.DATE
133
                                    | SWT.MEDIUM
134
                                    | SWT.SHORT
135
                                    | SWT.LONG );
136
    assertTrue( ( dateTime.getStyle() & SWT.DATE ) != 0 );
137
    assertTrue( ( dateTime.getStyle() & SWT.MEDIUM ) != 0 );
138
    assertTrue( ( dateTime.getStyle() & SWT.SHORT ) == 0 );
139
    assertTrue( ( dateTime.getStyle() & SWT.LONG ) == 0 );
140
    dateTime = new DateTime( shell, SWT.DATE
141
                             | SWT.MEDIUM
142
                             | SWT.SHORT );
143
    assertTrue( ( dateTime.getStyle() & SWT.DATE ) != 0 );
144
    assertTrue( ( dateTime.getStyle() & SWT.MEDIUM ) != 0 );
145
    assertTrue( ( dateTime.getStyle() & SWT.SHORT ) == 0 );
146
    dateTime = new DateTime( shell, SWT.DATE
147
                             | SWT.MEDIUM                             
148
                             | SWT.LONG );
149
    assertTrue( ( dateTime.getStyle() & SWT.DATE ) != 0 );
150
    assertTrue( ( dateTime.getStyle() & SWT.MEDIUM ) != 0 );    
151
    assertTrue( ( dateTime.getStyle() & SWT.LONG ) == 0 );
152
    dateTime = new DateTime( shell, SWT.TIME                            
153
                             | SWT.SHORT
154
                             | SWT.LONG );
155
    assertTrue( ( dateTime.getStyle() & SWT.TIME ) != 0 );    
156
    assertTrue( ( dateTime.getStyle() & SWT.SHORT ) != 0 );
157
    assertTrue( ( dateTime.getStyle() & SWT.LONG ) == 0 );
158
  }
159
160
  public void testDispose() {
161
    Display display = new Display();
162
    Shell shell = new Shell( display );
163
    DateTime dateTime = new DateTime( shell, SWT.DATE | SWT.MEDIUM );
164
    dateTime.dispose();
165
    assertTrue( dateTime.isDisposed() );
166
  }
167
}
(-)src/org/eclipse/swt/internal/widgets/displaykit/QooxdooResourcesUtil.java (-5 / +14 lines)
Lines 51-58 Link Here
51
    = "org/eclipse/swt/ButtonUtil.js";
51
    = "org/eclipse/swt/ButtonUtil.js";
52
  private static final String COMBO_UTIL_JS
52
  private static final String COMBO_UTIL_JS
53
    = "org/eclipse/swt/ComboUtil.js";
53
    = "org/eclipse/swt/ComboUtil.js";
54
  private static final String TOOL_ITEM_JS =
54
  private static final String TOOL_ITEM_JS
55
    "org/eclipse/swt/ToolItemUtil.js";
55
    = "org/eclipse/swt/ToolItemUtil.js";
56
  private static final String MENU_UTIL_JS
56
  private static final String MENU_UTIL_JS
57
    = "org/eclipse/swt/MenuUtil.js";
57
    = "org/eclipse/swt/MenuUtil.js";
58
  private static final String LINK_UTIL_JS
58
  private static final String LINK_UTIL_JS
Lines 90-96 Link Here
90
  private static final String COMBO_JS
90
  private static final String COMBO_JS
91
    = "org/eclipse/swt/widgets/Combo.js";
91
    = "org/eclipse/swt/widgets/Combo.js";
92
  private static final String GROUP_JS
92
  private static final String GROUP_JS
93
  = "org/eclipse/swt/widgets/Group.js";
93
    = "org/eclipse/swt/widgets/Group.js";
94
  private static final String TEXT_UTIL_JS
94
  private static final String TEXT_UTIL_JS
95
    = "org/eclipse/swt/TextUtil.js";
95
    = "org/eclipse/swt/TextUtil.js";
96
  private static final String SPINNER_JS
96
  private static final String SPINNER_JS
Lines 116-122 Link Here
116
  private static final String QX_CONSTANT_LAYOUT_JS
116
  private static final String QX_CONSTANT_LAYOUT_JS
117
    = "qx/constant/Layout.js";
117
    = "qx/constant/Layout.js";
118
  private static final String QX_CONSTANT_STYLE_JS
118
  private static final String QX_CONSTANT_STYLE_JS
119
    = "qx/constant/Style.js";
119
    = "qx/constant/Style.js";  
120
  private static final String DATE_TIME_DATE_JS
121
	= "org/eclipse/swt/widgets/DateTimeDate.js";
122
  private static final String DATE_TIME_TIME_JS
123
	= "org/eclipse/swt/widgets/DateTimeTime.js";
124
  private static final String DATE_TIME_CALENDAR_JS
125
	= "org/eclipse/swt/widgets/DateTimeCalendar.js";
120
126
121
  private QooxdooResourcesUtil() {
127
  private QooxdooResourcesUtil() {
122
    // prevent intance creation
128
    // prevent intance creation
Lines 183-189 Link Here
183
      register( BROWSER_JS );
189
      register( BROWSER_JS );
184
      register( PROGRESS_BAR_JS );
190
      register( PROGRESS_BAR_JS );
185
      register( FONT_SIZE_CALCULATION_JS );
191
      register( FONT_SIZE_CALCULATION_JS );
186
      register( CLABEL_UTIL_JS );
192
      register( CLABEL_UTIL_JS );      
193
      register( DATE_TIME_DATE_JS );
194
      register( DATE_TIME_TIME_JS );
195
      register( DATE_TIME_CALENDAR_JS );
187
196
188
      // register contributions
197
      // register contributions
189
      registerContributions();
198
      registerContributions();
(-)js/org/eclipse/swt/theme/AppearancesBase.js (+11 lines)
Lines 1746-1751 Link Here
1746
        opacity : 0.2
1746
        opacity : 0.2
1747
      };
1747
      };
1748
    }
1748
    }
1749
  },
1750
  
1751
  // ------------------------------------------------------------------------
1752
  // DateTime
1753
  
1754
  "datetime-date" : {
1755
    style : function( states ) {
1756
      return {
1757
        border : states.rwt_BORDER ? "control.BORDER.border" : "control.border"
1758
      }
1759
    }
1749
  }
1760
  }
1750
}
1761
}
1751
1762
(-)src/org/eclipse/swt/internal/widgets/datetimekit/DateTimeLCA.java (+88 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002-2008 Innoopract Informationssysteme GmbH. All rights
3
 * reserved. This program and the accompanying materials are made available
4
 * under the terms of the Eclipse Public License v1.0 which accompanies this
5
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
6
 * Contributors: Innoopract Informationssysteme GmbH - initial API and
7
 * implementation
8
 ******************************************************************************/
9
package org.eclipse.swt.internal.widgets.datetimekit;
10
11
import java.io.IOException;
12
import java.text.MessageFormat;
13
14
import org.eclipse.rwt.lifecycle.AbstractWidgetLCA;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.widgets.*;
17
18
public class DateTimeLCA extends AbstractWidgetLCA {
19
20
  private static final AbstractDateTimeLCADelegate DATE_LCA = new DateTimeDateLCA();
21
  private static final AbstractDateTimeLCADelegate TIME_LCA = new DateTimeTimeLCA();
22
  private static final AbstractDateTimeLCADelegate CALENDAR_LCA = new DateTimeCalendarLCA();
23
24
  public void preserveValues( final Widget widget ) {
25
    getDelegate( widget ).preserveValues( ( DateTime )widget );
26
  }
27
28
  public void readData( final Widget widget ) {
29
    getDelegate( widget ).readData( ( DateTime )widget );
30
  }
31
32
  public void renderInitialization( final Widget widget ) throws IOException {
33
    getDelegate( widget ).renderInitialization( ( DateTime )widget );
34
  }
35
36
  public void renderChanges( final Widget widget ) throws IOException {
37
    getDelegate( widget ).renderChanges( ( DateTime )widget );
38
  }
39
40
  public void renderDispose( final Widget widget ) throws IOException {
41
    getDelegate( widget ).renderDispose( ( DateTime )widget );
42
  }
43
44
  public void createResetHandlerCalls( final String typePoolId )
45
    throws IOException
46
  {
47
    getDelegate( typePoolId ).createResetHandlerCalls( typePoolId );
48
  }
49
50
  public String getTypePoolId( final Widget widget ) {
51
    // TODO [rh] disabled pooling, see bugs prefixed with [pooling]
52
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=204107
53
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=199142
54
    // return getDelegate( widget ).getTypePoolId( ( DateTime )widget );
55
    return null;
56
  }
57
58
  private static AbstractDateTimeLCADelegate getDelegate( final String tpId ) {
59
    AbstractDateTimeLCADelegate result;
60
    if( tpId.startsWith( DateTimeDateLCA.TYPE_POOL_ID ) ) {
61
      result = DATE_LCA;
62
    } else if( tpId.startsWith( DateTimeTimeLCA.TYPE_POOL_ID ) ) {
63
      result = TIME_LCA;
64
    } else if( tpId.startsWith( DateTimeCalendarLCA.TYPE_POOL_ID ) ) {
65
      result = CALENDAR_LCA;
66
    } else {
67
      String txt = "The typePoolId ''{0}'' is not supported.";
68
      String msg = MessageFormat.format( txt, new Object[]{
69
        tpId
70
      } );
71
      throw new IllegalArgumentException( msg );
72
    }
73
    return result;
74
  }
75
76
  private static AbstractDateTimeLCADelegate getDelegate( final Widget widget )
77
  {
78
    AbstractDateTimeLCADelegate result;
79
    if( ( widget.getStyle() & SWT.DATE ) != 0 ) {
80
      result = DATE_LCA;
81
    } else if( ( widget.getStyle() & SWT.TIME ) != 0 ) {
82
      result = TIME_LCA;
83
    } else {
84
      result = CALENDAR_LCA;
85
    }
86
    return result;
87
  }
88
}
(-)js/org/eclipse/swt/widgets/DateTimeDate.js (+701 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002-2008 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     Innoopract Informationssysteme GmbH - initial API and implementation
10
 ******************************************************************************/
11
12
qx.Class.define( "org.eclipse.swt.widgets.DateTimeDate", {
13
  extend : qx.ui.layout.CanvasLayout,
14
15
  construct : function( style, monthNames, weekdayNames, 
16
                        dateSeparator, datePattern ) {
17
    this.base( arguments );
18
    this.setAppearance( "datetime-date" );
19
    
20
    // Get styles
21
    this._short = qx.lang.String.contains( style, "short" );
22
    this._medium = qx.lang.String.contains( style, "medium" );
23
    this._long = qx.lang.String.contains( style, "long" );
24
    
25
    // Has selection listener
26
    this._hasSelectionListener = false;
27
    
28
    // Flag that indicates that the next request can be sent
29
    this._readyToSendChanges = true;
30
    
31
    // Get names of weekdays and months
32
    this._weekday = weekdayNames;
33
    this._monthname = monthNames;
34
        
35
    // Date pattern
36
    this._datePattern = datePattern;
37
    
38
    // Add listeners for font, background and foregraund color change
39
    this.addEventListener( "changeFont", this._rwt_onChangeFont, this );
40
    this.addEventListener( "changeTextColor", this._rwt_onChangeTextColor, this );
41
    this.addEventListener( "changeBackgroundColor", this._rwt_onChangeBackgoundColor, this );
42
    
43
    // Background color
44
    this._backgroundColor = "white";
45
    // Foreground color
46
    this._foregroundColor = "black";
47
    
48
    // Focused text field
49
    this._focusedTextField = null;    
50
    // Weekday
51
    this._weekdayTextField = new qx.ui.form.TextField;
52
    this._weekdayTextField.set({  
53
      textAlign: "center",
54
      selectable: false,
55
      readOnly: true,
56
      border: null,
57
      backgroundColor: this._backgroundColor,
58
      textColor : this._foregroundColor
59
    });
60
    if( this._long ) {
61
      this.add( this._weekdayTextField ); 
62
    }
63
    this._weekdayTextField.addEventListener( "keypress", this._onKeyPress, this );
64
    this._weekdayTextField.addEventListener( "contextmenu", this._onContextMenu, this );
65
    // Separator
66
    this._separator0 = new qx.ui.basic.Label(",");        
67
    this._separator0.set({
68
      paddingTop: 3,
69
      backgroundColor: this._backgroundColor,
70
      textColor : this._foregroundColor
71
    });
72
    this._separator0.addEventListener( "contextmenu", this._onContextMenu, this );
73
    if( this._long ) {
74
      this.add(this._separator0);
75
    }    
76
    // Month       
77
    this._monthTextField = new qx.ui.form.TextField;
78
    this._monthTextField.set({        
79
      textAlign: this._medium ? "right" : "center",
80
      selectable: false,
81
      readOnly: true,
82
      border: null,
83
      backgroundColor: this._backgroundColor,
84
      textColor : this._foregroundColor
85
    });
86
    // Integer value of the month 
87
    this._monthInt = 1;
88
    if( this._medium ) {
89
      this._monthTextField.setValue( this._monthInt );
90
    } else {   
91
      this._monthTextField.setValue( this._monthname[ this._monthInt - 1 ] );
92
    }
93
    this._monthTextField.addEventListener( "click",  this._onClick, this ); 
94
    this._monthTextField.addEventListener( "keypress", this._onKeyPress, this );
95
    this._monthTextField.addEventListener( "keyup", this._onKeyUp, this ); 
96
    this._monthTextField.addEventListener( "contextmenu", this._onContextMenu, this );
97
    this.add( this._monthTextField );
98
    // Separator 
99
    this._separator1 = new qx.ui.basic.Label( dateSeparator );        
100
    this._separator1.set({
101
      paddingTop: 3,
102
      backgroundColor: this._backgroundColor,
103
      textColor : this._foregroundColor
104
    });
105
    this._separator1.addEventListener( "contextmenu", this._onContextMenu, this );
106
    if( this._medium ) {
107
      this.add(this._separator1);
108
    }   
109
    // Date     
110
    this._dayTextField = new qx.ui.form.TextField;
111
    this._dayTextField.set({
112
      maxLength: 2,
113
      textAlign: "right",
114
      selectable: false,
115
      readOnly: true,       
116
      border: null,
117
      backgroundColor: this._backgroundColor,
118
      textColor : this._foregroundColor
119
    });
120
    this._dayTextField.setValue( 1 );
121
    this._dayTextField.addEventListener( "click",  this._onClick, this );
122
    this._dayTextField.addEventListener( "keypress", this._onKeyPress, this );
123
    this._dayTextField.addEventListener( "keyup", this._onKeyUp, this );  
124
    this._dayTextField.addEventListener( "contextmenu", this._onContextMenu, this );  
125
    if( !this._short ) {
126
      this.add( this._dayTextField );
127
    }
128
    // Separator
129
    this._separator2 = new qx.ui.basic.Label( "," );        
130
    this._separator2.set({
131
      paddingTop: 3,
132
      backgroundColor: this._backgroundColor,
133
      textColor : this._foregroundColor
134
    });
135
    if( this._medium ) {
136
      this._separator2.setText( dateSeparator );
137
    }
138
    this._separator2.addEventListener( "contextmenu", this._onContextMenu, this );  
139
    this.add(this._separator2);	    
140
    // Year    
141
    this._yearTextField = new qx.ui.form.TextField;  
142
    this._yearTextField.set({        
143
      maxLength: 4,
144
      textAlign: "right",
145
      selectable: false,
146
      readOnly: true,
147
      border: null,
148
      backgroundColor: this._backgroundColor,
149
      textColor : this._foregroundColor
150
    }); 
151
    // Last valid year
152
    this._lastValidYear = 1970;
153
    this._yearTextField.setValue( this._lastValidYear );
154
    this._yearTextField.addEventListener( "click",  this._onClick, this );
155
    this._yearTextField.addEventListener( "focusout",  this._onFocusOut, this );
156
    this._yearTextField.addEventListener( "keypress", this._onKeyPress, this );
157
    this._yearTextField.addEventListener( "keyup", this._onKeyUp, this ); 
158
    this._yearTextField.addEventListener( "contextmenu", this._onContextMenu, this );  
159
    this.add( this._yearTextField ); 
160
    // Spinner 
161
    this._spinner = new qx.ui.form.Spinner;
162
    this._spinner.set({
163
      wrap: true,
164
      border: null,
165
      backgroundColor: this._backgroundColor,
166
      textColor : this._foregroundColor
167
    });
168
    this._spinner.setMin( 1 ); 
169
    this._spinner.setMax( 12 );        
170
    this._spinner.setValue( this._monthInt );
171
    this._spinner.addEventListener( "change",  this._onSpinnerChange, this );
172
    this._spinner.addEventListener( "mousedown",  this._onSpinnerMouseDown, this );
173
    this._spinner.addEventListener( "mouseup",  this._onSpinnerMouseUp, this ); 
174
    this._spinner.addEventListener( "keypress", this._onKeyPress, this );
175
    this._spinner.addEventListener( "keyup", this._onKeyUp, this );
176
    this.add( this._spinner );
177
    // Set the default focused text field
178
    this._focusedTextField = this._monthTextField;  
179
    // Set the weekday
180
    this._setWeekday();
181
      
182
  },
183
184
  destruct : function() {
185
  	this.removeEventListener( "changeFont", this._rwt_onChangeFont, this );
186
    this.removeEventListener( "changeTextColor", this._rwt_onChangeTextColor, this );
187
    this.removeEventListener( "changeBackgroundColor", this._rwt_onChangeBackgoundColor, this );
188
    this._weekdayTextField.removeEventListener( "keypress", this._onKeyPress, this );
189
    this._weekdayTextField.removeEventListener( "contextmenu", this._onContextMenu, this );
190
    this._monthTextField.removeEventListener( "click",  this._onClick, this ); 
191
    this._monthTextField.removeEventListener( "keypress", this._onKeyPress, this );
192
    this._monthTextField.removeEventListener( "keyup", this._onKeyUp, this );
193
    this._monthTextField.removeEventListener( "contextmenu", this._onContextMenu, this );
194
    this._dayTextField.removeEventListener( "click",  this._onClick, this );
195
    this._dayTextField.removeEventListener( "keypress", this._onKeyPress, this );
196
    this._dayTextField.removeEventListener( "keyup", this._onKeyUp, this );
197
    this._dayTextField.removeEventListener( "contextmenu", this._onContextMenu, this );
198
    this._yearTextField.removeEventListener( "click",  this._onClick, this );
199
    this._yearTextField.removeEventListener( "focusout",  this._onFocusOut, this );
200
    this._yearTextField.removeEventListener( "keypress", this._onKeyPress, this );
201
    this._yearTextField.removeEventListener( "keyup", this._onKeyUp, this );
202
    this._yearTextField.removeEventListener( "contextmenu", this._onContextMenu, this );
203
    this._spinner.removeEventListener( "change",  this._onSpinnerChange, this ); 
204
    this._spinner.removeEventListener( "mousedown",  this._onSpinnerMouseDown, this ); 
205
    this._spinner.removeEventListener( "mouseup",  this._onSpinnerMouseUp, this ); 
206
    this._spinner.removeEventListener( "keypress", this._onKeyPress, this );
207
    this._spinner.removeEventListener( "keyup", this._onKeyUp, this ); 
208
    this._separator0.removeEventListener( "contextmenu", this._onContextMenu, this );
209
    this._separator1.removeEventListener( "contextmenu", this._onContextMenu, this );
210
    this._separator2.removeEventListener( "contextmenu", this._onContextMenu, this );
211
    this._disposeObjects( "_weekdayTextField",
212
                          "_monthTextField",
213
                          "_dayTextField",
214
                          "_yearTextField",
215
                          "_focusedTextField",
216
                          "_spinner",
217
                          "_separator0",
218
                          "_separator1",
219
                          "_separator2" );
220
  },
221
222
  statics : {
223
    WEEKDAY_TEXTFIELD : 0,
224
    DATE_TEXTFIELD : 1,
225
    MONTH_TEXTFIELD : 2,
226
    YEAR_TEXTFIELD : 3,
227
    WEEKDAY_MONTH_SEPARATOR : 4,
228
    MONTH_DATE_SEPARATOR : 5,
229
    DATE_YEAR_SEPARATOR : 6,
230
    SPINNER : 7,
231
    
232
    _isNoModifierPressed : function( evt ) {
233
      return    !evt.isCtrlPressed() 
234
             && !evt.isShiftPressed() 
235
             && !evt.isAltPressed() 
236
             && !evt.isMetaPressed();      
237
    }
238
  },
239
240
  members : {    
241
  	_rwt_onChangeFont : function( evt ) {
242
  	  var value = evt.getData();
243
  	  this._weekdayTextField.setFont( value );
244
      this._dayTextField.setFont( value );
245
      this._monthTextField.setFont( value );
246
      this._yearTextField.setFont( value );
247
    },
248
    
249
    _rwt_onChangeTextColor : function( evt ) {
250
      var value = evt.getData();
251
      this._foregroundColor = value;
252
      this._weekdayTextField.setTextColor( value );
253
      this._dayTextField.setTextColor( value );
254
      this._monthTextField.setTextColor( value );
255
      this._yearTextField.setTextColor( value ); 
256
      this._separator0.setTextColor( value );
257
      this._separator1.setTextColor( value );
258
      this._separator2.setTextColor( value );     
259
    },
260
    
261
    _rwt_onChangeBackgoundColor : function( evt ) {
262
      var value = evt.getData();
263
      this._backgroundColor = value;
264
      this._weekdayTextField.setBackgroundColor( value );
265
      this._dayTextField.setBackgroundColor( value );
266
      this._monthTextField.setBackgroundColor( value );
267
      this._yearTextField.setBackgroundColor( value );
268
      this._separator0.setBackgroundColor( value );
269
      this._separator1.setBackgroundColor( value );
270
      this._separator2.setBackgroundColor( value );
271
      this._spinner.setBackgroundColor( value );
272
    },
273
    
274
    _onContextMenu : function( evt ) {     
275
      var menu = this.getContextMenu();      
276
      if( menu != null ) {
277
        menu.setLocation( evt.getPageX(), evt.getPageY() );
278
        menu.setOpener( this );
279
        menu.show();
280
        evt.stopPropagation();
281
      }
282
    },
283
    
284
    _onClick : function( evt ) {    	     
285
      this._setFocusedTextField( evt.getTarget() );
286
    },
287
    
288
    _setFocusedTextField :  function( textField ) {
289
    	var tmpValue;
290
      this._focusedTextField.setBackgroundColor( this._backgroundColor );
291
      this._focusedTextField.setTextColor( this._foregroundColor );
292
    	// Set focused text field to null
293
      this._focusedTextField = null;
294
      if( textField === this._dayTextField ) {
295
        this._spinner.setMin( 1 );            
296
        this._spinner.setMax( this._getDaysInMonth() ); 
297
        tmpValue = this._removeLeadingZero( this._dayTextField.getValue() );
298
        this._spinner.setValue( parseInt( tmpValue ) );
299
      } else if( textField === this._monthTextField ) { 
300
        this._spinner.setMin( 1 );           
301
        this._spinner.setMax( 12 );
302
        this._spinner.setValue( this._monthInt );
303
      } else if( textField === this._yearTextField ) {
304
        this._spinner.setMin( 1752 );                        
305
        this._spinner.setMax( 9999 );                            
306
        this._spinner.setValue( this._lastValidYear );
307
      }
308
      // Set focused text field
309
      this._focusedTextField = textField;
310
      // Set highlight on focused text field
311
      this._focusedTextField.setBackgroundColor( "#0A246A" );
312
      this._focusedTextField.setTextColor( "white" );
313
      // Request focus
314
      this._focusedTextField.setFocused( true );
315
    },
316
    
317
    _onFocusOut : function( evt ) {
318
	    if( evt.getTarget() === this._yearTextField ) {
319
		    this._checkAndApplyYearValue();
320
	    }    	
321
    }, 
322
    
323
    _onSpinnerChange : function( evt ) {          
324
      if( this._focusedTextField != null ) {      	
325
      	var oldValue = this._focusedTextField.getValue();
326
        // Set the value
327
        if( this._focusedTextField === this._monthTextField ) {
328
          this._monthInt = this._spinner.getValue();
329
          if( this._medium ) {
330
					  this._focusedTextField.setValue( this._addLeadingZero( this._monthInt ) );			      
331
				  } else {   
332
					  this._focusedTextField.setValue( this._monthname[ this._monthInt - 1 ] );
333
				  }          
334
        } else if( this._focusedTextField === this._yearTextField ) {
335
        	  this._lastValidYear = this._spinner.getValue();
336
        	  this._focusedTextField.setValue( this._spinner.getValue() );
337
        } else {
338
        	this._focusedTextField.setValue( this._addLeadingZero( this._spinner.getValue() ) );
339
        }
340
        // Adjust date field
341
        if( this._focusedTextField == this._monthTextField || // month
342
            this._focusedTextField == this._yearTextField ) { // year          
343
          var dateValue = this._dayTextField.getValue();
344
          if( dateValue > this._getDaysInMonth() ) {
345
            this._dayTextField.setValue( this._getDaysInMonth() );
346
          }
347
        }  
348
        // Set the weekday field
349
        this._setWeekday();
350
        
351
        var newValue = this._focusedTextField.getValue();
352
        if( oldValue != newValue && this._readyToSendChanges ) {
353
          this._readyToSendChanges = false;
354
          // Send changes
355
          qx.client.Timer.once( this._sendChanges, this, 500 );
356
        }
357
      }
358
    },
359
    
360
    _onSpinnerMouseDown : function( evt ) {
361
    	// Set highlight on focused text field
362
      this._focusedTextField.setBackgroundColor( "#0A246A" );
363
      this._focusedTextField.setTextColor( "white" );      
364
    },
365
    
366
    _onSpinnerMouseUp : function( evt ) {      
367
      this._focusedTextField.setFocused( true );
368
    },
369
    
370
    _onKeyPress : function( evt ) {
371
      var keyIdentifier = evt.getKeyIdentifier();
372
      if( org.eclipse.swt.widgets.DateTimeDate._isNoModifierPressed( evt ) ) {
373
        switch( keyIdentifier ) {
374
          case "Left":
375
            if( this._datePattern == "MDY") {
376
            	this._rollLeft( this._monthTextField,
377
            	                this._dayTextField,
378
            	                this._yearTextField );
379
            } else if( this._datePattern == "DMY") {
380
            	this._rollLeft( this._dayTextField,
381
                              this._monthTextField,
382
                              this._yearTextField );
383
            } else {
384
            	if( this._medium ) {
385
            		this._rollLeft( this._yearTextField,
386
            		                this._monthTextField,
387
            		                this._dayTextField );
388
            	} else {
389
            		this._rollLeft( this._monthTextField,
390
                                this._dayTextField,
391
                                this._yearTextField );
392
            	}
393
            }
394
            break;
395
          case "Right":
396
            if( this._datePattern == "MDY") {
397
              this._rollRight( this._monthTextField,
398
                               this._dayTextField,
399
                               this._yearTextField );
400
            } else if( this._datePattern == "DMY") {
401
              this._rollRight( this._dayTextField,
402
                               this._monthTextField,
403
                               this._yearTextField );
404
            } else {
405
              if( this._medium ) {
406
                this._rollRight( this._yearTextField,
407
                                 this._monthTextField,
408
                                 this._dayTextField );
409
              } else {
410
                this._rollRight( this._monthTextField,
411
                                 this._dayTextField,
412
                                 this._yearTextField );
413
              }
414
            }
415
            break; 
416
          case "Up":
417
            if( this._focusedTextField === this._yearTextField ) {
418
            	this._checkAndApplyYearValue();
419
            }
420
            var value = this._spinner.getValue();
421
            if( value == this._spinner.getMax() ) {
422
              this._spinner.setValue( this._spinner.getMin() );
423
            } else {
424
              this._spinner.setValue( value + 1 );
425
            }
426
            break;
427
          case "Down":
428
            if( this._focusedTextField === this._yearTextField ) {
429
              this._checkAndApplyYearValue();
430
            }
431
            var value = this._spinner.getValue();
432
            if( value == this._spinner.getMin() ) {
433
              this._spinner.setValue( this._spinner.getMax() );
434
            } else {
435
              this._spinner.setValue( value - 1 );
436
            }
437
            break;
438
        }
439
      }
440
    },
441
    
442
    _rollRight : function( first, second, third ) {
443
    	// Apply year value
444
    	if( this._focusedTextField === this._yearTextField ) {
445
        this._checkAndApplyYearValue();
446
    	}
447
    	// Roll right
448
    	if( this._focusedTextField === first ){
449
    		if( second.isSeeable() ) {
450
    		  this._setFocusedTextField( second );
451
    		} else {
452
    			this._setFocusedTextField( third );
453
    		}
454
    	} else if( this._focusedTextField === second ) {
455
    		if( third.isSeeable() ) {
456
    		  this._setFocusedTextField( third );
457
    		} else {
458
    			this._setFocusedTextField( first );
459
    		}  
460
    	} else if( this._focusedTextField === third ) {
461
    		if( first.isSeeable() ) {
462
    		  this._setFocusedTextField( first );
463
    		} else {
464
    			this._setFocusedTextField( second );
465
    		}
466
    	}
467
    },
468
    
469
    _rollLeft : function( first, second, third ) {
470
    	// Apply year value
471
      if( this._focusedTextField === this._yearTextField ) {
472
        this._checkAndApplyYearValue();
473
      }
474
      // Roll left
475
      if( this._focusedTextField === first ){
476
        if( third.isSeeable() ) {
477
          this._setFocusedTextField( third );
478
        } else {
479
          this._setFocusedTextField( second );
480
        }
481
      } else if( this._focusedTextField === second ) {
482
        if( first.isSeeable() ) {
483
          this._setFocusedTextField( first );
484
        } else {
485
          this._setFocusedTextField( third );
486
        }  
487
      } else if( this._focusedTextField === third ) {
488
        if( second.isSeeable() ) {
489
          this._setFocusedTextField( second );
490
        } else {
491
          this._setFocusedTextField( first );
492
        }
493
      }
494
    },
495
    
496
    _onKeyUp : function( evt ) {
497
    	var keypress = evt.getKeyIdentifier();
498
    	var value = this._focusedTextField.getComputedValue();
499
    	value = this._removeLeadingZero( value );
500
    	if( org.eclipse.swt.widgets.DateTimeDate._isNoModifierPressed( evt ) ) {
501
	    	switch( keypress ) {
502
	        case "Tab":	        
503
	          this._focusedTextField.setBackgroundColor( this._backgroundColor );
504
	          this._focusedTextField.setTextColor( this._foregroundColor );
505
	          break;
506
	        case "0": case "1": case "2": case "3": case "4":
507
	        case "5": case "6": case "7": case "8": case "9":
508
	          this._focusedTextField.setFocused( true );		      
509
			      var maxChars = this._focusedTextField.getMaxLength(); 
510
			      if( this._focusedTextField === this._monthTextField ) {
511
			        value = "" + this._monthInt;
512
			        maxChars = 2;
513
			      }  
514
			      var newValue = keypress;    
515
			      if( value.length < maxChars ) {
516
			      	newValue = value + keypress;
517
			      }	
518
			      var intValue = parseInt( newValue );  
519
			      if( this._focusedTextField === this._dayTextField ||
520
			          this._focusedTextField === this._monthTextField ) {                    
521
			        if( intValue >= this._spinner.getMin() &&
522
			            intValue <= this._spinner.getMax() ) {
523
			          this._spinner.setValue( intValue );
524
			        } else {
525
			        	// Do it again without adding the old value
526
			          newValue = keypress;
527
	              intValue = parseInt( newValue );
528
			          if( intValue >= this._spinner.getMin() &&
529
			              intValue <= this._spinner.getMax() ) {
530
			            this._spinner.setValue( intValue );
531
			          }
532
			        }
533
			      } else if( this._focusedTextField == this._yearTextField ) { 		                             
534
			        this._focusedTextField.setValue( newValue );
535
			      }
536
	          break;
537
	        case "Home":
538
	          var newValue = this._spinner.getMin();
539
	          this._spinner.setValue( newValue );	          
540
	          break;
541
	        case "End":
542
	          var newValue = this._spinner.getMax();
543
	          this._spinner.setValue( newValue );	          
544
	          break;    
545
	    	}
546
    	}
547
    },
548
    
549
    _getDaysInMonth : function() {
550
      var result = 31;
551
      var tmpMonth = this._monthInt - 1;
552
      var tmpYear = parseInt( this._yearTextField.getValue() );
553
      var tmpDate = new Date();
554
      tmpDate.setYear( tmpYear );
555
      tmpDate.setMonth( tmpMonth );
556
      // Test 31
557
      tmpDate.setDate( 31 );
558
      if( tmpDate.getMonth() != tmpMonth ) {
559
      	result = 30;
560
      	tmpDate.setMonth( tmpMonth );
561
      	// Test 30
562
      	tmpDate.setDate( 30 );
563
      	if( tmpDate.getMonth() != tmpMonth ) {
564
      		result = 29;
565
      		tmpDate.setMonth( tmpMonth );
566
          // Test 29
567
          tmpDate.setDate( 29 );
568
          if( tmpDate.getMonth() != tmpMonth ) {
569
          	result = 28;
570
          }
571
      	}
572
      }
573
      return result; 
574
    },
575
    
576
    _setWeekday : function() {    	
577
    	var tmpDate = new Date();
578
    	tmpDate.setDate( parseInt( this._dayTextField.getValue() ) );
579
    	tmpDate.setMonth( this._monthInt - 1 );
580
    	tmpDate.setFullYear( parseInt( this._yearTextField.getValue() ) );
581
    	this._weekdayTextField.setValue( this._weekday[ tmpDate.getDay() + 1 ] );
582
    },
583
    
584
    _checkAndApplyYearValue : function() {       
585
    	var oldValue = this._lastValidYear;    	
586
      var value = parseInt( this._yearTextField.getValue() );        
587
      if( value >= 0 && value <= 29 ) {
588
      	this._lastValidYear = 2000 + value;
589
      }	else if( value >= 30 && value <= 99 ) {
590
      	this._lastValidYear = 1900 + value;
591
      } else if( value >= 1752 ) {
592
      	this._lastValidYear = value;
593
      }
594
      if( oldValue != this._lastValidYear ) {
595
				this._spinner.setValue( this._lastValidYear );
596
      }
597
    },
598
    
599
    _addLeadingZero : function( value ) {
600
      return value < 10 ? "0" + value : value;
601
    },
602
    
603
    _removeLeadingZero : function( value ) {
604
      var result = value;
605
      if( value.length == 2 ) {
606
        var firstChar = value.substring( 0, 1 );
607
        if( firstChar == "0" ) result = value.substring( 1 );
608
      }
609
      return result;
610
    },
611
    
612
    _sendChanges : function() {
613
      if( !org_eclipse_rap_rwt_EventUtil_suspend ) {        
614
        var widgetManager = org.eclipse.swt.WidgetManager.getInstance();
615
        var req = org.eclipse.swt.Request.getInstance();
616
        var id = widgetManager.findIdByWidget( this );        
617
        req.addParameter( id + ".date", this._removeLeadingZero( this._dayTextField.getValue() ) );
618
        req.addParameter( id + ".month", this._monthInt - 1 );
619
        req.addParameter( id + ".year", this._lastValidYear );
620
        if( this._hasSelectionListener ) {
621
          req.addEvent( "org.eclipse.swt.events.widgetSelected", id );
622
          req.send();
623
        }
624
        this._readyToSendChanges = true;
625
      }
626
    },
627
    
628
    setMonth : function( value ) { 
629
      this._monthInt = value + 1;
630
      if( this._medium ) {
631
        this._monthTextField.setValue( this._addLeadingZero( this._monthInt ) );
632
      } else {   
633
        this._monthTextField.setValue( this._monthname[ this._monthInt - 1 ] );
634
      }
635
      if( this._focusedTextField === this._monthTextField ) {
636
        this._spinner.setValue( this._monthInt );
637
      }
638
      // Set the weekday
639
      this._setWeekday();
640
    },
641
    
642
    setDay : function( value ) {
643
    	this._dayTextField.setValue( this._addLeadingZero( value ) );
644
    	if( this._focusedTextField === this._dayTextField ) {
645
        this._spinner.setValue( value );
646
      }
647
      // Set the weekday
648
      this._setWeekday();
649
    },
650
    
651
    setYear : function( value ) {
652
      this._lastValidYear = value;
653
      this._yearTextField.setValue( value );
654
      if( this._focusedTextField === this._yearTextField ) {
655
        this._spinner.setValue( value );
656
      }
657
      // Set the weekday
658
      this._setWeekday();
659
    },
660
    
661
    setHasSelectionListener : function( value ) {
662
      this._hasSelectionListener = value;
663
    },
664
    
665
    setBounds : function( ind, x, y, width, height ) {
666
    	var widget;
667
    	switch( ind ) {
668
    		case org.eclipse.swt.widgets.DateTimeDate.WEEKDAY_TEXTFIELD:
669
	    		widget = this._weekdayTextField;
670
    		break;
671
    		case org.eclipse.swt.widgets.DateTimeDate.DATE_TEXTFIELD:
672
    		  widget = this._dayTextField;
673
        break;
674
        case org.eclipse.swt.widgets.DateTimeDate.MONTH_TEXTFIELD:
675
          widget = this._monthTextField;
676
        break;
677
        case org.eclipse.swt.widgets.DateTimeDate.YEAR_TEXTFIELD:
678
          widget = this._yearTextField;
679
        break;
680
        case org.eclipse.swt.widgets.DateTimeDate.WEEKDAY_MONTH_SEPARATOR:
681
          widget = this._separator0;
682
        break;
683
        case org.eclipse.swt.widgets.DateTimeDate.MONTH_DATE_SEPARATOR:
684
          widget = this._separator1;
685
        break;
686
        case org.eclipse.swt.widgets.DateTimeDate.DATE_YEAR_SEPARATOR:
687
          widget = this._separator2;
688
        break;
689
        case org.eclipse.swt.widgets.DateTimeDate.SPINNER:
690
          widget = this._spinner;
691
        break;
692
    	}
693
    	widget.set({        
694
        left: x,
695
        top: y,
696
        width: width,
697
        height: height
698
      });  
699
    }
700
  }
701
} );
(-)src/org/eclipse/swt/internal/widgets/datetimekit/DateTimeLCAUtil.java (+68 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002-2008 Innoopract Informationssysteme GmbH. All rights
3
 * reserved. This program and the accompanying materials are made available
4
 * under the terms of the Eclipse Public License v1.0 which accompanies this
5
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
6
 * Contributors: Innoopract Informationssysteme GmbH - initial API and
7
 * implementation
8
 ******************************************************************************/
9
package org.eclipse.swt.internal.widgets.datetimekit;
10
11
import java.io.IOException;
12
13
import org.eclipse.rwt.lifecycle.*;
14
import org.eclipse.swt.events.SelectionEvent;
15
import org.eclipse.swt.graphics.Rectangle;
16
import org.eclipse.swt.internal.widgets.IDateTimeAdapter;
17
import org.eclipse.swt.internal.widgets.Props;
18
import org.eclipse.swt.widgets.DateTime;
19
20
final class DateTimeLCAUtil {
21
22
  private DateTimeLCAUtil() {
23
    // prevent instantiation
24
  }
25
  
26
  static IDateTimeAdapter getDateTimeAdapter( final DateTime dateTime ) {
27
    return ( IDateTimeAdapter )dateTime.getAdapter( IDateTimeAdapter.class );
28
  }
29
  
30
  static void preserveSubWidgetBounds( final DateTime dateTime,
31
                                       final int subWidgetID ) {
32
    IWidgetAdapter adapter = WidgetUtil.getAdapter( dateTime );
33
    IDateTimeAdapter dateTimeAdapter = getDateTimeAdapter( dateTime );
34
    Rectangle subWidgetBounds = dateTimeAdapter.getBounds( subWidgetID );
35
    adapter.preserve( subWidgetID + "_BOUNDS", subWidgetBounds );
36
  }
37
  
38
  static void writeSubWidgetBounds( final DateTime dateTime,
39
                                    final int subWidgetID )
40
    throws IOException    
41
  {
42
    IDateTimeAdapter dateTimeAdapter = getDateTimeAdapter( dateTime );    
43
    Rectangle newValue = dateTimeAdapter.getBounds( subWidgetID );
44
    if( WidgetLCAUtil.hasChanged( dateTime, 
45
                                  subWidgetID + "_BOUNDS", newValue ) ) {
46
      JSWriter writer = JSWriter.getWriterFor( dateTime );
47
      writer.call( "setBounds", new Object[]{
48
        new Integer( subWidgetID ),
49
        new Integer( newValue.x ),
50
        new Integer( newValue.y ),
51
        new Integer( newValue.width ),
52
        new Integer( newValue.height )
53
      });
54
    }
55
  }
56
  
57
  static void writeListener( final DateTime dateTime )
58
    throws IOException
59
  {  
60
    boolean hasListener = SelectionEvent.hasListener( dateTime );
61
    Boolean newValue = Boolean.valueOf( hasListener );
62
    String prop = Props.SELECTION_LISTENERS;
63
    if( WidgetLCAUtil.hasChanged( dateTime, prop, newValue, Boolean.FALSE ) ) {
64
      JSWriter writer = JSWriter.getWriterFor( dateTime );
65
      writer.set( "hasSelectionListener", newValue );
66
    }
67
  }
68
}
(-)src/org/eclipse/swt/internal/widgets/datetimekit/DateTimeTimeLCA.java (+171 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002-2008 Innoopract Informationssysteme GmbH. All rights
3
 * reserved. This program and the accompanying materials are made available
4
 * under the terms of the Eclipse Public License v1.0 which accompanies this
5
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
6
 * Contributors: Innoopract Informationssysteme GmbH - initial API and
7
 * implementation
8
 ******************************************************************************/
9
package org.eclipse.swt.internal.widgets.datetimekit;
10
11
import java.io.IOException;
12
13
import org.eclipse.rwt.lifecycle.*;
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.events.SelectionEvent;
16
import org.eclipse.swt.internal.widgets.IDateTimeAdapter;
17
import org.eclipse.swt.internal.widgets.Props;
18
import org.eclipse.swt.widgets.DateTime;
19
20
public class DateTimeTimeLCA extends AbstractDateTimeLCADelegate {
21
22
  static final String TYPE_POOL_ID = DateTimeTimeLCA.class.getName();
23
  // Property names for preserveValues
24
  static final String PROP_HOURS = "hours";
25
  static final String PROP_MINUTES = "minutes";
26
  static final String PROP_SECONDS = "seconds";
27
28
  // Property names for preserveValues
29
  void preserveValues( final DateTime dateTime ) {
30
    ControlLCAUtil.preserveValues( dateTime );
31
    IWidgetAdapter adapter = WidgetUtil.getAdapter( dateTime );
32
    boolean hasListeners = SelectionEvent.hasListener( dateTime );
33
    adapter.preserve( Props.SELECTION_LISTENERS,
34
                      Boolean.valueOf( hasListeners ) );
35
    adapter.preserve( PROP_HOURS, 
36
                      new Integer( dateTime.getHours() ) );
37
    adapter.preserve( PROP_MINUTES, 
38
                      new Integer( dateTime.getMinutes() ) );
39
    adapter.preserve( PROP_SECONDS, 
40
                      new Integer( dateTime.getSeconds() ) );
41
    preserveSubWidgetsBounds( dateTime );
42
  }
43
44
  void readData( final DateTime dateTime ) {
45
    String value = WidgetLCAUtil.readPropertyValue( dateTime, PROP_HOURS );
46
    if( value != null ) {
47
      dateTime.setHours( Integer.parseInt( value ) );
48
    }
49
    value = WidgetLCAUtil.readPropertyValue( dateTime, PROP_MINUTES );
50
    if( value != null ) {
51
      dateTime.setMinutes( Integer.parseInt( value ) );
52
    }
53
    value = WidgetLCAUtil.readPropertyValue( dateTime, PROP_SECONDS );
54
    if( value != null ) {
55
      dateTime.setSeconds( Integer.parseInt( value ) );
56
    }
57
    ControlLCAUtil.processSelection( dateTime, null, true );
58
  }
59
60
  void renderInitialization( final DateTime dateTime )
61
    throws IOException
62
  {
63
    JSWriter writer = JSWriter.getWriterFor( dateTime );
64
    String style = "";
65
    if( ( dateTime.getStyle() & SWT.SHORT ) != 0 ) {
66
      style = "short";
67
    } else if( ( dateTime.getStyle() & SWT.MEDIUM ) != 0 ) {
68
      style = "medium";
69
    } else if( ( dateTime.getStyle() & SWT.LONG ) != 0 ) {
70
      style = "long";
71
    }
72
    Object[] args = new Object[]{
73
      style
74
    };
75
    writer.newWidget( "org.eclipse.swt.widgets.DateTimeTime", args );
76
    WidgetLCAUtil.writeCustomVariant( dateTime );
77
    ControlLCAUtil.writeStyleFlags( dateTime );
78
  }
79
80
  void renderChanges( final DateTime dateTime ) throws IOException {
81
    ControlLCAUtil.writeChanges( dateTime );
82
    writeHours( dateTime );
83
    writeMinutes( dateTime );
84
    writeSeconds( dateTime );
85
    DateTimeLCAUtil.writeListener( dateTime );
86
    writeSubWidgetsBounds( dateTime );
87
  }
88
89
  void renderDispose( final DateTime dateTime ) throws IOException {
90
    JSWriter writer = JSWriter.getWriterFor( dateTime );
91
    writer.dispose();
92
  }
93
94
  void createResetHandlerCalls( final String typePoolId )
95
    throws IOException
96
  {
97
  }
98
99
  String getTypePoolId( final DateTime dateTime ) {
100
    return null;
101
  }
102
  // ////////////////////////////////////
103
  // Helping methods to write properties
104
  private void writeHours( final DateTime dateTime ) throws IOException {
105
    Integer newValue = new Integer( dateTime.getHours() );
106
    if( WidgetLCAUtil.hasChanged( dateTime, PROP_HOURS, newValue ) ) {
107
      JSWriter writer = JSWriter.getWriterFor( dateTime );
108
      writer.set( PROP_HOURS, newValue );
109
    }
110
  }
111
112
  private void writeMinutes( final DateTime dateTime ) throws IOException {
113
    Integer newValue = new Integer( dateTime.getMinutes() );
114
    if( WidgetLCAUtil.hasChanged( dateTime, PROP_MINUTES, newValue ) ) {
115
      JSWriter writer = JSWriter.getWriterFor( dateTime );
116
      writer.set( PROP_MINUTES, newValue );
117
    }
118
  }
119
120
  private void writeSeconds( final DateTime dateTime ) throws IOException {
121
    Integer newValue = new Integer( dateTime.getSeconds() );
122
    if( WidgetLCAUtil.hasChanged( dateTime, PROP_SECONDS, newValue ) ) {
123
      JSWriter writer = JSWriter.getWriterFor( dateTime );
124
      writer.set( PROP_SECONDS, newValue );
125
    }
126
  }
127
128
  private void writeSubWidgetsBounds( final DateTime dateTime )
129
    throws IOException
130
  {
131
    // The hours text field bounds
132
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
133
                    IDateTimeAdapter.HOURS_TEXTFIELD );
134
    // The hours minutes separator bounds
135
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
136
                    IDateTimeAdapter.HOURS_MINUTES_SEPARATOR );
137
    // The minutes text field bounds
138
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
139
                    IDateTimeAdapter.MINUTES_TEXTFIELD );
140
    // The minutes seconds separator bounds
141
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
142
                    IDateTimeAdapter.MINUTES_SECONDS_SEPARATOR );
143
    // The seconds text field bounds
144
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
145
                    IDateTimeAdapter.SECONDS_TEXTFIELD );
146
    // The spinner bounds
147
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
148
                    IDateTimeAdapter.SPINNER );
149
  }
150
  
151
  private void preserveSubWidgetsBounds( final DateTime dateTime ) {
152
    // The hours text field bounds
153
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
154
                    IDateTimeAdapter.HOURS_TEXTFIELD );
155
    // The hours minutes separator bounds
156
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
157
                    IDateTimeAdapter.HOURS_MINUTES_SEPARATOR );
158
    // The minutes text field bounds
159
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
160
                    IDateTimeAdapter.MINUTES_TEXTFIELD );
161
    // The minutes seconds separator bounds
162
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
163
                    IDateTimeAdapter.MINUTES_SECONDS_SEPARATOR );
164
    // The seconds text field bounds
165
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
166
                    IDateTimeAdapter.SECONDS_TEXTFIELD );
167
    // The spinner bounds
168
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
169
                    IDateTimeAdapter.SPINNER );
170
  }
171
}
(-)src/org/eclipse/swt/internal/widgets/datetimekit/DateTimeDateLCA.java (+190 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002-2008 Innoopract Informationssysteme GmbH. All rights
3
 * reserved. This program and the accompanying materials are made available
4
 * under the terms of the Eclipse Public License v1.0 which accompanies this
5
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
6
 * Contributors: Innoopract Informationssysteme GmbH - initial API and
7
 * implementation
8
 ******************************************************************************/
9
package org.eclipse.swt.internal.widgets.datetimekit;
10
11
import java.io.IOException;
12
13
import org.eclipse.rwt.lifecycle.*;
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.events.SelectionEvent;
16
import org.eclipse.swt.internal.widgets.IDateTimeAdapter;
17
import org.eclipse.swt.internal.widgets.Props;
18
import org.eclipse.swt.widgets.DateTime;
19
20
public class DateTimeDateLCA extends AbstractDateTimeLCADelegate {
21
22
  static final String TYPE_POOL_ID = DateTimeDateLCA.class.getName();
23
  // Property names for preserveValues
24
  static final String PROP_DAY = "day";
25
  static final String PROP_MONTH = "month";
26
  static final String PROP_YEAR = "year";
27
28
  // Property names for preserveValues
29
  void preserveValues( final DateTime dateTime ) {
30
    ControlLCAUtil.preserveValues( dateTime );
31
    IWidgetAdapter adapter = WidgetUtil.getAdapter( dateTime );
32
    boolean hasListeners = SelectionEvent.hasListener( dateTime );
33
    adapter.preserve( Props.SELECTION_LISTENERS,
34
                      Boolean.valueOf( hasListeners ) );
35
    adapter.preserve( PROP_DAY, 
36
                      new Integer( dateTime.getDay() ) );
37
    adapter.preserve( PROP_MONTH, 
38
                      new Integer( dateTime.getMonth() ) );
39
    adapter.preserve( PROP_YEAR, 
40
                      new Integer( dateTime.getYear() ) );
41
    preserveSubWidgetsBounds( dateTime );
42
  }
43
44
  void readData( final DateTime dateTime ) {
45
    String value = WidgetLCAUtil.readPropertyValue( dateTime, PROP_DAY );
46
    if( value != null ) {
47
      dateTime.setDay( Integer.parseInt( value ) );
48
    }
49
    value = WidgetLCAUtil.readPropertyValue( dateTime, PROP_MONTH );
50
    if( value != null ) {
51
      dateTime.setMonth( Integer.parseInt( value ) );
52
    }
53
    value = WidgetLCAUtil.readPropertyValue( dateTime, PROP_YEAR );
54
    if( value != null ) {
55
      dateTime.setYear( Integer.parseInt( value ) );
56
    }
57
    ControlLCAUtil.processSelection( dateTime, null, true );
58
  }
59
60
  void renderInitialization( final DateTime dateTime )
61
    throws IOException
62
  {
63
    IDateTimeAdapter dateTimeAdapter 
64
      = DateTimeLCAUtil.getDateTimeAdapter( dateTime );
65
    JSWriter writer = JSWriter.getWriterFor( dateTime );
66
    String style = "";
67
    if( ( dateTime.getStyle() & SWT.SHORT ) != 0 ) {
68
      style = "short";
69
    } else if( ( dateTime.getStyle() & SWT.MEDIUM ) != 0 ) {
70
      style = "medium";
71
    } else if( ( dateTime.getStyle() & SWT.LONG ) != 0 ) {
72
      style = "long";
73
    }
74
    Object[] args = new Object[]{
75
      style,
76
      dateTimeAdapter.getMonthNames(),
77
      dateTimeAdapter.getWeekdayNames(),
78
      dateTimeAdapter.getDateSeparator(),
79
      dateTimeAdapter.getDatePattern()
80
    };
81
    writer.newWidget( "org.eclipse.swt.widgets.DateTimeDate", args );
82
    WidgetLCAUtil.writeCustomVariant( dateTime );
83
    ControlLCAUtil.writeStyleFlags( dateTime );
84
  }
85
86
  void renderChanges( final DateTime dateTime ) throws IOException {
87
    ControlLCAUtil.writeChanges( dateTime );
88
    writeDay( dateTime );
89
    writeMonth( dateTime );
90
    writeYear( dateTime );
91
    DateTimeLCAUtil.writeListener( dateTime );
92
    writeSubWidgetsBounds( dateTime );
93
  }
94
95
  void renderDispose( final DateTime dateTime ) throws IOException {
96
    JSWriter writer = JSWriter.getWriterFor( dateTime );
97
    writer.dispose();
98
  }
99
100
  void createResetHandlerCalls( final String typePoolId )
101
    throws IOException
102
  {
103
  }
104
105
  String getTypePoolId( final DateTime dateTime ) {
106
    return null;
107
  }
108
109
  // ////////////////////////////////////
110
  // Helping methods to write properties
111
  private void writeDay( final DateTime dateTime ) throws IOException {
112
    Integer newValue = new Integer( dateTime.getDay() );
113
    if( WidgetLCAUtil.hasChanged( dateTime, PROP_DAY, newValue ) ) {
114
      JSWriter writer = JSWriter.getWriterFor( dateTime );
115
      writer.set( PROP_DAY, newValue );
116
    }
117
  }
118
119
  private void writeMonth( final DateTime dateTime ) throws IOException {
120
    Integer newValue = new Integer( dateTime.getMonth() );
121
    if( WidgetLCAUtil.hasChanged( dateTime, PROP_MONTH, newValue ) ) {
122
      JSWriter writer = JSWriter.getWriterFor( dateTime );
123
      writer.set( PROP_MONTH, newValue );
124
    }
125
  }
126
127
  private void writeYear( final DateTime dateTime ) throws IOException {
128
    Integer newValue = new Integer( dateTime.getYear() );
129
    if( WidgetLCAUtil.hasChanged( dateTime, PROP_YEAR, newValue ) ) {
130
      JSWriter writer = JSWriter.getWriterFor( dateTime );
131
      writer.set( PROP_YEAR, newValue );
132
    }
133
  }
134
135
  private void writeSubWidgetsBounds( final DateTime dateTime )
136
    throws IOException
137
  {
138
    // The weekday text field bounds
139
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
140
                    IDateTimeAdapter.WEEKDAY_TEXTFIELD );
141
    // The weekday month separator bounds
142
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
143
                    IDateTimeAdapter.WEEKDAY_MONTH_SEPARATOR );
144
    // The month text field bounds
145
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
146
                    IDateTimeAdapter.MONTH_TEXTFIELD );
147
    // The month date separator bounds
148
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
149
                    IDateTimeAdapter.MONTH_DAY_SEPARATOR );
150
    // The date text field bounds
151
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
152
                    IDateTimeAdapter.DAY_TEXTFIELD );
153
    // The date year separator bounds
154
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
155
                    IDateTimeAdapter.DAY_YEAR_SEPARATOR );
156
    // The year text field bounds
157
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
158
                    IDateTimeAdapter.YEAR_TEXTFIELD );
159
    // The spinner bounds
160
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
161
                    IDateTimeAdapter.SPINNER );
162
  }
163
  
164
  private void preserveSubWidgetsBounds( final DateTime dateTime ) {
165
    // The weekday text field bounds
166
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
167
                    IDateTimeAdapter.WEEKDAY_TEXTFIELD );
168
    // The weekday month separator bounds
169
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
170
                    IDateTimeAdapter.WEEKDAY_MONTH_SEPARATOR );
171
    // The month text field bounds
172
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
173
                    IDateTimeAdapter.MONTH_TEXTFIELD );
174
    // The month date separator bounds
175
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
176
                    IDateTimeAdapter.MONTH_DAY_SEPARATOR );
177
    // The date text field bounds
178
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
179
                    IDateTimeAdapter.DAY_TEXTFIELD );
180
    // The date year separator bounds
181
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
182
                    IDateTimeAdapter.DAY_YEAR_SEPARATOR );
183
    // The year text field bounds
184
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
185
                    IDateTimeAdapter.YEAR_TEXTFIELD );
186
    // The spinner bounds
187
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
188
                    IDateTimeAdapter.SPINNER );
189
  }
190
}
(-)src/org/eclipse/swt/internal/widgets/datetimekit/AbstractDateTimeLCADelegate.java (+30 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002-2008 Innoopract Informationssysteme GmbH. All rights
3
 * reserved. This program and the accompanying materials are made available
4
 * under the terms of the Eclipse Public License v1.0 which accompanies this
5
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
6
 * Contributors: Innoopract Informationssysteme GmbH - initial API and
7
 * implementation
8
 ******************************************************************************/
9
package org.eclipse.swt.internal.widgets.datetimekit;
10
11
import java.io.IOException;
12
13
import org.eclipse.swt.widgets.DateTime;
14
15
abstract class AbstractDateTimeLCADelegate {
16
17
  abstract void preserveValues( DateTime dateTime );
18
19
  abstract void readData( DateTime dateTime );
20
21
  abstract void renderInitialization( DateTime dateTime ) throws IOException;
22
23
  abstract void renderChanges( DateTime dateTime ) throws IOException;
24
25
  abstract void renderDispose( DateTime dateTime ) throws IOException;
26
27
  abstract void createResetHandlerCalls( String typePoolId ) throws IOException;
28
29
  abstract String getTypePoolId( DateTime dateTime );
30
}
(-)js/org/eclipse/swt/widgets/DateTimeCalendar.js (+30 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002-2008 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     Innoopract Informationssysteme GmbH - initial API and implementation
10
 ******************************************************************************/
11
12
qx.Class.define( "org.eclipse.swt.widgets.DateTimeCalendar", {
13
  extend : qx.ui.layout.CanvasLayout,
14
15
  construct : function( style ) {
16
    this.base( arguments );
17
  },
18
19
  destruct : function() {
20
    
21
  },
22
23
  statics : {
24
    
25
  },
26
27
  members : {
28
    
29
  }
30
} );
(-)js/org/eclipse/swt/widgets/DateTimeTime.js (+461 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002-2008 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     Innoopract Informationssysteme GmbH - initial API and implementation
10
 ******************************************************************************/
11
12
qx.Class.define( "org.eclipse.swt.widgets.DateTimeTime", {
13
  extend : qx.ui.layout.CanvasLayout,
14
15
  construct : function( style ) {
16
    this.base( arguments );    
17
    this.setAppearance( "datetime-date" );
18
    
19
    // Get styles
20
    this._short = qx.lang.String.contains( style, "short" );
21
    this._medium = qx.lang.String.contains( style, "medium" );
22
    this._long = qx.lang.String.contains( style, "long" );
23
    
24
    // Has selection listener
25
    this._hasSelectionListener = false;
26
    
27
    // Flag that indicates that the next request can be sent
28
    this._readyToSendChanges = true;
29
    
30
    // Add listeners for font, background and foregraund color change
31
    this.addEventListener( "changeFont", this._rwt_onChangeFont, this );
32
    this.addEventListener( "changeTextColor", this._rwt_onChangeTextColor, this );
33
    this.addEventListener( "changeBackgroundColor", this._rwt_onChangeBackgoundColor, this );
34
    
35
    // Background color
36
    this._backgroundColor = "white";
37
    // Foreground color
38
    this._foregroundColor = "black";
39
    
40
    // Focused text field
41
    this._focusedTextField = null;    
42
    // Hours
43
    this._hoursTextField = new qx.ui.form.TextField;
44
    this._hoursTextField.set({ 
45
    	maxLength: 2, 
46
      textAlign: "center",
47
      selectable: false,
48
      readOnly: true,
49
      border: null,
50
      backgroundColor: this._backgroundColor,
51
      textColor : this._foregroundColor
52
    });
53
    this._hoursTextField.setValue( "00" );
54
    this._hoursTextField.addEventListener( "click",  this._onClick, this ); 
55
    this._hoursTextField.addEventListener( "keypress", this._onKeyPress, this );
56
    this._hoursTextField.addEventListener( "keyup", this._onKeyUp, this );
57
    this._hoursTextField.addEventListener( "contextmenu", this._onContextMenu, this );  
58
    this.add(this._hoursTextField);
59
    // Separator
60
    this._separator3 = new qx.ui.basic.Label(":");        
61
    this._separator3.set({
62
      paddingTop: 3,
63
      backgroundColor: this._backgroundColor,
64
      textColor : this._foregroundColor
65
    });
66
    this._separator3.addEventListener( "contextmenu", this._onContextMenu, this );
67
    this.add(this._separator3);
68
    // Minutes
69
    this._minutesTextField = new qx.ui.form.TextField;
70
    this._minutesTextField.set({ 
71
      maxLength: 2, 
72
      textAlign: "center",
73
      selectable: false,
74
      readOnly: true,
75
      border: null,
76
      backgroundColor: this._backgroundColor,
77
      textColor : this._foregroundColor
78
    });
79
    this._minutesTextField.setValue( "00" );
80
    this._minutesTextField.addEventListener( "click",  this._onClick, this ); 
81
    this._minutesTextField.addEventListener( "keypress", this._onKeyPress, this );
82
    this._minutesTextField.addEventListener( "keyup", this._onKeyUp, this );
83
    this._minutesTextField.addEventListener( "contextmenu", this._onContextMenu, this );
84
    this.add(this._minutesTextField);
85
    // Separator
86
    this._separator4 = new qx.ui.basic.Label(":");        
87
    this._separator4.set({
88
      paddingTop: 3,
89
      backgroundColor: this._backgroundColor,
90
      textColor : this._foregroundColor
91
    });
92
    this._separator4.addEventListener( "contextmenu", this._onContextMenu, this );
93
    if( this._medium || this._long ) {
94
      this.add(this._separator4);
95
    }
96
    // Seconds
97
    this._secondsTextField = new qx.ui.form.TextField;
98
    this._secondsTextField.set({ 
99
      maxLength: 2, 
100
      textAlign: "center",
101
      selectable: false,
102
      readOnly: true,
103
      border: null,
104
      backgroundColor: this._backgroundColor,
105
      textColor : this._foregroundColor
106
    });
107
    this._secondsTextField.setValue( "00" );
108
    this._secondsTextField.addEventListener( "click",  this._onClick, this ); 
109
    this._secondsTextField.addEventListener( "keypress", this._onKeyPress, this );
110
    this._secondsTextField.addEventListener( "keyup", this._onKeyUp, this );
111
    this._secondsTextField.addEventListener( "contextmenu", this._onContextMenu, this );
112
    if( this._medium || this._long ) {
113
      this.add(this._secondsTextField);
114
    }
115
    // Spinner 
116
    this._spinner = new qx.ui.form.Spinner;
117
    this._spinner.set({
118
      wrap: true,
119
      border: null,
120
      backgroundColor: this._backgroundColor,
121
      textColor : this._foregroundColor
122
    });
123
    this._spinner.setMin( 0 ); 
124
    this._spinner.setMax( 23 );        
125
    this._spinner.setValue( 0 );
126
    this._spinner.addEventListener( "change",  this._onSpinnerChange, this ); 
127
    this._spinner.addEventListener( "mousedown",  this._onSpinnerMouseDown, this ); 
128
    this._spinner.addEventListener( "mouseup",  this._onSpinnerMouseUp, this );
129
    this._spinner.addEventListener( "keypress", this._onKeyPress, this );
130
    this._spinner.addEventListener( "keyup", this._onKeyUp, this );
131
    this.add( this._spinner );
132
    // Set the default focused text field
133
    this._focusedTextField = this._hoursTextField;
134
  },
135
136
  destruct : function() {
137
    this.removeEventListener( "changeFont", this._rwt_onChangeFont, this );
138
    this.removeEventListener( "changeTextColor", this._rwt_onChangeTextColor, this );
139
    this.removeEventListener( "changeBackgroundColor", this._rwt_onChangeBackgoundColor, this );
140
    this._hoursTextField.removeEventListener( "click",  this._onClick, this ); 
141
    this._hoursTextField.removeEventListener( "keypress", this._onKeyPress, this );
142
    this._hoursTextField.removeEventListener( "keyup", this._onKeyUp, this );
143
    this._hoursTextField.removeEventListener( "contextmenu", this._onContextMenu, this );
144
    this._minutesTextField.removeEventListener( "click",  this._onClick, this ); 
145
    this._minutesTextField.removeEventListener( "keypress", this._onKeyPress, this );
146
    this._minutesTextField.removeEventListener( "keyup", this._onKeyUp, this );
147
    this._minutesTextField.removeEventListener( "contextmenu", this._onContextMenu, this );
148
    this._secondsTextField.removeEventListener( "click",  this._onClick, this ); 
149
    this._secondsTextField.removeEventListener( "keypress", this._onKeyPress, this );
150
    this._secondsTextField.removeEventListener( "keyup", this._onKeyUp, this );
151
    this._secondsTextField.removeEventListener( "contextmenu", this._onContextMenu, this );
152
    this._spinner.removeEventListener( "change",  this._onSpinnerChange, this ); 
153
    this._spinner.removeEventListener( "mousedown",  this._onSpinnerMouseDown, this ); 
154
    this._spinner.removeEventListener( "mouseup",  this._onSpinnerMouseUp, this ); 
155
    this._spinner.removeEventListener( "keypress", this._onKeyPress, this );
156
    this._spinner.removeEventListener( "keyup", this._onKeyUp, this );
157
    this._separator3.removeEventListener( "contextmenu", this._onContextMenu, this );
158
    this._separator4.removeEventListener( "contextmenu", this._onContextMenu, this );
159
    this._disposeObjects( "_hoursTextField",
160
                          "_minutesTextField",
161
                          "_secondsTextField",
162
                          "_focusedTextField",
163
                          "_spinner",
164
                          "_separator3",
165
                          "_separator4" );
166
  },
167
168
  statics : {
169
    HOURS_TEXTFIELD : 8,
170
    MINUTES_TEXTFIELD : 9,
171
    SECONDS_TEXTFIELD : 10,    
172
    HOURS_MINUTES_SEPARATOR : 11,
173
    MINUTES_SECONDS_SEPARATOR : 12,    
174
    SPINNER : 7,
175
    
176
    _isNoModifierPressed : function( evt ) {
177
      return    !evt.isCtrlPressed() 
178
             && !evt.isShiftPressed() 
179
             && !evt.isAltPressed() 
180
             && !evt.isMetaPressed();      
181
    }
182
  },
183
184
  members : { 
185
    _rwt_onChangeFont : function( evt ) {
186
      var value = evt.getData();
187
      this._hoursTextField.setFont( value );
188
      this._minutesTextField.setFont( value );
189
      this._secondsTextField.setFont( value );
190
    },
191
    
192
    _rwt_onChangeTextColor : function( evt ) {
193
      var value = evt.getData();
194
      this._foregroundColor = value;
195
      this._hoursTextField.setTextColor( value );
196
      this._minutesTextField.setTextColor( value );
197
      this._secondsTextField.setTextColor( value );
198
      this._separator3.setTextColor( value );
199
      this._separator4.setTextColor( value );     
200
    },
201
    
202
    _rwt_onChangeBackgoundColor : function( evt ) {
203
      var value = evt.getData();
204
      this._backgroundColor = value;
205
      this._hoursTextField.setBackgroundColor( value );
206
      this._minutesTextField.setBackgroundColor( value );
207
      this._secondsTextField.setBackgroundColor( value );      
208
      this._separator3.setBackgroundColor( value );
209
      this._separator4.setBackgroundColor( value );      
210
      this._spinner.setBackgroundColor( value );
211
    },
212
    
213
    _onContextMenu : function( evt ) {     
214
      var menu = this.getContextMenu();      
215
      if( menu != null ) {
216
        menu.setLocation( evt.getPageX(), evt.getPageY() );
217
        menu.setOpener( this );
218
        menu.show();
219
        evt.stopPropagation();
220
      }
221
    },
222
    
223
    _onClick : function( evt ) {
224
      this._setFocusedTextField( evt.getTarget() );
225
    },
226
    
227
    _setFocusedTextField :  function( textField ) {
228
    	var tmpValue;
229
    	this._focusedTextField.setBackgroundColor( this._backgroundColor );
230
      this._focusedTextField.setTextColor( this._foregroundColor );
231
      // Set focused text field to null
232
      this._focusedTextField = null;
233
      if( textField === this._hoursTextField ) {
234
        this._spinner.setMin( 0 );            
235
        this._spinner.setMax( 23 ); 
236
        tmpValue = this._removeLeadingZero( this._hoursTextField.getValue() );
237
        this._spinner.setValue( parseInt( tmpValue ) );
238
      } else if( textField === this._minutesTextField ) { 
239
        this._spinner.setMin( 0 );           
240
        this._spinner.setMax( 59 );
241
        tmpValue = this._removeLeadingZero( this._minutesTextField.getValue() );
242
        this._spinner.setValue( parseInt( tmpValue ) );
243
      } else if( textField === this._secondsTextField ) {
244
        this._spinner.setMin( 0 );                        
245
        this._spinner.setMax( 59 ); 
246
        tmpValue = this._removeLeadingZero( this._secondsTextField.getValue() );                           
247
        this._spinner.setValue( parseInt( tmpValue ) );
248
      }
249
      // Set focused text field
250
      this._focusedTextField = textField;
251
      // Set highlight on focused text field
252
      this._focusedTextField.setBackgroundColor( "#0A246A" );
253
      this._focusedTextField.setTextColor( "white" );
254
      // Request focus
255
      this._focusedTextField.setFocused( true );
256
    },
257
    
258
    _onSpinnerChange : function( evt ) {          
259
      if( this._focusedTextField != null ) {
260
      	var oldValue = this._focusedTextField.getValue();
261
      	var newValue = this._addLeadingZero( this._spinner.getValue() );
262
      	this._focusedTextField.setValue( newValue );        
263
        if( oldValue != newValue && this._readyToSendChanges ) {
264
        	this._readyToSendChanges = false;
265
	        // Send changes
266
	        qx.client.Timer.once( this._sendChanges, this, 500 );
267
        }
268
      }
269
    },
270
    
271
    _onSpinnerMouseDown : function( evt ) {
272
      // Set highlight on focused text field
273
      this._focusedTextField.setBackgroundColor( "#0A246A" );
274
      this._focusedTextField.setTextColor( "white" );
275
    },
276
    
277
    _onSpinnerMouseUp : function( evt ) {      
278
      this._focusedTextField.setFocused( true );
279
    },
280
    
281
    _onKeyPress : function( evt ) {
282
      var keyIdentifier = evt.getKeyIdentifier();
283
      if( org.eclipse.swt.widgets.DateTimeTime._isNoModifierPressed( evt ) ) {
284
      	switch( keyIdentifier ) {
285
      		case "Left":
286
      		  if( this._focusedTextField === this._hoursTextField ) {
287
              if( this._short ) {
288
                this._setFocusedTextField( this._minutesTextField );
289
              } else {
290
                this._setFocusedTextField( this._secondsTextField );
291
              }
292
            } else if( this._focusedTextField === this._minutesTextField ) {
293
              this._setFocusedTextField( this._hoursTextField );              
294
            } else if( this._focusedTextField === this._secondsTextField ) {
295
              this._setFocusedTextField( this._minutesTextField );
296
            }
297
      		  break;
298
      		case "Right":
299
      		  if( this._focusedTextField === this._hoursTextField ) {
300
              this._setFocusedTextField( this._minutesTextField );
301
            } else if( this._focusedTextField === this._minutesTextField ) {
302
            	if( this._short ) {
303
            	  this._setFocusedTextField( this._hoursTextField );
304
            	} else {
305
            		this._setFocusedTextField( this._secondsTextField );
306
            	}
307
            } else if( this._focusedTextField === this._secondsTextField ) {
308
            	this._setFocusedTextField( this._hoursTextField );
309
            }
310
      		  break; 
311
      		case "Up":
312
      		  var value = this._spinner.getValue();
313
      		  if( value == this._spinner.getMax() ) {
314
      		  	this._spinner.setValue( this._spinner.getMin() );
315
      		  } else {
316
      		  	this._spinner.setValue( value + 1 );
317
      		  }
318
      		  break;
319
      		case "Down":
320
      		  var value = this._spinner.getValue();
321
            if( value == this._spinner.getMin() ) {
322
              this._spinner.setValue( this._spinner.getMax() );
323
            } else {
324
              this._spinner.setValue( value - 1 );
325
            }
326
            break;     
327
      	}
328
      }
329
    },  
330
    
331
    _onKeyUp : function( evt ) {
332
      var keypress = evt.getKeyIdentifier();
333
      var value = this._focusedTextField.getComputedValue();      
334
      value = this._removeLeadingZero( value );
335
      if( org.eclipse.swt.widgets.DateTimeTime._isNoModifierPressed( evt ) ) {
336
	      switch( keypress ) {
337
	      	case "Tab":
338
	      	  this._focusedTextField.setBackgroundColor( this._backgroundColor );
339
	          this._focusedTextField.setTextColor( this._foregroundColor );
340
	      	  break;
341
	      	case "0": case "1": case "2": case "3": case "4":
342
	      	case "5": case "6": case "7": case "8": case "9":
343
	      	  this._focusedTextField.setFocused( true );		      
344
			      var maxChars = this._focusedTextField.getMaxLength();
345
			      var newValue = keypress;
346
			      if( value.length < maxChars ) {
347
			      	newValue = value + keypress;
348
			      }	
349
			      var intValue = parseInt( newValue );
350
			      if( intValue >= this._spinner.getMin() &&
351
			          intValue <= this._spinner.getMax() ) {
352
			        this._spinner.setValue( intValue );      
353
			      } else {
354
			        newValue = keypress;
355
			        intValue = parseInt( newValue );
356
			        if( intValue >= this._spinner.getMin() &&
357
			            intValue <= this._spinner.getMax() ) {
358
			          this._spinner.setValue( intValue );
359
			        }
360
			      }
361
	      	  break;
362
	      	case "Home":
363
	          var newValue = this._spinner.getMin();
364
	          this._spinner.setValue( newValue );	          
365
	          break;
366
	        case "End":
367
	          var newValue = this._spinner.getMax();
368
	          this._spinner.setValue( newValue );	          
369
	          break;
370
	      } 
371
      }
372
    },
373
    
374
    _addLeadingZero : function( value ) {
375
    	return value < 10 ? "0" + value : value;
376
    },
377
    
378
    _removeLeadingZero : function( value ) {
379
    	var result = value;
380
    	if( value.length == 2 ) {
381
    		var firstChar = value.substring( 0, 1 );
382
    	  if( firstChar == "0" ) result = value.substring( 1 );
383
    	}
384
      return result;
385
    },
386
    
387
    _sendChanges : function() {
388
      if( !org_eclipse_rap_rwt_EventUtil_suspend ) {        
389
        var widgetManager = org.eclipse.swt.WidgetManager.getInstance();
390
        var req = org.eclipse.swt.Request.getInstance();
391
        var id = widgetManager.findIdByWidget( this );        
392
        req.addParameter( id + ".hours", 
393
                          this._removeLeadingZero( this._hoursTextField.getValue() ) );
394
        req.addParameter( id + ".minutes", 
395
                          this._removeLeadingZero( this._minutesTextField.getValue() ) );
396
        req.addParameter( id + ".seconds", 
397
                          this._removeLeadingZero( this._secondsTextField.getValue() ) );
398
        if( this._hasSelectionListener ) {
399
          req.addEvent( "org.eclipse.swt.events.widgetSelected", id );
400
          req.send();
401
        }
402
        this._readyToSendChanges = true;
403
      }
404
    },
405
    
406
    setHours : function( value ) { 
407
    	this._hoursTextField.setValue( this._addLeadingZero( value ) );      
408
      if( this._focusedTextField === this._hoursTextField ) {
409
        this._spinner.setValue( value );
410
      }
411
    },
412
    
413
    setMinutes : function( value ) {
414
      this._minutesTextField.setValue( this._addLeadingZero( value ) );
415
      if( this._focusedTextField === this._minutesTextField ) {
416
        this._spinner.setValue( value );
417
      }
418
    },
419
    
420
    setSeconds : function( value ) {
421
      this._secondsTextField.setValue( this._addLeadingZero( value ) );
422
      if( this._focusedTextField === this._secondsTextField ) {
423
        this._spinner.setValue( value );
424
      }
425
    },
426
    
427
    setHasSelectionListener : function( value ) {
428
      this._hasSelectionListener = value;
429
    },
430
    
431
    setBounds : function( ind, x, y, width, height ) {
432
      var widget;
433
      switch( ind ) {
434
        case org.eclipse.swt.widgets.DateTimeTime.HOURS_TEXTFIELD:
435
          widget = this._hoursTextField;
436
        break;
437
        case org.eclipse.swt.widgets.DateTimeTime.MINUTES_TEXTFIELD:
438
          widget = this._minutesTextField;
439
        break;
440
        case org.eclipse.swt.widgets.DateTimeTime.SECONDS_TEXTFIELD:
441
          widget = this._secondsTextField;
442
        break;        
443
        case org.eclipse.swt.widgets.DateTimeTime.HOURS_MINUTES_SEPARATOR:
444
          widget = this._separator3;
445
        break;
446
        case org.eclipse.swt.widgets.DateTimeTime.MINUTES_SECONDS_SEPARATOR:
447
          widget = this._separator4;
448
        break;        
449
        case org.eclipse.swt.widgets.DateTimeTime.SPINNER:
450
          widget = this._spinner;
451
        break;
452
      }
453
      widget.set({        
454
        left: x,
455
        top: y,
456
        width: width,
457
        height: height
458
      });  
459
    }
460
  }
461
} );
(-)src/org/eclipse/swt/internal/widgets/datetimekit/DateTimeCalendarLCA.java (+69 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002-2008 Innoopract Informationssysteme GmbH. All rights
3
 * reserved. This program and the accompanying materials are made available
4
 * under the terms of the Eclipse Public License v1.0 which accompanies this
5
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
6
 * Contributors: Innoopract Informationssysteme GmbH - initial API and
7
 * implementation
8
 ******************************************************************************/
9
package org.eclipse.swt.internal.widgets.datetimekit;
10
11
import java.io.IOException;
12
13
import org.eclipse.rwt.lifecycle.*;
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.widgets.DateTime;
16
17
public class DateTimeCalendarLCA extends AbstractDateTimeLCADelegate {
18
19
  static final String TYPE_POOL_ID = DateTimeCalendarLCA.class.getName();
20
21
  // Property names for preserveValues
22
  void preserveValues( final DateTime dateTime ) {
23
    ControlLCAUtil.preserveValues( dateTime );
24
    IWidgetAdapter adapter = WidgetUtil.getAdapter( dateTime );
25
  }
26
27
  void readData( final DateTime dateTime ) {
28
  }
29
30
  void renderInitialization( final DateTime dateTime )
31
    throws IOException
32
  {
33
    JSWriter writer = JSWriter.getWriterFor( dateTime );
34
    String style = "";
35
    if( ( dateTime.getStyle() & SWT.SHORT ) != 0 ) {
36
      style = "short";
37
    } else if( ( dateTime.getStyle() & SWT.MEDIUM ) != 0 ) {
38
      style = "medium";
39
    } else if( ( dateTime.getStyle() & SWT.LONG ) != 0 ) {
40
      style = "long";
41
    }
42
    Object[] args = new Object[]{
43
      style
44
    };
45
    writer.newWidget( "org.eclipse.swt.widgets.DateTimeCalendar", args );
46
    WidgetLCAUtil.writeCustomVariant( dateTime );
47
    ControlLCAUtil.writeStyleFlags( dateTime );
48
  }
49
50
  void renderChanges( final DateTime dateTime ) throws IOException {
51
    ControlLCAUtil.writeChanges( dateTime );
52
  }
53
54
  void renderDispose( final DateTime dateTime ) throws IOException {
55
    JSWriter writer = JSWriter.getWriterFor( dateTime );
56
    writer.dispose();
57
  }
58
59
  void createResetHandlerCalls( final String typePoolId )
60
    throws IOException
61
  {
62
  }
63
64
  String getTypePoolId( final DateTime dateTime ) {
65
    return null;
66
  }
67
  // ////////////////////////////////////
68
  // Helping methods to write properties
69
}
(-)src/org/eclipse/swt/SWT.java (+76 lines)
Lines 1564-1569 Link Here
1564
   * contains a transparent pixel (value is 1&lt;&lt;2).
1564
   * contains a transparent pixel (value is 1&lt;&lt;2).
1565
   */
1565
   */
1566
  public static final int TRANSPARENCY_PIXEL = 1 << 2;
1566
  public static final int TRANSPARENCY_PIXEL = 1 << 2;
1567
  
1568
  /**
1569
   * Style constant for date display (value is 1&lt;&lt;5).
1570
   * <p><b>Used By:</b><ul>
1571
   * <li><code>DateTime</code></li>
1572
   * </ul></p>
1573
   * 
1574
   * @since 3.3
1575
   */
1576
  public static final int DATE = 1 << 5;
1577
1578
  /**
1579
   * Style constant for time display (value is 1&lt;&lt;7).
1580
   * <p><b>Used By:</b><ul>
1581
   * <li><code>DateTime</code></li>
1582
   * </ul></p>
1583
   * 
1584
   * @since 3.3
1585
   */
1586
  public static final int TIME = 1 << 7;
1587
  
1588
  /**
1589
   * Style constant for calendar display (value is 1&lt;&lt;10).
1590
   * <p><b>Used By:</b><ul>
1591
   * <li><code>DateTime</code></li>
1592
   * </ul></p>
1593
   * 
1594
   * @since 3.3
1595
   */
1596
  public static final int CALENDAR = 1 << 10;
1597
1598
  /**
1599
   * Style constant for short date/time format (value is 1&lt;&lt;15).
1600
   * <p>
1601
   * A short date displays the month and year.
1602
   * A short time displays hours and minutes.
1603
   * <br>Note that this is a <em>HINT</em>.
1604
   * </p>
1605
   * <p><b>Used By:</b><ul>
1606
   * <li><code>DateTime</code></li>
1607
   * </ul></p>
1608
   * 
1609
   * @since 3.3
1610
   */
1611
  public static final int SHORT = 1 << 15;
1612
1613
  /**
1614
   * Style constant for medium date/time format (value is 1&lt;&lt;16).
1615
   * <p>
1616
   * A medium date displays the day, month and year.
1617
   * A medium time displays hours, minutes, and seconds.
1618
   * <br>Note that this is a <em>HINT</em>.
1619
   * </p>
1620
   * <p><b>Used By:</b><ul>
1621
   * <li><code>DateTime</code></li>
1622
   * </ul></p>
1623
   * 
1624
   * @since 3.3
1625
   */
1626
  public static final int MEDIUM = 1 << 16;
1627
1628
  /**
1629
   * Style constant for long date/time format (value is 1&lt;&lt;28).
1630
   * <p>
1631
   * A long date displays the day, month and year.
1632
   * A long time displays hours, minutes, and seconds.
1633
   * The day and month names may be displayed.
1634
   * <br>Note that this is a <em>HINT</em>.
1635
   * </p>
1636
   * <p><b>Used By:</b><ul>
1637
   * <li><code>DateTime</code></li>
1638
   * </ul></p>
1639
   * 
1640
   * @since 3.3
1641
   */
1642
  public static final int LONG = 1 << 28;
1567
1643
1568
  /**
1644
  /**
1569
   * Throws an appropriate exception based on the passed in error code.
1645
   * Throws an appropriate exception based on the passed in error code.
(-)src/org/eclipse/swt/widgets/DateTime.java (+891 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002-2008 Innoopract Informationssysteme GmbH. All rights
3
 * reserved. This program and the accompanying materials are made available
4
 * under the terms of the Eclipse Public License v1.0 which accompanies this
5
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
6
 * Contributors: Innoopract Informationssysteme GmbH - initial API and
7
 * implementation
8
 ******************************************************************************/
9
package org.eclipse.swt.widgets;
10
11
import java.text.*;
12
import java.util.*;
13
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.SWTException;
16
import org.eclipse.swt.events.SelectionEvent;
17
import org.eclipse.swt.events.SelectionListener;
18
import org.eclipse.swt.graphics.*;
19
import org.eclipse.swt.internal.graphics.TextSizeDetermination;
20
import org.eclipse.swt.internal.widgets.IDateTimeAdapter;
21
22
/**
23
 * Instances of this class are selectable user interface objects that allow the
24
 * user to enter and modify date or time values.
25
 * <p>
26
 * Note that although this class is a subclass of <code>Composite</code>, it
27
 * does not make sense to add children to it, or set a layout on it.
28
 * </p>
29
 * <dl>
30
 * <dt><b>Styles:</b></dt>
31
 * <dd>DATE, TIME, CALENDAR, SHORT, MEDIUM, LONG</dd>
32
 * <dt><b>Events:</b></dt>
33
 * <dd>Selection</dd>
34
 * </dl>
35
 * <p>
36
 * Note: Only one of the styles DATE, TIME, or CALENDAR may be specified, and
37
 * only one of the styles SHORT, MEDIUM, or LONG may be specified.
38
 * </p>
39
 * <p>
40
 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
41
 * </p>
42
 * 
43
 * @since x.x
44
 */
45
public class DateTime extends Composite {
46
  
47
  private final class DateTimeAdapter implements IDateTimeAdapter {
48
49
    public Rectangle getBounds( final int widget ) {
50
      Rectangle result = new Rectangle( 0, 0, 0, 0);
51
      switch( widget ) {
52
        case WEEKDAY_TEXTFIELD:
53
          result = weekdayTextFieldBounds;
54
        break;
55
        case DAY_TEXTFIELD:
56
          result = dayTextFieldBounds;
57
        break;
58
        case MONTH_TEXTFIELD:
59
          result = monthTextFieldBounds;
60
        break;
61
        case YEAR_TEXTFIELD:
62
          result = yearTextFieldBounds;
63
        break;
64
        case WEEKDAY_MONTH_SEPARATOR:
65
          result = separator0Bounds;
66
        break;
67
        case MONTH_DAY_SEPARATOR:
68
          result = separator1Bounds;
69
        break;
70
        case DAY_YEAR_SEPARATOR:
71
          result = separator2Bounds;
72
        break;
73
        case SPINNER:
74
          result = spinnerBounds;
75
        break;
76
        case HOURS_TEXTFIELD:
77
          result = hoursTextFieldBounds;
78
        break;
79
        case MINUTES_TEXTFIELD:
80
          result = minutesTextFieldBounds;
81
        break;
82
        case SECONDS_TEXTFIELD:
83
          result = secondsTextFieldBounds;
84
        break;
85
        case HOURS_MINUTES_SEPARATOR:
86
          result = separator3Bounds;
87
        break;
88
        case MINUTES_SECONDS_SEPARATOR:
89
          result = separator4Bounds;
90
        break;
91
      }
92
      return result;
93
    }
94
    
95
    public String[] getMonthNames() {
96
      return MONTH_NAMES;
97
    }
98
    
99
    public String[] getWeekdayNames() {
100
      return WEEKDAY_NAMES;
101
    }
102
    
103
    public String getDateSeparator() {
104
      return DATE_SEPARATOR;
105
    }
106
    
107
    public String getDatePattern() {
108
      return DATE_PATTERN;
109
    }
110
  }
111
  
112
  private int V_PADDING = 6;
113
  private int H_PADDING = 6;
114
  
115
  private String[] MONTH_NAMES;  
116
  private String[] WEEKDAY_NAMES;  
117
  private String DATE_SEPARATOR;
118
  private String DATE_PATTERN;
119
  
120
  private final IDateTimeAdapter dateTimeAdapter;  
121
  private Calendar rightNow;
122
  
123
  // Date fields  
124
  private Rectangle weekdayTextFieldBounds;
125
  private Rectangle dayTextFieldBounds;
126
  private Rectangle monthTextFieldBounds;
127
  private Rectangle yearTextFieldBounds;
128
  private Rectangle separator0Bounds;
129
  private Rectangle separator1Bounds;
130
  private Rectangle separator2Bounds;
131
  private Rectangle spinnerBounds;
132
  // Time fields
133
  private Rectangle hoursTextFieldBounds;
134
  private Rectangle minutesTextFieldBounds;
135
  private Rectangle secondsTextFieldBounds;
136
  private Rectangle separator3Bounds;
137
  private Rectangle separator4Bounds;
138
  
139
  /**
140
   * Constructs a new instance of this class given its parent and a style value
141
   * describing its behavior and appearance.
142
   * <p>
143
   * The style value is either one of the style constants defined in class
144
   * <code>SWT</code> which is applicable to instances of this class, or must
145
   * be built by <em>bitwise OR</em>'ing together (that is, using the
146
   * <code>int</code> "|" operator) two or more of those <code>SWT</code>
147
   * style constants. The class description lists the style constants that are
148
   * applicable to the class. Style bits are also inherited from superclasses.
149
   * </p>
150
   * 
151
   * @param parent a composite control which will be the parent of the new
152
   *          instance (cannot be null)
153
   * @param style the style of control to construct
154
   * @exception IllegalArgumentException
155
   *              <ul>
156
   *              <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
157
   *              </ul>
158
   * @exception SWTException
159
   *              <ul>
160
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
161
   *              thread that created the parent</li>
162
   *              <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed
163
   *              subclass</li>
164
   *              </ul>
165
   * @see SWT#DATE
166
   * @see SWT#TIME
167
   * @see SWT#CALENDAR
168
   * @see Widget#checkSubclass
169
   * @see Widget#getStyle
170
   */
171
  public DateTime( final Composite parent, final int style ) {
172
    super( parent, checkStyle( style ) );
173
    dateTimeAdapter = new DateTimeAdapter();
174
    rightNow = Calendar.getInstance();    
175
    DateFormatSymbols symbols = new DateFormatSymbols();
176
    MONTH_NAMES = symbols.getMonths();
177
    WEEKDAY_NAMES = symbols.getWeekdays();
178
    DATE_SEPARATOR = getDateSeparator();
179
    DATE_PATTERN = getDatePattern( DATE_SEPARATOR );
180
    computeSubWidgetsBounds();
181
  }
182
183
  /**
184
   * Adds the listener to the collection of listeners who will be notified when
185
   * the control is selected by the user, by sending it one of the messages
186
   * defined in the <code>SelectionListener</code> interface.
187
   * <p>
188
   * <code>widgetSelected</code> is called when the user changes the control's
189
   * value. <code>widgetDefaultSelected</code> is not called.
190
   * </p>
191
   * 
192
   * @param listener the listener which should be notified
193
   * @exception IllegalArgumentException
194
   *              <ul>
195
   *              <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
196
   *              </ul>
197
   * @exception SWTException
198
   *              <ul>
199
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
200
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
201
   *              thread that created the receiver</li>
202
   *              </ul>
203
   * @see SelectionListener
204
   * @see #removeSelectionListener
205
   * @see SelectionEvent
206
   */
207
  public void addSelectionListener( final SelectionListener listener ) {
208
    SelectionEvent.addListener( this, listener );
209
  }
210
  
211
  /**
212
   * Removes the listener from the collection of listeners who will be notified
213
   * when the control is selected by the user.
214
   * 
215
   * @param listener the listener which should no longer be notified
216
   * @exception IllegalArgumentException
217
   *              <ul>
218
   *              <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
219
   *              </ul>
220
   * @exception SWTException
221
   *              <ul>
222
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
223
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
224
   *              thread that created the receiver</li>
225
   *              </ul>
226
   * @see SelectionListener
227
   * @see #addSelectionListener
228
   */
229
  public void removeSelectionListener( final SelectionListener listener ) {
230
    SelectionEvent.removeListener( this, listener );
231
  }  
232
233
  /**
234
   * Returns the receiver's hours.
235
   * <p>
236
   * Hours is an integer between 0 and 23.
237
   * </p>
238
   * 
239
   * @return an integer between 0 and 23
240
   * @exception SWTException
241
   *              <ul>
242
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
243
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
244
   *              thread that created the receiver</li>
245
   *              </ul>
246
   */
247
  public int getHours() {
248
    checkWidget();
249
    return rightNow.get( Calendar.HOUR_OF_DAY );
250
  }
251
252
  /**
253
   * Returns the receiver's minutes.
254
   * <p>
255
   * Minutes is an integer between 0 and 59.
256
   * </p>
257
   * 
258
   * @return an integer between 0 and 59
259
   * @exception SWTException
260
   *              <ul>
261
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
262
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
263
   *              thread that created the receiver</li>
264
   *              </ul>
265
   */
266
  public int getMinutes() {
267
    checkWidget();
268
    return rightNow.get( Calendar.MINUTE );
269
  }
270
  
271
  /**
272
   * Returns the receiver's seconds.
273
   * <p>
274
   * Seconds is an integer between 0 and 59.
275
   * </p>
276
   * 
277
   * @return an integer between 0 and 59
278
   * @exception SWTException
279
   *              <ul>
280
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
281
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
282
   *              thread that created the receiver</li>
283
   *              </ul>
284
   */
285
  public int getSeconds() {
286
    checkWidget();    
287
    return rightNow.get( Calendar.SECOND );
288
  }
289
  
290
  /**
291
   * Returns the receiver's date, or day of the month.
292
   * <p>
293
   * The first day of the month is 1, and the last day depends on the month and
294
   * year.
295
   * </p>
296
   * 
297
   * @return a positive integer beginning with 1
298
   * @exception SWTException
299
   *              <ul>
300
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
301
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
302
   *              thread that created the receiver</li>
303
   *              </ul>
304
   */
305
  public int getDay() {
306
    checkWidget();    
307
    return rightNow.get( Calendar.DATE );
308
  }
309
310
  /**
311
   * Returns the receiver's month.
312
   * <p>
313
   * The first month of the year is 0, and the last month is 11.
314
   * </p>
315
   * 
316
   * @return an integer between 0 and 11
317
   * @exception SWTException
318
   *              <ul>
319
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
320
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
321
   *              thread that created the receiver</li>
322
   *              </ul>
323
   */
324
  public int getMonth() {
325
    checkWidget();    
326
    return rightNow.get( Calendar.MONTH );
327
  }
328
329
  /**
330
   * Returns the receiver's year.
331
   * <p>
332
   * The first year is 1752 and the last year is 9999.
333
   * </p>
334
   * 
335
   * @return an integer between 1752 and 9999
336
   * @exception SWTException
337
   *              <ul>
338
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
339
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
340
   *              thread that created the receiver</li>
341
   *              </ul>
342
   */
343
  public int getYear() {
344
    checkWidget();   
345
    return rightNow.get( Calendar.YEAR );
346
  } 
347
348
  /**
349
   * Sets the receiver's hours.
350
   * <p>
351
   * Hours is an integer between 0 and 23.
352
   * </p>
353
   * 
354
   * @param hours an integer between 0 and 23
355
   * @exception SWTException
356
   *              <ul>
357
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
358
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
359
   *              thread that created the receiver</li>
360
   *              </ul>
361
   */
362
  public void setHours( final int hours ) {
363
    checkWidget();
364
    if( hours >= 0 && hours <= 23 ) {
365
      rightNow.set( Calendar.HOUR_OF_DAY, hours );
366
    }
367
  }
368
369
  /**
370
   * Sets the receiver's minutes.
371
   * <p>
372
   * Minutes is an integer between 0 and 59.
373
   * </p>
374
   * 
375
   * @param minutes an integer between 0 and 59
376
   * @exception SWTException
377
   *              <ul>
378
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
379
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
380
   *              thread that created the receiver</li>
381
   *              </ul>
382
   */
383
  public void setMinutes( final int minutes ) {
384
    checkWidget();
385
    if( minutes >= 0 && minutes <= 59 ) {
386
      rightNow.set( Calendar.MINUTE, minutes );
387
    }    
388
  }
389
  
390
  /**
391
   * Sets the receiver's seconds.
392
   * <p>
393
   * Seconds is an integer between 0 and 59.
394
   * </p>
395
   * 
396
   * @param seconds an integer between 0 and 59
397
   * @exception SWTException
398
   *              <ul>
399
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
400
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
401
   *              thread that created the receiver</li>
402
   *              </ul>
403
   */
404
  public void setSeconds( final int seconds ) {
405
    checkWidget();
406
    if( seconds >= 0 && seconds <= 59 ) {
407
      rightNow.set( Calendar.SECOND, seconds );
408
    }    
409
  }
410
  
411
  /**
412
   * Sets the receiver's date, or day of the month, to the specified day.
413
   * <p>
414
   * The first day of the month is 1, and the last day depends on the month and
415
   * year.
416
   * </p>
417
   * 
418
   * @param day a positive integer beginning with 1
419
   * @exception SWTException
420
   *              <ul>
421
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
422
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
423
   *              thread that created the receiver</li>
424
   *              </ul>
425
   */
426
  public void setDay( final int day ) {
427
    checkWidget(); 
428
    int month = rightNow.get( Calendar.MONTH );
429
    int year = rightNow.get( Calendar.YEAR );
430
    if( day >= 1 && day <= getDaysInMonth( month, year ) ) {
431
      rightNow.set( Calendar.DATE, day );
432
    }
433
  }
434
435
  /**
436
   * Sets the receiver's month.
437
   * <p>
438
   * The first month of the year is 0, and the last month is 11.
439
   * </p>
440
   * 
441
   * @param month an integer between 0 and 11
442
   * @exception SWTException
443
   *              <ul>
444
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
445
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
446
   *              thread that created the receiver</li>
447
   *              </ul>
448
   */
449
  public void setMonth( final int month ) {
450
    checkWidget();
451
    int date = rightNow.get( Calendar.DATE );
452
    int year = rightNow.get( Calendar.YEAR );
453
    if( month >= 0 && month <= 11 && date <= getDaysInMonth( month, year ) ) {
454
      rightNow.set( Calendar.MONTH, month );
455
    }    
456
  }  
457
458
  /**
459
   * Sets the receiver's year.
460
   * <p>
461
   * The first year is 1752 and the last year is 9999.
462
   * </p>
463
   * 
464
   * @param year an integer between 1752 and 9999
465
   * @exception SWTException
466
   *              <ul>
467
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
468
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
469
   *              thread that created the receiver</li>
470
   *              </ul>
471
   */
472
  public void setYear( final int year ) {
473
    checkWidget();
474
    int date = rightNow.get( Calendar.DATE );
475
    int month = rightNow.get( Calendar.MONTH );
476
    if( year >= 1752 && year <= 9999 && date <= getDaysInMonth( month, year ) ) {
477
      rightNow.set( Calendar.YEAR, year );
478
    }
479
  }
480
  
481
  /**
482
   * Sets the font that the receiver will use to paint textual information
483
   * to the font specified by the argument, or to the default font for that
484
   * kind of control if the argument is null.
485
   *
486
   * @param font the new font (or null)
487
   *
488
   * @exception IllegalArgumentException <ul>
489
   *    <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
490
   *                </ul>
491
   * @exception SWTException <ul>
492
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
493
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
494
   *                </ul>
495
   */
496
  public void setFont( final Font font ) {
497
    if( font != getFont() ) {
498
      super.setFont( font );
499
    }
500
    computeSubWidgetsBounds();
501
  }
502
  
503
  public Object getAdapter( final Class adapter ) {
504
    Object result;
505
    if( adapter == IDateTimeAdapter.class ) {
506
      result = dateTimeAdapter;
507
    } else {
508
      result = super.getAdapter( adapter );
509
    }
510
    return result;
511
  }
512
  
513
  public Point computeSize( final int wHint, 
514
                            final int hHint, 
515
                            final boolean changed ) {
516
    checkWidget();    
517
    int width = 0, height = 0;
518
    if( wHint == SWT.DEFAULT || hHint == SWT.DEFAULT ) {
519
      Point size = computeSubWidgetsBounds();
520
      width = size.x;
521
      height = size.y;
522
    }
523
    if( width == 0 ) {
524
      width = DEFAULT_WIDTH;
525
    }  
526
    if( height == 0 ) {
527
      height = DEFAULT_HEIGHT;
528
    }  
529
    if( wHint != SWT.DEFAULT ) {
530
      width = wHint;
531
    }  
532
    if( hHint != SWT.DEFAULT ) {
533
      height = hHint;
534
    }  
535
    int border = getBorderWidth();
536
    width += border * 2;
537
    height += border * 2;
538
    return new Point( width, height );
539
  }
540
  
541
  private Point computeSubWidgetsBounds() {
542
    Font font = getFont();
543
    int width = 0, height = 0;
544
    if( ( style & SWT.CALENDAR ) != 0 ) {
545
    } else if( ( style & SWT.DATE ) != 0 ) {
546
      Point prefSize = new Point( 0, 0 );
547
      if( DATE_PATTERN.equals( "MDY" ) ) {
548
        prefSize = computeMDYBounds( font );        
549
      } else if( DATE_PATTERN.equals( "DMY" ) ) {
550
        prefSize = computeDMYBounds( font );
551
      } else {
552
        if( ( style & SWT.MEDIUM ) != 0 ) {
553
          prefSize = computeYMDBounds( font );
554
        } else {
555
          prefSize = computeMDYBounds( font ); 
556
        }
557
      }
558
      // Overall widget size
559
      width = prefSize.x;
560
      height = prefSize.y;
561
    } else if( ( style & SWT.TIME ) != 0 ) {
562
      // Hours text field
563
      hoursTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
564
      hoursTextFieldBounds.width 
565
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
566
      hoursTextFieldBounds.height 
567
        = TextSizeDetermination.stringExtent( font, "88" ).y + V_PADDING;
568
      // Hours minutes separator
569
      separator3Bounds = new Rectangle( 0, 0, 0, 0 );
570
      separator3Bounds.x = hoursTextFieldBounds.x + hoursTextFieldBounds.width;
571
      separator3Bounds.width 
572
        = TextSizeDetermination.stringExtent( font, ":" ).x;
573
      separator3Bounds.height = hoursTextFieldBounds.height;
574
      // Minutes text field
575
      minutesTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
576
      minutesTextFieldBounds.x = separator3Bounds.x + separator3Bounds.width;
577
      minutesTextFieldBounds.width = hoursTextFieldBounds.width;
578
      minutesTextFieldBounds.height = hoursTextFieldBounds.height;
579
      // Minutes seconds separator
580
      separator4Bounds = new Rectangle( 0, 0, 0, 0 );
581
      separator4Bounds.x = minutesTextFieldBounds.x 
582
                         + minutesTextFieldBounds.width;
583
      separator4Bounds.width = separator3Bounds.width;
584
      separator4Bounds.height = hoursTextFieldBounds.height;
585
      // Seconds text field
586
      secondsTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
587
      secondsTextFieldBounds.x = separator4Bounds.x + separator4Bounds.width;
588
      secondsTextFieldBounds.width = hoursTextFieldBounds.width;
589
      secondsTextFieldBounds.height = hoursTextFieldBounds.height;
590
      // The spinner bounds
591
      spinnerBounds = new Rectangle( 0, 0, 0, 0 );
592
      spinnerBounds.x = minutesTextFieldBounds.x 
593
                      + minutesTextFieldBounds.width;
594
      if( ( style & SWT.MEDIUM ) != 0 || ( style & SWT.LONG) != 0 ) {
595
        spinnerBounds.x = secondsTextFieldBounds.x 
596
                        + secondsTextFieldBounds.width;
597
      }
598
      spinnerBounds.width = 17;
599
      spinnerBounds.height = hoursTextFieldBounds.height;
600
      // Overall widget size     
601
      width = spinnerBounds.x + spinnerBounds.width;
602
      height = hoursTextFieldBounds.height;        
603
    }
604
    return new Point( width, height );
605
  }
606
  
607
  private Point computeMDYBounds( final Font font ) {
608
    // The weekday text field bounds
609
    weekdayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
610
    if( ( style & SWT.LONG ) != 0 ) {
611
      weekdayTextFieldBounds.width
612
        = getMaxStringLength( font, WEEKDAY_NAMES ) + H_PADDING + 2;
613
    }  
614
    weekdayTextFieldBounds.height
615
      = TextSizeDetermination.stringExtent( font, WEEKDAY_NAMES[1] ).y
616
        + V_PADDING;
617
    // The weekday month separator bounds
618
    separator0Bounds = new Rectangle( 0, 0, 0, 0 );
619
    separator0Bounds.x 
620
      = weekdayTextFieldBounds.x + weekdayTextFieldBounds.width;
621
    if( ( style & SWT.LONG ) != 0 ) {
622
      separator0Bounds.width 
623
        = TextSizeDetermination.stringExtent( font, "," ).x;
624
    }
625
    separator0Bounds.height = weekdayTextFieldBounds.height;      
626
    // The month text field bounds
627
    monthTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
628
    monthTextFieldBounds.x = separator0Bounds.x + separator0Bounds.width;
629
    if( ( style & SWT.MEDIUM ) != 0 ) {
630
      monthTextFieldBounds.width 
631
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
632
    } else {        
633
      monthTextFieldBounds.width 
634
        = getMaxStringLength( font, MONTH_NAMES ) + H_PADDING + 2;
635
    }
636
    monthTextFieldBounds.height = weekdayTextFieldBounds.height;
637
    // The month date separator bounds
638
    separator1Bounds = new Rectangle( 0, 0, 0, 0 );
639
    separator1Bounds.x = monthTextFieldBounds.x + monthTextFieldBounds.width;
640
    if( ( style & SWT.MEDIUM ) != 0 ) {
641
      separator1Bounds.width 
642
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
643
    }
644
    separator1Bounds.height = weekdayTextFieldBounds.height;
645
    // The date text field bounds
646
    dayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
647
    dayTextFieldBounds.x = separator1Bounds.x + separator1Bounds.width;
648
    if( ( style & SWT.SHORT ) == 0 ) {
649
      dayTextFieldBounds.width 
650
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
651
    }
652
    dayTextFieldBounds.height = weekdayTextFieldBounds.height;
653
    // The date year separator bounds
654
    separator2Bounds = new Rectangle( 0, 0, 0, 0 );
655
    separator2Bounds.x = dayTextFieldBounds.x + dayTextFieldBounds.width;
656
    if( ( style & SWT.MEDIUM ) != 0 ) {
657
      separator2Bounds.width 
658
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
659
    } else {
660
      separator2Bounds.width 
661
        = TextSizeDetermination.stringExtent( font, "," ).x;
662
    }
663
    separator2Bounds.height = weekdayTextFieldBounds.height;            
664
    // The year text field bounds
665
    yearTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
666
    yearTextFieldBounds.x = separator2Bounds.x + separator2Bounds.width;
667
    yearTextFieldBounds.width 
668
      = TextSizeDetermination.stringExtent( font, "8888" ).x + H_PADDING;
669
    yearTextFieldBounds.height = weekdayTextFieldBounds.height;
670
    // The spinner bounds
671
    spinnerBounds = new Rectangle( 0, 0, 0, 0 );
672
    spinnerBounds.x = yearTextFieldBounds.x + yearTextFieldBounds.width;
673
    spinnerBounds.width = 17;
674
    spinnerBounds.height = weekdayTextFieldBounds.height;
675
    // Overall widget size
676
    int width = spinnerBounds.x + spinnerBounds.width;
677
    int height = weekdayTextFieldBounds.height;
678
    return new Point( width, height );
679
  }
680
  
681
  private Point computeDMYBounds( final Font font ) {
682
    // The weekday text field bounds
683
    weekdayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
684
    if( ( style & SWT.LONG ) != 0 ) {
685
      weekdayTextFieldBounds.width
686
        = getMaxStringLength( font, WEEKDAY_NAMES ) + H_PADDING + 2;
687
    }  
688
    weekdayTextFieldBounds.height
689
      = TextSizeDetermination.stringExtent( font, WEEKDAY_NAMES[1] ).y 
690
        + V_PADDING;
691
    // The weekday day separator bounds
692
    separator0Bounds = new Rectangle( 0, 0, 0, 0 );
693
    separator0Bounds.x 
694
      = weekdayTextFieldBounds.x + weekdayTextFieldBounds.width;
695
    if( ( style & SWT.LONG ) != 0 ) {
696
      separator0Bounds.width 
697
        = TextSizeDetermination.stringExtent( font, "," ).x;
698
    }
699
    separator0Bounds.height = weekdayTextFieldBounds.height;      
700
    // The day text field bounds
701
    dayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
702
    dayTextFieldBounds.x = separator0Bounds.x + separator0Bounds.width;
703
    if( ( style & SWT.SHORT ) == 0 ) {
704
      dayTextFieldBounds.width 
705
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
706
    }
707
    dayTextFieldBounds.height = weekdayTextFieldBounds.height;
708
    // The day month separator bounds
709
    separator1Bounds = new Rectangle( 0, 0, 0, 0 );
710
    separator1Bounds.x = dayTextFieldBounds.x + dayTextFieldBounds.width;
711
    if( ( style & SWT.MEDIUM ) != 0 ) {
712
      separator1Bounds.width 
713
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
714
    }
715
    separator1Bounds.height = weekdayTextFieldBounds.height;
716
    // The month text field bounds
717
    monthTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
718
    monthTextFieldBounds.x = separator1Bounds.x + separator1Bounds.width;
719
    if( ( style & SWT.MEDIUM ) != 0 ) {
720
      monthTextFieldBounds.width 
721
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
722
    } else {        
723
      monthTextFieldBounds.width 
724
        = getMaxStringLength( font, MONTH_NAMES ) + H_PADDING + 2;
725
    }
726
    monthTextFieldBounds.height = weekdayTextFieldBounds.height;
727
    // The month year separator bounds
728
    separator2Bounds = new Rectangle( 0, 0, 0, 0 );
729
    separator2Bounds.x = monthTextFieldBounds.x + monthTextFieldBounds.width;
730
    if( ( style & SWT.MEDIUM ) != 0 ) {
731
      separator2Bounds.width 
732
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
733
    } else {
734
      separator2Bounds.width 
735
        = TextSizeDetermination.stringExtent( font, "," ).x;
736
    }
737
    separator2Bounds.height = weekdayTextFieldBounds.height;            
738
    // The year text field bounds
739
    yearTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
740
    yearTextFieldBounds.x = separator2Bounds.x + separator2Bounds.width;
741
    yearTextFieldBounds.width 
742
      = TextSizeDetermination.stringExtent( font, "8888" ).x + H_PADDING;
743
    yearTextFieldBounds.height = weekdayTextFieldBounds.height;
744
    // The spinner bounds
745
    spinnerBounds = new Rectangle( 0, 0, 0, 0 );
746
    spinnerBounds.x = yearTextFieldBounds.x + yearTextFieldBounds.width;
747
    spinnerBounds.width = 17;
748
    spinnerBounds.height = weekdayTextFieldBounds.height;
749
    // Overall widget size
750
    int width = spinnerBounds.x + spinnerBounds.width;
751
    int height = weekdayTextFieldBounds.height;
752
    return new Point( width, height );
753
  }
754
755
  private Point computeYMDBounds( final Font font ) {
756
    // The weekday text field bounds
757
    weekdayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
758
    if( ( style & SWT.LONG ) != 0 ) {
759
      weekdayTextFieldBounds.width
760
        = getMaxStringLength( font, WEEKDAY_NAMES ) + H_PADDING + 2;
761
    }  
762
    weekdayTextFieldBounds.height
763
      = TextSizeDetermination.stringExtent( font, WEEKDAY_NAMES[1] ).y 
764
        + V_PADDING;
765
    // The weekday day separator bounds
766
    separator0Bounds = new Rectangle( 0, 0, 0, 0 );
767
    separator0Bounds.x 
768
      = weekdayTextFieldBounds.x + weekdayTextFieldBounds.width;
769
    if( ( style & SWT.LONG ) != 0 ) {
770
      separator0Bounds.width 
771
        = TextSizeDetermination.stringExtent( font, "," ).x;
772
    }
773
    separator0Bounds.height = weekdayTextFieldBounds.height;
774
    // The year text field bounds
775
    yearTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
776
    yearTextFieldBounds.x = separator0Bounds.x + separator0Bounds.width;
777
    yearTextFieldBounds.width 
778
      = TextSizeDetermination.stringExtent( font, "8888" ).x + H_PADDING;
779
    yearTextFieldBounds.height = weekdayTextFieldBounds.height;
780
    // The year month separator bounds
781
    separator1Bounds = new Rectangle( 0, 0, 0, 0 );
782
    separator1Bounds.x = yearTextFieldBounds.x + yearTextFieldBounds.width;
783
    if( ( style & SWT.MEDIUM ) != 0 ) {
784
      separator1Bounds.width 
785
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
786
    }
787
    // The month text field bounds
788
    monthTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
789
    monthTextFieldBounds.x = separator1Bounds.x + separator1Bounds.width;
790
    if( ( style & SWT.MEDIUM ) != 0 ) {
791
      monthTextFieldBounds.width 
792
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
793
    } else {        
794
      monthTextFieldBounds.width 
795
        = getMaxStringLength( font, MONTH_NAMES ) + H_PADDING + 2;
796
    }
797
    monthTextFieldBounds.height = weekdayTextFieldBounds.height;
798
    // The month day separator bounds
799
    separator2Bounds = new Rectangle( 0, 0, 0, 0 );
800
    separator2Bounds.x = monthTextFieldBounds.x + monthTextFieldBounds.width;
801
    if( ( style & SWT.MEDIUM ) != 0 ) {
802
      separator2Bounds.width 
803
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
804
    } else {
805
      separator2Bounds.width 
806
        = TextSizeDetermination.stringExtent( font, "," ).x;
807
    }
808
    separator2Bounds.height = weekdayTextFieldBounds.height;     
809
    // The day text field bounds
810
    dayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
811
    dayTextFieldBounds.x = separator2Bounds.x + separator2Bounds.width;
812
    if( ( style & SWT.SHORT ) == 0 ) {
813
      dayTextFieldBounds.width 
814
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
815
    }
816
    dayTextFieldBounds.height = weekdayTextFieldBounds.height;
817
    
818
    separator1Bounds.height = weekdayTextFieldBounds.height;    
819
    // The spinner bounds
820
    spinnerBounds = new Rectangle( 0, 0, 0, 0 );
821
    spinnerBounds.x = dayTextFieldBounds.x + dayTextFieldBounds.width;
822
    spinnerBounds.width = 17;
823
    spinnerBounds.height = weekdayTextFieldBounds.height;
824
    // Overall widget size
825
    int width = spinnerBounds.x + spinnerBounds.width;
826
    int height = weekdayTextFieldBounds.height;
827
    return new Point( width, height );
828
  }
829
  
830
  private int getDaysInMonth( final int month, final int year ) {
831
    GregorianCalendar cal = new GregorianCalendar( year, month, 1 );
832
    return cal.getActualMaximum( Calendar.DAY_OF_MONTH );
833
  }
834
  
835
  private int getMaxStringLength( final Font font, final String[] strings ) {
836
    int maxLength = 0;
837
    for( int i = 0; i < strings.length; i++ ) {
838
      int currentStringWidth
839
        = TextSizeDetermination.stringExtent( font, strings[i] ).x;
840
      maxLength = Math.max( maxLength, currentStringWidth );
841
    }
842
    return maxLength;
843
  }
844
  
845
  private String getDateSeparator() {
846
    DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT );    
847
    String datePattern = ( ( SimpleDateFormat )df ).toPattern();
848
    String result = "";
849
    int index = 0;
850
    while( Character.isLetter( datePattern.charAt( index ) ) ) {
851
      index++;
852
    }
853
    result = Character.toString( datePattern.charAt( index ) );
854
    return result;
855
  }
856
  
857
  private String getDatePattern( final String dateSeparator ) {
858
    DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT );    
859
    String datePattern = ( ( SimpleDateFormat )df ).toPattern();
860
    String result = "";
861
    StringTokenizer st = new StringTokenizer( datePattern, 
862
                                              dateSeparator );
863
    while ( st.hasMoreTokens() ) {
864
      String token = st.nextToken();
865
      result += Character.toString( token.charAt( 0 ) );
866
    }
867
    return result.toUpperCase();
868
  }
869
  
870
  String getNameText() {
871
    return "DateTime";
872
  } 
873
  
874
  static int checkStyle( final int value ) {
875
    /*
876
     * Even though it is legal to create this widget with scroll bars, they
877
     * serve no useful purpose because they do not automatically scroll the
878
     * widget's client area. The fix is to clear the SWT style.
879
     */
880
    int style = value;
881
    style &= ~( SWT.H_SCROLL | SWT.V_SCROLL );
882
    style = checkBits( style, SWT.DATE, SWT.TIME, SWT.CALENDAR, 0, 0, 0 );
883
    return checkBits( style, SWT.MEDIUM, SWT.SHORT, SWT.LONG, 0, 0, 0 );
884
  }
885
886
  protected void checkSubclass() {
887
    if( !isValidSubclass() ) {
888
      error( SWT.ERROR_INVALID_SUBCLASS );
889
    }  
890
  }
891
}
(-)src/org/eclipse/swt/internal/widgets/IDateTimeAdapter.java (+40 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007-2008 Innoopract Informationssysteme GmbH. All rights
3
 * reserved. This program and the accompanying materials are made available
4
 * under the terms of the Eclipse Public License v1.0 which accompanies this
5
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
6
 * Contributors: Innoopract Informationssysteme GmbH - initial API and
7
 * implementation
8
 ******************************************************************************/
9
package org.eclipse.swt.internal.widgets;
10
11
import org.eclipse.swt.graphics.Rectangle;
12
13
public interface IDateTimeAdapter {
14
  // Date
15
  int WEEKDAY_TEXTFIELD = 0;
16
  int DAY_TEXTFIELD = 1;
17
  int MONTH_TEXTFIELD = 2;
18
  int YEAR_TEXTFIELD = 3;
19
  int WEEKDAY_MONTH_SEPARATOR = 4;
20
  int MONTH_DAY_SEPARATOR = 5;
21
  int DAY_YEAR_SEPARATOR = 6;
22
  int SPINNER = 7;
23
  // Time
24
  int HOURS_TEXTFIELD = 8;
25
  int MINUTES_TEXTFIELD = 9;
26
  int SECONDS_TEXTFIELD = 10;
27
  int HOURS_MINUTES_SEPARATOR = 11;
28
  int MINUTES_SECONDS_SEPARATOR = 12;
29
30
  Rectangle getBounds( int widget );
31
  
32
  String[] getMonthNames();
33
  
34
  String[] getWeekdayNames();
35
  
36
  String getDateSeparator();
37
  
38
  String getDatePattern();
39
  
40
}
(-)src/org/eclipse/rap/demo/controls/ControlsDemo.java (+1 lines)
Lines 60-65 Link Here
60
      new CompositeTab( topFolder ),
60
      new CompositeTab( topFolder ),
61
      new CoolBarTab( topFolder ),
61
      new CoolBarTab( topFolder ),
62
      new DialogsTab( topFolder ),
62
      new DialogsTab( topFolder ),
63
      new DateTimeTab( topFolder ),
63
      new GroupTab( topFolder ),
64
      new GroupTab( topFolder ),
64
      new LabelTab( topFolder ),
65
      new LabelTab( topFolder ),
65
      new ListTab( topFolder ),
66
      new ListTab( topFolder ),
(-)src/org/eclipse/rap/demo/controls/DateTimeTab.java (+134 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002-2008 Innoopract Informationssysteme GmbH. All rights
3
 * reserved. This program and the accompanying materials are made available
4
 * under the terms of the Eclipse Public License v1.0 which accompanies this
5
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
6
 * Contributors: Innoopract Informationssysteme GmbH - initial API and
7
 * implementation
8
 ******************************************************************************/
9
package org.eclipse.rap.demo.controls;
10
11
import org.eclipse.jface.dialogs.MessageDialog;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.custom.CTabFolder;
14
import org.eclipse.swt.events.*;
15
import org.eclipse.swt.layout.RowLayout;
16
import org.eclipse.swt.widgets.*;
17
18
class DateTimeTab extends ExampleTab {
19
20
  private static final String PROP_CONTEXT_MENU = "contextMenu";
21
  private static final String PROP_SELECTION_LISTENER = "selectionListener";
22
  DateTime dateTime1;
23
  Group group1, group2;
24
25
  DateTimeTab( final CTabFolder topFolder ) {
26
    super( topFolder, "DateTime" );
27
    setDefaultStyle( SWT.BORDER | SWT.DATE | SWT.MEDIUM );
28
  }
29
30
  protected void createStyleControls( final Composite parent ) {
31
    group1 = new Group( styleComp, SWT.SHADOW_IN );
32
    group1.setLayout( new RowLayout( SWT.VERTICAL ) );
33
    createStyleButton( group1, "DATE", SWT.DATE, SWT.RADIO, true );
34
    createStyleButton( group1, "TIME", SWT.TIME, SWT.RADIO, false );
35
    createStyleButton( group1, "CALENDAR", SWT.CALENDAR, SWT.RADIO, false );
36
    group2 = new Group( styleComp, SWT.SHADOW_IN );
37
    group2.setLayout( new RowLayout( SWT.VERTICAL ) );
38
    createStyleButton( group2, "SHORT", SWT.SHORT, SWT.RADIO, false );
39
    createStyleButton( group2, "MEDIUM", SWT.MEDIUM, SWT.RADIO, true );
40
    createStyleButton( group2, "LONG", SWT.LONG, SWT.RADIO, false );
41
    createStyleButton( "BORDER", SWT.BORDER, true );
42
    createVisibilityButton();
43
    createEnablementButton();
44
    createFontChooser();
45
    createFgColorButton();
46
    createBgColorButton();
47
    createPropertyCheckbox( "Add Context Menu", PROP_CONTEXT_MENU );
48
    createPropertyCheckbox( "Add Selection Listener", PROP_SELECTION_LISTENER );
49
  }
50
51
  protected void createExampleControls( final Composite parent ) {
52
    parent.setLayout( new RowLayout( SWT.VERTICAL ) );
53
    int style = getStyle() | getStyle( group1 ) | getStyle( group2 );
54
    /* Create the example widgets */
55
    dateTime1 = new DateTime( parent, style );
56
    if( hasCreateProperty( PROP_CONTEXT_MENU ) ) {
57
      Menu dateTimeMenu = new Menu( dateTime1 );
58
      MenuItem dateTimeMenuItem = new MenuItem( dateTimeMenu, SWT.PUSH );
59
      dateTimeMenuItem.addSelectionListener( new SelectionAdapter() {
60
61
        public void widgetSelected( final SelectionEvent event ) {
62
          String message = "You requested a context menu for the DateTime";
63
          MessageDialog.openInformation( dateTime1.getShell(),
64
                                         "Information",
65
                                         message );
66
        }
67
      } );
68
      dateTimeMenuItem.setText( "DateTime context menu item" );
69
      dateTime1.setMenu( dateTimeMenu );
70
    }
71
    if( hasCreateProperty( PROP_SELECTION_LISTENER ) ) {
72
      dateTime1.addSelectionListener( new SelectionListener() {
73
74
        public void widgetSelected( final SelectionEvent event ) {
75
          String message = "DateTime WidgetSelected!";
76
          MessageDialog.openInformation( dateTime1.getShell(),
77
                                         "Information",
78
                                         message );
79
          //log( message );
80
        }
81
82
        public void widgetDefaultSelected( final SelectionEvent event ) {
83
          String message = "DateTime WidgetDefaultSelected!";
84
          MessageDialog.openInformation( dateTime1.getShell(),
85
                                         "Information",
86
                                         message );
87
          //log( message );
88
        }
89
      } );
90
    }
91
    registerControl( dateTime1 );
92
  }
93
94
  protected Button createStyleButton( final Composite parent,
95
                                      final String name,
96
                                      final int style,
97
                                      final int buttonStyle,
98
                                      final boolean checked )
99
  {
100
    Button button = new Button( parent, buttonStyle );
101
    button.setText( name );
102
    button.addSelectionListener( new SelectionAdapter() {
103
104
      public void widgetSelected( final SelectionEvent event ) {
105
        createNew();
106
      }
107
    } );
108
    button.setData( "style", new Integer( style ) );
109
    button.setSelection( checked );
110
    return button;
111
  }
112
113
  protected int getStyle( final Composite comp ) {
114
    int result = SWT.NONE;
115
    if( comp != null ) {
116
      Control[] ctrls = comp.getChildren();
117
      if( ctrls.length != 0 ) {
118
        for( int i = 0; i < ctrls.length; i++ ) {
119
          if( ctrls[ i ] instanceof Button ) {
120
            Button button = ( Button )ctrls[ i ];
121
            if( button.getSelection() ) {
122
              Object data = button.getData( "style" );
123
              if( data != null && data instanceof Integer ) {
124
                int style = ( ( Integer )data ).intValue();
125
                result |= style;
126
              }
127
            }
128
          }
129
        }
130
      }
131
    }
132
    return result;
133
  }
134
}
(-)src/org/eclipse/RWTQ07TestSuite.java (+2 lines)
Lines 25-30 Link Here
25
import org.eclipse.swt.internal.widgets.combokit.ComboLCA_Test;
25
import org.eclipse.swt.internal.widgets.combokit.ComboLCA_Test;
26
import org.eclipse.swt.internal.widgets.controlkit.ControlLCA_Test;
26
import org.eclipse.swt.internal.widgets.controlkit.ControlLCA_Test;
27
import org.eclipse.swt.internal.widgets.coolbarkit.CoolBarLCA_Test;
27
import org.eclipse.swt.internal.widgets.coolbarkit.CoolBarLCA_Test;
28
import org.eclipse.swt.internal.widgets.datetimekit.DateTimeLCA_Test;
28
import org.eclipse.swt.internal.widgets.displaykit.DisplayLCAFocus_Test;
29
import org.eclipse.swt.internal.widgets.displaykit.DisplayLCAFocus_Test;
29
import org.eclipse.swt.internal.widgets.displaykit.DisplayLCA_Test;
30
import org.eclipse.swt.internal.widgets.displaykit.DisplayLCA_Test;
30
import org.eclipse.swt.internal.widgets.labelkit.LabelLCA_Test;
31
import org.eclipse.swt.internal.widgets.labelkit.LabelLCA_Test;
Lines 107-112 Link Here
107
    suite.addTestSuite( ToolItemLCA_Test.class );
108
    suite.addTestSuite( ToolItemLCA_Test.class );
108
    suite.addTestSuite( TabFolderLCA_Test.class );
109
    suite.addTestSuite( TabFolderLCA_Test.class );
109
    suite.addTestSuite( ScrolledCompositeLCA_Test.class );
110
    suite.addTestSuite( ScrolledCompositeLCA_Test.class );
111
    suite.addTestSuite( DateTimeLCA_Test.class );
110
112
111
    return suite;
113
    return suite;
112
  }
114
  }
(-)src/org/eclipse/swt/internal/widgets/datetimekit/DateTimeLCA_Test.java (+246 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002-2006 Innoopract Informationssysteme GmbH. All rights
3
 * reserved. This program and the accompanying materials are made available
4
 * under the terms of the Eclipse Public License v1.0 which accompanies this
5
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
6
 * Contributors: Innoopract Informationssysteme GmbH - initial API and
7
 * implementation
8
 ******************************************************************************/
9
package org.eclipse.swt.internal.widgets.datetimekit;
10
11
import junit.framework.TestCase;
12
13
import org.eclipse.rwt.Fixture;
14
import org.eclipse.rwt.graphics.Graphics;
15
import org.eclipse.rwt.internal.lifecycle.JSConst;
16
import org.eclipse.rwt.lifecycle.IWidgetAdapter;
17
import org.eclipse.rwt.lifecycle.WidgetUtil;
18
import org.eclipse.swt.RWTFixture;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.events.*;
21
import org.eclipse.swt.graphics.*;
22
import org.eclipse.swt.internal.widgets.IDateTimeAdapter;
23
import org.eclipse.swt.internal.widgets.Props;
24
import org.eclipse.swt.widgets.*;
25
26
public class DateTimeLCA_Test extends TestCase {
27
28
  public void testDateTimeDatePreserveValues() {
29
    Display display = new Display();
30
    Composite shell = new Shell( display, SWT.NONE );
31
    DateTime dateTime = new DateTime( shell, SWT.DATE | SWT.MEDIUM );
32
    dateTime.setDay( 1 );
33
    dateTime.setMonth( 1 );
34
    dateTime.setYear( 2008 );
35
    RWTFixture.markInitialized( display );
36
    // Test preserved day, month, year
37
    RWTFixture.preserveWidgets();
38
    IWidgetAdapter adapter = WidgetUtil.getAdapter( dateTime );
39
    Integer day = ( Integer )adapter.getPreserved( DateTimeDateLCA.PROP_DAY );
40
    assertEquals( 1, day.intValue() );
41
    Integer month = ( Integer )adapter.getPreserved( DateTimeDateLCA.PROP_MONTH );
42
    assertEquals( 1, month.intValue() );
43
    Integer year = ( Integer )adapter.getPreserved( DateTimeDateLCA.PROP_YEAR );
44
    assertEquals( 2008, year.intValue() );
45
    RWTFixture.clearPreserved();
46
    // Test preserved control properties
47
    testPreserveControlProperties( dateTime );
48
    // Test preserved sub widgets bounds
49
    IDateTimeAdapter dateTimeAdapter = DateTimeLCAUtil.getDateTimeAdapter( dateTime );
50
    RWTFixture.preserveWidgets();
51
    Rectangle bounds = ( Rectangle )adapter.getPreserved( IDateTimeAdapter.WEEKDAY_TEXTFIELD
52
                                                          + "_BOUNDS" );
53
    assertEquals( dateTimeAdapter.getBounds( IDateTimeAdapter.WEEKDAY_TEXTFIELD ),
54
                  bounds );
55
    bounds = ( Rectangle )adapter.getPreserved( IDateTimeAdapter.DAY_TEXTFIELD
56
                                                + "_BOUNDS" );
57
    assertEquals( dateTimeAdapter.getBounds( IDateTimeAdapter.DAY_TEXTFIELD ),
58
                  bounds );
59
    bounds = ( Rectangle )adapter.getPreserved( IDateTimeAdapter.MONTH_TEXTFIELD
60
                                                + "_BOUNDS" );
61
    assertEquals( dateTimeAdapter.getBounds( IDateTimeAdapter.MONTH_TEXTFIELD ),
62
                  bounds );
63
    bounds = ( Rectangle )adapter.getPreserved( IDateTimeAdapter.YEAR_TEXTFIELD
64
                                                + "_BOUNDS" );
65
    assertEquals( dateTimeAdapter.getBounds( IDateTimeAdapter.YEAR_TEXTFIELD ),
66
                  bounds );
67
    bounds = ( Rectangle )adapter.getPreserved( IDateTimeAdapter.WEEKDAY_MONTH_SEPARATOR
68
                                                + "_BOUNDS" );
69
    assertEquals( dateTimeAdapter.getBounds( IDateTimeAdapter.WEEKDAY_MONTH_SEPARATOR ),
70
                  bounds );
71
    bounds = ( Rectangle )adapter.getPreserved( IDateTimeAdapter.MONTH_DAY_SEPARATOR
72
                                                + "_BOUNDS" );
73
    assertEquals( dateTimeAdapter.getBounds( IDateTimeAdapter.MONTH_DAY_SEPARATOR ),
74
                  bounds );
75
    bounds = ( Rectangle )adapter.getPreserved( IDateTimeAdapter.DAY_YEAR_SEPARATOR
76
                                                + "_BOUNDS" );
77
    assertEquals( dateTimeAdapter.getBounds( IDateTimeAdapter.DAY_YEAR_SEPARATOR ),
78
                  bounds );
79
    bounds = ( Rectangle )adapter.getPreserved( IDateTimeAdapter.SPINNER
80
                                                + "_BOUNDS" );
81
    assertEquals( dateTimeAdapter.getBounds( IDateTimeAdapter.SPINNER ), bounds );
82
    RWTFixture.clearPreserved();
83
    // Test preserved selection listeners
84
    testPreserveSelectionListener( dateTime );
85
    display.dispose();
86
  }
87
88
  public void testDateTimeTimePreserveValues() {
89
    Display display = new Display();
90
    Composite shell = new Shell( display, SWT.NONE );
91
    DateTime dateTime = new DateTime( shell, SWT.TIME | SWT.MEDIUM );
92
    dateTime.setHours( 1 );
93
    dateTime.setMinutes( 2 );
94
    dateTime.setSeconds( 3 );
95
    RWTFixture.markInitialized( display );
96
    // Test preserved hours, minutes, seconds
97
    RWTFixture.preserveWidgets();
98
    IWidgetAdapter adapter = WidgetUtil.getAdapter( dateTime );
99
    Integer hours = ( Integer )adapter.getPreserved( DateTimeTimeLCA.PROP_HOURS );
100
    assertEquals( 1, hours.intValue() );
101
    Integer minutes = ( Integer )adapter.getPreserved( DateTimeTimeLCA.PROP_MINUTES );
102
    assertEquals( 2, minutes.intValue() );
103
    Integer seconds = ( Integer )adapter.getPreserved( DateTimeTimeLCA.PROP_SECONDS );
104
    assertEquals( 3, seconds.intValue() );
105
    RWTFixture.clearPreserved();
106
    // Test preserved control properties
107
    testPreserveControlProperties( dateTime );
108
    // Test preserved sub widgets bounds
109
    IDateTimeAdapter dateTimeAdapter = DateTimeLCAUtil.getDateTimeAdapter( dateTime );
110
    RWTFixture.preserveWidgets();
111
    Rectangle bounds = ( Rectangle )adapter.getPreserved( IDateTimeAdapter.HOURS_TEXTFIELD
112
                                                          + "_BOUNDS" );
113
    assertEquals( dateTimeAdapter.getBounds( IDateTimeAdapter.HOURS_TEXTFIELD ),
114
                  bounds );
115
    bounds = ( Rectangle )adapter.getPreserved( IDateTimeAdapter.MINUTES_TEXTFIELD
116
                                                + "_BOUNDS" );
117
    assertEquals( dateTimeAdapter.getBounds( IDateTimeAdapter.MINUTES_TEXTFIELD ),
118
                  bounds );
119
    bounds = ( Rectangle )adapter.getPreserved( IDateTimeAdapter.SECONDS_TEXTFIELD
120
                                                + "_BOUNDS" );
121
    assertEquals( dateTimeAdapter.getBounds( IDateTimeAdapter.SECONDS_TEXTFIELD ),
122
                  bounds );
123
    bounds = ( Rectangle )adapter.getPreserved( IDateTimeAdapter.HOURS_MINUTES_SEPARATOR
124
                                                + "_BOUNDS" );
125
    assertEquals( dateTimeAdapter.getBounds( IDateTimeAdapter.HOURS_MINUTES_SEPARATOR ),
126
                  bounds );
127
    bounds = ( Rectangle )adapter.getPreserved( IDateTimeAdapter.MINUTES_SECONDS_SEPARATOR
128
                                                + "_BOUNDS" );
129
    assertEquals( dateTimeAdapter.getBounds( IDateTimeAdapter.MINUTES_SECONDS_SEPARATOR ),
130
                  bounds );
131
    bounds = ( Rectangle )adapter.getPreserved( IDateTimeAdapter.SPINNER
132
                                                + "_BOUNDS" );
133
    assertEquals( dateTimeAdapter.getBounds( IDateTimeAdapter.SPINNER ), bounds );
134
    RWTFixture.clearPreserved();
135
    // Test preserved selection listeners
136
    testPreserveSelectionListener( dateTime );
137
    display.dispose();
138
  }
139
140
  public void testSelectionEvent() {
141
    // Date
142
    Display display = new Display();
143
    Composite shell = new Shell( display, SWT.NONE );
144
    DateTime dateTime = new DateTime( shell, SWT.DATE | SWT.MEDIUM );
145
    testSelectionEvent( dateTime );
146
    // Time
147
    dateTime = new DateTime( shell, SWT.TIME | SWT.MEDIUM );
148
    testSelectionEvent( dateTime );
149
  }
150
151
  private void testPreserveControlProperties( final DateTime dateTime ) {
152
    // control: enabled
153
    RWTFixture.preserveWidgets();
154
    IWidgetAdapter adapter = WidgetUtil.getAdapter( dateTime );
155
    assertEquals( Boolean.TRUE, adapter.getPreserved( Props.ENABLED ) );
156
    RWTFixture.clearPreserved();
157
    dateTime.setEnabled( false );
158
    RWTFixture.preserveWidgets();
159
    adapter = WidgetUtil.getAdapter( dateTime );
160
    assertEquals( Boolean.FALSE, adapter.getPreserved( Props.ENABLED ) );
161
    RWTFixture.clearPreserved();
162
    // visible
163
    RWTFixture.preserveWidgets();
164
    adapter = WidgetUtil.getAdapter( dateTime );
165
    assertEquals( Boolean.TRUE, adapter.getPreserved( Props.VISIBLE ) );
166
    RWTFixture.clearPreserved();
167
    dateTime.setVisible( false );
168
    RWTFixture.preserveWidgets();
169
    adapter = WidgetUtil.getAdapter( dateTime );
170
    assertEquals( Boolean.FALSE, adapter.getPreserved( Props.VISIBLE ) );
171
    RWTFixture.clearPreserved();
172
    // menu
173
    RWTFixture.preserveWidgets();
174
    adapter = WidgetUtil.getAdapter( dateTime );
175
    assertEquals( null, adapter.getPreserved( Props.MENU ) );
176
    RWTFixture.clearPreserved();
177
    Menu menu = new Menu( dateTime );
178
    MenuItem item = new MenuItem( menu, SWT.NONE );
179
    item.setText( "1 Item" );
180
    dateTime.setMenu( menu );
181
    RWTFixture.preserveWidgets();
182
    adapter = WidgetUtil.getAdapter( dateTime );
183
    assertEquals( menu, adapter.getPreserved( Props.MENU ) );
184
    RWTFixture.clearPreserved();
185
    // foreground background font
186
    Color background = Graphics.getColor( 122, 33, 203 );
187
    dateTime.setBackground( background );
188
    Color foreground = Graphics.getColor( 211, 178, 211 );
189
    dateTime.setForeground( foreground );
190
    Font font = Graphics.getFont( "font", 12, SWT.BOLD );
191
    dateTime.setFont( font );
192
    RWTFixture.preserveWidgets();
193
    adapter = WidgetUtil.getAdapter( dateTime );
194
    assertEquals( background, adapter.getPreserved( Props.BACKGROUND ) );
195
    assertEquals( foreground, adapter.getPreserved( Props.FOREGROUND ) );
196
    assertEquals( font, adapter.getPreserved( Props.FONT ) );
197
    RWTFixture.clearPreserved();
198
  }
199
200
  private void testPreserveSelectionListener( final DateTime dateTime ) {
201
    RWTFixture.preserveWidgets();
202
    IWidgetAdapter adapter = WidgetUtil.getAdapter( dateTime );
203
    Boolean hasListeners = ( Boolean )adapter.getPreserved( Props.SELECTION_LISTENERS );
204
    assertEquals( Boolean.FALSE, hasListeners );
205
    RWTFixture.clearPreserved();
206
    SelectionListener selectionListener = new SelectionAdapter() {
207
    };
208
    dateTime.addSelectionListener( selectionListener );
209
    RWTFixture.preserveWidgets();
210
    adapter = WidgetUtil.getAdapter( dateTime );
211
    hasListeners = ( Boolean )adapter.getPreserved( Props.SELECTION_LISTENERS );
212
    assertEquals( Boolean.TRUE, hasListeners );
213
    RWTFixture.clearPreserved();
214
  }
215
216
  private void testSelectionEvent( final DateTime dateTime ) {
217
    final StringBuffer log = new StringBuffer();
218
    SelectionListener selectionListener = new SelectionAdapter() {
219
220
      public void widgetSelected( SelectionEvent event ) {
221
        assertEquals( dateTime, event.getSource() );
222
        assertEquals( null, event.item );
223
        assertEquals( SWT.NONE, event.detail );
224
        assertEquals( 0, event.x );
225
        assertEquals( 0, event.y );
226
        assertEquals( 0, event.width );
227
        assertEquals( 0, event.height );
228
        assertEquals( true, event.doit );
229
        log.append( "widgetSelected" );
230
      }
231
    };
232
    dateTime.addSelectionListener( selectionListener );
233
    String dateTimeId = WidgetUtil.getId( dateTime );
234
    Fixture.fakeRequestParam( JSConst.EVENT_WIDGET_SELECTED, dateTimeId );
235
    RWTFixture.readDataAndProcessAction( dateTime );
236
    assertEquals( "widgetSelected", log.toString() );
237
  }
238
239
  protected void setUp() throws Exception {
240
    RWTFixture.setUp();
241
  }
242
243
  protected void tearDown() throws Exception {
244
    RWTFixture.tearDown();
245
  }
246
}

Return to bug 183177