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/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
    "calendar/lastMonth.gif",
130
    "calendar/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 (+894 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.rwt.RWT;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.SWTException;
17
import org.eclipse.swt.events.SelectionEvent;
18
import org.eclipse.swt.events.SelectionListener;
19
import org.eclipse.swt.graphics.*;
20
import org.eclipse.swt.internal.graphics.TextSizeDetermination;
21
import org.eclipse.swt.internal.widgets.IDateTimeAdapter;
22
23
/**
24
 * Instances of this class are selectable user interface objects that allow the
25
 * user to enter and modify date or time values.
26
 * <p>
27
 * Note that although this class is a subclass of <code>Composite</code>, it
28
 * does not make sense to add children to it, or set a layout on it.
29
 * </p>
30
 * <dl>
31
 * <dt><b>Styles:</b></dt>
32
 * <dd>DATE, TIME, CALENDAR, SHORT, MEDIUM, LONG</dd>
33
 * <dt><b>Events:</b></dt>
34
 * <dd>Selection</dd>
35
 * </dl>
36
 * <p>
37
 * Note: Only one of the styles DATE, TIME, or CALENDAR may be specified, and
38
 * only one of the styles SHORT, MEDIUM, or LONG may be specified.
39
 * </p>
40
 * <p>
41
 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
42
 * </p>
43
 * 
44
 * @since x.x
45
 */
