|
From: <sa...@us...> - 2003-11-07 08:23:22
|
Update of /cvsroot/jrobin/src/org/jrobin/inspector In directory sc8-pr-cvs1:/tmp/cvs-serv14464/org/jrobin/inspector Added Files: ArchiveTableModel.java DataTableModel.java DatasourceTableModel.java HeaderTableModel.java InspectorModel.java MainTreeModel.java RrdInspector.java RrdNode.java Log Message: packages org.jrobin.* created (old jrobin.* packages still exist, will be removed later) --- NEW FILE: ArchiveTableModel.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.inspector; import org.jrobin.core.*; import javax.swing.table.AbstractTableModel; import java.io.File; import java.io.IOException; import java.util.Date; class ArchiveTableModel extends AbstractTableModel { private static final Object[] DESCRIPTIONS = { "consolidation", "xff", "steps", "rows", "accum. value", "NaN steps", "start", "end" }; private static final String[] COLUMN_NAMES = {"description", "value"}; private File file; private Object[] values; private int dsIndex = -1, arcIndex = -1; public int getRowCount() { return DESCRIPTIONS.length; } public int getColumnCount() { return COLUMN_NAMES.length; } public Object getValueAt(int rowIndex, int columnIndex) { if (columnIndex == 0) { return DESCRIPTIONS[rowIndex]; } else if (columnIndex == 1) { if (values != null) { return values[rowIndex]; } else { return "--"; } } return null; } public String getColumnName(int column) { return COLUMN_NAMES[column]; } void setFile(File newFile) { if (file == null || !file.getAbsolutePath().equals(newFile.getAbsolutePath())) { file = newFile; setIndex(-1, -1); } } void setIndex(int newDsIndex, int newArcIndex) { if (dsIndex != newDsIndex || arcIndex != newArcIndex) { dsIndex = newDsIndex; arcIndex = newArcIndex; values = null; if(dsIndex >= 0 && arcIndex >= 0) { try { RrdDb rrd = new RrdDb(file.getAbsolutePath()); Archive arc = rrd.getArchive(arcIndex); ArcState state = arc.getArcState(dsIndex); values = new Object[]{ arc.getConsolFun(), "" + arc.getXff(), "" + arc.getSteps(), "" + arc.getRows(), InspectorModel.formatDouble(state.getAccumValue()), "" + state.getNanSteps(), "" + arc.getStartTime() + " [" + new Date(arc.getStartTime() * 1000L) + "]", "" + arc.getEndTime() + " [" + new Date(arc.getEndTime() * 1000L) + "]" }; rrd.close(); } catch (IOException e) { } catch (RrdException e) { } } fireTableDataChanged(); } } } --- NEW FILE: DataTableModel.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.inspector; import org.jrobin.core.*; import javax.swing.table.AbstractTableModel; import java.io.File; import java.io.IOException; import java.util.Date; class DataTableModel extends AbstractTableModel { private static final String[] COLUMN_NAMES = {"timestamp", "date", "value"}; private File file; private Object[][] values; private int dsIndex = -1, arcIndex = -1; public int getRowCount() { if(values == null) { return 0; } else { return values.length; } } public int getColumnCount() { return COLUMN_NAMES.length; } public Object getValueAt(int rowIndex, int columnIndex) { if(values == null) { return "--"; } return values[rowIndex][columnIndex]; } public String getColumnName(int column) { return COLUMN_NAMES[column]; } void setFile(File newFile) { if (file == null || !file.getAbsolutePath().equals(newFile.getAbsolutePath())) { file = newFile; setIndex(-1, -1); } } void setIndex(int newDsIndex, int newArcIndex) { if (dsIndex != newDsIndex || arcIndex != newArcIndex) { dsIndex = newDsIndex; arcIndex = newArcIndex; values = null; if(dsIndex >= 0 && arcIndex >= 0) { try { RrdDb rrd = new RrdDb(file.getAbsolutePath()); Archive arc = rrd.getArchive(arcIndex); Robin robin = arc.getRobin(dsIndex); long start = arc.getStartTime(); long step = arc.getArcStep(); double robinValues[] = robin.getValues(); values = new Object[robinValues.length][]; for(int i = 0; i < robinValues.length; i++) { long timestamp = start + i * step; String date = new Date(timestamp * 1000L).toString(); String value = InspectorModel.formatDouble(robinValues[i]); values[i] = new Object[] { "" + timestamp, date, value }; } rrd.close(); } catch (IOException e) { } catch (RrdException e) { } } fireTableDataChanged(); } } } --- NEW FILE: DatasourceTableModel.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.inspector; import org.jrobin.core.RrdDb; import org.jrobin.core.Datasource; import org.jrobin.core.RrdException; import javax.swing.table.AbstractTableModel; import java.io.IOException; import java.io.File; class DatasourceTableModel extends AbstractTableModel { private static final Object[] DESCRIPTIONS = {"name", "type", "heartbeat", "min value", "max value", "last value", "accum. value", "NaN seconds"}; private static final String[] COLUMN_NAMES = {"description", "value"}; private File file; private Object[] values; private int dsIndex = -1; public int getRowCount() { return DESCRIPTIONS.length; } public int getColumnCount() { return COLUMN_NAMES.length; } public Object getValueAt(int rowIndex, int columnIndex) { if (columnIndex == 0) { return DESCRIPTIONS[rowIndex]; } else if (columnIndex == 1) { if (values != null) { return values[rowIndex]; } else { return "--"; } } return null; } public String getColumnName(int column) { return COLUMN_NAMES[column]; } void setFile(File newFile) { if (file == null || !file.getAbsolutePath().equals(newFile.getAbsolutePath())) { file = newFile; setIndex(-1); } } void setIndex(int newDsIndex) { if (dsIndex != newDsIndex) { dsIndex = newDsIndex; values = null; if(dsIndex >= 0) { try { RrdDb rrd = new RrdDb(file.getAbsolutePath()); Datasource ds = rrd.getDatasource(dsIndex); values = new Object[]{ ds.getDsName(), ds.getDsType(), "" + ds.getHeartbeat(), InspectorModel.formatDouble(ds.getMinValue()), InspectorModel.formatDouble(ds.getMaxValue()), InspectorModel.formatDouble(ds.getLastValue()), InspectorModel.formatDouble(ds.getAccumValue()), "" + ds.getNanSeconds() }; rrd.close(); } catch (IOException e) { } catch (RrdException e) { } } fireTableDataChanged(); } } } --- NEW FILE: HeaderTableModel.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.inspector; import org.jrobin.core.RrdDb; import org.jrobin.core.Header; import org.jrobin.core.RrdException; import javax.swing.table.AbstractTableModel; import java.util.Date; import java.io.IOException; import java.io.File; class HeaderTableModel extends AbstractTableModel { private static final Object[] DESCRIPTIONS = {"path", "signature", "step", "last timestamp", "datasources", "archives", "size"}; private static final String[] COLUMN_NAMES = {"description", "value"}; private File file; private Object[] values; public int getRowCount() { return DESCRIPTIONS.length; } public int getColumnCount() { return COLUMN_NAMES.length; } public Object getValueAt(int rowIndex, int columnIndex) { if(columnIndex == 0) { return DESCRIPTIONS[rowIndex]; } else if(columnIndex == 1) { if(values != null) { return values[rowIndex]; } else { return "--"; } } return null; } public String getColumnName(int column) { return COLUMN_NAMES[column]; } void setFile(File newFile) { if(file == null || !file.getAbsolutePath().equals(newFile.getAbsolutePath())) { try { file = newFile; values = null; String path = file.getAbsolutePath(); RrdDb rrd = new RrdDb(path); Header header = rrd.getHeader(); String signature = header.getSignature(); String step = "" + header.getStep(); String lastTimestamp = header.getLastUpdateTime() + " [" + new Date(header.getLastUpdateTime() * 1000L) + "]"; String datasources = "" + header.getDsCount(); String archives = "" + header.getArcCount(); String size = rrd.getRrdFile().getFileSize() + " bytes"; rrd.close(); values = new Object[] { path, signature, step, lastTimestamp, datasources, archives, size }; fireTableDataChanged(); } catch (IOException e) { } catch (RrdException e) { } } } } --- NEW FILE: InspectorModel.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.inspector; import java.io.File; import java.text.DecimalFormat; /** * Created by saxon * User: stalker * Date: Oct 5, 2003 * Time: 11:26:05 AM */ class InspectorModel { private MainTreeModel mainTreeModel = new MainTreeModel(); private HeaderTableModel generalTableModel = new HeaderTableModel(); private DatasourceTableModel datasourceTableModel = new DatasourceTableModel(); private ArchiveTableModel archiveTableModel = new ArchiveTableModel(); private DataTableModel dataTableModel = new DataTableModel(); MainTreeModel getMainTreeModel() { return mainTreeModel; } HeaderTableModel getGeneralTableModel() { return generalTableModel; } DatasourceTableModel getDatasourceTableModel() { return datasourceTableModel; } DataTableModel getDataTableModel() { return dataTableModel; } ArchiveTableModel getArchiveTableModel() { return archiveTableModel; } void setFile(File file) { mainTreeModel.setFile(file); generalTableModel.setFile(file); datasourceTableModel.setFile(file); archiveTableModel.setFile(file); dataTableModel.setFile(file); } void selectModel(int dsIndex, int arcIndex) { datasourceTableModel.setIndex(dsIndex); archiveTableModel.setIndex(dsIndex, arcIndex); dataTableModel.setIndex(dsIndex, arcIndex); } private static String DOUBLE_FORMAT = "0.0000000000E00"; private static final DecimalFormat df = new DecimalFormat(DOUBLE_FORMAT); static String formatDouble(double x, String nanString) { if(Double.isNaN(x)) { return nanString; } return df.format(x); } static String formatDouble(double x) { return formatDouble(x, "" + Double.NaN); } } --- NEW FILE: MainTreeModel.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.inspector; import org.jrobin.core.RrdDb; import org.jrobin.core.RrdException; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.DefaultMutableTreeNode; import java.io.IOException; import java.io.File; class MainTreeModel extends DefaultTreeModel { private static final DefaultMutableTreeNode INVALID_NODE = new DefaultMutableTreeNode("No valid RRD file specified"); private File file; MainTreeModel() { super(INVALID_NODE); } void setFile(File newFile) { if (file == null || !file.getAbsolutePath().equals(newFile.getAbsolutePath())) { try { file = newFile; RrdDb rrd = new RrdDb(file.getAbsolutePath()); DefaultMutableTreeNode root = new DefaultMutableTreeNode(new RrdNode(rrd)); int dsCount = rrd.getRrdDef().getDsCount(); int arcCount = rrd.getRrdDef().getArcCount(); for (int dsIndex = 0; dsIndex < dsCount; dsIndex++) { DefaultMutableTreeNode dsNode = new DefaultMutableTreeNode(new RrdNode(rrd, dsIndex)); for (int arcIndex = 0; arcIndex < arcCount; arcIndex++) { DefaultMutableTreeNode arcNode = new DefaultMutableTreeNode(new RrdNode(rrd, dsIndex, arcIndex)); dsNode.add(arcNode); } root.add(dsNode); } rrd.close(); setRoot(root); } catch (IOException e) { setRoot(INVALID_NODE); } catch (RrdException e) { setRoot(INVALID_NODE); } } } } --- NEW FILE: RrdInspector.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.inspector; import javax.swing.*; import javax.swing.filechooser.FileFilter; import javax.swing.event.TreeSelectionListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.tree.TreeSelectionModel; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; import java.awt.*; import java.awt.event.*; import java.io.File; class RrdInspector extends JFrame { static final String TITLE = "RRD File Inspector"; static Dimension MAIN_TREE_SIZE = new Dimension(250, 400); static Dimension INFO_PANE_SIZE = new Dimension(450, 400); JTabbedPane tabbedPane = new JTabbedPane(); private JTree mainTree = new JTree(); private JTable generalTable = new JTable(); private JTable datasourceTable = new JTable(); private JTable archiveTable = new JTable(); private JTable dataTable = new JTable(); private InspectorModel inspectorModel = new InspectorModel(); RrdInspector() { super(TITLE); constructUI(); showCentered(); selectFile(); } private void showCentered() { pack(); Toolkit t = Toolkit.getDefaultToolkit(); Dimension screenSize = t.getScreenSize(), frameSize = getPreferredSize(); double x = (screenSize.getWidth() - frameSize.getWidth()) / 2; double y = (screenSize.getHeight() - frameSize.getHeight()) / 2; setLocation((int) x, (int) y); setVisible(true); } private void constructUI() { JPanel content = (JPanel) getContentPane(); content.setLayout(new BorderLayout()); // WEST, tree pane JPanel leftPanel = new JPanel(); leftPanel.setLayout(new BorderLayout()); JScrollPane treePane = new JScrollPane(mainTree); leftPanel.add(treePane); leftPanel.setPreferredSize(MAIN_TREE_SIZE); content.add(leftPanel, BorderLayout.WEST); mainTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); mainTree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { nodeChangedAction(); } }); mainTree.setModel(inspectorModel.getMainTreeModel()); // EAST, tabbed pane // GENERAL TAB JScrollPane spGeneral = new JScrollPane(generalTable); spGeneral.setPreferredSize(INFO_PANE_SIZE); tabbedPane.add("General info", spGeneral); generalTable.setModel(inspectorModel.getGeneralTableModel()); generalTable.getColumnModel().getColumn(0).setPreferredWidth(150); generalTable.getColumnModel().getColumn(0).setMaxWidth(150); //generalTable.getColumnModel().getColumn(0).setMinWidth(150); // DATASOURCE TAB JScrollPane spDatasource = new JScrollPane(datasourceTable); spDatasource.setPreferredSize(INFO_PANE_SIZE); tabbedPane.add("Datasource info", spDatasource); datasourceTable.setModel(inspectorModel.getDatasourceTableModel()); datasourceTable.getColumnModel().getColumn(0).setPreferredWidth(150); datasourceTable.getColumnModel().getColumn(0).setMaxWidth(150); //datasourceTable.getColumnModel().getColumn(0).setMinWidth(150); // ARCHIVE TAB JScrollPane spArchive = new JScrollPane(archiveTable); archiveTable.setModel(inspectorModel.getArchiveTableModel()); archiveTable.getColumnModel().getColumn(0).setPreferredWidth(150); archiveTable.getColumnModel().getColumn(0).setMaxWidth(150); //archiveTable.getColumnModel().getColumn(0).setMinWidth(150); spArchive.setPreferredSize(INFO_PANE_SIZE); tabbedPane.add("Archive info", spArchive); // DATA TAB JScrollPane spData = new JScrollPane(dataTable); dataTable.setModel(inspectorModel.getDataTableModel()); dataTable.getColumnModel().getColumn(0).setPreferredWidth(100); dataTable.getColumnModel().getColumn(0).setMaxWidth(100); dataTable.getColumnModel().getColumn(1).setPreferredWidth(150); spData.setPreferredSize(INFO_PANE_SIZE); tabbedPane.add("Archive data", spData); content.add(tabbedPane, BorderLayout.CENTER); // MENU JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); JMenuItem fileMenuItem = new JMenuItem("Open RRD file...", KeyEvent.VK_O); fileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { selectFile(); } }); fileMenu.add(fileMenuItem); JMenuItem exitMenuItem = new JMenuItem("Exit", KeyEvent.VK_X); exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); fileMenu.addSeparator(); fileMenu.add(exitMenuItem); menuBar.add(fileMenu); setJMenuBar(menuBar); // finalize UI addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } private void nodeChangedAction() { TreePath path = mainTree.getSelectionPath(); if(path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object obj = node.getUserObject(); if(obj instanceof RrdNode) { RrdNode rrdNode = (RrdNode) obj; inspectorModel.selectModel(rrdNode.getDsIndex(), rrdNode.getArcIndex()); if(rrdNode.getDsIndex() >= 0 && rrdNode.getArcIndex() >= 0) { // archive node if(tabbedPane.getSelectedIndex() < 2) { tabbedPane.setSelectedIndex(2); } } else if(rrdNode.getDsIndex() >= 0) { tabbedPane.setSelectedIndex(1); } else { tabbedPane.setSelectedIndex(0); } } } } private void selectFile() { JFileChooser chooser = new JFileChooser(); FileFilter filter = new FileFilter() { public boolean accept(File f) { return f.isDirectory()? true: f.getAbsolutePath().toLowerCase().endsWith(".rrd"); } public String getDescription() { return "JRobin RRD files"; } }; chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(this); if(returnVal == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); inspectorModel.setFile(file); tabbedPane.setSelectedIndex(0); } } public static void main(String[] args) { new RrdInspector(); } } --- NEW FILE: RrdNode.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.inspector; import org.jrobin.core.*; import java.io.File; import java.io.IOException; class RrdNode { private int dsIndex = -1, arcIndex = -1; private String label; RrdNode(RrdDb rrd) { // header node String path = rrd.getRrdFile().getFilePath(); label = new File(path).getName(); } RrdNode(RrdDb rrd, int dsIndex) throws IOException, RrdException { // datasource node this.dsIndex = dsIndex; RrdDef def = rrd.getRrdDef(); DsDef[] dsDefs = def.getDsDefs(); label = dsDefs[dsIndex].dump(); } RrdNode(RrdDb rrd, int dsIndex, int arcIndex) throws IOException, RrdException { // archive node this.dsIndex = dsIndex; this.arcIndex = arcIndex; ArcDef[] arcDefs = rrd.getRrdDef().getArcDefs(); label = arcDefs[arcIndex].dump(); } int getDsIndex() { return dsIndex; } int getArcIndex() { return arcIndex; } public String toString() { return label; } } |