1 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 Object [] DESCRIPTIONS = {"path", "signature", "step", "last timestamp", 39 "datasources", "archives", "size"}; 40 private static final String [] COLUMN_NAMES = {"description", "value"}; 41 42 private File file; 43 private Object [] 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 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 getColumnName(int column) { 67 return COLUMN_NAMES[column]; 68 } 69 70 void setFile(File newFile) { 71 try { 72 file = newFile; 73 values = null; 74 String path = file.getAbsolutePath(); 75 RrdDb rrd = new RrdDb(path); 76 Header header = rrd.getHeader(); 77 String signature = header.getSignature(); 78 String step = "" + header.getStep(); 79 String lastTimestamp = header.getLastUpdateTime() + " [" + 80 new Date (header.getLastUpdateTime() * 1000L) + "]"; 81 String datasources = "" + header.getDsCount(); 82 String archives = "" + header.getArcCount(); 83 String size = rrd.getRrdBackend().getLength() + " bytes"; 84 rrd.close(); 85 values = new Object []{ 86 path, signature, step, lastTimestamp, datasources, archives, size 87 }; 88 fireTableDataChanged(); 89 } catch (IOException e) { 90 e.printStackTrace(); 91 } catch (RrdException e) { 92 e.printStackTrace(); 93 } 94 } 95 } | Popular Tags |