46
public class DateTime extends Composite {
47
  
48
  private final class DateTimeAdapter implements IDateTimeAdapter {
49
50
    public Rectangle getBounds( final int widget ) {
51
      Rectangle result = new Rectangle( 0, 0, 0, 0);
52
      switch( widget ) {
53
        case WEEKDAY_TEXTFIELD:
54
          result = weekdayTextFieldBounds;
55
        break;
56
        case DAY_TEXTFIELD:
57
          result = dayTextFieldBounds;
58
        break;
59
        case MONTH_TEXTFIELD:
60
          result = monthTextFieldBounds;
61
        break;
62
        case YEAR_TEXTFIELD:
63
          result = yearTextFieldBounds;
64
        break;
65
        case WEEKDAY_MONTH_SEPARATOR:
66
          result = separator0Bounds;
67
        break;
68
        case MONTH_DAY_SEPARATOR:
69
          result = separator1Bounds;
70
        break;
71
        case DAY_YEAR_SEPARATOR:
72
          result = separator2Bounds;
73
        break;
74
        case SPINNER:
75
          result = spinnerBounds;
76
        break;
77
        case HOURS_TEXTFIELD:
78
          result = hoursTextFieldBounds;
79
        break;
80
        case MINUTES_TEXTFIELD:
81
          result = minutesTextFieldBounds;
82
        break;
83
        case SECONDS_TEXTFIELD:
84
          result = secondsTextFieldBounds;
85
        break;
86
        case HOURS_MINUTES_SEPARATOR:
87
          result = separator3Bounds;
88
        break;
89
        case MINUTES_SECONDS_SEPARATOR:
90
          result = separator4Bounds;
91
        break;
92
      }
93
      return result;
94
    }
95
    
96
    public String[] getMonthNames() {
97
      return MONTH_NAMES;
98
    }
99
    
100
    public String[] getWeekdayNames() {
101
      return WEEKDAY_NAMES;
102
    }
103
    
104
    public String getDateSeparator() {
105
      return DATE_SEPARATOR;
106
    }
107
    
108
    public String getDatePattern() {
109
      return DATE_PATTERN;
110
    }
111
  }
112
  
113
  private int V_PADDING = 6;
114
  private int H_PADDING = 6;
115
  
116
  private String[] MONTH_NAMES;  
117
  private String[] WEEKDAY_NAMES;  
118
  private String DATE_SEPARATOR;
119
  private String DATE_PATTERN;
120
  
121
  private final IDateTimeAdapter dateTimeAdapter;  
122
  private Calendar rightNow;
123
  
124
  // Date fields  
125
  private Rectangle weekdayTextFieldBounds;
126
  private Rectangle dayTextFieldBounds;
127
  private Rectangle monthTextFieldBounds;
128
  private Rectangle yearTextFieldBounds;
129
  private Rectangle separator0Bounds;
130
  private Rectangle separator1Bounds;
131
  private Rectangle separator2Bounds;
132
  private Rectangle spinnerBounds;
133
  // Time fields
134
  private Rectangle hoursTextFieldBounds;
135
  private Rectangle minutesTextFieldBounds;
136
  private Rectangle secondsTextFieldBounds;
137
  private Rectangle separator3Bounds;
138
  private Rectangle separator4Bounds;
139
  
140
  /**
141
   * Constructs a new instance of this class given its parent and a style value
142
   * describing its behavior and appearance.
143
   * <p>
144
   * The style value is either one of the style constants defined in class
145
   * <code>SWT</code> which is applicable to instances of this class, or must
146
   * be built by <em>bitwise OR</em>'ing together (that is, using the
147
   * <code>int</code> "|" operator) two or more of those <code>SWT</code>
148
   * style constants. The class description lists the style constants that are
149
   * applicable to the class. Style bits are also inherited from superclasses.
150
   * </p>
151
   * 
152
   * @param parent a composite control which will be the parent of the new
153
   *          instance (cannot be null)
154
   * @param style the style of control to construct
155
   * @exception IllegalArgumentException
156
   *              <ul>
157
   *              <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
158
   *              </ul>
159
   * @exception SWTException
160
   *              <ul>
161
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
162
   *              thread that created the parent</li>
163
   *              <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed
164
   *              subclass</li>
165
   *              </ul>
166
   * @see SWT#DATE
167
   * @see SWT#TIME
168
   * @see SWT#CALENDAR
169
   * @see Widget#checkSubclass
170
   * @see Widget#getStyle
171
   */
172
  public DateTime( final Composite parent, final int style ) {
173
    super( parent, checkStyle( style ) );
174
    dateTimeAdapter = new DateTimeAdapter();
175
    rightNow = Calendar.getInstance();    
176
    DateFormatSymbols symbols = new DateFormatSymbols( RWT.getLocale() );
177
    MONTH_NAMES = symbols.getMonths();
178
    WEEKDAY_NAMES = symbols.getWeekdays();
179
    DATE_SEPARATOR = getDateSeparator();
180
    DATE_PATTERN = getDatePattern( DATE_SEPARATOR );
181
    computeSubWidgetsBounds();
182
  }
183
184
  /**
185
   * Adds the listener to the collection of listeners who will be notified when
186
   * the control is selected by the user, by sending it one of the messages
187
   * defined in the <code>SelectionListener</code> interface.
188
   * <p>
189
   * <code>widgetSelected</code> is called when the user changes the control's
190
   * value. <code>widgetDefaultSelected</code> is not called.
191
   * </p>
192
   * 
193
   * @param listener the listener which should be notified
194
   * @exception IllegalArgumentException
195
   *              <ul>
196
   *              <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
197
   *              </ul>
198
   * @exception SWTException
199
   *              <ul>
200
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
201
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
202
   *              thread that created the receiver</li>
203
   *              </ul>
204
   * @see SelectionListener
205
   * @see #removeSelectionListener
206
   * @see SelectionEvent
207
   */
208
  public void addSelectionListener( final SelectionListener listener ) {
209
    SelectionEvent.addListener( this, listener );
210
  }
211
  
212
  /**
213
   * Removes the listener from the collection of listeners who will be notified
214
   * when the control is selected by the user.
215
   * 
216
   * @param listener the listener which should no longer be notified
217
   * @exception IllegalArgumentException
218
   *              <ul>
219
   *              <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
220
   *              </ul>
221
   * @exception SWTException
222
   *              <ul>
223
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
224
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
225
   *              thread that created the receiver</li>
226
   *              </ul>
227
   * @see SelectionListener
228
   * @see #addSelectionListener
229
   */
230
  public void removeSelectionListener( final SelectionListener listener ) {
231
    SelectionEvent.removeListener( this, listener );
232
  }  
233
234
  /**
235
   * Returns the receiver's hours.
236
   * <p>
237
   * Hours is an integer between 0 and 23.
238
   * </p>
239
   * 
240
   * @return an integer between 0 and 23
241
   * @exception SWTException
242
   *              <ul>
243
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
244
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
245
   *              thread that created the receiver</li>
246
   *              </ul>
247
   */
248
  public int getHours() {
249
    checkWidget();
250
    return rightNow.get( Calendar.HOUR_OF_DAY );
251
  }
252
253
  /**
254
   * Returns the receiver's minutes.
255
   * <p>
256
   * Minutes is an integer between 0 and 59.
257
   * </p>
258
   * 
259
   * @return an integer between 0 and 59
260
   * @exception SWTException
261
   *              <ul>
262
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
263
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
264
   *              thread that created the receiver</li>
265
   *              </ul>
266
   */
267
  public int getMinutes() {
268
    checkWidget();
269
    return rightNow.get( Calendar.MINUTE );
270
  }
271
  
272
  /**
273
   * Returns the receiver's seconds.
274
   * <p>
275
   * Seconds is an integer between 0 and 59.
276
   * </p>
277
   * 
278
   * @return an integer between 0 and 59
279
   * @exception SWTException
280
   *              <ul>
281
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
282
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
283
   *              thread that created the receiver</li>
284
   *              </ul>
285
   */
286
  public int getSeconds() {
287
    checkWidget();    
288
    return rightNow.get( Calendar.SECOND );
289
  }
290
  
291
  /**
292
   * Returns the receiver's date, or day of the month.
293
   * <p>
294
   * The first day of the month is 1, and the last day depends on the month and
295
   * year.
296
   * </p>
297
   * 
298
   * @return a positive integer beginning with 1
299
   * @exception SWTException
300
   *              <ul>
301
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
302
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
303
   *              thread that created the receiver</li>
304
   *              </ul>
305
   */
306
  public int getDay() {
307
    checkWidget();    
308
    return rightNow.get( Calendar.DATE );
309
  }
310
311
  /**
312
   * Returns the receiver's month.
313
   * <p>
314
   * The first month of the year is 0, and the last month is 11.
315
   * </p>
316
   * 
317
   * @return an integer between 0 and 11
318
   * @exception SWTException
319
   *              <ul>
320
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
321
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
322
   *              thread that created the receiver</li>
323
   *              </ul>
324
   */
325
  public int getMonth() {
326
    checkWidget();    
327
    return rightNow.get( Calendar.MONTH );
328
  }
329
330
  /**
331
   * Returns the receiver's year.
332
   * <p>
333
   * The first year is 1752 and the last year is 9999.
334
   * </p>
335
   * 
336
   * @return an integer between 1752 and 9999
337
   * @exception SWTException
338
   *              <ul>
339
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
340
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
341
   *              thread that created the receiver</li>
342
   *              </ul>
343
   */
344
  public int getYear() {
345
    checkWidget();   
346
    return rightNow.get( Calendar.YEAR );
347
  } 
348
349
  /**
350
   * Sets the receiver's hours.
351
   * <p>
352
   * Hours is an integer between 0 and 23.
353
   * </p>
354
   * 
355
   * @param hours an integer between 0 and 23
356
   * @exception SWTException
357
   *              <ul>
358
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
359
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
360
   *              thread that created the receiver</li>
361
   *              </ul>
362
   */
363
  public void setHours( final int hours ) {
364
    checkWidget();
365
    if( hours >= 0 && hours <= 23 ) {
366
      rightNow.set( Calendar.HOUR_OF_DAY, hours );
367
    }
368
  }
369
370
  /**
371
   * Sets the receiver's minutes.
372
   * <p>
373
   * Minutes is an integer between 0 and 59.
374
   * </p>
375
   * 
376
   * @param minutes an integer between 0 and 59
377
   * @exception SWTException
378
   *              <ul>
379
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
380
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
381
   *              thread that created the receiver</li>
382
   *              </ul>
383
   */
384
  public void setMinutes( final int minutes ) {
385
    checkWidget();
386
    if( minutes >= 0 && minutes <= 59 ) {
387
      rightNow.set( Calendar.MINUTE, minutes );
388
    }    
389
  }
390
  
391
  /**
392
   * Sets the receiver's seconds.
393
   * <p>
394
   * Seconds is an integer between 0 and 59.
395
   * </p>
396
   * 
397
   * @param seconds an integer between 0 and 59
398
   * @exception SWTException
399
   *              <ul>
400
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
401
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
402
   *              thread that created the receiver</li>
403
   *              </ul>
404
   */
405
  public void setSeconds( final int seconds ) {
406
    checkWidget();
407
    if( seconds >= 0 && seconds <= 59 ) {
408
      rightNow.set( Calendar.SECOND, seconds );
409
    }    
410
  }
411
  
412
  /**
413
   * Sets the receiver's date, or day of the month, to the specified day.
414
   * <p>
415
   * The first day of the month is 1, and the last day depends on the month and
416
   * year.
417
   * </p>
418
   * 
419
   * @param day a positive integer beginning with 1
420
   * @exception SWTException
421
   *              <ul>
422
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
423
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
424
   *              thread that created the receiver</li>
425
   *              </ul>
426
   */
427
  public void setDay( final int day ) {
428
    checkWidget(); 
429
    int month = rightNow.get( Calendar.MONTH );
430
    int year = rightNow.get( Calendar.YEAR );
431
    if( day >= 1 && day <= getDaysInMonth( month, year ) ) {
432
      rightNow.set( Calendar.DATE, day );
433
    }
434
  }
435
436
  /**
437
   * Sets the receiver's month.
438
   * <p>
439
   * The first month of the year is 0, and the last month is 11.
440
   * </p>
441
   * 
442
   * @param month an integer between 0 and 11
443
   * @exception SWTException
444
   *              <ul>
445
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
446
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
447
   *              thread that created the receiver</li>
448
   *              </ul>
449
   */
450
  public void setMonth( final int month ) {
451
    checkWidget();
452
    int date = rightNow.get( Calendar.DATE );
453
    int year = rightNow.get( Calendar.YEAR );
454
    if( month >= 0 && month <= 11 && date <= getDaysInMonth( month, year ) ) {
455
      rightNow.set( Calendar.MONTH, month );
456
    }    
457
  }  
458
459
  /**
460
   * Sets the receiver's year.
461
   * <p>
462
   * The first year is 1752 and the last year is 9999.
463
   * </p>
464
   * 
465
   * @param year an integer between 1752 and 9999
466
   * @exception SWTException
467
   *              <ul>
468
   *              <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
469
   *              <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
470
   *              thread that created the receiver</li>
471
   *              </ul>
472
   */
473
  public void setYear( final int year ) {
474
    checkWidget();
475
    int date = rightNow.get( Calendar.DATE );
476
    int month = rightNow.get( Calendar.MONTH );
477
    if( year >= 1752 && year <= 9999 && date <= getDaysInMonth( month, year ) ) {
478
      rightNow.set( Calendar.YEAR, year );
479
    }
480
  }
481
  
482
  /**
483
   * Sets the font that the receiver will use to paint textual information
484
   * to the font specified by the argument, or to the default font for that
485
   * kind of control if the argument is null.
486
   *
487
   * @param font the new font (or null)
488
   *
489
   * @exception IllegalArgumentException <ul>
490
   *    <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
491
   *                </ul>
492
   * @exception SWTException <ul>
493
   *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
494
   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
495
   *                </ul>
496
   */
497
  public void setFont( final Font font ) {
498
    if( font != getFont() ) {
499
      super.setFont( font );
500
    }
501
    computeSubWidgetsBounds();
502
  }
503
  
504
  public Object getAdapter( final Class adapter ) {
505
    Object result;
506
    if( adapter == IDateTimeAdapter.class ) {
507
      result = dateTimeAdapter;
508
    } else {
509
      result = super.getAdapter( adapter );
510
    }
511
    return result;
512
  }
513
  
514
  public Point computeSize( final int wHint, 
515
                            final int hHint, 
516
                            final boolean changed ) {
517
    checkWidget();    
518
    int width = 0, height = 0;
519
    if( wHint == SWT.DEFAULT || hHint == SWT.DEFAULT ) {
520
      Point size = computeSubWidgetsBounds();
521
      width = size.x;
522
      height = size.y;
523
    }
524
    if( width == 0 ) {
525
      width = DEFAULT_WIDTH;
526
    }  
527
    if( height == 0 ) {
528
      height = DEFAULT_HEIGHT;
529
    }  
530
    if( wHint != SWT.DEFAULT ) {
531
      width = wHint;
532
    }  
533
    if( hHint != SWT.DEFAULT ) {
534
      height = hHint;
535
    }  
536
    int border = getBorderWidth();
537
    width += border * 2;
538
    height += border * 2;
539
    return new Point( width, height );
540
  }
541
  
542
  private Point computeSubWidgetsBounds() {
543
    Font font = getFont();
544
    int width = 0, height = 0;
545
    if( ( style & SWT.CALENDAR ) != 0 ) {
546
      width = 168;
547
      height = 140;  
548
    } else if( ( style & SWT.DATE ) != 0 ) {
549
      Point prefSize = new Point( 0, 0 );
550
      if( DATE_PATTERN.equals( "MDY" ) ) {
551
        prefSize = computeMDYBounds( font );        
552
      } else if( DATE_PATTERN.equals( "DMY" ) ) {
553
        prefSize = computeDMYBounds( font );
554
      } else {
555
        if( ( style & SWT.MEDIUM ) != 0 ) {
556
          prefSize = computeYMDBounds( font );
557
        } else {
558
          prefSize = computeMDYBounds( font ); 
559
        }
560
      }
561
      // Overall widget size
562
      width = prefSize.x;
563
      height = prefSize.y;
564
    } else if( ( style & SWT.TIME ) != 0 ) {
565
      // Hours text field
566
      hoursTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
567
      hoursTextFieldBounds.width 
568
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
569
      hoursTextFieldBounds.height 
570
        = TextSizeDetermination.stringExtent( font, "88" ).y + V_PADDING;
571
      // Hours minutes separator
572
      separator3Bounds = new Rectangle( 0, 0, 0, 0 );
573
      separator3Bounds.x = hoursTextFieldBounds.x + hoursTextFieldBounds.width;
574
      separator3Bounds.width 
575
        = TextSizeDetermination.stringExtent( font, ":" ).x;
576
      separator3Bounds.height = hoursTextFieldBounds.height;
577
      // Minutes text field
578
      minutesTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
579
      minutesTextFieldBounds.x = separator3Bounds.x + separator3Bounds.width;
580
      minutesTextFieldBounds.width = hoursTextFieldBounds.width;
581
      minutesTextFieldBounds.height = hoursTextFieldBounds.height;
582
      // Minutes seconds separator
583
      separator4Bounds = new Rectangle( 0, 0, 0, 0 );
584
      separator4Bounds.x = minutesTextFieldBounds.x 
585
                         + minutesTextFieldBounds.width;
586
      separator4Bounds.width = separator3Bounds.width;
587
      separator4Bounds.height = hoursTextFieldBounds.height;
588
      // Seconds text field
589
      secondsTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
590
      secondsTextFieldBounds.x = separator4Bounds.x + separator4Bounds.width;
591
      secondsTextFieldBounds.width = hoursTextFieldBounds.width;
592
      secondsTextFieldBounds.height = hoursTextFieldBounds.height;
593
      // The spinner bounds
594
      spinnerBounds = new Rectangle( 0, 0, 0, 0 );
595
      spinnerBounds.x = minutesTextFieldBounds.x 
596
                      + minutesTextFieldBounds.width;
597
      if( ( style & SWT.MEDIUM ) != 0 || ( style & SWT.LONG) != 0 ) {
598
        spinnerBounds.x = secondsTextFieldBounds.x 
599
                        + secondsTextFieldBounds.width;
600
      }
601
      spinnerBounds.width = 17;
602
      spinnerBounds.height = hoursTextFieldBounds.height;
603
      // Overall widget size     
604
      width = spinnerBounds.x + spinnerBounds.width;
605
      height = hoursTextFieldBounds.height;        
606
    }
607
    return new Point( width, height );
608
  }
609
  
610
  private Point computeMDYBounds( final Font font ) {
611
    // The weekday text field bounds
612
    weekdayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
613
    if( ( style & SWT.LONG ) != 0 ) {
614
      weekdayTextFieldBounds.width
615
        = getMaxStringLength( font, WEEKDAY_NAMES ) + H_PADDING + 2;
616
    }  
617
    weekdayTextFieldBounds.height
618
      = TextSizeDetermination.stringExtent( font, WEEKDAY_NAMES[1] ).y
619
        + V_PADDING;
620
    // The weekday month separator bounds
621
    separator0Bounds = new Rectangle( 0, 0, 0, 0 );
622
    separator0Bounds.x 
623
      = weekdayTextFieldBounds.x + weekdayTextFieldBounds.width;
624
    if( ( style & SWT.LONG ) != 0 ) {
625
      separator0Bounds.width 
626
        = TextSizeDetermination.stringExtent( font, "," ).x;
627
    }
628
    separator0Bounds.height = weekdayTextFieldBounds.height;      
629
    // The month text field bounds
630
    monthTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
631
    monthTextFieldBounds.x = separator0Bounds.x + separator0Bounds.width;
632
    if( ( style & SWT.MEDIUM ) != 0 ) {
633
      monthTextFieldBounds.width 
634
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
635
    } else {        
636
      monthTextFieldBounds.width 
637
        = getMaxStringLength( font, MONTH_NAMES ) + H_PADDING + 2;
638
    }
639
    monthTextFieldBounds.height = weekdayTextFieldBounds.height;
640
    // The month date separator bounds
641
    separator1Bounds = new Rectangle( 0, 0, 0, 0 );
642
    separator1Bounds.x = monthTextFieldBounds.x + monthTextFieldBounds.width;
643
    if( ( style & SWT.MEDIUM ) != 0 ) {
644
      separator1Bounds.width 
645
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
646
    }
647
    separator1Bounds.height = weekdayTextFieldBounds.height;
648
    // The date text field bounds
649
    dayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
650
    dayTextFieldBounds.x = separator1Bounds.x + separator1Bounds.width;
651
    if( ( style & SWT.SHORT ) == 0 ) {
652
      dayTextFieldBounds.width 
653
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
654
    }
655
    dayTextFieldBounds.height = weekdayTextFieldBounds.height;
656
    // The date year separator bounds
657
    separator2Bounds = new Rectangle( 0, 0, 0, 0 );
658
    separator2Bounds.x = dayTextFieldBounds.x + dayTextFieldBounds.width;
659
    if( ( style & SWT.MEDIUM ) != 0 ) {
660
      separator2Bounds.width 
661
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
662
    } else {
663
      separator2Bounds.width 
664
        = TextSizeDetermination.stringExtent( font, "," ).x;
665
    }
666
    separator2Bounds.height = weekdayTextFieldBounds.height;            
667
    // The year text field bounds
668
    yearTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
669
    yearTextFieldBounds.x = separator2Bounds.x + separator2Bounds.width;
670
    yearTextFieldBounds.width 
671
      = TextSizeDetermination.stringExtent( font, "8888" ).x + H_PADDING;
672
    yearTextFieldBounds.height = weekdayTextFieldBounds.height;
673
    // The spinner bounds
674
    spinnerBounds = new Rectangle( 0, 0, 0, 0 );
675
    spinnerBounds.x = yearTextFieldBounds.x + yearTextFieldBounds.width;
676
    spinnerBounds.width = 17;
677
    spinnerBounds.height = weekdayTextFieldBounds.height;
678
    // Overall widget size
679
    int width = spinnerBounds.x + spinnerBounds.width;
680
    int height = weekdayTextFieldBounds.height;
681
    return new Point( width, height );
682
  }
683
  
684
  private Point computeDMYBounds( final Font font ) {
685
    // The weekday text field bounds
686
    weekdayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
687
    if( ( style & SWT.LONG ) != 0 ) {
688
      weekdayTextFieldBounds.width
689
        = getMaxStringLength( font, WEEKDAY_NAMES ) + H_PADDING + 2;
690
    }  
691
    weekdayTextFieldBounds.height
692
      = TextSizeDetermination.stringExtent( font, WEEKDAY_NAMES[1] ).y 
693
        + V_PADDING;
694
    // The weekday day separator bounds
695
    separator0Bounds = new Rectangle( 0, 0, 0, 0 );
696
    separator0Bounds.x 
697
      = weekdayTextFieldBounds.x + weekdayTextFieldBounds.width;
698
    if( ( style & SWT.LONG ) != 0 ) {
699
      separator0Bounds.width 
700
        = TextSizeDetermination.stringExtent( font, "," ).x;
701
    }
702
    separator0Bounds.height = weekdayTextFieldBounds.height;      
703
    // The day text field bounds
704
    dayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
705
    dayTextFieldBounds.x = separator0Bounds.x + separator0Bounds.width;
706
    if( ( style & SWT.SHORT ) == 0 ) {
707
      dayTextFieldBounds.width 
708
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
709
    }
710
    dayTextFieldBounds.height = weekdayTextFieldBounds.height;
711
    // The day month separator bounds
712
    separator1Bounds = new Rectangle( 0, 0, 0, 0 );
713
    separator1Bounds.x = dayTextFieldBounds.x + dayTextFieldBounds.width;
714
    if( ( style & SWT.MEDIUM ) != 0 ) {
715
      separator1Bounds.width 
716
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
717
    }
718
    separator1Bounds.height = weekdayTextFieldBounds.height;
719
    // The month text field bounds
720
    monthTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
721
    monthTextFieldBounds.x = separator1Bounds.x + separator1Bounds.width;
722
    if( ( style & SWT.MEDIUM ) != 0 ) {
723
      monthTextFieldBounds.width 
724
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
725
    } else {        
726
      monthTextFieldBounds.width 
727
        = getMaxStringLength( font, MONTH_NAMES ) + H_PADDING + 2;
728
    }
729
    monthTextFieldBounds.height = weekdayTextFieldBounds.height;
730
    // The month year separator bounds
731
    separator2Bounds = new Rectangle( 0, 0, 0, 0 );
732
    separator2Bounds.x = monthTextFieldBounds.x + monthTextFieldBounds.width;
733
    if( ( style & SWT.MEDIUM ) != 0 ) {
734
      separator2Bounds.width 
735
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
736
    } else {
737
      separator2Bounds.width 
738
        = TextSizeDetermination.stringExtent( font, "," ).x;
739
    }
740
    separator2Bounds.height = weekdayTextFieldBounds.height;            
741
    // The year text field bounds
742
    yearTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
743
    yearTextFieldBounds.x = separator2Bounds.x + separator2Bounds.width;
744
    yearTextFieldBounds.width 
745
      = TextSizeDetermination.stringExtent( font, "8888" ).x + H_PADDING;
746
    yearTextFieldBounds.height = weekdayTextFieldBounds.height;
747
    // The spinner bounds
748
    spinnerBounds = new Rectangle( 0, 0, 0, 0 );
749
    spinnerBounds.x = yearTextFieldBounds.x + yearTextFieldBounds.width;
750
    spinnerBounds.width = 17;
751
    spinnerBounds.height = weekdayTextFieldBounds.height;
752
    // Overall widget size
753
    int width = spinnerBounds.x + spinnerBounds.width;
754
    int height = weekdayTextFieldBounds.height;
755
    return new Point( width, height );
756
  }
757
758
  private Point computeYMDBounds( final Font font ) {
759
    // The weekday text field bounds
760
    weekdayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
761
    if( ( style & SWT.LONG ) != 0 ) {
762
      weekdayTextFieldBounds.width
763
        = getMaxStringLength( font, WEEKDAY_NAMES ) + H_PADDING + 2;
764
    }  
765
    weekdayTextFieldBounds.height
766
      = TextSizeDetermination.stringExtent( font, WEEKDAY_NAMES[1] ).y 
767
        + V_PADDING;
768
    // The weekday day separator bounds
769
    separator0Bounds = new Rectangle( 0, 0, 0, 0 );
770
    separator0Bounds.x 
771
      = weekdayTextFieldBounds.x + weekdayTextFieldBounds.width;
772
    if( ( style & SWT.LONG ) != 0 ) {
773
      separator0Bounds.width 
774
        = TextSizeDetermination.stringExtent( font, "," ).x;
775
    }
776
    separator0Bounds.height = weekdayTextFieldBounds.height;
777
    // The year text field bounds
778
    yearTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
779
    yearTextFieldBounds.x = separator0Bounds.x + separator0Bounds.width;
780
    yearTextFieldBounds.width 
781
      = TextSizeDetermination.stringExtent( font, "8888" ).x + H_PADDING;
782
    yearTextFieldBounds.height = weekdayTextFieldBounds.height;
783
    // The year month separator bounds
784
    separator1Bounds = new Rectangle( 0, 0, 0, 0 );
785
    separator1Bounds.x = yearTextFieldBounds.x + yearTextFieldBounds.width;
786
    if( ( style & SWT.MEDIUM ) != 0 ) {
787
      separator1Bounds.width 
788
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
789
    }
790
    // The month text field bounds
791
    monthTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
792
    monthTextFieldBounds.x = separator1Bounds.x + separator1Bounds.width;
793
    if( ( style & SWT.MEDIUM ) != 0 ) {
794
      monthTextFieldBounds.width 
795
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
796
    } else {        
797
      monthTextFieldBounds.width 
798
        = getMaxStringLength( font, MONTH_NAMES ) + H_PADDING + 2;
799
    }
800
    monthTextFieldBounds.height = weekdayTextFieldBounds.height;
801
    // The month day separator bounds
802
    separator2Bounds = new Rectangle( 0, 0, 0, 0 );
803
    separator2Bounds.x = monthTextFieldBounds.x + monthTextFieldBounds.width;
804
    if( ( style & SWT.MEDIUM ) != 0 ) {
805
      separator2Bounds.width 
806
        = TextSizeDetermination.stringExtent( font, DATE_SEPARATOR ).x;
807
    } else {
808
      separator2Bounds.width 
809
        = TextSizeDetermination.stringExtent( font, "," ).x;
810
    }
811
    separator2Bounds.height = weekdayTextFieldBounds.height;     
812
    // The day text field bounds
813
    dayTextFieldBounds = new Rectangle( 0, 0, 0, 0 );
814
    dayTextFieldBounds.x = separator2Bounds.x + separator2Bounds.width;
815
    if( ( style & SWT.SHORT ) == 0 ) {
816
      dayTextFieldBounds.width 
817
        = TextSizeDetermination.stringExtent( font, "88" ).x + H_PADDING;
818
    }
819
    dayTextFieldBounds.height = weekdayTextFieldBounds.height;
820
    
821
    separator1Bounds.height = weekdayTextFieldBounds.height;    
822
    // The spinner bounds
823
    spinnerBounds = new Rectangle( 0, 0, 0, 0 );
824
    spinnerBounds.x = dayTextFieldBounds.x + dayTextFieldBounds.width;
825
    spinnerBounds.width = 17;
826
    spinnerBounds.height = weekdayTextFieldBounds.height;
827
    // Overall widget size
828
    int width = spinnerBounds.x + spinnerBounds.width;
829
    int height = weekdayTextFieldBounds.height;
830
    return new Point( width, height );
831
  }
832
  
833
  private int getDaysInMonth( final int month, final int year ) {
834
    GregorianCalendar cal = new GregorianCalendar( year, month, 1 );
835
    return cal.getActualMaximum( Calendar.DAY_OF_MONTH );
836
  }
837
  
838
  private int getMaxStringLength( final Font font, final String[] strings ) {
839
    int maxLength = 0;
840
    for( int i = 0; i < strings.length; i++ ) {
841
      int currentStringWidth
842
        = TextSizeDetermination.stringExtent( font, strings[i] ).x;
843
      maxLength = Math.max( maxLength, currentStringWidth );
844
    }
845
    return maxLength;
846
  }
847
  
848
  private String getDateSeparator() {
849
    DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT );    
850
    String datePattern = ( ( SimpleDateFormat )df ).toPattern();
851
    String result = "";
852
    int index = 0;
853
    while( Character.isLetter( datePattern.charAt( index ) ) ) {
854
      index++;
855
    }
856
    result = Character.toString( datePattern.charAt( index ) );
857
    return result;
858
  }
