//****************************************************************************
// CLASS NAME:	OptionsFrame.java
//
// AUTHOR:	Rick Brink
//		    rick@mail.csh.rit.edu
//		    http://www.csh.rit.edu/~rick
//
// VERSION:	1.0
//
// HISTORY:	4/16/96		Initial Version
//
// COPYRIGHT INFORMATION:
//
// This program and the Java source is in the public domain.
// Permission to use, copy, modify, and distribute this software
// and its documentation for NON-COMMERCIAL purposes and
// without fee is hereby granted.
//
//    Copyright 1996
//
//    Rick Brink
//    1266 Brighton-Henrietta Townline Rd.
//    Rochester, NY 14623
//
// DISCLAIMER:
//
// The author claims no responsibility for any damage, direct or indirect,
// to any harware or software as a result of using this program.
//****************************************************************************

import java.awt.Frame;
import java.awt.Panel;
import java.awt.FlowLayout;
import java.awt.CardLayout;
import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Button;
import java.awt.Choice;
import java.awt.Label;
import java.awt.Checkbox;
import java.awt.Event;
import java.awt.Container;
import java.awt.Component;
import java.awt.Insets;

/**
  * A class representing the Frame containing a wide range
  * of options that the user may select in order to change the
  * appearance or operation of the Petri Net Tool.
  *
  * @see PetriTool
  * @see PetriToolFrame
  * @see java.awt.Frame
  * @see java.awt.Panel
  * @see java.awt.FlowLayout
  * @see java.awt.CardLayout
  * @see java.awt.BorderLayout
  * @see java.awt.GridBagLayout
  * @see java.awt.GridBagConstraints
  * @see java.awt.Button
  * @see java.awt.Choice
  * @see java.awt.Label
  * @see java.awt.Checkbox
  * @see java.awt.Event
  * @see java.awt.Container
  * @see java.awt.Component
  * @see java.awt.Insets
  *
  * @version 1.0 July 3, 1996
  *
  * @author  Rick Brink
**/
class OptionsFrame extends Frame {
    /**
      * Used to access the system variables that are
      * changed by the user.
    **/
    private protected PetriTool petriTool_;

    /**
      * Panel containing Buttons which allow the user
      * to select which category of options to update
    **/
    private protected Panel optionTabs_;

    /** Panel containing the current set of option to be updated **/
    private protected Panel optionPanel_;

    /** Layout used for optionPanel_ **/
    private protected CardLayout layout_;

    /** String label for the current optionPanel_ Card **/
    private protected String currentPanel_ = "Colors";


    /** Panel used to display options relating to Color **/
    private protected Panel colorPanel_;

    /** Allows user to select the foreground Color **/
    private protected Choice foregroundColorChoice_;

    /** Allows user to select the background Color **/
    private protected Choice backgroundColorChoice_;

    /** Allows user to select the grid Color **/
    private protected Choice gridColorChoice_;

    /** Allows user to select the border Color **/
    private protected Choice borderColorChoice_;

    /** Allows user to select the caption Color **/
    private protected Choice captionColorChoice_;

    /** Label for foregroundColorChoice_ **/
    private protected Label foregroundColorLabel_;

    /** Label for backgroundColorChoice_ **/
    private protected Label backgroundColorLabel_;

    /** Label for gridColorChoice_ **/
    private protected Label gridColorLabel_;

    /** Label for borderColorChoice_ **/
    private protected Label borderColorLabel_;

    /** Label for captionColorChoice_ **/
    private protected Label captionColorLabel_;

    /** Label for colorPanel_ **/
    private protected Label colorLabel_;


    /** Panel used to display miscellaneous options **/
    private protected Panel miscPanel_;

    /** Whether or not to display labels on Places **/
    private protected Checkbox placeLabelCheckbox_;

    /** Whether or not to display labels on Transitions **/
    private protected Checkbox transitionLabelCheckbox_;

    /** Choose the maximum number of tokens allowed in a Place **/
    private protected Choice placeCapacityChoice_;

    /** Label for placeCapacityChoice_ **/
    private protected Label placeCapacityLabel_;

    /** Label for the miscPanel_ **/
    private protected Label miscLabel_;


