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 */ 009 package jcolibri.method.gui.editors; 010 011 import java.text.DateFormat; 012 import java.text.ParseException; 013 import java.util.Collection; 014 import java.util.Date; 015 016 import javax.swing.JComponent; 017 import javax.swing.JFormattedTextField; 018 019 /** 020 * Parameter Editor for Date values. 021 * 022 * @author Juan A. Recio-Garcia 023 * @version 1.0 024 * @see jcolibri.method.gui.editors.ParameterEditor 025 */ 026 public 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 }