Revision 270 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/components/SpinnerNumberModel.java

View differences:

SpinnerNumberModel.java
1 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
*/
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 22
/*
23 23
 * AUTHORS (In addition to CIT):
24 24
 * 2010 Institute of New Imaging Technologies (INIT): 
......
33 33
 */
34 34
package org.gvsig.tools.swing.components;
35 35

  
36

  
37 36
import org.gvsig.tools.dynobject.DynField;
38 37

  
39 38
/**
40 39
 * @author <a href="mailto:reinhold@uji.es">cmartin</a>
41
 *
40
 * 
42 41
 */
43
public class SpinnerNumberModel extends javax.swing.SpinnerNumberModel{
44
   
42
public class SpinnerNumberModel extends javax.swing.SpinnerNumberModel {
43

  
45 44
    private boolean valid;
46 45
    private boolean firstTime = true;
47 46

  
48
    private SpinnerNumberModel(DynField field){
49
	super (0, (Comparable<?>) field
50
		.getMinValue(), (Comparable<?>) field.getMaxValue(), Integer
51
		.valueOf(1));
47
    private SpinnerNumberModel(DynField field) {
48
        super(0, (Comparable<?>) field.getMinValue(), (Comparable<?>) field
49
            .getMaxValue(), Integer.valueOf(1));
52 50
    }
53 51

  
54 52
    /**
......
56 54
     * @param value
57 55
     */
58 56
    public SpinnerNumberModel(DynField field, Number value) {
59
	this(field);
60
	setValue(value);
57
        this(field);
58
        setValue(value);
61 59
    }
62 60

  
63
    /* (non-Javadoc)
61
    /*
62
     * (non-Javadoc)
63
     * 
64 64
     * @see javax.swing.SpinnerNumberModel#getNumber()
65 65
     */
66 66
    @Override
67 67
    public Number getNumber() {
68
	// TODO Auto-generated method stub
69
	return super.getNumber();
68
        // TODO Auto-generated method stub
69
        return super.getNumber();
70 70
    }
71 71

  
72
    /* (non-Javadoc)
72
    /*
73
     * (non-Javadoc)
74
     * 
73 75
     * @see javax.swing.SpinnerNumberModel#getValue()
74 76
     */
75 77
    @Override
76 78
    public Object getValue() {
77
	 if (valid)
78
             return super.getValue();
79
         else
80
             return null;
79
        if (valid)
80
            return super.getValue();
81
        else
82
            return null;
81 83
    }
82 84

  
83
    /* (non-Javadoc)
85
    /*
86
     * (non-Javadoc)
87
     * 
84 88
     * @see javax.swing.SpinnerNumberModel#setValue(java.lang.Object)
85 89
     */
86 90
    @Override
87 91
    public void setValue(Object value) {
88
	 if (value != null)
89
         {
90
             try
91
             {
92
                 valid=true;
93
                 super.setValue(value);
94
                 return;
95
             }
96
             catch (Exception e){}
97
         }
98
         valid = false;
99
         super.setValue(value);
92
        if (value != null) {
93
            try {
94
                valid = true;
95
                super.setValue(value);
96
                return;
97
            } catch (Exception e) {
98
            }
99
        }
100
        valid = false;
101
        super.setValue(value);
100 102
    }
101
    
103

  
102 104
}

Also available in: Unified diff