    /** Panel used to display grid options **/
    private protected Panel gridPanel_;

    /** Whether or not to show the grid points **/
    private protected Checkbox showGridCheckbox_;

    /** Label for gridWidthChoice_ **/
    private protected Label gridWidthLabel_;

    /** Label for gridHeightChoice_ **/
    private protected Label gridHeightLabel_;

    /** Select the number of grid squares wide the grid should be **/
    private protected Choice gridWidthChoice_;

    /** Select the number of grid squares high the grid should be **/
    private protected Choice gridHeightChoice_;

    /** Label for the gridPanel_ **/
    private protected Label gridLabel_;


    /** Panel used to display simulation options **/
    private protected Panel simulationPanel_;

    /** Label for simulationSpeedChoice_ **/
    private protected Label simulationSpeedLabel_;

    /** Select the speed for simulation (1-10) **/
    private protected Choice simulationSpeedChoice_;

    /** Label for the historySizeChoice_ **/
    private protected Label historySizeLabel_;

    /**
      * Select the number of simulation cycles to save in history
      * for reverse stepping purposes
    **/
    private protected Choice historySizeChoice_;

    /** Label for simulationPanel_ **/
    private protected Label simulationLabel_;


    /** Panel used to display analysis options **/
    private protected Panel analysisPanel_;

    /** Whether or not to bound the time used for analysis **/
    private protected Checkbox boundAnalysisTimeCheckbox_;

    /** Label for boundTimeChoice_ **/
    private protected Label boundTimeLabel_;

    /** Choose a bounding time for analysis **/
    private protected Choice boundTimeChoice_;

    /** Label for analysisPanel_ **/
    private protected Label analysisLabel_;


    /** Panel containing Buttons for OK, Default, and Cancel **/
    private protected Panel buttonPanel_;


