Source code: jac/aspects/gui/web/DateEditor.java
1 /*
2 Copyright (C) 2001-2003 Laurent Martelli <laurent@aopsys.com>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17 USA */
18
19 package jac.aspects.gui.web;
20
21 import jac.aspects.gui.GuiAC;
22 import jac.core.rtti.FieldItem;
23 import jac.util.WrappedThrowableException;
24 import java.io.PrintWriter;
25 import java.text.ParseException;
26 import java.text.SimpleDateFormat;
27 import java.util.Date;
28
29 /**
30 * HTML editor and viewer for dates.
31 *
32 * @see jac.aspects.gui.GuiConf#setDateFormat(String)
33 * @see java.util.Date
34 */
35 public class DateEditor extends AbstractFieldEditor
36 implements HTMLEditor
37 {
38 SimpleDateFormat format = new SimpleDateFormat(GuiAC.getDateFormat());
39
40 public DateEditor(Object substance, FieldItem field) {
41 super(substance,field);
42 }
43
44 // HTMLEditor interface
45
46 public void genHTML(PrintWriter out) {
47 out.println("<input type=\"text\" name=\""+label+"\" size=\"12\" style=\"width:12ex\" "+
48 "value=\""+(value!=null?format.format((Date)value):"")+"\">");
49 }
50
51 public boolean readValue(Object parameter) {
52 String string=(String)parameter;
53 try {
54 Object date;
55 if (string==null || string.length()==0)
56 date = null;
57 else
58 date = format.parse(string);
59 setValue(date);
60 return true;
61 } catch(ParseException e) {
62 throw new WrappedThrowableException(e);
63 }
64 }
65
66
67 }
68