KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > swing > FormatViewer


1 /*
2   Copyright (C) 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 org.objectweb.jac.aspects.gui.swing;
20
21 import javax.swing.JComponent JavaDoc;
22 import javax.swing.JLabel JavaDoc;
23 import org.objectweb.jac.aspects.gui.FieldView;
24 import org.objectweb.jac.aspects.gui.Format;
25 import org.objectweb.jac.core.rtti.FieldItem;
26
27 /**
28  * A Swing viewer component for date values.
29  */

30
31 public abstract class FormatViewer extends AbstractFieldView
32     implements FieldView
33 {
34     /** Stores the default format of the date */
35     protected Format format;
36     protected JLabel JavaDoc label = new JLabel JavaDoc();
37
38     /**
39     * Constructs a new date editor. */

40
41     public FormatViewer(Object JavaDoc value, Object JavaDoc substance, FieldItem field) {
42         super(substance,field);
43         initFormat(field);
44         setValue(value);
45         add(label);
46     }
47
48     public FormatViewer() {
49         setTableFont();
50         setLayout();
51         add(label);
52     }
53
54     protected abstract void initFormat(FieldItem field);
55
56     protected void setLayout() {
57     }
58
59     public void setField(FieldItem field) {
60         super.setField(field);
61         initFormat(field);
62     }
63
64     // FieldView interface
65

66     public void setValue(Object JavaDoc value) {
67         if (value!=null)
68             label.setText(format.format(value));
69         else
70             label.setText("");
71     }
72
73     protected JComponent JavaDoc getComponent() {
74         return label;
75     }
76 }
77
Popular Tags