From: Tarus B. <ta...@us...> - 2006-12-21 18:02:49
|
Update of /cvsroot/jrobin/src/org/jrobin/inspector In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9082/org/jrobin/inspector Modified Files: ArchiveTableModel.java DataTableModel.java DatasourceTableModel.java EditArchiveDialog.java EditDatasourceDialog.java GraphFrame.java HeaderTableModel.java InspectorModel.java MainTreeModel.java RrdInspector.java RrdNode.java Util.java Log Message: Adding the new 1.5.4 code Index: DataTableModel.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/DataTableModel.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DataTableModel.java 27 Aug 2004 09:42:43 -0000 1.7 --- DataTableModel.java 21 Dec 2006 18:02:44 -0000 1.8 *************** *** 1,132 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (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]; ! } ! ! public boolean isCellEditable(int rowIndex, int columnIndex) { ! return columnIndex == 2; ! } ! ! public void setValueAt(Object aValue, int rowIndex, int columnIndex) { ! assert columnIndex == 2: "Column " + columnIndex + " is not editable!"; ! double value; ! try { ! value = Double.parseDouble(aValue.toString()); ! } ! catch (NumberFormatException nfe) { ! value = Double.NaN; ! } ! if(dsIndex >= 0 && arcIndex >= 0 && file != null) { ! try { ! RrdDb rrd = new RrdDb(file.getAbsolutePath()); ! Robin robin = rrd.getArchive(arcIndex).getRobin(dsIndex); ! robin.setValue(rowIndex, value); ! values[rowIndex][2] = InspectorModel.formatDouble(robin.getValue(rowIndex)); ! rrd.close(); ! } ! catch(Exception e) { ! Util.error(null, e); ! } ! } ! } ! ! void setFile(File newFile) { ! 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(), true); ! 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) { ! Util.error(null, e); ! } ! catch (RrdException e) { ! Util.error(null, e); ! } ! } ! fireTableDataChanged(); ! } ! } ! } --- 1,140 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@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]; ! } ! ! public boolean isCellEditable(int rowIndex, int columnIndex) { ! return columnIndex == 2; ! } ! ! public void setValueAt(Object aValue, int rowIndex, int columnIndex) { ! assert columnIndex == 2: "Column " + columnIndex + " is not editable!"; ! double value; ! try { ! value = Double.parseDouble(aValue.toString()); ! } ! catch (NumberFormatException nfe) { ! value = Double.NaN; ! } ! if (dsIndex >= 0 && arcIndex >= 0 && file != null) { ! try { ! RrdDb rrd = new RrdDb(file.getAbsolutePath()); ! try { ! Robin robin = rrd.getArchive(arcIndex).getRobin(dsIndex); ! robin.setValue(rowIndex, value); ! values[rowIndex][2] = InspectorModel.formatDouble(robin.getValue(rowIndex)); ! } ! finally { ! rrd.close(); ! } ! } ! catch (Exception e) { ! Util.error(null, e); ! } ! } ! } ! ! void setFile(File newFile) { ! 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(), true); ! try { ! 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 ! }; ! } ! } ! finally { ! rrd.close(); ! } ! } ! catch (IOException e) { ! Util.error(null, e); ! } ! catch (RrdException e) { ! Util.error(null, e); ! } ! } ! fireTableDataChanged(); ! } ! } ! } Index: MainTreeModel.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/MainTreeModel.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MainTreeModel.java 27 Aug 2004 09:42:43 -0000 1.7 --- MainTreeModel.java 21 Dec 2006 18:02:45 -0000 1.8 *************** *** 1,75 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (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); ! } ! ! boolean setFile(File newFile) { ! try { ! file = newFile; ! RrdDb rrd = new RrdDb(file.getAbsolutePath(), true); ! 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); ! return true; ! } catch (IOException e) { ! setRoot(INVALID_NODE); ! Util.error(null, e); ! } catch (RrdException e) { ! setRoot(INVALID_NODE); ! Util.error(null, e); ! } ! return false; ! } ! } --- 1,78 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@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"); ! ! MainTreeModel() { ! super(INVALID_NODE); ! } ! ! boolean setFile(File file) { ! try { ! RrdDb rrd = new RrdDb(file.getAbsolutePath(), true); ! try { ! 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); ! } ! setRoot(root); ! } ! finally { ! rrd.close(); ! } ! return true; ! } ! catch (IOException e) { ! setRoot(INVALID_NODE); ! Util.error(null, e); ! } ! catch (RrdException e) { ! setRoot(INVALID_NODE); ! Util.error(null, e); ! } ! return false; ! } ! } Index: DatasourceTableModel.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/DatasourceTableModel.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DatasourceTableModel.java 27 Aug 2004 09:42:43 -0000 1.7 --- DatasourceTableModel.java 21 Dec 2006 18:02:44 -0000 1.8 *************** *** 1,114 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (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]; ! } ! ! public boolean isCellEditable(int rowIndex, int columnIndex) { ! return false; ! } ! ! void setFile(File newFile) { ! 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(), true); ! 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) { ! Util.error(null, e); ! } ! catch (RrdException e) { ! Util.error(null, e); ! } ! } ! fireTableDataChanged(); ! } ! } } \ No newline at end of file --- 1,118 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@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]; ! } ! ! public boolean isCellEditable(int rowIndex, int columnIndex) { ! return false; ! } ! ! void setFile(File newFile) { ! 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(), true); ! try { ! 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() ! }; ! } ! finally { ! rrd.close(); ! } ! } ! catch (IOException e) { ! Util.error(null, e); ! } ! catch (RrdException e) { ! Util.error(null, e); ! } ! } ! fireTableDataChanged(); ! } ! } } \ No newline at end of file Index: RrdNode.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/RrdNode.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdNode.java 20 May 2004 10:29:33 -0000 1.3 --- RrdNode.java 21 Dec 2006 18:02:45 -0000 1.4 *************** *** 1,70 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (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.getRrdBackend().getPath(); ! 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; ! } ! } --- 1,70 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@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.getRrdBackend().getPath(); ! 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; ! } ! } Index: HeaderTableModel.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/HeaderTableModel.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** HeaderTableModel.java 27 Aug 2004 09:42:43 -0000 1.8 --- HeaderTableModel.java 21 Dec 2006 18:02:45 -0000 1.9 *************** *** 1,97 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (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) { ! try { ! file = newFile; ! values = null; ! String path = file.getAbsolutePath(); ! RrdDb rrd = new RrdDb(path, true); ! 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.getRrdBackend().getLength() + " bytes"; ! rrd.close(); ! values = new Object[]{ ! path, signature, step, lastTimestamp, datasources, archives, size ! }; ! fireTableDataChanged(); ! } catch (IOException e) { ! Util.error(null, e); ! } catch (RrdException e) { ! Util.error(null, e); ! } ! } } \ No newline at end of file --- 1,104 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@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 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 file) { ! try { ! values = null; ! String path = file.getAbsolutePath(); ! RrdDb rrd = new RrdDb(path, true); ! try { ! 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.getRrdBackend().getLength() + " bytes"; ! values = new Object[] { ! path, signature, step, lastTimestamp, datasources, archives, size ! }; ! } ! finally { ! rrd.close(); ! } ! fireTableDataChanged(); ! } ! catch (IOException e) { ! Util.error(null, e); ! } ! catch (RrdException e) { ! Util.error(null, e); ! } ! } } \ No newline at end of file Index: GraphFrame.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/GraphFrame.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GraphFrame.java 18 Sep 2004 12:10:29 -0000 1.2 --- GraphFrame.java 21 Dec 2006 18:02:44 -0000 1.3 *************** *** 1,266 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (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 org.jrobin.graph.RrdGraphDef; ! import org.jrobin.graph.RrdGraph; ! import org.jrobin.graph.LinearInterpolator; ! ! import javax.swing.*; ! import javax.swing.filechooser.FileFilter; ! import java.awt.*; ! import java.awt.event.*; ! import java.io.IOException; ! import java.io.File; ! import java.util.Date; ! ! class GraphFrame extends JFrame { ! private static final Color COLOR = Color.RED; ! private static final int WIDTH = 400, HEIGHT = 240; ! ! private Color color = COLOR; ! private GraphPanel graphPanel = new GraphPanel(); ! private JComboBox graphCombo = new JComboBox(); ! private RrdGraph rrdGraph; ! ! private String sourcePath, dsName; ! private int dsIndex, arcIndex; ! private long t1, t2; ! ! GraphFrame(String sourcePath, int dsIndex, int arcIndex) { ! this.sourcePath = sourcePath; ! this.dsIndex = dsIndex; ! this.arcIndex = arcIndex; ! createRrdGraph(); ! fillGraphCombo(); ! constructUI(); ! pack(); ! Util.placeWindow(this); ! setVisible(true); ! } ! ! private void createRrdGraph() { ! try { ! RrdDb rrdDb = new RrdDb(sourcePath, true); ! Datasource ds = rrdDb.getDatasource(dsIndex); ! Archive arc = rrdDb.getArchive(arcIndex); ! Robin robin = arc.getRobin(dsIndex); ! dsName = ds.getDsName(); ! t1 = arc.getStartTime(); ! t2 = arc.getEndTime(); ! long step = arc.getArcStep(); ! int count = robin.getSize(); ! long[] timestamps = new long[count]; ! for(int i = 0; i < count; i++) { ! timestamps[i] = t1 + i * step; ! } ! double[] values = robin.getValues(); ! RrdDef rrdDef = rrdDb.getRrdDef(); ! rrdDb.close(); ! RrdGraphDef rrdGraphDef = new RrdGraphDef(t1, t2); ! rrdGraphDef.setTitle(rrdDef.getDsDefs()[dsIndex].dump() + " " + ! rrdDef.getArcDefs()[arcIndex].dump()); ! LinearInterpolator linearInterpolator = new LinearInterpolator(timestamps, values); ! linearInterpolator.setInterpolationMethod(LinearInterpolator.INTERPOLATE_RIGHT); ! rrdGraphDef.datasource(dsName, linearInterpolator); ! rrdGraphDef.area(dsName, color, dsName + "@r"); ! rrdGraphDef.comment("START: " + new Date(t1 * 1000L) + "@r"); ! rrdGraphDef.comment("END: " + new Date(t2 * 1000L) + "@r"); ! rrdGraph = new RrdGraph(rrdGraphDef); ! rrdGraph.specifyImageSize(true); ! } catch (IOException e) { ! Util.error(this, e); ! } catch (RrdException e) { ! Util.error(this, e); ! } ! } ! ! private void fillGraphCombo() { ! try { ! RrdDb rrdDb = new RrdDb(sourcePath, true); ! RrdDef rrdDef = rrdDb.getRrdDef(); ! final DsDef[] dsDefs = rrdDef.getDsDefs(); ! final ArcDef[] arcDefs = rrdDef.getArcDefs(); ! GraphComboItem[] items = new GraphComboItem[rrdDef.getDsCount() * rrdDef.getArcCount()]; ! int selectedItem = -1; ! for(int i = 0, k = 0; i < rrdDef.getDsCount(); i++) { ! for(int j = 0; j < rrdDef.getArcCount(); k++, j++) { ! String description = dsDefs[i].dump() + " " + arcDefs[j].dump(); ! items[k] = new GraphComboItem(description, i, j); ! if(i == dsIndex && j == arcIndex) { ! selectedItem = k; ! } ! } ! } ! graphCombo.setModel(new DefaultComboBoxModel(items)); ! graphCombo.setSelectedIndex(selectedItem); ! } ! catch (IOException e) { ! Util.error(this, e); ! } ! catch (RrdException e) { ! Util.error(this, e); ! } ! } ! ! private void constructUI() { ! setTitle(new File(sourcePath).getName()); ! JPanel content = (JPanel) getContentPane(); ! content.setLayout(new BorderLayout(3, 3)); ! content.add(graphCombo, BorderLayout.NORTH); ! graphPanel.setPreferredSize(new Dimension(WIDTH, HEIGHT)); ! content.add(graphPanel, BorderLayout.CENTER); ! JPanel southPanel = new JPanel(); ! southPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); ! JButton colorButton = new JButton("Change graph color"); ! southPanel.add(colorButton); ! colorButton.addActionListener(new ActionListener() { ! public void actionPerformed(ActionEvent e) { ! changeColor(); ! } ! }); ! JButton saveButton = new JButton("Save graph"); ! saveButton.addActionListener(new ActionListener() { ! public void actionPerformed(ActionEvent e) { ! saveGraph(); ! } ! }); ! southPanel.add(Box.createHorizontalStrut(3)); ! southPanel.add(saveButton); ! content.add(southPanel, BorderLayout.SOUTH); ! // EVENT HANDLERS ! setDefaultCloseOperation(DISPOSE_ON_CLOSE); ! addWindowListener(new WindowAdapter() { ! public void windowClosing(WindowEvent e) { ! closeWindow(); ! } ! }); ! graphCombo.addItemListener(new ItemListener() { ! public void itemStateChanged(ItemEvent e) { ! if(e.getStateChange() == ItemEvent.SELECTED) { ! GraphComboItem item = (GraphComboItem) e.getItem(); ! dsIndex = item.getDsIndex(); ! arcIndex = item.getArcIndex(); ! createRrdGraph(); ! graphPanel.repaint(); ! } ! } ! }); ! } ! ! private void closeWindow() { ! Util.dismissWindow(this); ! } ! ! private void changeColor() { ! final JColorChooser picker = new JColorChooser(color); ! ActionListener okListener = new ActionListener() { ! public void actionPerformed(ActionEvent e) { ! color = picker.getColor(); ! createRrdGraph(); ! graphPanel.repaint(); ! } ! }; ! JColorChooser.createDialog(this, "Select color", true, picker, okListener, null).show(); ! } ! ! private void saveGraph() { ! JFileChooser chooser = new JFileChooser(); ! FileFilter filter = new FileFilter() { ! public boolean accept(File f) { ! return f.isDirectory()? true: ! f.getAbsolutePath().toLowerCase().endsWith(".png"); ! } ! public String getDescription() { ! return "PNG images"; ! } ! }; ! chooser.setFileFilter(filter); ! int returnVal = chooser.showSaveDialog(this); ! if(returnVal == JFileChooser.APPROVE_OPTION) { ! try { ! File selectedFile = chooser.getSelectedFile(); ! String path = selectedFile.getAbsolutePath(); ! if(!path.toLowerCase().endsWith(".png")) { ! path += ".png"; ! selectedFile = new File(path); ! } ! if(selectedFile.exists()) { ! // ask user to overwrite ! String message = "File [" + selectedFile.getName() + ! "] already exists. Do you want to overwrite it?"; ! int answer = JOptionPane.showConfirmDialog(this, ! message, "File exists", JOptionPane.YES_NO_OPTION); ! if(answer == JOptionPane.NO_OPTION) { ! return; ! } ! } ! rrdGraph.saveAsPNG(selectedFile.getAbsolutePath(), ! graphPanel.getWidth(), graphPanel.getHeight()); ! } catch (IOException e) { ! Util.error(this, "Could not save graph to file:\n" + e); ! } ! catch (RrdException e) { ! Util.error(this, "Could not save graph to file:\n" + e); ! } ! } ! } ! ! class GraphPanel extends JPanel { ! public void paintComponent(Graphics g) { ! try { ! rrdGraph.renderImage((Graphics2D) g, getWidth(), getHeight()); ! } catch (RrdException e) { ! Util.error(this, e); ! } catch (IOException e) { ! Util.error(this, e); ! } ! } ! } ! ! class GraphComboItem { ! private String description; ! private int dsIndex, arcIndex; ! ! GraphComboItem(String description, int dsIndex, int arcIndex) { ! this.description = description; ! this.dsIndex = dsIndex; ! this.arcIndex = arcIndex; ! } ! ! public String toString() { ! return description; ! } ! ! int getDsIndex() { ! return dsIndex; ! } ! ! int getArcIndex() { ! return arcIndex; ! } ! } ! } --- 1,302 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@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 org.jrobin.graph.RrdGraphDef; ! import org.jrobin.graph.RrdGraph; ! import org.jrobin.graph.RrdGraphInfo; ! import org.jrobin.data.LinearInterpolator; ! ! import javax.swing.*; ! import javax.swing.filechooser.FileFilter; ! import java.awt.*; ! import java.awt.event.*; ! import java.io.IOException; ! import java.io.File; ! import java.io.RandomAccessFile; ! import java.util.Date; ! ! class GraphFrame extends JFrame { ! private static final Color COLOR = Color.RED; ! private static final int WIDTH = 400, HEIGHT = 240; ! private int deltaWidth = 0, deltaHeight = 0; ! ! private Color color = COLOR; ! private GraphPanel graphPanel = new GraphPanel(); ! private JComboBox graphCombo = new JComboBox(); ! private RrdGraph rrdGraph; ! ! private String sourcePath; ! private int dsIndex, arcIndex; ! ! GraphFrame(String sourcePath, int dsIndex, int arcIndex) { ! this.sourcePath = sourcePath; ! this.dsIndex = dsIndex; ! this.arcIndex = arcIndex; ! fillGraphCombo(); ! constructUI(); ! pack(); ! //createRrdGraph(); ! Util.placeWindow(this); ! setVisible(true); ! } ! ! private void createRrdGraph() { ! //System.out.println("Creating graph..."); ! try { ! RrdDb rrdDb = new RrdDb(sourcePath, true); ! RrdDef rrdDef; ! long[] timestamps; ! double[] values; ! String dsName; ! long t1, t2; ! try { ! Datasource ds = rrdDb.getDatasource(dsIndex); ! Archive arc = rrdDb.getArchive(arcIndex); ! Robin robin = arc.getRobin(dsIndex); ! dsName = ds.getDsName(); ! t1 = arc.getStartTime(); ! t2 = arc.getEndTime(); ! long step = arc.getArcStep(); ! int count = robin.getSize(); ! timestamps = new long[count]; ! for (int i = 0; i < count; i++) { ! timestamps[i] = t1 + i * step; ! } ! values = robin.getValues(); ! rrdDef = rrdDb.getRrdDef(); ! } ! finally { ! rrdDb.close(); ! } ! RrdGraphDef rrdGraphDef = new RrdGraphDef(); ! rrdGraphDef.setTimeSpan(t1, t2); ! rrdGraphDef.setImageFormat("png"); ! rrdGraphDef.setTitle(rrdDef.getDsDefs()[dsIndex].dump() + " " + ! rrdDef.getArcDefs()[arcIndex].dump()); ! LinearInterpolator linearInterpolator = new LinearInterpolator(timestamps, values); ! linearInterpolator.setInterpolationMethod(LinearInterpolator.INTERPOLATE_RIGHT); ! rrdGraphDef.datasource(dsName, linearInterpolator); ! rrdGraphDef.area(dsName, color, dsName + "\\r"); ! rrdGraphDef.comment("START: " + new Date(t1 * 1000L) + "\\r"); ! rrdGraphDef.comment("END: " + new Date(t2 * 1000L) + "\\r"); ! int width = graphPanel.getWidth(), height = graphPanel.getHeight(); ! rrdGraphDef.setWidth(width + deltaWidth); ! rrdGraphDef.setHeight(height + deltaHeight); ! rrdGraph = new RrdGraph(rrdGraphDef); ! if (deltaWidth == 0 && deltaHeight == 0) { ! RrdGraphInfo info = rrdGraph.getRrdGraphInfo(); ! deltaWidth = graphPanel.getWidth() - info.getWidth(); ! deltaHeight = graphPanel.getHeight() - info.getHeight(); ! if (deltaWidth != 0 && deltaHeight != 0) { ! createRrdGraph(); // recursion is divine! ! } ! } ! } ! catch (IOException e) { ! Util.error(this, e); ! } ! catch (RrdException e) { ! Util.error(this, e); ! } ! } ! ! private void fillGraphCombo() { ! try { ! RrdDb rrdDb = new RrdDb(sourcePath, true); ! try { ! RrdDef rrdDef = rrdDb.getRrdDef(); ! final DsDef[] dsDefs = rrdDef.getDsDefs(); ! final ArcDef[] arcDefs = rrdDef.getArcDefs(); ! GraphComboItem[] items = new GraphComboItem[rrdDef.getDsCount() * rrdDef.getArcCount()]; ! int selectedItem = -1; ! for (int i = 0, k = 0; i < rrdDef.getDsCount(); i++) { ! for (int j = 0; j < rrdDef.getArcCount(); k++, j++) { ! String description = dsDefs[i].dump() + " " + arcDefs[j].dump(); ! items[k] = new GraphComboItem(description, i, j); ! if (i == dsIndex && j == arcIndex) { ! selectedItem = k; ! } ! } ! } ! graphCombo.setModel(new DefaultComboBoxModel(items)); ! graphCombo.setSelectedIndex(selectedItem); ! } ! finally { ! rrdDb.close(); ! } ! } ! catch (IOException e) { ! Util.error(this, e); ! } ! catch (RrdException e) { ! Util.error(this, e); ! } ! } ! ! private void constructUI() { ! setTitle(new File(sourcePath).getName()); ! JPanel content = (JPanel) getContentPane(); ! content.setLayout(new BorderLayout(0, 0)); ! content.add(graphCombo, BorderLayout.NORTH); ! graphPanel.setPreferredSize(new Dimension(WIDTH, HEIGHT)); ! content.add(graphPanel, BorderLayout.CENTER); ! JPanel southPanel = new JPanel(); ! southPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); ! JButton colorButton = new JButton("Change graph color"); ! southPanel.add(colorButton); ! colorButton.addActionListener(new ActionListener() { ! public void actionPerformed(ActionEvent e) { ! changeColor(); ! } ! }); ! JButton saveButton = new JButton("Save graph"); ! saveButton.addActionListener(new ActionListener() { ! public void actionPerformed(ActionEvent e) { ! saveGraph(); ! } ! }); ! southPanel.add(Box.createHorizontalStrut(3)); ! southPanel.add(saveButton); ! content.add(southPanel, BorderLayout.SOUTH); ! // EVENT HANDLERS ! setDefaultCloseOperation(DISPOSE_ON_CLOSE); ! addWindowListener(new WindowAdapter() { ! public void windowClosing(WindowEvent e) { ! closeWindow(); ! } ! }); ! addComponentListener(new ComponentAdapter() { ! public void componentResized(ComponentEvent e) { ! createRrdGraph(); ! graphPanel.repaint(); ! } ! }); ! graphCombo.addItemListener(new ItemListener() { ! public void itemStateChanged(ItemEvent e) { ! if (e.getStateChange() == ItemEvent.SELECTED) { ! GraphComboItem item = (GraphComboItem) e.getItem(); ! dsIndex = item.getDsIndex(); ! arcIndex = item.getArcIndex(); ! createRrdGraph(); ! graphPanel.repaint(); ! } ! } ! }); ! } ! ! private void closeWindow() { ! Util.dismissWindow(this); ! } ! ! private void changeColor() { ! final JColorChooser picker = new JColorChooser(color); ! ActionListener okListener = new ActionListener() { ! public void actionPerformed(ActionEvent e) { ! color = picker.getColor(); ! createRrdGraph(); ! repaint(); ! } ! }; ! JColorChooser.createDialog(this, "Select color", true, picker, okListener, null).setVisible(true); ! } ! ! private void saveGraph() { ! JFileChooser chooser = new JFileChooser(); ! FileFilter filter = new FileFilter() { ! public boolean accept(File f) { ! return f.isDirectory() || f.getAbsolutePath().toLowerCase().endsWith(".png"); ! } ! ! public String getDescription() { ! return "PNG images"; ! } ! }; ! chooser.setFileFilter(filter); ! int returnVal = chooser.showSaveDialog(this); ! if (returnVal == JFileChooser.APPROVE_OPTION) { ! try { ! File selectedFile = chooser.getSelectedFile(); ! String path = selectedFile.getAbsolutePath(); ! if (!path.toLowerCase().endsWith(".png")) { ! path += ".png"; ! selectedFile = new File(path); ! } ! if (selectedFile.exists()) { ! // ask user to overwrite ! String message = "File [" + selectedFile.getName() + ! "] already exists. Do you want to overwrite it?"; ! int answer = JOptionPane.showConfirmDialog(this, ! message, "File exists", JOptionPane.YES_NO_OPTION); ! if (answer == JOptionPane.NO_OPTION) { ! return; ! } ! } ! String absolutePath = selectedFile.getAbsolutePath(); ! byte[] data = rrdGraph.getRrdGraphInfo().getBytes(); ! RandomAccessFile f = new RandomAccessFile(absolutePath, "rw"); ! try { ! f.write(data); ! } ! finally { ! f.close(); ! } ! } ! catch (IOException e) { ! Util.error(this, "Could not save graph to file:\n" + e); ! } ! } ! } ! ! class GraphPanel extends JPanel { ! public void paintComponent(Graphics g) { ! rrdGraph.render(g); ! } ! } ! ! class GraphComboItem { ! private String description; ! private int dsIndex, arcIndex; ! ! GraphComboItem(String description, int dsIndex, int arcIndex) { ! this.description = description; ! this.dsIndex = dsIndex; ! this.arcIndex = arcIndex; ! } ! ! public String toString() { ! return description; ! } ! ! int getDsIndex() { ! return dsIndex; ! } ! ! int getArcIndex() { ! return arcIndex; ! } ! } ! } Index: Util.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/Util.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Util.java 27 Aug 2004 09:42:43 -0000 1.2 --- Util.java 21 Dec 2006 18:02:45 -0000 1.3 *************** *** 1,73 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (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 java.awt.*; ! import java.util.Vector; ! ! class Util { ! static void centerOnScreen(Window window) { ! Toolkit t = Toolkit.getDefaultToolkit(); ! Dimension screenSize = t.getScreenSize(); ! Dimension frameSize = window.getPreferredSize(); ! double x = (screenSize.getWidth() - frameSize.getWidth()) / 2; ! double y = (screenSize.getHeight() - frameSize.getHeight()) / 2; ! window.setLocation((int) x, (int) y); ! } ! ! static void error(Component parent, String message) { ! JOptionPane.showMessageDialog(parent, message, "Error", JOptionPane.ERROR_MESSAGE); ! } ! ! static void error(Component parent, Exception e) { ! e.printStackTrace(); ! error(parent, e.toString()); ! } ! ! private static Vector windows = new Vector(); ! private static final int WINDOW_POSITION_SHIFT = 20; ! ! static void placeWindow(Window window) { ! int count = windows.size(); ! if(count == 0) { ! centerOnScreen(window); ! } ! else { ! Window last = (Window) windows.get(count - 1); ! int x = last.getX() + WINDOW_POSITION_SHIFT; ! int y = last.getY() + WINDOW_POSITION_SHIFT; ! window.setLocation(x, y); ! } ! windows.add(window); ! } ! ! static void dismissWindow(Window window) { ! windows.remove(window); ! if(windows.size() == 0) { ! System.exit(0); ! } ! } ! } --- 1,73 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@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 java.awt.*; ! import java.util.Vector; ! ! class Util { ! static void centerOnScreen(Window window) { ! Toolkit t = Toolkit.getDefaultToolkit(); ! Dimension screenSize = t.getScreenSize(); ! Dimension frameSize = window.getPreferredSize(); ! double x = (screenSize.getWidth() - frameSize.getWidth()) / 2; ! double y = (screenSize.getHeight() - frameSize.getHeight()) / 2; ! window.setLocation((int) x, (int) y); ! } ! ! static void error(Component parent, String message) { ! JOptionPane.showMessageDialog(parent, message, "Error", JOptionPane.ERROR_MESSAGE); ! } ! ! static void error(Component parent, Exception e) { ! e.printStackTrace(); ! error(parent, e.toString()); ! } ! ! private static Vector<Window> windows = new Vector<Window>(); ! private static final int WINDOW_POSITION_SHIFT = 20; ! ! static void placeWindow(Window window) { ! int count = windows.size(); ! if (count == 0) { ! centerOnScreen(window); ! } ! else { ! Window last = windows.get(count - 1); ! int x = last.getX() + WINDOW_POSITION_SHIFT; ! int y = last.getY() + WINDOW_POSITION_SHIFT; ! window.setLocation(x, y); ! } ! windows.add(window); ! } ! ! static void dismissWindow(Window window) { ! windows.remove(window); ! if (windows.size() == 0) { ! System.exit(0); ! } ! } ! } Index: EditDatasourceDialog.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/EditDatasourceDialog.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EditDatasourceDialog.java 27 Aug 2004 09:42:43 -0000 1.2 --- EditDatasourceDialog.java 21 Dec 2006 18:02:44 -0000 1.3 *************** *** 1,208 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (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.DsDef; ! import org.jrobin.core.RrdException; ! ! import javax.swing.*; ! import java.awt.*; ! import java.awt.event.WindowEvent; ! import java.awt.event.ActionListener; ! import java.awt.event.ActionEvent; ! ! class EditDatasourceDialog extends JDialog { ! private static final int FIELD_SIZE = 20; ! private static final String TITLE_NEW = "New datasource"; ! private static final String TITLE_EDIT = "Edit datasource"; ! ! private JLabel nameLabel = new JLabel("Datasource name: "); ! private JLabel typeLabel = new JLabel("Datasource type: "); ! private JLabel heartbeatLabel = new JLabel("Heartbeat: "); ! private JLabel minLabel = new JLabel("... [truncated message content] |