Mercurial > hg > mep
view StimulusPanel.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 | 235484b93707 |
children | 9e45ae01f81e |
line wrap: on
line source
/*============================================================================= * File: StimulusPanel.java * Author: Marcus Pearce <m.pearce@gold.ac.uk> * Created: <2007-12-05 11:24:00 marcusp> * Time-stamp: <2011-07-19 15:39:36 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); if (exp.getAskFamiliarity()) { String[] q1BoxOptions = { "", "Yes", "No" }; q1Box = new JComboBox(q1BoxOptions); q1Box.setSelectedIndex(0); questionsPanel.add(new JLabel("Are you familiar with this melody?")); questionsPanel.add(q1Box); } if (exp.getAskLiking()) { 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() { if (exp.getAskFamiliarity()) q1Box.setSelectedIndex(0); if (exp.getAskLiking()) q2Box.setSelectedIndex(0); } public boolean unansweredQuestions() { if ((exp.getAskFamiliarity() && q1Box.getSelectedItem().equals("")) || (exp.getAskLiking() && 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); } } }