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/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 109-114 Link Here
109
    suite.addTestSuite( TabFolderLCA_Test.class );
110
    suite.addTestSuite( TabFolderLCA_Test.class );
110
    suite.addTestSuite( ScrolledCompositeLCA_Test.class );
111
    suite.addTestSuite( ScrolledCompositeLCA_Test.class );
111
    suite.addTestSuite( BrowserLCA_Test.class );
112
    suite.addTestSuite( BrowserLCA_Test.class );
113
    suite.addTestSuite( DateTimeLCA_Test.class );
112
114
113
    return suite;
115
    return suite;
114
  }
116
  }
(-)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
}
(-)src/org/eclipse/rwt/internal/theme/ThemeManager.java (-1 / +3 lines)
Lines 125-131 Link Here
125
    "tree/only_plus.gif",
125
    "tree/only_plus.gif",
126
    "tree/plus.gif",
126
    "tree/plus.gif",
127
    "tree/start_minus.gif",
127
    "tree/start_minus.gif",
128
    "tree/start_plus.gif",
128
    "tree/start_plus.gif",    
129
    "datechooser/lastMonth.gif",
130
    "datechooser/nextMonth.gif",    
129
  };
131
  };
130
132
131
  /** Where to load the default non-themeable images from */
133
  /** Where to load the default non-themeable images from */
(-)src/org/eclipse/swt/SWT.java (+76 lines)
Lines 1562-1567 Link Here
1562
   * contains a transparent pixel (value is 1<<2).
1562
   * contains a transparent pixel (value is 1<<2).
1563
   */
1563
   */
1564
  public static final int TRANSPARENCY_PIXEL = 1 << 2;
1564
  public static final int TRANSPARENCY_PIXEL = 1 << 2;
1565
  
1566
  /**
1567
   * Style constant for date display (value is 1&lt;&lt;5).
1568
   * <p><b>Used By:</b><ul>
1569
   * <li><code>DateTime</code></li>
1570
   * </ul></p>
1571
   * 
1572
   * @since 3.3
1573
   */
1574
  public static final int DATE = 1 << 5;
1575
1576
  /**
1577
   * Style constant for time display (value is 1&lt;&lt;7).
1578
   * <p><b>Used By:</b><ul>
1579
   * <li><code>DateTime</code></li>
1580
   * </ul></p>
1581
   * 
1582
   * @since 3.3
1583
   */
1584
  public static final int TIME = 1 << 7;
1585
  
1586
  /**
1587
   * Style constant for calendar display (value is 1&lt;&lt;10).
1588
   * <p><b>Used By:</b><ul>
1589
   * <li><code>DateTime</code></li>
1590
   * </ul></p>
1591
   * 
1592
   * @since 3.3
1593
   */
1594
  public static final int CALENDAR = 1 << 10;
1595
1596
  /**
1597
   * Style constant for short date/time format (value is 1&lt;&lt;15).
1598
   * <p>
1599
   * A short date displays the month and year.
1600
   * A short time displays hours and minutes.
1601
   * <br>Note that this is a <em>HINT</em>.
1602
   * </p>
1603
   * <p><b>Used By:</b><ul>
1604
   * <li><code>DateTime</code></li>
1605
   * </ul></p>
1606
   * 
1607
   * @since 3.3
1608
   */
1609
  public static final int SHORT = 1 << 15;
1610
1611
  /**
1612
   * Style constant for medium date/time format (value is 1&lt;&lt;16).
1613
   * <p>
1614
   * A medium date displays the day, month and year.
1615
   * A medium time displays hours, minutes, and seconds.
1616
   * <br>Note that this is a <em>HINT</em>.
1617
   * </p>
1618
   * <p><b>Used By:</b><ul>
1619
   * <li><code>DateTime</code></li>
1620
   * </ul></p>
1621
   * 
1622
   * @since 3.3
1623
   */
1624
  public static final int MEDIUM = 1 << 16;
1625
1626
  /**
1627
   * Style constant for long date/time format (value is 1&lt;&lt;28).
1628
   * <p>
1629
   * A long date displays the day, month and year.
1630
   * A long time displays hours, minutes, and seconds.
1631
   * The day and month names may be displayed.
1632
   * <br>Note that this is a <em>HINT</em>.
1633
   * </p>
1634
   * <p><b>Used By:</b><ul>
1635
   * <li><code>DateTime</code></li>
1636
   * </ul></p>
1637
   * 
1638
   * @since 3.3
1639
   */
1640
  public static final int LONG = 1 << 28;
