/* * EricaData.java * * Created on June 28, 2002, 11:40 AM */ 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 EricaData extends javax.swing.JInternalFrame { static final int intBUFFER = 2048; //constant used for zip file access Connection conData; Statement stmSQL; String strSubID = ""; String strSesID = ""; /** Creates new form EricaData */ public EricaData(String strPsubID, String strPName, String strPsesID) { initComponents(); try { Class.forName("org.gjt.mm.mysql.Driver"); conData = SubjectData.getDatabaseConnection(); //gets connection to the correct database } catch (Exception e) { e.printStackTrace(); } strSubID = strPsubID; strSesID = strPsesID; setTitle("Erica Experiment Details for subject " + strSubID + ": " + strPName + ", session number " + strSesID + "."); try { //get the musician categories stmSQL = conData.createStatement(); ResultSet rssSubjects = stmSQL.executeQuery("SELECT boxChoice FROM comboBoxes WHERE boxID = 'Musician' ORDER BY boxChoice"); cboMusician.addItem(""); //on top while(rssSubjects.next()) { cboMusician.addItem(rssSubjects.getString("boxChoice")); } } catch(java.sql.SQLException e) { e.printStackTrace(); } FillScreen(); //call sub to put the info on the screen from the database } private void FillScreen() { //get the subject's info from ericaData, if there. strSubID & strSesID accessable to whole form int intRow = 0; String strTemp = ""; //boolean bolTemp = true; try { stmSQL = conData.createStatement(); //stmSQL is global - have to get it ready ResultSet rssSubjects = stmSQL.executeQuery("SELECT * FROM ericaData WHERE subID = " + strSubID + " AND sessionID = " + strSesID ); if (rssSubjects.next() == true) { cmdOK.setText("Update"); //need to get the data out of the database txtTime.setText(rssSubjects.getString("timeStarted")); txtPath.setText(rssSubjects.getString("dataFile")); txtComment.setText(rssSubjects.getString("comment")); txtPANASp.setText(rssSubjects.getString("PANASpos")); txtPANASn.setText(rssSubjects.getString("PANASneg")); cboMusician.setSelectedItem(rssSubjects.getString("musician")); txtMCom.setText(rssSubjects.getString("musicCom")); txtTempo.setText(rssSubjects.getString("tempo")); txtHeard.setText(rssSubjects.getString("heard")); for (intRow = 0; intRow < 12; intRow++) { //put in the happiness values, column 1 strTemp = rssSubjects.getString("h" + (intRow + 1)); if ( strTemp.equals("null") == true ) { strTemp = ""; } tblLikert.setValueAt(strTemp, intRow, 1); } for (intRow = 0; intRow < 12; intRow++) { //put in the sadness values, column 2 strTemp = rssSubjects.getString("s" + (intRow + 1)); if ( strTemp.equals("null") == true ) { strTemp = ""; } tblLikert.setValueAt(strTemp, intRow, 2); } for (intRow = 0; intRow < 12; intRow++) { //put in the fear values, column 3 strTemp = rssSubjects.getString("f" + (intRow + 1)); if ( strTemp.equals("null") == true ) { strTemp = ""; } tblLikert.setValueAt(strTemp, intRow, 3); } for (intRow = 0; intRow < 12; intRow++) { //put in the excitement values, column 4 strTemp = rssSubjects.getString("e" + (intRow + 1)); if ( strTemp.equals("null") == true ) { strTemp = ""; } tblLikert.setValueAt(strTemp, intRow, 4); } txtTime.setEnabled(false); cmdSetData.setEnabled(false); //can't adjust unless delete } else { cmdOK.setText("Add"); return; } //exit sub - not in database } catch(java.sql.SQLException e) { e.printStackTrace(); } try { stmSQL = conData.createStatement(); //stmSQL is global - have to get it ready ResultSet rssSubjects = stmSQL.executeQuery("SELECT * FROM ericaDataLikert WHERE subID = " + strSubID + " AND sessionID = " + strSesID ); if (rssSubjects.next() == true) { //need to get the data out of the database for (intRow = 0; intRow < 12; intRow++) { //put in the heard before values, column 5 //Boolean b = new Boolean(rssSubjects.getBoolean("heardB" + (intRow + 1))); strTemp = rssSubjects.getString("heardB" + (intRow + 1)); if ( strTemp.equals("null") == true ) { strTemp = ""; } tblLikert.setValueAt(strTemp, intRow, 5); } for (intRow = 0; intRow < 12; intRow++) { //put in the familiar values, column 6 strTemp = rssSubjects.getString("familiar" + (intRow + 1)); if ( strTemp.equals("null") == true ) { strTemp = ""; } tblLikert.setValueAt(strTemp, intRow, 6); } for (intRow = 0; intRow < 12; intRow++) { //word choice, column 7 strTemp = rssSubjects.getString("word" + (intRow + 1)); if ( strTemp.equals("null") == true ) { strTemp = ""; } tblLikert.setValueAt(strTemp, intRow, 7); } } } 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; lblControl = new javax.swing.JLabel(); txtComment = new javax.swing.JTextArea(); jLabel30 = new javax.swing.JLabel(); jLabel31 = new javax.swing.JLabel(); cboMusician = new javax.swing.JComboBox(); cmdSetData = new javax.swing.JButton(); txtPath = new javax.swing.JTextField(); jLabel32 = new javax.swing.JLabel(); jLabel33 = new javax.swing.JLabel(); jLabel34 = new javax.swing.JLabel(); txtPANASn = new javax.swing.JTextField(); txtPANASp = new javax.swing.JTextField(); txtTime = new javax.swing.JTextField(); jLabel35 = new javax.swing.JLabel(); jLabel36 = new javax.swing.JLabel(); lblTempo = new javax.swing.JLabel(); jLabel38 = new javax.swing.JLabel(); txtHeard = new javax.swing.JTextField(); txtTempo = new javax.swing.JTextField(); jLabel39 = new javax.swing.JLabel(); txtMCom = new javax.swing.JTextField(); jLabel40 = new javax.swing.JLabel(); cmdOK = new javax.swing.JButton(); cmdCancel = new javax.swing.JButton(); cmdDelete = new javax.swing.JButton(); lblDelete = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); tblLikert = new javax.swing.JTable(); lblLikert = new javax.swing.JLabel(); cmdImport = new javax.swing.JButton(); getContentPane().setLayout(new java.awt.GridBagLayout()); setIconifiable(true); setMaximizable(true); setResizable(true); setTitle("Erica's Music Experiment Data"); lblControl.setText("control tasks"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.gridwidth = 3; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0); getContentPane().add(lblControl, gridBagConstraints); txtComment.setBorder(new javax.swing.border.EtchedBorder()); txtComment.setDoubleBuffered(true); txtComment.setMinimumSize(new java.awt.Dimension(350, 50)); txtComment.setPreferredSize(new java.awt.Dimension(500, 50)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 8; gridBagConstraints.gridwidth = 4; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(2, 1, 2, 0); getContentPane().add(txtComment, gridBagConstraints); jLabel30.setText("PANAS (positive):"); 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, 2, 2); getContentPane().add(jLabel30, gridBagConstraints); jLabel31.setText("PANAS (negative):"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 3); getContentPane().add(jLabel31, gridBagConstraints); cboMusician.setFont(new java.awt.Font("Dialog", 0, 12)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0); getContentPane().add(cboMusician, gridBagConstraints); cmdSetData.setText("Set Data File(s)"); cmdSetData.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdSetDataActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 4; gridBagConstraints.gridy = 6; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(3, 2, 3, 0); getContentPane().add(cmdSetData, gridBagConstraints); txtPath.setMinimumSize(new java.awt.Dimension(400, 21)); txtPath.setPreferredSize(new java.awt.Dimension(400, 21)); txtPath.setEnabled(false); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 6; gridBagConstraints.gridwidth = 3; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0); getContentPane().add(txtPath, gridBagConstraints); jLabel32.setText("Comment: "); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 8; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 2); getContentPane().add(jLabel32, gridBagConstraints); jLabel33.setText("Text Data File(s): "); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 6; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 2); getContentPane().add(jLabel33, gridBagConstraints); jLabel34.setText("musician status:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0); getContentPane().add(jLabel34, gridBagConstraints); txtPANASn.setMinimumSize(new java.awt.Dimension(130, 26)); txtPANASn.setPreferredSize(new java.awt.Dimension(130, 26)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 1; gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0); getContentPane().add(txtPANASn, gridBagConstraints); txtPANASp.setMinimumSize(new java.awt.Dimension(130, 26)); txtPANASp.setPreferredSize(new java.awt.Dimension(130, 26)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0); getContentPane().add(txtPANASp, gridBagConstraints); txtTime.setText("00:00"); txtTime.setMinimumSize(new java.awt.Dimension(130, 26)); txtTime.setPreferredSize(new java.awt.Dimension(130, 26)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 5; gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0); getContentPane().add(txtTime, gridBagConstraints); jLabel35.setText("time recording started (hh:mm, 00 to 24 for hours):"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 5; gridBagConstraints.gridwidth = 2; gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0); getContentPane().add(jLabel35, gridBagConstraints); jLabel36.setText("heard before:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 4; gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0); getContentPane().add(jLabel36, gridBagConstraints); lblTempo.setText("tempo:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0); getContentPane().add(lblTempo, gridBagConstraints); jLabel38.setFont(new java.awt.Font("Dialog", 2, 12)); jLabel38.setText("(# correct, out of 6 total)"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 4; gridBagConstraints.gridy = 4; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0); getContentPane().add(jLabel38, gridBagConstraints); txtHeard.setMinimumSize(new java.awt.Dimension(40, 26)); txtHeard.setPreferredSize(new java.awt.Dimension(40, 26)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 4; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0); getContentPane().add(txtHeard, gridBagConstraints); txtTempo.setMinimumSize(new java.awt.Dimension(40, 26)); txtTempo.setPreferredSize(new java.awt.Dimension(40, 26)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 4; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0); getContentPane().add(txtTempo, gridBagConstraints); jLabel39.setText("comment:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 2; gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0); getContentPane().add(jLabel39, gridBagConstraints); txtMCom.setMinimumSize(new java.awt.Dimension(250, 26)); txtMCom.setPreferredSize(new java.awt.Dimension(250, 26)); 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(2, 0, 2, 0); getContentPane().add(txtMCom, gridBagConstraints); jLabel40.setText("background information"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; getContentPane().add(jLabel40, gridBagConstraints); cmdOK.setMnemonic('O'); cmdOK.setText("OK"); 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 = 12; gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 2); getContentPane().add(cmdOK, gridBagConstraints); cmdCancel.setMnemonic('C'); cmdCancel.setText("Cancel"); 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 = 12; gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0); getContentPane().add(cmdCancel, gridBagConstraints); cmdDelete.setText("Delete Existing Data File"); 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 = 5; gridBagConstraints.gridwidth = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0); getContentPane().add(cmdDelete, gridBagConstraints); lblDelete.setFont(new java.awt.Font("Dialog", 2, 12)); lblDelete.setText("(to change the existing time started or data file click the Delete button and enter the new time and data file)"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 7; gridBagConstraints.gridwidth = 5; getContentPane().add(lblDelete, gridBagConstraints); jScrollPane1.setMinimumSize(new java.awt.Dimension(520, 214)); jScrollPane1.setPreferredSize(new java.awt.Dimension(520, 214)); tblLikert.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {new Integer(1), null, null, null, null, null, null, null}, {new Integer(2), null, null, null, null, null, null, null}, {new Integer(3), null, null, null, null, null, null, null}, {new Integer(4), null, null, null, null, null, null, null}, {new Integer(5), null, null, null, null, null, null, null}, {new Integer(6), null, null, null, null, null, null, null}, {new Integer(7), null, null, null, null, null, null, null}, {new Integer(8), null, null, null, null, null, null, null}, {new Integer(9), null, null, null, null, null, null, null}, {new Integer(10), null, null, null, null, null, null, null}, {new Integer(11), null, null, null, null, null, null, null}, {new Integer(12), null, null, null, null, null, null, null} }, new String [] { "clip", "happiness", "sadness", "fear", "activation", "heard b4", "familiar", "w. choice" } ) { Class[] types = new Class [] { java.lang.Integer.class, java.lang.String.class, java.lang.String.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, true, true, true, true, true, true, true }; public Class getColumnClass(int columnIndex) { return types [columnIndex]; } public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit [columnIndex]; } }); tblLikert.setRowSelectionAllowed(false); jScrollPane1.setViewportView(tblLikert); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 10; gridBagConstraints.gridwidth = 4; gridBagConstraints.gridheight = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0); getContentPane().add(jScrollPane1, gridBagConstraints); lblLikert.setText("Clip information. Likert ratings except for 'heard before' and 'familiar', where 1=yes and 0=no."); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 9; gridBagConstraints.gridwidth = 5; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0); getContentPane().add(lblLikert, gridBagConstraints); cmdImport.setText("Import From File"); cmdImport.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdImportActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 4; gridBagConstraints.gridy = 10; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; getContentPane().add(cmdImport, gridBagConstraints); pack(); }//GEN-END:initComponents private void cmdImportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdImportActionPerformed //import data into the table and Recognized/Tempo from a specially formatted plain text file //file format: the fields go in clip order (1 to 12), 7 fields per clip in the order happy, sad, //fearful, arousal, single word choice, heard before, familiarity. The last two fields are //RECOG: #correct out of 6 and TEMPO: # correct out of 6. //in file, for Heard before/familiar: Yes=1, No=0 (so 1s and 0s will be entered). String strTemp = ""; int intC = 0; String strInput = ""; File fileChosen; int intCrow = 0; //show a file chooser to let user pick a text file for compression. JFileChooser frmFileOpen = new JFileChooser(); //declare a JFileChooser - the select file box frmFileOpen.setApproveButtonText("Select"); //have button say Select instead of Open frmFileOpen.setMultiSelectionEnabled(false); //only can pick one file int intResult = frmFileOpen.showOpenDialog(null); //this returns if select or cancel was clicked if (intResult == JFileChooser.CANCEL_OPTION) { return; } fileChosen = frmFileOpen.getSelectedFile(); //the file picked if (fileChosen.isFile() == false) { JOptionPane.showMessageDialog(null, "The file is not valid.", "File Validation Error", JOptionPane.ERROR_MESSAGE); return; } try { //open the file and read it into strInput FileReader joFReader = new FileReader(fileChosen.getPath()); //reader to connect to the file BufferedReader joBReader = new BufferedReader(joFReader); strInput = joBReader.readLine(); //now the entire (one-line) file is in strInput joFReader.close(); joBReader.close(); //get rid of readers StringTokenizer joTokenizer = new StringTokenizer(strInput, "\t", false); //read strInput w/ tab delimiters //load the parts of strInput onto the form for( intCrow = 0; intCrow < 12; intCrow++ ) { for( intC = 1; intC <= 7; intC++ ){ strTemp = joTokenizer.nextToken(); //tab-delimited string tblLikert.setValueAt("" + strTemp, intCrow, intC); //put likert ratings into the grid //System.out.println("put " + strTemp + " at row: " + intCrow + " and col: " + intC); } } strTemp = joTokenizer.nextToken(); txtHeard.setText("" + strTemp); //number recognized, out of 6 strTemp = joTokenizer.nextToken(); txtTempo.setText("" + strTemp); //number correct on tempo task, out of 6 } catch (Exception e) { JOptionPane.showMessageDialog(null, "The file format is not valid.", "File Validation Error", JOptionPane.ERROR_MESSAGE); return; } }//GEN-LAST:event_cmdImportActionPerformed private void cmdDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdDeleteActionPerformed //delete the zip file associated with this session and clear out txtPath and txtTime for new info int intAnswer = 0; String strPath = ""; boolean bolMade = true; try { //get the path to the previous data file for this session & subject & time stmSQL = conData.createStatement(); ResultSet rssSubjects = stmSQL.executeQuery("SELECT dataFile FROM ericaData WHERE subID = '" + strSubID + "' AND sessionID = '" + strSesID + "'"); rssSubjects.next(); strPath = rssSubjects.getString("dataFile"); } catch(java.sql.SQLException e) { e.printStackTrace(); } File fileZipPath = new File(strPath); if (fileZipPath.exists() == true) { //file should already exist intAnswer = JOptionPane.showConfirmDialog(null, "The previous data file for this subject and session will be permanently deleted.\nIf you are replacing the existing file click yes, otherwise click no to cancel.", "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.", "Serious File Deletion Error", JOptionPane.ERROR_MESSAGE); return; } } } //blank and enable so can update the path & time txtPath.setText(""); txtTime.setText(""); txtTime.setEnabled(true); cmdSetData.setEnabled(true); }//GEN-LAST:event_cmdDeleteActionPerformed private void cmdOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdOKActionPerformed //Add or update the data in the database, according to caption of cmdOK String strSQL = ""; String strZipPath = ""; String strTime = ""; String strMinute = ""; String strHour = ""; String strPath = ""; boolean bolMade = true; String strMusician = ""; int intAnswer = 0; File fileZipPath; File fileDrive; String strInPath = ""; String str1 = ""; int count = 0; int intRow = 0; String strHB = ""; String strH = ""; String strS = ""; String strF = ""; String strE = ""; String strTemp = ""; String strFamiliar = ""; String strWord = ""; strMusician = (String)cboMusician.getSelectedItem(); // if (strMusician.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the musician category of this subject.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } if (cmdSetData.isEnabled() == true) { //if cmdSetData is enabled, then the zip file & time should be updated //get the time and check if entered correctly. if so, parse into hours and minutes if (SubjectData.CheckTime(txtTime.getText(), "clip start time") == true) { strTime = txtTime.getText(); } else { return; } strHour = strTime.substring(0,2); strMinute = strTime.substring(3,5); strPath = txtPath.getText(); if (strPath.equals("") == true) { JOptionPane.showMessageDialog(null, "Please indicate the path to the text data file(s) by clicking the Set Data File button.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; } /* fileDrive = new File("f:\\"); //look to see if there is an f drive (at UofI) if (fileDrive.exists() == true) { strZipPath = "f:\\subjectData\\subject_" + strSubID + "\\session_" + strSesID + "\\EricaData_" + strHour + "_" + strMinute + ".zip"; } else { intAnswer = JOptionPane.showConfirmDialog(null, "The program can't find the f drive. At the University of Iowa all data should be saved\nto the f drive. Please cancel the save and turn on the f drive. \nClick Yes to save the file to the C drive or No to cancel the save.", "File Save Confirm", JOptionPane.YES_NO_OPTION); if (intAnswer == JOptionPane.NO_OPTION) { return; } strZipPath = "c:\\subjectData\\subject_" + strSubID + "\\session_" + strSesID + "\\EricaData_" + strHour + "_" + strMinute + ".zip"; } //check if the directory exists on appropriate drive, and make it if not if (fileDrive.exists() == true) { fileZipPath = new File("f:\\subjectData\\subject_" + strSubID + "\\session_" + strSesID + "\\"); } else { 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; } } if (fileDrive.exists() == true) { fileZipPath = new File("f:\\subjectData\\subject_" + strSubID + "\\session_" + strSesID + "\\EricaData_" + strHour + "_" + strMinute + ".zip"); } else { fileZipPath = new File("c:\\subjectData\\subject_" + strSubID + "\\session_" + strSesID + "\\EricaData_" + strHour + "_" + strMinute + ".zip"); } */ fileZipPath = new File("c:\\subjectData\\subject_" + strSubID + "\\session_" + strSesID + "\\EricaData_" + strHour + "_" + strMinute + ".zip"); if (fileZipPath.exists() == true) { //file already exists intAnswer = JOptionPane.showConfirmDialog(null, "A file with for this subject and this session at this time already exists.\nIf you are replacing the existing file click yes, otherwise click no.", "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 ericaData 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 previous database entry.", "Database Deletion Error", JOptionPane.ERROR_MESSAGE); return; } } } try { //compress the file and resave it to strZipPath BufferedInputStream origin = null; FileOutputStream dest = new FileOutputStream(strZipPath); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest)); byte data[] = new byte[intBUFFER]; strInPath = txtPath.getText(); //read file(s) from text box if (strInPath.substring(0,1).equals("|") == true) { //more than one file to put into zip strInPath = strInPath.substring(1); //trim off first | while (strInPath.indexOf("|") > 0) { str1 = strInPath.substring(0,strInPath.indexOf("|")); //get next filename out strInPath = strInPath.substring(strInPath.indexOf("|") + 1); //trim off filename just saved to str1 FileInputStream fi = new FileInputStream(str1); origin = new BufferedInputStream(fi, intBUFFER); ZipEntry entry = new ZipEntry(str1); out.putNextEntry(entry); while((count = origin.read(data, 0, intBUFFER)) != -1) { out.write(data, 0, count); } origin.close(); out.closeEntry(); } } //add last file, or only file if multiples FileInputStream fi = new FileInputStream(strInPath); origin = new BufferedInputStream(fi, intBUFFER); ZipEntry entry = new ZipEntry(strInPath); out.putNextEntry(entry); while((count = origin.read(data, 0, intBUFFER)) != -1) { out.write(data, 0, count); } origin.close(); out.close(); //close these things for good } catch(Exception e) { e.printStackTrace(); } } //end if - only do above if txtPath enabled. if not, get time & path from text boxes else { strTime = txtTime.getText(); strZipPath = txtPath.getText(); } if (cmdOK.getText() == "Add") { //putting a new row in the database strSQL = "INSERT INTO ericaData VALUES ('" + strSubID + "', '" + strSesID + "', '" + strTime + "', '" + SubjectData.AddEscapeChars(strZipPath) + "', '" + SubjectData.AddEscapeChars(txtComment.getText()) + "', '" + SubjectData.AddEscapeChars(txtPANASp.getText()) + "', '" + SubjectData.AddEscapeChars(txtPANASn.getText()) + "', '" + SubjectData.AddEscapeChars(strMusician) + "', '" + SubjectData.AddEscapeChars(txtMCom.getText()) + "', '" + SubjectData.AddEscapeChars(txtTempo.getText()) + "', '" + SubjectData.AddEscapeChars(txtHeard.getText()); for (intRow = 0; intRow < 12; intRow++) { //get out the happiness values, column 1 strTemp = "" + tblLikert.getValueAt(intRow, 1); if (strTemp.equals("") == false) { strH = strH + "', '" + SubjectData.AddEscapeChars(strTemp); } else { strH = strH + "', '"; } } for (intRow = 0; intRow < 12; intRow++) { //get out the sadness values, column 2 strTemp = "" + tblLikert.getValueAt(intRow, 2); if (strTemp.equals("") == false) { strS = strS + "', '" + SubjectData.AddEscapeChars(strTemp); } else { strS = strS + "', '"; } } for (intRow = 0; intRow < 12; intRow++) { //get out the fear values, column 3 strTemp = "" + tblLikert.getValueAt(intRow, 3); if (strTemp.equals("") == false) { strF = strF + "', '" + SubjectData.AddEscapeChars(strTemp); } else { strF = strF + "', '"; } } for (intRow = 0; intRow < 12; intRow++) { //get out the excitement (activation) values, column 4 strTemp = "" + tblLikert.getValueAt(intRow, 4); if (strTemp.equals("") == false) { strE = strE + "', '" + SubjectData.AddEscapeChars(strTemp); } else { strE = strE + "', '"; } } strSQL = strSQL + strH + strS + strF + strE + "')"; } else { //updating the existing row in the database strSQL = "UPDATE ericaData SET timeStarted = '" + strTime + "', dataFile = '" + SubjectData.AddEscapeChars(strZipPath) + "', comment = '" + SubjectData.AddEscapeChars(txtComment.getText()) + "', PANASpos = '" + SubjectData.AddEscapeChars(txtPANASp.getText()) + "', PANASneg = '" + SubjectData.AddEscapeChars(txtPANASn.getText()) + "', musician = '" + SubjectData.AddEscapeChars(strMusician) + "', musicCom = '" + SubjectData.AddEscapeChars(txtMCom.getText()) + "', tempo = '" + SubjectData.AddEscapeChars(txtTempo.getText()) + "', heard = '" + SubjectData.AddEscapeChars(txtHeard.getText()); for (intRow = 0; intRow < 12; intRow++) { //get out the happiness values, column 1 strH = strH + "', h" + (intRow + 1) + " = '" + SubjectData.AddEscapeChars((String)tblLikert.getValueAt(intRow, 1)); } for (intRow = 0; intRow < 12; intRow++) { //get out the sadness values, column 2 strS = strS + "', s" + (intRow + 1) + " = '" + SubjectData.AddEscapeChars((String)tblLikert.getValueAt(intRow, 2)); } for (intRow = 0; intRow < 12; intRow++) { //get out the fear values, column 3 strF = strF + "', f" + (intRow + 1) + " = '" + SubjectData.AddEscapeChars((String)tblLikert.getValueAt(intRow, 3)); } for (intRow = 0; intRow < 12; intRow++) { //get out the excitement values, column 4 strE = strE + "', e" + (intRow + 1) + " = '" + SubjectData.AddEscapeChars((String)tblLikert.getValueAt(intRow, 4)); } strSQL = strSQL + strH + strS + strF + strE + "' WHERE subID = '" + strSubID + "' AND sessionID = '" + strSesID + "'"; } try { //put the new movie into the movieData table stmSQL = conData.createStatement(); //stmSQL & conData are global stmSQL.executeUpdate(strSQL); } catch(java.sql.SQLException e) { e.printStackTrace(); } try { //look to see if adding or updating the row in ericaDataLikert stmSQL = conData.createStatement(); ResultSet rssSubjects = stmSQL.executeQuery("SELECT * FROM ericaDataLikert WHERE subID = " + strSubID + " AND sessionID = " + strSesID ); if (rssSubjects.next() == false) { strSQL = "INSERT INTO ericaDataLikert VALUES ('" + strSubID + "', '" + strSesID; for (intRow = 0; intRow < 12; intRow++) { //get out the heard before values, column 5 strTemp = "" + tblLikert.getValueAt(intRow, 5); strHB = strHB + "', '" + strTemp; } for (intRow = 0; intRow < 12; intRow++) { //get out the familiar values, column 6 strTemp = "" + tblLikert.getValueAt(intRow, 6); strFamiliar = strFamiliar + "', '" + strTemp; } for (intRow = 0; intRow < 12; intRow++) { //get out the word choice values, column 7 strTemp = "" + tblLikert.getValueAt(intRow, 7); strWord = strWord + "', '" + strTemp; } strSQL = strSQL + strFamiliar + strHB + strWord + "')"; } else { //updating the existing row in the database strSQL = "UPDATE ericaDataLikert SET "; for (intRow = 0; intRow < 12; intRow++) { //get out the heard before values, column 5 strTemp = "" + tblLikert.getValueAt(intRow, 5); strHB = strHB + "heardB" + (intRow + 1) + " = '" + strTemp + "', "; } for (intRow = 0; intRow < 12; intRow++) { //get out the familiar values, column 6 strTemp = "" + tblLikert.getValueAt(intRow, 6); strFamiliar = strFamiliar + "familiar" + (intRow + 1) + " = '" + strTemp + "', "; } for (intRow = 0; intRow < 12; intRow++) { //get out the word values, column 7 strTemp = "" + tblLikert.getValueAt(intRow, 7); strWord = strWord + "word" + (intRow + 1) + " = '" + strTemp + "', "; } strSQL = strSQL + strHB + strFamiliar + strWord.substring(0, (strWord.length() - 2)) + " WHERE subID = '" + strSubID + "' AND sessionID = '" + strSesID + "'"; } } catch(java.sql.SQLException e) { e.printStackTrace(); } try { //put the new row/row update into ericaDataLikert stmSQL = conData.createStatement(); stmSQL.executeUpdate(strSQL); } catch(java.sql.SQLException e) { e.printStackTrace(); } try { this.setClosed(true); } //close this screen catch(java.beans.PropertyVetoException e) { e.printStackTrace(); } }//GEN-LAST:event_cmdOKActionPerformed private void cmdSetDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdSetDataActionPerformed //show a file chooser to let user pick a text file for compression. //JFileChooser comes with the ability to move around the directory structure int intC = 0; String strPath = ""; JFileChooser frmFileOpen = new JFileChooser(); //declare a JFileChooser - the select file box frmFileOpen.setApproveButtonText("Select Text Files"); //have button say Select instead of Open frmFileOpen.setMultiSelectionEnabled(true); //want to pick 12 files! int intResult = frmFileOpen.showOpenDialog(null); //this returns if select or cancel was clicked if (intResult == JFileChooser.APPROVE_OPTION) { File fileChosen[] = frmFileOpen.getSelectedFiles(); //the files picked for (intC = 0; intC < fileChosen.length; intC++) { strPath = "|" + fileChosen[intC].getPath() + strPath; } txtPath.setText(strPath); } }//GEN-LAST:event_cmdSetDataActionPerformed private void cmdCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdCancelActionPerformed try { this.setClosed(true); } //close this screen catch(java.beans.PropertyVetoException e) { e.printStackTrace(); } }//GEN-LAST:event_cmdCancelActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox cboMusician; private javax.swing.JButton cmdCancel; private javax.swing.JButton cmdDelete; private javax.swing.JButton cmdImport; private javax.swing.JButton cmdOK; private javax.swing.JButton cmdSetData; private javax.swing.JLabel jLabel30; private javax.swing.JLabel jLabel31; private javax.swing.JLabel jLabel32; private javax.swing.JLabel jLabel33; private javax.swing.JLabel jLabel34; private javax.swing.JLabel jLabel35; private javax.swing.JLabel jLabel36; private javax.swing.JLabel jLabel38; private javax.swing.JLabel jLabel39; private javax.swing.JLabel jLabel40; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JLabel lblControl; private javax.swing.JLabel lblDelete; private javax.swing.JLabel lblLikert; private javax.swing.JLabel lblTempo; private javax.swing.JTable tblLikert; private javax.swing.JTextArea txtComment; private javax.swing.JTextField txtHeard; private javax.swing.JTextField txtMCom; private javax.swing.JTextField txtPANASn; private javax.swing.JTextField txtPANASp; private javax.swing.JTextField txtPath; private javax.swing.JTextField txtTempo; private javax.swing.JTextField txtTime; // End of variables declaration//GEN-END:variables }