import java.awt.*;
import java.io.*;
import java.util.*;
import javax.swing.*;

/**
 * An application that reads text from the console,
 * counts the number of words that start with uppercase
 * letters, and saves the text in a file.
 *
 * This version uses the Observer Pattern
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 3.0
 */
public class SillyTextProcessor
{

    /**
     * The entry-point of the application
     *
     * @param args   The command line arguments
     */
    public static void main(String[] args) throws Exception
    {
       int                 maxLines;
       LineArchiver        archiver;
       LineReader          reader;
       ProgressWindow      bar;
       UCWordCounter       counter;


       // Process the command line parameter
       try 
       {
          maxLines = Integer.parseInt(args[0]);
       }
       catch (NumberFormatException nfe) 
       {
          maxLines = 5;
       }

//[body.

       // Initialization
       reader   = new LineReader(System.in, maxLines);
       bar      = new ProgressWindow(maxLines);
       archiver = new LineArchiver();
       counter  = new UCWordCounter();
	
       reader.addObserver(bar);
       reader.addObserver(archiver);
       reader.addObserver(counter);

       // Prompt the user
       System.out.println("Enter " +maxLines +
                          " lines of text (^Z to end):\n");

       reader.start();
//]body.
    }

}
