01: package org.apache.jorphan.gui;
02:
03: /**
04: * Renders a rate in a JTable.
05: *
06: * The output is in units appropriate to its dimension:
07: * <p>
08: * The number is represented in one of:
09: * - requests/second
10: * - requests/minute
11: * - requests/hour.
12: * <p>
13: * Examples: "34.2/sec" "0.1/sec" "43.0/hour" "15.9/min"
14: */
15: public class RateRenderer extends NumberRenderer {
16:
17: public RateRenderer(String format) {
18: super (format);
19: }
20:
21: public void setValue(Object value) {
22: if (value == null || !(value instanceof Double)) {
23: setText("#N/A"); // TODO: should this just call super()?
24: return;
25: }
26: double rate = ((Double) value).doubleValue();
27: if (rate == Double.MAX_VALUE) {
28: setText("#N/A"); // TODO: should this just call super()?
29: return;
30: }
31:
32: String unit = "sec";
33:
34: if (rate < 1.0) {
35: rate *= 60.0;
36: unit = "min";
37: }
38: if (rate < 1.0) {
39: rate *= 60.0;
40: unit = "hour";
41: }
42: setText(formatter.format(rate) + "/" + unit);
43: }
44: }
|