package html;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TextFormatter extends JFrame
{
    
    /**
     * The left and right margins between the screen and 
     * this window's left and right boundaries
     */    
    private static final int HORIZONTAL_MARGIN = 40;

    /**
     * The top and bottom margins between the screen and 
     * this window's top and bottom boundaries
     */    
    private static final int VERTICAL_MARGIN   = 500;

    /**
     * The size of the screen
     */
    private Dimension screenSize;
    private Font plain, bold, italic, both;
    private boolean isBold, isItalic;
    private Container contentPane; 


	public TextFormatter() {
		super("TextFormatter output");
		plain = new Font("Times", Font.PLAIN, 24);
		bold = new Font("Times", Font.BOLD, 24);
		italic = new Font("Times", Font.ITALIC, 24);
		both = new Font("Times", Font.ITALIC|Font.BOLD, 24);
		isBold = false; isItalic = false;
		initialize();
		show();
	}
	
	public void bold() { isBold = true; }
	public void italic() { isItalic = true; }
	public void plain() { isBold = false; isItalic = false; }
	public void outputText(String t) {
		Label label = new Label(t, Label.CENTER);
		Font font;
		if (isBold && isItalic) font = both;
		else if (isBold) font = bold;
		else if (isItalic) font = italic;
		else font = plain;
		label.setFont(font);
		contentPane.add(label);
        try{
		Thread.sleep(1500);
		} catch (Throwable e) {}
		show();
	}
	
    /**
     * Moves this dialog to the center of the screen.
     */
    protected void moveToCenter()
    {
         Dimension selfBounds = getSize();
         setLocation((screenSize.width - selfBounds.width) / 2,
                     (screenSize.height - selfBounds.height) / 2);
    }
	
	private void initialize(  ) {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        screenSize      = toolkit.getScreenSize();

        setSize(screenSize.width-HORIZONTAL_MARGIN,screenSize.height-VERTICAL_MARGIN);
	
        contentPane = getContentPane();
        contentPane.setBackground( Color.white );
        
        contentPane.setLayout(new FlowLayout(FlowLayout.LEFT, -8, 20));
        Label l1 = new Label("      ", Label.CENTER);
        l1.setFont(new Font("Helvetica", Font.BOLD, 16));
        //Label l2 = new Label("Another label", Label.CENTER);
        //l2.setFont(new Font("Helvetica", Font.PLAIN, 16));
      contentPane.add(l1);
      //contentPane.add(l2);
        moveToCenter();
        
        addWindowListener(
        	  new WindowAdapter( ) 
            {
            	  public void windowClosing(WindowEvent e) 
 				        {
				    	      System.exit(0);
            	  }
            }
        );
    }

}
