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, CBussey@39: goldMSI3_1, goldMSI3_2, goldMSI3_3, goldMSI3_4, goldMSI3_5, goldMSI3_6, goldMSI3_7, goldMSI3_8, goldMSI3_9, goldMSI3_10; m@12: m@0: private JButton finishButton; m@0: CBussey@39: private SubjectResults results; CBussey@39: CBussey@39: private boolean askFamiliarity = false; m@0: m@0: /* accessors */ m@0: public JButton getFinishButton() { return finishButton; } m@0: CBussey@39: /* constructors */ CBussey@39: public SubjectDataPanel(ExperimentGui gui, SubjectResults sr) { CBussey@39: this(gui, sr, false); CBussey@39: } CBussey@39: CBussey@39: public SubjectDataPanel(ExperimentGui gui, SubjectResults sr, boolean askFamiliarity) { CBussey@39: CBussey@39: this.askFamiliarity = askFamiliarity; m@0: results = sr; m@0: m@0: JPanel questionsPanel = new JPanel(); m@12: questionsPanel.setLayout(new GridBagLayout()); c@46: questionsPanel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); m@12: GridBagConstraints c = new GridBagConstraints(); c@46: //c.fill = GridBagConstraints.HORIZONTAL; 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" }; c@46: c@46: int componentHeight=10; c@46: int componentWidth=230; c@46: m@0: // Age m@12: c.gridy = 0; m@12: c.gridx = 0; c@46: ageField = new JTextField(18); m@12: c.anchor = GridBagConstraints.EAST; c@46: ageField.setPreferredSize(new Dimension(componentWidth,componentHeight)); c@46: questionsPanel.add(new JLabel("Age: "), c); c@46: c.gridy = 0; m@12: c.gridx = 1; m@12: c.anchor = GridBagConstraints.WEST; c@46: questionsPanel.add(ageField, c); m@0: m@0: // Gender m@12: c.gridy = 1; c@46: c.gridx = 0; m@0: String[] sexBoxOptions = { "", "Male", "Female" }; m@0: sexBox = new JComboBox(sexBoxOptions); c@46: sexBox.setSelectedIndex(0); c@46: sexBox.setPreferredSize(new Dimension(componentWidth,componentHeight)); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("Sex: "), c); c@46: c.gridy = 1; c@46: c.gridx = 1; m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(sexBox, c); m@0: m@12: // Ethnicity m@12: c.gridy = 2; c@46: c.gridx = 0; m@0: String[] ethnicityBoxOptions = m@0: { "", "Asian", "Black", "Chinese", "Mixed", "Other", "White", m@0: "Undisclosed" }; c@46: ethnicityBox = new JComboBox(ethnicityBoxOptions); c@46: ethnicityBox.setPreferredSize(new Dimension(componentWidth,componentHeight)); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("Ethnicity: "), c); m@12: c.anchor = GridBagConstraints.WEST; c@46: c.gridy = 2; c@46: c.gridx = 1; m@12: questionsPanel.add(ethnicityBox, c); m@0: m@12: // Nationality c@46: nationalityField = new JTextField(18); c@46: nationalityField.setPreferredSize(new Dimension(componentWidth,componentHeight)); c@46: c.anchor = GridBagConstraints.EAST; m@12: c.gridy = 3; c@46: c.gridx = 0; m@12: questionsPanel.add(new JLabel("Nationality: "), c); m@12: c.anchor = GridBagConstraints.WEST; c@46: c.gridy = 3; c@46: c.gridx = 1; m@12: questionsPanel.add(nationalityField, c); m@0: m@0: // Handedness m@12: c.gridy = 4; c@46: c.gridx = 0; m@0: String[] handBoxOptions = { "", "Right-handed", "Left-handed" }; c@46: handBox = new JComboBox(handBoxOptions); c@46: handBox.setPreferredSize(new Dimension(componentWidth,componentHeight)); 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; c@46: c.gridy = 4; c@46: c.gridx = 1; m@12: questionsPanel.add(handBox, c); m@0: m@0: // Hearing m@12: c.gridy = 5; c@46: c.gridx = 0; c@46: hearingBox = new JComboBox(yesNoOptions); c@46: hearingBox.setPreferredSize(new Dimension(componentWidth,componentHeight)); m@12: c.anchor = GridBagConstraints.EAST; c@46: questionsPanel.add(new JLabel("Do you have any hearing difficulties?"), c); m@12: c.anchor = GridBagConstraints.WEST; c@46: c.gridy = 5; c@46: c.gridx = 1; m@12: questionsPanel.add(hearingBox, c); m@0: m@0: // Musical Listening m@12: c.gridy = 6; c@46: c.gridx = 0; c@46: listeningField = new JTextField(18); c@46: listeningField.setPreferredSize(new Dimension(componentWidth,componentHeight)); 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; c@46: c.gridy = 6; c@46: c.gridx = 1; m@12: questionsPanel.add(listeningField, c); m@12: m@12: // GOLDMSI m@12: c.gridy = 7; c@46: c.gridx = 0; m@12: goldMSI3_1 = new JComboBox(agreeOptions); c@46: goldMSI3_1.setPreferredSize(new Dimension(componentWidth,componentHeight)); 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; c@46: c.gridy = 7; c@46: c.gridx = 1; m@12: questionsPanel.add(goldMSI3_1, c); m@12: m@12: c.gridy = 8; c@46: c.gridx = 0; m@12: goldMSI3_2 = new JComboBox(agreeOptions); c@46: goldMSI3_2.setPreferredSize(new Dimension(componentWidth,componentHeight)); 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; c@46: c.gridy = 8; c@46: c.gridx = 1; m@12: questionsPanel.add(goldMSI3_2, c); m@12: c@46: c.gridy = 9; c@46: c.gridx = 0; m@12: goldMSI3_3 = new JComboBox(agreeOptions); c@46: goldMSI3_3.setPreferredSize(new Dimension(componentWidth,componentHeight)); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("I would not consider myself a musician."), c); c@46: c.gridy = 9; c@46: c.gridx = 1; m@12: c.anchor = GridBagConstraints.WEST; m@12: questionsPanel.add(goldMSI3_3, c); m@12: m@12: c.gridy = 10; c@46: c.gridx = 0; m@12: String[] goldMSI3_4o = {"", "0", "1", "2", "3", "4-5", "6-9", "10 or more"}; m@12: goldMSI3_4 = new JComboBox(goldMSI3_4o); c@46: goldMSI3_4.setPreferredSize(new Dimension(componentWidth,componentHeight)); 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; c@46: c.gridy = 10; c@46: c.gridx = 1; m@12: questionsPanel.add(goldMSI3_4, c); m@12: m@12: c.gridy = 11; c@46: c.gridx = 0; 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); c@46: goldMSI3_5.setPreferredSize(new Dimension(componentWidth,componentHeight)); 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; c@46: c.gridy = 11; c@46: c.gridx = 1; m@12: questionsPanel.add(goldMSI3_5, c); m@12: m@12: c.gridy = 12; c@46: c.gridx = 0; m@12: goldMSI3_6 = new JComboBox(goldMSI3_4o); c@46: goldMSI3_6.setPreferredSize(new Dimension(componentWidth,componentHeight)); 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; c@46: c.gridy = 12; c@46: c.gridx = 1; m@12: questionsPanel.add(goldMSI3_6, c); m@12: m@12: c.gridy = 13; c@46: c.gridx = 0; c@46: String[] goldMSI3_7o = {"", "0", "0.5", "1", "2", "3", "4-6", "7 or more"}; m@12: goldMSI3_7 = new JComboBox(goldMSI3_7o); c@46: goldMSI3_7.setPreferredSize(new Dimension(componentWidth,componentHeight)); 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; c@46: c.gridy = 13; c@46: c.gridx = 1; m@12: questionsPanel.add(goldMSI3_7, c); m@12: m@12: c.gridy = 14; c@46: c.gridx = 0; m@12: goldMSI3_8 = new JComboBox(goldMSI3_4o); c@46: goldMSI3_8.setPreferredSize(new Dimension(componentWidth,componentHeight)); 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; c@46: c.gridy = 14; c@46: c.gridx = 1; m@12: questionsPanel.add(goldMSI3_8, c); m@12: m@12: c.gridy = 15; c@46: c.gridx = 0; m@12: String[] goldMSI3_9o = {"", "0", "1", "2", "3", "4", "5", "6 or more"}; m@12: goldMSI3_9 = new JComboBox(goldMSI3_9o); c@46: goldMSI3_9.setPreferredSize(new Dimension(componentWidth,componentHeight)); m@12: c.anchor = GridBagConstraints.EAST; m@12: questionsPanel.add(new JLabel("I can play ------- musical instruments."), c); m@12: c.anchor = GridBagConstraints.WEST; c@46: c.gridy = 15; c@46: c.gridx = 1; m@12: questionsPanel.add(goldMSI3_9, c); m@0: CBussey@39: if(askFamiliarity){ CBussey@39: c.gridy = 16; c@46: c.gridx = 0; c@40: String[] goldMSI3_10o = {"", "0%", "25%", "50%", "75%", "100%"}; CBussey@39: goldMSI3_10 = new JComboBox(goldMSI3_10o); c@46: goldMSI3_10.setPreferredSize(new Dimension(componentWidth,componentHeight)); CBussey@39: c.anchor = GridBagConstraints.EAST; c@41: questionsPanel.add(new JLabel("I was familiar with approximately ------- of the songs."), c); CBussey@39: c.anchor = GridBagConstraints.WEST; c@46: c.gridy = 16; c@46: c.gridx = 1; CBussey@39: questionsPanel.add(goldMSI3_10, c); CBussey@39: } CBussey@39: 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); c@46: 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(); jeremy@37: String[] id = {"ID", 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()}; CBussey@39: if(askFamiliarity){ CBussey@39: subjectData.add(goldMSI3_9a); CBussey@39: String[] goldMSI3_10a = {"GoldMSI3.10", (String)goldMSI3_10.getSelectedItem()}; CBussey@39: subjectData.add(goldMSI3_10a); CBussey@39: } m@12: CBussey@39: results.setSubjectData(subjectData); m@0: } m@0: m@0: public boolean allDataEntered () { CBussey@39: 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("") || CBussey@39: goldMSI3_9.getSelectedItem().equals("") m@12: ) CBussey@39: return false; CBussey@39: else if (askFamiliarity && goldMSI3_10.getSelectedItem().equals("")) return false; CBussey@39: else return true; m@0: } m@0: m@0: public void addFinishButtonListener(ActionListener al) { m@0: finishButton.addActionListener(al); m@0: } m@0: }