/* * MainFrame.java * * Created on June 13, 2002, 10:03 PM */ package readstardump; import javax.swing.*; import java.io.*; import jas.hist.*; import java.awt.*; /** * * @author karlen * @version */ public class MainFrame extends javax.swing.JFrame { File directory = null; File readFile = null; StarDumpData starDumpData; /** Creates new form MainFrame */ public MainFrame() { initComponents (); readButton.setEnabled(false); // can't read until file specified plotButton.setEnabled(false); // can't plot until successful read adcComboBox.addItem("A"); adcComboBox.addItem("B"); for (int i=0; i<36; i++) locComboBox.addItem(new Integer(i)); for (int i=0; i<16; i++) pinComboBox.addItem(new Integer(i)); adcComboBox.setSelectedIndex(0); locComboBox.setSelectedIndex(0); pinComboBox.setSelectedIndex(0); pack (); } /** 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 FormEditor. */ private void initComponents() {//GEN-BEGIN:initComponents filePanel = new javax.swing.JPanel(); fileLabel = new javax.swing.JLabel(); fileField = new javax.swing.JTextField(); fileButton = new javax.swing.JButton(); jSeparator1 = new javax.swing.JSeparator(); timeLabel = new javax.swing.JLabel(); timeField = new javax.swing.JTextField(); jSeparator2 = new javax.swing.JSeparator(); readButton = new javax.swing.JButton(); plotOptionsPanel = new javax.swing.JPanel(); locLabel = new javax.swing.JLabel(); locComboBox = new javax.swing.JComboBox(); adcLabel = new javax.swing.JLabel(); adcComboBox = new javax.swing.JComboBox(); pinLabel = new javax.swing.JLabel(); pinComboBox = new javax.swing.JComboBox(); jSeparator3 = new javax.swing.JSeparator(); plotButton = new javax.swing.JButton(); jasPanel = new javax.swing.JPanel(); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); fileLabel.setText("File: "); filePanel.add(fileLabel); fileField.setEditable(false); fileField.setText("not yet specified"); fileField.setMinimumSize(new java.awt.Dimension(150, 20)); fileField.setPreferredSize(new java.awt.Dimension(150, 20)); filePanel.add(fileField); fileButton.setFont(new java.awt.Font("Dialog", 0, 10)); fileButton.setText("change"); fileButton.setMaximumSize(new java.awt.Dimension(71, 20)); fileButton.setMinimumSize(new java.awt.Dimension(71, 20)); fileButton.setPreferredSize(new java.awt.Dimension(71, 20)); fileButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { fileButtonActionPerformed(evt); } }); filePanel.add(fileButton); jSeparator1.setMinimumSize(new java.awt.Dimension(10, 0)); jSeparator1.setPreferredSize(new java.awt.Dimension(10, 0)); filePanel.add(jSeparator1); timeLabel.setText("Time bins:"); filePanel.add(timeLabel); timeField.setText("100"); timeField.setMinimumSize(new java.awt.Dimension(30, 20)); timeField.setPreferredSize(new java.awt.Dimension(30, 20)); filePanel.add(timeField); jSeparator2.setMinimumSize(new java.awt.Dimension(10, 0)); jSeparator2.setPreferredSize(new java.awt.Dimension(10, 0)); filePanel.add(jSeparator2); readButton.setFont(new java.awt.Font("Dialog", 0, 10)); readButton.setText("read data"); readButton.setMaximumSize(new java.awt.Dimension(81, 20)); readButton.setMinimumSize(new java.awt.Dimension(81, 20)); readButton.setPreferredSize(new java.awt.Dimension(81, 20)); readButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { readButtonActionPerformed(evt); } }); filePanel.add(readButton); getContentPane().add(filePanel, java.awt.BorderLayout.NORTH); locLabel.setText("Loc:"); plotOptionsPanel.add(locLabel); locComboBox.setMinimumSize(new java.awt.Dimension(60, 20)); locComboBox.setPreferredSize(new java.awt.Dimension(60, 20)); plotOptionsPanel.add(locComboBox); adcLabel.setText("ADC:"); plotOptionsPanel.add(adcLabel); adcComboBox.setMinimumSize(new java.awt.Dimension(40, 20)); adcComboBox.setPreferredSize(new java.awt.Dimension(40, 20)); plotOptionsPanel.add(adcComboBox); pinLabel.setText("Pin:"); plotOptionsPanel.add(pinLabel); pinComboBox.setMinimumSize(new java.awt.Dimension(60, 20)); pinComboBox.setName("null"); pinComboBox.setPreferredSize(new java.awt.Dimension(60, 20)); plotOptionsPanel.add(pinComboBox); jSeparator3.setMinimumSize(new java.awt.Dimension(10, 0)); jSeparator3.setPreferredSize(new java.awt.Dimension(10, 0)); plotOptionsPanel.add(jSeparator3); plotButton.setFont(new java.awt.Font("Dialog", 0, 10)); plotButton.setText("plot"); plotButton.setMaximumSize(new java.awt.Dimension(60, 20)); plotButton.setMinimumSize(new java.awt.Dimension(60, 20)); plotButton.setPreferredSize(new java.awt.Dimension(60, 20)); plotButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { plotButtonActionPerformed(evt); } }); plotOptionsPanel.add(plotButton); getContentPane().add(plotOptionsPanel, java.awt.BorderLayout.SOUTH); jasPanel.setLayout(new java.awt.BorderLayout()); getContentPane().add(jasPanel, java.awt.BorderLayout.CENTER); }//GEN-END:initComponents private void plotButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_plotButtonActionPerformed // Add your handling code here: int iLoc = locComboBox.getSelectedIndex(); int iADC = adcComboBox.getSelectedIndex(); int iPin = pinComboBox.getSelectedIndex(); if (iLoc >= 0 && iLoc <= 35 && iPin >=0 && iPin <= 15) { starDumpData.setChannel(iLoc,iADC,iPin); JASHist plot = new JASHist(); plot.addData(starDumpData).show(true); jasPanel.removeAll(); jasPanel.add(plot,BorderLayout.CENTER); } }//GEN-LAST:event_plotButtonActionPerformed private void readButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_readButtonActionPerformed // Add your handling code here: int nBin = Integer.valueOf(timeField.getText()).intValue(); starDumpData = new StarDumpData(readFile,nBin); plotButton.setEnabled(starDumpData.isGood()); }//GEN-LAST:event_readButtonActionPerformed private void fileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileButtonActionPerformed // Add your handling code here: JFileChooser chooser = new JFileChooser(); ExampleFileFilter filter = new ExampleFileFilter(); filter.addExtension("dat"); filter.addExtension("irq"); filter.setDescription("STAR dump files"); chooser.setFileFilter(filter); if (directory != null) chooser.setCurrentDirectory(directory); File afile; //********** int returnVal = chooser.showOpenDialog(MainFrame.this); if (returnVal == JFileChooser.APPROVE_OPTION) { readFile= chooser.getSelectedFile(); directory = readFile.getParentFile(); readButton.setEnabled(true); fileField.setText(readFile.toString()); } else { readButton.setEnabled(false); } plotButton.setEnabled(false); }//GEN-LAST:event_fileButtonActionPerformed /** Exit the Application */ private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm System.exit (0); }//GEN-LAST:event_exitForm // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton fileButton; private javax.swing.JTextField fileField; private javax.swing.JSeparator jSeparator2; private javax.swing.JButton readButton; private javax.swing.JButton plotButton; private javax.swing.JLabel timeLabel; private javax.swing.JPanel jasPanel; private javax.swing.JComboBox locComboBox; private javax.swing.JLabel fileLabel; private javax.swing.JLabel adcLabel; private javax.swing.JComboBox pinComboBox; private javax.swing.JComboBox adcComboBox; private javax.swing.JSeparator jSeparator1; private javax.swing.JPanel filePanel; private javax.swing.JTextField timeField; private javax.swing.JPanel plotOptionsPanel; private javax.swing.JSeparator jSeparator3; private javax.swing.JLabel locLabel; private javax.swing.JLabel pinLabel; // End of variables declaration//GEN-END:variables }