-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathBarePercentFormat.java
More file actions
executable file
·184 lines (167 loc) · 6.06 KB
/
BarePercentFormat.java
File metadata and controls
executable file
·184 lines (167 loc) · 6.06 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
* BarePercentFormat.java
*
* Copyright (C) 2006-2014 Andrew Rambaut
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package figtree.ui;
import java.text.*;
/**
* This NumberFormat converts numbers to and from percent notation.
* Once an instance has been created, the format and parse methods may be used
* as defined in java.text.NumberFormat.
*
* @version $Id$
*
* $HeadURL$
*
* $LastChangedBy$
* $LastChangedDate$
* $LastChangedRevision$
*/
public class BarePercentFormat extends NumberFormat
{
private final NumberFormat nf;
public BarePercentFormat() {
this.nf = new DecimalFormat();
}
/**
* Returns the maximum number of digits allowed in the fraction portion of a
* number.
*
* @see #setMaximumFractionDigits
*/
@Override
public int getMaximumFractionDigits() {
return nf.getMaximumFractionDigits();
}
/**
* Returns the maximum number of digits allowed in the integer portion of a
* number.
*
* @see #setMaximumIntegerDigits
*/
@Override
public int getMaximumIntegerDigits() {
return nf.getMaximumIntegerDigits();
}
/**
* Returns the minimum number of digits allowed in the fraction portion of a
* number.
*
* @see #setMinimumFractionDigits
*/
@Override
public int getMinimumFractionDigits() {
return nf.getMinimumFractionDigits();
}
/**
* Returns the minimum number of digits allowed in the integer portion of a
* number.
*
* @see #setMinimumIntegerDigits
*/
@Override
public int getMinimumIntegerDigits() {
return nf.getMinimumIntegerDigits();
}
/**
* Sets the maximum number of digits allowed in the fraction portion of a
* number. maximumFractionDigits must be >= minimumFractionDigits. If the
* new value for maximumFractionDigits is less than the current value
* of minimumFractionDigits, then minimumFractionDigits will also be set to
* the new value.
*
* @param newValue the maximum number of fraction digits to be shown; if
* less than zero, then zero is used. The concrete subclass may enforce an
* upper limit to this value appropriate to the numeric type being formatted.
* @see #getMaximumFractionDigits
*/
@Override
public void setMaximumFractionDigits(int newValue) {
nf.setMaximumFractionDigits(newValue);
}
/**
* Sets the minimum number of digits allowed in the integer portion of a
* number. minimumIntegerDigits must be <= maximumIntegerDigits. If the
* new value for minimumIntegerDigits exceeds the current value
* of maximumIntegerDigits, then maximumIntegerDigits will also be set to
* the new value
*
* @param newValue the minimum number of integer digits to be shown; if
* less than zero, then zero is used. The concrete subclass may enforce an
* upper limit to this value appropriate to the numeric type being formatted.
* @see #getMinimumIntegerDigits
*/
@Override
public void setMinimumIntegerDigits(int newValue) {
nf.setMinimumIntegerDigits(newValue);
}
/**
* Sets the minimum number of digits allowed in the fraction portion of a
* number. minimumFractionDigits must be <= maximumFractionDigits. If the
* new value for minimumFractionDigits exceeds the current value
* of maximumFractionDigits, then maximumIntegerDigits will also be set to
* the new value
*
* @param newValue the minimum number of fraction digits to be shown; if
* less than zero, then zero is used. The concrete subclass may enforce an
* upper limit to this value appropriate to the numeric type being formatted.
* @see #getMinimumFractionDigits
*/
@Override
public void setMinimumFractionDigits(int newValue) {
nf.setMinimumFractionDigits(newValue);
}
/**
* Sets the maximum number of digits allowed in the integer portion of a
* number. maximumIntegerDigits must be >= minimumIntegerDigits. If the
* new value for maximumIntegerDigits is less than the current value
* of minimumIntegerDigits, then minimumIntegerDigits will also be set to
* the new value.
*
* @param newValue the maximum number of integer digits to be shown; if
* less than zero, then zero is used. The concrete subclass may enforce an
* upper limit to this value appropriate to the numeric type being formatted.
* @see #getMaximumIntegerDigits
*/
@Override
public void setMaximumIntegerDigits(int newValue) {
nf.setMaximumIntegerDigits(newValue);
}
/**
* Specialization of format.
*
* @see java.text.Format#format
*/
public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
return nf.format(number * 100.0, toAppendTo, pos);
}
/**
* Specialization of format.
*
* @see java.text.Format#format
*/
public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
return nf.format(number * 100, toAppendTo, pos);
}
/**
* @see java.text.Format#parseObject
*/
public Number parse(String source, ParsePosition parsePosition) {
return nf.parse(source, parsePosition).doubleValue() / 100.0;
}
}