annotate SubjectDataPanel.java @ 52:76e99859bdb4 tip

Add class files for previous changes.
author Marcus Pearce <marcus.pearce@eecs.qmul.ac.uk>
date Wed, 25 Feb 2015 10:11:04 +0000
parents 5f9dde32392f
children
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,
CBussey@39 19 goldMSI3_1, goldMSI3_2, goldMSI3_3, goldMSI3_4, goldMSI3_5, goldMSI3_6, goldMSI3_7, goldMSI3_8, goldMSI3_9, goldMSI3_10;
m@12 20
m@0 21 private JButton finishButton;
m@0 22
CBussey@39 23 private SubjectResults results;
CBussey@39 24
CBussey@39 25 private boolean askFamiliarity = false;
m@0 26
m@0 27 /* accessors */
m@0 28 public JButton getFinishButton() { return finishButton; }
m@0 29
CBussey@39 30 /* constructors */
CBussey@39 31 public SubjectDataPanel(ExperimentGui gui, SubjectResults sr) {
CBussey@39 32 this(gui, sr, false);
CBussey@39 33 }
CBussey@39 34
CBussey@39 35 public SubjectDataPanel(ExperimentGui gui, SubjectResults sr, boolean askFamiliarity) {
CBussey@39 36
CBussey@39 37 this.askFamiliarity = askFamiliarity;
m@0 38 results = sr;
m@0 39
m@0 40 JPanel questionsPanel = new JPanel();
m@12 41 questionsPanel.setLayout(new GridBagLayout());
c@46 42 questionsPanel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
m@12 43 GridBagConstraints c = new GridBagConstraints();
c@46 44 //c.fill = GridBagConstraints.HORIZONTAL;
m@12 45 c.ipadx = 10;
m@12 46 c.ipady = 30;
m@12 47 //c.insets = new Insets(50,50,50,50);
m@12 48
m@0 49 questionsPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(""),BorderFactory.createEmptyBorder(5,5,5,5)), questionsPanel.getBorder()));
m@0 50
m@0 51 String[] yesNoOptions = { "", "Yes", "No" };
m@12 52 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 53
c@46 54 int componentHeight=10;
c@46 55 int componentWidth=230;
c@46 56
m@0 57 // Age
m@12 58 c.gridy = 0;
m@12 59 c.gridx = 0;
c@46 60 ageField = new JTextField(18);
m@12 61 c.anchor = GridBagConstraints.EAST;
c@46 62 ageField.setPreferredSize(new Dimension(componentWidth,componentHeight));
c@46 63 questionsPanel.add(new JLabel("Age: "), c);
c@46 64 c.gridy = 0;
m@12 65 c.gridx = 1;
m@12 66 c.anchor = GridBagConstraints.WEST;
c@46 67 questionsPanel.add(ageField, c);
m@0 68
m@0 69 // Gender
m@12 70 c.gridy = 1;
c@46 71 c.gridx = 0;
m@0 72 String[] sexBoxOptions = { "", "Male", "Female" };
m@0 73 sexBox = new JComboBox(sexBoxOptions);
c@46 74 sexBox.setSelectedIndex(0);
c@46 75 sexBox.setPreferredSize(new Dimension(componentWidth,componentHeight));
m@12 76 c.anchor = GridBagConstraints.EAST;
m@12 77 questionsPanel.add(new JLabel("Sex: "), c);
c@46 78 c.gridy = 1;
c@46 79 c.gridx = 1;
m@12 80 c.anchor = GridBagConstraints.WEST;
m@12 81 questionsPanel.add(sexBox, c);
m@0 82
m@12 83 // Ethnicity
m@12 84 c.gridy = 2;
c@46 85 c.gridx = 0;
m@0 86 String[] ethnicityBoxOptions =
m@0 87 { "", "Asian", "Black", "Chinese", "Mixed", "Other", "White",
m@0 88 "Undisclosed" };
c@46 89 ethnicityBox = new JComboBox(ethnicityBoxOptions);
c@46 90 ethnicityBox.setPreferredSize(new Dimension(componentWidth,componentHeight));
m@12 91 c.anchor = GridBagConstraints.EAST;
m@12 92 questionsPanel.add(new JLabel("Ethnicity: "), c);
m@12 93 c.anchor = GridBagConstraints.WEST;
c@46 94 c.gridy = 2;
c@46 95 c.gridx = 1;
m@12 96 questionsPanel.add(ethnicityBox, c);
m@0 97
m@12 98 // Nationality
c@46 99 nationalityField = new JTextField(18);
c@46 100 nationalityField.setPreferredSize(new Dimension(componentWidth,componentHeight));
c@46 101 c.anchor = GridBagConstraints.EAST;
m@12 102 c.gridy = 3;
c@46 103 c.gridx = 0;
m@12 104 questionsPanel.add(new JLabel("Nationality: "), c);
m@12 105 c.anchor = GridBagConstraints.WEST;
c@46 106 c.gridy = 3;
c@46 107 c.gridx = 1;
m@12 108 questionsPanel.add(nationalityField, c);
m@0 109
m@0 110 // Handedness
m@12 111 c.gridy = 4;
c@46 112 c.gridx = 0;
m@0 113 String[] handBoxOptions = { "", "Right-handed", "Left-handed" };
c@46 114 handBox = new JComboBox(handBoxOptions);
c@46 115 handBox.setPreferredSize(new Dimension(componentWidth,componentHeight));
m@0 116 handBox.setSelectedIndex(0);
m@12 117 c.anchor = GridBagConstraints.EAST;
m@12 118 questionsPanel.add(new JLabel("Handedness: "), c);
m@12 119 c.anchor = GridBagConstraints.WEST;
c@46 120 c.gridy = 4;
c@46 121 c.gridx = 1;
m@12 122 questionsPanel.add(handBox, c);
m@0 123
m@0 124 // Hearing
m@12 125 c.gridy = 5;
c@46 126 c.gridx = 0;
c@46 127 hearingBox = new JComboBox(yesNoOptions);
c@46 128 hearingBox.setPreferredSize(new Dimension(componentWidth,componentHeight));
m@12 129 c.anchor = GridBagConstraints.EAST;
c@46 130 questionsPanel.add(new JLabel("Do you have any hearing difficulties?"), c);
m@12 131 c.anchor = GridBagConstraints.WEST;
c@46 132 c.gridy = 5;
c@46 133 c.gridx = 1;
m@12 134 questionsPanel.add(hearingBox, c);
m@0 135
m@0 136 // Musical Listening
m@12 137 c.gridy = 6;
c@46 138 c.gridx = 0;
c@46 139 listeningField = new JTextField(18);
c@46 140 listeningField.setPreferredSize(new Dimension(componentWidth,componentHeight));
m@12 141 c.anchor = GridBagConstraints.EAST;
m@12 142 questionsPanel.add(new JLabel("How many hours per day do you spend listening to music?"), c);
m@12 143 c.anchor = GridBagConstraints.WEST;
c@46 144 c.gridy = 6;
c@46 145 c.gridx = 1;
m@12 146 questionsPanel.add(listeningField, c);
m@12 147
m@12 148 // GOLDMSI
m@12 149 c.gridy = 7;
c@46 150 c.gridx = 0;
m@12 151 goldMSI3_1 = new JComboBox(agreeOptions);
c@46 152 goldMSI3_1.setPreferredSize(new Dimension(componentWidth,componentHeight));
m@12 153 c.anchor = GridBagConstraints.EAST;
m@12 154 questionsPanel.add(new JLabel("I have never been complimented on my talents as a musical performer."), c);
m@12 155 c.anchor = GridBagConstraints.WEST;
c@46 156 c.gridy = 7;
c@46 157 c.gridx = 1;
m@12 158 questionsPanel.add(goldMSI3_1, c);
m@12 159
m@12 160 c.gridy = 8;
c@46 161 c.gridx = 0;
m@12 162 goldMSI3_2 = new JComboBox(agreeOptions);
c@46 163 goldMSI3_2.setPreferredSize(new Dimension(componentWidth,componentHeight));
m@12 164 c.anchor = GridBagConstraints.EAST;
m@12 165 questionsPanel.add(new JLabel("I can't read a musical score."), c);
m@12 166 c.anchor = GridBagConstraints.WEST;
c@46 167 c.gridy = 8;
c@46 168 c.gridx = 1;
m@12 169 questionsPanel.add(goldMSI3_2, c);
m@12 170
c@46 171 c.gridy = 9;
c@46 172 c.gridx = 0;
m@12 173 goldMSI3_3 = new JComboBox(agreeOptions);
c@46 174 goldMSI3_3.setPreferredSize(new Dimension(componentWidth,componentHeight));
m@12 175 c.anchor = GridBagConstraints.EAST;
m@12 176 questionsPanel.add(new JLabel("I would not consider myself a musician."), c);
c@46 177 c.gridy = 9;
c@46 178 c.gridx = 1;
m@12 179 c.anchor = GridBagConstraints.WEST;
m@12 180 questionsPanel.add(goldMSI3_3, c);
m@12 181
m@12 182 c.gridy = 10;
c@46 183 c.gridx = 0;
m@12 184 String[] goldMSI3_4o = {"", "0", "1", "2", "3", "4-5", "6-9", "10 or more"};
m@12 185 goldMSI3_4 = new JComboBox(goldMSI3_4o);
c@46 186 goldMSI3_4.setPreferredSize(new Dimension(componentWidth,componentHeight));
m@12 187 c.anchor = GridBagConstraints.EAST;
m@12 188 questionsPanel.add(new JLabel("I engaged in regular, daily practice of a musical instrument (including voice) for ------- years."), c);
m@12 189 c.anchor = GridBagConstraints.WEST;
c@46 190 c.gridy = 10;
c@46 191 c.gridx = 1;
m@12 192 questionsPanel.add(goldMSI3_4, c);
m@12 193
m@12 194 c.gridy = 11;
c@46 195 c.gridx = 0;
m@12 196 String[] goldMSI3_5o = {"", "0", "0.5", "1", "1.5", "2", "3-4", "5 or more"};
m@12 197 goldMSI3_5 = new JComboBox(goldMSI3_4o);
c@46 198 goldMSI3_5.setPreferredSize(new Dimension(componentWidth,componentHeight));
m@12 199 c.anchor = GridBagConstraints.EAST;
m@12 200 questionsPanel.add(new JLabel("At the peak of my interest, I practised ------- hours per day on my primary instrument."), c);
m@12 201 c.anchor = GridBagConstraints.WEST;
c@46 202 c.gridy = 11;
c@46 203 c.gridx = 1;
m@12 204 questionsPanel.add(goldMSI3_5, c);
m@12 205
m@12 206 c.gridy = 12;
c@46 207 c.gridx = 0;
m@12 208 goldMSI3_6 = new JComboBox(goldMSI3_4o);
c@46 209 goldMSI3_6.setPreferredSize(new Dimension(componentWidth,componentHeight));
m@12 210 c.anchor = GridBagConstraints.EAST;
m@12 211 questionsPanel.add(new JLabel("I have played or sung in a group, band, choir or orchestra for ------- years."), c);
m@12 212 c.anchor = GridBagConstraints.WEST;
c@46 213 c.gridy = 12;
c@46 214 c.gridx = 1;
m@12 215 questionsPanel.add(goldMSI3_6, c);
m@12 216
m@12 217 c.gridy = 13;
c@46 218 c.gridx = 0;
c@46 219 String[] goldMSI3_7o = {"", "0", "0.5", "1", "2", "3", "4-6", "7 or more"};
m@12 220 goldMSI3_7 = new JComboBox(goldMSI3_7o);
c@46 221 goldMSI3_7.setPreferredSize(new Dimension(componentWidth,componentHeight));
m@12 222 c.anchor = GridBagConstraints.EAST;
m@12 223 questionsPanel.add(new JLabel("I have had formal training in music theory for ------- years."), c);
m@12 224 c.anchor = GridBagConstraints.WEST;
c@46 225 c.gridy = 13;
c@46 226 c.gridx = 1;
m@12 227 questionsPanel.add(goldMSI3_7, c);
m@12 228
m@12 229 c.gridy = 14;
c@46 230 c.gridx = 0;
m@12 231 goldMSI3_8 = new JComboBox(goldMSI3_4o);
c@46 232 goldMSI3_8.setPreferredSize(new Dimension(componentWidth,componentHeight));
m@12 233 c.anchor = GridBagConstraints.EAST;
m@12 234 questionsPanel.add(new JLabel("I have had ------- years of formal training on a musical instrument (including voice) during my lifetime."), c);
m@12 235 c.anchor = GridBagConstraints.WEST;
c@46 236 c.gridy = 14;
c@46 237 c.gridx = 1;
m@12 238 questionsPanel.add(goldMSI3_8, c);
m@12 239
m@12 240 c.gridy = 15;
c@46 241 c.gridx = 0;
m@12 242 String[] goldMSI3_9o = {"", "0", "1", "2", "3", "4", "5", "6 or more"};
m@12 243 goldMSI3_9 = new JComboBox(goldMSI3_9o);
c@46 244 goldMSI3_9.setPreferredSize(new Dimension(componentWidth,componentHeight));
m@12 245 c.anchor = GridBagConstraints.EAST;
m@12 246 questionsPanel.add(new JLabel("I can play ------- musical instruments."), c);
m@12 247 c.anchor = GridBagConstraints.WEST;
c@46 248 c.gridy = 15;
c@46 249 c.gridx = 1;
m@12 250 questionsPanel.add(goldMSI3_9, c);
m@0 251
CBussey@39 252 if(askFamiliarity){
CBussey@39 253 c.gridy = 16;
c@46 254 c.gridx = 0;
c@40 255 String[] goldMSI3_10o = {"", "0%", "25%", "50%", "75%", "100%"};
CBussey@39 256 goldMSI3_10 = new JComboBox(goldMSI3_10o);
c@46 257 goldMSI3_10.setPreferredSize(new Dimension(componentWidth,componentHeight));
CBussey@39 258 c.anchor = GridBagConstraints.EAST;
c@41 259 questionsPanel.add(new JLabel("I was familiar with approximately ------- of the songs."), c);
CBussey@39 260 c.anchor = GridBagConstraints.WEST;
c@46 261 c.gridy = 16;
c@46 262 c.gridx = 1;
CBussey@39 263 questionsPanel.add(goldMSI3_10, c);
CBussey@39 264 }
CBussey@39 265
m@0 266 // Put it all together
m@0 267 JPanel finishPanel = new JPanel();
jeremy@27 268 finishButton = new JButton("Finish");
m@0 269 finishPanel.add(finishButton);
m@0 270
m@0 271 JPanel topPanel = new JPanel();
m@0 272 topPanel.add(new JLabel("Please answer the following questions:"),
m@0 273 BorderLayout.NORTH);
m@0 274
m@12 275 //JPanel questionsPanel2 = new JPanel();
m@12 276 //questionsPanel2.setLayout(new BorderLayout());
m@12 277 //questionsPanel2.add(questionsPanel, BorderLayout.CENTER);
m@0 278
marcus@19 279 JScrollPane questionsPanel2 = new JScrollPane(questionsPanel);
marcus@19 280
m@0 281 //getRootPane().setDefaultButton(finishButton);
m@0 282 this.setLayout (new BorderLayout());
marcus@21 283 if (gui.getExperiment().getFinalQuestionnaire()) {
marcus@21 284 add(topPanel, BorderLayout.NORTH);
c@46 285 add(questionsPanel2, BorderLayout.CENTER);
marcus@21 286 }
m@0 287 add(finishPanel,BorderLayout.SOUTH);
m@0 288 }
m@0 289
m@0 290 public void storeData() {
m@0 291 ArrayList subjectData = new ArrayList();
jeremy@37 292 String[] id = {"ID", results.getSubjectID()};
m@0 293 subjectData.add(id);
m@0 294 String[] age = {"Age",ageField.getText()};
m@0 295 subjectData.add(age);
m@0 296 String[] sex = {"Gender",(String)sexBox.getSelectedItem()};
m@0 297 subjectData.add(sex);
m@0 298 String[] hand = {"Hand",(String)handBox.getSelectedItem()};
m@0 299 subjectData.add(hand);
m@12 300 String[] ethnicity = {"Ethnicity",(String)ethnicityBox.getSelectedItem()};
m@0 301 subjectData.add(ethnicity);
m@0 302 String[] nationality = {"Nationality",nationalityField.getText()};
m@0 303 subjectData.add(nationality);
m@0 304 String[] hear = {"HearingDiff", (String)hearingBox.getSelectedItem()};
m@0 305 subjectData.add(hear);
m@12 306 String[] listening = {"Listening", listeningField.getText()};
m@0 307 subjectData.add(listening);
m@12 308
m@12 309 String[] goldMSI3_1a = {"GoldMSI3.1", (String)goldMSI3_1.getSelectedItem()};
m@12 310 subjectData.add(goldMSI3_1a);
m@12 311 String[] goldMSI3_2a = {"GoldMSI3.2", (String)goldMSI3_2.getSelectedItem()};
m@12 312 subjectData.add(goldMSI3_2a);
m@12 313 String[] goldMSI3_3a = {"GoldMSI3.3", (String)goldMSI3_3.getSelectedItem()};
m@12 314 subjectData.add(goldMSI3_3a);
m@12 315 String[] goldMSI3_4a = {"GoldMSI3.4", (String)goldMSI3_4.getSelectedItem()};
m@12 316 subjectData.add(goldMSI3_4a);
m@12 317 String[] goldMSI3_5a = {"GoldMSI3.5", (String)goldMSI3_5.getSelectedItem()};
m@12 318 subjectData.add(goldMSI3_5a);
m@12 319 String[] goldMSI3_6a = {"GoldMSI3.6", (String)goldMSI3_6.getSelectedItem()};
m@12 320 subjectData.add(goldMSI3_6a);
m@12 321 String[] goldMSI3_7a = {"GoldMSI3.7", (String)goldMSI3_7.getSelectedItem()};
m@12 322 subjectData.add(goldMSI3_7a);
m@12 323 String[] goldMSI3_8a = {"GoldMSI3.8", (String)goldMSI3_8.getSelectedItem()};
m@12 324 subjectData.add(goldMSI3_8a);
m@12 325 String[] goldMSI3_9a = {"GoldMSI3.9", (String)goldMSI3_9.getSelectedItem()};
CBussey@39 326 if(askFamiliarity){
CBussey@39 327 subjectData.add(goldMSI3_9a);
CBussey@39 328 String[] goldMSI3_10a = {"GoldMSI3.10", (String)goldMSI3_10.getSelectedItem()};
CBussey@39 329 subjectData.add(goldMSI3_10a);
CBussey@39 330 }
m@12 331
CBussey@39 332 results.setSubjectData(subjectData);
m@0 333 }
m@0 334
m@0 335 public boolean allDataEntered () {
CBussey@39 336 if (ageField.getText().equals("") ||
m@0 337 sexBox.getSelectedItem().equals("") ||
m@0 338 handBox.getSelectedItem().equals("") ||
m@0 339 ethnicityBox.getSelectedItem().equals("") ||
m@0 340 nationalityField.getText().equals("") ||
m@0 341 hearingBox.getSelectedItem().equals("") ||
m@12 342 listeningField.getText().equals("") ||
m@12 343 goldMSI3_1.getSelectedItem().equals("") ||
m@12 344 goldMSI3_2.getSelectedItem().equals("") ||
m@12 345 goldMSI3_3.getSelectedItem().equals("") ||
m@12 346 goldMSI3_4.getSelectedItem().equals("") ||
m@12 347 goldMSI3_5.getSelectedItem().equals("") ||
m@12 348 goldMSI3_6.getSelectedItem().equals("") ||
m@12 349 goldMSI3_7.getSelectedItem().equals("") ||
m@12 350 goldMSI3_8.getSelectedItem().equals("") ||
CBussey@39 351 goldMSI3_9.getSelectedItem().equals("")
m@12 352 )
CBussey@39 353 return false;
CBussey@39 354 else if (askFamiliarity && goldMSI3_10.getSelectedItem().equals("")) return false;
CBussey@39 355 else return true;
m@0 356 }
m@0 357
m@0 358 public void addFinishButtonListener(ActionListener al) {
m@0 359 finishButton.addActionListener(al);
m@0 360 }
m@0 361 }