View Javadoc

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   *
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;
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 }