1
package figtree.treeviewer.painters;
7
This NumberFormat converts numbers to and from percent notation.
8
Once an instance has been created, the format and parse methods may be used
9
as defined in java.text.NumberFormat.
12
@author Andrew Rambaut
15
public class PercentFormat extends NumberFormat
17
private final NumberFormat nf;
19
public PercentFormat() {
20
this.nf = new DecimalFormat();
25
* Returns the maximum number of digits allowed in the fraction portion of a
28
* @see #setMaximumFractionDigits
31
public int getMaximumFractionDigits() {
32
return nf.getMaximumFractionDigits();
36
* Returns the maximum number of digits allowed in the integer portion of a
39
* @see #setMaximumIntegerDigits
42
public int getMaximumIntegerDigits() {
43
return nf.getMaximumIntegerDigits();
47
* Returns the minimum number of digits allowed in the fraction portion of a
50
* @see #setMinimumFractionDigits
53
public int getMinimumFractionDigits() {
54
return nf.getMinimumFractionDigits();
58
* Returns the minimum number of digits allowed in the integer portion of a
61
* @see #setMinimumIntegerDigits
64
public int getMinimumIntegerDigits() {
65
return nf.getMinimumIntegerDigits();
69
* Sets the maximum number of digits allowed in the fraction portion of a
70
* number. maximumFractionDigits must be >= minimumFractionDigits. If the
71
* new value for maximumFractionDigits is less than the current value
72
* of minimumFractionDigits, then minimumFractionDigits will also be set to
75
* @param newValue the maximum number of fraction digits to be shown; if
76
* less than zero, then zero is used. The concrete subclass may enforce an
77
* upper limit to this value appropriate to the numeric type being formatted.
78
* @see #getMaximumFractionDigits
81
public void setMaximumFractionDigits(int newValue) {
82
nf.setMaximumFractionDigits(newValue);
86
* Sets the minimum number of digits allowed in the integer portion of a
87
* number. minimumIntegerDigits must be <= maximumIntegerDigits. If the
88
* new value for minimumIntegerDigits exceeds the current value
89
* of maximumIntegerDigits, then maximumIntegerDigits will also be set to
92
* @param newValue the minimum number of integer digits to be shown; if
93
* less than zero, then zero is used. The concrete subclass may enforce an
94
* upper limit to this value appropriate to the numeric type being formatted.
95
* @see #getMinimumIntegerDigits
98
public void setMinimumIntegerDigits(int newValue) {
99
nf.setMinimumIntegerDigits(newValue);
103
* Sets the minimum number of digits allowed in the fraction portion of a
104
* number. minimumFractionDigits must be <= maximumFractionDigits. If the
105
* new value for minimumFractionDigits exceeds the current value
106
* of maximumFractionDigits, then maximumIntegerDigits will also be set to
109
* @param newValue the minimum number of fraction digits to be shown; if
110
* less than zero, then zero is used. The concrete subclass may enforce an
111
* upper limit to this value appropriate to the numeric type being formatted.
112
* @see #getMinimumFractionDigits
115
public void setMinimumFractionDigits(int newValue) {
116
nf.setMinimumFractionDigits(newValue);
120
* Sets the maximum number of digits allowed in the integer portion of a
121
* number. maximumIntegerDigits must be >= minimumIntegerDigits. If the
122
* new value for maximumIntegerDigits is less than the current value
123
* of minimumIntegerDigits, then minimumIntegerDigits will also be set to
126
* @param newValue the maximum number of integer digits to be shown; if
127
* less than zero, then zero is used. The concrete subclass may enforce an
128
* upper limit to this value appropriate to the numeric type being formatted.
129
* @see #getMaximumIntegerDigits
132
public void setMaximumIntegerDigits(int newValue) {
133
nf.setMaximumIntegerDigits(newValue);
137
* Specialization of format.
139
* @see java.text.Format#format
141
public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
142
return nf.format(number * 100.0, toAppendTo, pos).append("%");
146
* Specialization of format.
148
* @see java.text.Format#format
150
public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
151
return nf.format(number * 100, toAppendTo, pos).append("%");
155
* @see java.text.Format#parseObject
157
public Number parse(String source, ParsePosition parsePosition) {
158
return nf.parse(source, parsePosition).doubleValue() / 100.0;
b'\\ No newline at end of file'