view InstructionsPanel.java @ 39:796b3e3e053f

Changed MidiPlayer.java to allow the use of external sequencer programs (e.g. Garageband). Changed Experiment.java to allow user to specify in commandline whether to use default MidiDevice (true), specified MidiDevice (0<variable<MidiDevs.length), or list the available devices on start up. Changed ExperimentGui.java and SubjectDataPanel.java to add familiarity question if familiarity question isn't included at the presentation of each stimuli.
author CBussey
date Fri, 31 May 2013 17:40:59 +0100
parents 0e030f32a6e2
children
line wrap: on
line source
/*=============================================================================
 * File:       InstructionsPanel.java
 * Author:     Marcus Pearce <m.pearce@gold.ac.uk>
 * Created:    <2007-12-05 10:57:31 marcusp>
 * Time-stamp: <2007-12-14 16:29:55 marcusp>
 *=============================================================================
 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import java.io.*;
import java.util.regex.Pattern;

public class InstructionsPanel extends JPanel { 

    /* invalid subject id */ 
    public static final String INVALID_SUBJECT_ID = "----"; 

    /* variables */ 
    private ExperimentGui gui; 
    private JTextField subjectIDField; 
    private JButton nextButton = new JButton(); 
    
    /* accessors */ 
    public JButton getNextButton() { return nextButton; }
    
    /* constructor */ 
    public InstructionsPanel (ExperimentGui eg) { 

        gui = eg; 
        Experiment exp = gui.getExperiment(); 
        
        String file = exp.getInstructionsFile(); 
        JScrollPane instructionsPane = createInstructionsPane(file); 

        JLabel label = new JLabel("Participant ID: ");
        subjectIDField = new JTextField(10);

        nextButton = new JButton("Continue"); 

        JPanel subjectIDPane = new JPanel(); 
        subjectIDPane.add(label);
        subjectIDPane.add(subjectIDField); 
        subjectIDPane.add(nextButton); 

        this.setLayout (new BorderLayout());
        this.add(instructionsPane, BorderLayout.CENTER); 
        this.add(subjectIDPane, BorderLayout.SOUTH);
    }

    /* methods */ 

    public String getSubjectID() {
	String subjID = subjectIDField.getText();
	Pattern nonAlphaNum = Pattern.compile("[^a-zA-Z0-9]");
	
	if (nonAlphaNum.matcher(subjID).find()) {
            subjID = INVALID_SUBJECT_ID; 
        }

        return subjID; 
    }
    
    private JScrollPane createInstructionsPane(String instructionsFile) {
        
        JEditorPane editorPane = new JEditorPane();

        try { 
            FileReader reader = new FileReader(new File(instructionsFile)); 
            editorPane.setEditable(false);
            editorPane.setContentType("text/html");
            editorPane.read(reader, null);
        } catch (Exception e) { 
            System.out.println(e.getMessage());
        }
        
        JScrollPane editorScrollPane = new JScrollPane(editorPane);
        editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        editorScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

        editorScrollPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Instructions"), BorderFactory.createEmptyBorder(5,5,5,5)));
        editorScrollPane.setPreferredSize(new Dimension(300, 250));
        editorScrollPane.setMinimumSize(new Dimension(10, 10));
        return editorScrollPane;
    }

    public void addNextButtonListener(ActionListener al) { 
        nextButton.addActionListener(al); 
    }
}