KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jrobin > inspector > ArchiveTableModel


1 /* ============================================================
2  * JRobin : Pure java implementation of RRDTool's functionality
3  * ============================================================
4  *
5  * Project Info: http://www.jrobin.org
6  * Project Lead: Sasa Markovic (saxon@jrobin.org);
7  *
8  * (C) Copyright 2003, by Sasa Markovic.
9  *
10  * Developers: Sasa Markovic (saxon@jrobin.org)
11  * Arne Vandamme (cobralord@jrobin.org)
12  *
13  * This library is free software; you can redistribute it and/or modify it under the terms
14  * of the GNU Lesser General Public License as published by the Free Software Foundation;
15  * either version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License along with this
22  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */

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