import java.awt.*;
import javax.swing.*;

/**
 * A frame/window that shows progress being made
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 3.0
 */
public class ProgressWindow extends    JFrame
                            implements LineObserver
{
    int                   lines;
    JProgressBar          bar;



    /**
     * Explicit Value Constructor
     *
     * @param max   The number of "operations"
     */
    public ProgressWindow(int max)
    {
       super();

       lines = 0;
       bar = new JProgressBar(0, max);
       performLayout();
       setVisible(true);
    }


    /**
     * Handle a line of text
     */
    public void handleLine(LineSubject source)
    {
       indicateProgress();
    }




    /**
     * Indicate that progress has been made
     */
    private void indicateProgress()
    {
       lines++;
       bar.setValue(lines);
    }



    /**
     * Layout this component
     */
    private void performLayout()
    {
       setSize(300,50);

       bar.setString("Lines Read");
       bar.setStringPainted(true);

       getContentPane().add(bar);
    }
}