    /**
      * Construct a new Options frame.  This frame allows the
      * user to select options relating to Color, Grid, Simulation,
      * Analysis, and other miscellaneous items.
    **/
    public OptionsFrame(PetriTool app) {
        super("PetriTool Options");
        petriTool_ = app;
        setLayout (new BorderLayout());

        // ---------------------------------------------------------
        // OPTIONS FRAME
        // ---------------------------------------------------------

        // Create a Panel of buttons from which to choose option groups
        optionTabs_ = new Panel();
        optionTabs_.add(new Button("Colors"));
        optionTabs_.add(new Button("Grid"));
        optionTabs_.add(new Button("Analysis"));
        optionTabs_.add(new Button("Simulation"));
        optionTabs_.add(new Button("Misc"));
        add("North", optionTabs_);

        // Create the card layout panel
        optionPanel_ = new Panel();
        layout_ = new CardLayout();
        optionPanel_.setLayout(layout_);

        // ---------------------------------------------------------
        // COLOR OPTIONS
        // ---------------------------------------------------------

        // Create a Panel for Color options
        colorPanel_ = new Panel();
        colorPanel_.setLayout (new GridBagLayout());

        // Label the option box
        colorLabel_ = new Label("Color Options", Label.LEFT);
        constrain(colorPanel_, colorLabel_, 0, 0, 2, 2, 0,
                  GridBagConstraints.NORTH, 0, 0, 0, 0, 0, 0);

        // Choices for Foreground Color
        foregroundColorChoice_ = new Choice();
        foregroundColorChoice_.addItem("black");
        foregroundColorChoice_.addItem("blue");
        foregroundColorChoice_.addItem("cyan");
        foregroundColorChoice_.addItem("darkGray");
        foregroundColorChoice_.addItem("gray");
        foregroundColorChoice_.addItem("green");
        foregroundColorChoice_.addItem("lightGray");
        foregroundColorChoice_.addItem("magenta");
        foregroundColorChoice_.addItem("orange");
        foregroundColorChoice_.addItem("pink");
        foregroundColorChoice_.addItem("red");
        foregroundColorChoice_.addItem("white");
        foregroundColorChoice_.addItem("yellow");
        foregroundColorLabel_ = new Label("Foreground Color");
        constrain(colorPanel_, foregroundColorLabel_, 1, 2, 1, 1);
        constrain(colorPanel_, foregroundColorChoice_, 0, 2, 1, 1, 0,
                  GridBagConstraints.EAST, 0, 0, 0, 0, 0, 0);


         // Choices for Background Color
        backgroundColorChoice_ = new Choice();
        backgroundColorChoice_.addItem("black");
        backgroundColorChoice_.addItem("blue");
        backgroundColorChoice_.addItem("cyan");
        backgroundColorChoice_.addItem("darkGray");
        backgroundColorChoice_.addItem("gray");
        backgroundColorChoice_.addItem("green");
        backgroundColorChoice_.addItem("lightGray");
        backgroundColorChoice_.addItem("magenta");
        backgroundColorChoice_.addItem("orange");
        backgroundColorChoice_.addItem("pink");
        backgroundColorChoice_.addItem("red");
        backgroundColorChoice_.addItem("white");
        backgroundColorChoice_.addItem("yellow");
        backgroundColorLabel_ = new Label("Background Color");
        constrain(colorPanel_, backgroundColorLabel_, 1, 3, 1, 1);
        constrain(colorPanel_, backgroundColorChoice_, 0, 3, 1, 1, 0,
                  GridBagConstraints.EAST, 0, 0, 0, 0, 0, 0);

        // Choices for Grid Color
        gridColorChoice_ = new Choice();
        gridColorChoice_.addItem("black");
        gridColorChoice_.addItem("blue");
        gridColorChoice_.addItem("cyan");
        gridColorChoice_.addItem("darkGray");
        gridColorChoice_.addItem("gray");
        gridColorChoice_.addItem("green");
        gridColorChoice_.addItem("lightGray");
        gridColorChoice_.addItem("magenta");
        gridColorChoice_.addItem("orange");
        gridColorChoice_.addItem("pink");
        gridColorChoice_.addItem("red");
        gridColorChoice_.addItem("white");
        gridColorChoice_.addItem("yellow");
        gridColorLabel_ = new Label("Grid Color");
        constrain(colorPanel_, gridColorLabel_, 1, 4, 1, 1);
        constrain(colorPanel_, gridColorChoice_, 0, 4, 1, 1, 0,
                  GridBagConstraints.EAST, 0, 0, 0, 0, 0, 0);

        // Choices for Border Color
        borderColorChoice_ = new Choice();
        borderColorChoice_.addItem("black");
        borderColorChoice_.addItem("blue");
        borderColorChoice_.addItem("cyan");
        borderColorChoice_.addItem("darkGray");
        borderColorChoice_.addItem("gray");
        borderColorChoice_.addItem("green");
        borderColorChoice_.addItem("lightGray");
        borderColorChoice_.addItem("magenta");
        borderColorChoice_.addItem("orange");
        borderColorChoice_.addItem("pink");
        borderColorChoice_.addItem("red");
        borderColorChoice_.addItem("white");
        borderColorChoice_.addItem("yellow");
        borderColorLabel_ = new Label("Border Color");
        constrain(colorPanel_, borderColorLabel_, 1, 5, 1, 1);
        constrain(colorPanel_, borderColorChoice_, 0, 5, 1, 1, 0,
                  GridBagConstraints.EAST, 0, 0, 0, 0, 0, 0);

        // Choices for caption Color
        captionColorChoice_ = new Choice();
        captionColorChoice_.addItem("black");
        captionColorChoice_.addItem("blue");
        captionColorChoice_.addItem("cyan");
        captionColorChoice_.addItem("darkGray");
        captionColorChoice_.addItem("gray");
        captionColorChoice_.addItem("green");
        captionColorChoice_.addItem("lightGray");
        captionColorChoice_.addItem("magenta");
        captionColorChoice_.addItem("orange");
        captionColorChoice_.addItem("pink");
        captionColorChoice_.addItem("red");
        captionColorChoice_.addItem("white");
        captionColorChoice_.addItem("yellow");
        captionColorLabel_ = new Label("Caption Color");
        constrain(colorPanel_, captionColorLabel_, 1, 6, 1, 1);
        constrain(colorPanel_, captionColorChoice_, 0, 6, 1, 1, 0,
                  GridBagConstraints.EAST, 0, 0, 0, 0, 0, 0);


        // ---------------------------------------------------------
        // MISC OPTIONS
        // ---------------------------------------------------------

        // Create a Panel for Misc options
        miscPanel_ = new Panel();
        miscPanel_.setLayout (new GridBagLayout());

        // Label the option box
        miscLabel_ = new Label("Miscellaneous Options", Label.LEFT);
        constrain(miscPanel_, miscLabel_, 0, 0, 2, 2);

        // Display Place labels
        placeLabelCheckbox_ = new Checkbox("Display Place Labels");
        constrain(miscPanel_, placeLabelCheckbox_, 0, 2, 2, 1);

        // Display Place labels
        transitionLabelCheckbox_ = new Checkbox("Display Transition Labels");
        constrain(miscPanel_, transitionLabelCheckbox_, 0, 3, 2, 1);

        // Choose maximum place capacity
        placeCapacityChoice_ = new Choice();
        placeCapacityChoice_.addItem("1");
        placeCapacityChoice_.addItem("2");
        placeCapacityChoice_.addItem("3");
        placeCapacityChoice_.addItem("4");
        placeCapacityChoice_.addItem("5");
        placeCapacityChoice_.addItem("6");
        placeCapacityChoice_.addItem("7");
        placeCapacityChoice_.addItem("8");
        placeCapacityChoice_.addItem("9");
        placeCapacityChoice_.addItem("10");
        placeCapacityChoice_.addItem("11");
        placeCapacityChoice_.addItem("12");
        placeCapacityChoice_.addItem("13");
        placeCapacityChoice_.addItem("14");
        placeCapacityChoice_.addItem("15");
        placeCapacityChoice_.addItem("16");
        placeCapacityChoice_.addItem("32");
        placeCapacityLabel_ = new Label("Place Capacity");
        constrain(miscPanel_, placeCapacityChoice_, 0, 4, 1, 1, 0,
                  GridBagConstraints.EAST, 0, 0, 0, 0, 0, 0);
        constrain(miscPanel_, placeCapacityLabel_, 1, 4, 1, 1, 0,
                  GridBagConstraints.WEST, 0, 0, 0, 0, 0, 0);




        // ---------------------------------------------------------
        // GRID OPTIONS
        // ---------------------------------------------------------

        // Create a Panel for Grid options
        gridPanel_ = new Panel();
        gridPanel_.setLayout (new GridBagLayout());

        // Label the option box
        gridLabel_ = new Label("Grid Options", Label.CENTER);
        constrain(gridPanel_, gridLabel_, 0, 0, 2, 2, 0,
                  GridBagConstraints.NORTH, 0, 0, 0, 0, 0, 0);

        // Show Grid
        showGridCheckbox_ = new Checkbox("Show Grid");
        constrain(gridPanel_, showGridCheckbox_, 0, 2, 2, 1, 0,
                  GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0);

        // Choices for Grid Size
        gridWidthChoice_ = new Choice();
        gridWidthChoice_.addItem("10");
        gridWidthChoice_.addItem("15");
        gridWidthChoice_.addItem("20");
        gridWidthChoice_.addItem("25");
        gridWidthChoice_.addItem("30");
        gridWidthChoice_.addItem("35");
        gridWidthChoice_.addItem("40");
        gridWidthChoice_.addItem("45");
        gridWidthChoice_.addItem("50");
        constrain(gridPanel_, gridWidthChoice_, 0, 3, 1, 1, 0,
                  GridBagConstraints.EAST, 0, 0, 0, 0, 0, 0);
        gridWidthLabel_ = new Label("Grid Width");
        constrain(gridPanel_, gridWidthLabel_, 1, 3, 1, 1, 0,
                  GridBagConstraints.WEST, 0, 0, 0, 0, 0, 0);

        gridHeightChoice_ = new Choice();
        gridHeightChoice_.addItem("10");
        gridHeightChoice_.addItem("15");
        gridHeightChoice_.addItem("20");
        gridHeightChoice_.addItem("25");
        gridHeightChoice_.addItem("30");
        gridHeightChoice_.addItem("35");
        gridHeightChoice_.addItem("40");
        gridHeightChoice_.addItem("45");
        gridHeightChoice_.addItem("50");
        constrain(gridPanel_, gridHeightChoice_, 0, 4, 1, 1, 0,
                  GridBagConstraints.EAST, 0, 0, 0, 0, 0, 0);
        gridHeightLabel_ = new Label("Grid Height");
        constrain(gridPanel_, gridHeightLabel_, 1, 4, 1, 1, 0,
                  GridBagConstraints.WEST, 0, 0, 0, 0, 0, 0);


        // ---------------------------------------------------------
        // SIMULATION OPTIONS
        // ---------------------------------------------------------

        // Create a Panel for Simulation options
        simulationPanel_ = new Panel();
        simulationPanel_.setLayout (new GridBagLayout());

        // Label the option box
        simulationLabel_ = new Label("Simulation Options", Label.CENTER);
        constrain(simulationPanel_, simulationLabel_, 0, 0, 2, 2, 0,
                  GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0);

        // Choices for simulation speed
        simulationSpeedChoice_ = new Choice();
        simulationSpeedChoice_.addItem("1");
        simulationSpeedChoice_.addItem("2");
        simulationSpeedChoice_.addItem("3");
        simulationSpeedChoice_.addItem("4");
        simulationSpeedChoice_.addItem("5");
        simulationSpeedChoice_.addItem("6");
        simulationSpeedChoice_.addItem("7");
        simulationSpeedChoice_.addItem("8");
        simulationSpeedChoice_.addItem("9");
        simulationSpeedChoice_.addItem("10");
        simulationSpeedLabel_ = new Label("Simulation Speed");
        constrain(simulationPanel_, simulationSpeedLabel_, 1, 2, 1, 1);
        constrain(simulationPanel_, simulationSpeedChoice_, 0, 2, 1, 1);

        // Choices for simulation history size
        historySizeChoice_ = new Choice();
        historySizeChoice_.addItem("10");
        historySizeChoice_.addItem("25");
        historySizeChoice_.addItem("50");
        historySizeChoice_.addItem("75");
        historySizeChoice_.addItem("100");
        historySizeChoice_.addItem("200");
        historySizeChoice_.addItem("250");
        historySizeChoice_.addItem("300");
        historySizeChoice_.addItem("400");
        historySizeChoice_.addItem("500");
        historySizeLabel_ = new Label("History Size");
        constrain(simulationPanel_, historySizeLabel_, 1, 3, 1, 1);
        constrain(simulationPanel_, historySizeChoice_, 0, 3, 1, 1);

        // ---------------------------------------------------------
        // ANALYSIS OPTIONS
        // ---------------------------------------------------------

        // Create a Panel for Analysis options
        analysisPanel_ = new Panel();
        analysisPanel_.setLayout (new GridBagLayout());

        // Label the option box
        analysisLabel_ = new Label("Analysis Options", Label.CENTER);
        constrain(analysisPanel_, analysisLabel_, 0, 0, 2, 2, 0,
                  GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0);

        // Bounded Analysis Time (Y/N)
        boundAnalysisTimeCheckbox_ = new Checkbox("Bound Analysis Time");
        constrain(analysisPanel_, boundAnalysisTimeCheckbox_, 0, 2, 2, 1, 0,
                  GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0);

        // Bounded Analysis Time (minutes)
        boundTimeChoice_ = new Choice();
        boundTimeChoice_.addItem("1");
        boundTimeChoice_.addItem("5");
        boundTimeChoice_.addItem("10");
        boundTimeChoice_.addItem("30");
        boundTimeChoice_.addItem("60");
        boundTimeChoice_.addItem("240");
        boundTimeChoice_.addItem("480");
        boundTimeLabel_ = new Label("Bound Time (minutes)");
        constrain(analysisPanel_, boundTimeLabel_, 1, 3, 1, 1, 0,
                  GridBagConstraints.WEST, 0, 0, 0, 0, 0, 0);
        constrain(analysisPanel_, boundTimeChoice_, 0, 3, 1, 1, 0,
                  GridBagConstraints.EAST, 0, 0, 0, 0, 0, 0);

        // Create a button panel
        buttonPanel_ = new Panel();
        buttonPanel_.setLayout (new FlowLayout());
        buttonPanel_.add (new Button ("OK"));
        buttonPanel_.add (new Button ("Default"));
        buttonPanel_.add (new Button ("Cancel"));

        // ---------------------------------------------------------
        // OPTIONS FRAME continued
        // ---------------------------------------------------------

        //  Add option panels to the card layout
        optionPanel_.add ("Colors", colorPanel_);
        optionPanel_.add ("Grid", gridPanel_);
        optionPanel_.add ("Simulation", simulationPanel_);
        optionPanel_.add ("Analysis", analysisPanel_);
        optionPanel_.add ("Misc", miscPanel_);

        add("Center", optionPanel_);
        add("South", buttonPanel_);

        // Set all of the options to their defaults
        setCurrentValues ();

        // Size and show the OptionsFrame
        resize(350, 250);
        show();
        resize(350, 250);
    }


