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 / spinner / NullDateEditor.java @ 298

History | View | Annotate | Download (4.07 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.spinner;
35

    
36
import java.awt.Component;
37
import java.text.SimpleDateFormat;
38

    
39
import javax.swing.JSpinner;
40
import javax.swing.SpinnerDateModel;
41
import javax.swing.event.ChangeEvent;
42

    
43
import org.gvsig.tools.dynobject.DynField;
44
import org.gvsig.tools.swing.serv.field.component.date.JNullSpinner;
45
import org.gvsig.tools.swing.serv.field.component.spinner.NullSpinnerHandler.NullSpinnerDateModel;
46

    
47
/**
48
 * @author <a href="mailto:reinhold@uji.es">cmartin</a>
49
 * 
50
 */
51
public class NullDateEditor extends JSpinner.DateEditor {
52

    
53
    /**
54
     * 
55
     */
56
    private static final long serialVersionUID = -8215795896530639400L;
57
    private DynField dynField;
58
    private NullSpinnerDateModel model;
59

    
60
    /**
61
     * @param spinner
62
     * @param dynFieldFormatter
63
     * @param dynField2
64
     */
65
    public NullDateEditor(JNullSpinner spinner, DynField dynField,
66
        DynFieldFormatter formatter) {
67
        super(spinner);
68
        this.model = (NullSpinnerDateModel) spinner.getModel();
69
        this.dynField = dynField;
70
        this.setLocale(spinner.getLocale());
71
        this.getTextField().setAlignmentX(Component.RIGHT_ALIGNMENT);
72
        this.getTextField().setAlignmentY(Component.CENTER_ALIGNMENT);
73
        this.getTextField().setFormatterFactory(
74
            new DynFieldFormatterFactory(formatter));
75
    }
76

    
77
    @Override
78
    public SimpleDateFormat getFormat() {
79
        return model.getFormat();
80
    }
81

    
82
    @Override
83
    public SpinnerDateModel getModel() {
84
        return this.model;
85
    }
86

    
87
    @Override
88
    public void stateChanged(ChangeEvent e) {
89
        JNullSpinner spinner = (JNullSpinner) (e.getSource());
90
        Object value = spinner.getValue();
91
        getTextField().setValue(value);
92
    }
93

    
94
    // private void setFormatPattern(int type, Locale loc) {
95
    // // to do: locale settings
96
    // String strPattern = null;
97
    // switch (type){
98
    // }
99
    // }
100

    
101
    // public void stateChanged(ChangeEvent e) {
102
    //            
103
    // Date date = (Date) ((DateSpinner) e.getSource()).getModel().getValue();
104
    // String str = "";
105
    // if (date != null) {
106
    // str = date.toString();
107
    // }
108
    // if (!getTextField().getText().equals(str)){
109
    // getTextField().setText(str);
110
    // super.stateChanged(e);
111
    // }
112
    // }
113

    
114
    // public void format(Date date){
115
    // ((NullableDateSpinnerModel) this.getModel()).format(date);
116
    // }
117
    //        
118
    // Object value = getSpinner().getValue();
119
    // String text = "";
120
    // // String text = "(Add a value)";
121
    // if (value != null) {
122
    // // text = getFormat().format((Number) value);
123
    // super.stateChanged(e);
124
    // }else{
125
    // //
126
    // // text = getFormat().format((Date) value);
127
    // // SpinnerModel model = getSpinner().getModel();
128
    // // model.setValue(0);
129
    // getTextField().setText(text);
130
    // getTextField().repaint();
131
    // }
132
    // }
133
}