package org.jcon.test.screen;

import org.jcon.ui.OutputConsole;
import org.jcon.util.DataLib;
import org.jcon.ba.system.ItemSystemMgr;
import javax.swing.JApplet;
import java.awt.Color;

/**
* The system entry point and marker class. A complex
* format is used to support Applet or application.
* THIS IS UNDERGOING TESTING
*
* @author Jack Harich
*/  // java -nojit org.jcon.test.screen.StartSystem

public class StartSystem extends JApplet {

//---------- Private Fields ------------------------------
private static boolean running = false;

//---------- Initialization ------------------------------
public static void main(String args[]) {
    System.out.println("Starting...");

    // OutputConsole option
    boolean showOutputConsole = DataLib
        .arrayContainsValueIgnoreCase(args, "OutputConsole");

    if (showOutputConsole) {
        new OutputConsole().setVisible(true);
    }
    // Start sytsem
    ItemSystemMgr mgr = new ItemSystemMgr();
    mgr.startSystem(new StartSystem(), args);
}
//---------- Applet Implementation -----------------------
/**
* This function is called by the web browser when the
* class has been embedded in a web page. The init() 
* function gets the parameters from the html page 
* and calls main with the parameters.
*
* @author Cindy Conway
*/
public void init() { 

    // Set the applet box to white on the html page
    getContentPane().setBackground(Color.white);

    // Only run the applet if it is not currently running
    // This keeps additional applets from being
    // loaded when the user presses refresh on their
    // browser
    if (running == false) {
        // Get Parameters. 

        // Allocate enough memory in args to hold the 
        // parameters, then set the parameters in args
        // CMC 1/12/99 String[] args = new String[0];
        String[] args = new String[0]; 

        // Get the host ip address
        // If it was specified, put it in args
        String hostArg = getParameter("host");
        if (hostArg != null) {
            args = new String[1];
            print(" Input Parameter: host = " + hostArg);
            args[0] = "host=" + hostArg;
        } 
		else {
            print(" Input Parameter: host = null Using parex parameter.");
		}

        // Call main with args
        StartSystem.main(args);
        running = true;
    }
}
//---------- Private Methods -----------------------------
private static void print(String text) {
    System.out.println("StartSystem" + text);
}

} // End class
