001/** 002 * DateEditor.java 003 * jCOLIBRI2 framework. 004 * @author Juan A. Recio-Garc�a. 005 * GAIA - Group for Artificial Intelligence Applications 006 * http://gaia.fdi.ucm.es 007 * 02/11/2007 008 */ 009package es.ucm.fdi.gaia.jcolibri.method.gui.editors; 010 011import java.text.DateFormat; 012import java.text.ParseException; 013import java.util.Collection; 014import java.util.Date; 015 016import javax.swing.JComponent; 017import javax.swing.JFormattedTextField; 018 019/** 020 * Parameter Editor for Date values. 021 * 022 * @author Juan A. Recio-Garcia 023 * @version 1.0 024 * @see ParameterEditor 025 */ 026public class DateEditor extends JFormattedTextField implements ParameterEditor { 027 private static final long serialVersionUID = 1L; 028 029 030 /** 031 * Creates a new instance 032 */ 033 public DateEditor() { 034 setValue(new Date()); 035 } 036 037 /** 038 * Returns a Date object 039 */ 040 public Object getEditorValue() { 041 try { 042 return DateFormat.getDateInstance().parse(getText()); 043 } catch (ParseException pe) { 044 return null; // To do, check what to do 045 } 046 } 047 048 /** 049 * Returns the JComponent 050 */ 051 public JComponent getJComponent() { 052 return (JComponent) this; 053 } 054 055 /** 056 * Receives a Date value 057 */ 058 public void setEditorValue(Object defaultValue) { 059 if(defaultValue==null) 060 { 061 this.setText(""); 062 return; 063 } 064 if (!(defaultValue instanceof Date)) 065 return; 066 Date value = (Date) defaultValue; 067 this.setValue(value); 068 } 069 070 /** 071 * Does nothing 072 */ 073 public void setAllowedValues(Collection<Object> allowedValues) 074 { 075 } 076 077}