Mercurial > hg > mep
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/StimulusPanel.java Tue May 18 11:37:10 2010 +0100 @@ -0,0 +1,167 @@ +/*============================================================================= + * File: StimulusPanel.java + * Author: Marcus Pearce <m.pearce@gold.ac.uk> + * Created: <2007-12-05 11:24:00 marcusp> + * Time-stamp: <2010-05-18 11:12:14 marcusp> + *============================================================================= + */ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +public class StimulusPanel extends JPanel { + + /* the Experiment */ + private Experiment exp; + private ExperimentGui gui; + + /* navigation buttons */ + private JButton playButton, nextButton; + + /* The response buttons */ + private JButton[] responseButton; + + /* The song number label */ + private JLabel songNumberLabel; + + /* The questions about each melody */ + private JComboBox q1Box; + private JComboBox q2Box; + + /* accessors */ + public JButton getPlayButton() { return playButton; } + public JButton getNextButton() { return nextButton; } + public JButton[] getResponseButtons() { return responseButton; } + public JComboBox getQ1Box() { return q1Box; } + public JComboBox getQ2Box() { return q2Box; } + + /* constructor */ + public StimulusPanel(ExperimentGui egui, Clock clock) { + + gui = egui; + exp = gui.getExperiment(); + responseButton = new JButton[exp.getScaleLength()]; + + // The display panel (Clock) + JPanel displayPanel = new JPanel(); + displayPanel.setBackground(Color.black); + displayPanel.setBorder(BorderFactory.createRaisedBevelBorder()); + displayPanel.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.fill = GridBagConstraints.HORIZONTAL; + c.gridx = 2; + c.gridy = 2; + displayPanel.add(clock, c); + + // Add the response buttons + JPanel responsePanel = new JPanel(); + responsePanel.setLayout (new BorderLayout()); + responsePanel.setBorder(BorderFactory.createRaisedBevelBorder()); + + JPanel anchorsPanel = new JPanel(); + anchorsPanel.add(new JLabel(exp.getLowAnchor()), BorderLayout.WEST); + anchorsPanel.add(new JLabel(" "), + BorderLayout.CENTER); + anchorsPanel.add(new JLabel(exp.getHighAnchor()), BorderLayout.EAST); + + JPanel ratingsPanel = new JPanel(); + for (int i = 0; i < responseButton.length; i++) { + responseButton[i] = new JButton(Integer.toString(i+1)); + responseButton[i].setFocusPainted(false); + ratingsPanel.add(responseButton[i]); + } + responsePanel.add(ratingsPanel, BorderLayout.NORTH); + responsePanel.add(anchorsPanel, BorderLayout.SOUTH); + + // Questions Panel + JPanel questionsPanel = new JPanel(); + GridLayout gl = new GridLayout(2,2); + gl.setHgap(50); + questionsPanel.setLayout(gl); + + String[] q1BoxOptions = { "", "Yes", "No" }; + q1Box = new JComboBox(q1BoxOptions); + q1Box.setSelectedIndex(0); + questionsPanel.add(new JLabel("Are you familiar with this melody?")); + questionsPanel.add(q1Box); + + String[] q2BoxOptions = { "", "1", "2", "3", "4", "5"}; + q2Box = new JComboBox(q2BoxOptions); + q2Box.setSelectedIndex(0); + questionsPanel.add(new JLabel("How pleasant do you find this melody (1 = very unpleasant, 5 = very pleasant)?")); + questionsPanel.add(q2Box); + + JPanel questionsPanel2 = new JPanel(); + questionsPanel2.setBorder(BorderFactory.createRaisedBevelBorder()); + questionsPanel2.add(questionsPanel, BorderLayout.CENTER); + + // Navigation Panel + JPanel navPanel = new JPanel(); + playButton = new JButton(new ImageIcon("Icons/Play24.gif")); + playButton.setText("Play"); + + nextButton = new JButton(new ImageIcon("Icons/StepForward24.gif")); + nextButton.setText("Play next melody"); + + songNumberLabel = new JLabel(""); + setSongNumberText(); + navPanel.add(songNumberLabel); + //navPanel.add(playButton); + navPanel.add(nextButton); + navPanel.setBorder(BorderFactory.createRaisedBevelBorder()); + + // Add it all + JPanel southPanel = new JPanel(); + southPanel.setLayout (new BorderLayout()); + southPanel.add(responsePanel, BorderLayout.NORTH); + southPanel.add(questionsPanel2, BorderLayout.CENTER); + + this.setLayout (new BorderLayout()); + this.add(navPanel, BorderLayout.NORTH); + this.add(displayPanel, BorderLayout.CENTER); + this.add(southPanel, BorderLayout.SOUTH); + } + + public void setSongNumberText() { + String m = + "Block " + + exp.getCurrentBlockID() + + ", Melody " + + Integer.toString(exp.getCurrentBlock().getMelodyNumber()) + + ": "; + songNumberLabel.setText(m); + } + + public void defaultAnswers() { + q1Box.setSelectedIndex(0); + q2Box.setSelectedIndex(0); + } + + public boolean unansweredQuestions() { + if (q1Box.getSelectedItem().equals("") || + q2Box.getSelectedItem().equals("") + ) + return true; + else + return false; + } + + public void addAllListeners(ActionListener al) { + playButton.addActionListener(al); + nextButton.addActionListener(al); + + for (int i = 0; i < responseButton.length; i++) { + responseButton[i].addActionListener(al); + } + } + + public void addAllKeyListeners(KeyListener al) { + playButton.addKeyListener(al); + nextButton.addKeyListener(al); + + for (int i = 0; i < responseButton.length; i++) { + responseButton[i].addKeyListener(al); + } + } +}