m@0: /*============================================================================= m@0: * File: SubjectDataPanel.java m@0: * Author: Marcus Pearce m@0: * Created: <2007-02-14 11:28:27 marcusp> marcus@21: * Time-stamp: <2012-03-27 16:48:33 marcusp> m@0: *============================================================================= m@0: */ m@0: m@0: import java.awt.*; m@0: import java.awt.event.*; m@0: import javax.swing.*; m@0: import java.util.ArrayList; m@0: m@0: public class SubjectDataPanel extends JPanel { m@0: m@0: /* variables */ m@12: private JTextField ageField, listeningField, nationalityField; m@12: private JComboBox sexBox, handBox, hearingBox, ethnicityBox, m@12: goldMSI3_1, goldMSI3_2, goldMSI3_3, goldMSI3_4, goldMSI3_5, goldMSI3_6, goldMSI3_7, goldMSI3_8, goldMSI3_9; m@12: m@0: private JButton finishButton; m@0: m@0: private SubjectResults results; m@0: m@0: /* accessors */ m@0: public JButton getFinishButton() { return finishButton; } m@0: m@0: /* constructor */ m@0: public SubjectDataPanel(ExperimentGui gui, SubjectResults sr) { m@0: m@0: results = sr; m@0: m@0: JPanel questionsPanel = new JPanel(); m@12: questionsPanel.setLayout(new GridBagLayout()); m@12: GridBagConstraints c = new GridBagConstraints(); m@12: //c.fill = GridBagConstraints.BOTH; m@12: c.ipadx = 10; m@12: c.ipady = 30; m@12: //c.insets = new Insets(50,50,50,50); m@12: m@0: questionsPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(""),BorderFactory.createEmptyBorder(5,5,5,5)), questionsPanel.getBorder())); m@0: m@0: String[] yesNoOptions = { "", "Yes", "No" }; m@12: String[] agreeOptions = { "", "1 Completely Disagree", "2 Strongly Disagree", "3 Disagree", "4 Neither agree nor disagree", "5 Agree", "6 Strongly Agree", "7 Completely agree" }; m@0: m@0: // Age m@12: c.gridy = 0; m@12: c.gridx = 0; m@0: ageField = new JTextField(10); m@12: c.anchor = GridBagConstraints.EAST; m@0: questionsPanel.add(new JLabel("Age: ")); m@12: c.gridx = 1; m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(ageField, c); m@0: m@0: // Gender m@12: c.gridx = GridBagConstraints.RELATIVE; m@12: c.gridy = 1; m@0: String[] sexBoxOptions = { "", "Male", "Female" }; m@0: sexBox = new JComboBox(sexBoxOptions); m@0: sexBox.setSelectedIndex(0); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("Sex: "), c); m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(sexBox, c); m@0: m@12: // Ethnicity m@12: c.gridy = 2; m@0: String[] ethnicityBoxOptions = m@0: { "", "Asian", "Black", "Chinese", "Mixed", "Other", "White", m@0: "Undisclosed" }; m@0: ethnicityBox = new JComboBox(ethnicityBoxOptions); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("Ethnicity: "), c); m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(ethnicityBox, c); m@0: m@12: // Nationality m@12: c.gridy = 3; m@0: nationalityField = new JTextField(10); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("Nationality: "), c); m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(nationalityField, c); m@0: m@0: // Handedness m@12: c.gridy = 4; m@0: String[] handBoxOptions = { "", "Right-handed", "Left-handed" }; m@0: handBox = new JComboBox(handBoxOptions); m@0: handBox.setSelectedIndex(0); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("Handedness: "), c); m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(handBox, c); m@0: m@0: // Hearing m@12: c.gridy = 5; m@0: hearingBox = new JComboBox(yesNoOptions); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("Do you have any hearing difficulties?"), c); m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(hearingBox, c); m@0: m@0: // Musical Listening m@12: c.gridy = 6; m@0: listeningField = new JTextField(10); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("How many hours per day do you spend listening to music?"), c); m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(listeningField, c); m@12: m@12: // GOLDMSI m@12: c.gridy = 7; m@12: goldMSI3_1 = new JComboBox(agreeOptions); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("I have never been complimented on my talents as a musical performer."), c); m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(goldMSI3_1, c); m@12: m@12: c.gridy = 8; m@12: goldMSI3_2 = new JComboBox(agreeOptions); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("I can't read a musical score."), c); m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(goldMSI3_2, c); m@12: m@12: c.gridy = 9; m@12: goldMSI3_3 = new JComboBox(agreeOptions); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("I would not consider myself a musician."), c); m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(goldMSI3_3, c); m@12: m@12: c.gridy = 10; m@12: String[] goldMSI3_4o = {"", "0", "1", "2", "3", "4-5", "6-9", "10 or more"}; m@12: goldMSI3_4 = new JComboBox(goldMSI3_4o); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("I engaged in regular, daily practice of a musical instrument (including voice) for ------- years."), c); m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(goldMSI3_4, c); m@12: m@12: c.gridy = 11; m@12: String[] goldMSI3_5o = {"", "0", "0.5", "1", "1.5", "2", "3-4", "5 or more"}; m@12: goldMSI3_5 = new JComboBox(goldMSI3_4o); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("At the peak of my interest, I practised ------- hours per day on my primary instrument."), c); m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(goldMSI3_5, c); m@12: m@12: c.gridy = 12; m@12: goldMSI3_6 = new JComboBox(goldMSI3_4o); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("I have played or sung in a group, band, choir or orchestra for ------- years."), c); m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(goldMSI3_6, c); m@12: m@12: c.gridy = 13; m@12: String[] goldMSI3_7o = {"", "0", "0.5", "1", "2", "3", "4-6", "7 or more"}; m@12: goldMSI3_7 = new JComboBox(goldMSI3_7o); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("I have had formal training in music theory for ------- years."), c); m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(goldMSI3_7, c); m@12: m@12: c.gridy = 14; m@12: goldMSI3_8 = new JComboBox(goldMSI3_4o); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("I have had ------- years of formal training on a musical instrument (including voice) during my lifetime."), c); m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(goldMSI3_8, c); m@12: m@12: c.gridy = 15; m@12: String[] goldMSI3_9o = {"", "0", "1", "2", "3", "4", "5", "6 or more"}; m@12: goldMSI3_9 = new JComboBox(goldMSI3_9o); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("I can play ------- musical instruments."), c); m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(goldMSI3_9, c); m@0: m@0: // Put it all together m@0: JPanel finishPanel = new JPanel(); jeremy@27: finishButton = new JButton("Finish"); m@0: finishPanel.add(finishButton); m@0: m@0: JPanel topPanel = new JPanel(); m@0: topPanel.add(new JLabel("Please answer the following questions:"), m@0: BorderLayout.NORTH); m@0: m@12: //JPanel questionsPanel2 = new JPanel(); m@12: //questionsPanel2.setLayout(new BorderLayout()); m@12: //questionsPanel2.add(questionsPanel, BorderLayout.CENTER); m@0: marcus@19: JScrollPane questionsPanel2 = new JScrollPane(questionsPanel); marcus@19: m@0: //getRootPane().setDefaultButton(finishButton); m@0: this.setLayout (new BorderLayout()); marcus@21: if (gui.getExperiment().getFinalQuestionnaire()) { marcus@21: add(topPanel, BorderLayout.NORTH); marcus@21: add(questionsPanel2, BorderLayout.CENTER); marcus@21: } m@0: add(finishPanel,BorderLayout.SOUTH); m@0: } m@0: m@0: public void storeData() { m@0: ArrayList subjectData = new ArrayList(); m@0: String[] id = {"ID", Integer.toString(results.getSubjectID())}; m@0: subjectData.add(id); m@0: String[] age = {"Age",ageField.getText()}; m@0: subjectData.add(age); m@0: String[] sex = {"Gender",(String)sexBox.getSelectedItem()}; m@0: subjectData.add(sex); m@0: String[] hand = {"Hand",(String)handBox.getSelectedItem()}; m@0: subjectData.add(hand); m@12: String[] ethnicity = {"Ethnicity",(String)ethnicityBox.getSelectedItem()}; m@0: subjectData.add(ethnicity); m@0: String[] nationality = {"Nationality",nationalityField.getText()}; m@0: subjectData.add(nationality); m@0: String[] hear = {"HearingDiff", (String)hearingBox.getSelectedItem()}; m@0: subjectData.add(hear); m@12: String[] listening = {"Listening", listeningField.getText()}; m@0: subjectData.add(listening); m@12: m@12: String[] goldMSI3_1a = {"GoldMSI3.1", (String)goldMSI3_1.getSelectedItem()}; m@12: subjectData.add(goldMSI3_1a); m@12: String[] goldMSI3_2a = {"GoldMSI3.2", (String)goldMSI3_2.getSelectedItem()}; m@12: subjectData.add(goldMSI3_2a); m@12: String[] goldMSI3_3a = {"GoldMSI3.3", (String)goldMSI3_3.getSelectedItem()}; m@12: subjectData.add(goldMSI3_3a); m@12: String[] goldMSI3_4a = {"GoldMSI3.4", (String)goldMSI3_4.getSelectedItem()}; m@12: subjectData.add(goldMSI3_4a); m@12: String[] goldMSI3_5a = {"GoldMSI3.5", (String)goldMSI3_5.getSelectedItem()}; m@12: subjectData.add(goldMSI3_5a); m@12: String[] goldMSI3_6a = {"GoldMSI3.6", (String)goldMSI3_6.getSelectedItem()}; m@12: subjectData.add(goldMSI3_6a); m@12: String[] goldMSI3_7a = {"GoldMSI3.7", (String)goldMSI3_7.getSelectedItem()}; m@12: subjectData.add(goldMSI3_7a); m@12: String[] goldMSI3_8a = {"GoldMSI3.8", (String)goldMSI3_8.getSelectedItem()}; m@12: subjectData.add(goldMSI3_8a); m@12: String[] goldMSI3_9a = {"GoldMSI3.9", (String)goldMSI3_9.getSelectedItem()}; m@12: subjectData.add(goldMSI3_9a); m@12: m@0: results.setSubjectData(subjectData); m@0: } m@0: m@0: public boolean allDataEntered () { m@0: if (ageField.getText().equals("") || m@0: sexBox.getSelectedItem().equals("") || m@0: handBox.getSelectedItem().equals("") || m@0: ethnicityBox.getSelectedItem().equals("") || m@0: nationalityField.getText().equals("") || m@0: hearingBox.getSelectedItem().equals("") || m@12: listeningField.getText().equals("") || m@12: goldMSI3_1.getSelectedItem().equals("") || m@12: goldMSI3_2.getSelectedItem().equals("") || m@12: goldMSI3_3.getSelectedItem().equals("") || m@12: goldMSI3_4.getSelectedItem().equals("") || m@12: goldMSI3_5.getSelectedItem().equals("") || m@12: goldMSI3_6.getSelectedItem().equals("") || m@12: goldMSI3_7.getSelectedItem().equals("") || m@12: goldMSI3_8.getSelectedItem().equals("") || m@12: goldMSI3_9.getSelectedItem().equals("") m@12: ) m@0: return false; m@0: else return true; m@0: } m@0: m@0: public void addFinishButtonListener(ActionListener al) { m@0: finishButton.addActionListener(al); m@0: } m@0: }