/[schmitzm]/branches/2.0-RC2/src/skrueger/swing/formatter/MbDecimalFormatter.java
ViewVC logotype

Annotation of /branches/2.0-RC2/src/skrueger/swing/formatter/MbDecimalFormatter.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 604 - (hide annotations)
Wed Dec 9 14:15:53 2009 UTC (15 years, 2 months ago) by alfonx
Original Path: branches/2.0-RC1/src/skrueger/swing/formatter/MbDecimalFormatter.java
File MIME type: text/plain
File size: 1408 byte(s)
2.0-RC1 branch ist für GP1.3 bugfixes...  1.0-gt2-2.6  ist der entwicklungs brnach 
1 alfonx 519 package skrueger.swing.formatter;
2    
3     import java.text.DecimalFormat;
4     import java.text.FieldPosition;
5    
6     /**
7     * A formatter that formats double and long byte number into a Kb, Mb or Gb
8     * format.
9     */
10    
11     public class MbDecimalFormatter extends DecimalFormat {
12    
13     public MbDecimalFormatter() {
14     super("#########0.0");
15     }
16    
17     @Override
18     public StringBuffer format(double number, StringBuffer result,
19     FieldPosition fieldPosition) {
20    
21     String unit = "Mb";
22     number /= 1024. * 1024.;
23     if (number >= 512.) {
24     unit = "Gb";
25     number /= 1024.;
26     }
27    
28     if (number >= 0.1) {
29     return super.format(number, result, fieldPosition).append(unit);
30     } else {
31     return super.format(0.1, result, fieldPosition).append(unit)
32     .insert(0, "<");
33     }
34    
35     };
36    
37     @Override
38     public StringBuffer format(long number_l, StringBuffer result,
39     FieldPosition fieldPosition) {
40    
41     if (number_l < Double.MAX_VALUE) {
42     // The number is not that big.. convert to Double and go...
43     return format(Double.valueOf(number_l), result, fieldPosition);
44     }
45    
46     // We have a BIG number... Rounding-errors don't count anymore.
47     number_l /= 1024. * 1024.;
48     String unit = "Mb";
49    
50     if (number_l >= 512.) {
51     unit = "Gb";
52     number_l /= 1024.;
53     }
54    
55     if (number_l >= 0.1) {
56     return super.format(number_l, result, fieldPosition).append(unit);
57     } else {
58     return super.format(0.1, result, fieldPosition).append(unit)
59     .insert(0, "<");
60     }
61    
62     };
63    
64     }

Properties

Name Value
svn:eol-style native
svn:keywords Id URL
svn:mime-type text/plain

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26