1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui.table;
21
22 import javax.swing.table.DefaultTableCellRenderer;
23
24 import org.xnap.util.Formatter;
25
26 /***
27 * Renders time for a table cell. If the value is an Integer object it
28 * is rendered as a length. If value is a Long object it is rendered
29 * as absolute time relative to the 1.1.1970.
30 *
31 * @see Formatter
32 */
33 public class TimeCellRenderer extends DefaultTableCellRenderer
34 {
35
36
37
38 public TimeCellRenderer()
39 {
40 setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
41 }
42
43
44
45 protected void setValue(Object value)
46 {
47 String s = "";
48
49 if (value != null) {
50 if (value instanceof Integer) {
51 int i = ((Number)value).intValue();
52 if (i >= 0) {
53 s = Formatter.formatLength(i);
54 }
55 }
56 else if (value instanceof Long) {
57 long l = ((Long)value).longValue();
58 if (l >= 0) {
59 s = Formatter.formatTime(l);
60 }
61 }
62 }
63
64 super.setValue(s);
65 }
66 }