KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > binding > DatePickerBinding


1 /*
2  * $Id: DatePickerBinding.java,v 1.3 2004/08/31 19:52:56 dmouse Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.swing.binding;
9
10 import java.util.Calendar JavaDoc;
11 import java.util.Date JavaDoc;
12 import java.util.GregorianCalendar JavaDoc;
13
14 import javax.swing.JComponent JavaDoc;
15
16 import org.jdesktop.swing.data.DataModel;
17 import org.jdesktop.swing.data.MetaData;
18
19 import org.jdesktop.swing.JXDatePicker;
20
21 public class DatePickerBinding extends AbstractBinding {
22
23     private JXDatePicker picker;
24
25     public DatePickerBinding(JXDatePicker picker,
26                  DataModel model, String JavaDoc fieldName) {
27         super(picker, model, fieldName, AbstractBinding.AUTO_VALIDATE_NONE);
28     }
29
30     public JComponent JavaDoc getComponent() {
31     return picker;
32     }
33
34     public void setComponent(JComponent JavaDoc component) {
35     this.picker = (JXDatePicker)component;
36     }
37
38     protected Object JavaDoc getComponentValue() {
39     Class JavaDoc klazz = metaData.getElementClass();
40     if (klazz == Date JavaDoc.class) {
41         return picker.getDate();
42     }
43     else if (klazz == Calendar JavaDoc.class) {
44             GregorianCalendar JavaDoc cal = new GregorianCalendar JavaDoc();
45             cal.setTimeInMillis(picker.getDateInMillis());
46         return cal;
47     }
48         else if (klazz == Long JavaDoc.class) {
49             return new Long JavaDoc(picker.getDateInMillis());
50         }
51     // default?
52
return picker.getDate();
53     }
54
55     protected void setComponentValue(Object JavaDoc value) {
56     Class JavaDoc klazz = metaData.getElementClass();
57     if (klazz == Date JavaDoc.class) {
58         picker.setDate((Date JavaDoc)value);
59     }
60     else if (klazz == Calendar JavaDoc.class) {
61         picker.setDateInMillis(((Calendar JavaDoc)value).getTimeInMillis());
62     }
63         else if (klazz == Long JavaDoc.class) {
64             picker.setDateInMillis(((Long JavaDoc)value).longValue());
65         }
66     }
67 }
68
Popular Tags