view SubjectDataPanel.java @ 47:be66ee2fe9fe

Added abstract class EndBlockPanel to deliver end of block messages (e.g. end of practice block). Added and implemented EndTestPanel which gives "thank you for participating" etc message at end of test.
author Carl Bussey <c.bussey@se10.qmul.ac.uk>
date Thu, 13 Jun 2013 18:33:34 +0100
parents 5f9dde32392f
children
line wrap: on
line source
/*=============================================================================
 * File:       SubjectDataPanel.java
 * Author:     Marcus Pearce <m.pearce@gold.ac.uk>
 * Created:    <2007-02-14 11:28:27 marcusp>
 * Time-stamp: <2012-03-27 16:48:33 marcusp>
 *=============================================================================
 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.ArrayList; 

public class SubjectDataPanel extends JPanel { 

    /* variables */ 
    private JTextField ageField, listeningField, nationalityField; 
    private JComboBox sexBox, handBox, hearingBox, ethnicityBox, 
        goldMSI3_1, goldMSI3_2, goldMSI3_3, goldMSI3_4, goldMSI3_5, goldMSI3_6, goldMSI3_7, goldMSI3_8, goldMSI3_9, goldMSI3_10;

    private JButton finishButton; 

    private SubjectResults results;
    
    private boolean askFamiliarity = false;

    /* accessors */ 
    public JButton getFinishButton() { return finishButton; }

    /* constructors */
    public SubjectDataPanel(ExperimentGui gui, SubjectResults sr) {
        this(gui, sr, false);
    }
    
    public SubjectDataPanel(ExperimentGui gui, SubjectResults sr, boolean askFamiliarity) {
    
    this.askFamiliarity = askFamiliarity;
	results = sr; 

	JPanel questionsPanel = new JPanel(); 
	questionsPanel.setLayout(new GridBagLayout());
        questionsPanel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
        GridBagConstraints c = new GridBagConstraints();
        //c.fill = GridBagConstraints.HORIZONTAL;
        c.ipadx = 10;
        c.ipady = 30;
        //c.insets = new Insets(50,50,50,50);

	questionsPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(""),BorderFactory.createEmptyBorder(5,5,5,5)), questionsPanel.getBorder()));
	
	String[] yesNoOptions = { "", "Yes", "No" };
        String[] agreeOptions = { "", "1 Completely Disagree", "2 Strongly Disagree", "3 Disagree", "4 Neither agree nor disagree", "5 Agree", "6 Strongly Agree", "7 Completely agree" };
        
        int componentHeight=10;
        int componentWidth=230;
        
        // Age 
        c.gridy = 0;
        c.gridx = 0;
	ageField = new JTextField(18);
        c.anchor = GridBagConstraints.EAST;
        ageField.setPreferredSize(new Dimension(componentWidth,componentHeight));
	questionsPanel.add(new JLabel("Age: "), c);
        c.gridy = 0;
        c.gridx = 1;
        c.anchor = GridBagConstraints.WEST;
	questionsPanel.add(ageField, c);

        // Gender 
        c.gridy = 1;
        c.gridx = 0;
	String[] sexBoxOptions = { "", "Male", "Female" }; 
	sexBox = new JComboBox(sexBoxOptions); 
	sexBox.setSelectedIndex(0);
        sexBox.setPreferredSize(new Dimension(componentWidth,componentHeight));
        c.anchor = GridBagConstraints.EAST;
	questionsPanel.add(new JLabel("Sex: "), c);
        c.gridy = 1;
        c.gridx = 1;
        c.anchor = GridBagConstraints.WEST;
	questionsPanel.add(sexBox, c); 

        // Ethnicity
        c.gridy = 2;
        c.gridx = 0;
	String[] ethnicityBoxOptions = 
            { "", "Asian", "Black", "Chinese", "Mixed", "Other", "White", 
              "Undisclosed" }; 
	ethnicityBox = new JComboBox(ethnicityBoxOptions);
        ethnicityBox.setPreferredSize(new Dimension(componentWidth,componentHeight));
        c.anchor = GridBagConstraints.EAST;
	questionsPanel.add(new JLabel("Ethnicity: "), c); 
        c.anchor = GridBagConstraints.WEST;
        c.gridy = 2;
        c.gridx = 1;
	questionsPanel.add(ethnicityBox, c); 
        
        // Nationality
	nationalityField = new JTextField(18);
        nationalityField.setPreferredSize(new Dimension(componentWidth,componentHeight));
        c.anchor = GridBagConstraints.EAST;
        c.gridy = 3;
        c.gridx = 0;
	questionsPanel.add(new JLabel("Nationality: "), c); 
        c.anchor = GridBagConstraints.WEST;
        c.gridy = 3;
        c.gridx = 1;
	questionsPanel.add(nationalityField, c); 

        // Handedness 
        c.gridy = 4;
        c.gridx = 0;
	String[] handBoxOptions = { "", "Right-handed", "Left-handed" };
	handBox = new JComboBox(handBoxOptions);
        handBox.setPreferredSize(new Dimension(componentWidth,componentHeight));
	handBox.setSelectedIndex(0); 
        c.anchor = GridBagConstraints.EAST;
	questionsPanel.add(new JLabel("Handedness: "), c); 
        c.anchor = GridBagConstraints.WEST;
        c.gridy = 4;
        c.gridx = 1;
	questionsPanel.add(handBox, c); 

        // Hearing 
        c.gridy = 5;
        c.gridx = 0;
        hearingBox = new JComboBox(yesNoOptions);
        hearingBox.setPreferredSize(new Dimension(componentWidth,componentHeight));
        c.anchor = GridBagConstraints.EAST;
        questionsPanel.add(new JLabel("Do you have any hearing difficulties?"), c);
        c.anchor = GridBagConstraints.WEST;
        c.gridy = 5;
        c.gridx = 1;
	questionsPanel.add(hearingBox, c); 

        // Musical Listening 
        c.gridy = 6;
        c.gridx = 0;
        listeningField = new JTextField(18);
        listeningField.setPreferredSize(new Dimension(componentWidth,componentHeight));
        c.anchor = GridBagConstraints.EAST;
	questionsPanel.add(new JLabel("How many hours per day do you spend listening to music?"), c); 
        c.anchor = GridBagConstraints.WEST;
        c.gridy = 6;
        c.gridx = 1;
        questionsPanel.add(listeningField, c); 

        // GOLDMSI
        c.gridy = 7;
        c.gridx = 0;
        goldMSI3_1 = new JComboBox(agreeOptions);
        goldMSI3_1.setPreferredSize(new Dimension(componentWidth,componentHeight));
        c.anchor = GridBagConstraints.EAST;
        questionsPanel.add(new JLabel("I have never been complimented on my talents as a musical performer."), c);
        c.anchor = GridBagConstraints.WEST;
        c.gridy = 7;
        c.gridx = 1;
        questionsPanel.add(goldMSI3_1, c);

        c.gridy = 8;
        c.gridx = 0;
        goldMSI3_2 = new JComboBox(agreeOptions);
        goldMSI3_2.setPreferredSize(new Dimension(componentWidth,componentHeight));
        c.anchor = GridBagConstraints.EAST;
        questionsPanel.add(new JLabel("I can't read a musical score."), c);
        c.anchor = GridBagConstraints.WEST;
        c.gridy = 8;
        c.gridx = 1;
        questionsPanel.add(goldMSI3_2, c);
        
        c.gridy = 9;
        c.gridx = 0;
        goldMSI3_3 = new JComboBox(agreeOptions);
        goldMSI3_3.setPreferredSize(new Dimension(componentWidth,componentHeight));
        c.anchor = GridBagConstraints.EAST;
        questionsPanel.add(new JLabel("I would not consider myself a musician."), c);
        c.gridy = 9;
        c.gridx = 1;
        c.anchor = GridBagConstraints.WEST;
        questionsPanel.add(goldMSI3_3, c);
        
        c.gridy = 10;
        c.gridx = 0;
        String[] goldMSI3_4o = {"", "0", "1", "2", "3", "4-5", "6-9", "10 or more"};
        goldMSI3_4 = new JComboBox(goldMSI3_4o);
        goldMSI3_4.setPreferredSize(new Dimension(componentWidth,componentHeight));
        c.anchor = GridBagConstraints.EAST;
        questionsPanel.add(new JLabel("I engaged in regular, daily practice of a musical instrument (including voice) for ------- years."), c);
        c.anchor = GridBagConstraints.WEST;
        c.gridy = 10;
        c.gridx = 1;
        questionsPanel.add(goldMSI3_4, c);

        c.gridy = 11;
        c.gridx = 0;
        String[] goldMSI3_5o = {"", "0", "0.5", "1", "1.5", "2", "3-4", "5 or more"};
        goldMSI3_5 = new JComboBox(goldMSI3_4o);
        goldMSI3_5.setPreferredSize(new Dimension(componentWidth,componentHeight));
        c.anchor = GridBagConstraints.EAST;
        questionsPanel.add(new JLabel("At the peak of my interest, I practised ------- hours per day on my primary instrument."), c);
        c.anchor = GridBagConstraints.WEST;
        c.gridy = 11;
        c.gridx = 1;
        questionsPanel.add(goldMSI3_5, c);

        c.gridy = 12;
        c.gridx = 0;
        goldMSI3_6 = new JComboBox(goldMSI3_4o);
        goldMSI3_6.setPreferredSize(new Dimension(componentWidth,componentHeight));
        c.anchor = GridBagConstraints.EAST;
        questionsPanel.add(new JLabel("I have played or sung in a group, band, choir or orchestra for ------- years."), c);
        c.anchor = GridBagConstraints.WEST;
        c.gridy = 12;
        c.gridx = 1;
        questionsPanel.add(goldMSI3_6, c);
        
        c.gridy = 13;
        c.gridx = 0;
        String[] goldMSI3_7o = {"", "0", "0.5", "1", "2", "3", "4-6", "7 or more"};
        goldMSI3_7 = new JComboBox(goldMSI3_7o);
        goldMSI3_7.setPreferredSize(new Dimension(componentWidth,componentHeight));
        c.anchor = GridBagConstraints.EAST;
        questionsPanel.add(new JLabel("I have had formal training in music theory for ------- years."), c);
        c.anchor = GridBagConstraints.WEST;
        c.gridy = 13;
        c.gridx = 1;
        questionsPanel.add(goldMSI3_7, c);

        c.gridy = 14;
        c.gridx = 0;
        goldMSI3_8 = new JComboBox(goldMSI3_4o);
        goldMSI3_8.setPreferredSize(new Dimension(componentWidth,componentHeight));
        c.anchor = GridBagConstraints.EAST;
        questionsPanel.add(new JLabel("I have had ------- years of formal training on a musical instrument (including voice) during my lifetime."), c);
        c.anchor = GridBagConstraints.WEST;
        c.gridy = 14;
        c.gridx = 1;
        questionsPanel.add(goldMSI3_8, c);

        c.gridy = 15;
        c.gridx = 0;
        String[] goldMSI3_9o = {"", "0", "1", "2", "3", "4", "5", "6 or more"};        
        goldMSI3_9 = new JComboBox(goldMSI3_9o);
        goldMSI3_9.setPreferredSize(new Dimension(componentWidth,componentHeight));
        c.anchor = GridBagConstraints.EAST;
        questionsPanel.add(new JLabel("I can play ------- musical instruments."), c);
        c.anchor = GridBagConstraints.WEST;
        c.gridy = 15;
        c.gridx = 1;
        questionsPanel.add(goldMSI3_9, c);
        
        if(askFamiliarity){
            c.gridy = 16;
            c.gridx = 0;
            String[] goldMSI3_10o = {"", "0%", "25%", "50%", "75%", "100%"};
            goldMSI3_10 = new JComboBox(goldMSI3_10o);
            goldMSI3_10.setPreferredSize(new Dimension(componentWidth,componentHeight));
            c.anchor = GridBagConstraints.EAST;
            questionsPanel.add(new JLabel("I was familiar with approximately ------- of the songs."), c);
            c.anchor = GridBagConstraints.WEST;
            c.gridy = 16;
            c.gridx = 1;
            questionsPanel.add(goldMSI3_10, c);
        }
        
        // Put it all together 
        JPanel finishPanel = new JPanel(); 
	finishButton = new JButton("Finish"); 
        finishPanel.add(finishButton); 

        JPanel topPanel = new JPanel(); 
        topPanel.add(new JLabel("Please answer the following questions:"), 
                     BorderLayout.NORTH); 
        
        //JPanel questionsPanel2 = new JPanel(); 
        //questionsPanel2.setLayout(new BorderLayout()); 
        //questionsPanel2.add(questionsPanel, BorderLayout.CENTER); 

        JScrollPane questionsPanel2 = new JScrollPane(questionsPanel);

	//getRootPane().setDefaultButton(finishButton);
        this.setLayout (new BorderLayout());
	if (gui.getExperiment().getFinalQuestionnaire()) {
            add(topPanel, BorderLayout.NORTH); 
            add(questionsPanel2, BorderLayout.CENTER);
        }
	add(finishPanel,BorderLayout.SOUTH); 
    } 

    public void storeData() { 
	ArrayList subjectData = new ArrayList();
	String[] id = {"ID", results.getSubjectID()}; 
	subjectData.add(id);        
	String[] age = {"Age",ageField.getText()}; 
	subjectData.add(age);
	String[] sex = {"Gender",(String)sexBox.getSelectedItem()}; 
	subjectData.add(sex);
	String[] hand = {"Hand",(String)handBox.getSelectedItem()}; 
	subjectData.add(hand);
	String[] ethnicity = {"Ethnicity",(String)ethnicityBox.getSelectedItem()}; 
	subjectData.add(ethnicity);
	String[] nationality = {"Nationality",nationalityField.getText()}; 
	subjectData.add(nationality); 
	String[] hear = {"HearingDiff", (String)hearingBox.getSelectedItem()}; 
	subjectData.add(hear); 
	String[] listening = {"Listening", listeningField.getText()}; 
	subjectData.add(listening); 
        
        String[] goldMSI3_1a = {"GoldMSI3.1", (String)goldMSI3_1.getSelectedItem()};
        subjectData.add(goldMSI3_1a);
        String[] goldMSI3_2a = {"GoldMSI3.2", (String)goldMSI3_2.getSelectedItem()};
        subjectData.add(goldMSI3_2a);
        String[] goldMSI3_3a = {"GoldMSI3.3", (String)goldMSI3_3.getSelectedItem()};
        subjectData.add(goldMSI3_3a);
        String[] goldMSI3_4a = {"GoldMSI3.4", (String)goldMSI3_4.getSelectedItem()};
        subjectData.add(goldMSI3_4a);
        String[] goldMSI3_5a = {"GoldMSI3.5", (String)goldMSI3_5.getSelectedItem()};
        subjectData.add(goldMSI3_5a);
        String[] goldMSI3_6a = {"GoldMSI3.6", (String)goldMSI3_6.getSelectedItem()};
        subjectData.add(goldMSI3_6a);
        String[] goldMSI3_7a = {"GoldMSI3.7", (String)goldMSI3_7.getSelectedItem()};
        subjectData.add(goldMSI3_7a);
        String[] goldMSI3_8a = {"GoldMSI3.8", (String)goldMSI3_8.getSelectedItem()};
        subjectData.add(goldMSI3_8a);
        String[] goldMSI3_9a = {"GoldMSI3.9", (String)goldMSI3_9.getSelectedItem()};
        if(askFamiliarity){
            subjectData.add(goldMSI3_9a);
            String[] goldMSI3_10a = {"GoldMSI3.10", (String)goldMSI3_10.getSelectedItem()};
            subjectData.add(goldMSI3_10a);
        }

        results.setSubjectData(subjectData);
    } 

    public boolean allDataEntered () { 
        if (ageField.getText().equals("") ||
            sexBox.getSelectedItem().equals("") ||
            handBox.getSelectedItem().equals("") ||
            ethnicityBox.getSelectedItem().equals("") || 
            nationalityField.getText().equals("") || 
            hearingBox.getSelectedItem().equals("") ||
            listeningField.getText().equals("") ||
            goldMSI3_1.getSelectedItem().equals("") ||
            goldMSI3_2.getSelectedItem().equals("") ||
            goldMSI3_3.getSelectedItem().equals("") ||
            goldMSI3_4.getSelectedItem().equals("") ||
            goldMSI3_5.getSelectedItem().equals("") ||
            goldMSI3_6.getSelectedItem().equals("") ||
            goldMSI3_7.getSelectedItem().equals("") ||
            goldMSI3_8.getSelectedItem().equals("") ||
            goldMSI3_9.getSelectedItem().equals("") 
            )
            return false;
        else if (askFamiliarity && goldMSI3_10.getSelectedItem().equals("")) return false;
        else return true;
    }

    public void addFinishButtonListener(ActionListener al) { 
        finishButton.addActionListener(al); 
    }
}