KickJava   Java API By Example, From Geeks To Geeks.

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


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.RrdDb;
29 import org.jrobin.core.Header;
30 import org.jrobin.core.RrdException;
31
32 import javax.swing.table.AbstractTableModel JavaDoc;
33 import java.util.Date JavaDoc;
34 import java.io.IOException JavaDoc;
35 import java.io.File JavaDoc;
36
37 class HeaderTableModel extends AbstractTableModel JavaDoc {
38     private static final Object JavaDoc[] DESCRIPTIONS = {"path", "signature", "step", "last timestamp",
39                                                   "datasources", "archives", "size"};
40     private static final String JavaDoc[] COLUMN_NAMES = {"description", "value"};
41
42     private File JavaDoc file;
43     private Object JavaDoc[] values;
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         } else if (columnIndex == 1) {
57             if (values != null) {
58                 return values[rowIndex];
59             } else {
60                 return "--";
61             }
62         }
63         return null;
64     }
65
66     public String JavaDoc getColumnName(int column) {
67         return COLUMN_NAMES[column];
68     }
69
70     void setFile(File JavaDoc newFile) {
71         try {
72             file = newFile;
73             values = null;
74             String JavaDoc path = file.getAbsolutePath();
75             RrdDb rrd = new RrdDb(path);
76             Header header = rrd.getHeader();
77             String JavaDoc signature = header.getSignature();
78             String JavaDoc step = "" + header.getStep();
79             String JavaDoc lastTimestamp = header.getLastUpdateTime() + " [" +
80                 new Date JavaDoc(header.getLastUpdateTime() * 1000L) + "]";
81             String JavaDoc datasources = "" + header.getDsCount();
82             String JavaDoc archives = "" + header.getArcCount();
83             String JavaDoc size = rrd.getRrdBackend().getLength() + " bytes";
84             rrd.close();
85             values = new Object JavaDoc[]{
86                 path, signature, step, lastTimestamp, datasources, archives, size
87             };
88             fireTableDataChanged();
89         } catch (IOException JavaDoc e) {
90             e.printStackTrace();
91         } catch (RrdException e) {
92             e.printStackTrace();
93         }
94     }
95 }
Popular Tags