Mercurial > hg > mep
comparison StimulusPanel.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 | 6108a8aa9d82 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4031cbb02f08 |
---|---|
1 /*============================================================================= | |
2 * File: StimulusPanel.java | |
3 * Author: Marcus Pearce <m.pearce@gold.ac.uk> | |
4 * Created: <2007-12-05 11:24:00 marcusp> | |
5 * Time-stamp: <2010-05-18 11:12:14 marcusp> | |
6 *============================================================================= | |
7 */ | |
8 | |
9 import java.awt.*; | |
10 import java.awt.event.*; | |
11 import javax.swing.*; | |
12 | |
13 public class StimulusPanel extends JPanel { | |
14 | |
15 /* the Experiment */ | |
16 private Experiment exp; | |
17 private ExperimentGui gui; | |
18 | |
19 /* navigation buttons */ | |
20 private JButton playButton, nextButton; | |
21 | |
22 /* The response buttons */ | |
23 private JButton[] responseButton; | |
24 | |
25 /* The song number label */ | |
26 private JLabel songNumberLabel; | |
27 | |
28 /* The questions about each melody */ | |
29 private JComboBox q1Box; | |
30 private JComboBox q2Box; | |
31 | |
32 /* accessors */ | |
33 public JButton getPlayButton() { return playButton; } | |
34 public JButton getNextButton() { return nextButton; } | |
35 public JButton[] getResponseButtons() { return responseButton; } | |
36 public JComboBox getQ1Box() { return q1Box; } | |
37 public JComboBox getQ2Box() { return q2Box; } | |
38 | |
39 /* constructor */ | |
40 public StimulusPanel(ExperimentGui egui, Clock clock) { | |
41 | |
42 gui = egui; | |
43 exp = gui.getExperiment(); | |
44 responseButton = new JButton[exp.getScaleLength()]; | |
45 | |
46 // The display panel (Clock) | |
47 JPanel displayPanel = new JPanel(); | |
48 displayPanel.setBackground(Color.black); | |
49 displayPanel.setBorder(BorderFactory.createRaisedBevelBorder()); | |
50 displayPanel.setLayout(new GridBagLayout()); | |
51 GridBagConstraints c = new GridBagConstraints(); | |
52 c.fill = GridBagConstraints.HORIZONTAL; | |
53 c.gridx = 2; | |
54 c.gridy = 2; | |
55 displayPanel.add(clock, c); | |
56 | |
57 // Add the response buttons | |
58 JPanel responsePanel = new JPanel(); | |
59 responsePanel.setLayout (new BorderLayout()); | |
60 responsePanel.setBorder(BorderFactory.createRaisedBevelBorder()); | |
61 | |
62 JPanel anchorsPanel = new JPanel(); | |
63 anchorsPanel.add(new JLabel(exp.getLowAnchor()), BorderLayout.WEST); | |
64 anchorsPanel.add(new JLabel(" "), | |
65 BorderLayout.CENTER); | |
66 anchorsPanel.add(new JLabel(exp.getHighAnchor()), BorderLayout.EAST); | |
67 | |
68 JPanel ratingsPanel = new JPanel(); | |
69 for (int i = 0; i < responseButton.length; i++) { | |
70 responseButton[i] = new JButton(Integer.toString(i+1)); | |
71 responseButton[i].setFocusPainted(false); | |
72 ratingsPanel.add(responseButton[i]); | |
73 } | |
74 responsePanel.add(ratingsPanel, BorderLayout.NORTH); | |
75 responsePanel.add(anchorsPanel, BorderLayout.SOUTH); | |
76 | |
77 // Questions Panel | |
78 JPanel questionsPanel = new JPanel(); | |
79 GridLayout gl = new GridLayout(2,2); | |
80 gl.setHgap(50); | |
81 questionsPanel.setLayout(gl); | |
82 | |
83 String[] q1BoxOptions = { "", "Yes", "No" }; | |
84 q1Box = new JComboBox(q1BoxOptions); | |
85 q1Box.setSelectedIndex(0); | |
86 questionsPanel.add(new JLabel("Are you familiar with this melody?")); | |
87 questionsPanel.add(q1Box); | |
88 | |
89 String[] q2BoxOptions = { "", "1", "2", "3", "4", "5"}; | |
90 q2Box = new JComboBox(q2BoxOptions); | |
91 q2Box.setSelectedIndex(0); | |
92 questionsPanel.add(new JLabel("How pleasant do you find this melody (1 = very unpleasant, 5 = very pleasant)?")); | |
93 questionsPanel.add(q2Box); | |
94 | |
95 JPanel questionsPanel2 = new JPanel(); | |
96 questionsPanel2.setBorder(BorderFactory.createRaisedBevelBorder()); | |
97 questionsPanel2.add(questionsPanel, BorderLayout.CENTER); | |
98 | |
99 // Navigation Panel | |
100 JPanel navPanel = new JPanel(); | |
101 playButton = new JButton(new ImageIcon("Icons/Play24.gif")); | |
102 playButton.setText("Play"); | |
103 | |
104 nextButton = new JButton(new ImageIcon("Icons/StepForward24.gif")); | |
105 nextButton.setText("Play next melody"); | |
106 | |
107 songNumberLabel = new JLabel(""); | |
108 setSongNumberText(); | |
109 navPanel.add(songNumberLabel); | |
110 //navPanel.add(playButton); | |
111 navPanel.add(nextButton); | |
112 navPanel.setBorder(BorderFactory.createRaisedBevelBorder()); | |
113 | |
114 // Add it all | |
115 JPanel southPanel = new JPanel(); | |
116 southPanel.setLayout (new BorderLayout()); | |
117 southPanel.add(responsePanel, BorderLayout.NORTH); | |
118 southPanel.add(questionsPanel2, BorderLayout.CENTER); | |
119 | |
120 this.setLayout (new BorderLayout()); | |
121 this.add(navPanel, BorderLayout.NORTH); | |
122 this.add(displayPanel, BorderLayout.CENTER); | |
123 this.add(southPanel, BorderLayout.SOUTH); | |
124 } | |
125 | |
126 public void setSongNumberText() { | |
127 String m = | |
128 "Block " + | |
129 exp.getCurrentBlockID() + | |
130 ", Melody " + | |
131 Integer.toString(exp.getCurrentBlock().getMelodyNumber()) + | |
132 ": "; | |
133 songNumberLabel.setText(m); | |
134 } | |
135 | |
136 public void defaultAnswers() { | |
137 q1Box.setSelectedIndex(0); | |
138 q2Box.setSelectedIndex(0); | |
139 } | |
140 | |
141 public boolean unansweredQuestions() { | |
142 if (q1Box.getSelectedItem().equals("") || | |
143 q2Box.getSelectedItem().equals("") | |
144 ) | |
145 return true; | |
146 else | |
147 return false; | |
148 } | |
149 | |
150 public void addAllListeners(ActionListener al) { | |
151 playButton.addActionListener(al); | |
152 nextButton.addActionListener(al); | |
153 | |
154 for (int i = 0; i < responseButton.length; i++) { | |
155 responseButton[i].addActionListener(al); | |
156 } | |
157 } | |
158 | |
159 public void addAllKeyListeners(KeyListener al) { | |
160 playButton.addKeyListener(al); | |
161 nextButton.addKeyListener(al); | |
162 | |
163 for (int i = 0; i < responseButton.length; i++) { | |
164 responseButton[i].addKeyListener(al); | |
165 } | |
166 } | |
167 } |