package at.oefai.aaa;

import java.io.File;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import com.jgoodies.plaf.plastic.PlasticLookAndFeel;
import com.jgoodies.plaf.plastic.PlasticXPLookAndFeel;
import com.jgoodies.plaf.plastic.theme.ExperienceBlue;

/**
 * <p>Title: AAAViewer</p>
 * <p>Description: project for a master thesis in computer science (Dimplomarbeit)</p>
 * <p>Copyright: Copyright (c) 2003</p>
 *
 * Lets you view ActAffAct scenes.
 * Saving and restoring of actaffact snapshots, starting and pausing of the action, detailed
 * info about the agents and their environment.
 * @author Stefan Rank
 */
public class AAAViewerApp {
    private IState actingState = new StateManager();

    /**
     * The main class constructor called from main.
     */
    protected AAAViewerApp() {
        // check for default file in the prefs.
        String defFileLoc = AppPrefs.getDefaultFileLocation();
        if (! defFileLoc.equals("")) {
            this.actingState.load(new File(defFileLoc));
        }
    }

    /**
     * The main class starting point for ActAffAct.
     */
    public static void main(final String[] argv) {
        if (argv.length > 0) {
            System.out.println("no command line arguments needed (ignoring it)");
            System.out.println("          (persistent settings in aaaPref.xml)");
            System.exit(-1); // 'abnormal' program termination
        }

        Logger log = Logger.getLogger("");
        Handler[] hs = log.getHandlers();
        if (hs.length > 0) {
            Formatter f = new SimplestFormatter();
            hs[0].setFormatter(f);
            hs[0].setLevel(Level.ALL); // loglevels are managed at Logger level
        }

        // set up native system Look&Feel or even plastic from jgoodies
        PlasticXPLookAndFeel laf = new PlasticXPLookAndFeel();
        PlasticLookAndFeel.setMyCurrentTheme(new ExperienceBlue());
        try { // these should not throw serious exceptions so just print a stacktrace (no logger yet)
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            // but now try to use the plasticxplookandfeel
            UIManager.setLookAndFeel(laf);
        } catch (ClassNotFoundException e) {
            log.logp(Level.WARNING, null, null, "catching Exception from setLookAndFeel", e);
        } catch (InstantiationException e) {
            log.logp(Level.WARNING, null, null, "catching Exception from setLookAndFeel", e);
        } catch (IllegalAccessException e) {
            log.logp(Level.WARNING, null, null, "catching Exception from setLookAndFeel", e);
        } catch (UnsupportedLookAndFeelException e) {
            log.logp(Level.WARNING, null, null, "catching Exception from setLookAndFeel", e);
        }
        //      for testing:
        //com.jgoodies.clearlook.ClearLookManager.setMode(com.jgoodies.clearlook.ClearLookMode.DEBUG);
        //com.jgoodies.clearlook.ClearLookManager.setMode(com.jgoodies.clearlook.ClearLookMode.ON);
        //com.jgoodies.clearlook.ClearLookManager.setMode(com.jgoodies.clearlook.ClearLookMode.VERBOSE);

        new AAAViewerApp();
    }
}



