Package eas.startSetup.marbBuilder

Source Code of eas.startSetup.marbBuilder.SteuerFenster

/*
* Datei:          SteuerFenster.java
* Autor(en):      Lukas König
* Java-Version:   6.0
* Erstellt (vor): 19.12.2008
*
* (c) This file and the EAS (Easy Agent Simulation) framework containing it
* is protected by Creative Commons by-nc-sa license. Any altered or
* further developed versions of this file have to meet the agreements
* stated by the license conditions.
*
* In a nutshell
* -------------
* You are free:
* - to Share -- to copy, distribute and transmit the work
* - to Remix -- to adapt the work
*
* Under the following conditions:
* - Attribution -- You must attribute the work in the manner specified by the
*   author or licensor (but not in any way that suggests that they endorse
*   you or your use of the work).
* - Noncommercial -- You may not use this work for commercial purposes.
* - Share Alike -- If you alter, transform, or build upon this work, you may
*   distribute the resulting work only under the same or a similar license to
*   this one.
*
* + Detailed license conditions (Germany):
*   http://creativecommons.org/licenses/by-nc-sa/3.0/de/
* + Detailed license conditions (unported):
*   http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en
*
* This header must be placed in the beginning of any version of this file.
*/

package eas.startSetup.marbBuilder;

import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.List;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Random;

import eas.math.fundamentalAlgorithms.type2grammars.EarleyParser;
import eas.miscellaneous.StaticMethods;
import eas.miscellaneous.system.FileNamePostfixFilter;
import eas.miscellaneous.system.windowFrames.CheckboxDialog;
import eas.miscellaneous.system.windowFrames.GeneralDialog;
import eas.miscellaneous.system.windowFrames.WindowClosingAdapter;
import eas.plugins.Plugin;
import eas.plugins.standard.eaPlugin.evolvableTranslators.EvolutionPluginCompletelyEvolvable;
import eas.plugins.standard.visualization.AllroundVideoPlugin;
import eas.simulation.ConstantsSimulation;
import eas.simulation.SimulationStarter;
import eas.simulation.spatial.sim2D.marbSimulation.EnvironmentEA;
import eas.simulation.spatial.sim2D.marbSimulation.OpsFactory;
import eas.simulation.spatial.sim2D.marbSimulation.RobEA;
import eas.simulation.spatial.sim2D.marbSimulation.endlAutomat.EndlicherAutomat;
import eas.simulation.spatial.sim2D.marbSimulation.endlAutomat.RobCode;
import eas.simulation.spatial.sim2D.marbSimulation.endlAutomat.Transition;
import eas.simulation.spatial.sim2D.marbSimulation.endlAutomat.ZInfo;
import eas.simulation.spatial.sim2D.marbSimulation.endlAutomat.conditions.Condition;
import eas.simulation.spatial.sim2D.marbSimulation.mutation.CondMutVerfahren;
import eas.simulation.spatial.sim2D.marbSimulation.rekombination.RekVerfahren;
import eas.startSetup.GlobalVariables;
import eas.startSetup.ParCollection;
import eas.startSetup.marbBuilder.darstellungsModi.DarstModEA;
import eas.startSetup.marbBuilder.graph.Knoten;