859
  
860
  private String getDatePattern( final String dateSeparator ) {
861
    DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT );    
862
    String datePattern = ( ( SimpleDateFormat )df ).toPattern();
863
    String result = "";
864
    StringTokenizer st = new StringTokenizer( datePattern, 
865
                                              dateSeparator );
866
    while ( st.hasMoreTokens() ) {
867
      String token = st.nextToken();
868
      result += Character.toString( token.charAt( 0 ) );
869
    }
870
    return result.toUpperCase();
871
  }
872
  
873
  String getNameText() {
874
    return "DateTime";
875
  } 
876
  
877
  static int checkStyle( final int value ) {
878
    /*
879
     * Even though it is legal to create this widget with scroll bars, they
880
     * serve no useful purpose because they do not automatically scroll the
881
     * widget's client area. The fix is to clear the SWT style.
882
     */
883
    int style = value;
884
    style &= ~( SWT.H_SCROLL | SWT.V_SCROLL );
885
    style = checkBits( style, SWT.DATE, SWT.TIME, SWT.CALENDAR, 0, 0, 0 );
886
    return checkBits( style, SWT.MEDIUM, SWT.SHORT, SWT.LONG, 0, 0, 0 );
887
  }
888
889
  protected void checkSubclass() {
890
    if( !isValidSubclass() ) {
891
      error( SWT.ERROR_INVALID_SUBCLASS );
892
    }  
893
  }
894
}
(-)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/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/RWTHostTestSuite.java (+1 lines)
Lines 146-151 Link Here
146
    suite.addTestSuite( ExternalBrowser_Test.class );
146
    suite.addTestSuite( ExternalBrowser_Test.class );
147
    suite.addTestSuite( ProgressBar_Test.class );
147
    suite.addTestSuite( ProgressBar_Test.class );
148
    suite.addTestSuite( BusyIndicator_Test.class );
148
    suite.addTestSuite( BusyIndicator_Test.class );
149
    suite.addTestSuite( DateTime_Test.class );
149
150
150
    suite.addTestSuite( Image_Test.class );
151
    suite.addTestSuite( Image_Test.class );
151
    suite.addTestSuite( ImageData_Test.class );
152
    suite.addTestSuite( ImageData_Test.class );
