Source code: echopoint/ClientDatePicker.java
1 package echopoint;
2 /*
3 * This file is part of the Echo Point Project. This project is a collection
4 * of Components that have extended the Echo Web Application Framework.
5 *
6 * EchoPoint is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * EchoPoint is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with Echo Point; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 import java.lang.reflect.Field;
22 import java.text.SimpleDateFormat;
23 import java.util.Calendar;
24 import java.util.Locale;
25
26 import nextapp.echo.Color;
27 import nextapp.echo.Font;
28 import nextapp.echo.ImageReference;
29 import nextapp.echo.ResourceImageReference;
30 import nextapp.echo.Style;
31
32 import echopoint.ui.resource.ResourceNames;
33 import echopoint.util.reflect.ReflectionSetter;
34 import echopoint.util.throwable.ThrowableKit;
35
36 /**
37 * A <code>ClientDatePicker</code> allows the user to select a date
38 * without requiring a trip back to the server. The formatted date
39 * is placed into the content of the TextField.
40 * <br/>
41 *
42 * <h4>Styles overview:</h4><br/>
43 * The Calendar's colors (background and foreground) are broken out into the following:
44 * <ul>
45 * <li>DayColumnHeader: The "S M T W Th F S" header section
46 * <li>CurrentMonthDate: A Date that is within the currently selected month
47 * <li>OtherMonthDate: A Date that is in the month before or after the currently selected month
48 * <li>CurrentDate: The currently selected date
49 * <li>TodayText: The text at the bottom of the calendar to select today's date
50 * <li>YearNavigation: The year selector
51 * <li>MonthNavigation: The month selector
52 * <li>TopLine: horizontal rule at the top of the calendar
53 * <li>BottomLine: horizontal rule at the bottom of the calendar
54 * <li>CurrentDateBorder: The border around the currently selected date
55 * <li>CurrentMonthDateRollover: Mouseover color for CurrentMonthDate
56 * <li>OtherMonthDateRollover: Mouseover color for OtherMonthDate
57 * <li>CurrentDateRollover: Mouseover color for CurrentDate
58 * </ul>
59 * <br/>
60 * <h4/>Other Style properties of interest</h4>
61 * <ul>
62 * <li>OffsetX / OffsetY : Relative positioning. This will accept negative numbers
63 * <li>CalendarFont : Global calendar font.
64 * <li>Icon : An optional image that may be used as the popup control
65 * <li>ButtonText: The text to display on the button used as the popup control (set to null or "" to disable)
66 * </ul>
67 * <br/>
68 *
69 * <h4>Date Format Strings</h4><br/>
70 * The <code>ClientDatePicker</code> uses the following date format strings :
71 * <blockquote><pre>
72 * Field | Full Form | Short Form
73 * -------------+--------------------+-----------------------
74 * Year | yyyy (4 digits) | yy (2 digits), y (2 or 4 digits)
75 * Month | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
76 * | NNN (abbr.) |
77 * Day of Month | dd (2 digits) | d (1 or 2 digits)
78 * Day of Week | EE (name) | E (abbr)
79 * Hour (1-12) | hh (2 digits) | h (1 or 2 digits)
80 * Hour (0-23) | HH (2 digits) | H (1 or 2 digits)
81 * Hour (0-11) | KK (2 digits) | K (1 or 2 digits)
82 * Hour (1-24) | kk (2 digits) | k (1 or 2 digits)
83 * Minute | mm (2 digits) | m (1 or 2 digits)
84 * Second | ss (2 digits) | s (1 or 2 digits)
85 * AM/PM | a |
86 * </pre></blockquote>
87 * <br/>
88 * NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm!<br/>
89 * Examples:<br/>
90 * "MMM d, y" matches: January 01, 2000<br/>
91 * Dec 1, 1900<br/>
92 * Nov 20, 00<br/>
93 * "M/d/yy" matches: 01/20/00<br/>
94 * 9/2/00<br/>
95 * "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"<br/>
96 * <br/>
97 *
98 * @author Jason Dalton (jdalton@asset.com) and Chris Bozic (cbozic@asset.com)
99 */
100 public class ClientDatePicker extends TextField implements ReflectionSetter {
101
102 public static final String INVALID_COLOR_PROPERTY = "invalidColor";
103 public static final String BOTTOM_LINE_FOREGROUND_PROPERTY = "bottomLineForeground";
104 public static final String TOP_LINE_FOREGROUND_PROPERTY = "topLineForeground";
105 public static final String TODAY_TEXT_FOREGROUND_PROPERTY = "todayTextForeground";
106 public static final String TODAY_TEXT_BACKGROUND_PROPERTY = "todayTextBackground";
107 public static final String OTHER_MONTH_DATE_FOREGROUND_PROPERTY = "otherMonthDateForeground";
108 public static final String OTHER_MONTH_DATE_BACKGROUND_PROPERTY = "otherMonthDateBackground";
109 public static final String DAY_COLUMN_HEADER_FOREGROUND_PROPERTY = "dayColumnHeaderForeground";
110 public static final String DAY_COLUMN_HEADER_BACKGROUND_PROPERTY = "dayColumnHeaderBackground";
111 public static final String CURRENT_MONTH_DATE_FOREGROUND_PROPERTY = "currentMonthDateForeground";
112 public static final String CURRENT_MONTH_DATE_BACKGROUND_PROPERTY = "currentMonthDateBackground";
113 public static final String CURRENT_DATE_FOREGROUND_PROPERTY = "currentDateForeground";
114 public static final String CURRENT_DATE_BACKGROUND_PROPERTY = "currentDateBackground";
115 public static final String CALENDAR_FONT_PROPERTY = "calendarFont";
116 public static final String YEAR_NAVIGATION_FOREGROUND_PROPERTY = "yearNavigationForeground";
117 public static final String YEAR_NAVIGATION_BACKGROUND_PROPERTY = "yearNavigationBackground";
118 public static final String MONTH_NAVIGATION_FOREGROUND_PROPERTY = "monthNavigationForeground";
119 public static final String MONTH_NAVIGATION_BACKGROUND_PROPERTY = "monthNavigationBackground";
120 public static final String CURRENT_DATE_BORDER_FOREGROUND_PROPERTY = "currentDateBorderForeground";
121 public static final String OTHER_MONTH_DATE_ROLLOVER_FOREGROUND_PROPERTY = "otherMonthDateRolloverForeground";
122 public static final String OTHER_MONTH_DATE_ROLLOVER_BACKGROUND_PROPERTY = "otherMonthDateRolloverBackground";
123 public static final String CURRENT_MONTH_DATE_ROLLOVER_FOREGROUND_PROPERTY = "currentMonthDateRolloverForeground";
124 public static final String CURRENT_MONTH_DATE_ROLLOVER_BACKGROUND_PROPERTY = "currentMonthDateRolloverBackground";
125 public static final String CURRENT_DATE_ROLLOVER_FOREGROUND_PROPERTY = "currentDateRolloverForeground";
126 public static final String CURRENT_DATE_ROLLOVER_BACKGROUND_PROPERTY = "currentDateRolloverBackground";
127 public static final String NAVIGATION_ROLLOVER_FOREGROUND_PROPERTY = "navigationRolloverForeground";
128 public static final String NAVIGATION_ROLLOVER_BACKGROUND_PROPERTY = "navigationRolloverBackground";
129 public static final String ICON_PROPERTY = "icon";
130 public static final String BUTTON_TEXT_PROPERTY = "buttonText";
131 public static final String BUTTON_RENDERING_PROPERTY = "buttonRendering";
132
133 public static final String DATE_FORMAT_PROPERTY = "dateFormat";
134 public static final String OFFSET_Y_PROPERTY = "offsetY";
135 public static final String OFFSET_X_PROPERTY = "offsetX";
136 public static final String LOCALE_PROPERTY = "locale";
137
138 public static final String STYLE_INVALID_COLOR = INVALID_COLOR_PROPERTY;
139 public static final String STYLE_BOTTOM_LINE_FOREGROUND = BOTTOM_LINE_FOREGROUND_PROPERTY;
140 public static final String STYLE_TOP_LINE_FOREGROUND = TOP_LINE_FOREGROUND_PROPERTY;
141 public static final String STYLE_TODAY_TEXT_FOREGROUND = TODAY_TEXT_FOREGROUND_PROPERTY;
142 public static final String STYLE_TODAY_TEXT_BACKGROUND = TODAY_TEXT_BACKGROUND_PROPERTY;
143 public static final String STYLE_OTHER_MONTH_DATE_FOREGROUND = OTHER_MONTH_DATE_FOREGROUND_PROPERTY;
144 public static final String STYLE_OTHER_MONTH_DATE_BACKGROUND = OTHER_MONTH_DATE_BACKGROUND_PROPERTY;
145 public static final String STYLE_DAY_COLUMN_HEADER_FOREGROUND = DAY_COLUMN_HEADER_FOREGROUND_PROPERTY;
146 public static final String STYLE_DAY_COLUMN_HEADER_BACKGROUND = DAY_COLUMN_HEADER_BACKGROUND_PROPERTY;
147 public static final String STYLE_CURRENT_MONTH_DATE_FOREGROUND = CURRENT_MONTH_DATE_FOREGROUND_PROPERTY;
148 public static final String STYLE_CURRENT_MONTH_DATE_BACKGROUND = CURRENT_MONTH_DATE_BACKGROUND_PROPERTY;
149 public static final String STYLE_CURRENT_DATE_FOREGROUND = CURRENT_DATE_FOREGROUND_PROPERTY;
150 public static final String STYLE_CURRENT_DATE_BACKGROUND = CURRENT_DATE_BACKGROUND_PROPERTY;
151 public static final String STYLE_CALENDAR_FONT = CALENDAR_FONT_PROPERTY;
152 public static final String STYLE_YEAR_NAVIGATION_FOREGROUND = YEAR_NAVIGATION_FOREGROUND_PROPERTY;
153 public static final String STYLE_YEAR_NAVIGATION_BACKGROUND = YEAR_NAVIGATION_BACKGROUND_PROPERTY;
154 public static final String STYLE_MONTH_NAVIGATION_FOREGROUND = MONTH_NAVIGATION_FOREGROUND_PROPERTY;
155 public static final String STYLE_MONTH_NAVIGATION_BACKGROUND = MONTH_NAVIGATION_BACKGROUND_PROPERTY;
156 public static final String STYLE_CURRENT_DATE_BORDER_FOREGROUND = CURRENT_DATE_BORDER_FOREGROUND_PROPERTY;
157 public static final String STYLE_OTHER_MONTH_DATE_ROLLOVER_FOREGROUND = OTHER_MONTH_DATE_ROLLOVER_FOREGROUND_PROPERTY;
158 public static final String STYLE_OTHER_MONTH_DATE_ROLLOVER_BACKGROUND = OTHER_MONTH_DATE_ROLLOVER_BACKGROUND_PROPERTY;
159 public static final String STYLE_CURRENT_MONTH_DATE_ROLLOVER_FOREGROUND = CURRENT_MONTH_DATE_ROLLOVER_FOREGROUND_PROPERTY;
160 public static final String STYLE_CURRENT_MONTH_DATE_ROLLOVER_BACKGROUND = CURRENT_MONTH_DATE_ROLLOVER_BACKGROUND_PROPERTY;
161 public static final String STYLE_CURRENT_DATE_ROLLOVER_FOREGROUND = CURRENT_DATE_ROLLOVER_FOREGROUND_PROPERTY;
162 public static final String STYLE_CURRENT_DATE_ROLLOVER_BACKGROUND = CURRENT_DATE_ROLLOVER_BACKGROUND_PROPERTY;
163 public static final String STYLE_NAVIGATION_ROLLOVER_FOREGROUND = NAVIGATION_ROLLOVER_FOREGROUND_PROPERTY;
164 public static final String STYLE_NAVIGATION_ROLLOVER_BACKGROUND = NAVIGATION_ROLLOVER_BACKGROUND_PROPERTY;
165 public static final String STYLE_ICON = ICON_PROPERTY;
166 public static final String STYLE_BUTTON_TEXT = BUTTON_TEXT_PROPERTY;
167 public static final String STYLE_BUTTON_RENDERING = BUTTON_RENDERING_PROPERTY;
168
169 /** the default icon used */
170 public static final ImageReference DEFAULT_ICON;
171 static {
172 DEFAULT_ICON = new ResourceImageReference(ResourceNames.CLIENT_CALENDAR_ICON,12,10);
173 }
174
175 private static final int DEFAULT_COLUMNS = 12;
176 private static final String DEFAULT_DATE_FORMAT = "MM/dd/yyyy";
177
178 private SimpleDateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT);
179
180 private int offsetX = 0;
181 private int offsetY = 0;
182
183 private Color dayColumnHeaderForeground = Color.BLACK;
184 private Color dayColumnHeaderBackground = Color.WHITE;
185 private Color currentMonthDateForeground = Color.BLACK;
186 private Color currentMonthDateBackground = Color.WHITE;
187 private Color otherMonthDateForeground = Color.DARKGRAY;
188 private Color otherMonthDateBackground = Color.WHITE;
189 private Color currentDateForeground = Color.BLACK;
190 private Color currentDateBackground = Color.LIGHTGRAY;
191 private Color todayTextForeground = Color.BLACK;
192 private Color todayTextBackground = Color.WHITE;
193 private Color yearNavigationForeground = Color.BLACK;
194 private Color yearNavigationBackground = Color.LIGHTGRAY;
195 private Color monthNavigationForeground = Color.BLACK;
196 private Color monthNavigationBackground = Color.LIGHTGRAY;
197 private Color topLineForeground = Color.LIGHTGRAY;
198 private Color bottomLineForeground = Color.LIGHTGRAY;
199 private Color currentDateBorderForeground = Color.BLACK;
200 private Color currentMonthDateRolloverForeground = Color.LIGHTGRAY;
201 private Color currentMonthDateRolloverBackground = Color.WHITE;
202 private Color otherMonthDateRolloverForeground = Color.LIGHTGRAY;
203 private Color otherMonthDateRolloverBackground = Color.WHITE;
204 private Color currentDateRolloverForeground = Color.WHITE;
205 private Color currentDateRolloverBackground = Color.LIGHTGRAY;
206 private Color navigationRolloverForeground = Color.WHITE;
207 private Color navigationRolloverBackground = Color.LIGHTGRAY;
208 private Color invalidColor = Color.RED;
209
210 private Locale locale = Locale.getDefault();
211
212 private Font calendarFont = new Font(Font.ARIAL,Font.PLAIN,8);
213
214 private ImageReference icon = DEFAULT_ICON;
215 private String buttonText = "";
216
217 private boolean buttonRendering = true;
218
219 /**
220 * Creates a default <code>ClientDatePicker</code>
221 */
222 public ClientDatePicker() {
223 this(DEFAULT_COLUMNS);
224 }
225
226 /**
227 * Creates a <code>ClientDatePicker</code> that is <i>columns</i> wide.
228 */
229 public ClientDatePicker(int columns) {
230 this((Calendar)null, columns);
231 }
232
233 /**
234 * Creates a <code>ClientDatePicker</code> with <code>number</code> as the initial
235 * Date value.
236 *
237 */
238 public ClientDatePicker(Calendar date) {
239 this(date, DEFAULT_COLUMNS);
240 }
241
242 /**
243 * Creates a <code>ClientDatePicker</code> with <code>number</code> as the initial
244 * value and a given column size.
245 *
246 */
247 public ClientDatePicker(Calendar date, int columns) {
248 super(columns);
249 setSelectedDate(date);
250 }
251
252 /**
253 * Creates a <code>ClientDatePicker</code> with <code>text</code> as the initial
254 * value.
255 *
256 */
257 public ClientDatePicker(String text) {
258 this(text, DEFAULT_COLUMNS);
259 }
260
261 /**
262 * Creates a <code>ClientDatePicker</code> with <code>text</code> as the initial
263 * value and that is <code>columns</code> wide.
264 *
265 */
266 public ClientDatePicker(String text, int columns) {
267 super(text, columns);
268 }
269
270 /**
271 *
272 */
273 public Color getNavigationRolloverBackground() {
274 return navigationRolloverBackground;
275 }
276
277 /**
278 * @param navigationRolloverBackground
279 */
280 public void setNavigationRolloverBackground(Color navigationRolloverBackground) {
281 set(ClientDatePicker.class, NAVIGATION_ROLLOVER_BACKGROUND_PROPERTY, navigationRolloverBackground);
282 }
283
284 /**
285 *
286 */
287 public Color getNavigationRolloverForeground() {
288 return navigationRolloverForeground;
289 }
290
291 /**
292 * @param navigationRolloverForeground
293 */
294 public void setNavigationRolloverForeground(Color navigationRolloverForeground) {
295 set(ClientDatePicker.class, NAVIGATION_ROLLOVER_FOREGROUND_PROPERTY, navigationRolloverForeground);
296 }
297
298 /**
299 *
300 */
301 public String getButtonText() {
302 return buttonText;
303 }
304
305 /**
306 * @param buttonText
307 */
308 public void setButtonText(String buttonText) {
309 set(ClientDatePicker.class, BUTTON_TEXT_PROPERTY, buttonText);
310 }
311
312 /**
313 *
314 */
315 public ImageReference getIcon() {
316 return icon;
317 }
318
319 /**
320 * @param icon
321 */
322 public void setIcon(ImageReference icon) {
323 set(ClientDatePicker.class, ICON_PROPERTY, icon);
324 }
325
326 /**
327 *
328 */
329 public int getOffsetX() {
330 return offsetX;
331 }
332
333 /**
334 * @param offsetX
335 */
336 public void setOffsetX(int offsetX) {
337 set(ClientDatePicker.class, OFFSET_X_PROPERTY, new Integer(offsetX));
338 }
339
340 /**
341 *
342 */
343 public int getOffsetY() {
344 return offsetY;
345 }
346
347 /**
348 * @param offsetY
349 */
350 public void setOffsetY(int offsetY) {
351 set(ClientDatePicker.class, OFFSET_Y_PROPERTY, new Integer(offsetY));
352 }
353
354
355 /**
356 *
357 */
358 public Color getCurrentDateRolloverBackground() {
359 return currentDateRolloverBackground;
360 }
361
362 /**
363 * @param currentDateRolloverBackground
364 */
365 public void setCurrentDateRolloverBackground(Color currentDateRolloverBackground) {
366 set(ClientDatePicker.class, CURRENT_DATE_ROLLOVER_BACKGROUND_PROPERTY, currentDateRolloverBackground);
367 }
368
369 /**
370 *
371 */
372 public Color getCurrentDateRolloverForeground() {
373 return currentDateRolloverForeground;
374 }
375
376 /**
377 * @param currentDateRolloverForeground
378 */
379 public void setCurrentDateRolloverForeground(Color currentDateRolloverForeground) {
380 set(ClientDatePicker.class, CURRENT_DATE_ROLLOVER_FOREGROUND_PROPERTY, currentDateRolloverForeground);
381 }
382
383 /**
384 *
385 */
386 public Color getCurrentMonthDateRolloverBackground() {
387 return currentMonthDateRolloverBackground;
388 }
389
390 /**
391 * @param currentMonthDateRolloverBackground
392 */
393 public void setCurrentMonthDateRolloverBackground(Color currentMonthDateRolloverBackground) {
394 set(ClientDatePicker.class, CURRENT_MONTH_DATE_ROLLOVER_BACKGROUND_PROPERTY, currentMonthDateRolloverBackground);
395 }
396
397 /**
398 *
399 */
400 public Color getCurrentMonthDateRolloverForeground() {
401 return currentMonthDateRolloverForeground;
402 }
403
404 /**
405 * @param currentMonthDateRolloverForeground
406 */
407 public void setCurrentMonthDateRolloverForeground(Color currentMonthDateRolloverForeground) {
408 set(ClientDatePicker.class, CURRENT_MONTH_DATE_ROLLOVER_FOREGROUND_PROPERTY, currentMonthDateRolloverForeground);
409 }
410
411 /**
412 *
413 */
414 public Color getOtherMonthDateRolloverBackground() {
415 return otherMonthDateRolloverBackground;
416 }
417
418 /**
419 * @param otherMonthDateRolloverBackground
420 */
421 public void setOtherMonthDateRolloverBackground(Color otherMonthDateRolloverBackground) {
422 set(ClientDatePicker.class, OTHER_MONTH_DATE_ROLLOVER_BACKGROUND_PROPERTY, otherMonthDateRolloverBackground);
423 }
424
425 /**
426 *
427 */
428 public Color getOtherMonthDateRolloverForeground() {
429 return otherMonthDateRolloverForeground;
430 }
431
432 /**
433 * @param otherMonthDateRolloverForeground
434 */
435 public void setOtherMonthDateRolloverForeground(Color otherMonthDateRolloverForeground) {
436 set(ClientDatePicker.class, OTHER_MONTH_DATE_ROLLOVER_FOREGROUND_PROPERTY, otherMonthDateRolloverForeground);
437 }
438
439 /**
440 *
441 */
442 public Color getCurrentDateBorderForeground() {
443 return currentDateBorderForeground;
444 }
445
446 /**
447 * @param currentDateBorderForeground
448 */
449 public void setCurrentDateBorderForeground(Color currentDateBorderForeground) {
450 set(ClientDatePicker.class, CURRENT_DATE_BORDER_FOREGROUND_PROPERTY, currentDateBorderForeground);
451 }
452
453 /**
454 *
455 */
456 public Color getMonthNavigationBackground() {
457 return monthNavigationBackground;
458 }
459
460 /**
461 * @param monthNavigationBackground
462 */
463 public void setMonthNavigationBackground(Color monthNavigationBackground) {
464 set(ClientDatePicker.class, MONTH_NAVIGATION_BACKGROUND_PROPERTY, monthNavigationBackground);
465 }
466
467 /**
468 *
469 */
470 public Color getMonthNavigationForeground() {
471 return monthNavigationForeground;
472 }
473
474 /**
475 * @param monthNavigationForeground
476 */
477 public void setMonthNavigationForeground(Color monthNavigationForeground) {
478 set(ClientDatePicker.class, MONTH_NAVIGATION_FOREGROUND_PROPERTY, monthNavigationForeground);
479 }
480
481 /**
482 *
483 */
484 public Color getYearNavigationBackground() {
485 return yearNavigationBackground;
486 }
487
488 /**
489 * @param yearNavigationBackground
490 */
491 public void setYearNavigationBackground(Color yearNavigationBackground) {
492 set(ClientDatePicker.class, YEAR_NAVIGATION_BACKGROUND_PROPERTY, yearNavigationBackground);
493 }
494
495 /**
496 *
497 */
498 public Color getYearNavigationForeground() {
499 return yearNavigationForeground;
500 }
501
502 /**
503 * @param yearNavigationForeground
504 */
505 public void setYearNavigationForeground(Color yearNavigationForeground) {
506 set(ClientDatePicker.class, YEAR_NAVIGATION_FOREGROUND_PROPERTY, yearNavigationForeground);
507 }
508
509 /**
510 *
511 */
512 public Font getCalendarFont() {
513 return calendarFont;
514 }
515
516 /**
517 *
518 */
519 public void setCalendarFont(Font calendarFont) {
520 set(ClientDatePicker.class, CALENDAR_FONT_PROPERTY, calendarFont);
521 }
522
523 /**
524 *
525 */
526 public Color getCurrentDateBackground() {
527 return currentDateBackground;
528 }
529
530 /**
531 *
532 */
533 public void setCurrentDateBackground(Color currentDateBackground) {
534 set(ClientDatePicker.class, CURRENT_DATE_BACKGROUND_PROPERTY, currentDateBackground);
535 }
536
537 /**
538 *
539 */
540 public Color getCurrentDateForeground() {
541 return currentDateForeground;
542 }
543
544 /**
545 * @param currentDateForeground
546 */
547 public void setCurrentDateForeground(Color currentDateForeground) {
548 set(ClientDatePicker.class, CURRENT_DATE_FOREGROUND_PROPERTY, currentDateForeground);
549 }
550
551 /**
552 *
553 */
554 public Color getCurrentMonthDateBackground() {
555 return currentMonthDateBackground;
556 }
557
558 /**
559 * @param currentMonthDateBackground
560 */
561 public void setCurrentMonthDateBackground(Color currentMonthDateBackground) {
562 set(ClientDatePicker.class, CURRENT_MONTH_DATE_BACKGROUND_PROPERTY, currentMonthDateBackground);
563 }
564
565 /**
566 *
567 */
568 public Color getCurrentMonthDateForeground() {
569 return currentMonthDateForeground;
570 }
571
572 /**
573 * @param currentMonthDateForeground
574 */
575 public void setCurrentMonthDateForeground(Color currentMonthDateForeground) {
576 set(ClientDatePicker.class, CURRENT_MONTH_DATE_FOREGROUND_PROPERTY, currentMonthDateForeground);
577 }
578
579 /**
580 *
581 */
582 public Color getDayColumnHeaderBackground() {
583 return dayColumnHeaderBackground;
584 }
585
586 /**
587 * @param dayColumnHeaderBackground
588 */
589 public void setDayColumnHeaderBackground(Color dayColumnHeaderBackground) {
590 set(ClientDatePicker.class, DAY_COLUMN_HEADER_BACKGROUND_PROPERTY, dayColumnHeaderBackground);
591 }
592
593 /**
594 *
595 */
596 public Color getDayColumnHeaderForeground() {
597 return dayColumnHeaderForeground;
598 }
599
600 /**
601 * @param dayColumnHeaderForeground
602 */
603 public void setDayColumnHeaderForeground(Color dayColumnHeaderForeground) {
604 set(ClientDatePicker.class, DAY_COLUMN_HEADER_FOREGROUND_PROPERTY, dayColumnHeaderForeground);
605 }
606
607
608
609 /**
610 *
611 */
612 public Color getOtherMonthDateBackground() {
613 return otherMonthDateBackground;
614 }
615
616 /**
617 * @param otherMonthDateBackground
618 */
619 public void setOtherMonthDateBackground(Color otherMonthDateBackground) {
620 set(ClientDatePicker.class, OTHER_MONTH_DATE_BACKGROUND_PROPERTY, otherMonthDateBackground);
621 }
622
623 /**
624 *
625 */
626 public Color getOtherMonthDateForeground() {
627 return otherMonthDateForeground;
628 }
629
630 /**
631 * @param otherMonthDateForeground
632 */
633 public void setOtherMonthDateForeground(Color otherMonthDateForeground) {
634 set(ClientDatePicker.class, OTHER_MONTH_DATE_FOREGROUND_PROPERTY, otherMonthDateForeground);
635 }
636
637 /**
638 *
639 */
640 public Color getTodayTextBackground() {
641 return todayTextBackground;
642 }
643
644 /**
645 * @param todayTextBackground
646 */
647 public void setTodayTextBackground(Color todayTextBackground) {
648 set(ClientDatePicker.class, TODAY_TEXT_BACKGROUND_PROPERTY, todayTextBackground);
649 }
650
651 /**
652 *
653 */
654 public Color getTodayTextForeground() {
655 return todayTextForeground;
656 }
657
658 /**
659 * @param todayTextForeground
660 */
661 public void setTodayTextForeground(Color todayTextForeground) {
662 set(ClientDatePicker.class, TODAY_TEXT_FOREGROUND_PROPERTY, todayTextForeground);
663 }
664
665 /**
666 *
667 */
668 public Color getTopLineForeground() {
669 return topLineForeground;
670 }
671
672 /**
673 * @param topLineForeground
674 */
675 public void setTopLineForeground(Color topLineForeground) {
676 set(ClientDatePicker.class, TOP_LINE_FOREGROUND_PROPERTY, topLineForeground);
677 }
678
679 /**
680 *
681 */
682 public Color getBottomLineForeground() {
683 return bottomLineForeground;
684 }
685
686 /**
687 * @param bottomLineForeground
688 */
689 public void setBottomLineForeground(Color bottomLineForeground) {
690 set(ClientDatePicker.class, BOTTOM_LINE_FOREGROUND_PROPERTY, bottomLineForeground);
691 }
692
693 public void setInvalidColor(Color invalidColor) {
694 set(ClientDatePicker.class, INVALID_COLOR_PROPERTY, invalidColor);
695 }
696
697 public Color getInvalidColor() {
698 return invalidColor;
699 }
700
701 /**
702 *
703 */
704 public Calendar getSelectedDate() {
705 return parse();
706 }
707
708 /**
709 * Returns a Date by parsing the current text. If it returns null
710 * then the current text is not a valid number.
711 */
712 private Calendar parse() {
713 String text = getText();
714
715 Calendar date = Calendar.getInstance(getLocale());
716 try {
717 date.setTime(dateFormat.parse(text));
718 } catch (Exception eat){
719 date = null;
720 }
721
722 //show or clear invalid color
723 update();
724 return date;
725 }
726
727 /**
728 * @param date
729 */
730 public void setSelectedDate(Calendar date) {
731 if (date != null)
732 super.setText(dateFormat.format(date.getTime()));
733 else
734 super.setText("");
735 }
736
737 /**
738 *
739 * Sets the format String for the date picker.
740 * See class documentation for more information on accepted date formats
741 *
742 * @param format
743 */
744 public void setDateFormat(SimpleDateFormat format){
745 if (format == null)
746 throw new IllegalArgumentException("DateFormat must not be null");
747
748 set(ClientDatePicker.class, DATE_FORMAT_PROPERTY, format);
749 }
750
751 public SimpleDateFormat getDateFormat(){
752 return dateFormat;
753 }
754
755 /**
756 * This method returns TRUE if the text of the ClientDatePicker can be parsed into a
757 * valid Date with the current DateFormat.
758 */
759 public boolean isValid() {
760 return parse() != null;
761 }
762
763 /**
764 * @see nextapp.echo.TextField#applyStyle(nextapp.echo.Style)
765 */
766 public void applyStyle(Style style) {
767 super.applyStyle(style);
768
769 if (style.hasAttribute(STYLE_BOTTOM_LINE_FOREGROUND))
770 setBottomLineForeground((Color) style.getAttribute(STYLE_BOTTOM_LINE_FOREGROUND));
771 if (style.hasAttribute(STYLE_CALENDAR_FONT))
772 setCalendarFont((Font) style.getAttribute(STYLE_CALENDAR_FONT));
773 if (style.hasAttribute(STYLE_CURRENT_DATE_BACKGROUND))
774 setCurrentDateBackground((Color) style.getAttribute(STYLE_CURRENT_DATE_BACKGROUND));
775 if (style.hasAttribute(STYLE_CURRENT_DATE_BORDER_FOREGROUND))
776 setCurrentDateBorderForeground((Color) style.getAttribute(STYLE_CURRENT_DATE_BORDER_FOREGROUND));
777 if (style.hasAttribute(STYLE_CURRENT_DATE_FOREGROUND))
778 setCurrentDateForeground((Color) style.getAttribute(STYLE_CURRENT_DATE_FOREGROUND));
779 if (style.hasAttribute(STYLE_CURRENT_DATE_ROLLOVER_BACKGROUND))
780 setCurrentDateRolloverBackground((Color) style.getAttribute(STYLE_CURRENT_DATE_ROLLOVER_BACKGROUND));
781 if (style.hasAttribute(STYLE_CURRENT_DATE_ROLLOVER_FOREGROUND))
782 setCurrentDateRolloverForeground((Color) style.getAttribute(STYLE_CURRENT_DATE_ROLLOVER_FOREGROUND));
783 if (style.hasAttribute(STYLE_CURRENT_MONTH_DATE_BACKGROUND))
784 setCurrentMonthDateBackground((Color) style.getAttribute(STYLE_CURRENT_MONTH_DATE_BACKGROUND));
785 if (style.hasAttribute(STYLE_CURRENT_MONTH_DATE_FOREGROUND))
786 setCurrentMonthDateForeground((Color) style.getAttribute(STYLE_CURRENT_MONTH_DATE_FOREGROUND));
787 if (style.hasAttribute(STYLE_CURRENT_MONTH_DATE_ROLLOVER_BACKGROUND))
788 setCurrentMonthDateRolloverBackground((Color) style.getAttribute(STYLE_CURRENT_MONTH_DATE_ROLLOVER_BACKGROUND));
789 if (style.hasAttribute(STYLE_CURRENT_MONTH_DATE_ROLLOVER_FOREGROUND))
790 setCurrentMonthDateRolloverForeground((Color) style.getAttribute(STYLE_CURRENT_MONTH_DATE_ROLLOVER_FOREGROUND));
791 if (style.hasAttribute(STYLE_DAY_COLUMN_HEADER_BACKGROUND))
792 setDayColumnHeaderBackground((Color) style.getAttribute(STYLE_DAY_COLUMN_HEADER_BACKGROUND));
793 if (style.hasAttribute(STYLE_DAY_COLUMN_HEADER_FOREGROUND))
794 setDayColumnHeaderForeground((Color) style.getAttribute(STYLE_DAY_COLUMN_HEADER_FOREGROUND));
795 if (style.hasAttribute(STYLE_INVALID_COLOR))
796 setInvalidColor((Color) style.getAttribute(STYLE_INVALID_COLOR));
797 if (style.hasAttribute(STYLE_MONTH_NAVIGATION_BACKGROUND))
798 setMonthNavigationBackground((Color) style.getAttribute(STYLE_MONTH_NAVIGATION_BACKGROUND));
799 if (style.hasAttribute(STYLE_MONTH_NAVIGATION_FOREGROUND))
800 setMonthNavigationForeground((Color) style.getAttribute(STYLE_MONTH_NAVIGATION_FOREGROUND));
801 if (style.hasAttribute(STYLE_NAVIGATION_ROLLOVER_BACKGROUND))
802 setNavigationRolloverBackground((Color) style.getAttribute(STYLE_NAVIGATION_ROLLOVER_BACKGROUND));
803 if (style.hasAttribute(STYLE_NAVIGATION_ROLLOVER_FOREGROUND))
804 setNavigationRolloverForeground((Color) style.getAttribute(STYLE_NAVIGATION_ROLLOVER_FOREGROUND));
805 if (style.hasAttribute(STYLE_OTHER_MONTH_DATE_BACKGROUND))
806 setOtherMonthDateBackground((Color) style.getAttribute(STYLE_OTHER_MONTH_DATE_BACKGROUND));
807 if (style.hasAttribute(STYLE_OTHER_MONTH_DATE_FOREGROUND))
808 setOtherMonthDateForeground((Color) style.getAttribute(STYLE_OTHER_MONTH_DATE_FOREGROUND));
809 if (style.hasAttribute(STYLE_OTHER_MONTH_DATE_ROLLOVER_BACKGROUND))
810 setOtherMonthDateRolloverBackground((Color) style.getAttribute(STYLE_OTHER_MONTH_DATE_ROLLOVER_BACKGROUND));
811 if (style.hasAttribute(STYLE_OTHER_MONTH_DATE_ROLLOVER_FOREGROUND))
812 setOtherMonthDateRolloverForeground((Color) style.getAttribute(STYLE_OTHER_MONTH_DATE_ROLLOVER_FOREGROUND));
813 if (style.hasAttribute(STYLE_TODAY_TEXT_BACKGROUND))
814 setTodayTextBackground((Color) style.getAttribute(STYLE_TODAY_TEXT_BACKGROUND));
815 if (style.hasAttribute(STYLE_TODAY_TEXT_FOREGROUND))
816 setTodayTextForeground((Color) style.getAttribute(STYLE_TODAY_TEXT_FOREGROUND));
817 if (style.hasAttribute(STYLE_TOP_LINE_FOREGROUND))
818 setTopLineForeground((Color) style.getAttribute(STYLE_TOP_LINE_FOREGROUND));
819 if (style.hasAttribute(STYLE_YEAR_NAVIGATION_BACKGROUND))
820 setYearNavigationBackground((Color) style.getAttribute(STYLE_YEAR_NAVIGATION_BACKGROUND));
821 if (style.hasAttribute(STYLE_YEAR_NAVIGATION_FOREGROUND))
822 setYearNavigationForeground((Color) style.getAttribute(STYLE_YEAR_NAVIGATION_FOREGROUND));
823 if (style.hasAttribute(STYLE_ICON))
824 setIcon((ImageReference) style.getAttribute(STYLE_ICON));
825 if (style.hasAttribute(STYLE_BUTTON_TEXT))
826 setButtonText((String) style.getAttribute(STYLE_BUTTON_TEXT));
827 if (style.hasAttribute(STYLE_BUTTON_RENDERING))
828 setButtonRendering( ((Boolean) style.getAttribute(STYLE_BUTTON_RENDERING)).booleanValue() );
829 }
830
831 public Locale getLocale() {
832 return this.locale;
833 }
834
835 public void setLocale(Locale locale) {
836 set(ClientDatePicker.class, LOCALE_PROPERTY, locale);
837 }
838
839 /**
840 *
841 */
842 public boolean isButtonRendering() {
843 return buttonRendering;
844 }
845
846 /**
847 * Setting this to false causes the button text and/or icon to be
848 * rendered as a plain button instead of a push button.
849 * Default: true
850 */
851 public void setButtonRendering(boolean buttonRendering) {
852 set(ClientDatePicker.class, BUTTON_RENDERING_PROPERTY, new Boolean(buttonRendering));
853 }
854
855 /**
856 * Sets a property and fires the corresponding property change event.
857 * This would be a handy method to have in Component. It could reduce a
858 * lot of code.
859 */
860 protected void set(Class clazz, String propertyName, Object arg) {
861 try {
862 Field property = clazz.getDeclaredField(propertyName);
863 Object oldValue = property.get(this);
864 property.set(this, arg);
865 this.firePropertyChange(propertyName, oldValue, arg);
866 } catch (Exception e) {
867 /*
868 * Since this method is only called internally, we can
869 * get away with throwing runtime exceptions. Any thrown from here will
870 * get caught during development time.
871 */
872 throw ThrowableKit.makeRuntimeException(e);
873 }
874 }
875
876 /** @see echopoint.util.ReflectionSetter#set(Field, Object) */
877 public Object set(java.lang.reflect.Field field, Object newValue) throws Exception {
878 Object oldValue = field.get(this); field.set(this,newValue); return oldValue;
879 }
880
881
882 }