Puka - Software for Detection of Breaths in Strain Gauge Recordings 1.0.0

File: <base>/sourceCode/subjectData/ViewDatabaseKey.java (6,200 bytes)
/*
 * ViewDatabaseKey.java
 *
 * Created on July 24, 2002, 3:38 PM
 */

package subjectData;

/**
 *
 * @author  Joset A. Etzel
 */
import subjectData.*; import java.sql.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*;
public class ViewDatabaseKey extends javax.swing.JInternalFrame {
    Connection conData; Statement stmSQL;   //variables for sql database access
  /** Creates new form ViewDatabaseKey */
    public ViewDatabaseKey() {
      initComponents();
      //connect to the database
      try { 
				Class.forName("org.gjt.mm.mysql.Driver"); 
				conData = SubjectData.getDatabaseConnection();
      } catch (Exception e) { e.printStackTrace(); }
      ExcelAdapter myAd = new ExcelAdapter(tblKey);  //call code to let the table copy and paste into Excel
      CreateKey();  //call sub to put the info into tblKey
    }

    /** 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.
     */
  private void initComponents() {//GEN-BEGIN:initComponents
    java.awt.GridBagConstraints gridBagConstraints;

    cmdClose = new javax.swing.JButton();
    jLabel1 = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();
    tblKey = new javax.swing.JTable();

    getContentPane().setLayout(new java.awt.GridBagLayout());

    setClosable(true);
    setIconifiable(true);
    setMaximizable(true);
    setResizable(true);
    setTitle("Database Key");
    cmdClose.setText("Close");
    cmdClose.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        cmdCloseActionPerformed(evt);
      }
    });

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
    getContentPane().add(cmdClose, gridBagConstraints);

    jLabel1.setFont(new java.awt.Font("Dialog", 2, 12));
    jLabel1.setText("Copy (ctrl+c) and paste (ctrl+v) this text into Excel or Notepad to print it.");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    getContentPane().add(jLabel1, gridBagConstraints);

    jScrollPane1.setMinimumSize(new java.awt.Dimension(600, 303));
    jScrollPane1.setPreferredSize(new java.awt.Dimension(603, 303));
    tblKey.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] {

      },
      new String [] {
        "subID", "name or PPG", "sessionID", "experiment type", "date"
      }
    ) {
      Class[] types = new Class [] {
        java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
      };
      boolean[] canEdit = new boolean [] {
        false, false, false, false, false
      };

      public Class getColumnClass(int columnIndex) {
        return types [columnIndex];
      }

      public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit [columnIndex];
      }
    });
    tblKey.setPreferredScrollableViewportSize(new java.awt.Dimension(500, 400));
    tblKey.setPreferredSize(new java.awt.Dimension(600, 350));
    jScrollPane1.setViewportView(tblKey);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 0);
    getContentPane().add(jScrollPane1, gridBagConstraints);

    pack();
  }//GEN-END:initComponents

    private void cmdCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdCloseActionPerformed
        //close the frame
        try {  this.setClosed(true); }
        catch (java.beans.PropertyVetoException e) { e.printStackTrace(); }
    }//GEN-LAST:event_cmdCloseActionPerformed

    private void  CreateKey() {
      //creates the database key and displays it in tblKey as:
      //count subID PPG/Name sessionID expType  expDate
      int intC = -1; String strVec[] = {"", "", "", "", "", ""}; String strTemp = ""; String strNames = "";
      DefaultTableModel tblModel = (DefaultTableModel)tblKey.getModel();  //get the table model for the table so can alter it
      
      try {   //get all of the subjects' IDs and names/PPGs out and into strNames
        stmSQL = conData.createStatement();  //stmSQL is global - have to get it ready
        ResultSet rssSubjects = stmSQL.executeQuery("SELECT subject.*, sessionData.* FROM subject LEFT JOIN sessionData ON (subject.subID = sessionData.subID) ORDER BY PPG, lastName");
        
        while (rssSubjects.next()) {  //fill up the table
          intC = intC + 1; 
          tblModel.addRow(strVec);  //add a new empty row so can put in the info
          tblModel.setValueAt("" + rssSubjects.getInt("subID"), intC, 0);  //first column is subject ID
          strTemp = rssSubjects.getString("PPG");
          if ( strTemp.equals("") == false ) { strNames = strTemp; }
          else { strNames = rssSubjects.getString("lastName") + ", " + rssSubjects.getString("firstName") + " " + rssSubjects.getString("middleInitial") + "."; }
          tblModel.setValueAt(strNames, intC, 1);  //then subject name or PPG
          tblModel.setValueAt("" + rssSubjects.getInt("sessionID"), intC, 2);  //third column is sessionID
          tblModel.setValueAt(rssSubjects.getString("expType"), intC, 3);  //fourth is experiment type
          tblModel.setValueAt(rssSubjects.getString("expDate"), intC, 4);  //last is experiment date      
        }
      } catch(java.sql.SQLException e) { e.printStackTrace(); }         
    }

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton cmdClose;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JTable tblKey;
  // End of variables declaration//GEN-END:variables

}