(-)src/org/eclipse/swt/widgets/DateTime_Test.java (+167 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Innoopract Informationssysteme GmbH. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html Contributors:
6
 * Innoopract Informationssysteme GmbH - initial API and implementation
7
 ******************************************************************************/
8
package org.eclipse.swt.widgets;
9
10
import java.util.Calendar;
11
12
import junit.framework.TestCase;
13
14
import org.eclipse.swt.RWTFixture;
15
import org.eclipse.swt.SWT;
16
17
public class DateTime_Test extends TestCase {
18
19
  protected void setUp() throws Exception {
20
    RWTFixture.setUp();
21
  }
22
23
  protected void tearDown() throws Exception {
24
    RWTFixture.tearDown();
25
  }
26
27
  public void testInitialValues() {
28
    Display display = new Display();
29
    Shell shell = new Shell( display, SWT.NONE );
30
    Calendar rightNow = Calendar.getInstance();
31
    DateTime dateTime = new DateTime( shell, SWT.DATE | SWT.MEDIUM );
32
    assertEquals( rightNow.get( Calendar.DATE ), dateTime.getDay() );
33
    assertEquals( rightNow.get( Calendar.MONTH ), dateTime.getMonth() );
34
    assertEquals( rightNow.get( Calendar.YEAR ), dateTime.getYear() );
35
    assertEquals( rightNow.get( Calendar.HOUR_OF_DAY ), dateTime.getHours() );
36
    assertEquals( rightNow.get( Calendar.MINUTE ), dateTime.getMinutes() );
37
    assertEquals( rightNow.get( Calendar.SECOND ), dateTime.getSeconds() );
38
  }
39
40
  public void testInvalidValues() {
41
    Display display = new Display();
42
    Shell shell = new Shell( display, SWT.NONE );    
43
    DateTime dateTime = new DateTime( shell, SWT.NONE );
44
    dateTime.setDay( 1 );
45
    dateTime.setMonth( 0 );
46
    dateTime.setYear( 2008 );
47
    dateTime.setHours( 0 );
48
    dateTime.setMinutes( 0 );
49
    dateTime.setSeconds( 0 );
50
    assertEquals( 1, dateTime.getDay() );
51
    assertEquals( 0, dateTime.getMonth() );
52
    assertEquals( 2008, dateTime.getYear() );
53
    assertEquals( 0, dateTime.getHours() );
54
    assertEquals( 0, dateTime.getMinutes() );
55
    assertEquals( 0, dateTime.getSeconds() );
56
    // Test day
57
    dateTime.setDay( 61 );
58
    assertEquals( 1, dateTime.getDay() );
59
    dateTime.setDay( 0 );
60
    assertEquals( 1, dateTime.getDay() );
61
    dateTime.setDay( -5 );
62
    assertEquals( 1, dateTime.getDay() );
63
    dateTime.setMonth( 1 );
64
    dateTime.setDay( 29 );
65
    assertEquals( 29, dateTime.getDay() );
66
    dateTime.setDay( 30 );
67
    assertEquals( 29, dateTime.getDay() );    
68
    // Test month
69
    dateTime.setMonth( 12 );
70
    assertEquals( 1, dateTime.getMonth() );
71
    dateTime.setMonth( -5 );
72
    assertEquals( 1, dateTime.getMonth() );    
73
    dateTime.setMonth( 0 );
74
    dateTime.setDay( 31 );
75
    dateTime.setMonth( 1 );
76
    assertEquals( 0, dateTime.getMonth() );
77
    // Test year
78
    dateTime.setYear( 12345 );
79
    assertEquals( 2008, dateTime.getYear() );
80
    dateTime.setYear( 123 );
81
    assertEquals( 2008, dateTime.getYear() );
82
    dateTime.setDay( 29 );
83
    dateTime.setMonth( 1 );    
84
    dateTime.setYear( 2007 );
85
    assertEquals( 2008, dateTime.getYear() );
86
    // Test hours
87
    dateTime.setHours( 24 );
88
    assertEquals( 0, dateTime.getHours() );
89
    dateTime.setHours( -3 );
90
    assertEquals( 0, dateTime.getHours() );
91
    // Test minutes
92
    dateTime.setMinutes( 65 );
93
    assertEquals( 0, dateTime.getMinutes() );
94
    dateTime.setMinutes( -7 );
95
    assertEquals( 0, dateTime.getMinutes() );
96
    // Test seconds
97
    dateTime.setSeconds( 89 );
98
    assertEquals( 0, dateTime.getSeconds() );
99
    dateTime.setSeconds( -1 );
100
    assertEquals( 0, dateTime.getSeconds() );
101
  }
102
103
  public void testStyle() {
104
    Display display = new Display();
105
    Shell shell = new Shell( display, SWT.NONE );    
106
    // Test SWT.NONE
107
    DateTime dateTime = new DateTime( shell, SWT.NONE );
108
    assertTrue( ( dateTime.getStyle() & SWT.DATE ) != 0 );
109
    assertTrue( ( dateTime.getStyle() & SWT.MEDIUM ) != 0 );
110
    // Test SWT.BORDER
111
    dateTime = new DateTime( shell, SWT.BORDER );
112
    assertTrue( ( dateTime.getStyle() & SWT.DATE ) != 0 );
113
    assertTrue( ( dateTime.getStyle() & SWT.MEDIUM ) != 0 );
114
    assertTrue( ( dateTime.getStyle() & SWT.BORDER ) != 0 );
115
    // Test combination of SWT.DATE | SWT.TIME | SWT.CALENDAR
116
    dateTime = new DateTime( shell, SWT.DATE | SWT.TIME | SWT.CALENDAR );
117
    assertTrue( ( dateTime.getStyle() & SWT.DATE ) != 0 );
118
    assertTrue( ( dateTime.getStyle() & SWT.TIME ) == 0 );
119
    assertTrue( ( dateTime.getStyle() & SWT.CALENDAR ) == 0 );
120
    dateTime = new DateTime( shell, SWT.DATE | SWT.TIME );
121
    assertTrue( ( dateTime.getStyle() & SWT.DATE ) != 0 );
122
    assertTrue( ( dateTime.getStyle() & SWT.TIME ) == 0 );
123
    dateTime = new DateTime( shell, SWT.DATE | SWT.CALENDAR );
124
    assertTrue( ( dateTime.getStyle() & SWT.DATE ) != 0 );
125
    assertTrue( ( dateTime.getStyle() & SWT.CALENDAR ) == 0 );
126
    dateTime = new DateTime( shell, SWT.TIME | SWT.CALENDAR );
127
    assertTrue( ( dateTime.getStyle() & SWT.TIME ) != 0 );
128
    assertTrue( ( dateTime.getStyle() & SWT.CALENDAR ) == 0 );
129
    dateTime = new DateTime( shell, SWT.CALENDAR );
130
    assertTrue( ( dateTime.getStyle() & SWT.CALENDAR ) != 0 );
131
    // Test combination of SWT.MEDIUM | SWT.SHORT | SWT.LONG
132
    dateTime = new DateTime( shell, SWT.DATE
133
                                    | SWT.MEDIUM
134
                                    | SWT.SHORT
135
                                    | SWT.LONG );
136
    assertTrue( ( dateTime.getStyle() & SWT.DATE ) != 0 );
137
    assertTrue( ( dateTime.getStyle() & SWT.MEDIUM ) != 0 );
138
    assertTrue( ( dateTime.getStyle() & SWT.SHORT ) == 0 );
139
    assertTrue( ( dateTime.getStyle() & SWT.LONG ) == 0 );
140
    dateTime = new DateTime( shell, SWT.DATE
141
                             | SWT.MEDIUM
142
                             | SWT.SHORT );
143
    assertTrue( ( dateTime.getStyle() & SWT.DATE ) != 0 );
144
    assertTrue( ( dateTime.getStyle() & SWT.MEDIUM ) != 0 );
145
    assertTrue( ( dateTime.getStyle() & SWT.SHORT ) == 0 );
146
    dateTime = new DateTime( shell, SWT.DATE
147
                             | SWT.MEDIUM                             
148
                             | SWT.LONG );
149
    assertTrue( ( dateTime.getStyle() & SWT.DATE ) != 0 );
150
    assertTrue( ( dateTime.getStyle() & SWT.MEDIUM ) != 0 );    
151
    assertTrue( ( dateTime.getStyle() & SWT.LONG ) == 0 );
152
    dateTime = new DateTime( shell, SWT.TIME                            
153
                             | SWT.SHORT
154
                             | SWT.LONG );
155
    assertTrue( ( dateTime.getStyle() & SWT.TIME ) != 0 );    
156
    assertTrue( ( dateTime.getStyle() & SWT.SHORT ) != 0 );
157
    assertTrue( ( dateTime.getStyle() & SWT.LONG ) == 0 );
158
  }
159
160
  public void testDispose() {
161
    Display display = new Display();
162
    Shell shell = new Shell( display );
163
    DateTime dateTime = new DateTime( shell, SWT.DATE | SWT.MEDIUM );
164
    dateTime.dispose();
165
    assertTrue( dateTime.isDisposed() );
166
  }
167
}
(-)src/org/eclipse/swt/internal/widgets/displaykit/QooxdooResourcesUtil.java (-4 / +16 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 CALENDAR_JS
127
    = "org/eclipse/swt/widgets/Calendar.js";
120
128
121
  private QooxdooResourcesUtil() {
129
  private QooxdooResourcesUtil() {
122
    // prevent intance creation
130
    // prevent intance creation
Lines 184-189 Link Here
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( CALENDAR_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
  // Calendar
1772
  
1773
  "calendar-navBar" : {
1774
    style : function(states) {      
1775
      return {
1776
      	backgroundColor : "#0A246A",
1777
      	padding : [ 4, 4, 4, 4 ]
1778
      };
1779
    }
1780
  },
1781
      
1782
  "calendar-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
  "calendar-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
  "calendar-datepane" : {
1815
    style : function(states) {
1816
      return {
1817
        backgroundColor : "white"
1818
      };
1819
    }
1820
  },
1821
1822
  "calendar-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
  "calendar-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 + ".day", this._removeLeadingZero( this._dayTextField.getValue() ) );
618
        req.addParameter( id + ".month", this._monthInt - 1 );
619
        req.addParameter( id + ".year", this._lastValidYear );
620
        if( this._hasSelectionListener ) {
621
          req.addEvent( "org.eclipse.swt.events.widgetSelected", id );
622
          req.send();
623
        }
624
        this._readyToSendChanges = true;
625
      }
626
    },
627
    
628
    setMonth : function( value ) { 
629
      this._monthInt = value + 1;
630
      if( this._medium ) {
631
        this._monthTextField.setValue( this._addLeadingZero( this._monthInt ) );
632
      } else {   
633
        this._monthTextField.setValue( this._monthname[ this._monthInt - 1 ] );
634
      }
635
      if( this._focusedTextField === this._monthTextField ) {
636
        this._spinner.setValue( this._monthInt );
637
      }
638
      // Set the weekday
639
      this._setWeekday();
640
    },
641
    
642
    setDay : function( value ) {
643
    	this._dayTextField.setValue( this._addLeadingZero( value ) );
644
    	if( this._focusedTextField === this._dayTextField ) {
645
        this._spinner.setValue( value );
646
      }
647
      // Set the weekday
648
      this._setWeekday();
649
    },
650
    
651
    setYear : function( value ) {
652
      this._lastValidYear = value;
653
      this._yearTextField.setValue( value );
654
      if( this._focusedTextField === this._yearTextField ) {
655
        this._spinner.setValue( value );
656
      }
657
      // Set the weekday
658
      this._setWeekday();
659
    },
660
    
661
    setHasSelectionListener : function( value ) {
662
      this._hasSelectionListener = value;
663
    },
664
    
665
    setBounds : function( ind, x, y, width, height ) {
666
    	var widget;
667
    	switch( ind ) {
668
    		case org.eclipse.swt.widgets.DateTimeDate.WEEKDAY_TEXTFIELD:
669
	    		widget = this._weekdayTextField;
670
    		break;
671
    		case org.eclipse.swt.widgets.DateTimeDate.DATE_TEXTFIELD:
672
    		  widget = this._dayTextField;
673
        break;
674
        case org.eclipse.swt.widgets.DateTimeDate.MONTH_TEXTFIELD:
675
          widget = this._monthTextField;
676
        break;
677
        case org.eclipse.swt.widgets.DateTimeDate.YEAR_TEXTFIELD:
678
          widget = this._yearTextField;
679
        break;
680
        case org.eclipse.swt.widgets.DateTimeDate.WEEKDAY_MONTH_SEPARATOR:
681
          widget = this._separator0;
682
        break;
683
        case org.eclipse.swt.widgets.DateTimeDate.MONTH_DATE_SEPARATOR:
684
          widget = this._separator1;
685
        break;
686
        case org.eclipse.swt.widgets.DateTimeDate.DATE_YEAR_SEPARATOR:
687
          widget = this._separator2;
688
        break;
689
        case org.eclipse.swt.widgets.DateTimeDate.SPINNER:
690
          widget = this._spinner;
691
        break;
692
    	}
693
    	widget.set({        
694
        left: x,
695
        top: y,
696
        width: width,
697
        height: height
698
      });  
699
    }
700
  }
701
} );
(-)src/org/eclipse/swt/internal/widgets/datetimekit/DateTimeLCAUtil.java (+68 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002-2008 Innoopract Informationssysteme GmbH. All rights
3
 * reserved. This program and the accompanying materials are made available
4
 * under the terms of the Eclipse Public License v1.0 which accompanies this
5
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
6
 * Contributors: Innoopract Informationssysteme GmbH - initial API and
7
 * implementation
8
 ******************************************************************************/
9
package org.eclipse.swt.internal.widgets.datetimekit;
10
11
import java.io.IOException;
12
13
import org.eclipse.rwt.lifecycle.*;
14
import org.eclipse.swt.events.SelectionEvent;
15
import org.eclipse.swt.graphics.Rectangle;
16
import org.eclipse.swt.internal.widgets.IDateTimeAdapter;
17
import org.eclipse.swt.internal.widgets.Props;
18
import org.eclipse.swt.widgets.DateTime;
19
20
final class DateTimeLCAUtil {
21
22
  private DateTimeLCAUtil() {
23
    // prevent instantiation
24
  }
25
  
26
  static IDateTimeAdapter getDateTimeAdapter( final DateTime dateTime ) {
27
    return ( IDateTimeAdapter )dateTime.getAdapter( IDateTimeAdapter.class );
28
  }
29
  
30
  static void preserveSubWidgetBounds( final DateTime dateTime,
31
                                       final int subWidgetID ) {
32
    IWidgetAdapter adapter = WidgetUtil.getAdapter( dateTime );
33
    IDateTimeAdapter dateTimeAdapter = getDateTimeAdapter( dateTime );
34
    Rectangle subWidgetBounds = dateTimeAdapter.getBounds( subWidgetID );
35
    adapter.preserve( subWidgetID + "_BOUNDS", subWidgetBounds );
36
  }
37
  
38
  static void writeSubWidgetBounds( final DateTime dateTime,
39
                                    final int subWidgetID )
40
    throws IOException    
41
  {
42
    IDateTimeAdapter dateTimeAdapter = getDateTimeAdapter( dateTime );    
43
    Rectangle newValue = dateTimeAdapter.getBounds( subWidgetID );
44
    if( WidgetLCAUtil.hasChanged( dateTime, 
45
                                  subWidgetID + "_BOUNDS", newValue ) ) {
46
      JSWriter writer = JSWriter.getWriterFor( dateTime );
47
      writer.call( "setBounds", new Object[]{
48
        new Integer( subWidgetID ),
49
        new Integer( newValue.x ),
50
        new Integer( newValue.y ),
51
        new Integer( newValue.width ),
52
        new Integer( newValue.height )
53
      });
54
    }
55
  }
56
  
57
  static void writeListener( final DateTime dateTime )
58
    throws IOException
59
  {  
60
    boolean hasListener = SelectionEvent.hasListener( dateTime );
61
    Boolean newValue = Boolean.valueOf( hasListener );
62
    String prop = Props.SELECTION_LISTENERS;
63
    if( WidgetLCAUtil.hasChanged( dateTime, prop, newValue, Boolean.FALSE ) ) {
64
      JSWriter writer = JSWriter.getWriterFor( dateTime );
65
      writer.set( "hasSelectionListener", newValue );
66
    }
67
  }
68
}
(-)src/org/eclipse/swt/internal/widgets/datetimekit/DateTimeTimeLCA.java (+171 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002-2008 Innoopract Informationssysteme GmbH. All rights
3
 * reserved. This program and the accompanying materials are made available
4
 * under the terms of the Eclipse Public License v1.0 which accompanies this
5
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
6
 * Contributors: Innoopract Informationssysteme GmbH - initial API and
7
 * implementation
8
 ******************************************************************************/
9
package org.eclipse.swt.internal.widgets.datetimekit;
10
11
import java.io.IOException;
12
13
import org.eclipse.rwt.lifecycle.*;
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.events.SelectionEvent;
16
import org.eclipse.swt.internal.widgets.IDateTimeAdapter;
17
import org.eclipse.swt.internal.widgets.Props;
18
import org.eclipse.swt.widgets.DateTime;
19
20
public class DateTimeTimeLCA extends AbstractDateTimeLCADelegate {
21
22
  static final String TYPE_POOL_ID = DateTimeTimeLCA.class.getName();
23
  // Property names for preserveValues
24
  static final String PROP_HOURS = "hours";
25
  static final String PROP_MINUTES = "minutes";
26
  static final String PROP_SECONDS = "seconds";
27
28
  // Property names for preserveValues
29
  void preserveValues( final DateTime dateTime ) {
30
    ControlLCAUtil.preserveValues( dateTime );
31
    IWidgetAdapter adapter = WidgetUtil.getAdapter( dateTime );
32
    boolean hasListeners = SelectionEvent.hasListener( dateTime );
33
    adapter.preserve( Props.SELECTION_LISTENERS,
34
                      Boolean.valueOf( hasListeners ) );
35
    adapter.preserve( PROP_HOURS, 
36
                      new Integer( dateTime.getHours() ) );
37
    adapter.preserve( PROP_MINUTES, 
38
                      new Integer( dateTime.getMinutes() ) );
39
    adapter.preserve( PROP_SECONDS, 
40
                      new Integer( dateTime.getSeconds() ) );
41
    preserveSubWidgetsBounds( dateTime );
42
  }
43
44
  void readData( final DateTime dateTime ) {
45
    String value = WidgetLCAUtil.readPropertyValue( dateTime, PROP_HOURS );
46
    if( value != null ) {
47
      dateTime.setHours( Integer.parseInt( value ) );
48
    }
49
    value = WidgetLCAUtil.readPropertyValue( dateTime, PROP_MINUTES );
50
    if( value != null ) {
51
      dateTime.setMinutes( Integer.parseInt( value ) );
52
    }
53
    value = WidgetLCAUtil.readPropertyValue( dateTime, PROP_SECONDS );
54
    if( value != null ) {
55
      dateTime.setSeconds( Integer.parseInt( value ) );
56
    }
57
    ControlLCAUtil.processSelection( dateTime, null, true );
58
  }
59
60
  void renderInitialization( final DateTime dateTime )
61
    throws IOException
62
  {
63
    JSWriter writer = JSWriter.getWriterFor( dateTime );
64
    String style = "";
65
    if( ( dateTime.getStyle() & SWT.SHORT ) != 0 ) {
66
      style = "short";
67
    } else if( ( dateTime.getStyle() & SWT.MEDIUM ) != 0 ) {
68
      style = "medium";
69
    } else if( ( dateTime.getStyle() & SWT.LONG ) != 0 ) {
70
      style = "long";
71
    }
72
    Object[] args = new Object[]{
73
      style
74
    };
75
    writer.newWidget( "org.eclipse.swt.widgets.DateTimeTime", args );
76
    WidgetLCAUtil.writeCustomVariant( dateTime );
77
    ControlLCAUtil.writeStyleFlags( dateTime );
78
  }
79
80
  void renderChanges( final DateTime dateTime ) throws IOException {
81
    ControlLCAUtil.writeChanges( dateTime );
82
    writeHours( dateTime );
83
    writeMinutes( dateTime );
84
    writeSeconds( dateTime );
85
    DateTimeLCAUtil.writeListener( dateTime );
86
    writeSubWidgetsBounds( dateTime );
87
  }
88
89
  void renderDispose( final DateTime dateTime ) throws IOException {
90
    JSWriter writer = JSWriter.getWriterFor( dateTime );
91
    writer.dispose();
92
  }
93
94
  void createResetHandlerCalls( final String typePoolId )
95
    throws IOException
96
  {
97
  }
98
99
  String getTypePoolId( final DateTime dateTime ) {
100
    return null;
101
  }
102
  // ////////////////////////////////////
103
  // Helping methods to write properties
104
  private void writeHours( final DateTime dateTime ) throws IOException {
105
    Integer newValue = new Integer( dateTime.getHours() );
106
    if( WidgetLCAUtil.hasChanged( dateTime, PROP_HOURS, newValue ) ) {
107
      JSWriter writer = JSWriter.getWriterFor( dateTime );
108
      writer.set( PROP_HOURS, newValue );
109
    }
110
  }
111
112
  private void writeMinutes( final DateTime dateTime ) throws IOException {
113
    Integer newValue = new Integer( dateTime.getMinutes() );
114
    if( WidgetLCAUtil.hasChanged( dateTime, PROP_MINUTES, newValue ) ) {
115
      JSWriter writer = JSWriter.getWriterFor( dateTime );
116
      writer.set( PROP_MINUTES, newValue );
117
    }
118
  }
119
120
  private void writeSeconds( final DateTime dateTime ) throws IOException {
121
    Integer newValue = new Integer( dateTime.getSeconds() );
122
    if( WidgetLCAUtil.hasChanged( dateTime, PROP_SECONDS, newValue ) ) {
123
      JSWriter writer = JSWriter.getWriterFor( dateTime );
124
      writer.set( PROP_SECONDS, newValue );
125
    }
126
  }
127
128
  private void writeSubWidgetsBounds( final DateTime dateTime )
129
    throws IOException
130
  {
131
    // The hours text field bounds
132
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
133
                    IDateTimeAdapter.HOURS_TEXTFIELD );
134
    // The hours minutes separator bounds
135
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
136
                    IDateTimeAdapter.HOURS_MINUTES_SEPARATOR );
137
    // The minutes text field bounds
138
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
139
                    IDateTimeAdapter.MINUTES_TEXTFIELD );
140
    // The minutes seconds separator bounds
141
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
142
                    IDateTimeAdapter.MINUTES_SECONDS_SEPARATOR );
