~ubuntu-branches/ubuntu/utopic/figtree/utopic

« back to all changes in this revision

Viewing changes to src/figtree/treeviewer/painters/PercentFormat.java

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Tille
  • Date: 2011-02-21 08:17:38 UTC
  • Revision ID: james.westby@ubuntu.com-20110221081738-80pe2ulo8rg7up10
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package figtree.treeviewer.painters;
 
2
 
 
3
import java.text.*;
 
4
 
 
5
/**
 
6
 <p>
 
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.
 
10
 </p>
 
11
 
 
12
 @author Andrew Rambaut
 
13
 */
 
14
 
 
15
public class PercentFormat extends NumberFormat
 
16
{
 
17
    private final NumberFormat nf;
 
18
 
 
19
    public PercentFormat() {
 
20
        this.nf = new DecimalFormat();
 
21
    }
 
22
 
 
23
 
 
24
    /**
 
25
     * Returns the maximum number of digits allowed in the fraction portion of a
 
26
     * number.
 
27
     *
 
28
     * @see #setMaximumFractionDigits
 
29
     */
 
30
    @Override
 
31
    public int getMaximumFractionDigits() {
 
32
        return nf.getMaximumFractionDigits();
 
33
    }
 
34
 
 
35
    /**
 
36
     * Returns the maximum number of digits allowed in the integer portion of a
 
37
     * number.
 
38
     *
 
39
     * @see #setMaximumIntegerDigits
 
40
     */
 
41
    @Override
 
42
    public int getMaximumIntegerDigits() {
 
43
        return nf.getMaximumIntegerDigits();
 
44
    }
 
45
 
 
46
    /**
 
47
     * Returns the minimum number of digits allowed in the fraction portion of a
 
48
     * number.
 
49
     *
 
50
     * @see #setMinimumFractionDigits
 
51
     */
 
52
    @Override
 
53
    public int getMinimumFractionDigits() {
 
54
        return nf.getMinimumFractionDigits();
 
55
    }
 
56
 
 
57
    /**
 
58
     * Returns the minimum number of digits allowed in the integer portion of a
 
59
     * number.
 
60
     *
 
61
     * @see #setMinimumIntegerDigits
 
62
     */
 
63
    @Override
 
64
    public int getMinimumIntegerDigits() {
 
65
        return nf.getMinimumIntegerDigits();
 
66
    }
 
67
 
 
68
    /**
 
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
 
73
     * the new value.
 
74
     *
 
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
 
79
     */
 
80
    @Override
 
81
    public void setMaximumFractionDigits(int newValue) {
 
82
        nf.setMaximumFractionDigits(newValue);
 
83
    }
 
84
 
 
85
    /**
 
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
 
90
     * the new value
 
91
     *
 
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
 
96
     */
 
97
    @Override
 
98
    public void setMinimumIntegerDigits(int newValue) {
 
99
        nf.setMinimumIntegerDigits(newValue);
 
100
    }
 
101
 
 
102
    /**
 
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
 
107
     * the new value
 
108
     *
 
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
 
113
     */
 
114
    @Override
 
115
    public void setMinimumFractionDigits(int newValue) {
 
116
        nf.setMinimumFractionDigits(newValue);
 
117
    }
 
118
 
 
119
    /**
 
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
 
124
     * the new value.
 
125
     *
 
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
 
130
     */
 
131
    @Override
 
132
    public void setMaximumIntegerDigits(int newValue) {
 
133
        nf.setMaximumIntegerDigits(newValue);
 
134
    }
 
135
 
 
136
    /**
 
137
     * Specialization of format.
 
138
     *
 
139
     * @see java.text.Format#format
 
140
     */
 
141
     public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
 
142
        return nf.format(number * 100.0, toAppendTo, pos).append("%");
 
143
    }
 
144
 
 
145
    /**
 
146
     * Specialization of format.
 
147
     *
 
148
     * @see java.text.Format#format
 
149
     */
 
150
     public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
 
151
        return nf.format(number * 100, toAppendTo, pos).append("%");
 
152
    }
 
153
 
 
154
    /**
 
155
     * @see java.text.Format#parseObject
 
156
     */
 
157
     public Number parse(String source, ParsePosition parsePosition) {
 
158
        return nf.parse(source, parsePosition).doubleValue() / 100.0;
 
159
    }
 
160
}
 
 
b'\\ No newline at end of file'