comparison InstructionsPanel.java @ 0:4031cbb02f08

Initial import. Ignore-this: 87317e384f22bde48db996355191fa5f
author Marcus Pearce <m.pearce@gold.ac.uk>
date Tue, 18 May 2010 11:37:10 +0100
parents
children 0e030f32a6e2
comparison
equal deleted inserted replaced
-1:000000000000 0:4031cbb02f08
1 /*=============================================================================
2 * File: InstructionsPanel.java
3 * Author: Marcus Pearce <m.pearce@gold.ac.uk>
4 * Created: <2007-12-05 10:57:31 marcusp>
5 * Time-stamp: <2007-12-14 16:29:55 marcusp>
6 *=============================================================================
7 */
8
9 import java.awt.*;
10 import java.awt.event.*;
11 import javax.swing.*;
12 import javax.swing.text.*;
13 import java.io.*;
14
15 public class InstructionsPanel extends JPanel {
16
17 /* invalid subject id */
18 public static final int INVALID_SUBJECT_ID = -1000;
19
20 /* variables */
21 private ExperimentGui gui;
22 private JTextField subjectIDField;
23 private JButton nextButton = new JButton();
24
25 /* accessors */
26 public JButton getNextButton() { return nextButton; }
27
28 /* constructor */
29 public InstructionsPanel (ExperimentGui eg) {
30
31 gui = eg;
32 Experiment exp = gui.getExperiment();
33
34 String file = exp.getInstructionsFile();
35 JScrollPane instructionsPane = createInstructionsPane(file);
36
37 JLabel label = new JLabel("Participant ID: ");
38 subjectIDField = new JTextField(10);
39
40 nextButton = new JButton("Continue");
41
42 JPanel subjectIDPane = new JPanel();
43 subjectIDPane.add(label);
44 subjectIDPane.add(subjectIDField);
45 subjectIDPane.add(nextButton);
46
47 this.setLayout (new BorderLayout());
48 this.add(instructionsPane, BorderLayout.CENTER);
49 this.add(subjectIDPane, BorderLayout.SOUTH);
50 }
51
52 /* methods */
53
54 public int getSubjectID() {
55 int subjID;
56 try {
57 subjID = Integer.parseInt(subjectIDField.getText());
58 } catch (NumberFormatException e) {
59 subjID = INVALID_SUBJECT_ID;
60 }
61 return subjID;
62 }
63
64 private JScrollPane createInstructionsPane(String instructionsFile) {
65
66 JEditorPane editorPane = new JEditorPane();
67
68 try {
69 FileReader reader = new FileReader(new File(instructionsFile));
70 editorPane.setEditable(false);
71 editorPane.setContentType("text/html");
72 editorPane.read(reader, null);
73 } catch (Exception e) {
74 System.out.println(e.getMessage());
75 }
76
77 JScrollPane editorScrollPane = new JScrollPane(editorPane);
78 editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
79 editorScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
80
81 editorScrollPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Instructions"), BorderFactory.createEmptyBorder(5,5,5,5)));
82 editorScrollPane.setPreferredSize(new Dimension(300, 250));
83 editorScrollPane.setMinimumSize(new Dimension(10, 10));
84 return editorScrollPane;
85 }
86
87 public void addNextButtonListener(ActionListener al) {
88 nextButton.addActionListener(al);
89 }
90 }