Revision 298 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/NullableNumberSpinnerModel.java
NullableNumberSpinnerModel.java | ||
---|---|---|
33 | 33 |
*/ |
34 | 34 |
package org.gvsig.tools.swing.serv.field.component.spinner; |
35 | 35 |
|
36 |
import java.text.Format; |
|
37 |
|
|
38 |
import javax.swing.AbstractSpinnerModel; |
|
39 | 36 |
import javax.swing.SpinnerModel; |
40 | 37 |
import javax.swing.SpinnerNumberModel; |
41 |
import javax.swing.event.ChangeListener; |
|
42 | 38 |
|
43 | 39 |
import org.gvsig.tools.ToolsLocator; |
44 | 40 |
import org.gvsig.tools.dataTypes.CoercionException; |
... | ... | |
52 | 48 |
public class NullableNumberSpinnerModel extends SpinnerNumberModel implements |
53 | 49 |
SpinnerModel { |
54 | 50 |
|
51 |
/** |
|
52 |
* |
|
53 |
*/ |
|
54 |
private static final long serialVersionUID = 1320385929219211201L; |
|
55 | 55 |
private DynField field; |
56 | 56 |
private Object number; |
57 | 57 |
private boolean isFirstTime; |
... | ... | |
66 | 66 |
this.field = field; |
67 | 67 |
this.isFirstTime = true; |
68 | 68 |
super.setValue(0); |
69 |
if (value != null) |
|
69 |
if (value != null) {
|
|
70 | 70 |
setValue(value); |
71 |
} |
|
71 | 72 |
} |
72 | 73 |
|
73 | 74 |
/* |
... | ... | |
78 | 79 |
@Override |
79 | 80 |
public Object getNextValue() { |
80 | 81 |
Number next = null; |
81 |
if (isNull()){ |
|
82 |
if (isNull()) {
|
|
82 | 83 |
next = 0; |
83 |
} else{ |
|
84 |
} else {
|
|
84 | 85 |
next = (Number) super.getNextValue(); |
85 | 86 |
} |
86 | 87 |
this.number = next; |
87 | 88 |
return next; |
88 | 89 |
} |
89 | 90 |
|
90 |
protected boolean isNull() { |
|
91 |
Object value = getValue(); |
|
92 |
return ((value == null) || (value.equals(""))); |
|
93 |
} |
|
94 |
|
|
95 | 91 |
/* |
96 | 92 |
* (non-Javadoc) |
97 | 93 |
* |
... | ... | |
99 | 95 |
*/ |
100 | 96 |
@Override |
101 | 97 |
public Object getPreviousValue() { |
102 |
if (isNull()) |
|
98 |
if (isNull()) {
|
|
103 | 99 |
return null; |
100 |
} |
|
104 | 101 |
if (this.number.equals(this.getMinimum())) { |
105 | 102 |
// we are at the minimum value and we want to change to |
106 | 103 |
// "undetermined" |
... | ... | |
120 | 117 |
if (this.isFirstTime) { |
121 | 118 |
this.number = 0; |
122 | 119 |
} |
123 |
if (this.number == null){ |
|
120 |
if (this.number == null) {
|
|
124 | 121 |
return null; |
125 | 122 |
} |
126 | 123 |
try { |
127 |
return (Number) ToolsLocator.getDataTypesManager().coerce(
|
|
124 |
return ToolsLocator.getDataTypesManager().coerce( |
|
128 | 125 |
this.field.getType(), this.number); |
129 | 126 |
} catch (LocatorException e) { |
130 | 127 |
// TODO Auto-generated catch block |
... | ... | |
136 | 133 |
return null; |
137 | 134 |
} |
138 | 135 |
|
136 |
protected boolean isNull() { |
|
137 |
Object value = getValue(); |
|
138 |
return ((value == null) || (value.equals(""))); |
|
139 |
} |
|
140 |
|
|
139 | 141 |
/* |
140 | 142 |
* (non-Javadoc) |
141 | 143 |
* |
... | ... | |
145 | 147 |
public void setValue(Object value) { |
146 | 148 |
this.number = value; |
147 | 149 |
this.isFirstTime = false; |
148 |
if (!isNull()){ |
|
150 |
if (!isNull()) {
|
|
149 | 151 |
super.setValue(value); |
150 | 152 |
} |
151 | 153 |
this.fireStateChanged(); |
Also available in: Unified diff