1 7 8 package org.jdesktop.swing.binding; 9 10 import java.util.Calendar ; 11 import java.util.Date ; 12 import java.util.GregorianCalendar ; 13 14 import javax.swing.JComponent ; 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 fieldName) { 27 super(picker, model, fieldName, AbstractBinding.AUTO_VALIDATE_NONE); 28 } 29 30 public JComponent getComponent() { 31 return picker; 32 } 33 34 public void setComponent(JComponent component) { 35 this.picker = (JXDatePicker)component; 36 } 37 38 protected Object getComponentValue() { 39 Class klazz = metaData.getElementClass(); 40 if (klazz == Date .class) { 41 return picker.getDate(); 42 } 43 else if (klazz == Calendar .class) { 44 GregorianCalendar cal = new GregorianCalendar (); 45 cal.setTimeInMillis(picker.getDateInMillis()); 46 return cal; 47 } 48 else if (klazz == Long .class) { 49 return new Long (picker.getDateInMillis()); 50 } 51 return picker.getDate(); 53 } 54 55 protected void setComponentValue(Object value) { 56 Class klazz = metaData.getElementClass(); 57 if (klazz == Date .class) { 58 picker.setDate((Date )value); 59 } 60 else if (klazz == Calendar .class) { 61 picker.setDateInMillis(((Calendar )value).getTimeInMillis()); 62 } 63 else if (klazz == Long .class) { 64 picker.setDateInMillis(((Long )value).longValue()); 65 } 66 } 67 } 68 | Popular Tags |