    /**
      * Handle WINDOW_DESTROY events, propagate all others up
      * with super.handleEvent().
    **/
    public boolean handleEvent(Event ev) {
        if (ev.id == Event.WINDOW_DESTROY) {
            hide();
            petriTool_.optionsFrame_ = null;
            return true;
        }
        return super.handleEvent(ev);
    }


    /**
      * Set all of the option choices back to their default values
    **/
    public void setDefaultValues(boolean setAllDefaults) {

        if (currentPanel_.equals("Colors") || setAllDefaults) {
            foregroundColorChoice_.select("black");
            backgroundColorChoice_.select("white");
            gridColorChoice_.select("gray");
            borderColorChoice_.select("red");
            captionColorChoice_.select("blue");
        }

        if (currentPanel_.equals("Grid") || setAllDefaults) {
            showGridCheckbox_.setState(true);
            gridWidthChoice_.select("25");
            gridHeightChoice_.select("25");
        }

        if (currentPanel_.equals("Simulation") || setAllDefaults) {
            simulationSpeedChoice_.select("5");
            historySizeChoice_.select("100");
        }

        if (currentPanel_.equals("Analysis") || setAllDefaults) {
            boundAnalysisTimeCheckbox_.setState(true);
            boundTimeChoice_.select("1");
        }

        if (currentPanel_.equals("Misc") || setAllDefaults) {
            placeLabelCheckbox_.setState(true);
            transitionLabelCheckbox_.setState(true);
            placeCapacityChoice_.select("16");
        }

        repaint();
    }