143
    // The seconds text field bounds
144
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
145
                    IDateTimeAdapter.SECONDS_TEXTFIELD );
146
    // The spinner bounds
147
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
148
                    IDateTimeAdapter.SPINNER );
149
  }
150
  
151
  private void preserveSubWidgetsBounds( final DateTime dateTime ) {
152
    // The hours text field bounds
153
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
154
                    IDateTimeAdapter.HOURS_TEXTFIELD );
155
    // The hours minutes separator bounds
156
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
157
                    IDateTimeAdapter.HOURS_MINUTES_SEPARATOR );
158
    // The minutes text field bounds
159
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
160
                    IDateTimeAdapter.MINUTES_TEXTFIELD );
161
    // The minutes seconds separator bounds
162
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
163
                    IDateTimeAdapter.MINUTES_SECONDS_SEPARATOR );
164
    // The seconds text field bounds
165
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
166
                    IDateTimeAdapter.SECONDS_TEXTFIELD );
167
    // The spinner bounds
168
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
169
                    IDateTimeAdapter.SPINNER );
170
  }
171
}
(-)src/org/eclipse/swt/internal/widgets/datetimekit/DateTimeDateLCA.java (+190 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002-2008 Innoopract Informationssysteme GmbH. All rights
3
 * reserved. This program and the accompanying materials are made available
4
 * under the terms of the Eclipse Public License v1.0 which accompanies this
5
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
6
 * Contributors: Innoopract Informationssysteme GmbH - initial API and
7
 * implementation
8
 ******************************************************************************/
9
package org.eclipse.swt.internal.widgets.datetimekit;
10
11
import java.io.IOException;
12
13
import org.eclipse.rwt.lifecycle.*;
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.events.SelectionEvent;
16
import org.eclipse.swt.internal.widgets.IDateTimeAdapter;
17
import org.eclipse.swt.internal.widgets.Props;
18
import org.eclipse.swt.widgets.DateTime;
19
20
public class DateTimeDateLCA extends AbstractDateTimeLCADelegate {
21
22
  static final String TYPE_POOL_ID = DateTimeDateLCA.class.getName();
23
  // Property names for preserveValues
24
  static final String PROP_DAY = "day";
25
  static final String PROP_MONTH = "month";
26
  static final String PROP_YEAR = "year";
27
28
  // Property names for preserveValues
29
  void preserveValues( final DateTime dateTime ) {
30
    ControlLCAUtil.preserveValues( dateTime );
31
    IWidgetAdapter adapter = WidgetUtil.getAdapter( dateTime );
32
    boolean hasListeners = SelectionEvent.hasListener( dateTime );
33
    adapter.preserve( Props.SELECTION_LISTENERS,
34
                      Boolean.valueOf( hasListeners ) );
35
    adapter.preserve( PROP_DAY, 
36
                      new Integer( dateTime.getDay() ) );
37
    adapter.preserve( PROP_MONTH, 
38
                      new Integer( dateTime.getMonth() ) );
39
    adapter.preserve( PROP_YEAR, 
40
                      new Integer( dateTime.getYear() ) );
41
    preserveSubWidgetsBounds( dateTime );
42
  }
43
44
  void readData( final DateTime dateTime ) {
45
    String value = WidgetLCAUtil.readPropertyValue( dateTime, PROP_DAY );
46
    if( value != null ) {
47
      dateTime.setDay( Integer.parseInt( value ) );
48
    }
49
    value = WidgetLCAUtil.readPropertyValue( dateTime, PROP_MONTH );
50
    if( value != null ) {
51
      dateTime.setMonth( Integer.parseInt( value ) );
52
    }
53
    value = WidgetLCAUtil.readPropertyValue( dateTime, PROP_YEAR );
54
    if( value != null ) {
55
      dateTime.setYear( Integer.parseInt( value ) );
56
    }
57
    ControlLCAUtil.processSelection( dateTime, null, true );
58
  }
59
60
  void renderInitialization( final DateTime dateTime )
61
    throws IOException
62
  {
63
    IDateTimeAdapter dateTimeAdapter 
64
      = DateTimeLCAUtil.getDateTimeAdapter( dateTime );
65
    JSWriter writer = JSWriter.getWriterFor( dateTime );
66
    String style = "";
67
    if( ( dateTime.getStyle() & SWT.SHORT ) != 0 ) {
68
      style = "short";
69
    } else if( ( dateTime.getStyle() & SWT.MEDIUM ) != 0 ) {
70
      style = "medium";
71
    } else if( ( dateTime.getStyle() & SWT.LONG ) != 0 ) {
72
      style = "long";
73
    }
74
    Object[] args = new Object[]{
75
      style,
76
      dateTimeAdapter.getMonthNames(),
77
      dateTimeAdapter.getWeekdayNames(),
78
      dateTimeAdapter.getDateSeparator(),
79
      dateTimeAdapter.getDatePattern()
80
    };
81
    writer.newWidget( "org.eclipse.swt.widgets.DateTimeDate", args );
82
    WidgetLCAUtil.writeCustomVariant( dateTime );
83
    ControlLCAUtil.writeStyleFlags( dateTime );
84
  }
85
86
  void renderChanges( final DateTime dateTime ) throws IOException {
87
    ControlLCAUtil.writeChanges( dateTime );
88
    writeDay( dateTime );
89
    writeMonth( dateTime );
90
    writeYear( dateTime );
91
    DateTimeLCAUtil.writeListener( dateTime );
92
    writeSubWidgetsBounds( dateTime );
93
  }
94
95
  void renderDispose( final DateTime dateTime ) throws IOException {
96
    JSWriter writer = JSWriter.getWriterFor( dateTime );
97
    writer.dispose();
98
  }
99
100
  void createResetHandlerCalls( final String typePoolId )
101
    throws IOException
102
  {
103
  }
104
105
  String getTypePoolId( final DateTime dateTime ) {
106
    return null;
107
  }
108
109
  // ////////////////////////////////////
110
  // Helping methods to write properties
111
  private void writeDay( final DateTime dateTime ) throws IOException {
112
    Integer newValue = new Integer( dateTime.getDay() );
113
    if( WidgetLCAUtil.hasChanged( dateTime, PROP_DAY, newValue ) ) {
114
      JSWriter writer = JSWriter.getWriterFor( dateTime );
115
      writer.set( PROP_DAY, newValue );
116
    }
117
  }
118
119
  private void writeMonth( final DateTime dateTime ) throws IOException {
120
    Integer newValue = new Integer( dateTime.getMonth() );
121
    if( WidgetLCAUtil.hasChanged( dateTime, PROP_MONTH, newValue ) ) {
122
      JSWriter writer = JSWriter.getWriterFor( dateTime );
123
      writer.set( PROP_MONTH, newValue );
124
    }
125
  }
126
127
  private void writeYear( final DateTime dateTime ) throws IOException {
128
    Integer newValue = new Integer( dateTime.getYear() );
129
    if( WidgetLCAUtil.hasChanged( dateTime, PROP_YEAR, newValue ) ) {
130
      JSWriter writer = JSWriter.getWriterFor( dateTime );
131
      writer.set( PROP_YEAR, newValue );
132
    }
133
  }
134
135
  private void writeSubWidgetsBounds( final DateTime dateTime )
136
    throws IOException
137
  {
138
    // The weekday text field bounds
139
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
140
                    IDateTimeAdapter.WEEKDAY_TEXTFIELD );
141
    // The weekday month separator bounds
142
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
143
                    IDateTimeAdapter.WEEKDAY_MONTH_SEPARATOR );
144
    // The month text field bounds
145
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
146
                    IDateTimeAdapter.MONTH_TEXTFIELD );
