Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.swing / org.gvsig.tools.swing.serv / org.gvsig.tools.swing.serv.field / src / main / java / org / gvsig / tools / swing / serv / field / component / date / JDateDynFieldComponent.java @ 270

History | View | Annotate | Download (6.05 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22
/*
23
 * AUTHORS (In addition to CIT):
24
 * 2010 Institute of New Imaging Technologies (INIT): 
25
 *   http://www.init.uji.es
26
 * Geographic Information research group: 
27
 *   http://www.geoinfo.uji.es
28
 * Universitat Jaume I, Spain
29
 */
30

    
31
/**
32
 * 
33
 */
34
package org.gvsig.tools.swing.serv.field.component.date;
35

    
36
import java.util.Date;
37

    
38
import javax.swing.JComponent;
39

    
40
import org.gvsig.tools.dynobject.DynField;
41
import org.gvsig.tools.service.ServiceException;
42
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
43
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
44
import org.gvsig.tools.swing.spi.AbstractJDynFieldComponent;
45

    
46
/**
47
 * @author <a href="mailto:reinhold@uji.es">cmartin</a>
48
 * 
49
 */
50
public class JDateDynFieldComponent extends AbstractJDynFieldComponent
51
    implements JDynFieldComponent {
52

    
53
    private DateSpinner dateField;
54
    private JComponent panel;
55

    
56
    /**
57
     * @param dynField
58
     * @param value
59
     * @param button
60
     * @throws ServiceException
61
     */
62
    public JDateDynFieldComponent(ValueField parent, DynField dynField)
63
        throws ServiceException {
64
        this(parent, dynField, null);
65
    }
66

    
67
    // private void initUI(){
68
    // this.tfFile = new JTextField();
69
    // this.fc = createFileChooser();
70
    // }
71

    
72
    /**
73
     * @param parent
74
     * @param dynField
75
     * @param type
76
     * @throws ServiceException
77
     */
78
    public JDateDynFieldComponent(ValueField parent, DynField dynField,
79
        String type) throws ServiceException {
80
        super(dynField, parent);
81
    }
82

    
83
    /*
84
     * (non-Javadoc)
85
     * 
86
     * @see org.gvsig.tools.swing.spi.AbstractJDynFieldComponent#afterUI()
87
     */
88
    @Override
89
    protected void afterUI() {
90
    }
91

    
92
    /*
93
     * (non-Javadoc)
94
     * 
95
     * @see
96
     * org.gvsig.tools.swing.api.dynobject.dynfield.JComponent#getComponent()
97
     */
98
    public Object getComponent() {
99
        return panel;
100
    }
101

    
102
    /*
103
     * (non-Javadoc)
104
     * 
105
     * @see org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#getValue()
106
     */
107
    public Object getValue() {
108
        return getDateField().getValue();
109
    }
110

    
111
    public DateSpinner getDateField() {
112
        if (this.dateField != null)
113
            return this.dateField;
114
        this.dateField =
115
            new DateSpinner((Date) this.getFieldValue(), this.getDynField()
116
                .getType());
117
        return this.dateField;
118
    }
119

    
120
    /*
121
     * (non-Javadoc)
122
     * 
123
     * @see org.gvsig.tools.swing.spi.AbstractJDynFieldComponent#initData()
124
     */
125
    @Override
126
    protected void initData() {
127
        // TODO Auto-generated method stub
128

    
129
    }
130

    
131
    @Override
132
    protected void initUI() {
133
        // DateFormat dateFormat =
134
        // DateFormat.getDateInstance(DateFormat.DATE_FIELD);
135

    
136
        // this.panel = this.createBoxLayout(dateField, this.button, 1, 1,
137
        // null);
138
        // this.setEnabled(true);
139
    }
140

    
141
    /*
142
     * (non-Javadoc)
143
     * 
144
     * @see
145
     * 
146
     * 
147
     * org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#isMandatory
148
     * ()
149
     */
150
    @Override
151
    public boolean isMandatory() {
152
        return this.getDynField().isMandatory();
153
    }
154

    
155
    //
156
    // /*
157
    // * (non-Javadoc)
158
    // *
159
    // * @see org.gvsig.tools.swing.serv.field.core.ResultListener#onResult(int,
160
    // * java.lang.Object)
161
    // */
162
    // public void onResult(int returnVal, Object returnValue) {
163
    //
164
    // if (returnVal == ResultProvider.RETURN_OK) {
165
    // this.setValue(returnValue);
166
    // }
167
    // PluginServices.getMDIManager().closeWindow((IWindow) panel);
168
    //
169
    // }
170

    
171
    /*
172
     * (non-Javadoc)
173
     * 
174
     * @see
175
     * 
176
     * 
177
     * org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#requestFocus
178
     * ()
179
     */
180
    public void requestFocus() {
181
        getDateField().requestFocus();
182
    }
183

    
184
    /*
185
     * (non-Javadoc)
186
     * 
187
     * @see
188
     * 
189
     * 
190
     * org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#setEnabled
191
     * (boolean)
192
     */
193
    public void setEnabled(boolean isEnabled) {
194
        getDateField().setEnabled(isEnabled);
195
    }
196

    
197
    /*
198
     * (non-Javadoc)
199
     * 
200
     * @seeorg.gvsig.tools.swing.spi.AbstractJDynFieldComponent#
201
     * setJDynFieldComponentListeners()
202
     */
203
    @Override
204
    protected void setJDynFieldComponentListeners() {
205
        // TODO Auto-generated method stub
206

    
207
    }
208

    
209
    /*
210
     * (non-Javadoc)
211
     * 
212
     * @see org.gvsig.tools.swing.spi.AbstractJDynFieldComponent#setReadOnly()
213
     */
214
    @Override
215
    protected void setReadOnly() {
216
        getDateField().setEditable(false);
217
    }
218

    
219
    /*
220
     * (non-Javadoc)
221
     * 
222
     * @see
223
     * org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#setValue(java
224
     * .lang.Object)
225
     */
226
    protected void setNullValue() {
227
        this.getDateField().setValue(null);
228
    }
229

    
230
    protected void setNonNullValue(Object value) {
231
        if (value instanceof Date)
232
            getDateField().setValue((Date) value);
233
    }
234

    
235
    public JComponent asJComponent() {
236
        return this.getDateField();
237
    }
238

    
239
}