1565
1641
1566
  /**
1642
  /**
1567
   * Throws an appropriate exception based on the passed in error code.
1643
   * Throws an appropriate exception based on the passed in error code.
(-)src/org/eclipse/swt/widgets/DateTime.java (+893 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
      width = 168;
546
      height = 140;  
547
    } else if( ( style & SWT.DATE ) != 0 ) {
548
      Point prefSize = new Point( 0, 0 );
549
      if( DATE_PATTERN.equals( "MDY" ) ) {
550
        prefSize = computeMDYBounds( font );        
551
      } else if( DATE_PATTERN.equals( "DMY" ) ) {
552
        prefSize = computeDMYBounds( font );
553
      } else {
554
        if( ( style & SWT.MEDIUM ) != 0 ) {
555
          prefSize = computeYMDBounds( font );
556
        } else {
557
          prefSize = computeMDYBounds( font ); 
558
        }
559
      }
560
      // Overall widget size
561
      width = prefSize.x;
562
      height = prefSize.y;
563
    } else if( ( style & SWT.TIME ) != 0 ) {
564
      // Hours text field
565
      hoursTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
566
      hoursTextFieldBounds.width 
567
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
568
      hoursTextFieldBounds.height 
569
        = TextSizeDetermination.stringExtent( font, "88" ).y + V_PADDING;
570
      // Hours minutes separator
571
      separator3Bounds = new Rectangle( 0, 0, 0, 0 );
572
      separator3Bounds.x = hoursTextFieldBounds.x + hoursTextFieldBounds.width;
573
      separator3Bounds.width 
574
        = TextSizeDetermination.stringExtent( font, ":" ).x;
575
      separator3Bounds.height = hoursTextFieldBounds.height;
576
      // Minutes text field
577
      minutesTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
578
      minutesTextFieldBounds.x = separator3Bounds.x + separator3Bounds.width;
579
      minutesTextFieldBounds.width = hoursTextFieldBounds.width;
580
      minutesTextFieldBounds.height = hoursTextFieldBounds.height;
581
      // Minutes seconds separator
582
      separator4Bounds = new Rectangle( 0, 0, 0, 0 );
583
      separator4Bounds.x = minutesTextFieldBounds.x 
584
                         + minutesTextFieldBounds.width;
585
      separator4Bounds.width = separator3Bounds.width;
586
      separator4Bounds.height = hoursTextFieldBounds.height;
587
      // Seconds text field
588
      secondsTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
589
      secondsTextFieldBounds.x = separator4Bounds.x + separator4Bounds.width;
590
      secondsTextFieldBounds.width = hoursTextFieldBounds.width;
591
      secondsTextFieldBounds.height = hoursTextFieldBounds.height;
592
      // The spinner bounds
593
      spinnerBounds = new Rectangle( 0, 0, 0, 0 );
594
      spinnerBounds.x = minutesTextFieldBounds.x 
595
                      + minutesTextFieldBounds.width;
596
      if( ( style & SWT.MEDIUM ) != 0 || ( style & SWT.LONG) != 0 ) {
597
        spinnerBounds.x = secondsTextFieldBounds.x 
598
                        + secondsTextFieldBounds.width;
599
      }
600
      spinnerBounds.width = 17;
601
      spinnerBounds.height = hoursTextFieldBounds.height;
602
      // Overall widget size     
603
      width = spinnerBounds.x + spinnerBounds.width;
604
      height = hoursTextFieldBounds.height;        
605
    }
606
    return new Point( width, height );
607
  }
608
  
609
  private Point computeMDYBounds( final Font font ) {
610
    // The weekday text field bounds
611
    weekdayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
612
    if( ( style & SWT.LONG ) != 0 ) {
613
      weekdayTextFieldBounds.width
614
        = getMaxStringLength( font, WEEKDAY_NAMES ) + H_PADDING + 2;
615
    }  
616
    weekdayTextFieldBounds.height
617
      = TextSizeDetermination.stringExtent( font, WEEKDAY_NAMES[1] ).y
618
        + V_PADDING;
619
    // The weekday month separator bounds
620
    separator0Bounds = new Rectangle( 0, 0, 0, 0 );
621
    separator0Bounds.x 
622
      = weekdayTextFieldBounds.x + weekdayTextFieldBounds.width;
623
    if( ( style & SWT.LONG ) != 0 ) {
624
      separator0Bounds.width 
625
        = TextSizeDetermination.stringExtent( font, "," ).x;
626
    }
627
    separator0Bounds.height = weekdayTextFieldBounds.height;      
628
    // The month text field bounds
629
    monthTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
630
    monthTextFieldBounds.x = separator0Bounds.x + separator0Bounds.width;
631
    if( ( style & SWT.MEDIUM ) != 0 ) {
632
      monthTextFieldBounds.width 
633
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
634
    } else {        
635
      monthTextFieldBounds.width 
636
        = getMaxStringLength( font, MONTH_NAMES ) + H_PADDING + 2;
637
    }
638
    monthTextFieldBounds.height = weekdayTextFieldBounds.height;
639
    // The month date separator bounds
640
    separator1Bounds = new Rectangle( 0, 0, 0, 0 );
641
    separator1Bounds.x = monthTextFieldBounds.x + monthTextFieldBounds.width;
642
    if( ( style & SWT.MEDIUM ) != 0 ) {
643
      separator1Bounds.width 
644
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
645
    }
646
    separator1Bounds.height = weekdayTextFieldBounds.height;
647
    // The date text field bounds
648
    dayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
649
    dayTextFieldBounds.x = separator1Bounds.x + separator1Bounds.width;
650
    if( ( style & SWT.SHORT ) == 0 ) {
651
      dayTextFieldBounds.width 
652
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
653
    }
654
    dayTextFieldBounds.height = weekdayTextFieldBounds.height;
655
    // The date year separator bounds
656
    separator2Bounds = new Rectangle( 0, 0, 0, 0 );
657
    separator2Bounds.x = dayTextFieldBounds.x + dayTextFieldBounds.width;
658
    if( ( style & SWT.MEDIUM ) != 0 ) {
659
      separator2Bounds.width 
660
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
661
    } else {
662
      separator2Bounds.width 
663
        = TextSizeDetermination.stringExtent( font, "," ).x;
664
    }
665
    separator2Bounds.height = weekdayTextFieldBounds.height;            
666
    // The year text field bounds
667
    yearTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
668
    yearTextFieldBounds.x = separator2Bounds.x + separator2Bounds.width;
669
    yearTextFieldBounds.width 
670
      = TextSizeDetermination.stringExtent( font, "8888" ).x + H_PADDING;
671
    yearTextFieldBounds.height = weekdayTextFieldBounds.height;
672
    // The spinner bounds
673
    spinnerBounds = new Rectangle( 0, 0, 0, 0 );
674
    spinnerBounds.x = yearTextFieldBounds.x + yearTextFieldBounds.width;
675
    spinnerBounds.width = 17;
676
    spinnerBounds.height = weekdayTextFieldBounds.height;
677
    // Overall widget size
678
    int width = spinnerBounds.x + spinnerBounds.width;
679
    int height = weekdayTextFieldBounds.height;
680
    return new Point( width, height );
681
  }
682
  
683
  private Point computeDMYBounds( final Font font ) {
684
    // The weekday text field bounds
685
    weekdayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
686
    if( ( style & SWT.LONG ) != 0 ) {
687
      weekdayTextFieldBounds.width
688
        = getMaxStringLength( font, WEEKDAY_NAMES ) + H_PADDING + 2;
689
    }  
690
    weekdayTextFieldBounds.height
691
      = TextSizeDetermination.stringExtent( font, WEEKDAY_NAMES[1] ).y 
692
        + V_PADDING;
693
    // The weekday day separator bounds
694
    separator0Bounds = new Rectangle( 0, 0, 0, 0 );
695
    separator0Bounds.x 
696
      = weekdayTextFieldBounds.x + weekdayTextFieldBounds.width;
697
    if( ( style & SWT.LONG ) != 0 ) {
698
      separator0Bounds.width 
699
        = TextSizeDetermination.stringExtent( font, "," ).x;
700
    }
701
    separator0Bounds.height = weekdayTextFieldBounds.height;      
702
    // The day text field bounds
703
    dayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
704
    dayTextFieldBounds.x = separator0Bounds.x + separator0Bounds.width;
705
    if( ( style & SWT.SHORT ) == 0 ) {
706
      dayTextFieldBounds.width 
707
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
708
    }
709
    dayTextFieldBounds.height = weekdayTextFieldBounds.height;
710
    // The day month separator bounds
711
    separator1Bounds = new Rectangle( 0, 0, 0, 0 );
712
    separator1Bounds.x = dayTextFieldBounds.x + dayTextFieldBounds.width;
713
    if( ( style & SWT.MEDIUM ) != 0 ) {
714
      separator1Bounds.width 
715
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
716
    }
717
    separator1Bounds.height = weekdayTextFieldBounds.height;
718
    // The month text field bounds
719
    monthTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
720
    monthTextFieldBounds.x = separator1Bounds.x + separator1Bounds.width;
721
    if( ( style & SWT.MEDIUM ) != 0 ) {
722
      monthTextFieldBounds.width 
723
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
724
    } else {        
725
      monthTextFieldBounds.width 
726
        = getMaxStringLength( font, MONTH_NAMES ) + H_PADDING + 2;
727
    }
728
    monthTextFieldBounds.height = weekdayTextFieldBounds.height;
729
    // The month year separator bounds
730
    separator2Bounds = new Rectangle( 0, 0, 0, 0 );
731
    separator2Bounds.x = monthTextFieldBounds.x + monthTextFieldBounds.width;
732
    if( ( style & SWT.MEDIUM ) != 0 ) {
733
      separator2Bounds.width 
734
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
735
    } else {
736
      separator2Bounds.width 
737
        = TextSizeDetermination.stringExtent( font, "," ).x;
738
    }
739
    separator2Bounds.height = weekdayTextFieldBounds.height;            
740
    // The year text field bounds
741
    yearTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
742
    yearTextFieldBounds.x = separator2Bounds.x + separator2Bounds.width;
743
    yearTextFieldBounds.width 
744
      = TextSizeDetermination.stringExtent( font, "8888" ).x + H_PADDING;
745
    yearTextFieldBounds.height = weekdayTextFieldBounds.height;
746
    // The spinner bounds
747
    spinnerBounds = new Rectangle( 0, 0, 0, 0 );
748
    spinnerBounds.x = yearTextFieldBounds.x + yearTextFieldBounds.width;
749
    spinnerBounds.width = 17;
750
    spinnerBounds.height = weekdayTextFieldBounds.height;
751
    // Overall widget size
752
    int width = spinnerBounds.x + spinnerBounds.width;
753
    int height = weekdayTextFieldBounds.height;
754
    return new Point( width, height );
755
  }
756
757
  private Point computeYMDBounds( final Font font ) {
758
    // The weekday text field bounds
759
    weekdayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
760
    if( ( style & SWT.LONG ) != 0 ) {
761
      weekdayTextFieldBounds.width
762
        = getMaxStringLength( font, WEEKDAY_NAMES ) + H_PADDING + 2;
763
    }  
764
    weekdayTextFieldBounds.height
765
      = TextSizeDetermination.stringExtent( font, WEEKDAY_NAMES[1] ).y 
766
        + V_PADDING;
767
    // The weekday day separator bounds
768
    separator0Bounds = new Rectangle( 0, 0, 0, 0 );
769
    separator0Bounds.x 
770
      = weekdayTextFieldBounds.x + weekdayTextFieldBounds.width;
771
    if( ( style & SWT.LONG ) != 0 ) {
772
      separator0Bounds.width 
773
        = TextSizeDetermination.stringExtent( font, "," ).x;
774
    }
775
    separator0Bounds.height = weekdayTextFieldBounds.height;
776
    // The year text field bounds
777
    yearTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
778
    yearTextFieldBounds.x = separator0Bounds.x + separator0Bounds.width;
779
    yearTextFieldBounds.width 
780
      = TextSizeDetermination.stringExtent( font, "8888" ).x + H_PADDING;
781
    yearTextFieldBounds.height = weekdayTextFieldBounds.height;
782
    // The year month separator bounds
783
    separator1Bounds = new Rectangle( 0, 0, 0, 0 );
784
    separator1Bounds.x = yearTextFieldBounds.x + yearTextFieldBounds.width;
785
    if( ( style & SWT.MEDIUM ) != 0 ) {
786
      separator1Bounds.width 
787
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
788
    }
789
    // The month text field bounds
790
    monthTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
791
    monthTextFieldBounds.x = separator1Bounds.x + separator1Bounds.width;
792
    if( ( style & SWT.MEDIUM ) != 0 ) {
793
      monthTextFieldBounds.width 
794
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
795
    } else {        
796
      monthTextFieldBounds.width 
797
        = getMaxStringLength( font, MONTH_NAMES ) + H_PADDING + 2;
798
    }
799
    monthTextFieldBounds.height = weekdayTextFieldBounds.height;
800
    // The month day separator bounds
801
    separator2Bounds = new Rectangle( 0, 0, 0, 0 );
802
    separator2Bounds.x = monthTextFieldBounds.x + monthTextFieldBounds.width;
803
    if( ( style & SWT.MEDIUM ) != 0 ) {
804
      separator2Bounds.width 
805
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
806
    } else {
807
      separator2Bounds.width 
808
        = TextSizeDetermination.stringExtent( font, "," ).x;
809
    }
810
    separator2Bounds.height = weekdayTextFieldBounds.height;     
811
    // The day text field bounds
812
    dayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
813
    dayTextFieldBounds.x = separator2Bounds.x + separator2Bounds.width;
814
    if( ( style & SWT.SHORT ) == 0 ) {
815
      dayTextFieldBounds.width 
816
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
817
    }
818
    dayTextFieldBounds.height = weekdayTextFieldBounds.height;
819
    
820
    separator1Bounds.height = weekdayTextFieldBounds.height;    
821
    // The spinner bounds
822
    spinnerBounds = new Rectangle( 0, 0, 0, 0 );
823
    spinnerBounds.x = dayTextFieldBounds.x + dayTextFieldBounds.width;
824
    spinnerBounds.width = 17;
825
    spinnerBounds.height = weekdayTextFieldBounds.height;
826
    // Overall widget size
827
    int width = spinnerBounds.x + spinnerBounds.width;
828
    int height = weekdayTextFieldBounds.height;
829
    return new Point( width, height );
830
  }
831
  
832
  private int getDaysInMonth( final int month, final int year ) {
833
    GregorianCalendar cal = new GregorianCalendar( year, month, 1 );
834
    return cal.getActualMaximum( Calendar.DAY_OF_MONTH );
835
  }
836
  
837
  private int getMaxStringLength( final Font font, final String[] strings ) {
838
    int maxLength = 0;
839
    for( int i = 0; i < strings.length; i++ ) {
840
      int currentStringWidth
841
        = TextSizeDetermination.stringExtent( font, strings[i] ).x;
842
      maxLength = Math.max( maxLength, currentStringWidth );
843
    }
844
    return maxLength;
845
  }
846
  
847
  private String getDateSeparator() {
848
    DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT );    
849
    String datePattern = ( ( SimpleDateFormat )df ).toPattern();
850
    String result = "";
851
    int index = 0;
852
    while( Character.isLetter( datePattern.charAt( index ) ) ) {
853
      index++;
854
    }
855
    result = Character.toString( datePattern.charAt( index ) );
856
    return result;
857
  }
858
  
859
  private String getDatePattern( final String dateSeparator ) {
860
    DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT );    
861
    String datePattern = ( ( SimpleDateFormat )df ).toPattern();
862
    String result = "";
863
    StringTokenizer st = new StringTokenizer( datePattern, 
864
                                              dateSeparator );
865
    while ( st.hasMoreTokens() ) {
866
      String token = st.nextToken();
867
      result += Character.toString( token.charAt( 0 ) );
868
    }
869
    return result.toUpperCase();
870
  }
871
  
872
  String getNameText() {
873
    return "DateTime";
874
  } 
875
  
876
  static int checkStyle( final int value ) {
877
    /*
878
     * Even though it is legal to create this widget with scroll bars, they
879
     * serve no useful purpose because they do not automatically scroll the
880
     * widget's client area. The fix is to clear the SWT style.
881
     */
