01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //limitations under the License.
10: //
11: //The Original Code is "The Columba Project"
12: //
13: //The Initial Developers of the Original Code are Frederik Dietz and Timo
14: // Stich.
15: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16: //
17: //All Rights Reserved.
18: package org.columba.calendar.ui.comp;
19:
20: import java.awt.Dimension;
21: import java.text.DateFormat;
22: import java.util.Calendar;
23: import java.util.GregorianCalendar;
24:
25: import org.columba.calendar.model.api.IDateRange;
26: import org.columba.calendar.ui.navigation.DateAreaBeanFactory;
27:
28: import com.miginfocom.calendar.datearea.DateArea;
29: import com.miginfocom.util.dates.BoundaryRounder;
30: import com.miginfocom.util.dates.DateRangeI;
31: import com.miginfocom.util.dates.ImmutableDateRange;
32:
33: public class DatePicker extends com.miginfocom.calendar.DatePicker {
34:
35: private com.miginfocom.beans.DateAreaBean dateAreaBean;
36:
37: public DatePicker() {
38: super ();
39:
40: dateAreaBean = DateAreaBeanFactory.initDateArea();
41:
42: // enable selection
43: dateAreaBean.setSelectionType(DateArea.SELECTION_TYPE_NORMAL);
44:
45: Calendar today = Calendar.getInstance();
46: long startMillis = new GregorianCalendar(today
47: .get(java.util.Calendar.YEAR), 0, 0).getTimeInMillis();
48: long endMillis = new GregorianCalendar(today
49: .get(java.util.Calendar.YEAR), 12, 31)
50: .getTimeInMillis();
51: ImmutableDateRange dr = new ImmutableDateRange(startMillis,
52: endMillis, false, null, null);
53: dateAreaBean.getDateArea().setVisibleDateRange(dr);
54: dateAreaBean.setPreferredSize(new Dimension(200, 400));
55:
56: dateAreaBean
57: .setSelectionBoundaryType(DateRangeI.RANGE_TYPE_DAY);
58: dateAreaBean.getDateArea().setSelectionRounder(
59: new BoundaryRounder(DateRangeI.RANGE_TYPE_DAY, true,
60: true, false, 1, 1, null));
61: dateAreaBean.repaint();
62: setDateAreaContainer(dateAreaBean);
63:
64: setHomeButtonVisible(true);
65: setLeftRightButtonsVisible(true);
66: setDefaultDateStyle(DateFormat.DEFAULT);
67: setHideEndDate(true);
68:
69: setDate(Calendar.getInstance());
70: }
71:
72: public void setDate(Calendar date) {
73: ImmutableDateRange dr = new ImmutableDateRange(date
74: .getTimeInMillis(), date.getTimeInMillis(), false,
75: null, null);
76:
77: setSelectedRange(dr);
78: }
79:
80: public Calendar getDate() {
81: DateRangeI range = getSelectedRange();
82:
83: return range.getStart();
84: }
85:
86: public void setSelectedColumbaDateRange(IDateRange range) {
87: ImmutableDateRange dr = new ImmutableDateRange(range
88: .getStartTime().getTimeInMillis(), range.getEndTime()
89: .getTimeInMillis(), true, null, null);
90:
91: setSelectedRange(dr);
92: }
93:
94: }
|