📄 rrdinspector.java
字号:
/* ============================================================
* JRobin : Pure java implementation of RRDTool's functionality
* ============================================================
*
* Project Info: http://www.jrobin.org
* Project Lead: Sasa Markovic (saxon@jrobin.org);
*
* (C) Copyright 2003, by Sasa Markovic.
*
* Developers: Sasa Markovic (saxon@jrobin.org)
*
*
* 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.*;
import javax.swing.table.DefaultTableCellRenderer;
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;
import java.io.IOException;
/**
* Utility application (swing) to analyze, change and plot content of JRobin RRD files.
*/
public 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 = "JRobinLite project\nRrdInspector utility\n" +
"Copyright (C) 2003-2005 Sasa Markovic. All rights reserved.";
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();
private String lastDirectory = null;
private RrdInspector(String path) {
super(TITLE);
constructUI();
pack();
Util.placeWindow(this);
setVisible(true);
if (path == null) {
selectFile();
}
else {
loadFile(new File(path));
}
}
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);
// 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);
// ARCHIVE TAB
JScrollPane spArchive = new JScrollPane(archiveTable);
archiveTable.setModel(inspectorModel.getArchiveTableModel());
archiveTable.getColumnModel().getColumn(0).setPreferredWidth(150);
archiveTable.getColumnModel().getColumn(0).setMaxWidth(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);
dataTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() {
{
setBackground(Color.YELLOW);
}
});
spData.setPreferredSize(INFO_PANE_SIZE);
tabbedPane.add("Archive data", spData);
content.add(tabbedPane, BorderLayout.CENTER);
////////////////////////////////////////
// MENU
////////////////////////////////////////
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() {
public void actionPerformed(ActionEvent e) {
selectFile();
}
});
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() {
public void actionPerformed(ActionEvent e) {
addDatasource();
}
});
fileMenu.add(addDatasourceMenuItem);
// Edit datasource
JMenuItem editDatasourceMenuItem = new JMenuItem("Edit datasource...");
editDatasourceMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editDatasource();
}
});
fileMenu.add(editDatasourceMenuItem);
// Remove datasource
JMenuItem removeDatasourceMenuItem = new JMenuItem("Remove datasource");
removeDatasourceMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
removeDatasource();
}
});
fileMenu.add(removeDatasourceMenuItem);
fileMenu.addSeparator();
// Add archive
JMenuItem addArchiveMenuItem = new JMenuItem("Add archive...");
addArchiveMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addArchive();
}
});
fileMenu.add(addArchiveMenuItem);
// Edit archive
JMenuItem editArchiveMenuItem = new JMenuItem("Edit archive...");
editArchiveMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editArchive();
}
});
fileMenu.add(editArchiveMenuItem);
// Remove archive
JMenuItem removeArchiveMenuItem = new JMenuItem("Remove archive...");
removeArchiveMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
removeArchive();
}
});
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() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
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);
}
private void nodeChangedAction() {
RrdNode rrdNode = getSelectedRrdNode();
if (rrdNode != null) {
inspectorModel.selectModel(rrdNode.getDsIndex(), rrdNode.getArcIndex());
if (rrdNode.getDsIndex() >= 0 && rrdNode.getArcIndex() >= 0) {
// archive node
if (tabbedPane.getSelectedIndex() < 2) {
tabbedPane.setSelectedIndex(2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -