view InterBlockPanel.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 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); 
    }
}