Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.dynform / org.gvsig.tools.dynform.spi / src / main / java / org / gvsig / tools / dynform / spi / dynformfield / CustomSpinnerDateModel.java @ 1947

History | View | Annotate | Download (2.69 KB)

1 954 jbadia
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24 919 jjdelcerro
package org.gvsig.tools.dynform.spi.dynformfield;
25
26 1388 fdiaz
import java.util.Date;
27
28 919 jjdelcerro
import javax.swing.SpinnerDateModel;
29
30 1388 fdiaz
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32
/**
33
 * SpinerDateModel nullable
34
 *
35
 * @author fdiaz
36
 *
37
 */
38
public class CustomSpinnerDateModel extends SpinnerDateModel {
39 919 jjdelcerro
40 1388 fdiaz
    /**
41
         *
42 919 jjdelcerro
         */
43 1388 fdiaz
    private static final long serialVersionUID = 4389535440347616567L;
44
45
    private static Logger logger = LoggerFactory
46
        .getLogger(CustomSpinnerDateModel.class);
47
48
    private boolean valid;
49
    private boolean allowNull;
50
51
    /**
52
    *
53
    */
54
   public CustomSpinnerDateModel() {
55
       this(false);
56
   }
57
    /**
58
     * @param allowNull
59
     *
60
     */
61
    public CustomSpinnerDateModel(boolean allowNull) {
62
        super();
63
        valid = false;
64
        this.allowNull = allowNull;
65
    }
66
67
    public void setValue(Object val) {
68
        if(!allowNull){
69
            super.setValue(val);
70
            return;
71
        }
72
        if (val != null) {
73
            valid = true;
74
            super.setValue(val);
75
            return;
76
        }
77
        valid = false;
78
    }
79
80
    public Object getValue() {
81
        if(!allowNull){
82
            return super.getValue();
83
        }
84
        if (valid) {
85
            return super.getValue();
86
        } else {
87
            return null;
88
        }
89
    }
90
91
    public Object getNextValue() {
92
        if (!allowNull){
93
            return super.getNextValue();
94
        }
95
        if (!valid) {
96
            Date p = new Date();
97
            return p;
98
        }
99
100
        return super.getNextValue();
101
    }
102
103
    public Object getPreviousValue() {
104
        if (!allowNull){
105
            return super.getPreviousValue();
106
        }
107
        if (!valid) {
108
            Date p = new Date();
109
            return p;
110
        }
111
112
        return super.getPreviousValue();
113
    }
114
115
}