147
    // The month date separator bounds
148
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
149
                    IDateTimeAdapter.MONTH_DAY_SEPARATOR );
150
    // The date text field bounds
151
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
152
                    IDateTimeAdapter.DAY_TEXTFIELD );
153
    // The date year separator bounds
154
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
155
                    IDateTimeAdapter.DAY_YEAR_SEPARATOR );
156
    // The year text field bounds
157
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
158
                    IDateTimeAdapter.YEAR_TEXTFIELD );
159
    // The spinner bounds
160
    DateTimeLCAUtil.writeSubWidgetBounds( dateTime, 
161
                    IDateTimeAdapter.SPINNER );
162
  }
163
  
164
  private void preserveSubWidgetsBounds( final DateTime dateTime ) {
165
    // The weekday text field bounds
166
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
167
                    IDateTimeAdapter.WEEKDAY_TEXTFIELD );
168
    // The weekday month separator bounds
169
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
170
                    IDateTimeAdapter.WEEKDAY_MONTH_SEPARATOR );
171
    // The month text field bounds
172
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
173
                    IDateTimeAdapter.MONTH_TEXTFIELD );
174
    // The month date separator bounds
175
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
176
                    IDateTimeAdapter.MONTH_DAY_SEPARATOR );
177
    // The date text field bounds
178
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
179
                    IDateTimeAdapter.DAY_TEXTFIELD );
180
    // The date year separator bounds
181
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
182
                    IDateTimeAdapter.DAY_YEAR_SEPARATOR );
183
    // The year text field bounds
184
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
185
                    IDateTimeAdapter.YEAR_TEXTFIELD );
186
    // The spinner bounds
187
    DateTimeLCAUtil.preserveSubWidgetBounds( dateTime, 
188
                    IDateTimeAdapter.SPINNER );
189
  }