    /**
      * Load all of the option items with their current values
      * in PetriTool
    **/
    public void setCurrentValues() {
        String tempString__ = new String("");
        foregroundColorChoice_.select(petriTool_.foregroundColorStr_);
        backgroundColorChoice_.select(petriTool_.backgroundColorStr_);
        gridColorChoice_.select(petriTool_.gridColorStr_);
        borderColorChoice_.select(petriTool_.borderColorStr_);
        captionColorChoice_.select(petriTool_.captionColorStr_);

        showGridCheckbox_.setState(petriTool_.showGrid_);
        gridWidthChoice_.select(tempString__.valueOf(petriTool_.gridWidth_));
        gridHeightChoice_.select(tempString__.valueOf(petriTool_.gridHeight_));

        simulationSpeedChoice_.select(tempString__.valueOf(petriTool_.simulationSpeed_));
        historySizeChoice_.select(tempString__.valueOf(petriTool_.historySize_));

        boundAnalysisTimeCheckbox_.setState(petriTool_.boundAnalysisTime_);
        boundTimeChoice_.select(tempString__.valueOf(petriTool_.boundTime_));

        placeLabelCheckbox_.setState(petriTool_.placeLabels_);
        transitionLabelCheckbox_.setState(petriTool_.transitionLabels_);
        placeCapacityChoice_.select(tempString__.valueOf(petriTool_.maxPlaceCapacity_));

        repaint();
    }