882
    int style = value;
883
    style &= ~( SWT.H_SCROLL | SWT.V_SCROLL );
884
    style = checkBits( style, SWT.DATE, SWT.TIME, SWT.CALENDAR, 0, 0, 0 );
885
    return checkBits( style, SWT.MEDIUM, SWT.SHORT, SWT.LONG, 0, 0, 0 );
886
  }
887
888
  protected void checkSubclass() {
889
    if( !isValidSubclass() ) {
890
      error( SWT.ERROR_INVALID_SUBCLASS );
891
    }  
892
  }
893
}
(-)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 / +2 lines)
Lines 52-57 Link Here
52
    ensureMinTabHeight( topFolder );
52
    ensureMinTabHeight( topFolder );
53
53
54
    final ExampleTab[] tabs = new ExampleTab[] {
54
    final ExampleTab[] tabs = new ExampleTab[] {
55
      new DateTimeTab( topFolder ),
55
      new ButtonTab( topFolder ),
56
      new ButtonTab( topFolder ),
56
//      new RequestTab( topFolder ),
57
//      new RequestTab( topFolder ),
57
      new CBannerTab( topFolder ),
58
      new CBannerTab( topFolder ),
Lines 59-65 Link Here
59
      new ComboTab( topFolder ),
60
      new ComboTab( topFolder ),
60
      new CompositeTab( topFolder ),
61
      new CompositeTab( topFolder ),
61
      new CoolBarTab( topFolder ),
62
      new CoolBarTab( topFolder ),
62
      new DialogsTab( topFolder ),
63
      new DialogsTab( 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/swt/internal/widgets/displaykit/QooxdooResourcesUtil.java (-5 / +17 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";  
126
  private static final String QX_DATE_CHOOSER_JS
127
    = "qx/ui/component/DateChooser.js";
120
128
121
  private QooxdooResourcesUtil() {
129
  private QooxdooResourcesUtil() {
122
    // prevent intance creation
130
    // prevent intance creation
Lines 183-189 Link Here
183
      register( BROWSER_JS );
191
      register( BROWSER_JS );
184
      register( PROGRESS_BAR_JS );
192
      register( PROGRESS_BAR_JS );
185
      register( FONT_SIZE_CALCULATION_JS );
193
      register( FONT_SIZE_CALCULATION_JS );
186
      register( CLABEL_UTIL_JS );
194
      register( CLABEL_UTIL_JS );      
195
      register( DATE_TIME_DATE_JS );
196
      register( DATE_TIME_TIME_JS );
197
      register( DATE_TIME_CALENDAR_JS );     
198
      register( QX_DATE_CHOOSER_JS );
187
199
188
      // register contributions
200
      // register contributions
189
      registerContributions();
201
      registerContributions();
(-)js/org/eclipse/swt/theme/AppearancesBase.js (-2 / +102 lines)
Lines 13-19 Link Here
13
qx.Theme.define( "org.eclipse.swt.theme.AppearancesBase",
13
qx.Theme.define( "org.eclipse.swt.theme.AppearancesBase",
14
{
14
{
15
  title : "Appearances Base Theme",
15
  title : "Appearances Base Theme",
16
16
  
17
  appearances : {
17
  appearances : {
18
18
19
  "empty" : {
19
  "empty" : {
Lines 1746-1752 Link Here
1746
        opacity : 0.2
1746
        opacity : 0.2
1747
      };
1747
      };
1748
    }
1748
    }
1749
  }
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
    }
1760
  },
1761
  
1762
  "datetime-calendar" : {
1763
    style : function( states ) {
1764
      return {
1765
        border : states.rwt_BORDER ? "control.BORDER.border" : "control.border"
1766
      }
1767
    }
1768
  },
1769
  
1770
  // ------------------------------------------------------------------------
1771
  // DateChooser
1772
  
1773
  "datechooser-navBar" : {
1774
    style : function(states) {      
1775
      return {
1776
      	backgroundColor : "#0A246A",
1777
      	padding : [ 4, 4, 4, 4 ]
1778
      };
1779
    }
1780
  },
1781
      
1782
  "datechooser-toolbar-button" : {
1783
    style : function(states) {
1784
      var result =
1785
      {
1786
        spacing : 4,
1787
        width : "auto",
1788
        verticalChildrenAlign : "middle"
1789
      };
1790
1791
      if (states.pressed || states.checked || states.abandoned) {
1792
        result.padding = [ 2, 0, 0, 2 ];
1793
      } else {
1794
        result.padding = 2;
1795
      }
1796
1797
      return result;
1798
    }
1799
  },
1800
1801
  "datechooser-monthyear" : {
1802
    style : function(states) {
1803
      var boldFont = qx.ui.core.Font.fromString( "11 bold Tahoma, 'Lucida Sans Unicode', sans-serif" );
1804
      
1805
      return {
1806
        font          : boldFont,
1807
        textAlign     : "center",
1808
        textColor     : "white",
1809
        verticalAlign : "middle"
1810
      };
1811
    }
1812
  },
1813
1814
  "datechooser-datepane" : {
1815
    style : function(states) {
1816
      return {
1817
        backgroundColor : "white"
1818
      };
1819
    }
1820
  },
1821
1822
  "datechooser-weekday" : {
1823
    style : function(states) {
1824
      var border = qx.ui.core.Border.fromConfig({
1825
        bottom : [ 1, "solid", "gray" ]
1826
      });
1827
      
1828
      return {
1829
        border          : border,        
1830
        textAlign       : "center",
1831
        textColor       : "#0A246A",
1832
        backgroundColor : "white"
1833
      };
1834
    }
1835
  },
1836
1837
  "datechooser-day" : {
1838
    style : function(states) {
1839
    	var border = new qx.ui.core.Border( 1, "solid", "red" );
1840
      
1841
      return {
1842
        textAlign       : "center",
1843
        verticalAlign   : "middle",
1844
        border          : states.today ? border : "undefined",
1845
        textColor       : states.selected ? "white" : states.otherMonth ? "#808080" : "undefined",
1846
        backgroundColor : states.selected ? "#0A246A" : "undefined"
1847
      };
1848
    }
1849
  }  
1750
}
1850
}
1751
1851
1752
} );
1852
} );
(-)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/qx/ui/component/DateChooser.js (+774 lines)
Added Link Here
1
/* ************************************************************************
2
3
   qooxdoo - the new era of web development
4
5
   http://qooxdoo.org
6
7
   Copyright:
8
     2006 STZ-IDA, Germany, http://www.stz-ida.de
9
10
   License:
11
     LGPL: http://www.gnu.org/licenses/lgpl.html
12
     EPL: http://www.eclipse.org/org/documents/epl-v10.php
13
     See the LICENSE file in the project's top-level directory for details.
14
15
   Authors:
16
     * Til Schneider (til132)
17
18
************************************************************************ */
19
20
/* ************************************************************************
21
22
#embed(qx.widgettheme/datechooser/*)
23
24
************************************************************************ */
25
26
/**
27
 * Shows a calendar and allows choosing a date.
28
 *
29
 * @appearance datechooser-toolbar-button {qx.ui.toolbar.Button}
30
 * @appearance datechooser-navBar {qx.ui.layout.BoxLayout}
31
 * @appearance datechooser-monthyear {qx.ui.basic.Label}
32
 * @appearance datechooser-weekday {qx.ui.basic.Label}
33
 * @appearance datechooser-datepane {qx.ui.layout.CanvasLayout}
34
 * @appearance datechooser-weekday {qx.ui.basic.Label}
35
 *
36
 * @appearance datechooser-day {qx.ui.basic.Label}
37
 * @state weekend {datechooser-day}
38
 * @state otherMonth {datechooser-day}
39
 * @state today {datechooser-day}
40
 * @state selected {datechooser-day}
41
 */
42
qx.Class.define("qx.ui.component.DateChooser", {
43
  extend : qx.ui.layout.BoxLayout,
44
45
  /*
46
  *****************************************************************************
47
     CONSTRUCTOR
48
  *****************************************************************************
49
  */
50
51
  /**
52
   * @param date {Date ? null} The initial date to show. If <code>null</code>
53
   *        the current day (today) is shown.
54
   */
55
  construct : function(date) {
56
    this.base(arguments);
57
58
    this.setOrientation("vertical");
59
60
    // Create the navigation bar
61
    var navBar = new qx.ui.layout.BoxLayout;
62
    navBar.setAppearance("datechooser-navBar");
63
64
    navBar.set({
65
      height  : "auto",
66
      spacing : 1
67
    });
68
69
    var lastMonthBt = new qx.ui.toolbar.Button(null, "widget/datechooser/lastMonth.gif");
70
    var monthYearLabel = new qx.ui.basic.Label;
71
    var nextMonthBt = new qx.ui.toolbar.Button(null, "widget/datechooser/nextMonth.gif");
72
73
    lastMonthBt.set({
74
      show    : 'icon',
75
      toolTip : new qx.ui.popup.ToolTip(this.tr("Last month"))
76
    });
77
78
    nextMonthBt.set({
79
      show    : 'icon',
80
      toolTip : new qx.ui.popup.ToolTip(this.tr("Next month"))
81
    });
82
83
    lastMonthBt.setAppearance("datechooser-toolbar-button");
84
    nextMonthBt.setAppearance("datechooser-toolbar-button");
85
86
    lastMonthBt.addEventListener("click", this._onNavButtonClicked, this);
87
    nextMonthBt.addEventListener("click", this._onNavButtonClicked, this);
88
89
    this._lastMonthBt = lastMonthBt;
90
    this._nextMonthBt = nextMonthBt;
91
92
    monthYearLabel.setAppearance("datechooser-monthyear");
93
    monthYearLabel.set({ width : "1*" });
94
95
    navBar.add(lastMonthBt, monthYearLabel, nextMonthBt);
96
    this._monthYearLabel = monthYearLabel;
97
    navBar.setHtmlProperty("id", "navBar");
98
99
    // Create the date pane
100
    var datePane = new qx.ui.layout.CanvasLayout;
101
    datePane.setAppearance("datechooser-datepane");
102
103
    datePane.set({
104
      width  : qx.ui.component.DateChooser.CELL_WIDTH * 7,
105
      height : qx.ui.component.DateChooser.CELL_HEIGHT * 7
106
    });
107
108
    this._weekdayLabelArr = [];
109
110
    for (var i=0; i<7; i++) {
111
      var label = new qx.ui.basic.Label;
112
      label.setAppearance("datechooser-weekday");
113
      label.setSelectable(false);
114
      label.setCursor("default");
115
116
      label.set({
117
        width  : qx.ui.component.DateChooser.CELL_WIDTH,
118
        height : qx.ui.component.DateChooser.CELL_HEIGHT,
119
        left   : i * qx.ui.component.DateChooser.CELL_WIDTH
120
      });
121
122
      datePane.add(label);
123
      this._weekdayLabelArr.push(label);
124
    }
125
126
    // Add the days
127
    this._dayLabelArr = [];
128
129
    for (var y=0; y<6; y++) {
130
      // Add the day labels
131
      for (var x=0; x<7; x++) {
132
        var label = new qx.ui.basic.Label;
133
        label.setAppearance("datechooser-day");
134
        label.setSelectable(false);
135
        label.setCursor("default");
136
137
        label.set({
138
          width  : qx.ui.component.DateChooser.CELL_WIDTH,
139
          height : qx.ui.component.DateChooser.CELL_HEIGHT,
140
          left   : x * qx.ui.component.DateChooser.CELL_WIDTH,
141
          top    : (y + 1) * qx.ui.component.DateChooser.CELL_HEIGHT
142
        });
143
144
        label.addEventListener("mousedown", this._onDayClicked, this);
145
        label.addEventListener("dblclick", this._onDayDblClicked, this);
146
        datePane.add(label);
147
        this._dayLabelArr.push(label);
148
      }
149
    }
150
151
    // Make focusable
152
    this.setTabIndex(1);
153
    this.addEventListener("keypress", this._onkeypress);
154
155
    // Show the right date
156
    var shownDate = (date != null) ? date : new Date();
157
    this.showMonth(shownDate.getMonth(), shownDate.getFullYear());
158
159
    // listen for locale changes
160
    qx.locale.Manager.getInstance().addEventListener("changeLocale", this._updateDatePane, this);
161
162
    // Add the main widgets
163
    this.add(navBar);
164
    this.add(datePane);
165
166
    // Initialize dimensions
167
    this.initWidth();
168
    this.initHeight();
169
  },
170
171
  /*
172
  *****************************************************************************
173
     EVENTS
174
  *****************************************************************************
175
  */
176
177
  events: {
178
    /** Fired when a date was selected. The event holds the new selected date in its data property.*/
179
    "select"     : "qx.event.type.DataEvent"
180
  },
181
182
  /*
183
  *****************************************************************************
184
     STATICS
185
  *****************************************************************************
186
  */
187
188
  statics : {
189
  	CELL_WIDTH : 24,
190
  	CELL_HEIGHT : 16,
191
    MONTH_NAMES : [],
192
    WEEKDAY_NAMES : []
193
  },
194
195
  /*
196
  *****************************************************************************
197
     PROPERTIES
198
  *****************************************************************************
199
  */
200
201
  properties : {
202
    width : {
203
      refine : true,
204
      init : "auto"
205
    },
206
207
    height : {
208
      refine : true,
209
      init : "auto"
210
    },
211
212
    /** The currently shown month. 0 = january, 1 = february, and so on. */
213
    shownMonth : {
214
      check : "Integer",
215
      init : null,
216
      nullable : true,
217
      event : "changeShownMonth"
218
    },
219
220
    /** The currently shown year. */
221
    shownYear : {
222
      check : "Integer",
223
      init : null,
224
      nullable : true,
225
      event : "changeShownYear"
226
    },
227
228
    /** {Date} The currently selected date. */
229
    date : {
230
      check : "Date",
231
      init : null,
232
      nullable : true,
233
      apply : "_applyDate",
234
      event : "changeDate",
235
      transform : "_checkDate"
236
    }
237
  },
238
239
  /*
240
  *****************************************************************************
241
     MEMBERS
242
  *****************************************************************************
243
  */
244
245
  members : {
246
    // property checker
247
    /**
248
     * TODOC
249
     *
250
     * @type member
251
     * @param value {var} Current value
252
     * @return {var} TODOC
253
     */
254
    _checkDate : function(value) {
255
      // Use a clone of the date internally since date instances may be changed
256
      return (value == null) ? null : new Date(value.getTime());
257
    },
258
259
    // property modifier
260
    /**
261
     * TODOC
262
     *
263
     * @type member
264
     * @param value {var} Current value
265
     * @param old {var} Previous value
266
     */
267
    _applyDate : function(value, old) {
268
      if ((value != null) && (this.getShownMonth() != value.getMonth() || this.getShownYear() != value.getFullYear())) {
269
        // The new date is in another month -> Show that month
270
        this.showMonth(value.getMonth(), value.getFullYear());
271
      } else {
272
        // The new date is in the current month -> Just change the states
273
        var newDay = (value == null) ? -1 : value.getDate();
274
275
        for (var i=0; i<6*7; i++) {
276
          var dayLabel = this._dayLabelArr[i];
277
278
          if (dayLabel.hasState("otherMonth")) {
279
            if (dayLabel.hasState("selected")) {
280
              dayLabel.removeState("selected");
281
            }
282
          } else {
283
            var day = parseInt(dayLabel.getText());
284
285
            if (day == newDay) {
286
              dayLabel.addState("selected");
287
            } else if (dayLabel.hasState("selected")) {
288
              dayLabel.removeState("selected");
289
            }
290
          }
291
        }
292
      }
293
    },
294
295
    /**
296
     * Event handler. Called when a navigation button has been clicked.
297
     *
298
     * @type member
299
     * @param evt {Map} the event.
300
     * @return {void}
301
     */
302
    _onNavButtonClicked : function(evt) {
303
      var year = this.getShownYear();
304
      var month = this.getShownMonth();
305
306
      switch(evt.getCurrentTarget()) {
307
        case this._lastMonthBt:
308
          month--;
309
310
          if (month < 0) {
311
            month = 11;
312
            year--;
313
          }
314
315
          break;
316
317
        case this._nextMonthBt:
318
          month++;
319
320
          if (month >= 12) {
321
            month = 0;
322
            year++;
323
          }
324
325
          break;
326
      }
327
328
      this.showMonth(month, year);
329
    },
330
331
    /**
332
     * Event handler. Called when a day has been clicked.
333
     *
334
     * @type member
335
     * @param evt {Map} the event.
336
     * @return {void}
337
     */
338
    _onDayClicked : function(evt) {
339
      var time = evt.getCurrentTarget().dateTime;
340
      this.setDate(new Date(time));
341
    },
342
343
    /**
344
     * TODOC
345
     *
346
     * @type member
347
     * @return {void}
348
     */
349
    _onDayDblClicked : function() {
350
      this.createDispatchDataEvent("select", this.getDate());
351
    },
352
353
    /**
354
     * Event handler. Called when a key was pressed.
355
     *
356
     * @type member
357
     * @param evt {Map} the event.
358
     * @return {boolean | void} TODOC
359
     */
360
    _onkeypress : function(evt) {
361
      var dayIncrement = null;
362
      var monthIncrement = null;
363
      var yearIncrement = null;
364
365
      if (evt.getModifiers() == 0) {
366
        switch(evt.getKeyIdentifier()) {
367
          case "Left":
368
            dayIncrement = -1;
369
            break;
370
371
          case "Right":
372
            dayIncrement = 1;
373
            break;
374
375
          case "Up":
376
            dayIncrement = -7;
377
            break;
378
379
          case "Down":
380
            dayIncrement = 7;
381
            break;
382
383
          case "PageUp":
384
            monthIncrement = -1;
385
            break;
386
387
          case "PageDown":
388
            monthIncrement = 1;
389
            break;
390
391
          case "Escape":
392
            if (this.getDate() != null) {
393
              this.setDate(null);
394
              return true;
395
            }
396
397
            break;
398
399
          case "Enter":
400
          case "Space":
401
            if (this.getDate() != null) {
402
              this.createDispatchDataEvent("select", this.getDate());
403
            }
404
405
            return;
406
        }
407
      }
408
      else if (evt.isShiftPressed()) {
409
        switch(evt.getKeyIdentifier()) {
410
          case "PageUp":
411
            yearIncrement = -1;
412
            break;
413
414
          case "PageDown":
415
            yearIncrement = 1;
416
            break;
417
        }
418
      }
419
420
      if (dayIncrement != null || monthIncrement != null || yearIncrement != null) {
421
        var date = this.getDate();
422
423
        if (date != null) {
424
          date = new Date(date.getTime()); // TODO: Do cloning in getter
425
        }
426
427
        if (date == null) {
428
          date = new Date();
429
        } else {
430
          if (dayIncrement != null) date.setDate(date.getDate() + dayIncrement);
431
          if (monthIncrement != null) date.setMonth(date.getMonth() + monthIncrement);
432
          if (yearIncrement != null) date.setFullYear(date.getFullYear() + yearIncrement);
433
        }
434
435
        this.setDate(date);
436
      }
437
    },
438
439
    // ***** Methods *****
440
    /**
441
     * Shows a certain month.
442
     *
443
     * @type member
444
     * @param month {Integer ? null} the month to show (0 = january). If not set the month
445
     *      will remain the same.
446
     * @param year {Integer ? null} the year to show. If not set the year will remain the
447
     *      same.
448
     * @return {void}
449
     */
450
    showMonth : function(month, year) {
451
      if ((month != null && month != this.getShownMonth()) || (year != null && year != this.getShownYear())) {
452
        if (month != null) {
453
          this.setShownMonth(month);
454
        }
455
456
        if (year != null) {
457
          this.setShownYear(year);
458
        }
459
460
        this._updateDatePane();
461
      }
462
    },
463
464
    /**
465
     * Updates the date pane.
466
     *
467
     * @type member
468
     * @return {void}
469
     */
470
    _updateDatePane : function() {
471
      var today = new Date();
472
      var todayYear = today.getFullYear();
473
      var todayMonth = today.getMonth();
474
      var todayDayOfMonth = today.getDate();
475
476
      var selDate = this.getDate();
477
      var selYear = (selDate == null) ? -1 : selDate.getFullYear();
478
      var selMonth = (selDate == null) ? -1 : selDate.getMonth();
479
      var selDayOfMonth = (selDate == null) ? -1 : selDate.getDate();
480
481
      var shownMonth = this.getShownMonth();
482
      var shownYear = this.getShownYear();
483
484
      var startOfWeek = this.__getWeekStart();
485
486
      // Create a help date that points to the first of the current month
487
      var helpDate = new Date(this.getShownYear(), this.getShownMonth(), 1);
488
      
489
      var year = this.getShownYear();      
490
      var month = qx.ui.component.DateChooser.MONTH_NAMES[ this.getShownMonth() ];
491
      this._monthYearLabel.setText( month + ", " + year );
492
493
      // Show the day names
494
      var firstDayOfWeek = helpDate.getDay();
495
      var firstSundayInMonth = (1 + 7 - firstDayOfWeek) % 7;
496
      
497
      for (var i=0; i<7; i++) {
498
        var day = (i + startOfWeek) % 7;
499
500
        var dayLabel = this._weekdayLabelArr[i];
501
502
        helpDate.setDate(firstSundayInMonth + day);
503
        
504
        var weekdayName = qx.ui.component.DateChooser.WEEKDAY_NAMES[ helpDate.getDay() + 1 ];
505
        weekdayName = weekdayName.substring( 0, 3 );
506
        
507
        dayLabel.setText( weekdayName );
508
509
        if (this.__isWeekend(day)) {
510
          dayLabel.addState("weekend");
511
        } else {
512
          dayLabel.removeState("weekend");
513
        }
514
      }
515
516
      // Show the days
517
      helpDate = new Date(shownYear, shownMonth, 1);
518
      var nrDaysOfLastMonth = (7 + firstDayOfWeek - startOfWeek) % 7;
519
      helpDate.setDate(helpDate.getDate() - nrDaysOfLastMonth);
520
521
      for (var week=0; week<6; week++) {
522
        for (var i=0; i<7; i++) {
523
          var dayLabel = this._dayLabelArr[week * 7 + i];
524
525
          var year = helpDate.getFullYear();
526
          var month = helpDate.getMonth();
527
          var dayOfMonth = helpDate.getDate();
528
529
          var isSelectedDate = (selYear == year && selMonth == month && selDayOfMonth == dayOfMonth);
530
531
          if (isSelectedDate) {
532
            dayLabel.addState("selected");
533
          } else {
534
            dayLabel.removeState("selected");
535
          }
536
537
          if (month != shownMonth) {
538
            dayLabel.addState("otherMonth");
539
          } else {
540
            dayLabel.removeState("otherMonth");
541
          }
542
543
          var isToday = (year == todayYear && month == todayMonth && dayOfMonth == todayDayOfMonth);
544
545
          if (isToday) {
546
            dayLabel.addState("today");
547
          } else {
548
            dayLabel.removeState("today");
549
          }
550
551
          dayLabel.setText("" + dayOfMonth);
552
          dayLabel.dateTime = helpDate.getTime();
553
554
          // Go to the next day
555
          helpDate.setDate(helpDate.getDate() + 1);
556
        }
557
      }
558
    }, 
559
    
560
    /**
561
     * Return the day the week starts with
562
     *
563
     * Reference: Common Locale Data Repository (cldr) supplementalData.xml
564
     *
565
     * @type member
566
     * @param locale {String} optional locale to be used
567
     * @return {Integer} index of the first day of the week. 0=sunday, 1=monday, ...
568
     */
569
    __getWeekStart : function(locale) {
570
      var weekStart = {
571
        // default is monday
572
        "MV" : 5, // friday
573
        "AE" : 6, // saturday
574
        "AF" : 6,
575
        "BH" : 6,
576
        "DJ" : 6,
577
        "DZ" : 6,
578
        "EG" : 6,
579
        "ER" : 6,
580
        "ET" : 6,
581
        "IQ" : 6,
582
        "IR" : 6,
583
        "JO" : 6,
584
        "KE" : 6,
585
        "KW" : 6,
586
        "LB" : 6,
587
        "LY" : 6,
588
        "MA" : 6,
589
        "OM" : 6,
590
        "QA" : 6,
591
        "SA" : 6,
592
        "SD" : 6,
593
        "SO" : 6,
594
        "TN" : 6,
595
        "YE" : 6,
596
        "AS" : 0, // sunday
597
        "AU" : 0,
598
        "AZ" : 0,
599
        "BW" : 0,
600
        "CA" : 0,
601
        "CN" : 0,
602
        "FO" : 0,
603
        "GE" : 0,
604
        "GL" : 0,
605
        "GU" : 0,
606
        "HK" : 0,
607
        "IE" : 0,
608
        "IL" : 0,
609
        "IS" : 0,
610
        "JM" : 0,
611
        "JP" : 0,
612
        "KG" : 0,
613
        "KR" : 0,
614
        "LA" : 0,
615
        "MH" : 0,
616
        "MN" : 0,
617
        "MO" : 0,
618
        "MP" : 0,
619
        "MT" : 0,
620
        "NZ" : 0,
621
        "PH" : 0,
622
        "PK" : 0,
623
        "SG" : 0,
624
        "TH" : 0,
625
        "TT" : 0,
626
        "TW" : 0,
627
        "UM" : 0,
628
        "US" : 0,
629
        "UZ" : 0,
630
        "VI" : 0,
631
        "ZA" : 0,
632
        "ZW" : 0,
633
        "MW" : 0,
634
        "NG" : 0,
635
        "TJ" : 0
636
      };
637
638
      var territory = this.__getTerritory(locale);
639
640
      // default is monday
641
      return weekStart[territory] != null ? weekStart[territory] : 1;
642
    },
643
    
644
    /**
645
     * Return the day the weekend starts with
646
     *
647
     * Reference: Common Locale Data Repository (cldr) supplementalData.xml
648
     *
649
     * @type member
650
     * @param locale {String} optional locale to be used
651
     * @return {Integer} index of the first day of the weekend. 0=sunday, 1=monday, ...
652
     */
653
    __getWeekendStart : function(locale) {
654
      var weekendStart = {
655
        // default is saturday
656
        "EG" : 5, // friday
657
        "IL" : 5,
658
        "SY" : 5,
659
        "IN" : 0, // sunday
660
        "AE" : 4, // thursday
661
        "BH" : 4,
662
        "DZ" : 4,
663
        "IQ" : 4,
664
        "JO" : 4,
665
        "KW" : 4,
666
        "LB" : 4,
667
        "LY" : 4,
668
        "MA" : 4,
669
        "OM" : 4,
670
        "QA" : 4,
671
        "SA" : 4,
672
        "SD" : 4,
673
        "TN" : 4,
674
        "YE" : 4
675
      };
676
677
      var territory = this.__getTerritory(locale);
678
679
      // default is saturday
680
      return weekendStart[territory] != null ? weekendStart[territory] : 6;
681
    },
682
683
    /**
684
     * Return the day the weekend ends with
685
     *
686
     * Reference: Common Locale Data Repository (cldr) supplementalData.xml
687
     *
688
     * @type member
689
     * @param locale {String} optional locale to be used
690
     * @return {Integer} index of the last day of the weekend. 0=sunday, 1=monday, ...
691
     */
692
    __getWeekendEnd : function(locale) {
693
      var weekendEnd = {
694
        // default is sunday
695
        "AE" : 5, // friday
696
        "BH" : 5,
697
        "DZ" : 5,
698
        "IQ" : 5,
699
        "JO" : 5,
700
        "KW" : 5,
701
        "LB" : 5,
702
        "LY" : 5,
703
        "MA" : 5,
704
        "OM" : 5,
705
        "QA" : 5,
706
        "SA" : 5,
707
        "SD" : 5,
708
        "TN" : 5,
709
        "YE" : 5,
710
        "AF" : 5,
711
        "IR" : 5,
712
        "EG" : 6, // saturday
713
        "IL" : 6,
714
        "SY" : 6
715
      };
716
717
      var territory = this.__getTerritory(locale);
718
719
      // default is sunday
720
      return weekendEnd[territory] != null ? weekendEnd[territory] : 0;
721
    },
722
723
    /**
724
     * Returns whether a certain day of week belongs to the week end.
725
     *
726
     * @type member
727
     * @param day {Integer} index of the day. 0=sunday, 1=monday, ...
728
     * @param locale {String} optional locale to be used
729
     * @return {Boolean} whether the given day is a weekend day
730
     */
731
    __isWeekend : function(day, locale) {
732
      var weekendStart = this.__getWeekendStart(locale);
733
      var weekendEnd = this.__getWeekendEnd(locale);
734
735
      if (weekendEnd > weekendStart) {
736
        return ((day >= weekendStart) && (day <= weekendEnd));
737
      } else {
738
        return ((day >= weekendStart) || (day <= weekendEnd));
739
      }
740
    },
741
    
742
    /**
743
     * Extract the territory part from a locale
744
     *
745
     * @type member
746
     * @param locale {String} the locale
747
     * @return {String} territory
748
     */
749
    __getTerritory : function(locale) {
750
      if (locale) {
751
        var territory = locale.split("_")[1] || locale;
752
      } else {
753
        territory = qx.locale.Manager.getInstance().getTerritory() || qx.locale.Manager.getInstance().getLanguage();
754
      }
755
756
      return territory.toUpperCase();
757
    }
758
  },
759
760
  /*
761
  *****************************************************************************
762
     DESTRUCTOR
763
  *****************************************************************************
764
  */
765
766
  destruct : function() {
767
    qx.locale.Manager.getInstance().removeEventListener("changeLocale", this._updateDatePane, this);
768
769
    this._disposeObjects("_lastMonthBt", "_nextMonthBt", "_monthYearLabel");
770
771
    this._disposeObjectDeep("_weekdayLabelArr", 1);
772
    this._disposeObjectDeep("_dayLabelArr", 1);    
773
  }
774
});
(-)js/org/eclipse/swt/widgets/DateTimeCalendar.js (+81 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, monthNames, weekdayNames ) {
16
    this.base( arguments );
17
    this.setAppearance( "datetime-calendar" );      
18
    
19
    // Has selection listener
20
    this._hasSelectionListener = false;
21
    
22
    // Get names of weekdays and months
23
    qx.ui.component.DateChooser.MONTH_NAMES = monthNames;    
24
    qx.ui.component.DateChooser.WEEKDAY_NAMES = weekdayNames;
25
    
26
    // The DateChooser
27
    this._calendar = new qx.ui.component.DateChooser;
28
    this._calendar.addEventListener( "changeDate", this._onChangeDate, this );
29
    this._calendar.setDate( new Date( 74, 5, 6 ) );
30
    this.add( this._calendar );
31
  },
32
33
  destruct : function() {
34
  	this._calendar.removeEventListener( "changeDate", this._onChangeDate, this );
35
    this._disposeObjects( "_calendar" );
36
  },
37
38
  members : {
39
  	_onChangeDate : function() {
40
  		var date = this._calendar.getDate();
41
  		this._sendChanges( date.getDate(), date.getMonth(), date.getYear() );
42
  	},
43
  	
44
  	_sendChanges : function( date, month, year ) {
45
      if( !org_eclipse_rap_rwt_EventUtil_suspend ) {        
46
        var widgetManager = org.eclipse.swt.WidgetManager.getInstance();
47
        var req = org.eclipse.swt.Request.getInstance();
48
        var id = widgetManager.findIdByWidget( this );        
49
        req.addParameter( id + ".date", date );
50
        req.addParameter( id + ".month", month );
51
        req.addParameter( id + ".year", year );
52
        if( this._hasSelectionListener ) {
53
          req.addEvent( "org.eclipse.swt.events.widgetSelected", id );
54
          req.send();
55
        }
56
      }
57
    },
58
    
59
    setMonth : function( value ) { 
60
      var date = this._calendar.getDate();
61
      date.setMonth( value );
62
      this._calendar.setDate( date );
63
    },
64
    
65
    setDay : function( value ) {
66
      var date = this._calendar.getDate();
67
      date.setDate( value );
68
      this._calendar.setDate( date );
69
    },
70
    
71
    setYear : function( value ) {
72
      var date = this._calendar.getDate();
73
      date.setYear( value );
74
      this._calendar.setDate( date );
75
    },
76
    
77
    setHasSelectionListener : function( value ) {
78
      this._hasSelectionListener = value;
79
    }
80
  }
81
} );
(-)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 (+130 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 DateTimeCalendarLCA extends AbstractDateTimeLCADelegate {
21
22
  static final String TYPE_POOL_ID = DateTimeCalendarLCA.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
  }
42
43
  void readData( final DateTime dateTime ) {
44
    String value = WidgetLCAUtil.readPropertyValue( dateTime, PROP_DAY );
45
    if( value != null ) {
46
      dateTime.setDay( Integer.parseInt( value ) );
47
    }
48
    value = WidgetLCAUtil.readPropertyValue( dateTime, PROP_MONTH );
49
    if( value != null ) {
50
      dateTime.setMonth( Integer.parseInt( value ) );
51
    }
52
    value = WidgetLCAUtil.readPropertyValue( dateTime, PROP_YEAR );
53
    if( value != null ) {
54
      dateTime.setYear( Integer.parseInt( value ) );
55
    }
56
    ControlLCAUtil.processSelection( dateTime, null, true );
57
  }
58
59
  void renderInitialization( final DateTime dateTime )
60
    throws IOException
61
  {
62
    IDateTimeAdapter dateTimeAdapter 
63
      = DateTimeLCAUtil.getDateTimeAdapter( dateTime );
64
    JSWriter writer = JSWriter.getWriterFor( dateTime );
65
    String style = "";
66
    if( ( dateTime.getStyle() & SWT.SHORT ) != 0 ) {
67
      style = "short";
68
    } else if( ( dateTime.getStyle() & SWT.MEDIUM ) != 0 ) {
69
      style = "medium";
70
    } else if( ( dateTime.getStyle() & SWT.LONG ) != 0 ) {
71
      style = "long";
72
    }
73
    Object[] args = new Object[]{
74
      style,
75
      dateTimeAdapter.getMonthNames(),
76
      dateTimeAdapter.getWeekdayNames()
77
    };
78
    writer.newWidget( "org.eclipse.swt.widgets.DateTimeCalendar", args );
79
    WidgetLCAUtil.writeCustomVariant( dateTime );
80
    ControlLCAUtil.writeStyleFlags( dateTime );
81
  }
82
83
  void renderChanges( final DateTime dateTime ) throws IOException {
84
    ControlLCAUtil.writeChanges( dateTime );
85
    writeDay( dateTime );
86
    writeMonth( dateTime );
87
    writeYear( dateTime );
88
    DateTimeLCAUtil.writeListener( dateTime );
89
  }
90
91
  void renderDispose( final DateTime dateTime ) throws IOException {
92
    JSWriter writer = JSWriter.getWriterFor( dateTime );
93
    writer.dispose();
94
  }
95
96
  void createResetHandlerCalls( final String typePoolId )
97
    throws IOException
98
  {
99
  }
100
101
  String getTypePoolId( final DateTime dateTime ) {
102
    return null;
103
  }
104
  
105
  // ////////////////////////////////////
106
  // Helping methods to write properties
107
  private void writeDay( final DateTime dateTime ) throws IOException {
108
    Integer newValue = new Integer( dateTime.getDay() );
109
    if( WidgetLCAUtil.hasChanged( dateTime, PROP_DAY, newValue ) ) {
110
      JSWriter writer = JSWriter.getWriterFor( dateTime );
111
      writer.set( PROP_DAY, newValue );
112
    }
113
  }
114
115
  private void writeMonth( final DateTime dateTime ) throws IOException {
116
    Integer newValue = new Integer( dateTime.getMonth() );
117
    if( WidgetLCAUtil.hasChanged( dateTime, PROP_MONTH, newValue ) ) {
118
      JSWriter writer = JSWriter.getWriterFor( dateTime );
119
      writer.set( PROP_MONTH, newValue );
120
    }
121
  }
122
123
  private void writeYear( final DateTime dateTime ) throws IOException {
124
    Integer newValue = new Integer( dateTime.getYear() );
125
    if( WidgetLCAUtil.hasChanged( dateTime, PROP_YEAR, newValue ) ) {
126
      JSWriter writer = JSWriter.getWriterFor( dateTime );
127
      writer.set( PROP_YEAR, newValue );
128
    }
129
  }
130
}

Return to bug 183177