/* * MovieData.java * * Created on April 1, 2002, 2:01 PM */ package subjectData; /** * * @author Joset A. Etzel */ import java.io.*; import java.util.*; import java.util.zip.*; import javax.swing.*; import java.sql.*; import javax.swing.filechooser.*; import java.io.File; import java.awt.*; import java.awt.event.*; import subjectData.*; public class MovieData extends javax.swing.JInternalFrame { static final int intBUFFER = 2048; //constant used for zip file access Connection conData; Statement stmSQL; //variables for sql database access /** Creates new form MovieData */ public MovieData() { initComponents(); //connect to the database try { Class.forName("org.gjt.mm.mysql.Driver"); } catch (Exception e) {} try { conData = DriverManager.getConnection("jdbc:mysql://localhost/subjectData", "root", ""); } catch (java.sql.SQLException e) { e.printStackTrace(); } FillCombos(); //call sub } private void FillCombos() { //fill cboSubject with the names from subject & cboMovie, cboCondition from comboBoxes String strNames = ""; String strTemp = ""; cboSubject.removeAllItems(); cboMovie.removeAllItems(); cboCondition.removeAllItems(); //just in case try { //get the subjects stmSQL = conData.createStatement(); //stmSQL is global - have to get it ready ResultSet rssSubjects = stmSQL.executeQuery("SELECT subID, PPG, firstName, middleInitial, lastName FROM subject ORDER BY lastName, PPG"); cboSubject.addItem(""); //on top while(rssSubjects.next()) { //fill up cboSubject w/subject names & PPG numbers strTemp = rssSubjects.getString("PPG"); if ( strTemp.equals("") == false ) { strNames = rssSubjects.getInt("subID") + ": " + strTemp; } else { strNames = rssSubjects.getInt("subID") + ": " + rssSubjects.getString("lastName") + ", " + rssSubjects.getString("firstName") + " " + rssSubjects.getString("middleInitial") + "."; } cboSubject.addItem(strNames); } } catch(java.sql.SQLException e) { e.printStackTrace(); } try { //get the movies stmSQL = conData.createStatement(); ResultSet rssSubjects = stmSQL.executeQuery("SELECT boxChoice FROM comboBoxes WHERE boxID = 'Movies' ORDER BY boxChoice"); cboMovie.addItem(""); //on top while(rssSubjects.next()) { cboMovie.addItem(rssSubjects.getString("boxChoice")); } } catch(java.sql.SQLException e) { e.printStackTrace(); } try { //get the conditions stmSQL = conData.createStatement(); ResultSet rssSubjects = stmSQL.executeQuery("SELECT boxChoice FROM comboBoxes WHERE boxID = 'Condition' ORDER BY boxChoice"); cboCondition.addItem(""); //on top while(rssSubjects.next()) { cboCondition.addItem(rssSubjects.getString("boxChoice")); } } catch(java.sql.SQLException e) { e.printStackTrace(); } } /** 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; cmdOK = new javax.swing.JButton(); cmdCancel = new javax.swing.JButton(); lblAdded = new javax.swing.JLabel(); cmdAddNew = new javax.swing.JButton(); lblSubject = new javax.swing.JLabel(); cboSubject = new javax.swing.JComboBox(); lblSession = new javax.swing.JLabel(); cboSession = new javax.swing.JComboBox(); jSeparator1 = new javax.swing.JSeparator(); cmdDelete = new javax.swing.JButton(); jSeparator2 = new javax.swing.JSeparator(); jScrollPane1 = new javax.swing.JScrollPane(); lstSessions = new javax.swing.JList(); pnlMovie = new javax.swing.JPanel(); lblDot = new javax.swing.JLabel(); cboMinute = new javax.swing.JComboBox(); cboMinute.addItem("00"); cboMinute.addItem("05"); for (int intC = 10; intC < 65; intC = intC + 5) { cboMinute.addItem("" + intC); } txtComment = new javax.swing.JTextArea(); cboCondition = new javax.swing.JComboBox(); lblMovie = new javax.swing.JLabel(); cboHour = new javax.swing.JComboBox(); for (int intC = 0; intC < 10; intC++) { cboHour.addItem("0" + intC); } for (int intC = 10; intC < 25; intC++) { cboHour.addItem("" + intC); } lblTime = new javax.swing.JLabel(); cboMovie = new javax.swing.JComboBox(); cmdSetFile = new javax.swing.JButton(); txtSetFile = new javax.swing.JTextField(); lblComment = new javax.swing.JLabel(); lblCondition = new javax.swing.JLabel(); lblSetFile = new javax.swing.JLabel(); getContentPane().setLayout(new java.awt.GridBagLayout()); setMaximizable(true); setTitle("Data for a Movie Viewing"); setIconifiable(true); setResizable(true); setPreferredSize(new java.awt.Dimension(800, 445)); cmdOK.setText("OK"); cmdOK.setEnabled(false); cmdOK.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdOKActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 4; gridBagConstraints.gridy = 7; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; getContentPane().add(cmdOK, gridBagConstraints); cmdCancel.setText("Close"); cmdCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdCancelActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 7; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5); getContentPane().add(cmdCancel, gridBagConstraints); lblAdded.setText("data added for this session:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 2; gridBagConstraints.ipady = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(15, 0, 5, 0); getContentPane().add(lblAdded, gridBagConstraints); cmdAddNew.setMnemonic('\u0001'); cmdAddNew.setText("Add or Edit this Session's Data"); cmdAddNew.setEnabled(false); cmdAddNew.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdAddNewActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 2, 0, 0); getContentPane().add(cmdAddNew, gridBagConstraints); lblSubject.setText("select subject:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.ipadx = 2; getContentPane().add(lblSubject, gridBagConstraints); cboSubject.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { cboSubjectItemStateChanged(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.ipadx = 2; gridBagConstraints.ipady = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; getContentPane().add(cboSubject, gridBagConstraints); lblSession.setText("select session: "); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 2); getContentPane().add(lblSession, gridBagConstraints); cboSession.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cboSessionActionPerformed(evt); } }); cboSession.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { cboSessionItemStateChanged(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; getContentPane().add(cboSession, gridBagConstraints); jSeparator1.setPreferredSize(new java.awt.Dimension(400, 4)); jSeparator1.setMinimumSize(new java.awt.Dimension(400, 4)); jSeparator1.setAlignmentY(1.0F); jSeparator1.setMaximumSize(new java.awt.Dimension(400, 4)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.gridwidth = 4; gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 0); getContentPane().add(jSeparator1, gridBagConstraints); cmdDelete.setText("Delete This Session's Data"); cmdDelete.setEnabled(false); cmdDelete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdDeleteActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 3; gridBagConstraints.gridwidth = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 2, 5, 0); getContentPane().add(cmdDelete, gridBagConstraints); jSeparator2.setPreferredSize(new java.awt.Dimension(400, 4)); jSeparator2.setMinimumSize(new java.awt.Dimension(400, 4)); jSeparator2.setAlignmentY(1.0F); jSeparator2.setMaximumSize(new java.awt.Dimension(400, 4)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 6; gridBagConstraints.gridwidth = 4; gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 0); getContentPane().add(jSeparator2, gridBagConstraints); jScrollPane1.setPreferredSize(new java.awt.Dimension(250, 100)); jScrollPane1.setMinimumSize(new java.awt.Dimension(250, 100)); lstSessions.setBorder(new javax.swing.border.EtchedBorder()); lstSessions.setModel(new javax.swing.AbstractListModel() { String[] strings = { "select a session" }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); lstSessions.setPreferredSize(new java.awt.Dimension(90, 20)); lstSessions.setMaximumSize(new java.awt.Dimension(250, 100)); lstSessions.setVisibleRowCount(5); lstSessions.setEnabled(false); lstSessions.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { lstSessionsMouseClicked(evt); } }); jScrollPane1.setViewportView(lstSessions); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 3; gridBagConstraints.gridheight = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; getContentPane().add(jScrollPane1, gridBagConstraints); pnlMovie.setLayout(new java.awt.GridBagLayout()); pnlMovie.setBorder(new javax.swing.border.TitledBorder("movieData")); pnlMovie.setMinimumSize(new java.awt.Dimension(626, 193)); pnlMovie.setVisible(false); lblDot.setText(":"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 4; gridBagConstraints.gridy = 0; pnlMovie.add(lblDot, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 5; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(2, 1, 0, 0); pnlMovie.add(cboMinute, gridBagConstraints); txtComment.setPreferredSize(new java.awt.Dimension(350, 100)); txtComment.setDoubleBuffered(true); txtComment.setMinimumSize(new java.awt.Dimension(350, 100)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 5; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(2, 1, 2, 0); pnlMovie.add(txtComment, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0); pnlMovie.add(cboCondition, gridBagConstraints); lblMovie.setText("Movie: "); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 2); pnlMovie.add(lblMovie, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 1); pnlMovie.add(cboHour, gridBagConstraints); lblTime.setText("Start Time: "); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 3); pnlMovie.add(lblTime, gridBagConstraints); cboMovie.setFont(new java.awt.Font("Dialog", 0, 12)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0); pnlMovie.add(cboMovie, gridBagConstraints); cmdSetFile.setText("Set Data File"); cmdSetFile.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdSetFileActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 3; gridBagConstraints.gridwidth = 3; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 0); pnlMovie.add(cmdSetFile, gridBagConstraints); txtSetFile.setPreferredSize(new java.awt.Dimension(250, 21)); txtSetFile.setMinimumSize(new java.awt.Dimension(250, 21)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.gridwidth = 2; pnlMovie.add(txtSetFile, gridBagConstraints); lblComment.setText("Comment: "); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 2); pnlMovie.add(lblComment, gridBagConstraints); lblCondition.setText("Condition: "); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 2); pnlMovie.add(lblCondition, gridBagConstraints); lblSetFile.setText("Text Data File: "); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 2); pnlMovie.add(lblSetFile, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 5; gridBagConstraints.gridwidth = 4; getContentPane().add(pnlMovie, gridBagConstraints); pack(); }//GEN-END:initComponents private void cboSessionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboSessionActionPerformed }//GEN-LAST:event_cboSessionActionPerformed private void cmdESetPathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdESetPathActionPerformed }//GEN-LAST:event_cmdESetPathActionPerformed private void lstSessionsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstSessionsMouseClicked cmdDelete.setEnabled(true); }//GEN-LAST:event_lstSessionsMouseClicked private void cmdCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdCancelActionPerformed // try to close the frame try { this.setClosed(true); } catch(java.beans.PropertyVetoException e) { e.printStackTrace(); } }//GEN-LAST:event_cmdCancelActionPerformed private void cmdDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdDeleteActionPerformed //call appropriate delete sub depending on what type of data to delete String strTemp = ""; String strType = ""; strTemp = (String)cboSession.getSelectedItem(); //determine type of session if (strTemp.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the session.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } strType = strTemp.substring((strTemp.indexOf("(") + 1), strTemp.indexOf(")")); //parse out the expType if (strType.equals("Movie Viewing") == true) { DeleteMovieData(); } //call sub to delete a movieData session } private void DeleteMovieData() { //delete the movie highlighted in lstSessions; called by cmdDeleteActionPerformed int intAnswer = 0; String strTemp = ""; String strSubID = ""; String strSesID = ""; String strTime = ""; boolean bolMade = true; String strSQL = ""; String strPath = ""; strTemp = (String)cboSession.getSelectedItem(); if (strTemp.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the session.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } strSesID = strTemp.substring(0, strTemp.indexOf(":")); //parse out the subID strTemp = (String)cboSubject.getSelectedItem(); if (strTemp.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the subject.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } strSubID = strTemp.substring(0, strTemp.indexOf(":")); //parse out the subID strTemp = (String)lstSessions.getSelectedValue(); //get the item that's highlighted if (strTemp.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the movie session to delete.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } strTime = strTemp.substring((strTemp.indexOf(", ") + 2)); //parse out the timeStarted //ask the user if they are sure they want to delete the movie intAnswer = JOptionPane.showConfirmDialog(null, "The movie session " + strTemp + " will be permanently deleted from the database, including the data file. \n Are you sure you want to delete this?", "File Delete Confirm", JOptionPane.YES_NO_OPTION); if (intAnswer == JOptionPane.NO_OPTION) { return; } try { //get the dataFile out of the database strSQL = "SELECT dataFile FROM movieData WHERE subID = \"" + strSubID + "\" AND sessionID = \"" + strSesID + "\" AND timeStarted = \"" + strTime + "\""; stmSQL = conData.createStatement(); ResultSet rssSubjects = stmSQL.executeQuery(strSQL); rssSubjects.next(); strPath = rssSubjects.getString("dataFile"); } catch(java.sql.SQLException e) { e.printStackTrace(); } File fileZipPath = new File(strPath); if (fileZipPath.exists() == true) { bolMade = fileZipPath.delete(); } //delete the existing file; bolMade shows if successful if (bolMade == false) { JOptionPane.showMessageDialog(null, "There has been an error deleting the previous file. The old file was not deleted.", "File Deletion Error", JOptionPane.ERROR_MESSAGE); return; } try { //delete the existing record from the movieData table stmSQL = conData.createStatement(); //stmSQL & conData are global stmSQL.executeUpdate("DELETE FROM movieData WHERE subID = \"" + strSubID + "\" AND sessionID = \"" + strSesID + "\" AND timeStarted = \"" + strTime + "\""); } catch(java.sql.SQLException e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, "There has been an error deleting the database entry.", "Database Deletion Error", JOptionPane.ERROR_MESSAGE); return; } UpdateListBox(); //call sub to fill up the list of movies for the current subject and session ResetMovieDataScreen(); }//GEN-LAST:event_cmdDeleteActionPerformed private void cboSessionItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboSessionItemStateChanged //call sub to fill up the list of movies for the current subject and session if ((String)cboSession.getSelectedItem() != "") { //only want to do this if clicked, not if loading if (evt.getStateChange() == ItemEvent.SELECTED) { lstSessions.setEnabled(true); UpdateListBox(); //call sub to fill up the list of movies for the current subject and session }} //end the ifs }//GEN-LAST:event_cboSessionItemStateChanged private void UpdateListBox () { //show the movies entered in the list box for the current subject and session String strSQL = ""; String strTemp = ""; String strID = ""; String strTime = ""; String strType = ""; String strMovie = ""; String strList[]; int intSize = 0; strTemp = (String)cboSession.getSelectedItem(); //determine type & sessionID of session if (strTemp.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the session.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } strType = strTemp.substring((strTemp.indexOf("(") + 1), strTemp.indexOf(")")); //parse out the expType strID = strTemp.substring(0, strTemp.indexOf(":")); //parse out the sessionID if (strType.equals("Movie Viewing") == true) { //show the movieData sessions strSQL = "SELECT timeStarted, whichMovie FROM movieData WHERE sessionID = \"" + strID + "\" ORDER BY timeStarted"; try { ResultSet rssSubjects = stmSQL.executeQuery(strSQL); //make the resultset on the sql statement while(rssSubjects.next()) { intSize = intSize + 1; } //count the number of rows in the resultset rssSubjects.beforeFirst(); //move to the start of the resultset again strList = new String[intSize]; //get the array ready to hold the data intSize = 0; while(rssSubjects.next()) { //get the data out of the database strTime = rssSubjects.getString("timeStarted"); strMovie = rssSubjects.getString("whichMovie"); strList[intSize] = strMovie + ", " + strTime; //store the movie intSize = intSize + 1; } //update count for next time lstSessions.setListData(strList); //put data in strList into lstSessions so visible } catch(java.sql.SQLException e) { e.printStackTrace(); } } else if (strType.equals("Erica Sound Clips") == true) { //show the ericaData sessions strSQL = "SELECT timeStarted FROM ericaData WHERE sessionID = \"" + strID + "\" ORDER BY timeStarted"; try { ResultSet rssSubjects = stmSQL.executeQuery(strSQL); //make the resultset on the sql statement while(rssSubjects.next()) { intSize = intSize + 1; } //count the number of rows in the resultset rssSubjects.beforeFirst(); //move to the start of the resultset again strList = new String[intSize]; //get the array ready to hold the data intSize = 0; while(rssSubjects.next()) { //get the data out of the database strTime = rssSubjects.getString("timeStarted"); strList[intSize] = strTime; //store the clip in strList intSize = intSize + 1; } //update count for next time lstSessions.setListData(strList); //put data in strList into lstSessions so visible } catch(java.sql.SQLException e) { e.printStackTrace(); } } } private void cboSubjectItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboSubjectItemStateChanged //after the subject's name was selected, show the session numbers in the session combo box String strSQL = ""; String strDate = ""; String strSubID = ""; String strTemp = ""; int intID = 0; if ((String)cboSubject.getSelectedItem() != "") { //only want to do this if clicked, not if loading if (evt.getStateChange() == ItemEvent.SELECTED) { cboSession.removeAllItems(); cboSession.addItem(""); //blank on top; don't want duplicates strTemp = (String)cboSubject.getSelectedItem(); //parse out subID strSubID = strTemp.substring(0, strTemp.indexOf(":")); try { //get the sessions for this subject from the database strSQL = "SELECT sessionID, expDate, expType FROM session WHERE subID = \"" + strSubID + "\" ORDER BY expDate"; //sql statement to execute stmSQL = conData.createStatement(); //stmSQL is global - have to get it ready ResultSet rssSubjects = stmSQL.executeQuery(strSQL); //make the resultset on the sql statement while(rssSubjects.next()) { //fill up cboSession intID = rssSubjects.getInt("sessionID"); strDate = rssSubjects.getString("expDate"); cboSession.addItem("" + intID + ": " + strDate + " (" + rssSubjects.getString("expType") + ")"); } } catch(java.sql.SQLException e) { e.printStackTrace(); } cmdAddNew.setEnabled(true); }} }//GEN-LAST:event_cboSubjectItemStateChanged private void cmdAddNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdAddNewActionPerformed //enable the controls needed to enter a new movie if subject and session selected String strTemp = ""; String strType = ""; String strTempName = ""; String strTempID = ""; String strSesID = ""; strTemp = (String)cboSubject.getSelectedItem(); if (strTemp.length() < 1) { JOptionPane.showMessageDialog(null, "Please select the subject.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } strTemp = (String)cboSession.getSelectedItem(); if (strTemp.length() < 1) { JOptionPane.showMessageDialog(null, "Please select the session.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } strType = strTemp.substring((strTemp.indexOf("(") + 1), strTemp.indexOf(")")); //parse out the expType if (strType.equals("Movie Viewing") == true) { pnlMovie.setVisible(true); } //a movieData session else if (strType.equals("Erica Sound Clips") == true) { //display EricaData; have to pass it the subjectID & sessionID from cboSubject strTemp = (String)cboSubject.getSelectedItem(); strTempID = strTemp.substring(0, strTemp.indexOf(":")); strTempName = strTemp.substring(strTemp.indexOf(":") + 2); if (strTemp.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the subject from the box.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } strTemp = (String)cboSession.getSelectedItem(); strSesID = strTemp.substring(0, strTemp.indexOf(":")); EricaData frmErica = new EricaData(strTempID, strTempName, strSesID); JDesktopPane contentPane = this.getDesktopPane(); //get desktop pane that this internal frame is in contentPane.add(frmErica, javax.swing.JLayeredPane.DEFAULT_LAYER); //add new frame to desktop frame frmErica.setBounds(20, 20, 700, 580); frmErica.show(); } cmdOK.setEnabled(true); }//GEN-LAST:event_cmdAddNewActionPerformed private void cmdOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdOKActionPerformed //call appropriate sub to enter data from whatever panel is visible (depends on session type) String strTemp = ""; String strType = ""; strTemp = (String)cboSession.getSelectedItem(); //determine type of session if (strTemp.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the session.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } strType = strTemp.substring((strTemp.indexOf("(") + 1), strTemp.indexOf(")")); //parse out the expType if (strType.equals("Movie Viewing") == true) { EnterMovieData(); } //call sub to enter a movieData session }//GEN-LAST:event_cmdOKActionPerformed private void EnterMovieData() { //put the movie into movieData for this session and zip the data file. called by cmdOKActionPerformed String strMovie = ""; String strCondition = ""; String strHour = ""; String strMinute = ""; String strComment = ""; String strPath = ""; String strSubID = ""; String strSesID = ""; String strTime = ""; String strZipPath = ""; String strTemp = ""; boolean bolMade = false; int intAnswer = 0; strTemp = (String)cboSession.getSelectedItem(); if (strTemp.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the session.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } strSesID = strTemp.substring(0, strTemp.indexOf(":")); //parse out the sessionID strTemp = (String)cboSubject.getSelectedItem(); if (strTemp.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the subject.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } strSubID = strTemp.substring(0, strTemp.indexOf(":")); //parse out the subID strMovie = (String)cboMovie.getSelectedItem(); strCondition = (String)cboCondition.getSelectedItem(); strMinute = (String)cboMinute.getSelectedItem(); strHour = (String)cboHour.getSelectedItem(); strComment = txtComment.getText(); strPath = txtSetFile.getText(); strTime = strHour + ":" + strMinute + ":00"; //put together the time string in the correct format strZipPath = "c:\\subjectData\\subject_" + strSubID + "\\session_" + strSesID + "\\" + strMovie + "_" + strHour + "_" + strMinute + ".zip"; //check that the user input was ok if (strMovie.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the movie.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } if (strCondition.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the condition.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } if (strComment.equals("") == true) { JOptionPane.showMessageDialog(null, "Please enter a comment. If the movie was viewed without incident, please type OK in the comment box.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } if (strPath.equals("") == true) { JOptionPane.showMessageDialog(null, "Please indicate the path to the text data file by clicking the Set Data File button.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } //check if the directory exists, and make it if not File fileZipPath = new File("c:\\subjectData\\subject_" + strSubID + "\\session_" + strSesID + "\\"); if (fileZipPath.exists() == false) { //look to see if session's directory already exists bolMade = fileZipPath.mkdirs(); //if not, make it. check if error and exit if there was if (bolMade == false) { JOptionPane.showMessageDialog(null, "There has been an error making the directory needed to store this subject's data. The data was not stored.", "Directory Creation Error", JOptionPane.ERROR_MESSAGE); return; } } fileZipPath = new File("c:\\subjectData\\subject_" + strSubID + "\\session_" + strSesID + "\\" + strMovie + "_" + strHour + "_" + strMinute + ".zip"); if (fileZipPath.exists() == true) { //file already exists intAnswer = JOptionPane.showConfirmDialog(null, "A file with for this subject, this session, and this movie, at this time already exists. If you are replacing the existing file click yes, otherwise click no and correct the subject, session, time, or movie.", "File Delete Confirm", JOptionPane.YES_NO_OPTION); if (intAnswer == JOptionPane.NO_OPTION) {return; } else { bolMade = fileZipPath.delete(); //delete the existing file; bolMade shows if successful if (bolMade == false) { JOptionPane.showMessageDialog(null, "There has been an error deleting the previous file. The old file was not deleted.", "File Deletion Error", JOptionPane.ERROR_MESSAGE); return; } try { //delete the existing record from the movieData table stmSQL = conData.createStatement(); //stmSQL & conData are global stmSQL.executeUpdate("DELETE FROM movieData WHERE subID = \"" + strSubID + "\" AND sessionID = \"" + strSesID + "\" AND timeStarted = \"" + strTime + "\" AND whichMovie = \"" + strMovie + "\""); } catch(java.sql.SQLException e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, "There has been an error deleting the previous database entry.", "Database Deletion Error", JOptionPane.ERROR_MESSAGE); return; } }} try { //put the new movie into the movieData table stmSQL = conData.createStatement(); //stmSQL & conData are global strZipPath = SubjectData.AddEscapeChars(strZipPath); strComment = SubjectData.AddEscapeChars(strComment); stmSQL.executeUpdate("INSERT INTO movieData VALUES ('" + strSubID + "', '" + strSesID + "', '" + strTime + "', '" + strMovie + "', '" + strCondition + "', '" + strZipPath + "', '" + strComment + "')"); } catch(java.sql.SQLException e) { e.printStackTrace(); } try { //compress the file and resave it to strZipPath BufferedInputStream origin = null; FileOutputStream dest = new FileOutputStream(strZipPath); //FileOutputStream dest = new FileOutputStream(txttxtSetFile.getText()); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest)); byte data[] = new byte[intBUFFER]; FileInputStream fi = new FileInputStream(txtSetFile.getText()); origin = new BufferedInputStream(fi, intBUFFER); ZipEntry entry = new ZipEntry(txtSetFile.getText()); out.putNextEntry(entry); int count; while((count = origin.read(data, 0, intBUFFER)) != -1) { out.write(data, 0, count); } origin.close(); out.close(); } catch(Exception e) { e.printStackTrace(); } pnlMovie.setVisible(false); ResetMovieDataScreen(); //call sub to blank out the boxes & disable everything again UpdateListBox(); //call sub to fill up the list of movies for the current subject and session } private void ResetMovieDataScreen() { //blanks the controls on pnlMovie cboMovie.setSelectedIndex(0); cboHour.setSelectedIndex(0); cboMinute.setSelectedIndex(0); cboCondition.setSelectedIndex(0); txtComment.setText(""); txtSetFile.setText(""); } private void cmdSetFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdSetFileActionPerformed //show a file chooser to let user pick a text file for compression. //JFileChooser comes with the ability to move around the directory structure JFileChooser frmFileOpen = new JFileChooser(); //declare a JFileChooser - the select file box frmFileOpen.setApproveButtonText("Select Text File"); //have button say Select instead of Open int intResult = frmFileOpen.showOpenDialog(null); //this returns if select or cancel was clicked File fileChosen = frmFileOpen.getSelectedFile(); //the file picked, if any if (intResult == JFileChooser.APPROVE_OPTION) { txtSetFile.setText(fileChosen.getPath()); } else if (intResult == JFileChooser.CANCEL_OPTION) { txtSetFile.setText(""); } }//GEN-LAST:event_cmdSetFileActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox cboCondition; private javax.swing.JComboBox cboHour; private javax.swing.JComboBox cboMinute; private javax.swing.JComboBox cboMovie; private javax.swing.JComboBox cboSession; private javax.swing.JComboBox cboSubject; private javax.swing.JButton cmdAddNew; private javax.swing.JButton cmdCancel; private javax.swing.JButton cmdDelete; private javax.swing.JButton cmdOK; private javax.swing.JButton cmdSetFile; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JSeparator jSeparator1; private javax.swing.JSeparator jSeparator2; private javax.swing.JLabel lblAdded; private javax.swing.JLabel lblComment; private javax.swing.JLabel lblCondition; private javax.swing.JLabel lblDot; private javax.swing.JLabel lblMovie; private javax.swing.JLabel lblSession; private javax.swing.JLabel lblSetFile; private javax.swing.JLabel lblSubject; private javax.swing.JLabel lblTime; private javax.swing.JList lstSessions; private javax.swing.JPanel pnlMovie; private javax.swing.JTextArea txtComment; private javax.swing.JTextField txtSetFile; // End of variables declaration//GEN-END:variables }