    /**
      * Save all of the values selected by the user to the
      * appropriate variables in PetriTool
    **/
    public void setNewValues() {

        Integer tempInt__ = new Integer (gridWidthChoice_.getSelectedItem());
        Integer tempInt2__ = new Integer (gridHeightChoice_.getSelectedItem());
        petriTool_.setGridSize (tempInt__.intValue(), tempInt2__.intValue());

        tempInt__ = new Integer (simulationSpeedChoice_.getSelectedItem());
        tempInt2__ = new Integer (historySizeChoice_.getSelectedItem());
        Integer tempInt3__ = new Integer (boundTimeChoice_.getSelectedItem());
        Integer tempInt4__ = new Integer (placeCapacityChoice_.getSelectedItem());

        petriTool_.setSystemVariables(foregroundColorChoice_.getSelectedItem(),
                                      backgroundColorChoice_.getSelectedItem(),
                                      gridColorChoice_.getSelectedItem(),
                                      borderColorChoice_.getSelectedItem(),
                                      captionColorChoice_.getSelectedItem(),
                                      placeLabelCheckbox_.getState(),
                                      transitionLabelCheckbox_.getState(),
                                      showGridCheckbox_.getState(),
                                      tempInt__.intValue(),
                                      tempInt2__.intValue(),
                                      boundAnalysisTimeCheckbox_.getState(),
                                      tempInt3__.intValue(),
                                      tempInt4__.intValue());
    }


