jdk/src/share/classes/sun/tools/jconsole/Formatter.java
author sla
Tue, 19 Mar 2013 13:26:42 +0100
changeset 18197 ae73e4f50e08
parent 14342 8435a30053c1
child 24969 afa6934dd8e8
permissions -rw-r--r--
8003703: Update RMI connection dialog box Reviewed-by: skoivu, ahgross, mchung, jbachorik
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 12851
diff changeset
     2
 * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.jconsole;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
class Formatter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    final static long SECOND = 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    final static long MINUTE = 60 * SECOND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    final static long HOUR   = 60 * MINUTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    final static long DAY    = 24 * HOUR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    final static String cr = System.getProperty("line.separator");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    final static DateFormat timeDF            = new SimpleDateFormat("HH:mm");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private final static DateFormat timeWithSecondsDF = new SimpleDateFormat("HH:mm:ss");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private final static DateFormat dateDF            = new SimpleDateFormat("yyyy-MM-dd");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private final static String decimalZero =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
                                new DecimalFormatSymbols().getDecimalSeparator() + "0";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static String formatTime(long t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        String str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        if (t < 1 * MINUTE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            String seconds = String.format("%.3f", t / (double)SECOND);
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    50
            str = Resources.format(Messages.DURATION_SECONDS, seconds);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            long remaining = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            long days = remaining / DAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            remaining %= 1 * DAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            long hours = remaining / HOUR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            remaining %= 1 * HOUR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            long minutes = remaining / MINUTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            if (t >= 1 * DAY) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    60
                str = Resources.format(Messages.DURATION_DAYS_HOURS_MINUTES,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    61
                                       days, hours, minutes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            } else if (t >= 1 * HOUR) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    63
                str = Resources.format(Messages.DURATION_HOURS_MINUTES,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    64
                                       hours, minutes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            } else {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    66
                str = Resources.format(Messages.DURATION_MINUTES, minutes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    static String formatNanoTime(long t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        long ms = t / 1000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return formatTime(ms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    static String formatClockTime(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        return timeDF.format(time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    static String formatDate(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return dateDF.format(time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    static String formatDateTime(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return dateDF.format(time) + " " + timeWithSecondsDF.format(time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    90
    static DateFormat getDateTimeFormat(String dtfStr) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        int dateStyle = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        int timeStyle = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (dtfStr.startsWith("SHORT")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            dateStyle = DateFormat.SHORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        } else if (dtfStr.startsWith("MEDIUM")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            dateStyle = DateFormat.MEDIUM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        } else if (dtfStr.startsWith("LONG")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            dateStyle = DateFormat.LONG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        } else if (dtfStr.startsWith("FULL")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            dateStyle = DateFormat.FULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (dtfStr.endsWith("SHORT")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            timeStyle = DateFormat.SHORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        } else if (dtfStr.endsWith("MEDIUM")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            timeStyle = DateFormat.MEDIUM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        } else if (dtfStr.endsWith("LONG")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            timeStyle = DateFormat.LONG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        } else if (dtfStr.endsWith("FULL")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            timeStyle = DateFormat.FULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        if (dateStyle != -1 && timeStyle != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            return DateFormat.getDateTimeInstance(dateStyle, timeStyle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        } else if (dtfStr.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            return new SimpleDateFormat(dtfStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            return DateFormat.getDateTimeInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    static double toExcelTime(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        // Excel is bug compatible with Lotus 1-2-3 and pretends
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        // that 1900 was a leap year, so count from 1899-12-30.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        // Note that the month index is zero-based in Calendar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        Calendar cal = new GregorianCalendar(1899, 11, 30);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        // Adjust for the fact that now may be DST but then wasn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        Calendar tmpCal = new GregorianCalendar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        tmpCal.setTimeInMillis(time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        int dst = tmpCal.get(Calendar.DST_OFFSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (dst > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            cal.set(Calendar.DST_OFFSET, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        long millisSince1900 = time - cal.getTimeInMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        double value = (double)millisSince1900 / (24 * 60 * 60 * 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    static String[] formatKByteStrings(long... bytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        int n = bytes.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            if (bytes[i] > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                bytes[i] /= 1024;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        String[] strings = formatLongs(bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        for (int i = 0; i < n; i++) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   154
            strings[i] = Resources.format(Messages.KBYTES, strings[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return strings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    static String formatKBytes(long bytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (bytes == -1) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   161
            return Resources.format(Messages.KBYTES, "-1");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        long kb = bytes / 1024;
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   165
        return Resources.format(Messages.KBYTES, justify(kb, 10));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    static String formatBytes(long v, boolean html) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return formatBytes(v, v, html);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    static String formatBytes(long v, long vMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return formatBytes(v, vMax, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    static String formatBytes(long v, long vMax, boolean html) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        String s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        int exp = (int)Math.log10((double)vMax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (exp < 3) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   183
            s = Resources.format(Messages.SIZE_BYTES, v);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        } else if (exp < 6) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   185
            s = Resources.format(Messages.SIZE_KB, trimDouble(v / Math.pow(10.0, 3)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        } else if (exp < 9) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   187
            s = Resources.format(Messages.SIZE_MB, trimDouble(v / Math.pow(10.0, 6)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        } else {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   189
            s = Resources.format(Messages.SIZE_GB, trimDouble(v / Math.pow(10.0, 9)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (html) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            s = s.replace(" ", "&nbsp;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Return the input value rounded to one decimal place.  If after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * rounding the string ends in the (locale-specific) decimal point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * followed by a zero then trim that off as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    private static String trimDouble(double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        String s = String.format("%.1f", d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (s.length() > 3 && s.endsWith(decimalZero)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            s = s.substring(0, s.length()-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    static String formatLong(long value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return String.format("%,d", value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    static String[] formatLongs(long... longs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        int n = longs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        int size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        String[] strings = new String[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            strings[i] = formatLong(longs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            size = Math.max(size, strings[i].length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            strings[i] = justify(strings[i], size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        return strings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    // A poor attempt at right-justifying for numerical data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    static String justify(long value, int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return justify(formatLong(value), size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    static String justify(String str, int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        StringBuffer buf = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        buf.append("<TT>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        int n = size - str.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            buf.append("&nbsp;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        buf.append(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        buf.append("</TT>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    static String newRow(String label, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return newRow(label, value, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    static String newRow(String label, String value, int columnPerRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (label == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            label = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            label += ":&nbsp;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        label = "<th nowrap align=right valign=top>" + label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        value = "<td colspan=" + (columnPerRow-1) + "> <font size =-1>" + value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return "<tr>" + label + value + "</tr>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    static String newRow(String label1, String value1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                         String label2, String value2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        label1 = "<th nowrap align=right valign=top>" + label1 + ":&nbsp;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        value1 = "<td><font size =-1>" + value1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        label2 = "<th nowrap align=right valign=top>" + label2 + ":&nbsp;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        value2 = "<td><font size =-1>" + value2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        return "<tr>" + label1 + value1 + label2 + value2 + "</tr>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
}