/*
 *  Draco Econometrics
 *  Copyright (C) 2006-2007 Approximatrix, LLC
 *  http://www.approximatrix.com
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.approximatrix.draco.application;

import javax.swing.SwingUtilities;

/** Class to in */
public class InitializeWorker {
	
	private static final long INIT_MS = 1000;
	private static final long SLEEP_MS = 2000;
	
	private static final String[] MESSAGES = {"Initializing...",
											  "Loading and Sizing Graphics",
											  "Creating the Main Window",
											  "Advertising..." };
	
	public static int GetTotalSteps() {
		return MESSAGES.length;
	}
	
	public InitializeWorker() {
	}
	
	public int getTotalSteps() {
		return MESSAGES.length;
	}
	
	public String getStepDescription(int i) {
		if(i>=0&&i<this.getTotalSteps()) 
			return MESSAGES[i];
		else
			return "Starting Up...";
	}
	
	public void doStep(int step) {
		switch(step) {
			case 0:
				this.advertise(INIT_MS);
				break;
			case 1:
				this.loadGraphics();
				break;
			case 2:
				this.createMainWindow();
				break;
			case 3:
				this.advertise(SLEEP_MS);
				break;
		}
	}
	
	private void loadGraphics() {
		ApplicationManager.LoadIcons();
	}
	
	private void createMainWindow() {
		Runnable doCreateWindow = new Runnable() {
            public void run() {
            	ApplicationManager.RequestNewWindow();
            }
        };
		SwingUtilities.invokeLater(doCreateWindow);
	}
	
	private void advertise(final long ms) {
		try {
			Thread.sleep(ms);
		} catch (InterruptedException ie) {
			System.err.println("Problem advertising...");
		}
	}
	
}