    /**
      * Handle all actions of the Buttons within the OptionFrame
    **/
    public boolean action(Event ev, Object arg) {
         if (ev.target instanceof Button) {
            String label = (String)arg;
            if (arg.equals ("Colors")) {
                layout_.show(optionPanel_, "Colors");
                currentPanel_ = "Colors";
            }
            else if (arg.equals ("Grid")) {
                layout_.show(optionPanel_, "Grid");
                currentPanel_ = "Grid";
            }
            else if (arg.equals ("Simulation")) {
                layout_.show(optionPanel_, "Simulation");
                currentPanel_ = "Simulation";
            }
            else if (arg.equals ("Analysis")) {
                layout_.show(optionPanel_, "Analysis");
                currentPanel_ = "Analysis";
            }
            else if (arg.equals ("Misc")) {
                layout_.show(optionPanel_, "Misc");
                currentPanel_ = "Misc";
            }
            else if (arg.equals ("Default")) {
                setDefaultValues(false);
                return true;
            }
            else if (arg.equals ("Cancel")) {
                hide();
                petriTool_.optionsFrame_ = null;
                return true;
            }
            else if (arg.equals ("OK")) {
                setNewValues();
                hide();
                petriTool_.optionsFrame_ = null;
                petriTool_.designPanel_.repaint();
                return true;
            }
        }
        return true;

    }

    /**
	 * constrain - a method for placing components in a grid bag
	 *             layout
	 *
	 * @see		awt.GridBagLayout
	 * @author	Rick Brink
	 *
	**/
    public void constrain(Container container, Component component,
                  int grid_x, int grid_y, int grid_width, int grid_height,
                  int fill, int anchor, double weight_x, double weight_y,
                  int top, int left, int bottom, int right)
    {
        GridBagConstraints c = new GridBagConstraints();
        c.gridx = grid_x; c.gridy = grid_y;
        c.gridwidth = grid_width; c.gridheight = grid_height;
        c.fill = fill; c.anchor = anchor;
        c.weightx = weight_x; c.weighty = weight_y;
        if (top+bottom+left+right > 0)
            c.insets = new Insets(top, left, bottom, right);

        ((GridBagLayout)container.getLayout()).setConstraints(component, c);
        container.add(component);
    }

	/**
	 * constrain - a method for placing components in a grid bag
	 *             layout
	 *
	 * @see		awt.GridBagLayout
	 * @author	Rick Brink
	 *
	**/
    public void constrain(Container container, Component component,
                  int grid_x, int grid_y, int grid_width, int grid_height) {
        constrain(container, component, grid_x, grid_y,
              grid_width, grid_height, GridBagConstraints.NONE,
              GridBagConstraints.NORTHWEST, 0.0, 0.0, 0, 0, 0, 0);
    }


	/**
	 * constrain - a method for placing components in a grid bag
	 *             layout
	 *
	 * @see		awt.GridBagLayout
	 * @author	Rick Brink
	 *
	**/
    public void constrain(Container container, Component component,
                  int grid_x, int grid_y, int grid_width, int grid_height,
                  int top, int left, int bottom, int right) {
        constrain(container, component, grid_x, grid_y,
              grid_width, grid_height, GridBagConstraints.NONE,
              GridBagConstraints.NORTHWEST,
              0.0, 0.0, top, left, bottom, right);
    }

}
