/*
 * Aleph Toolkit
 *
 * Copyright 1999, Brown University, Providence, RI.
 * 
 *                         All Rights Reserved
 * 
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose other than its incorporation into a
 * commercial product is hereby granted without fee, provided that the
 * above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of Brown University not be used in
 * advertising or publicity pertaining to distribution of the software
 * without specific, written prior permission.
 * 
 * BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ANY
 * PARTICULAR PURPOSE.  IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR
 * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

package aleph.gui;

import aleph.Aleph;
import aleph.Config;
import java.awt.Frame;
import java.util.Properties;
import java.util.Vector;
import java.util.Enumeration;
import java.util.NoSuchElementException;

/**
 * Keeps track of all the state information maintained by the gui.
 *
 * @author Maurice Herlihy
 * @date January 1999
 **/

public class State implements java.io.Serializable {

  // output constants
  public static final int CONSOLE = 0; // console display area
  public static final int PANED   = 1; // each PE gets one pane
  public static final int SINGLE  = 2; // each PE gets own window
  public static final int STDOUT  = 3; // each PE gets own window

  public int numPEs;		// number of PEs requested
  public int outChoice = 0;	// where to display output

  /**
   * Hosts where server is running.  
   **/
  public Vector liveHosts = new Vector();
  /**
   * Subset of liveHosts selected by user.
   **/
  public Vector selectedHosts = new Vector();
  
  public boolean logging;	// log console?
  public boolean profile;	// profile execution?
  public boolean java_g;	// run with java_g?

  // Properties named "aleph.blah"
  public Properties proprties = new Properties();

  public Frame frame;		// null in Batch mode

  /**
   * Constructor for awt
   **/
  public State(Frame frame) {
    this.frame    = frame;
    // Set flages as requested by run-time switch or Config file.
    java_g  = (System.getProperty("aleph.java_g") != null) || Config.java_g;
    profile = (System.getProperty("aleph.profile") != null) || Config.profile;
    logging = (System.getProperty("aleph.logging") != null) || Config.logging;
    numPEs  = Aleph.getIntProperty("aleph.numPEs", Config.numPEs);
  }

  /**
   * Constructor for batch
   **/
  public State () {
    this(null);
  }
  
  public String toString () {
    StringBuffer s = new StringBuffer("State[");
    s.append("numPEs: ");
    s.append(Integer.toString(numPEs));
    if (logging)
      s.append(", logging: on");
    if (profile)
      s.append(", profile: on");
    if (java_g)
      s.append(", java_g: on");
    s.append(", selected:" );
    for (Enumeration e = selectedHosts.elements();
         e.hasMoreElements();) {
      s.append(" ");
      s.append(e.nextElement().toString());
    }
    s.append("]");
    return s.toString();
  }

}
