/** * Copyright (C) 2012-14 graphene developers. See COPYRIGHT.TXT * All rights reserved. Use is subject to license terms. See LICENSE.TXT */ package org.epics.graphene.rrdtool; import java.awt.image.BufferedImage; import java.text.SimpleDateFormat; import org.epics.graphene.ScatterGraph2DRenderer; import org.epics.util.array.CollectionNumber; import org.epics.util.array.IteratorNumber; import org.epics.util.time.Timestamp; /** * * @author carcassi */ public class ScatterPlot extends javax.swing.JFrame { /** * Creates new form ScatterPlot */ public ScatterPlot() { initComponents(); } SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); /** * 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. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); xFilename = new javax.swing.JTextField(); yFilename = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); startDate = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); endDate = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); imagePanel1 = new org.epics.graphene.rrdtool.ImagePanel(); jScrollPane3 = new javax.swing.JScrollPane(); valuesX = new javax.swing.JTextArea(); jScrollPane4 = new javax.swing.JScrollPane(); valuesY = new javax.swing.JTextArea(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText("x filename:"); jLabel2.setText("y filename:"); xFilename.setText("/media/sf_Shared/dc2-5-17_cpu_system_54823.rrd"); yFilename.setText("/media/sf_Shared/dc2-5-17_cpu_user_54824.rrd"); jLabel3.setText("Start date:"); startDate.setText("01/10/2012"); jLabel4.setText("End date:"); endDate.setText("11/10/2012"); jButton1.setText("Plot"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout imagePanel1Layout = new javax.swing.GroupLayout(imagePanel1); imagePanel1.setLayout(imagePanel1Layout); imagePanel1Layout.setHorizontalGroup( imagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE) ); imagePanel1Layout.setVerticalGroup( imagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 350, Short.MAX_VALUE) ); valuesX.setColumns(20); valuesX.setRows(5); jScrollPane3.setViewportView(valuesX); valuesY.setColumns(20); valuesY.setRows(5); jScrollPane4.setViewportView(valuesY); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addComponent(jLabel1) .addComponent(jLabel3) .addComponent(jLabel4)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(xFilename, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE) .addComponent(yFilename, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(startDate, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(endDate, javax.swing.GroupLayout.Alignment.LEADING))) .addComponent(imagePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 301, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 301, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(xFilename, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(yFilename, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(startDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(endDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(imagePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addComponent(jScrollPane3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane4))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed try { RrdToolReader reader = new RrdToolReader(); Timestamp start = Timestamp.of(format.parse(startDate.getText())); Timestamp end = Timestamp.of(format.parse(endDate.getText())); TimeSeriesMulti xData = reader.readFile(xFilename.getText(), "AVERAGE", start, end); TimeSeriesMulti yData = reader.readFile(yFilename.getText(), "AVERAGE", start, end); // Point2DDataset dataset = Point2DDatasets.lineData(xData.getValues(), yData.getValues()); // valuesX.setText(toText(xData.getValues())); // valuesY.setText(toText(yData.getValues())); BufferedImage image = new BufferedImage(imagePanel1.getWidth(), imagePanel1.getHeight(), BufferedImage.TYPE_3BYTE_BGR); ScatterGraph2DRenderer renderer = new ScatterGraph2DRenderer(imagePanel1.getWidth(), imagePanel1.getHeight()); // renderer.draw(image.createGraphics(), dataset); imagePanel1.setImage(image); } catch(Exception ex) { ex.printStackTrace(); } }//GEN-LAST:event_jButton1ActionPerformed private String toText(CollectionNumber coll) { StringBuilder builder = new StringBuilder(); IteratorNumber iter = coll.iterator(); while (iter.hasNext()) { builder.append(iter.nextDouble()).append("\n"); } return builder.toString(); } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(ScatterPlot.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(ScatterPlot.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(ScatterPlot.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(ScatterPlot.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ScatterPlot().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextField endDate; private org.epics.graphene.rrdtool.ImagePanel imagePanel1; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JScrollPane jScrollPane4; private javax.swing.JTextField startDate; private javax.swing.JTextArea valuesX; private javax.swing.JTextArea valuesY; private javax.swing.JTextField xFilename; private javax.swing.JTextField yFilename; // End of variables declaration//GEN-END:variables }