KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > calendar > ui > comp > DatePicker


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//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 JavaDoc;
21 import java.text.DateFormat JavaDoc;
22 import java.util.Calendar JavaDoc;
23 import java.util.GregorianCalendar JavaDoc;
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 JavaDoc today = Calendar.getInstance();
46         long startMillis = new GregorianCalendar JavaDoc(today.get(java.util.Calendar.YEAR), 0, 0).getTimeInMillis();
47         long endMillis = new GregorianCalendar JavaDoc(today.get(java.util.Calendar.YEAR), 12, 31).getTimeInMillis();
48         ImmutableDateRange dr = new ImmutableDateRange(startMillis, endMillis,
49                 false, null, null);
50         dateAreaBean.getDateArea().setVisibleDateRange(dr);
51         dateAreaBean.setPreferredSize(new Dimension JavaDoc(200, 400));
52
53         dateAreaBean.setSelectionBoundaryType(DateRangeI.RANGE_TYPE_DAY);
54         dateAreaBean.getDateArea().setSelectionRounder(
55                 new BoundaryRounder(DateRangeI.RANGE_TYPE_DAY, true, true,
56                         false, 1, 1, null));
57         dateAreaBean.repaint();
58         setDateAreaContainer(dateAreaBean);
59
60         setHomeButtonVisible(true);
61         setLeftRightButtonsVisible(true);
62         setDefaultDateStyle(DateFormat.DEFAULT);
63         setHideEndDate(true);
64
65         setDate(Calendar.getInstance());
66     }
67
68     public void setDate(Calendar JavaDoc date) {
69         ImmutableDateRange dr = new ImmutableDateRange(date.getTimeInMillis(),
70                 date.getTimeInMillis(), false, null, null);
71
72         setSelectedRange(dr);
73     }
74
75     public Calendar JavaDoc getDate() {
76         DateRangeI range = getSelectedRange();
77
78         return range.getStart();
79     }
80
81     public void setSelectedColumbaDateRange(IDateRange range) {
82         ImmutableDateRange dr = new ImmutableDateRange(range.getStartTime()
83                 .getTimeInMillis(), range.getEndTime().getTimeInMillis(), true,
84                 null, null);
85
86         setSelectedRange(dr);
87     }
88
89 }
90
Popular Tags