/*
* MainResponsePanel.java
*
* Created on 4 May 2005, 01:15
*
* AsItHappens - real-time network monitor
* Copyright (C) 2006 Mark Abrahams
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*/
package nz.co.abrahams.asithappens.response;
import nz.co.abrahams.asithappens.core.DataType;
import nz.co.abrahams.asithappens.storage.DataSets;
import nz.co.abrahams.asithappens.storage.Device;
import nz.co.abrahams.asithappens.collectors.DataCollector;
import nz.co.abrahams.asithappens.snmputil.SNMPException;
import nz.co.abrahams.asithappens.core.DBException;
import nz.co.abrahams.asithappens.core.Configuration;
import nz.co.abrahams.asithappens.cartgraph.TimeSeriesContext;
import nz.co.abrahams.asithappens.cartgraph.DataGraph;
import nz.co.abrahams.asithappens.uiutil.ErrorHandler;
import nz.co.abrahams.asithappens.sdn.SDNContainerPanel;
/**
* The graphical pane for creating Response graphs.
*
* @author mark
*/
public class MainResponsePanel extends javax.swing.JPanel {
/** Creates a new MainResponsePanel form. */
public MainResponsePanel() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
deviceLabel = new javax.swing.JLabel();
deviceField = new javax.swing.JTextField();
pollLabel = new javax.swing.JLabel();
pollField = new javax.swing.JTextField();
pollUnitsLabel = new javax.swing.JLabel();
storeDataCheckBox = new javax.swing.JCheckBox();
responseButton = new javax.swing.JButton();
setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
deviceLabel.setText("Device");
add(deviceLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 50, 20));
add(deviceField, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 10, 120, -1));
pollLabel.setText("Poll Interval");
add(pollLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, 80, 20));
pollField.setText("2000");
add(pollField, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 40, 50, -1));
pollUnitsLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
pollUnitsLabel.setText("ms");
add(pollUnitsLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 40, 20, 20));
storeDataCheckBox.setText("Store collected data");
add(storeDataCheckBox, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 70, 180, -1));
responseButton.setText("Response Graph");
responseButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
responseButtonActionPerformed(evt);
}
});
add(responseButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 105, 180, -1));
}// </editor-fold>//GEN-END:initComponents
/** Creates a new response graph. */
private void responseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_responseButtonActionPerformed
Device device;
int pollInterval;
DataCollector collector;
DataSets data;
TimeSeriesContext context;
DataGraph graphFrame;
try {
//data = new ResponseData(new Device(deviceField.getText()), Integer.parseInt(pollField.getText()) * 1000, "Response Graph", "ms", storeDataCheckBox.isSelected());
device = new Device(deviceField.getText());
//pollInterval = Integer.parseInt(pollField.getText()) * 1000;
pollInterval = Integer.parseInt(pollField.getText());
if ( Configuration.getProperty("collector.response.class").equals("windows") )
collector = new ResponseWindowsCollector(device, pollInterval);
else
collector = new ResponseCollector(device, pollInterval);
data = new DataSets(DataType.RESPONSE, collector, device, pollInterval, null, DataSets.DIRECTION_NONE, null, storeDataCheckBox.isSelected());
context = new TimeSeriesContext(data);
//graphFrame = new DataGraph(context);
graphFrame = new DataGraph(context);
} catch (DBException e) {
ErrorHandler.modalError(null, "Please ensure that database is running and accessible",
"Error opening database connection", e);
} catch (java.net.UnknownHostException e) {
ErrorHandler.modalError(null, "Please ensure that device name \"" + deviceField.getText() + "\" is valid",
"Unknown host " + deviceField.getText());
}
// Should never be thrown for Response data type
catch (SNMPException e) {
ErrorHandler.modalError(null, "Application error",
"Response Graph should not be using SNMP", e);
}
}//GEN-LAST:event_responseButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField deviceField;
private javax.swing.JLabel deviceLabel;
private javax.swing.JTextField pollField;
private javax.swing.JLabel pollLabel;
private javax.swing.JLabel pollUnitsLabel;
private javax.swing.JButton responseButton;
private javax.swing.JCheckBox storeDataCheckBox;
// End of variables declaration//GEN-END:variables
}