view InterBlockPanel.java @ 45:351b0c8b34ac

Fixed issue where error message was shown every time the user chose to move continue using the keyboard. Fixed issue where data wasn't saving to file after questionaire. Changed SubjectData output filename to "<Participant ID>_qu.dat" (previously was "subjects.dat". Would have been overwritten as wasn't dynamic.
author Carl Bussey <c.bussey@se10.qmul.ac.uk>
date Sun, 09 Jun 2013 22:06:52 +0100
parents 4031cbb02f08
children be66ee2fe9fe
line wrap: on
line source
/*=============================================================================
 * File:       InterBlockPanel.java
 * Author:     Marcus Pearce <m.pearce@gold.ac.uk>
 * Created:    <2008-01-08 15:39:18 marcusp>
 * Time-stamp: <2008-03-04 17:16:48 marcusp>
 *=============================================================================
 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class InterBlockPanel extends JPanel { 
    
    /* variables */ 
    private JButton continueButton;
    private JLabel message;
    private String previousText; 
    private String text = ""; 
    private Experiment exp; 

    /* accessors */ 
    public JButton getContinueButton() { return continueButton; }
    public void setText() { 
        previousText = text; 
        text = exp.getCurrentBlock().getLabel(); 
    }

    /* constructor */ 
    public InterBlockPanel(Experiment e) { 
        
        exp = e; 
        setText(); 

        continueButton = new JButton("Continue"); 
        JPanel continuePane = new JPanel(); 
        continuePane.add(continueButton); 

        message = new JLabel(); 
        message.setHorizontalAlignment(JLabel.CENTER);
        updateMessageDisplay(); 
        JPanel messagePane = new JPanel(new FlowLayout(FlowLayout.CENTER)); 
        messagePane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
        messagePane.add(message); 
        
        this.setLayout(new BorderLayout()); 
        this.add(messagePane, BorderLayout.CENTER); 
        this.add(continuePane, BorderLayout.SOUTH); 
    }

    public void updateMessageDisplay() { 
        message.setText(formatMessage()); 
    }
    
    private String formatMessage() { 
        StringBuffer sb = new StringBuffer();
        sb.append("<html><font size=\"+1\" face=\"sans\"><p align=center>");
        sb.append("That is the end of the ");
        sb.append(previousText); 
        sb.append(" block. "); 
        sb.append("<br>");
        sb.append("If you have any questions, you may ask them now."); 
        sb.append("<br>"); 
        sb.append("Otherwise, press the button below to continue on to the ");
        sb.append(text);
        sb.append(" block."); 
        sb.append("</p></html>");

        return sb.toString();
    }

    public void addContinueButtonListener(ActionListener al) { 
        continueButton.addActionListener(al); 
    }
}