/**
* Klasse zur Repräsentation eines Steuerfensters.
*
* @author Lukas König
*/
public class SteuerFenster extends Frame
                           implements ActionListener,
                                      ItemListener {

    /**
     * Die Versions-ID.
     */
    private static final long serialVersionUID = 1L;

    /**
     * Die Parameter für den Lauf.
     */
    private ParCollection pars;

    /**
     * Liste von Graphfenstern, die verwaltet werden.
     */
    private ArrayList<Vis> graphen;

    /**
     * Der aktuell ausgewählte Graph.
     */
    private Vis aktGrph;

    /**
     * Eine Listbox.
     */
    private List ktList;

    /**
     * Eine Textfeld, in dem die Aktion steht.
     */
    private TextField aktion;

    /**
     * Eine Textfeld, in dem der Parameter steht.
     */
    private TextField param;

    /**
     * Eine Textfeld, in dem der Zustandsname steht.
     */
    private TextField zustName;

    /**
     * Eine Textfeld, in dem das Alter des Zustands steht.
     */
    private TextField alter;

    /**
     * Speichert den aktuellen Knoten.
     */
    private Knoten aktKnot;

    /**
     * Das Panel, das angezeigt wird, wenn eine Kante geändert wird.
     */
    private Panel kantenEinstell;

    /**
     * Eine Textfeld, in dem die Bedingung steht.
     */
    private TextField beding;

    /**
     * Eine Textfeld, in dem der Folgezustand steht.
     */
    private TextField folgeZust;

    /**
     * Das Alter der jeweiligen Kante.
     */
    private TextField ktAlter;

    /**
     * Die Auswahl der Graphen als Auswahlfeld.
     */
    private Choice grAuswahl;

    /**
     * zählt die neu erzeugten Graphen.
     */
    private int graphZaehl;

    /**
     * Die Umgebung, in der sich die Roboter befinden.
     */
    private EnvironmentEA umg;

    /**
     * Erkenner mit einer Grammatik für Bytes.
     */
    private EarleyParser byteErk;

    /**
     * Erkenner mit einer Grammatik für Bedingungen.
     */
    private EarleyParser bedgErk;

    /**
     * Erkenner mit einer Grammatik für Sequenzen.
     */
    private EarleyParser seqErk;

    /**
     * Fenster zum Anzeigen der Sensoren des aktiven Roboters während der
     * Simulation.
     */
    private SensorenDarstellung sensFenster;

    /**
     * Der Zufallsgenerator.
     */
    private Random rand;
   
    /**
     * Das Rekombinationsverfahren.
     */
    private RekVerfahren rekombArt;

    /**
     * Die Anzahl an Automaten.
     */
    private int autAnz;
   
    /**
     * Das Mutationsverfahren für Verhaltensautomaten.
     */
    private CondMutVerfahren mutArtVerh;

    /**
     * Das Mutationsverfahren für Translatoren.
     */
    private CondMutVerfahren mutArtTrans;

    /**
     * Die aktuell gültigen Plugins.
     */
    private LinkedList<Plugin<?>> plugins;
   
    /**
     * Der Konstruktor.
     *
     * @param parameter  Der Parametersatz für den Lauf.
     */
    public SteuerFenster(final ParCollection parameter) {
        super(GlobalVariables.PROG_NAME
                + " V "
                + GlobalVariables.PROG_VERSION);
        this.pars = parameter;
        this.reset();
    }
   
    /**
     * Setzt das Steuerfenster zurück.
     */
    public void reset() {
        this.removeAll();
       
        this.plugins = this.pars.getPlugins();
       
        this.rand = new Random(this.pars.getSeed().longValue());

        // Setzen der Mutation.
        if (this.pars.getPlugIDList().contains(new EvolutionPluginCompletelyEvolvable().id())) {
            this.mutArtVerh = OpsFactory.getKonstMut(this.pars
                    .getParValueString(EvolutionPluginCompletelyEvolvable.MUT_ART_VE), this.rand,
                    this.pars);

            this.mutArtTrans = OpsFactory.getKonstMut(this.pars
                    .getParValueString(EvolutionPluginCompletelyEvolvable.MUT_ART_TR), this.rand,
                    this.pars);

            this.rekombArt = OpsFactory.getKonstRek(this.pars
                    .getParValueString(EvolutionPluginCompletelyEvolvable.REK_VERFAHREN_AT), this.pars,
                    this.rand);

            this.pars.setParValue(EvolutionPluginCompletelyEvolvable.MUT_ART_VE, this.mutArtVerh.id());
        }
       
        this.autAnz = eas.simulation.ConstantsSimulation.ANZAHL_AN_AUTOMATEN;
       
        this.graphen = new ArrayList<Vis>();
        this.aktGrph = null;
        this.graphZaehl = 0;
        this.byteErk = new EarleyParser(
                eas.math.fundamentalAlgorithms.type2grammars.ConstantsEarley.GRAMM_BY, this.pars);
        this.bedgErk = new EarleyParser(
                eas.math.fundamentalAlgorithms.type2grammars.ConstantsEarley.GRAMM_BE, this.pars);
        this.seqErk  = new EarleyParser(
                eas.math.fundamentalAlgorithms.type2grammars.ConstantsEarley.GRAMM_SE, this.pars);

        this.setLocation(800, 0);
        this.setSize(300, 700);
        this.setzeSteuerelemente();
        this.ladeGraphen();
        this.autAnz = this.aktGrph.getRob().vAuts().length;
        this.setVisible(true);

        this.sensFenster
        = new SensorenDarstellung(
                ConstantsSimulation.SENSOR_ANZAHL_ANZEIGEN,
                ConstantsSimulation.SENSOR_ANZAHL_BERECHNET,
                this.aktGrph.getRob());
        this.sensFenster.setSize(ConstantsSimulation.SENS_FENSTER_BREITE,
                                 ConstantsSimulation.SENS_FENSTER_HOEHE);
        this.sensFenster.setAlwaysOnTop(true);
    }

    /**
     * lädt gespeicherte Graphen aus dem im Parameterobjekt angegebenen
     * Verzeichnis.
     */
    private void ladeGraphen() {
        File verz = new File(this.pars.getStdDirectory());
        String endung = eas.startSetup.marbBuilder.ConstantsGraphVis.GRAPH_ENDUNG;
        String[] gespGr = verz.list(new FileNamePostfixFilter(endung));
        String graphName;
        Vis graphFenster;

        if (gespGr != null) {
            for (int i = 0; i < gespGr.length; i++) {
                graphName = gespGr[i].substring(
                                0,
                                gespGr[i].length() - endung.length() - 1);
               
                graphFenster = new Vis(Messages.getString("SteuerFenster.EA")
                                       + graphName + "]",
                                       graphName,
                                       this,
                                       this.umg,
                                       this.seqErk,
                                       this.mutArtVerh,
                                       this.mutArtTrans,
                                       this.rand,
                                       this.kleinsteFreieID(),
                                       this.pars,
                                       this.autAnz,
                                       null,
                                       this.plugins);

                this.grAuswahl.add(graphName);
                this.graphen.add(graphFenster);
                this.graphZaehl++;
            }
        }

        // Erzeuge einzelnen neuen Graphen, falls kein Graph gespeichert war.
        if (this.graphen.size() <= 0
            || this.grAuswahl.getItemCount() <= 0) {

            graphFenster = new Vis(
                    Messages.getString("SteuerFenster.EA")
                        + eas.startSetup.marbBuilder.ConstantsGraphVis.STD_GRAPH_NAME
                        + 0
                        + "]",
                    eas.startSetup.marbBuilder.ConstantsGraphVis.STD_GRAPH_NAME + 0,
                    this,
                    this.umg,
                    this.seqErk,
                    this.mutArtVerh,
                    this.mutArtTrans,
                    this.rand,
                    this.kleinsteFreieID(),
                    this.pars,
                    this.autAnz,
                    null,
                    this.plugins);
            this.grAuswahl.add(eas.startSetup.marbBuilder.ConstantsGraphVis.STD_GRAPH_NAME
                                    + 0);
            this.graphen.add(graphFenster);
            this.graphZaehl++;
        }

        this.waehleGraph(0);
    }

    /**
     * wählt einen Graphen für die Darstellung aus.
     *
     * @param nummer  Die Nummer des zu wählenden Graphen.
     */
    private void waehleGraph(final int nummer) {
        int altX = 0;
        int altY = 0;

        if (this.aktGrph != null) {
            altX = this.aktGrph.getLocation().x;
            altY = this.aktGrph.getLocation().y;
        }

        this.aktGrph = this.graphen.get(nummer);
        this.aktGrph.setLocation(altX, altY);
        this.aktGrph.setVisible(true);
        this.grAuswahl.select(nummer);

        for (int i = 0; i < this.graphen.size(); i++) {
            if (i != nummer) {
                this.graphen.get(i).setVisible(false);
            }
        }
    }

    /**
     * Setzt alle Steuerelemente und Fenstereigenschaften.
     */
    private void setzeSteuerelemente() {
        this.addWindowListener(new WindowClosingAdapter(true, this));
        this.setBackground(Color.lightGray);
        this.setLayout(new GridLayout(1, 1));

        Button b;
        Panel buttonPanel = new Panel();
        Panel buttonPanel2 = new Panel();
        Panel buttonPanel3 = new Panel();
        Panel buttonPanel4 = new Panel();
        Panel listPanel = new Panel();
        Panel editPanel = new Panel();
        Panel labelPanel = new Panel();
        listPanel.setLayout(new GridLayout(0, 1));
        editPanel.setLayout(new GridLayout(4, 1));
        labelPanel.setLayout(new GridLayout(4, 1));
        buttonPanel2.setLayout(new GridLayout(5, 2));
        buttonPanel3.setLayout(new GridLayout(6, 3));
        buttonPanel4.setLayout(new GridLayout(2, 1));
       
        Panel choiPan = new Panel(new GridLayout(1, 1));

        Panel p = new Panel();
        b = new Button(Messages.getString("SteuerFenster.Autoanordnung"));
        b.addActionListener(this);
        buttonPanel.add(b);
        b = new Button(Messages.getString("SteuerFenster.Beenden"));
        b.addActionListener(this);
        buttonPanel.add(b);
        b = new Button(Messages.getString("SteuerFenster.KnotLoeschen"));
        b.addActionListener(this);
        buttonPanel2.add(b);
        b = new Button(Messages.getString("SteuerFenster.KnotEinfuegen"));
        b.addActionListener(this);
        buttonPanel2.add(b);
        b = new Button(Messages.getString("SteuerFenster.KantLoeschen"));
        b.addActionListener(this);
        buttonPanel2.add(b);
        b = new Button(Messages.getString("SteuerFenster.KantEinfuegen"));
        b.addActionListener(this);
        buttonPanel2.add(b);
        b = new Button(Messages.getString("SteuerFenster.Uebernehmen"));
        b.addActionListener(this);
        buttonPanel2.add(b);
        b = new Button(Messages.getString("SteuerFenster.AusSequenz"));
        b.addActionListener(this);
        buttonPanel2.add(b);
        b = new Button("Aus Std-Sequenz");
        b.addActionListener(this);
        buttonPanel2.add(b);
        b = new Button(Messages.getString("SteuerFenster.InterpretScript"));
        b.addActionListener(this);
        buttonPanel2.add(b);
        b = new Button(Messages.getString("SteuerFenster.Fancy"));
        b.addActionListener(this);
        buttonPanel2.add(b);
       
        b = new Button(Messages.getString("SteuerFenster.SIM"));
        b.addActionListener(this);
        buttonPanel4.add(b);
        b = new Button(Messages.getString("SteuerFenster.EVO"));
        b.addActionListener(this);
        buttonPanel4.add(b);

        this.aktion = new TextField("", 5);
        this.param = new TextField("", 5);
        this.alter = new TextField("", 5);
        this.zustName = new TextField("", 5);
        this.zustName.setEditable(false);

        labelPanel.add(new Label(Messages.getString("SteuerFenster.Zustand"),
                                 Label.LEFT));
        labelPanel.add(new Label(Messages.getString("SteuerFenster.Aktion"),
                                 Label.LEFT));
        labelPanel.add(new Label(Messages.getString("SteuerFenster.Parameter"),
                                 Label.LEFT));
        labelPanel.add(new Label(Messages.getString("SteuerFenster.Alter"),
                                 Label.LEFT));
        editPanel.add(this.zustName);
        editPanel.add(this.aktion);
        editPanel.add(this.param);
        editPanel.add(this.alter);

        this.ktList = new List(5, false);
        this.ktList.add(
            "                                            "
            + "                                          ");
        this.ktList.addActionListener(this);
        this.ktList.addItemListener(this);
        listPanel.add(this.ktList);

        this.kantenEinstell = new Panel();
        this.kantenEinstell.setLayout(new GridLayout(3, 1));
        this.beding = new TextField("", 35);
        this.folgeZust = new TextField("", 35);
        this.ktAlter = new TextField("", 35);
        this.kantenEinstell.add(this.beding);
        this.kantenEinstell.add(this.folgeZust);
        this.kantenEinstell.add(this.ktAlter);

        this.grAuswahl = new Choice();
        choiPan.add(this.grAuswahl);
        this.grAuswahl.addItemListener(this);

        b = new Button(Messages.getString("SteuerFenster.GraphLoeschen"));
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button(Messages.getString("SteuerFenster.GraphLeeren"));
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button(Messages.getString("SteuerFenster.AlleLeeren"));
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button(Messages.getString("SteuerFenster.NeuerGraph"));
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button(Messages.getString("SteuerFenster.Mutation"));
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button(Messages.getString("SteuerFenster.Rekombination"));
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button(Messages.getString("SteuerFenster.GraphKopieren"));
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button(Messages.getString("SteuerFenster.GraphSpeichern"));
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button(Messages.getString("SteuerFenster.GraphLaden"));
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button(Messages.getString("SteuerFenster.GraphUmbenennen"));
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button(Messages.getString("SteuerFenster.Vereinfache"));
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button(Messages.getString("SteuerFenster.VereinfacheAlle"));
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button(Messages.getString("SteuerFenster.ErzeugeHEX"));
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button(Messages.getString("SteuerFenster.Automatenzahl"));
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button(Messages.getString("SteuerFenster.Gesamtautomat"));
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button("PNG...");
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button("Alle löschen!");
        b.addActionListener(this);
        buttonPanel3.add(b);
        b = new Button("Alle speichern");
        b.addActionListener(this);
        buttonPanel3.add(b);

        p.add(buttonPanel);
        p.add(listPanel);
        p.add(labelPanel);
        p.add(editPanel);
        p.add(this.kantenEinstell);
        p.add(buttonPanel2);
        p.add(choiPan);
        p.add(buttonPanel3);
        p.add(buttonPanel4);

        this.kantenEinstell.setVisible(true);
        this.kantenEinstell.setEnabled(false);
        this.beding.setText("");
        this.folgeZust.setText("");
        this.ktAlter.setText("");
        this.add(p);

        this.setResizable(true);
    }

    /**
     * Selektiert einen Knoten und fügt ihn in die Darstellungsstrukturen
     * ein.
     *
     * @param knot  Der neue Knoten.
     */
    public void selKn(final Knoten knot) {
        String bed;
        int folgeZustand;
        int kantAlter;
        ZInfo zusatz;
        Iterator<Transition> it;
        Transition bedingung;
        String istStart = "";

        this.loescheSelKnot();
        this.aktKnot = knot;

        if (this.aktKnot != null) {
            zusatz = this.aktKnot.getInfo();

            it = zusatz.getBeds().iterator();
            while (it.hasNext()) {
                bedingung = it.next();
                bed = bedingung.getCond().toString();
                folgeZustand = bedingung.getFolgezustand();
                kantAlter = bedingung.getAlter();
                this.ktList.add(bed
                                  + "-"
                                  + folgeZustand
                                  + " ("
                                  + kantAlter
                                  + ")");
            }

            this.aktion.setText("" + zusatz.getAktion());
            this.param.setText("" + zusatz.getParam());
            this.alter.setText("" + zusatz.getAlter());
            if (zusatz.istStartZ()) {
                istStart = Messages.getString("SteuerFenster.IstStart");
            }
            this.zustName.setText("" + knot.holeName() + istStart);
        }
    }

    /**
     * löscht den aktuellen Knoten und die Listenelemente, etc.
     */
    public void loescheSelKnot() {
        this.aktKnot = null;
        this.ktList.removeAll();
        this.aktion.setText("");
        this.param.setText("");
        this.alter.setText("");
        this.zustName.setText("");
        this.beding.setText("");
        this.folgeZust.setText("");
        this.ktAlter.setText("");
        this.kantenEinstell.setEnabled(false);
        this.beding.setText("");
        this.folgeZust.setText("");
     }

    /**
     * Behandelt die änderung des Listenelements.
     *
     * @param event  Das Event.
     */
    @Override
    public void itemStateChanged(final ItemEvent event) {
        int pos;
        ZInfo zusatz;
        Transition bed;

        if (event.getSource() == this.ktList) {
            pos = ((Integer) event.getItem()).intValue();
            this.kantenEinstell.setEnabled(true);

            if (this.ktList.getSelectedItem() != null) {
                if (this.ktList.getSelectedItem().equals(
                        Messages.getString("SteuerFenster.KanteNeu"))) {
                    this.beding.setText(
                        Messages.getString("SteuerFenster.Bedingung"));
                    this.folgeZust.setText(
                        Messages.getString("SteuerFenster.FolgeZ"));
                    this.ktAlter.setText(
                        Messages.getString("SteuerFenster.KantAlter"));
                } else {
                    zusatz = this.aktKnot.getInfo();
                    bed = zusatz.getBeds().get(pos);
                    this.beding.setText(bed.getCond().toString());
                    this.folgeZust.setText("" + bed.getFolgezustand());
                    this.ktAlter.setText("" + bed.getAlter());
                }
            }
        } else if (event.getSource() == this.grAuswahl) {
            this.waehleGraph(this.grAuswahl.getSelectedIndex());
            this.selKn(this.aktGrph.getAktSelKnot());
        }
    }

    /**
     * Die actionPerformed Methode.
     *
     * @param event  Das Event.
     */
    @Override
    public void actionPerformed(final ActionEvent event) {
        Object obj = event.getSource();
        String cmd = event.getActionCommand();
        String neueBed;
        int pos;
        ZInfo neuerZusatz;
        String neuFlZst;
        String neuKtAl;
        String[] elemente;
        boolean grammOk = true;
        Iterator<Vis> itG;
        String[] altSeq = this.aktGrph.getRob().erzeugeStrSeqs();
        Condition[] altCond = this.aktGrph.getRob().getConds();
        String befehl;

        befehl = ""
            + StaticMethods.posSuch(ConstantsSimulation.getBefehlNamenArray(this.pars),
                                this.aktion.getText());

        this.setCursor(new Cursor(Cursor.WAIT_CURSOR));

        itG = this.graphen.iterator();
        while (itG.hasNext()) {
            itG.next().setCursor(new Cursor(Cursor.WAIT_CURSOR));
        }

        try {
            if (obj instanceof Button) {
                if (cmd.equals(Messages.getString(
                        "SteuerFenster.Autoanordnung"))) {
                    this.aktGrph.zuruecksetzen();
                } else if (cmd.equals(Messages.getString(
                        "SteuerFenster.Beenden"))) {
                    WindowClosingAdapter ende
                        = new WindowClosingAdapter(true, this);
                    ende.schliesseExt(this);
                } else if (cmd.equals(Messages.getString(
                        "SteuerFenster.Uebernehmen"))
                           && this.aktKnot != null) {
                    GeneralDialog dia;
                    ArrayList<String> buttons = new ArrayList<String>();
                    buttons.add(Messages.getString("SteuerFenster.OK"));

                    if (!this.byteErk.erkenne(befehl)) {
                        dia = new GeneralDialog(this,
                                        null,
                                        Messages.getString(
                                           "SteuerFenster.Earley"),
                                        buttons,
                                        "<"
                                        + befehl
                                        + ">\n\n\n"
                                        + this.byteErk.toString());
                        dia.setVisible(true);
                        grammOk = grammOk & false;
                    }
                    if (!this.byteErk.erkenne(this.param.getText())) {
                        dia = new GeneralDialog(this,
                                        null,
                                        Messages.getString(
                                           "SteuerFenster.Earley"),
                                        buttons,
                                        "<"
                                        + this.param.getText()
                                        + ">\n\n\n"
                                        + this.byteErk.toString());
                        dia.setVisible(true);
                        grammOk = grammOk & false;
                    }
                    if (!this.byteErk.erkenne(this.alter.getText())) {
                        dia = new GeneralDialog(this,
                                        null,
                                        Messages.getString(
                                           "SteuerFenster.Earley"),
                                        buttons,
                                        "<"
                                        + this.alter.getText()
                                        + ">\n\n\n"
                                        + this.byteErk.toString());
                        dia.setVisible(true);
                        grammOk = grammOk & false;
                    }
                    if (this.ktList.getSelectedItems().length > 0) {
                        this.beding.setText(
                                EndlicherAutomat.formatBed(
                                        this.beding.getText()));
                       
                        if (!this.bedgErk.erkenne(this.beding.getText())) {
                            dia = new GeneralDialog(this,
                                            null,
                                            Messages.getString(
                                               "SteuerFenster.Earley"),
                                            buttons,
                                            "<"
                                            + this.beding.getText()
                                            + ">\n\n\n"
                                            + this.bedgErk.toString());
                            dia.setVisible(true);
                            grammOk = grammOk & false;
                        }
                        if (!this.byteErk.erkenne(this.folgeZust.getText())) {
                            dia = new GeneralDialog(this,
                                            null,
                                            Messages.getString(
                                               "SteuerFenster.Earley"),
                                            buttons,
                                            "<"
                                            + this.folgeZust.getText()
                                            + ">\n\n\n"
                                            + this.byteErk.toString());
                            dia.setVisible(true);
                            grammOk = grammOk & false;
                        }
                        if (!this.byteErk.erkenne(this.ktAlter.getText())) {
                            dia = new GeneralDialog(this,
                                            null,
                                            Messages.getString(
                                               "SteuerFenster.Earley"),
                                            buttons,
                                            "<"
                                            + this.ktAlter.getText()
                                            + ">\n\n\n"
                                            + this.byteErk.toString());
                            dia.setVisible(true);
                            grammOk = grammOk & false;
                        }
                    } else {
                        grammOk = grammOk & true;
                    }

                    if (grammOk) {
                        boolean istStart
                            = this.aktGrph.getRob().istStartZ(this.aktKnot);
                        if (this.ktList.getSelectedItem() != null
                            && !this.beding.getText().equals(
                                Messages.getString("SteuerFenster.Bedingung"))
                            && !this.folgeZust.getText().equals(
                                Messages.getString("SteuerFenster.FolgeZ"))
                            && !this.ktAlter.getText().equals(
                                Messages.getString("SteuerFenster.KantAlter"))
                            && !this.beding.getText().equals("")
                            && !this.folgeZust.getText().equals("")
                            && !this.ktAlter.getText().equals("")) {
                            pos = this.ktList.getSelectedIndex();
                            neueBed = StaticMethods.ausFormatBed(
                                          this.beding.getText())
                                      + "-"
                                      + this.folgeZust.getText()
                                      + " ("
                                      + this.ktAlter.getText()
                                      + ")";
                            this.ktList.replaceItem(neueBed, pos);
                        }
                        this.aktKnot.loescheAlleNachfolger();
                        if (this.alter.getText().equals("")) {
                            this.alter.setText("1");
                        }
                        neuerZusatz = new ZInfo(
                                Integer.parseInt(befehl),
                                Integer.parseInt(this.param.getText()),
                                null,
                                istStart,
                                Integer.parseInt(this.alter.getText()));

                        this.aktKnot.setzeInformation(neuerZusatz);
                       
                        elemente = this.ktList.getItems();
                        String aktEl;
                        for (int i = 0; i < elemente.length; i++) {
                            aktEl = elemente[i];
                            if (!aktEl.equals(Messages.getString(
                                    "SteuerFenster.KanteNeu"))) {
                                int j;
                                for (j = 0;
                                aktEl.charAt(j) != '-';
                                    j = j + 0) {
                                    j++;
                                }
                                int k;
                                for (k = j;
                                aktEl.charAt(k) != '(';
                                    k = k + 0) {
                                    k++;
                                }
                                neueBed = aktEl.substring(0, j);
                                neuFlZst = aktEl.substring(j + 1, k - 1);
                                neuKtAl = aktEl.substring(k + 1,
                                        aktEl.length() - 1);

                                neueBed = EndlicherAutomat.formatBed(neueBed);
                               
                                this.aktGrph.getRob().vAuts()[
                                     this.aktGrph.getAktAut()].einfuegKante(
                                     this.aktKnot.holeName(),
                                     new Integer(
                                         Integer.parseInt(neuFlZst)),
                                     neueBed,
                                     Integer.parseInt(neuKtAl));
                            }
                        }
                    }
                } else if (cmd.equals(Messages.getString(
                                "SteuerFenster.KnotLoeschen"))
                           && this.aktKnot != null) {
                    this.aktGrph.getRob().vAuts()[
                                   this.aktGrph.getAktAut()].entferneKnoten(
                        this.aktKnot.holeName());
                    this.loescheSelKnot();
                } else if (cmd.equals(Messages.getString(
                                "SteuerFenster.KantLoeschen"))
                            && this.ktList.getSelectedItem() != null) {
                    int j;
                    int k;

                    if (this.ktList.getSelectedItem().equals("<Neue"
                                                               + " Kante>")) {
                        this.ktList.remove(this.ktList.getSelectedIndex());
                    } else {
                        neueBed = this.ktList.getSelectedItem();
                        for (j = 0; neueBed.charAt(j) != '-'; j = j + 0) {
                            j++;
                        }
                        for (k = j; neueBed.charAt(k) != '('; k = k + 0) {
                            k++;
                        }
                        neuFlZst = neueBed.substring(j + 1,
                                                     k - 1);
                        this.aktGrph.getRob().vAuts()[
                                      this.aktGrph.getAktAut()].entferneKante(
                                    this.aktKnot.holeName(),
                                    new Integer(Integer.parseInt(neuFlZst)));
                        this.ktList.remove(this.ktList.getSelectedIndex());
                    }
                    if (this.ktList.getItemCount() > 0) {
                        this.ktList.select(0);
                    }
                } else if (cmd.equals(Messages.getString(
                                "SteuerFenster.KnotEinfuegen"))
                           && !this.aktion.getText().equals("")
                           && !this.param.getText().equals("")) {
                    int i = 1;
                    Integer ii = new Integer(i);

                    GeneralDialog dia;
                    ArrayList<String> buttons = new ArrayList<String>();
                    buttons.add(Messages.getString("SteuerFenster.OK"));

                    if (!this.byteErk.erkenne(befehl)) {
                        dia = new GeneralDialog(this,
                                        null,
                                        Messages.getString(
                                           "SteuerFenster.Earley"),
                                        buttons,
                                        "<"
                                        + befehl
                                        + ">\n\n\n"
                                        + this.byteErk.toString());
                        dia.setVisible(true);
                        grammOk = grammOk & false;
                    }
                    if (!this.byteErk.erkenne(this.param.getText())) {
                        dia = new GeneralDialog(this,
                                        null,
                                        Messages.getString(
                                           "SteuerFenster.Earley"),
                                        buttons,
                                        "<"
                                        + this.param.getText()
                                        + ">\n\n\n"
                                        + this.byteErk.toString());
                        dia.setVisible(true);
                        grammOk = grammOk & false;
                    }
                    if (!this.byteErk.erkenne(this.alter.getText())) {
                        dia = new GeneralDialog(this,
                                        null,
                                        Messages.getString(
                                           "SteuerFenster.Earley"),
                                        buttons,
                                        "<"
                                        + this.alter.getText()
                                        + ">\n\n\n"
                                        + this.byteErk.toString());
                        dia.setVisible(true);
                        grammOk = grammOk & false;
                    }

                    if (grammOk) {
                        while (this.aktGrph.getRob().vAuts()[
                         this.aktGrph.getAktAut()].holAdj().containsKey(ii)) {
                            i++;
                            ii = new Integer(i);
                        }

                        if (this.alter.getText().equals("")) {
                            this.alter.setText("1");
                        }
                        this.aktGrph.getRob().vAuts()[
                               this.aktGrph.getAktAut()].einfuegenKnoten(
                                    ii,
                                    Integer.parseInt(befehl),
                                    Integer.parseInt(this.param.getText()),
                                    Integer.parseInt(this.alter.getText()));
                    }
                } else if (cmd.equals(Messages.getString(
                                "SteuerFenster.KantEinfuegen"))
                           && this.aktKnot != null) {
                    this.ktList.add(Messages.getString(
                                    "SteuerFenster.KanteNeu"));
                } else if (cmd.equals(Messages.getString(
                                "SteuerFenster.AusSequenz"))) {
                    int autNum = this.aktGrph.getAktAut();
                    String condS = this.aktGrph.getConditions()[autNum];
                    Condition cond = StaticMethods.ausBed(condS);
                   
                    this.aktGrph.getRob().erzeugeAusSequenz(
                        this.aktGrph.getAktAut(),
                        this.aktGrph.holeAktTxtSeq(),
                        cond,
                        this.aktGrph.getRob().getAktTAut(),
                        true);
                    this.loescheSelKnot();
                    StaticMethods.log(
                            StaticMethods.LOG_DEBUG,
                            "Aus Sequenz mit aktuellem Translator.",
                            this.pars);
                } else if (cmd.equals("Aus Std-Sequenz")) {
                    int autNum = this.aktGrph.getAktAut();
                    String condS = this.aktGrph.getConditions()[autNum];
                    Condition cond = StaticMethods.ausBed(condS);
                   
                    this.aktGrph.getRob().erzeugeAusSequenz(
                        this.aktGrph.getAktAut(),
                        this.aktGrph.holeAktTxtSeq(),
                        cond,
                        true);
                    this.loescheSelKnot();
                    StaticMethods.log(
                            StaticMethods.LOG_DEBUG,
                            "Aus Sequenz mit Standardkodierung "
                            + "ohne Translator.",
                            this.pars);
                } else if (cmd.equals(Messages.getString(
                                "SteuerFenster.AusSequenzen"))) {
                    this.aktGrph.erzeugeAlleAusSeq(
                            this.aktGrph.getSeqs(),
                            StaticMethods.ausBeds(this.aktGrph.getConditions()),
                            true);
                    this.loescheSelKnot();
                } else if (cmd.equals(Messages.getString(
                                "SteuerFenster.GraphLoeschen"))) {
                    GeneralDialog nachfrage;
                    ArrayList<String> buttons = new ArrayList<String>();
                    buttons.add(Messages.getString("SteuerFenster.OK"));
                    buttons.add(Messages.getString("SteuerFenster.Abbrechen"));

                    nachfrage = new GeneralDialog(
                                    this,
                                    "Soll der aktuelle Endliche Automat "
                                    + "<" + this.aktGrph
                                    + "> wirklich von der Festplatte gelöscht"
                                    + " UND aus der Darstellung entfernt "
                                    + "werden?",
                                    Messages.getString(
                                                "SteuerFenster.GraphLoeschen"),
                                    buttons,
                                    null);
                    nachfrage.setVisible(true);

                    if (nachfrage.getResult().equals(Messages.getString(
                                    "SteuerFenster.OK"))) {
                        this.loescheGraph(this.aktGrph, true);
                        this.waehleGraph(0);
                    }
                } else if (cmd.equals(Messages.getString(
                                "SteuerFenster.NeuerGraph"))) {
                    this.neuerGraph();
                    this.waehleGraph(this.graphZaehl - 1);
                } else if (cmd.equals(Messages.getString(
                                "SteuerFenster.GraphLeeren"))) {
                    GeneralDialog nachfrage;
                    ArrayList<String> buttons = new ArrayList<String>();
                    buttons.add(Messages.getString("SteuerFenster.OK"));
                    buttons.add(Messages.getString("SteuerFenster.Abbrechen"));

                    nachfrage = new GeneralDialog(
                                    this,
                                    "Sollen ALLE KNOTEN des aktuellen "
                                    + "Endlichen Automaten "
                                    + "<" + this.aktGrph
                                    + "> wirklich gelöscht"
                                    + " werden?",
                                    Messages.getString(
                                                  "SteuerFenster.GraphLeeren"),
                                    buttons,
                                    null);
                    nachfrage.setVisible(true);

                    if (nachfrage.getResult().equals(Messages.getString(
                                    "SteuerFenster.OK"))) {
                        this.aktGrph.leereAktGraph();
                        this.selKn(null);
                    }
                } else if (cmd.equals(Messages.getString(
                                    "SteuerFenster.AlleLeeren"))) {
                    GeneralDialog nachfrage;
                    ArrayList<String> buttons = new ArrayList<String>();
                    buttons.add(Messages.getString("SteuerFenster.OK"));
                    buttons.add(Messages.getString("SteuerFenster.Abbrechen"));
               
                    nachfrage = new GeneralDialog(
                                    this,
                                    "Sollen ALLE KNOTEN ALLER AUTOMATEN "
                                        + " wirklich gelöscht werden?",
                                    Messages.getString(
                                                  "SteuerFenster.AlleLeeren"),
                                    buttons,
                                    null);
                    nachfrage.setVisible(true);
               
                    if (nachfrage.getResult().equals(Messages.getString(
                                    "SteuerFenster.OK"))) {
                        Vis aktGraph;
                        Iterator<Vis> it = this.graphen.iterator();
                        while (it.hasNext()) {
                            aktGraph = it.next();
                            aktGraph.leereAlleGraphen();
                            aktGraph.neuZeichnen();
                        }
                        this.selKn(null);
                    }
                } else if (cmd.equals(Messages.getString(
                                "SteuerFenster.GraphKopieren"))) {
                    String[] seq = this.aktGrph.getRob().erzeugeStrSeqs();
                    Condition[] conds = this.aktGrph.getRob().getConds();
                    DarstModEA[] darAlt;
                    darAlt = (DarstModEA[])
                        StaticMethods.seriaClone(this.aktGrph.getDarstellArt());

                    this.neuerGraph();
                    this.waehleGraph(this.graphZaehl - 1);
                    this.aktGrph.setzeAlleSeq(seq);
                    this.aktGrph.getRob().erzeugeAusSequenzen(seq,
                                                              conds,
                                                              null,
                                                              false);
                    this.aktGrph.setDarstellArt(darAlt);

                } else if (cmd.equals(Messages.getString(
                                "SteuerFenster.GraphSpeichern"))) {
                    this.aktGrph.speichereGraph(
                                    Messages.getString("Vis.All"));
                } else if (cmd.equals(Messages.getString(
                                "SteuerFenster.GraphLaden"))) {
                    GeneralDialog nachfrage;
                    ArrayList<String> buttons = new ArrayList<String>();
                    buttons.add(Messages.getString("SteuerFenster.OK"));
                    buttons.add(Messages.getString("SteuerFenster.Abbrechen"));

                    nachfrage = new GeneralDialog(
                                    this,
                                    Messages.getString("SteuerFenster."
                                                    + "SollNeuLaden")
                                    + " <" + this.aktGrph
                                    + ">.",
                                    Messages.getString(
                                                  "SteuerFenster.GraphLaden"),
                                    buttons,
                                    null);
                    nachfrage.setVisible(true);

                    if (nachfrage.getResult().equals(Messages.getString(
                                    "SteuerFenster.OK"))) {
                        this.aktGrph.ladeRob();
                        this.loescheSelKnot();
                    }
                } else if (cmd.equals(Messages.getString(
                                "SteuerFenster.SIM"))) {
                    this.simStarten(false);
                } else if (cmd.equals(Messages.getString(
                                "SteuerFenster.EVO"))) {
                    this.simStarten(true);
                } else if (cmd.equals(
                        Messages.getString("SteuerFenster.GraphUmbenennen"))) {
                    GeneralDialog dia;
                    ArrayList<String> buttons = new ArrayList<String>();
                    buttons.add(Messages.getString("SteuerFenster.OK"));
                    buttons.add(Messages.getString("SteuerFenster.Abbrechen"));

                    dia = new GeneralDialog(
                                    this,
                                    null,
                                    Messages.getString("SteuerFenster."
                                                     + "SollUmbenennen"),
                                    buttons,
                                    this.aktGrph.getGraphName(),
                                    1,
                                    50,
                                    true);
                    dia.setVisible(true);

                    if (dia.getResult().equals(
                                    Messages.getString("SteuerFenster.OK"))) {
                        String name = dia.getText();
                        boolean ok = true;
                        Iterator<Vis> it = this.graphen.iterator();

                        while (it.hasNext()) {
                            Vis aktG = it.next();
                            if (aktG.getGraphName().equals(name)) {
                                ok = false;
                            }
                        }

                        if (ok) {
                            int index = this.grAuswahl.getSelectedIndex();
                            int max = this.grAuswahl.getItemCount();
                            ArrayList<String> strings = new ArrayList<String>();
                            for (int i = 0; i < max; i++) {
                                if (i == index) {
                                    strings.add(name);
                                } else {
                                    strings.add(this.grAuswahl.getItem(i));
                                }
                            }

                            this.grAuswahl.removeAll();
                            this.aktGrph.setGraphName(name);

                            for (int i = 0; i < max; i++) {
                                this.grAuswahl.add(strings.get(i));
                            }

                            this.grAuswahl.select(index);
                        }
                    }

                } else if (cmd.equals(
                           Messages.getString("SteuerFenster.Mutation"))) {
                    this.aktGrph.mutiere();
                } else if (cmd.equals(
                        Messages.getString("SteuerFenster.Rekombination"))) {
                    ArrayList<String> a = new ArrayList<String>();
                    Iterator<Vis> it = this.graphen.iterator();
                    while (it.hasNext()) {
                        Vis v = it.next();
                        a.add(v.toString());
                    }
                   
                    GeneralDialog dia = new GeneralDialog(
                              this,
                              "Rekombination",
                              "Bitte die zu rekombinierenden\nGraphen wählen.",
                              a,
                              Messages.getString("SteuerFenster.Abbrechen"),
                              Messages.getString("SteuerFenster.OK"),
                              true,
                              -1);
                    dia.setVisible(true);
                    if (dia.getResult()
                            == Messages.getString("SteuerFenster.OK")) {
                       
                        String[] str = dia.getListe().getSelectedItems();
                        RobEA[] pop = new RobEA[str.length];
                        Vis v;
                       
                        for (int i = 0; i < str.length; i++) {
                            it = this.graphen.iterator();
                            while (it.hasNext()) {
                                v = it.next();
                                if (v.toString().equals(str[i])) {
                                    pop[i] = v.getRob();
                                   
                                    for (int j = 0;
                                         j < v.getRob().vAuts().length;
                                         j++) {
                                        ArrayList<String> b
                                            = new ArrayList<String>(1);
                                        b.add(Messages.getString(
                                                "SteuerFenster.OK"));
                                        GeneralDialog dia2
                                            = new GeneralDialog(
                                                    this,
                                                    "",
                                                    "Fitness " + j
                                                      + " ("
                                                      + str[i]
                                                      + ")",
                                                    b,
                                                    "" + pop[i].getFitness()[0],
                                                    1,
                                                    50,
                                                    true);
   
                                        dia2.setVisible(true);
                                       
                                        pop[i].setFitness(j,
                                            Integer.parseInt(dia2.getText()));
                                        }
                                   
                                    break;
                                }
                            }
                        }

                        RobCode[] r = this.rekombArt.rekombEinz(pop);
                        for (int i = 0; i < r.length; i++) {
                            v = this.neuerGraph();
                            v.erzeugeAlleAusSeq(
                                    r[i].getVStdCodes(),
                                    null,
                                    false);
                            this.selGraph(v);
                        }
                    }
                   
                } else if (cmd.equals(
                           Messages.getString("SteuerFenster.ErzeugeHEX"))) {
                    FileDialog dia;

                    dia = new FileDialog(this,
                                         Messages.getString("SteuerFenster."
                                                        + "ErzeugeHEXTitel"),
                                         FileDialog.SAVE);
                    dia.setVisible(true);

                    if (!(dia.getDirectory() == null)
                        && !(dia.getFile() == null)) {
                        LinkedList<Integer> seq
                            = this.aktGrph.getRob().erzeugeSequenz(
                                    this.aktGrph.getAktAut());
                        FileWriter f = new FileWriter(dia.getDirectory()
                                                      + File.separatorChar
                                                      + dia.getFile());
                        Iterator<Integer> it = seq.iterator();

                        while (it.hasNext()) {
                            f.write(it.next().intValue());
                        }
                        f.close();
                    }
                } else if (cmd.equals(
                        Messages.getString("SteuerFenster.Vereinfache"))) {
                    this.aktGrph.getRob().vAuts()[
                                   this.aktGrph.getAktAut()].vereinfache();
                    Condition condSimp =
                        this.aktGrph.getRob().getConds()[
                                  this.aktGrph.getAktAut()].simplify();
                    this.aktGrph.getRob().setCond(this.aktGrph.getAktAut(),
                                                  condSimp);
                   
                } else if (cmd.equals(
                        Messages.getString("SteuerFenster.VereinfacheAlle"))) {
                    Iterator<Vis> it = this.graphen.iterator();
                    Condition condSimp;
                    Vis aktVis;
                    while (it.hasNext()) {
                        aktVis = it.next();
                        for (int i = 0;
                             i < aktVis.getRob().vAuts().length;
                             i++) {
                            aktVis.getRob().vAuts()[i].vereinfache();

                            condSimp = this.aktGrph.getRob().getConds()[
                                          i].simplify();
                            this.aktGrph.getRob().setCond(i, condSimp);
                            aktVis.neuZeichnen();
                        }
                    }
                } else if (cmd.equals(
                        Messages.getString("SteuerFenster.InterpretScript"))) {
                   
                    this.aktGrph.getRob().vAuts()[
                        this.aktGrph.getAktAut()].erzeugeAusScript(
                            this.aktGrph.holeAktTxtSeq(), this.pars);
                } else if (cmd.equals(
                        Messages.getString("SteuerFenster.Automatenzahl"))) {
                   
                    ArrayList<String> b
                        = new ArrayList<String>(1);
                    b.add(Messages.getString(
                        "SteuerFenster.OK"));
                    GeneralDialog dia2
                        = new GeneralDialog(
                            this,
                            "reef",
                            "Anzahl der Automaten "
                            + "(wirkt sich nur auf zukünftige Roboter aus)",
                            b,
                            "" + this.autAnz,
                            1,
                            50,
                            true);

                    dia2.setVisible(true);
                   
                    this.autAnz = Integer.parseInt(dia2.getText());
                } else if (cmd.equals(
                        Messages.getString("SteuerFenster.Gesamtautomat"))) {
                    EndlicherAutomat[] eas = this.aktGrph.getRob().getVAut();
                    Condition[] conds = this.aktGrph.getRob().getConds();
                   
                    this.neuerGraph();
                    this.waehleGraph(this.graphZaehl - 1);
                    this.aktGrph.erzeugeAktAusSequenz(
                       StaticMethods.gesamtAutomat(eas, conds, this.pars).erzeugeStringSeq(),
                       StaticMethods.ausBed("t"),
                       false);
                } else if (cmd.equals(
                        Messages.getString("SteuerFenster.Fancy"))) {
                    this.pars.setParValue(eas.statistics.ConstantsStatistics.EINFACHE_DARSTELLUNG,
                            !this.pars.getParValueBoolean(eas.statistics.ConstantsStatistics.EINFACHE_DARSTELLUNG));
                    if (this.pars.getParValueBoolean(eas.statistics.ConstantsStatistics.EINFACHE_DARSTELLUNG)) {
                        this.pars.setParValue(eas.statistics.ConstantsStatistics.BEZIER_KONST,
                                eas.startSetup.marbBuilder.zeichenModi.ConstantsZeichenModi.BEZ_FANCY);
                    } else {
                        this.pars.setParValue(eas.statistics.ConstantsStatistics.BEZIER_KONST,
                                eas.startSetup.marbBuilder.zeichenModi.ConstantsZeichenModi.BEZ_NORMAL);
                    }
                } else if (cmd.equals("PNG...")) {
                    FileDialog dia;
                    String oldVerz;
                   
                    dia = new FileDialog(this,
                                         "Automatendarstellung als PNG "
                                         + "speichern",
                                         FileDialog.SAVE);
                   
                    dia.setFilenameFilter(new FileNamePostfixFilter("png"));
                   
                    dia.setVisible(true);

                    if (!(dia.getDirectory() == null)
                        && !(dia.getFile() == null)) {
                        oldVerz = this.pars.getStdDirectory();
                        this.pars.setStdDirectory(dia.getDirectory());
                        this.aktGrph.savePNGandPDF(dia.getFile());
                        this.pars.setStdDirectory(oldVerz);
                    }
                } else if (cmd.equals("Alle löschen!")) {
                    ArrayList<String> butts = new ArrayList<String>(2);
                    ArrayList<String> choices = new ArrayList<String>(5);
                    ArrayList<Boolean> aktiv = new ArrayList<Boolean>(5);
                   
                    String gra, tra, con, koo, png, tmp, dat, gz, gif, txt;
                   
                    butts.add("Abbrechen");
                    butts.add("OK");

                    gra = "Alle GRA-Dateien löschen";
                    tra = "Alle TRA-Dateien löschen";
                    con = "Alle CON-Dateien löschen";
                    koo = "Alle KOO-Dateien löschen";
                    png = "Alle PNG-Dateien löschen";
                    tmp = "Alle TMP-Dateien löschen";
                    dat = "Alle DAT-Dateien löschen";
                    gz = "Alle GZ-Dateien löschen";
                    gif = "Alle GIF-Dateien löschen";
                    txt = "Alle TXT-Dateien löschen";
                   
                   
                    choices.add(gra);
                    aktiv.add(false);
                    choices.add(tra);
                    aktiv.add(false);
                    choices.add(con);
                    aktiv.add(false);
                    choices.add(koo);
                    aktiv.add(true);
                    choices.add(png);
                    aktiv.add(true);
                    choices.add(tmp);
                    aktiv.add(true);
                    choices.add(dat);
                    aktiv.add(true);
                    choices.add(gz);
                    aktiv.add(false);
                    choices.add(gif);
                    aktiv.add(false);
                    choices.add(txt);
                    aktiv.add(false);
                   
                    CheckboxDialog dia = new CheckboxDialog(
                            this,
                            "Geben Sie an, welche Dateitypen aus"
                                + " dem Verzeichnis '"
                                + this.pars.getStdDirectory()
                                + "' gelöscht werden sollen",
                            "Löschen best�tigen",
                            butts,
                            choices,
                            aktiv);
                   
                    dia.setVisible(true);
                   
                    if (dia.getResult().equals("OK")) {
                        if (dia.getAuswahl().contains(tmp)) {
                            StaticMethods.deleteALL(
                                    eas.startSetup.marbBuilder.ConstantsGraphVis.TEMP_ENDUNG,
                                    this.pars);
                        }
                       
                        if (dia.getAuswahl().contains(con)) {
                            StaticMethods.deleteALL(
                                    eas.startSetup.marbBuilder.ConstantsGraphVis.BED_ENDUNG,
                                    this.pars);
                        }
                       
                        if (dia.getAuswahl().contains(koo)) {
                            StaticMethods.deleteALL(
                                    eas.startSetup.marbBuilder.ConstantsGraphVis.KOORD_ENDUNG,
                                    this.pars);
                        }

                        if (dia.getAuswahl().contains(gra)) {
                            StaticMethods.deleteALL(
                                    eas.startSetup.marbBuilder.ConstantsGraphVis.GRAPH_ENDUNG,
                                    this.pars);
                        }

                        if (dia.getAuswahl().contains(tra)) {
                            StaticMethods.deleteALL(
                                    eas.startSetup.marbBuilder.ConstantsGraphVis.TRANS_ENDUNG,
                                    this.pars);
                        }

                        if (dia.getAuswahl().contains(png)) {
                            StaticMethods.deleteALL(
                                    eas.startSetup.marbBuilder.ConstantsGraphVis.PNG_ENDUNG,
                                    this.pars);
                        }

                        if (dia.getAuswahl().contains(dat)) {
                            StaticMethods.deleteALL(
                                    "dat",
                                    this.pars);
                        }

                        if (dia.getAuswahl().contains(gz)) {
                            StaticMethods.deleteALL(
                                    "gz",
                                    this.pars);
                        }
                       
                        if (dia.getAuswahl().contains(gif)) {
                            StaticMethods.deleteALL(
                                    "gif",
                                    this.pars);
                        }

                        if (dia.getAuswahl().contains(txt)) {
                            StaticMethods.deleteALL(
                                    "txt",
                                    this.pars);
                        }
                    }
                } else if (cmd.equals("Alle speichern")) {
                    this.speichereAlleGraphen(Messages.getString("Vis.All"));
                }
            }
           
            if (grammOk) {
                this.kantenEinstell.setEnabled(false);
                this.beding.setText("");
                this.folgeZust.setText("");
                this.ktAlter.setText("");
               
                for (int i = 0;
                        i < this.aktGrph.getRob().getVAut().length;
                        i++) {
                    this.aktGrph.getRob().getVAut()[i].setSeqVeraendert();
                }
               
                this.aktGrph.neuZeichnen();
            }
        } catch (Exception e) {
            GeneralDialog nachfrage;
            ArrayList<String> buttons = new ArrayList<String>();
            buttons.add(Messages.getString("SteuerFenster.OK"));
            String output = "";
           
            String[] out = new String[e.getStackTrace().length];
            for (int i = 0; i < out.length; i++) {
                out[i] = e.getStackTrace()[i].toString();
                output += "\n  " + out[i];
            }
           
            StaticMethods.log(StaticMethods.LOG_ERROR,
                          output,
                          this.pars);
           
            nachfrage = new GeneralDialog(
                        this,
                        e.toString()
                        + "\n\nZeile: " + e.getStackTrace()[0].getLineNumber()
                        + "\nMethode: " + e.getStackTrace()[0].getMethodName()
                        + "\nKlasse: " + e.getStackTrace()[0].getClassName()
                        + "\nDatei: " + e.getStackTrace()[0].getFileName(),
                        Messages.getString(
                                      "Vis.UnbehFehler")
                        + e.getStackTrace()[0].getClassName(),
                        buttons,
                        null);
            nachfrage.setVisible(true);
            this.aktGrph.getRob().erzeugeAusSequenzen(
                    altSeq,
                    altCond,
                    null,
                    false);
            this.aktGrph.setzeConds(altCond);
        } finally {
            this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
           
            itG = this.graphen.iterator();
            while (itG.hasNext()) {
                itG.next().setCursor(
                                new Cursor(Cursor.DEFAULT_CURSOR));
            }
        }
    }

    /**
     * löscht den angegebenen Graphen aus der Darstellung (und evtl. von der
     * Festplatte). Falls nach dem Löschen kein weiterer Graph existiert,
     * wird ein neuer leerer Graph erzeugt.
     *
     * @param lGraph    Der zu löschende Graph.
     * @param loeschen  Ob der Graph auch von der Festplatte gelöscht werden
     *                  soll.
     */
    public void loescheGraph(final Vis     lGraph,
                             final boolean loeschen) {
        this.graphen.remove(lGraph);
        this.grAuswahl.remove(
                lGraph.getGraphName());
        if (loeschen) {
            lGraph.loescheGraphDateien();
        }
        lGraph.setVisible(false);
        lGraph.dispose();
        this.graphZaehl--;
        if (this.graphZaehl <= 0) {
            Vis graphFenster;
            graphFenster = new Vis(Messages.getString(
                                "SteuerFenster.EA")
                           + eas.startSetup.marbBuilder.ConstantsGraphVis.STD_GRAPH_NAME
                           + 0
                           + "]",
                           eas.startSetup.marbBuilder.ConstantsGraphVis.STD_GRAPH_NAME
                           + 0,
                           this,
                           this.umg,
                           this.seqErk,
                           this.mutArtVerh,
                           this.mutArtTrans,
                           this.rand,
                           this.kleinsteFreieID(),
                           this.pars,
                           this.autAnz,
                           null,
                           this.plugins);
           
            this.grAuswahl.add(
                             eas.startSetup.marbBuilder.ConstantsGraphVis.STD_GRAPH_NAME
                             + 0);
            this.graphen.add(graphFenster);
            this.graphZaehl++;
        }
    }
   
    /**
     * Startet die Simulation.
     *
     * @param evol  Ob evolviert werden soll.
     */
    private void simStarten(final boolean evol) {
        boolean existiert = false;
        this.speichereAlleGraphen(Messages.getString("Alle"));

        // Evolutions-Plugin.
        if (evol) {
            String[] plugs = new String[this.pars.getPlugIDArray().length + 1];
            int i = 0;
            for (i = 0; i < this.pars.getPlugIDArray().length; i++) {
                plugs[i] = this.pars.getPlugIDArray()[i];
                if (plugs[i].equals(new EvolutionPluginCompletelyEvolvable().id())) {
                    existiert = true;
                    break;
                }
            }
            if (!existiert) {
                plugs[plugs.length - 1] = new EvolutionPluginCompletelyEvolvable().id();
                this.pars.setPlugins(plugs);
            }
        }

        // Videoaufnahme-Plugin.
        existiert = false;
        String[] plugs = new String[this.pars.getPlugIDArray().length + 1];
        int i = 0;
        for (i = 0; i < this.pars.getPlugIDArray().length; i++) {
            plugs[i] = this.pars.getPlugIDArray()[i];
            if (plugs[i].equals(new AllroundVideoPlugin().id())) {
                existiert = true;
                break;
            }
        }
        if (!existiert) {
            plugs[plugs.length - 1] = new AllroundVideoPlugin().id();
            this.pars.setPlugins(plugs);
            this.pars.setParValue(AllroundVideoPlugin.LIVE_FILM_PAR, true);
        }
       
        this.pars.complete();
       
        for (Vis v : this.graphen) {
            v.dispose();
        }
        this.dispose();
       
        SimulationStarter.main(this.pars.getAllParsArrayView());
    }
   
    /**
     * Setzt alle Graphen auf den angegebenen Simläuft-Wert.
     *
     * @param wert  Ob gerade eine Simulation läuft.
     */
    public void setzeSimLf(final boolean wert) {
        Iterator<Vis> it = this.graphen.iterator();

        if (wert) {
            StaticMethods.log(StaticMethods.LOG_INFO,
                          "Simulation gestartet.",
                          this.pars);
           
            StaticMethods.deleteALL(
                    eas.startSetup.marbBuilder.ConstantsGraphVis.TEMP_ENDUNG, this.pars);
            StaticMethods.renameALL(eas.startSetup.marbBuilder.ConstantsGraphVis.GRAPH_ENDUNG,
                                eas.startSetup.marbBuilder.ConstantsGraphVis.TEMP_ENDUNG,
                                this.pars);
        } else {
            StaticMethods.log(StaticMethods.LOG_INFO,
                          "Simulation beendet.",
                          this.pars);
           
            StaticMethods.deleteALL(
                    eas.startSetup.marbBuilder.ConstantsGraphVis.GRAPH_ENDUNG, this.pars);
            StaticMethods.renameALL(eas.startSetup.marbBuilder.ConstantsGraphVis.TEMP_ENDUNG,
                                eas.startSetup.marbBuilder.ConstantsGraphVis.GRAPH_ENDUNG,
                                this.pars);
            StaticMethods.deleteALL(
                    eas.startSetup.marbBuilder.ConstantsGraphVis.TEMP_ENDUNG, this.pars);
        }
      
        while (it.hasNext()) {
            it.next().setSimLaueft(wert);
        }
    }

    /**
     * Erzeugt einen neuen Graphen mit dem ersten freien Standardnamen.
     *
     * @return Der neue Graph.
     */
    public Vis neuerGraph() {
        String graphName = "";
        int graphNummer = 0;
        Vis graphFenster;
        boolean ok = false;

        while (!ok) {
            graphName = "graph" + graphNummer;
            Iterator<Vis> it = this.graphen.iterator();
            ok = true;
            while (it.hasNext()) {
                if (it.next().toString().equals(graphName)) {
                    ok = false;
                }
            }
            graphNummer++;
        }

        graphFenster = new Vis(
                Messages.getString("SteuerFenster.EA")
                    + graphName + "]",
                graphName,
                this,
                this.umg,
                this.seqErk,
                this.mutArtVerh,
                this.mutArtTrans,
                this.rand,
                this.kleinsteFreieID(),
                this.pars,
                this.autAnz,
                null,
                this.plugins);

        this.grAuswahl.add(graphName);
        this.graphen.add(graphFenster);
        this.graphZaehl++;
       
        return graphFenster;
    }

    /**
     * Speichert alle Graphen in der Liste <code>this.graphen</code>.
     *
     * @param anfAnw  Die Anweisung, die beim ersten speichern an die
     *                Speichermethode übergeben wird.
     *
     * @return Ob nach dem Speichern beendet werden soll.
     */
    public boolean speichereAlleGraphen(final String anfAnw) {
        Vis aktgr = this.aktGrph;
        Iterator<Vis> it = this.graphen.iterator();
        Iterator<Vis> it2;
        Vis aktGr;
        String anweisung = anfAnw;

        while (it.hasNext()) {
            it2 = this.graphen.iterator();
            while (it2.hasNext()) {
                it2.next().setVisible(false);
            }
            aktGr = it.next();
            if (!anweisung.equals(Messages.getString("Vis.All"))
                && !anweisung.equals(Messages.getString("Vis.None"))) {
                aktGr.setVisible(true);
            }

            if (anweisung.equals(Messages.getString("Vis.Cancel"))) {
                this.selGraph(aktgr);
                return false;
            }

            anweisung = aktGr.speichereGraph(anweisung);
        }
        if (anweisung.equals(Messages.getString("Vis.Cancel"))) {
            this.selGraph(aktgr);
            return false;
        } else {
            return true;
        }
    }

    /**
     * Aktuellen Graphen setzen.
     *
     * @param aktGr The aktGraph to set.
     */
    public void setAktGraph(final Vis aktGr) {
        this.aktGrph = aktGr;
    }

    /**
     * Selektiert das angegebene Graphfenster (macht es sichtbar, etc).
     *
     * @param graph  Das zu selektierende Graphfenster.
     */
    public void selGraph(final Vis graph) {
        int i = 0;

        while (this.graphen.get(i) != graph) {
            i++;
        }

        this.waehleGraph(i);
        this.selKn(this.aktGrph.getAktSelKnot());
        this.aktGrph.neuZeichnen();
    }

    /**
     * Setzt <code>this</code> auf "sichtbar".
     */
    public void setzeSichtbar() {
        this.ktList.add(
        "                                                               ");
        this.setVisible(true);
        this.aktGrph.selKnoten(this.aktGrph.getAktSelKnot(), 0);
    }

    /**
     * Gibt die kleinste noch nicht von einem der aktuellen Graphen verwendete
     * ID zurück.
     *
     * @return  Die kleinste noch nicht verwendete ID.
     */
    public int kleinsteFreieID() {
        int kleinste = 0;
        Iterator<Vis> it = this.graphen.iterator();
        Vis aktGr;
       
        while (it.hasNext()) {
            aktGr = it.next();
            if (kleinste <= aktGr.getRob().id()) {
                kleinste = aktGr.getRob().id() + 1;
            }
        }
       
        return kleinste;
    }

    /**
     * Zeichnet alle Vis-Fenster neu.
     */
    public void repaintAll() {
        Iterator<Vis> it = this.graphen.iterator();
        while (it.hasNext()) {
            it.next().neuZeichnen();
        }
    }
   
    /**
     * Die Startmethode des Frames.
     *
     * @param args  Die Parameter für das Parameterobjekt. Sie werden direkt
     *              an die Klasse Parametersatz weitergegeben. Zur Formatierung
     *              der Parameter siehe diese Klasse sowie die Klasse
     *              Konstanten der Pakets statistik.
     */
    public static void main(final String[] args) {
        ParCollection pr = GlobalVariables.getPrematureParameters();
        pr.overwriteParameterList(args);

        // Info-Datei schreiben:
        /*
        StatMeth.schreibeInfoDatei(pr);
        */
       
        SteuerFenster steuer = new SteuerFenster(pr);
        StaticMethods.log(
                StaticMethods.LOG_DEBUG,
                "\n" + pr.toString(),
                pr,
                "plain",
                null);
        steuer.ktList.removeAll();
    }
}
TOP

Related Classes of eas.startSetup.marbBuilder.SteuerFenster

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.