1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package org.jrobin.inspector;
27
28 import org.jrobin.core.RrdDb;
29 import org.jrobin.core.Header;
30 import org.jrobin.core.RrdException;
31
32 import javax.swing.table.AbstractTableModel;
33 import java.util.Date;
34 import java.io.IOException;
35 import java.io.File;
36
37 class HeaderTableModel extends AbstractTableModel {
38 private static final long serialVersionUID = 1L;
39 private static final Object[] DESCRIPTIONS = {
40 "path", "signature", "step", "last timestamp",
41 "datasources", "archives", "size"
42 };
43 private static final String[] COLUMN_NAMES = {"description", "value"};
44
45 private Object[] values;
46
47 public int getRowCount() {
48 return DESCRIPTIONS.length;
49 }
50
51 public int getColumnCount() {
52 return COLUMN_NAMES.length;
53 }
54
55 public Object getValueAt(int rowIndex, int columnIndex) {
56 if (columnIndex == 0) {
57 return DESCRIPTIONS[rowIndex];
58 }
59 else if (columnIndex == 1) {
60 if (values != null) {
61 return values[rowIndex];
62 }
63 else {
64 return "--";
65 }
66 }
67 return null;
68 }
69
70 public String getColumnName(int column) {
71 return COLUMN_NAMES[column];
72 }
73
74
75 void setFile(File file) {
76 try {
77 values = null;
78 String path = file.getAbsolutePath();
79 RrdDb rrd = new RrdDb(path, true);
80 try {
81 Header header = rrd.getHeader();
82 String signature = header.getSignature();
83 String step = "" + header.getStep();
84 String lastTimestamp = header.getLastUpdateTime() + " [" +
85 new Date(header.getLastUpdateTime() * 1000L) + "]";
86 String datasources = "" + header.getDsCount();
87 String archives = "" + header.getArcCount();
88 String size = rrd.getRrdBackend().getLength() + " bytes";
89 values = new Object[] {
90 path, signature, step, lastTimestamp, datasources, archives, size
91 };
92 }
93 finally {
94 rrd.close();
95 }
96 fireTableDataChanged();
97 }
98 catch (IOException e) {
99 Util.error(null, e);
100 }
101 catch (RrdException e) {
102 Util.error(null, e);
103 }
104 }
105 }