190
}
(-)src/org/eclipse/swt/internal/widgets/datetimekit/AbstractDateTimeLCADelegate.java (+30 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002-2008 Innoopract Informationssysteme GmbH. All rights
3
 * reserved. This program and the accompanying materials are made available
4
 * under the terms of the Eclipse Public License v1.0 which accompanies this
5
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
6
 * Contributors: Innoopract Informationssysteme GmbH - initial API and
7
 * implementation
8
 ******************************************************************************/
9
package org.eclipse.swt.internal.widgets.datetimekit;
10
11
import java.io.IOException;
12
13
import org.eclipse.swt.widgets.DateTime;
14
15
abstract class AbstractDateTimeLCADelegate {
16
17
  abstract void preserveValues( DateTime dateTime );
18
19
  abstract void readData( DateTime dateTime );
20
21
  abstract void renderInitialization( DateTime dateTime ) throws IOException;
22
23
  abstract void renderChanges( DateTime dateTime ) throws IOException;
24
25
  abstract void renderDispose( DateTime dateTime ) throws IOException;
26
27
  abstract void createResetHandlerCalls( String typePoolId ) throws IOException;
28
29
  abstract String getTypePoolId( DateTime dateTime );
30
}
(-)js/org/eclipse/swt/widgets/DateTimeCalendar.js (+94 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
    org.eclipse.swt.widgets.Calendar.MONTH_NAMES = monthNames;    
24
    org.eclipse.swt.widgets.Calendar.WEEKDAY_NAMES = weekdayNames;
25
    
26
    // The Calendar
27
    this._calendar = new org.eclipse.swt.widgets.Calendar;
28
    this._calendar.addEventListener( "changeDate", this._onChangeDate, this );
29
    this._calendar.setDate( new Date( 74, 5, 6 ) );
30
    this.add( this._calendar );
31
    
32
    this.addEventListener( "contextmenu", this._onContextMenu, this );
33
  },
34
35
  destruct : function() {
36
  	this._calendar.removeEventListener( "changeDate", this._onChangeDate, this );
37
  	this.removeEventListener( "contextmenu", this._onContextMenu, this );
38
    this._disposeObjects( "_calendar" );
39
  },
40
41
  members : {
42
  	_onChangeDate : function() {
43
  		var date = this._calendar.getDate();  		
44
  		this._sendChanges( date.getDate(), date.getMonth(), date.getFullYear() );
45
  	},
46
  	
47
  	_onContextMenu : function( evt ) {     
48
      var menu = this.getContextMenu();      
49
      if( menu != null ) {
50
        menu.setLocation( evt.getPageX(), evt.getPageY() );
51
        menu.setOpener( this );
52
        menu.show();
53
        evt.stopPropagation();
54
      }
55
    },
56
  	
57
  	_sendChanges : function( date, month, year ) {
58
      if( !org_eclipse_rap_rwt_EventUtil_suspend ) {        
59
        var widgetManager = org.eclipse.swt.WidgetManager.getInstance();
60
        var req = org.eclipse.swt.Request.getInstance();
61
        var id = widgetManager.findIdByWidget( this );        
62
        req.addParameter( id + ".day", date );
63
        req.addParameter( id + ".month", month );
64
        req.addParameter( id + ".year", year );
65
        if( this._hasSelectionListener ) {
66
          req.addEvent( "org.eclipse.swt.events.widgetSelected", id );
67
          req.send();
68
        }
69
      }
70
    },
71
    
72
    setMonth : function( value ) { 
73
      var date = this._calendar.getDate();
74
      date.setMonth( value );
75
      this._calendar.setDate( date );
76
    },
77
    
78
    setDay : function( value ) {
79
      var date = this._calendar.getDate();
80
      date.setDate( value );
81
      this._calendar.setDate( date );
82
    },
83
    
84
    setYear : function( value ) {
85
      var date = this._calendar.getDate();
86
      date.setYear( value );
87
      this._calendar.setDate( date );
88
    },
89
    
90
    setHasSelectionListener : function( value ) {
91
      this._hasSelectionListener = value;
92
    }
93
  }
94
} );
(-)js/org/eclipse/swt/widgets/Calendar.js (+766 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
 /**
13
  * This is a modified version of qooxdoo qx.ui.component.DateChooser component.
14
  */
15
16
/**
17
 * Shows a calendar and allows choosing a date.
18
 *
19
 * @appearance calendar-toolbar-button {qx.ui.toolbar.Button}
20
 * @appearance calendar-navBar {qx.ui.layout.BoxLayout}
21
 * @appearance calendar-monthyear {qx.ui.basic.Label}
22
 * @appearance calendar-weekday {qx.ui.basic.Label}
23
 * @appearance calendar-datepane {qx.ui.layout.CanvasLayout}
24
 * @appearance calendar-weekday {qx.ui.basic.Label}
25
 *
26
 * @appearance calendar-day {qx.ui.basic.Label}
27
 * @state weekend {calendar-day}
28
 * @state otherMonth {calendar-day}
29
 * @state today {calendar-day}
30
 * @state selected {calendar-day}
31
 */
32
qx.Class.define("org.eclipse.swt.widgets.Calendar", {
33
  extend : qx.ui.layout.BoxLayout,
34
35
  /*
36
  *****************************************************************************
37
     CONSTRUCTOR
38
  *****************************************************************************
39
  */
40
41
  /**
42
   * @param date {Date ? null} The initial date to show. If <code>null</code>
43
   *        the current day (today) is shown.
44
   */
45
  construct : function(date) {
46
    this.base(arguments);
47
48
    this.setOrientation("vertical");
49
50
    // Create the navigation bar
51
    var navBar = new qx.ui.layout.BoxLayout;
52
    navBar.setAppearance("calendar-navBar");
53
54
    navBar.set({
55
      height  : "auto",
56
      spacing : 1
57
    });
58
59
    var lastMonthBt = new qx.ui.toolbar.Button(null, "widget/calendar/lastMonth.gif");
60
    var monthYearLabel = new qx.ui.basic.Label;
61
    var nextMonthBt = new qx.ui.toolbar.Button(null, "widget/calendar/nextMonth.gif");
62
63
    lastMonthBt.set({
64
      show    : 'icon',
65
      toolTip : new qx.ui.popup.ToolTip(this.tr("Last month"))
66
    });
67
68
    nextMonthBt.set({
69
      show    : 'icon',
70
      toolTip : new qx.ui.popup.ToolTip(this.tr("Next month"))
71
    });
72
73
    lastMonthBt.setAppearance("calendar-toolbar-button");
74
    nextMonthBt.setAppearance("calendar-toolbar-button");
75
76
    lastMonthBt.addEventListener("click", this._onNavButtonClicked, this);
77
    nextMonthBt.addEventListener("click", this._onNavButtonClicked, this);
78
79
    this._lastMonthBt = lastMonthBt;
80
    this._nextMonthBt = nextMonthBt;
81
82
    monthYearLabel.setAppearance("calendar-monthyear");
83
    monthYearLabel.set({ width : "1*" });
84
85
    navBar.add(lastMonthBt, monthYearLabel, nextMonthBt);
86
    this._monthYearLabel = monthYearLabel;
87
    navBar.setHtmlProperty("id", "navBar");
88
89
    // Create the date pane
90
    var datePane = new qx.ui.layout.CanvasLayout;
91
    datePane.setAppearance("calendar-datepane");
92
93
    datePane.set({
94
      width  : org.eclipse.swt.widgets.Calendar.CELL_WIDTH * 7,
95
      height : org.eclipse.swt.widgets.Calendar.CELL_HEIGHT * 7
96
    });
97
98
    this._weekdayLabelArr = [];
99
100
    for (var i=0; i<7; i++) {
101
      var label = new qx.ui.basic.Label;
102
      label.setAppearance("calendar-weekday");
103
      label.setSelectable(false);
104
      label.setCursor("default");
105
106
      label.set({
107
        width  : org.eclipse.swt.widgets.Calendar.CELL_WIDTH,
108
        height : org.eclipse.swt.widgets.Calendar.CELL_HEIGHT,
109
        left   : i * org.eclipse.swt.widgets.Calendar.CELL_WIDTH
110
      });
111
112
      datePane.add(label);
113
      this._weekdayLabelArr.push(label);
114
    }
115
116
    // Add the days
117
    this._dayLabelArr = [];
118
119
    for (var y=0; y<6; y++) {
120
      // Add the day labels
121
      for (var x=0; x<7; x++) {
122
        var label = new qx.ui.basic.Label;
123
        label.setAppearance("calendar-day");
124
        label.setSelectable(false);
125
        label.setCursor("default");
126
127
        label.set({
128
          width  : org.eclipse.swt.widgets.Calendar.CELL_WIDTH,
129
          height : org.eclipse.swt.widgets.Calendar.CELL_HEIGHT,
130
          left   : x * org.eclipse.swt.widgets.Calendar.CELL_WIDTH,
131
          top    : (y + 1) * org.eclipse.swt.widgets.Calendar.CELL_HEIGHT
132
        });
133
134
        label.addEventListener("mousedown", this._onDayClicked, this);
135
        label.addEventListener("dblclick", this._onDayDblClicked, this);
136
        datePane.add(label);
137
        this._dayLabelArr.push(label);
138
      }
139
    }
140
141
    // Make focusable
142
    this.setTabIndex(1);
143
    this.addEventListener("keypress", this._onkeypress);
144
145
    // Show the right date
146
    var shownDate = (date != null) ? date : new Date();
147
    this.showMonth(shownDate.getMonth(), shownDate.getFullYear());
148
149
    // listen for locale changes
150
    qx.locale.Manager.getInstance().addEventListener("changeLocale", this._updateDatePane, this);
151
152
    // Add the main widgets
153
    this.add(navBar);
154
    this.add(datePane);
155
156
    // Initialize dimensions
157
    this.initWidth();
158
    this.initHeight();
159
  },
160
161
  /*
162
  *****************************************************************************
163
     EVENTS
164
  *****************************************************************************
165
  */
166
167
  events: {
168
    /** Fired when a date was selected. The event holds the new selected date in its data property.*/
169
    "select"     : "qx.event.type.DataEvent"
170
  },
171
172
  /*
173
  *****************************************************************************
174
     STATICS
175
  *****************************************************************************
176
  */
177
178
  statics : {
179
  	CELL_WIDTH : 24,
180
  	CELL_HEIGHT : 16,
181
    MONTH_NAMES : [],
182
    WEEKDAY_NAMES : []
183
  },
184
185
  /*
186
  *****************************************************************************
187
     PROPERTIES
188
  *****************************************************************************
189
  */
190
191
  properties : {
192
    width : {
193
      refine : true,
194
      init : "auto"
195
    },
196
197
    height : {
198
      refine : true,
199
      init : "auto"
200
    },
201
202
    /** The currently shown month. 0 = january, 1 = february, and so on. */
203
    shownMonth : {
204
      check : "Integer",
205
      init : null,
206
      nullable : true,
207
      event : "changeShownMonth"
208
    },
209
210
    /** The currently shown year. */
211
    shownYear : {
212
      check : "Integer",
213
      init : null,
214
      nullable : true,
215
      event : "changeShownYear"
216
    },
217
218
    /** {Date} The currently selected date. */
219
    date : {
220
      check : "Date",
221
      init : null,
222
      nullable : true,
223
      apply : "_applyDate",
224
      event : "changeDate",
225
      transform : "_checkDate"
226
    }
227
  },
228
229
  /*
230
  *****************************************************************************
231
     MEMBERS
232
  *****************************************************************************
233
  */
234
235
  members : {
236
    // property checker
237
    /**
238
     * TODOC
239
     *
240
     * @type member
241
     * @param value {var} Current value
242
     * @return {var} TODOC
243
     */
244
    _checkDate : function(value) {
245
      // Use a clone of the date internally since date instances may be changed
246
      return (value == null) ? null : new Date(value.getTime());
247
    },
248
249
    // property modifier
250
    /**
251
     * TODOC
252
     *
253
     * @type member
254
     * @param value {var} Current value
255
     * @param old {var} Previous value
256
     */
257
    _applyDate : function(value, old) {
258
      if ((value != null) && (this.getShownMonth() != value.getMonth() || this.getShownYear() != value.getFullYear())) {
259
        // The new date is in another month -> Show that month
260
        this.showMonth(value.getMonth(), value.getFullYear());
261
      } else {
262
        // The new date is in the current month -> Just change the states
263
        var newDay = (value == null) ? -1 : value.getDate();
264
265
        for (var i=0; i<6*7; i++) {
266
          var dayLabel = this._dayLabelArr[i];
267
268
          if (dayLabel.hasState("otherMonth")) {
269
            if (dayLabel.hasState("selected")) {
270
              dayLabel.removeState("selected");
271
            }
272
          } else {
273
            var day = parseInt(dayLabel.getText());
274
275
            if (day == newDay) {
276
              dayLabel.addState("selected");
277
            } else if (dayLabel.hasState("selected")) {
278
              dayLabel.removeState("selected");
279
            }
280
          }
281
        }
282
      }
283
    },
284
285
    /**
286
     * Event handler. Called when a navigation button has been clicked.
287
     *
288
     * @type member
289
     * @param evt {Map} the event.
290
     * @return {void}
291
     */
292
    _onNavButtonClicked : function(evt) {
293
      var year = this.getShownYear();
294
      var month = this.getShownMonth();
295
296
      switch(evt.getCurrentTarget()) {
297
        case this._lastMonthBt:
298
          month--;
299
300
          if (month < 0) {
301
            month = 11;
302
            year--;
303
          }
304
305
          break;
306
307
        case this._nextMonthBt:
308
          month++;
309
310
          if (month >= 12) {
311
            month = 0;
312
            year++;
313
          }
314
315
          break;
316
      }
317
318
      this.showMonth(month, year);
319
    },
320
321
    /**
322
     * Event handler. Called when a day has been clicked.
323
     *
324
     * @type member
325
     * @param evt {Map} the event.
326
     * @return {void}
327
     */
328
    _onDayClicked : function(evt) {
329
    	if( evt.isLeftButtonPressed() ) {
330
        var time = evt.getCurrentTarget().dateTime;
331
        this.setDate(new Date(time));
332
    	}
333
    },
334
335
    /**
336
     * TODOC
337
     *
338
     * @type member
339
     * @return {void}
340
     */
341
    _onDayDblClicked : function() {
342
      this.createDispatchDataEvent("select", this.getDate());
343
    },
344
345
    /**
346
     * Event handler. Called when a key was pressed.
347
     *
348
     * @type member
349
     * @param evt {Map} the event.
350
     * @return {boolean | void} TODOC
351
     */
352
    _onkeypress : function(evt) {
353
      var dayIncrement = null;
354
      var monthIncrement = null;
355
      var yearIncrement = null;
356
357
      if (evt.getModifiers() == 0) {
358
        switch(evt.getKeyIdentifier()) {
359
          case "Left":
360
            dayIncrement = -1;
361
            break;
362
363
          case "Right":
364
            dayIncrement = 1;
365
            break;
366
367
          case "Up":
368
            dayIncrement = -7;
369
            break;
370
371
          case "Down":
372
            dayIncrement = 7;
373
            break;
374
375
          case "PageUp":
376
            monthIncrement = -1;
377
            break;
378
379
          case "PageDown":
380
            monthIncrement = 1;
381
            break;
382
383
          case "Escape":
384
            if (this.getDate() != null) {
385
              this.setDate(null);
386
              return true;
387
            }
388
389
            break;
390
391
          case "Enter":
392
          case "Space":
393
            if (this.getDate() != null) {
394
              this.createDispatchDataEvent("select", this.getDate());
395
            }
396
397
            return;
398
        }
399
      }
400
      else if (evt.isShiftPressed()) {
401
        switch(evt.getKeyIdentifier()) {
402
          case "PageUp":
403
            yearIncrement = -1;
404
            break;
405
406
          case "PageDown":
407
            yearIncrement = 1;
408
            break;
409
        }
410
      }
411
412
      if (dayIncrement != null || monthIncrement != null || yearIncrement != null) {
413
        var date = this.getDate();
414
415
        if (date != null) {
416
          date = new Date(date.getTime()); // TODO: Do cloning in getter
417
        }
418
419
        if (date == null) {
420
          date = new Date();
421
        } else {
422
          if (dayIncrement != null) date.setDate(date.getDate() + dayIncrement);
423
          if (monthIncrement != null) date.setMonth(date.getMonth() + monthIncrement);
424
          if (yearIncrement != null) date.setFullYear(date.getFullYear() + yearIncrement);
425
        }
426
427
        this.setDate(date);
428
      }
429
    },
430
431
    // ***** Methods *****
432
    /**
433
     * Shows a certain month.
434
     *
435
     * @type member
436
     * @param month {Integer ? null} the month to show (0 = january). If not set the month
437
     *      will remain the same.
438
     * @param year {Integer ? null} the year to show. If not set the year will remain the
439
     *      same.
440
     * @return {void}
441
     */
442
    showMonth : function(month, year) {
443
      if ((month != null && month != this.getShownMonth()) || (year != null && year != this.getShownYear())) {
444
        if (month != null) {
445
          this.setShownMonth(month);
446
        }
447
448
        if (year != null) {
449
          this.setShownYear(year);
450
        }
451
452
        this._updateDatePane();
453
      }
454
    },
455
456
    /**
457
     * Updates the date pane.
458
     *
459
     * @type member
460
     * @return {void}
461
     */
462
    _updateDatePane : function() {
463
      var today = new Date();
464
      var todayYear = today.getFullYear();
465
      var todayMonth = today.getMonth();
466
      var todayDayOfMonth = today.getDate();
467
468
      var selDate = this.getDate();
469
      var selYear = (selDate == null) ? -1 : selDate.getFullYear();
470
      var selMonth = (selDate == null) ? -1 : selDate.getMonth();
471
      var selDayOfMonth = (selDate == null) ? -1 : selDate.getDate();
472
473
      var shownMonth = this.getShownMonth();
474
      var shownYear = this.getShownYear();
475
476
      var startOfWeek = this.__getWeekStart();
477
478
      // Create a help date that points to the first of the current month
479
      var helpDate = new Date(this.getShownYear(), this.getShownMonth(), 1);
480
      
481
      var year = this.getShownYear();      
482
      var month = org.eclipse.swt.widgets.Calendar.MONTH_NAMES[ this.getShownMonth() ];
483
      this._monthYearLabel.setText( month + ", " + year );
484
485
      // Show the day names
486
      var firstDayOfWeek = helpDate.getDay();
487
      var firstSundayInMonth = (1 + 7 - firstDayOfWeek) % 7;
488
      
489
      for (var i=0; i<7; i++) {
490
        var day = (i + startOfWeek) % 7;
491
492
        var dayLabel = this._weekdayLabelArr[i];
493
494
        helpDate.setDate(firstSundayInMonth + day);
495
        
496
        var weekdayName = org.eclipse.swt.widgets.Calendar.WEEKDAY_NAMES[ helpDate.getDay() + 1 ];
497
        weekdayName = weekdayName.substring( 0, 3 );
498
        
499
        dayLabel.setText( weekdayName );
500
501
        if (this.__isWeekend(day)) {
502
          dayLabel.addState("weekend");
503
        } else {
504
          dayLabel.removeState("weekend");
505
        }
506
      }
507
508
      // Show the days
509
      helpDate = new Date(shownYear, shownMonth, 1);
510
      var nrDaysOfLastMonth = (7 + firstDayOfWeek - startOfWeek) % 7;
511
      helpDate.setDate(helpDate.getDate() - nrDaysOfLastMonth);
512
513
      for (var week=0; week<6; week++) {
514
        for (var i=0; i<7; i++) {
515
          var dayLabel = this._dayLabelArr[week * 7 + i];
516
517
          var year = helpDate.getFullYear();
518
          var month = helpDate.getMonth();
519
          var dayOfMonth = helpDate.getDate();
520
521
          var isSelectedDate = (selYear == year && selMonth == month && selDayOfMonth == dayOfMonth);
522
523
          if (isSelectedDate) {
524
            dayLabel.addState("selected");
525
          } else {
526
            dayLabel.removeState("selected");
527
          }
528
529
          if (month != shownMonth) {
530
            dayLabel.addState("otherMonth");
531
          } else {
532
            dayLabel.removeState("otherMonth");
533
          }
534
535
          var isToday = (year == todayYear && month == todayMonth && dayOfMonth == todayDayOfMonth);
536
537
          if (isToday) {
538
            dayLabel.addState("today");
539
          } else {
540
            dayLabel.removeState("today");
541
          }
542
543
          dayLabel.setText("" + dayOfMonth);
544
          dayLabel.dateTime = helpDate.getTime();
545
546
          // Go to the next day
547
          helpDate.setDate(helpDate.getDate() + 1);
548
        }
549
      }
550
    }, 
551
    
552
    /**
553
     * Return the day the week starts with
554
     *
555
     * Reference: Common Locale Data Repository (cldr) supplementalData.xml
556
     *
557
     * @type member
558
     * @param locale {String} optional locale to be used
559
     * @return {Integer} index of the first day of the week. 0=sunday, 1=monday, ...
560
     */
561
    __getWeekStart : function(locale) {
562
      var weekStart = {
563
        // default is monday
564
        "MV" : 5, // friday
565
        "AE" : 6, // saturday
566
        "AF" : 6,
567
        "BH" : 6,
568
        "DJ" : 6,
569
        "DZ" : 6,
570
        "EG" : 6,
571
        "ER" : 6,
572
        "ET" : 6,
573
        "IQ" : 6,
574
        "IR" : 6,
575
        "JO" : 6,
576
        "KE" : 6,
577
        "KW" : 6,
578
        "LB" : 6,
579
        "LY" : 6,
580
        "MA" : 6,
581
        "OM" : 6,
582
        "QA" : 6,
583
        "SA" : 6,
584
        "SD" : 6,
585
        "SO" : 6,
586
        "TN" : 6,
587
        "YE" : 6,
588
        "AS" : 0, // sunday
589
        "AU" : 0,
590
        "AZ" : 0,
591
        "BW" : 0,
592
        "CA" : 0,
593
        "CN" : 0,
594
        "FO" : 0,
595
        "GE" : 0,
596
        "GL" : 0,
597
        "GU" : 0,
598
        "HK" : 0,
599
        "IE" : 0,
600
        "IL" : 0,
601
        "IS" : 0,
602
        "JM" : 0,
603
        "JP" : 0,
604
        "KG" : 0,
605
        "KR" : 0,
606
        "LA" : 0,
607
        "MH" : 0,
608
        "MN" : 0,
609
        "MO" : 0,
610
        "MP" : 0,
611
        "MT" : 0,
612
        "NZ" : 0,
613
        "PH" : 0,
614
        "PK" : 0,
615
        "SG" : 0,
616
        "TH" : 0,
617
        "TT" : 0,
618
        "TW" : 0,
619
        "UM" : 0,
620
        "US" : 0,
621
        "UZ" : 0,
622
        "VI" : 0,
623
        "ZA" : 0,
624
        "ZW" : 0,
625
        "MW" : 0,
626
        "NG" : 0,
627
        "TJ" : 0
628
      };
629
630
      var territory = this.__getTerritory(locale);
631
632
      // default is monday
633
      return weekStart[territory] != null ? weekStart[territory] : 1;
634
    },
635
    
636
    /**
637
     * Return the day the weekend starts with
638
     *
639
     * Reference: Common Locale Data Repository (cldr) supplementalData.xml
640
     *
641
     * @type member
642
     * @param locale {String} optional locale to be used
643
     * @return {Integer} index of the first day of the weekend. 0=sunday, 1=monday, ...
644
     */
645
    __getWeekendStart : function(locale) {
646
      var weekendStart = {
647
        // default is saturday
648
        "EG" : 5, // friday
649
        "IL" : 5,
650
        "SY" : 5,
651
        "IN" : 0, // sunday
652
        "AE" : 4, // thursday
653
        "BH" : 4,
654
        "DZ" : 4,
655
        "IQ" : 4,
656
        "JO" : 4,
657
        "KW" : 4,
658
        "LB" : 4,
659
        "LY" : 4,
660
        "MA" : 4,
661
        "OM" : 4,
662
        "QA" : 4,
663
        "SA" : 4,
664
        "SD" : 4,
665
        "TN" : 4,
666
        "YE" : 4
667
      };
668
669
      var territory = this.__getTerritory(locale);
670
671
      // default is saturday
672
      return weekendStart[territory] != null ? weekendStart[territory] : 6;
673
    },
674
675
    /**
676
     * Return the day the weekend ends with
677
     *
678
     * Reference: Common Locale Data Repository (cldr) supplementalData.xml
679
     *
680
     * @type member
681
     * @param locale {String} optional locale to be used
682
     * @return {Integer} index of the last day of the weekend. 0=sunday, 1=monday, ...
683
     */
684
    __getWeekendEnd : function(locale) {
685
      var weekendEnd = {
686
        // default is sunday
687
        "AE" : 5, // friday
688
        "BH" : 5,
689
        "DZ" : 5,
690
        "IQ" : 5,
691
        "JO" : 5,
692
        "KW" : 5,
693
        "LB" : 5,
694
        "LY" : 5,
695
        "MA" : 5,
696
        "OM" : 5,
697
        "QA" : 5,
698
        "SA" : 5,
699
        "SD" : 5,
700
        "TN" : 5,
701
        "YE" : 5,
702
        "AF" : 5,
703
        "IR" : 5,
704
        "EG" : 6, // saturday
705
        "IL" : 6,
706
        "SY" : 6
707
      };
708
709
      var territory = this.__getTerritory(locale);
710
711
      // default is sunday
712
      return weekendEnd[territory] != null ? weekendEnd[territory] : 0;
713
    },
714
715
    /**
716
     * Returns whether a certain day of week belongs to the week end.
717
     *
718
     * @type member
719
     * @param day {Integer} index of the day. 0=sunday, 1=monday, ...
720
     * @param locale {String} optional locale to be used
721
     * @return {Boolean} whether the given day is a weekend day
722
     */
723
    __isWeekend : function(day, locale) {
724
      var weekendStart = this.__getWeekendStart(locale);
725
      var weekendEnd = this.__getWeekendEnd(locale);
726
727
      if (weekendEnd > weekendStart) {
728
        return ((day >= weekendStart) && (day <= weekendEnd));
729
      } else {
730
        return ((day >= weekendStart) || (day <= weekendEnd));
731
      }
732
    },
733
    
734
    /**
735
     * Extract the territory part from a locale
736
     *
737
     * @type member
738
     * @param locale {String} the locale
739
     * @return {String} territory
740
     */
741
    __getTerritory : function(locale) {
742
      if (locale) {
743
        var territory = locale.split("_")[1] || locale;
744
      } else {
745
        territory = qx.locale.Manager.getInstance().getTerritory() || qx.locale.Manager.getInstance().getLanguage();
746
      }
747
748
      return territory.toUpperCase();
749
    }
750
  },
751
752
  /*
753
  *****************************************************************************
754
     DESTRUCTOR
755
  *****************************************************************************
756
  */
757
758
  destruct : function() {
759
    qx.locale.Manager.getInstance().removeEventListener("changeLocale", this._updateDatePane, this);
760
761
    this._disposeObjects("_lastMonthBt", "_nextMonthBt", "_monthYearLabel");
762
763
    this._disposeObjectDeep("_weekdayLabelArr", 1);
764
    this._disposeObjectDeep("_dayLabelArr", 1);    
765
  }
766
});
(-)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
}
(-)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! Selected date: "
76
            + dateTime1.getDay() 
77
            + "/" + ( dateTime1.getMonth() + 1 )
78
            + "/" + dateTime1.getYear()
79
            + " " + dateTime1.getHours()
80
            + ":" + dateTime1.getMinutes()
81
            + ":" + dateTime1.getSeconds();          
82
          log( message );
83
        }
84
85
        public void widgetDefaultSelected( final SelectionEvent event ) {
86
          String message = "DateTime WidgetDefaultSelected!";          
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
}

Return to bug 183177