KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mc4j > console > swing > editor > DateEditor


1 /*
2  * Copyright 2002-2004 Greg Hinkle
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.mc4j.console.swing.editor;
18
19 import org.openide.explorer.propertysheet.ExPropertyEditor;
20 import org.openide.explorer.propertysheet.InplaceEditor;
21 import org.openide.explorer.propertysheet.PropertyEnv;
22 import org.openide.explorer.propertysheet.PropertyModel;
23
24 import java.awt.Component JavaDoc;
25 import java.awt.Graphics JavaDoc;
26 import java.awt.Rectangle JavaDoc;
27 import java.awt.event.ActionListener JavaDoc;
28 import java.beans.PropertyEditor JavaDoc;
29 import java.beans.PropertyEditorSupport JavaDoc;
30 import java.util.Date JavaDoc;
31
32 import javax.swing.JComponent JavaDoc;
33 import javax.swing.KeyStroke JavaDoc;
34
35 /**
36  *
37  * @author Greg Hinkle (ghinkle@users.sourceforge.net), January 2002
38  * @version $Revision: 480 $($Author: ghinkl $ / $Date: 2004-10-05 01:17:41 -0400 (Tue, 05 Oct 2004) $)
39  */

40 public class DateEditor extends PropertyEditorSupport JavaDoc implements ExPropertyEditor, InplaceEditor.Factory {
41     
42     private Date JavaDoc currentDate;
43
44
45
46     protected PropertyEditor editor;
47     protected PropertyEnv env;
48     protected PropertyModel propertyModel;
49
50     private DateEditorInplace renderer;
51
52
53     public void attachEnv(PropertyEnv env) {
54         this.env = env;
55         this.env.registerInplaceEditorFactory(this);
56     }
57
58
59     public boolean isPaintable() {
60         return true;
61     }
62
63     public void paintValue(Graphics JavaDoc gfx, Rectangle JavaDoc box) {
64         if (renderer == null) {
65             renderer = new DateEditorInplace();
66         }
67
68         renderer.setSize (box.width, box.height);
69         renderer.doLayout();
70         Graphics JavaDoc g = gfx.create(box.x, box.y, box.width, box.height);
71         renderer.setOpaque(true);
72         renderer.paint (g);
73         g.dispose();
74     }
75     public InplaceEditor getInplaceEditor() {
76         return new DateEditorInplace();
77     }
78
79
80     public void setValue(Object JavaDoc value) {
81         super.setValue(value);
82         currentDate = (Date JavaDoc) value;
83     }
84
85     public Object JavaDoc getValue() {
86         return currentDate;
87     }
88
89
90
91
92     class DateEditorInplace extends CalendarComboBox implements InplaceEditor {
93
94         public DateEditorInplace() {
95             super(false);
96             super.setDate(currentDate);
97
98         }
99
100
101         public void connect(PropertyEditor pe, PropertyEnv env) {
102         }
103
104         public JComponent JavaDoc getComponent() {
105             return this;
106         }
107
108         public void clear() {
109         }
110
111         public Object JavaDoc getValue() {
112             return null;
113         }
114
115         public void setValue(Object JavaDoc o) {
116         }
117
118         public boolean supportsTextEntry() {
119             return false;
120         }
121
122         public void reset() {
123         }
124
125         public void addActionListener(ActionListener JavaDoc al) {
126         }
127
128         public void removeActionListener(ActionListener JavaDoc al) {
129         }
130
131         public KeyStroke JavaDoc[] getKeyStrokes() {
132             return new KeyStroke JavaDoc[0];
133         }
134
135         public PropertyEditor getPropertyEditor() {
136             return null;
137         }
138
139         public PropertyModel getPropertyModel() {
140             return null;
141         }
142
143         public void setPropertyModel(PropertyModel pm) {
144         }
145
146         public boolean isKnownComponent(Component JavaDoc c) {
147             return true;
148         }
149     }
150
151 }
152
Popular Tags