view SubjectDataPanel.java @ 18:bc3744eb0180

Add class files.
author Marcus Pearce <marcus.pearce@eecs.qmul.ac.uk>
date Tue, 17 Jan 2012 13:03:19 +0000
parents 284c23df4652
children 0c5205934936
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: <2011-11-10 19:13:15 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;

    private JButton finishButton; 

    private SubjectResults results; 

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

    /* constructor */ 
    public SubjectDataPanel(ExperimentGui gui, SubjectResults sr) { 
	
	results = sr; 

	JPanel questionsPanel = new JPanel(); 
	questionsPanel.setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        //c.fill = GridBagConstraints.BOTH;
        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" };

        // Age 
        c.gridy = 0;
        c.gridx = 0;
	ageField = new JTextField(10);
        c.anchor = GridBagConstraints.EAST;
	questionsPanel.add(new JLabel("Age: ")); 
        c.gridx = 1;
        c.anchor = GridBagConstraints.WEST;
	questionsPanel.add(ageField, c); 

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

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

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

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

        // Musical Listening 
        c.gridy = 6;
        listeningField = new JTextField(10); 
        c.anchor = GridBagConstraints.EAST;
	questionsPanel.add(new JLabel("How many hours per day do you spend listening to music?"), c); 
        c.anchor = GridBagConstraints.WEST;
        questionsPanel.add(listeningField, c); 

        // GOLDMSI
        c.gridy = 7;
        goldMSI3_1 = new JComboBox(agreeOptions);
        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;
        questionsPanel.add(goldMSI3_1, c);

        c.gridy = 8;
        goldMSI3_2 = new JComboBox(agreeOptions);
        c.anchor = GridBagConstraints.EAST;
        questionsPanel.add(new JLabel("I can't read a musical score."), c);
        c.anchor = GridBagConstraints.WEST;
        questionsPanel.add(goldMSI3_2, c);
        
        c.gridy = 9;        
        goldMSI3_3 = new JComboBox(agreeOptions);
        c.anchor = GridBagConstraints.EAST;
        questionsPanel.add(new JLabel("I would not consider myself a musician."), c);
        c.anchor = GridBagConstraints.WEST;
        questionsPanel.add(goldMSI3_3, c);
        
        c.gridy = 10;
        String[] goldMSI3_4o = {"", "0", "1", "2", "3", "4-5", "6-9", "10 or more"};
        goldMSI3_4 = new JComboBox(goldMSI3_4o);
        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;
        questionsPanel.add(goldMSI3_4, c);

        c.gridy = 11;
        String[] goldMSI3_5o = {"", "0", "0.5", "1", "1.5", "2", "3-4", "5 or more"};
        goldMSI3_5 = new JComboBox(goldMSI3_4o);
        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;
        questionsPanel.add(goldMSI3_5, c);

        c.gridy = 12;
        goldMSI3_6 = new JComboBox(goldMSI3_4o);
        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;
        questionsPanel.add(goldMSI3_6, c);
        
        c.gridy = 13;
        String[] goldMSI3_7o = {"", "0", "0.5", "1", "2", "3", "4-6", "7 or more"};        
        goldMSI3_7 = new JComboBox(goldMSI3_7o);
        c.anchor = GridBagConstraints.EAST;
        questionsPanel.add(new JLabel("I have had formal training in music theory for ------- years."), c);
        c.anchor = GridBagConstraints.WEST;
        questionsPanel.add(goldMSI3_7, c);

        c.gridy = 14;
        goldMSI3_8 = new JComboBox(goldMSI3_4o);
        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;
        questionsPanel.add(goldMSI3_8, c);

        c.gridy = 15;
        String[] goldMSI3_9o = {"", "0", "1", "2", "3", "4", "5", "6 or more"};        
        goldMSI3_9 = new JComboBox(goldMSI3_9o);
        c.anchor = GridBagConstraints.EAST;
        questionsPanel.add(new JLabel("I can play ------- musical instruments."), c);
        c.anchor = GridBagConstraints.WEST;
        questionsPanel.add(goldMSI3_9, 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); 

	//getRootPane().setDefaultButton(finishButton);
        this.setLayout (new BorderLayout());
        add(topPanel, BorderLayout.NORTH); 
	add(questionsPanel, BorderLayout.CENTER); 
	add(finishPanel,BorderLayout.SOUTH); 
    } 

    public void storeData() { 
	ArrayList subjectData = new ArrayList();
	String[] id = {"ID", Integer.toString(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()};
        subjectData.add(goldMSI3_9a);

        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 return true; 
    }

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