From: Sasa M. <sa...@us...> - 2004-08-27 09:42:54
|
Update of /cvsroot/jrobin/src/org/jrobin/inspector In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24887/org/jrobin/inspector Modified Files: ArchiveTableModel.java DataTableModel.java DatasourceTableModel.java EditArchiveDialog.java EditDatasourceDialog.java HeaderTableModel.java MainTreeModel.java RrdInspector.java Util.java Log Message: Major RRDInspector changes: - archived values are editable - archived values can be plotted - multiple RRDs/plots can be open Index: EditDatasourceDialog.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/EditDatasourceDialog.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EditDatasourceDialog.java 9 Dec 2003 12:22:04 -0000 1.1 --- EditDatasourceDialog.java 27 Aug 2004 09:42:43 -0000 1.2 *************** *** 198,202 **** catch(RrdException e) { // should not be hear ever! ! e.printStackTrace(); return null; } --- 198,202 ---- catch(RrdException e) { // should not be hear ever! ! Util.error(this, e); return null; } Index: Util.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/Util.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Util.java 9 Dec 2003 12:22:04 -0000 1.1 --- Util.java 27 Aug 2004 09:42:43 -0000 1.2 *************** *** 27,30 **** --- 27,31 ---- import javax.swing.*; import java.awt.*; + import java.util.Vector; class Util { *************** *** 41,43 **** --- 42,73 ---- 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); + } + } } Index: DataTableModel.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/DataTableModel.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DataTableModel.java 18 Aug 2004 12:51:26 -0000 1.6 --- DataTableModel.java 27 Aug 2004 09:42:43 -0000 1.7 *************** *** 64,67 **** --- 64,94 ---- } + 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; *************** *** 94,101 **** } catch (IOException e) { ! e.printStackTrace(); } catch (RrdException e) { ! e.printStackTrace(); } } --- 121,128 ---- } catch (IOException e) { ! Util.error(null, e); } catch (RrdException e) { ! Util.error(null, e); } } Index: MainTreeModel.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/MainTreeModel.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MainTreeModel.java 18 Aug 2004 12:51:27 -0000 1.6 --- MainTreeModel.java 27 Aug 2004 09:42:43 -0000 1.7 *************** *** 66,71 **** --- 66,73 ---- } catch (IOException e) { setRoot(INVALID_NODE); + Util.error(null, e); } catch (RrdException e) { setRoot(INVALID_NODE); + Util.error(null, e); } return false; Index: EditArchiveDialog.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/EditArchiveDialog.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EditArchiveDialog.java 9 Dec 2003 12:22:04 -0000 1.1 --- EditArchiveDialog.java 27 Aug 2004 09:42:43 -0000 1.2 *************** *** 190,194 **** catch(RrdException e) { // should not be hear ever! ! e.printStackTrace(); return null; } --- 190,194 ---- catch(RrdException e) { // should not be hear ever! ! Util.error(this, e); return null; } Index: DatasourceTableModel.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/DatasourceTableModel.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DatasourceTableModel.java 18 Aug 2004 12:51:26 -0000 1.6 --- DatasourceTableModel.java 27 Aug 2004 09:42:43 -0000 1.7 *************** *** 34,40 **** 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; --- 34,44 ---- 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; *************** *** 69,72 **** --- 73,80 ---- } + public boolean isCellEditable(int rowIndex, int columnIndex) { + return false; + } + void setFile(File newFile) { file = newFile; *************** *** 95,102 **** } catch (IOException e) { ! e.printStackTrace(); } catch (RrdException e) { ! e.printStackTrace(); } } --- 103,110 ---- } catch (IOException e) { ! Util.error(null, e); } catch (RrdException e) { ! Util.error(null, e); } } Index: ArchiveTableModel.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/ArchiveTableModel.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ArchiveTableModel.java 18 Aug 2004 12:51:26 -0000 1.6 --- ArchiveTableModel.java 27 Aug 2004 09:42:42 -0000 1.7 *************** *** 98,105 **** } catch (IOException e) { ! e.printStackTrace(); } catch (RrdException e) { ! e.printStackTrace(); } } --- 98,105 ---- } catch (IOException e) { ! Util.error(null, e); } catch (RrdException e) { ! Util.error(null, e); } } Index: RrdInspector.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/RrdInspector.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RrdInspector.java 18 Aug 2004 12:51:27 -0000 1.7 --- RrdInspector.java 27 Aug 2004 09:42:43 -0000 1.8 *************** *** 29,32 **** --- 29,33 ---- import javax.swing.*; + import javax.swing.table.DefaultTableCellRenderer; import javax.swing.filechooser.FileFilter; import javax.swing.event.TreeSelectionListener; *************** *** 41,50 **** class RrdInspector extends JFrame { static final String TITLE = "RRD File Inspector"; static final boolean SHOULD_FIX_ARCHIVED_VALUES = false; ! static final boolean SHOULD_CREATE_BACKUPS = true; ! ! static Dimension MAIN_TREE_SIZE = new Dimension(250, 400); ! static Dimension INFO_PANE_SIZE = new Dimension(450, 400); JTabbedPane tabbedPane = new JTabbedPane(); --- 42,52 ---- class RrdInspector extends JFrame { + static final boolean SHOULD_CREATE_BACKUPS = true; static final String TITLE = "RRD File Inspector"; static final boolean SHOULD_FIX_ARCHIVED_VALUES = false; ! static final Dimension MAIN_TREE_SIZE = new Dimension(250, 400); ! static final Dimension INFO_PANE_SIZE = new Dimension(450, 400); ! static final String ABOUT = "JRobin project\nRrdInspector utility\n" + ! "Copyright (C) 2003-2004 Sasa Markovic, Arne Vandamme"; JTabbedPane tabbedPane = new JTabbedPane(); *************** *** 62,66 **** super(TITLE); constructUI(); ! showCentered(); if(path == null) { selectFile(); --- 64,70 ---- super(TITLE); constructUI(); ! pack(); ! Util.placeWindow(this); ! setVisible(true); if(path == null) { selectFile(); *************** *** 71,84 **** } - 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(); --- 75,78 ---- *************** *** 134,137 **** --- 128,134 ---- dataTable.getColumnModel().getColumn(0).setMaxWidth(100); dataTable.getColumnModel().getColumn(1).setPreferredWidth(150); + dataTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() { + { setBackground(Color.YELLOW); } + }); spData.setPreferredSize(INFO_PANE_SIZE); tabbedPane.add("Archive data", spData); *************** *** 143,149 **** //////////////////////////////////////// JMenuBar menuBar = new JMenuBar(); ! // FILE JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); JMenuItem fileMenuItem = new JMenuItem("Open RRD file...", KeyEvent.VK_O); fileMenuItem.addActionListener(new ActionListener() { --- 140,149 ---- //////////////////////////////////////// JMenuBar menuBar = new JMenuBar(); ! ! // FILE MENU JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); + + // Open file JMenuItem fileMenuItem = new JMenuItem("Open RRD file...", KeyEvent.VK_O); fileMenuItem.addActionListener(new ActionListener() { *************** *** 153,157 **** --- 153,168 ---- }); fileMenu.add(fileMenuItem); + + // Open file in new window + JMenuItem fileMenuItem2 = new JMenuItem("Open RRD file in new window..."); + fileMenuItem2.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + new RrdInspector(null); + } + }); + fileMenu.add(fileMenuItem2); fileMenu.addSeparator(); + + // Add datasource JMenuItem addDatasourceMenuItem = new JMenuItem("Add datasource..."); addDatasourceMenuItem.addActionListener(new ActionListener() { *************** *** 161,164 **** --- 172,177 ---- }); fileMenu.add(addDatasourceMenuItem); + + // Edit datasource JMenuItem editDatasourceMenuItem = new JMenuItem("Edit datasource..."); editDatasourceMenuItem.addActionListener(new ActionListener() { *************** *** 168,171 **** --- 181,186 ---- }); fileMenu.add(editDatasourceMenuItem); + + // Remove datasource JMenuItem removeDatasourceMenuItem = new JMenuItem("Remove datasource"); removeDatasourceMenuItem.addActionListener(new ActionListener() { *************** *** 176,179 **** --- 191,196 ---- fileMenu.add(removeDatasourceMenuItem); fileMenu.addSeparator(); + + // Add archive JMenuItem addArchiveMenuItem = new JMenuItem("Add archive..."); addArchiveMenuItem.addActionListener(new ActionListener() { *************** *** 183,186 **** --- 200,205 ---- }); fileMenu.add(addArchiveMenuItem); + + // Edit archive JMenuItem editArchiveMenuItem = new JMenuItem("Edit archive..."); editArchiveMenuItem.addActionListener(new ActionListener() { *************** *** 190,193 **** --- 209,214 ---- }); fileMenu.add(editArchiveMenuItem); + + // Remove archive JMenuItem removeArchiveMenuItem = new JMenuItem("Remove archive..."); removeArchiveMenuItem.addActionListener(new ActionListener() { *************** *** 197,201 **** --- 218,233 ---- }); fileMenu.add(removeArchiveMenuItem); + + // Plot archive values + JMenuItem plotArchiveMenuItem = new JMenuItem("Plot archive values..."); + plotArchiveMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + plotArchive(); + } + }); + fileMenu.add(plotArchiveMenuItem); fileMenu.addSeparator(); + + // Exit JMenuItem exitMenuItem = new JMenuItem("Exit", KeyEvent.VK_X); exitMenuItem.addActionListener(new ActionListener() { *************** *** 205,218 **** }); fileMenu.add(exitMenuItem); menuBar.add(fileMenu); setJMenuBar(menuBar); // finalize UI addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { ! System.exit(0); } }); } --- 237,273 ---- }); fileMenu.add(exitMenuItem); + + // HELP MENU + JMenu helpMenu = new JMenu("Help"); + fileMenu.setMnemonic(KeyEvent.VK_H); + + // About + JMenuItem aboutMenuItem = new JMenuItem("About..."); + aboutMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + about(); + } + }); + helpMenu.add(aboutMenuItem); + menuBar.add(fileMenu); + menuBar.add(helpMenu); setJMenuBar(menuBar); // finalize UI + setDefaultCloseOperation(DISPOSE_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { ! closeWindow(); } }); + } + + private void closeWindow() { + Util.dismissWindow(this); + } + private void about() { + JOptionPane.showMessageDialog(this, ABOUT, "About", JOptionPane.INFORMATION_MESSAGE); } *************** *** 293,299 **** tabbedPane.setSelectedIndex(0); } catch (IOException e) { ! Util.error(this, e.toString()); } catch (RrdException e) { ! Util.error(this, e.toString()); } } --- 348,354 ---- tabbedPane.setSelectedIndex(0); } catch (IOException e) { ! Util.error(this, e); } catch (RrdException e) { ! Util.error(this, e); } } *************** *** 315,321 **** tabbedPane.setSelectedIndex(0); } catch (IOException e) { ! Util.error(this, e.toString()); } catch (RrdException e) { ! Util.error(this, e.toString()); } } --- 370,376 ---- tabbedPane.setSelectedIndex(0); } catch (IOException e) { ! Util.error(this, e); } catch (RrdException e) { ! Util.error(this, e); } } *************** *** 351,357 **** rrd.close(); } catch (IOException e) { ! Util.error(this, e.toString()); } catch (RrdException e) { ! Util.error(this, e.toString()); } } --- 406,412 ---- rrd.close(); } catch (IOException e) { ! Util.error(this, e); } catch (RrdException e) { ! Util.error(this, e); } } *************** *** 388,394 **** rrd.close(); } catch (IOException e) { ! Util.error(this, e.toString()); } catch (RrdException e) { ! Util.error(this, e.toString()); } } --- 443,449 ---- rrd.close(); } catch (IOException e) { ! Util.error(this, e); } catch (RrdException e) { ! Util.error(this, e); } } *************** *** 415,421 **** tabbedPane.setSelectedIndex(0); } catch (IOException e) { ! Util.error(this, e.toString()); } catch (RrdException e) { ! Util.error(this, e.toString()); } } --- 470,476 ---- tabbedPane.setSelectedIndex(0); } catch (IOException e) { ! Util.error(this, e); } catch (RrdException e) { ! Util.error(this, e); } } *************** *** 444,453 **** tabbedPane.setSelectedIndex(0); } catch (IOException e) { ! Util.error(this, e.toString()); } catch (RrdException e) { ! Util.error(this, e.toString()); } } private static void printUsageAndExit() { System.err.println("usage: " + RrdInspector.class.getName() + " [<filename>]"); --- 499,524 ---- tabbedPane.setSelectedIndex(0); } catch (IOException e) { ! Util.error(this, e); } catch (RrdException e) { ! Util.error(this, e); } } + private void plotArchive() { + if (!inspectorModel.isOk()) { + Util.error(this, "Open a valid RRD file first."); + return; + } + RrdNode rrdNode = getSelectedRrdNode(); + int arcIndex = -1; + if(rrdNode == null || (arcIndex = rrdNode.getArcIndex()) < 0) { + Util.error(this, "Select archive first"); + return; + } + String sourcePath = inspectorModel.getFile().getAbsolutePath(); + int dsIndex = rrdNode.getDsIndex(); + new GraphFrame(sourcePath, dsIndex, arcIndex); + } + private static void printUsageAndExit() { System.err.println("usage: " + RrdInspector.class.getName() + " [<filename>]"); Index: HeaderTableModel.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/HeaderTableModel.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** HeaderTableModel.java 18 Aug 2004 12:51:26 -0000 1.7 --- HeaderTableModel.java 27 Aug 2004 09:42:43 -0000 1.8 *************** *** 68,71 **** --- 68,73 ---- } + + void setFile(File newFile) { try { *************** *** 88,94 **** fireTableDataChanged(); } catch (IOException e) { ! e.printStackTrace(); } catch (RrdException e) { ! e.printStackTrace(); } } --- 90,96 ---- fireTableDataChanged(); } catch (IOException e) { ! Util.error(null, e); } catch (RrdException e) { ! Util.error(null, e); } } |