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.*;
29
30 import javax.swing.table.AbstractTableModel;
31 import java.io.File;
32 import java.io.IOException;
33 import java.util.Date;
34
35 class ArchiveTableModel extends AbstractTableModel {
36 private static final long serialVersionUID = 1L;
37 private static final Object[] DESCRIPTIONS = {
38 "consolidation", "xff", "steps", "rows", "accum. value", "NaN steps", "start", "end"
39 };
40 private static final String[] COLUMN_NAMES = {"description", "value"};
41
42 private File file;
43 private Object[] values;
44 private int dsIndex = -1, arcIndex = -1;
45
46 public int getRowCount() {
47 return DESCRIPTIONS.length;
48 }
49
50 public int getColumnCount() {
51 return COLUMN_NAMES.length;
52 }
53
54 public Object getValueAt(int rowIndex, int columnIndex) {
55 if (columnIndex == 0) {
56 return DESCRIPTIONS[rowIndex];
57 }
58 else if (columnIndex == 1) {
59 if (values != null) {
60 return values[rowIndex];
61 }
62 else {
63 return "--";
64 }
65 }
66 return null;
67 }
68
69 public String getColumnName(int column) {
70 return COLUMN_NAMES[column];
71 }
72
73 void setFile(File newFile) {
74 file = newFile;
75 setIndex(-1, -1);
76 }
77
78 void setIndex(int newDsIndex, int newArcIndex) {
79 if (dsIndex != newDsIndex || arcIndex != newArcIndex) {
80 dsIndex = newDsIndex;
81 arcIndex = newArcIndex;
82 values = null;
83 if (dsIndex >= 0 && arcIndex >= 0) {
84 try {
85 RrdDb rrd = new RrdDb(file.getAbsolutePath(), true);
86 try {
87 Archive arc = rrd.getArchive(arcIndex);
88 ArcState state = arc.getArcState(dsIndex);
89 values = new Object[] {
90 arc.getConsolFun(),
91 "" + arc.getXff(),
92 "" + arc.getSteps(),
93 "" + arc.getRows(),
94 InspectorModel.formatDouble(state.getAccumValue()),
95 "" + state.getNanSteps(),
96 "" + arc.getStartTime() + " [" + new Date(arc.getStartTime() * 1000L) + "]",
97 "" + arc.getEndTime() + " [" + new Date(arc.getEndTime() * 1000L) + "]"
98 };
99 }
100 finally {
101 rrd.close();
102 }
103 }
104 catch (IOException e) {
105 Util.error(null, e);
106 }
107 catch (RrdException e) {
108 Util.error(null, e);
109 }
110 }
111 fireTableDataChanged();
112 }
113 }
114 }