Mercurial > hg > mep
view StimulusPanel.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 | f23acab50cd3 |
children | d3977e825d91 |
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: <2012-03-27 16:39:33 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); */ JPanel responsePanel = new JPanel(); responsePanel.setLayout(new FlowLayout()); responsePanel.setBorder(BorderFactory.createRaisedBevelBorder()); responsePanel.add(new JLabel(exp.getLowAnchor())); for (int i = 0; i < responseButton.length; i++) { responseButton[i] = new JButton(Integer.toString(i+1)); responseButton[i].setFocusPainted(false); responsePanel.add(responseButton[i]); } responsePanel.add(new JLabel(exp.getHighAnchor())); // 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 much do you like this melody as a whole? (1 = not at all; 5 = very much)")); 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("Next"); 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); } //resets the background colour of the buttons public void resetButtonBackgrounds() { for(JButton button : responseButton) { button.setBackground(UIManager.getColor( "Button.background" )); } } 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); } } public void setResponseEnabled(boolean set) { for (int i = 0; i < responseButton.length; i++) { responseButton[i].setEnabled(set); } } public void highlightResponse(int buttonIndex) { responseButton[buttonIndex].setBackground(Color.blue); responseButton[buttonIndex].setOpaque(true); responseButton[buttonIndex].revalidate(); } }