-
Notifications
You must be signed in to change notification settings - Fork 98
/
DoubleFormatter.java
65 lines (56 loc) · 1.82 KB
/
DoubleFormatter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package org.eclipse.nebula.widgets.formattedtext;
import java.util.Locale;
/**
* This class provides formatting of <code>Double</code> values in a
* <code>FormattedText</code>.<p>
*
* NumberFormatter returns different numeric types based on the current
* value in the Text field. DoubleFormatter is an override of NumberFormatter
* allowing to guaranty to always return Double values (Number.doubleValue()).
*/
public class DoubleFormatter extends NumberFormatter {
public DoubleFormatter() {
super();
}
public DoubleFormatter(Locale loc) {
super(loc);
}
public DoubleFormatter(String editPattern, Locale loc) {
super(editPattern, loc);
}
public DoubleFormatter(String editPattern, String displayPattern, Locale loc) {
super(editPattern, displayPattern, loc);
}
public DoubleFormatter(String editPattern, String displayPattern) {
super(editPattern, displayPattern);
}
public DoubleFormatter(String editPattern) {
super(editPattern);
}
/**
* Returns the current value of the text control if it is a valid <code>Double</code>.
* If the buffer is flagged as modified, the value is recalculated by parsing
* with the <code>nfEdit</code> initialized with the edit pattern. If the
* number is not valid, returns <code>null</code>.
*
* @return current number value if valid, <code>null</code> else
* @see ITextFormatter#getValue()
*/
public Object getValue() {
Object value = super.getValue();
if ( value instanceof Number ) {
return new Double(((Number) value).doubleValue());
}
return super.getValue();
}
/**
* Returns the type of value this {@link ITextFormatter} handles,
* i.e. returns in {@link #getValue()}.<br>
* A DoubleFormatter always returns a Double value.
*
* @return The value type.
*/
public Class<Double> getValueType() {
return Double.class;
}
}