import java.awt.*;
import java.io.IOException;

/**
 * Main class for the client. It handles interaction with user, sends user
 * supplied messages over the network to the server, and processes messages 
 * from the server. It has a controlPanel to handle chat and classroom issues,
 * and a drawPanel to provide a shared whiteBoard. It also has a ClientSocket
 * to manage it's connection to the server.
 *
 * @author    Johan Andersen
 * @version   $Revision: 1.3 $       $Date: 1998/05/04 17:12:34 $
 * 
 * @see controlPanel
 * @see drawPanel
 * @see ClientSocket
 */

class whiteBoard
{
  public controlPanel cp;
  public drawPanel dp;

  protected ClientSocket socket;

  /**
   * Creates the user interface. Instantiates a control panel and a draw panel.
   * 
   * @see drawPanel
   * @see controlPanel
   */

  public whiteBoard()
  {
    cp = new controlPanel(this);
    cp.setTitle("WhiteBoard");

    dp = new drawPanel(this,400,400);
    dp.setTitle("WhiteBoard");
  }

  /**
   * Function called by the controlPanel to attempt to log into a server.
   *
   * @param user The username to log in as
   * @param host The hostname of the server we want to log into
   * @param port The port number the server is running on.
   *
   * @exception IOException  Thrown if an IO exception occurs during connection
   * @exception DupUserException Thrown if the selected username is in use
   *
   * @see ClientSocket
   */

  public void connect(String user, String host, int port)
       throws IOException, DupUserException
  {
    socket = new ClientSocket(this,user,host,port);
  }

  /**
   * Function called when the user changes type (ie from student to teacher or
   * from teacher to student). Add more cases into this procedure for more
   * types (ie, Observer)
   *
   * @param type the case-insensitive type-descriptor (currently allowed values
   *             are "teacher" and "student")
   */

  public void setType(String type)
  {
    if (type.equalsIgnoreCase("student")) {
      cp.setLevel(false);
      dp.setDrawable(false);
    } else if (type.equalsIgnoreCase("teacher")) {
      cp.setLevel(true);
      dp.setDrawable(true);
    }
  }

  /**
   * Function called to cleanly quit the program
   */
  public void doQuit()
  {
    cp.setVisible(false);
    cp.dispose();

    dp.setVisible(false);
    dp.dispose();
    
    System.exit(0);
  }

  public static void main(String args[]) 
  {
    whiteBoard wb = new whiteBoard();
    
    wb.cp.setLocation(100,100);
    wb.dp.setLocation(500,100);
    wb.cp.setVisible(true);
    wb.dp.setVisible(true);
  }
}
