annotate SubjectDataPanel.java @ 35:c860b5b4428d

Remove Block.class
author Jeremy Gow <jeremy.gow@gmail.com>
date Wed, 14 Nov 2012 12:15:51 +0000
parents 014c83185b2a
children 0e030f32a6e2
rev   line source
m@0 1 /*=============================================================================
m@0 2 * File: SubjectDataPanel.java
m@0 3 * Author: Marcus Pearce <m.pearce@gold.ac.uk>
m@0 4 * Created: <2007-02-14 11:28:27 marcusp>
marcus@21 5 * Time-stamp: <2012-03-27 16:48:33 marcusp>
m@0 6 *=============================================================================
m@0 7 */
m@0 8
m@0 9 import java.awt.*;
m@0 10 import java.awt.event.*;
m@0 11 import javax.swing.*;
m@0 12 import java.util.ArrayList;
m@0 13
m@0 14 public class SubjectDataPanel extends JPanel {
m@0 15
m@0 16 /* variables */
m@12 17 private JTextField ageField, listeningField, nationalityField;
m@12 18 private JComboBox sexBox, handBox, hearingBox, ethnicityBox,
m@12 19 goldMSI3_1, goldMSI3_2, goldMSI3_3, goldMSI3_4, goldMSI3_5, goldMSI3_6, goldMSI3_7, goldMSI3_8, goldMSI3_9;
m@12 20
m@0 21 private JButton finishButton;
m@0 22
m@0 23 private SubjectResults results;
m@0 24
m@0 25 /* accessors */
m@0 26 public JButton getFinishButton() { return finishButton; }
m@0 27
m@0 28 /* constructor */
m@0 29 public SubjectDataPanel(ExperimentGui gui, SubjectResults sr) {
m@0 30
m@0 31 results = sr;
m@0 32
m@0 33 JPanel questionsPanel = new JPanel();
m@12 34 questionsPanel.setLayout(new GridBagLayout());
m@12 35 GridBagConstraints c = new GridBagConstraints();
m@12 36 //c.fill = GridBagConstraints.BOTH;
m@12 37 c.ipadx = 10;
m@12 38 c.ipady = 30;
m@12 39 //c.insets = new Insets(50,50,50,50);
m@12 40
m@0 41 questionsPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(""),BorderFactory.createEmptyBorder(5,5,5,5)), questionsPanel.getBorder()));
m@0 42
m@0 43 String[] yesNoOptions = { "", "Yes", "No" };
m@12 44 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 45
m@0 46 // Age
m@12 47 c.gridy = 0;
m@12 48 c.gridx = 0;
m@0 49 ageField = new JTextField(10);
m@12 50 c.anchor = GridBagConstraints.EAST;
m@0 51 questionsPanel.add(new JLabel("Age: "));
m@12 52 c.gridx = 1;
m@12 53 c.anchor = GridBagConstraints.WEST;
m@12 54 questionsPanel.add(ageField, c);
m@0 55
m@0 56 // Gender
m@12 57 c.gridx = GridBagConstraints.RELATIVE;
m@12 58 c.gridy = 1;
m@0 59 String[] sexBoxOptions = { "", "Male", "Female" };
m@0 60 sexBox = new JComboBox(sexBoxOptions);
m@0 61 sexBox.setSelectedIndex(0);
m@12 62 c.anchor = GridBagConstraints.EAST;
m@12 63 questionsPanel.add(new JLabel("Sex: "), c);
m@12 64 c.anchor = GridBagConstraints.WEST;
m@12 65 questionsPanel.add(sexBox, c);
m@0 66
m@12 67 // Ethnicity
m@12 68 c.gridy = 2;
m@0 69 String[] ethnicityBoxOptions =
m@0 70 { "", "Asian", "Black", "Chinese", "Mixed", "Other", "White",
m@0 71 "Undisclosed" };
m@0 72 ethnicityBox = new JComboBox(ethnicityBoxOptions);
m@12 73 c.anchor = GridBagConstraints.EAST;
m@12 74 questionsPanel.add(new JLabel("Ethnicity: "), c);
m@12 75 c.anchor = GridBagConstraints.WEST;
m@12 76 questionsPanel.add(ethnicityBox, c);
m@0 77
m@12 78 // Nationality
m@12 79 c.gridy = 3;
m@0 80 nationalityField = new JTextField(10);
m@12 81 c.anchor = GridBagConstraints.EAST;
m@12 82 questionsPanel.add(new JLabel("Nationality: "), c);
m@12 83 c.anchor = GridBagConstraints.WEST;
m@12 84 questionsPanel.add(nationalityField, c);
m@0 85
m@0 86 // Handedness
m@12 87 c.gridy = 4;
m@0 88 String[] handBoxOptions = { "", "Right-handed", "Left-handed" };
m@0 89 handBox = new JComboBox(handBoxOptions);
m@0 90 handBox.setSelectedIndex(0);
m@12 91 c.anchor = GridBagConstraints.EAST;
m@12 92 questionsPanel.add(new JLabel("Handedness: "), c);
m@12 93 c.anchor = GridBagConstraints.WEST;
m@12 94 questionsPanel.add(handBox, c);
m@0 95
m@0 96 // Hearing
m@12 97 c.gridy = 5;
m@0 98 hearingBox = new JComboBox(yesNoOptions);
m@12 99 c.anchor = GridBagConstraints.EAST;
m@12 100 questionsPanel.add(new JLabel("Do you have any hearing difficulties?"), c);
m@12 101 c.anchor = GridBagConstraints.WEST;
m@12 102 questionsPanel.add(hearingBox, c);
m@0 103
m@0 104 // Musical Listening
m@12 105 c.gridy = 6;
m@0 106 listeningField = new JTextField(10);
m@12 107 c.anchor = GridBagConstraints.EAST;
m@12 108 questionsPanel.add(new JLabel("How many hours per day do you spend listening to music?"), c);
m@12 109 c.anchor = GridBagConstraints.WEST;
m@12 110 questionsPanel.add(listeningField, c);
m@12 111
m@12 112 // GOLDMSI
m@12 113 c.gridy = 7;
m@12 114 goldMSI3_1 = new JComboBox(agreeOptions);
m@12 115 c.anchor = GridBagConstraints.EAST;
m@12 116 questionsPanel.add(new JLabel("I have never been complimented on my talents as a musical performer."), c);
m@12 117 c.anchor = GridBagConstraints.WEST;
m@12 118 questionsPanel.add(goldMSI3_1, c);
m@12 119
m@12 120 c.gridy = 8;
m@12 121 goldMSI3_2 = new JComboBox(agreeOptions);
m@12 122 c.anchor = GridBagConstraints.EAST;
m@12 123 questionsPanel.add(new JLabel("I can't read a musical score."), c);
m@12 124 c.anchor = GridBagConstraints.WEST;
m@12 125 questionsPanel.add(goldMSI3_2, c);
m@12 126
m@12 127 c.gridy = 9;
m@12 128 goldMSI3_3 = new JComboBox(agreeOptions);
m@12 129 c.anchor = GridBagConstraints.EAST;
m@12 130 questionsPanel.add(new JLabel("I would not consider myself a musician."), c);
m@12 131 c.anchor = GridBagConstraints.WEST;
m@12 132 questionsPanel.add(goldMSI3_3, c);
m@12 133
m@12 134 c.gridy = 10;
m@12 135 String[] goldMSI3_4o = {"", "0", "1", "2", "3", "4-5", "6-9", "10 or more"};
m@12 136 goldMSI3_4 = new JComboBox(goldMSI3_4o);
m@12 137 c.anchor = GridBagConstraints.EAST;
m@12 138 questionsPanel.add(new JLabel("I engaged in regular, daily practice of a musical instrument (including voice) for ------- years."), c);
m@12 139 c.anchor = GridBagConstraints.WEST;
m@12 140 questionsPanel.add(goldMSI3_4, c);
m@12 141
m@12 142 c.gridy = 11;
m@12 143 String[] goldMSI3_5o = {"", "0", "0.5", "1", "1.5", "2", "3-4", "5 or more"};
m@12 144 goldMSI3_5 = new JComboBox(goldMSI3_4o);
m@12 145 c.anchor = GridBagConstraints.EAST;
m@12 146 questionsPanel.add(new JLabel("At the peak of my interest, I practised ------- hours per day on my primary instrument."), c);
m@12 147 c.anchor = GridBagConstraints.WEST;
m@12 148 questionsPanel.add(goldMSI3_5, c);
m@12 149
m@12 150 c.gridy = 12;
m@12 151 goldMSI3_6 = new JComboBox(goldMSI3_4o);
m@12 152 c.anchor = GridBagConstraints.EAST;
m@12 153 questionsPanel.add(new JLabel("I have played or sung in a group, band, choir or orchestra for ------- years."), c);
m@12 154 c.anchor = GridBagConstraints.WEST;
m@12 155 questionsPanel.add(goldMSI3_6, c);
m@12 156
m@12 157 c.gridy = 13;
m@12 158 String[] goldMSI3_7o = {"", "0", "0.5", "1", "2", "3", "4-6", "7 or more"};
m@12 159 goldMSI3_7 = new JComboBox(goldMSI3_7o);
m@12 160 c.anchor = GridBagConstraints.EAST;
m@12 161 questionsPanel.add(new JLabel("I have had formal training in music theory for ------- years."), c);
m@12 162 c.anchor = GridBagConstraints.WEST;
m@12 163 questionsPanel.add(goldMSI3_7, c);
m@12 164
m@12 165 c.gridy = 14;
m@12 166 goldMSI3_8 = new JComboBox(goldMSI3_4o);
m@12 167 c.anchor = GridBagConstraints.EAST;
m@12 168 questionsPanel.add(new JLabel("I have had ------- years of formal training on a musical instrument (including voice) during my lifetime."), c);
m@12 169 c.anchor = GridBagConstraints.WEST;
m@12 170 questionsPanel.add(goldMSI3_8, c);
m@12 171
m@12 172 c.gridy = 15;
m@12 173 String[] goldMSI3_9o = {"", "0", "1", "2", "3", "4", "5", "6 or more"};
m@12 174 goldMSI3_9 = new JComboBox(goldMSI3_9o);
m@12 175 c.anchor = GridBagConstraints.EAST;
m@12 176 questionsPanel.add(new JLabel("I can play ------- musical instruments."), c);
m@12 177 c.anchor = GridBagConstraints.WEST;
m@12 178 questionsPanel.add(goldMSI3_9, c);
m@0 179
m@0 180 // Put it all together
m@0 181 JPanel finishPanel = new JPanel();
jeremy@27 182 finishButton = new JButton("Finish");
m@0 183 finishPanel.add(finishButton);
m@0 184
m@0 185 JPanel topPanel = new JPanel();
m@0 186 topPanel.add(new JLabel("Please answer the following questions:"),
m@0 187 BorderLayout.NORTH);
m@0 188
m@12 189 //JPanel questionsPanel2 = new JPanel();
m@12 190 //questionsPanel2.setLayout(new BorderLayout());
m@12 191 //questionsPanel2.add(questionsPanel, BorderLayout.CENTER);
m@0 192
marcus@19 193 JScrollPane questionsPanel2 = new JScrollPane(questionsPanel);
marcus@19 194
m@0 195 //getRootPane().setDefaultButton(finishButton);
m@0 196 this.setLayout (new BorderLayout());
marcus@21 197 if (gui.getExperiment().getFinalQuestionnaire()) {
marcus@21 198 add(topPanel, BorderLayout.NORTH);
marcus@21 199 add(questionsPanel2, BorderLayout.CENTER);
marcus@21 200 }
m@0 201 add(finishPanel,BorderLayout.SOUTH);
m@0 202 }
m@0 203
m@0 204 public void storeData() {
m@0 205 ArrayList subjectData = new ArrayList();
m@0 206 String[] id = {"ID", Integer.toString(results.getSubjectID())};
m@0 207 subjectData.add(id);
m@0 208 String[] age = {"Age",ageField.getText()};
m@0 209 subjectData.add(age);
m@0 210 String[] sex = {"Gender",(String)sexBox.getSelectedItem()};
m@0 211 subjectData.add(sex);
m@0 212 String[] hand = {"Hand",(String)handBox.getSelectedItem()};
m@0 213 subjectData.add(hand);
m@12 214 String[] ethnicity = {"Ethnicity",(String)ethnicityBox.getSelectedItem()};
m@0 215 subjectData.add(ethnicity);
m@0 216 String[] nationality = {"Nationality",nationalityField.getText()};
m@0 217 subjectData.add(nationality);
m@0 218 String[] hear = {"HearingDiff", (String)hearingBox.getSelectedItem()};
m@0 219 subjectData.add(hear);
m@12 220 String[] listening = {"Listening", listeningField.getText()};
m@0 221 subjectData.add(listening);
m@12 222
m@12 223 String[] goldMSI3_1a = {"GoldMSI3.1", (String)goldMSI3_1.getSelectedItem()};
m@12 224 subjectData.add(goldMSI3_1a);
m@12 225 String[] goldMSI3_2a = {"GoldMSI3.2", (String)goldMSI3_2.getSelectedItem()};
m@12 226 subjectData.add(goldMSI3_2a);
m@12 227 String[] goldMSI3_3a = {"GoldMSI3.3", (String)goldMSI3_3.getSelectedItem()};
m@12 228 subjectData.add(goldMSI3_3a);
m@12 229 String[] goldMSI3_4a = {"GoldMSI3.4", (String)goldMSI3_4.getSelectedItem()};
m@12 230 subjectData.add(goldMSI3_4a);
m@12 231 String[] goldMSI3_5a = {"GoldMSI3.5", (String)goldMSI3_5.getSelectedItem()};
m@12 232 subjectData.add(goldMSI3_5a);
m@12 233 String[] goldMSI3_6a = {"GoldMSI3.6", (String)goldMSI3_6.getSelectedItem()};
m@12 234 subjectData.add(goldMSI3_6a);
m@12 235 String[] goldMSI3_7a = {"GoldMSI3.7", (String)goldMSI3_7.getSelectedItem()};
m@12 236 subjectData.add(goldMSI3_7a);
m@12 237 String[] goldMSI3_8a = {"GoldMSI3.8", (String)goldMSI3_8.getSelectedItem()};
m@12 238 subjectData.add(goldMSI3_8a);
m@12 239 String[] goldMSI3_9a = {"GoldMSI3.9", (String)goldMSI3_9.getSelectedItem()};
m@12 240 subjectData.add(goldMSI3_9a);
m@12 241
m@0 242 results.setSubjectData(subjectData);
m@0 243 }
m@0 244
m@0 245 public boolean allDataEntered () {
m@0 246 if (ageField.getText().equals("") ||
m@0 247 sexBox.getSelectedItem().equals("") ||
m@0 248 handBox.getSelectedItem().equals("") ||
m@0 249 ethnicityBox.getSelectedItem().equals("") ||
m@0 250 nationalityField.getText().equals("") ||
m@0 251 hearingBox.getSelectedItem().equals("") ||
m@12 252 listeningField.getText().equals("") ||
m@12 253 goldMSI3_1.getSelectedItem().equals("") ||
m@12 254 goldMSI3_2.getSelectedItem().equals("") ||
m@12 255 goldMSI3_3.getSelectedItem().equals("") ||
m@12 256 goldMSI3_4.getSelectedItem().equals("") ||
m@12 257 goldMSI3_5.getSelectedItem().equals("") ||
m@12 258 goldMSI3_6.getSelectedItem().equals("") ||
m@12 259 goldMSI3_7.getSelectedItem().equals("") ||
m@12 260 goldMSI3_8.getSelectedItem().equals("") ||
m@12 261 goldMSI3_9.getSelectedItem().equals("")
m@12 262 )
m@0 263 return false;
m@0 264 else return true;
m@0 265 }
m@0 266
m@0 267 public void addFinishButtonListener(ActionListener al) {
m@0 268 finishButton.addActionListener(al);
m@0 269 }
m@0 270 }