Package gui

Source Code of gui.EasyBotApp

package gui;

import gui.dialogs.CreateNeuralNet;
import gui.dialogs.NewSimulationDialog;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;

import javax.media.CaptureDeviceManager;

import org.apache.commons.io.FileUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

import resources.PropertiesLoader;
import resources.digesters.ClassManager;
import resources.digesters.Plugin;
import utils.ErrorMessage;
import utils.defines.Defines;
import utils.images.ImageUtils;
import utils.logging.Logger;
import utils.logging.LoggerException;

import com.cloudgarden.resource.SWTResourceManager;

import components.commchannel.serial.frontcam.serialPort;
import components.gps.GPS;
import components.gps.RecognizedItems;
import components.gps.imagebased.ImageBasedGPS;
import components.imagecollector.webcam.WebcamImageCollector;
import components.neuralnetwork.ExternalNeuralNetwork;
import components.neuralnetwork.NeuralNetworkException;
import components.robot.Robot;
import components.robot.RobotGUI;

import core.simulation.Simulation;
import core.simulation.SimulationException;

/**
* <code>EasyBotApp</code> es la clase aplicaci�n, a partir de la cual se
* lanza todo el sistema. Tiene la responsabilidad de inicializar y recrear la
* interfaz gr�fica de usuario (GUI). <br>
* <br>
*
* Esta clase no puede ser extendida.
*/
public final class EasyBotApp extends Composite implements Observer {

  // TODO: renombrar los atributos, usando nombres representativos
  private Composite composite2;

  private Composite customRobotStatus;

  private Composite composite12;

  private Composite composite5;

  private Composite composite4;

  private Composite composite11;

  private Composite rigthTopPannel;

  private Composite propertiesPannel;

  private Composite composite10;

  private Composite leftBottonPannel;

  private Composite leftTopPannel;

  private Composite leftMiddlePannel;

  private Composite composite9;

  private Composite composite8;

  private Composite composite7;

  private Composite composite6;

  private Composite rightBottonPannel;

  private Composite simulationPanel;

  private Composite composite3;

  private Composite robotStatus;

  private Label label7;

  private Label label6;

  private Label label24;

  private Label label22;

  private Label label8;

  private CLabel cSpeedTitle;

  private Label label23;

  private CLabel cLabel4;

  private TableColumn simulationTableColumnDescription;

  private TableColumn neuronalNetTableColumnDescription;

  private Label label21;

  private ToolBar toolBar4;

  private Label label20;

  private CLabel cLabel3;

  private Label label19;

  private Label label18;

  private Label label17;

  private Label label16;

  private Label label15;

  private Label label14;

  private Label label13;

  private Label label12;

  private Label label11;

  private Label label9;

  private SashForm sashForm3;

  private Label label5;

  private Label label4;

  private Label label3;

  private Label label2;

  private CLabel cLabel2;

  private CLabel cLabel1;

  private SashForm sashForm2;

  private SashForm sashForm1;

  private Label label1;

  private Canvas sceneCanvas;

  private Image background;

  private GC backgroundGC;

  private DecimalFormat formatter;

  private RecognizedItems mazeItems;

  private Image swtImage;

  private SimulationBase simulationBase;

  private NeuralNetworkBase neuralNetworksBase;

  private boolean getStatusPanel;

  private Button displayRealView;

  private Button displaySchematicView;

  private Composite simulationTableComposite;

  private Table simulationTable;

  private TableColumn simulationTableColumnPath;

  private TableColumn simulationTableColumnDuration;

  private TableColumn simulationTableColumnName;

  private Composite neuronalNetTableComposite;

  private Table neuronalNetTable;

  private TableColumn neuronalNetTableColumnPath;

  private TableColumn neuronalNetTableColumnName;

  private TableColumn neuronalNetTableColumnType;

  private TableColumn neuronalNetTableColumnSelected;

  // �rbol de componentes.
  private Tree worldTree;

  private TreeItem rootItem;

  // Controlores de simulaci�n/reproducci�n.
  private ToolBar playControls;

  private ToolItem playButton;

  private ToolItem pauseButton;

  private ToolItem stopButton;

  private ToolItem recButton;

  private Scale speedControl;

  private Button speedReset;

  private Label speedLabel;

  private ToolItem newSimulationButton;

  private ToolItem loadSimulationButton;

  private ToolItem deleteSimulationButton;

  private ToolItem newNeuronalNetButton;

  private ToolItem loadNeuronalNetButton;

  private ToolItem deleteNeuronalNetButton;

  private static EasyBotApp inst;

  private ExternalNeuralNetwork externalNN;

  {

    // Register as a resource user - SWTResourceManager will
    // handle the obtaining and disposing of resources
    SWTResourceManager.registerResourceUser(this);
  }

  /**
   * Construye la interfaz gr�fica de usuario (GUI) principal.
   *
   * @param parent
   *            composite padre.
   * @param style
   *            estilo.
   * @throws EasyBotAppException
   */
  public EasyBotApp(Composite parent, int style) throws EasyBotAppException {
    super(parent, style);

    try {
      Logger.init();
      Logger.info("******** COMENZANDO LOGUEO ********");
    } catch (LoggerException e) {
      ErrorMessage.customMessage("Error inicializando el logger: "
          + e.getMessage(), ErrorMessage.ERROR_MESSAGE, parent);
      throw new EasyBotAppException("Error inicializando el logger: "
          + e.getMessage());
    }

    background = new org.eclipse.swt.graphics.Image(Display.getDefault(),
        Defines.DEFAULT_IMAGE_RESOLUTION[0],
        Defines.DEFAULT_IMAGE_RESOLUTION[1]);
    backgroundGC = new GC(background);
    formatter = new DecimalFormat("##0");
    swtImage = null;
    getStatusPanel = true;
    externalNN = new ExternalNeuralNetwork();
    inst = this;

    try {
      simulationBase = new SimulationBase(PropertiesLoader.getInstance()
          .getProperty("SimulationBaseFile"));
    } catch (SimulationException e) {
      throw new EasyBotAppException(e.getMessage());
    }

    try {
      neuralNetworksBase = new NeuralNetworkBase(PropertiesLoader
          .getInstance().getProperty("NeuralNetworkBaseFile"));
    } catch (NeuralNetworkException e) {
      throw new EasyBotAppException(e.getMessage());
    }

    initGUI();
  }

  /**
   * Este m�todo inicializa la interfaz gr�fica de usuario (GUI). Es invocado
   * por el constructor.
   */
  private void initGUI() {
    try {
      this.setSize(1024, 768);
      this.setBackground(SWTResourceManager.getColor(192, 192, 192));
      GridLayout thisLayout = new GridLayout();
      thisLayout.makeColumnsEqualWidth = true;
      thisLayout.horizontalSpacing = 0;
      thisLayout.marginWidth = 0;
      thisLayout.marginHeight = 0;
      thisLayout.verticalSpacing = 0;
      this.setLayout(thisLayout);
      this.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_ARROW));
      getShell().addShellListener(new ShellAdapter() {
        public void shellClosed(ShellEvent evt) {
          dispose();
        }
      });

      this.addListener(SWT.Dispose, new Listener() {
        public void handleEvent(Event evt) {
          // Este "handler" se invoca cuando se liberan
          // los recursos de la ventana principal.
          // applicationDisposed(evt);
        }
      });

      {
        label1 = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
        GridData label1LData = new GridData();
        label1LData.horizontalAlignment = GridData.FILL;
        label1LData.grabExcessHorizontalSpace = true;
        label1.setLayoutData(label1LData);
        label1.setText("label1");
      }
      {
        composite2 = new Composite(this, SWT.NONE);
        GridLayout composite2Layout = new GridLayout();
        composite2Layout.makeColumnsEqualWidth = true;
        GridData composite2LData = new GridData(SWT.FILL, SWT.FILL,
            true, true);
        composite2LData.widthHint = 697;
        composite2.setLayoutData(composite2LData);
        composite2.setLayout(composite2Layout);
        {
          sashForm1 = new SashForm(composite2, SWT.HORIZONTAL
              | SWT.H_SCROLL);
          GridLayout sashForm1Layout = new GridLayout();
          sashForm1Layout.horizontalSpacing = 2;
          sashForm1Layout.marginHeight = 0;
          sashForm1Layout.marginWidth = 1;
          sashForm1Layout.verticalSpacing = 1;
          sashForm1Layout.numColumns = 2;
          sashForm1.setLayout(sashForm1Layout);
          GridData sashForm1LData = new GridData();
          sashForm1LData.grabExcessHorizontalSpace = true;
          sashForm1LData.grabExcessVerticalSpace = true;
          sashForm1LData.horizontalAlignment = GridData.FILL;
          sashForm1LData.verticalAlignment = GridData.FILL;
          sashForm1.setLayoutData(sashForm1LData);
          sashForm1.setSize(60, 30);
          sashForm1.setCursor(SWTResourceManager
              .getCursor(SWT.CURSOR_ARROW));
          {
            composite3 = new Composite(sashForm1, SWT.NONE);
            GridLayout composite3Layout = new GridLayout();
            composite3Layout.horizontalSpacing = 0;
            composite3Layout.marginHeight = 0;
            composite3Layout.marginWidth = 0;
            composite3Layout.verticalSpacing = 0;
            GridData composite3LData = new GridData();
            composite3LData.grabExcessHorizontalSpace = true;
            composite3LData.grabExcessVerticalSpace = true;
            composite3.setLayoutData(composite3LData);
            composite3.setLayout(composite3Layout);
            {
              sashForm3 = new SashForm(composite3, SWT.NONE);
              GridLayout sashForm3Layout = new GridLayout();
              sashForm3Layout.horizontalSpacing = 0;
              sashForm3Layout.marginHeight = 0;
              sashForm3Layout.marginWidth = 0;
              sashForm3Layout.verticalSpacing = 0;
              sashForm3.setLayout(sashForm3Layout);
              GridData sashForm3LData = new GridData();
              sashForm3LData.horizontalAlignment = GridData.FILL;
              sashForm3LData.verticalAlignment = GridData.FILL;
              sashForm3LData.grabExcessHorizontalSpace = true;
              sashForm3LData.grabExcessVerticalSpace = true;
              sashForm3.setLayoutData(sashForm3LData);
              sashForm3.setSize(60, 30);
              sashForm3.setOrientation(SWT.VERTICAL);
              {
                leftTopPannel = new Composite(sashForm3,
                    SWT.NONE);
                GridLayout composite4Layout = new GridLayout();
                composite4Layout.numColumns = 3;
                composite4Layout.horizontalSpacing = 0;
                composite4Layout.marginHeight = 0;
                composite4Layout.marginWidth = 0;
                composite4Layout.verticalSpacing = 0;
                GridData composite4LData = new GridData();
                composite4LData.horizontalSpan = 0;
                leftTopPannel.setLayoutData(composite4LData);
                leftTopPannel.setLayout(composite4Layout);
                {
                  label17 = new Label(leftTopPannel,
                      SWT.SEPARATOR);
                  GridData label17LData = new GridData();
                  label17LData.verticalAlignment = GridData.FILL;
                  label17LData.grabExcessVerticalSpace = true;
                  label17.setLayoutData(label17LData);
                  label17.setText("label17");
                }
                {
                  composite10 = new Composite(leftTopPannel,
                      SWT.NONE);
                  GridLayout composite10Layout = new GridLayout();
                  composite10Layout.makeColumnsEqualWidth = true;
                  composite10Layout.horizontalSpacing = 0;
                  composite10Layout.marginHeight = 0;
                  composite10Layout.marginWidth = 0;
                  composite10Layout.verticalSpacing = 0;
                  GridData composite10LData = new GridData();
                  composite10LData.horizontalAlignment = GridData.FILL;
                  composite10LData.verticalAlignment = GridData.FILL;
                  composite10LData.grabExcessHorizontalSpace = true;
                  composite10LData.grabExcessVerticalSpace = true;
                  composite10LData.verticalSpan = 0;
                  composite10.setLayoutData(composite10LData);
                  composite10.setLayout(composite10Layout);
                  {
                    label16 = new Label(composite10,
                        SWT.SEPARATOR | SWT.HORIZONTAL);
                    GridData label16LData = new GridData();
                    label16LData.grabExcessHorizontalSpace = true;
                    label16LData.horizontalAlignment = GridData.FILL;
                    label16LData.horizontalSpan = 0;
                    label16.setLayoutData(label16LData);
                    label16.setText("label16");
                  }
                  {
                    composite11 = new Composite(
                        composite10, SWT.NONE);
                    GridLayout composite11Layout = new GridLayout();
                    composite11Layout.horizontalSpacing = 0;
                    composite11Layout.marginHeight = 0;
                    composite11Layout.marginWidth = 0;
                    composite11Layout.verticalSpacing = 0;
                    GridData composite11LData = new GridData();
                    composite11LData.verticalAlignment = GridData.FILL;
                    composite11LData.horizontalAlignment = GridData.FILL;
                    composite11LData.grabExcessHorizontalSpace = true;
                    composite11LData.grabExcessVerticalSpace = true;
                    composite11
                        .setLayoutData(composite11LData);
                    composite11
                        .setLayout(composite11Layout);
                    {
                      composite12 = new Composite(
                          composite11, SWT.NONE);
                      FillLayout composite12Layout1 = new FillLayout(
                          org.eclipse.swt.SWT.HORIZONTAL);
                      composite12
                          .setLayout(composite12Layout1);
                      GridData composite12LData1 = new GridData();
                      composite12
                          .setLayoutData(composite12LData1);
                      composite12
                          .setFont(SWTResourceManager
                              .getFont("Tahoma",
                                  8, 1,
                                  false,
                                  false));
                      {
                        cLabel4 = new CLabel(
                            composite12,
                            SWT.SHADOW_NONE);
                        cLabel4
                            .setFont(SWTResourceManager
                                .getFont(
                                    "Tahoma",
                                    9, 1,
                                    false,
                                    false));
                        cLabel4
                            .setText("Explorador de Componentes");
                        cLabel4
                            .setImage(SWTResourceManager
                                .getImage("resources/icons/icon32x32/enable/draw.png"));
                        cLabel4
                            .setForeground(SWTResourceManager
                                .getColor(91,
                                    91, 91));
                      }
                    }
                    {
                      label23 = new Label(composite11,
                          SWT.SEPARATOR
                              | SWT.HORIZONTAL);
                      label23.setText("label21");
                      GridData label23LData = new GridData();
                      label23LData.horizontalAlignment = GridData.FILL;
                      label23LData.grabExcessHorizontalSpace = true;
                      label23.setLayoutData(label23LData);
                    }
                    {
                      GridData tree1LData = new GridData();
                      tree1LData.verticalAlignment = GridData.FILL;
                      tree1LData.horizontalAlignment = GridData.FILL;
                      tree1LData.grabExcessVerticalSpace = true;
                      tree1LData.grabExcessHorizontalSpace = true;
                      worldTree = new Tree(composite11,
                          SWT.NONE);
                      worldTree.setLayoutData(tree1LData);
                      worldTree
                          .addSelectionListener(new SelectionAdapter() {
                            public void widgetSelected(
                                SelectionEvent evt) {
                              worldTreeWidgetSelected(evt);
                            }
                          });
                      {
                        rootItem = new TreeItem(
                            worldTree, SWT.NONE);
                        rootItem.setText("World");
                        rootItem
                            .setImage(SWTResourceManager
                                .getImage("resources/icons/icon24x24/enable/earth.png"));
                      }
                    }
                  }
                  {
                    label15 = new Label(composite10,
                        SWT.SEPARATOR | SWT.HORIZONTAL);
                    GridData label15LData = new GridData();
                    label15LData.grabExcessHorizontalSpace = true;
                    label15LData.horizontalAlignment = GridData.FILL;
                    label15.setLayoutData(label15LData);
                    label15.setText("label15");
                  }
                }
                {
                  label9 = new Label(leftTopPannel,
                      SWT.SEPARATOR | SWT.VERTICAL);
                  GridData label9LData = new GridData(
                      SWT.RIGHT, SWT.FILL, false, true);
                  label9.setLayoutData(label9LData);
                  label9.setText("label9");
                }
              }
              {
                leftMiddlePannel = new Composite(sashForm3,
                    SWT.NONE);
                GridLayout composite1Layout = new GridLayout();
                composite1Layout.numColumns = 3;
                composite1Layout.verticalSpacing = 0;
                composite1Layout.marginWidth = 0;
                composite1Layout.marginHeight = 0;
                composite1Layout.horizontalSpacing = 0;
                leftMiddlePannel.setLayout(composite1Layout);
                leftMiddlePannel.setSize(505, 100);
                {
                  label19 = new Label(leftMiddlePannel,
                      SWT.SEPARATOR | SWT.VERTICAL);
                  GridData label19LData = new GridData();
                  label19LData.grabExcessVerticalSpace = true;
                  label19LData.verticalAlignment = GridData.FILL;
                  label19.setLayoutData(label19LData);
                  label19.setText("label19");
                }
                {
                  neuronalNetTableComposite = new Composite(
                      leftMiddlePannel, SWT.NONE);
                  GridLayout composite12Layout = new GridLayout();
                  composite12Layout.makeColumnsEqualWidth = true;
                  composite12Layout.horizontalSpacing = 0;
                  composite12Layout.marginHeight = 0;
                  composite12Layout.marginWidth = 0;
                  composite12Layout.verticalSpacing = 0;
                  GridData composite12LData = new GridData(
                      SWT.FILL, SWT.TOP, true, false);
                  composite12LData.heightHint = 200;
                  neuronalNetTableComposite
                      .setLayoutData(composite12LData);
                  neuronalNetTableComposite
                      .setLayout(composite12Layout);
                  {
                    label20 = new Label(
                        neuronalNetTableComposite,
                        SWT.SEPARATOR | SWT.HORIZONTAL);
                    GridData label20LData = new GridData();
                    label20LData.grabExcessHorizontalSpace = true;
                    label20LData.horizontalAlignment = GridData.FILL;
                    label20.setLayoutData(label20LData);
                    label20.setText("label20");
                  }
                  {
                    composite5 = new Composite(
                        neuronalNetTableComposite,
                        SWT.NONE);
                    FillLayout composite5Layout1 = new FillLayout(
                        org.eclipse.swt.SWT.HORIZONTAL);
                    composite5.setLayout(composite5Layout1);
                    GridData composite5LData1 = new GridData();
                    composite5
                        .setLayoutData(composite5LData1);
                    composite5.setFont(SWTResourceManager
                        .getFont("Tahoma", 8, 1, false,
                            false));
                    {
                      cLabel3 = new CLabel(composite5,
                          SWT.SHADOW_NONE);
                      cLabel3.setFont(SWTResourceManager
                          .getFont("Tahoma", 9, 1,
                              false, false));
                      cLabel3.setText("Redes neuronales");
                      cLabel3
                          .setImage(SWTResourceManager
                              .getImage("resources/icons/icon32x32/enable/neuron.png"));
                      cLabel3
                          .setForeground(SWTResourceManager
                              .getColor(91, 91,
                                  91));
                    }
                  }
                  {
                    label21 = new Label(
                        neuronalNetTableComposite,
                        SWT.SEPARATOR | SWT.HORIZONTAL);
                    GridData label21LData = new GridData();
                    label21LData.grabExcessHorizontalSpace = true;
                    label21LData.horizontalAlignment = GridData.FILL;
                    label21.setLayoutData(label21LData);
                    label21.setText("label21");
                  }
                  {
                    GridData toolBar4LData = new GridData();
                    toolBar4LData.grabExcessHorizontalSpace = true;
                    toolBar4LData.horizontalAlignment = GridData.FILL;
                    toolBar4LData.verticalAlignment = GridData.FILL;
                    toolBar4 = new ToolBar(
                        neuronalNetTableComposite,
                        SWT.FLAT);
                    toolBar4.setLayoutData(toolBar4LData);
                    {
                      newNeuronalNetButton = new ToolItem(
                          toolBar4, SWT.NONE);
                      newNeuronalNetButton
                          .setImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/enable/db-create.png"));
                      newNeuronalNetButton
                          .setToolTipText("Crear red");
                      newNeuronalNetButton
                          .setEnabled(true);
                      newNeuronalNetButton
                          .addSelectionListener(new SelectionAdapter() {
                            public void widgetSelected(
                                SelectionEvent evt) {
                              newNeuronalNetWidgetSelected(evt);
                            }
                          });
                    }
                    {
                      loadNeuronalNetButton = new ToolItem(
                          toolBar4, SWT.NONE);
                      loadNeuronalNetButton
                          .setImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/enable/db-add.png"));
                      loadNeuronalNetButton
                          .setDisabledImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/disable/db-add-des.png"));
                      loadNeuronalNetButton
                          .setToolTipText("Agregar red");
                      loadNeuronalNetButton
                          .setEnabled(true);
                      loadNeuronalNetButton
                          .addSelectionListener(new SelectionAdapter() {
                            public void widgetSelected(
                                SelectionEvent evt) {
                              loadNeuronalNetWidgetSelected(evt);
                            }
                          });
                    }
                    {
                      deleteNeuronalNetButton = new ToolItem(
                          toolBar4, SWT.NONE);
                      deleteNeuronalNetButton
                          .setImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/enable/db-remove.png"));
                      deleteNeuronalNetButton
                          .setToolTipText("Eliminar Red");
                      deleteNeuronalNetButton
                          .setDisabledImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/disable/db-remove-des.png"));
                      deleteNeuronalNetButton
                          .setEnabled(false);
                      deleteNeuronalNetButton
                          .addSelectionListener(new SelectionAdapter() {
                            public void widgetSelected(
                                SelectionEvent evt) {
                              deleteNeuronalNetWidgetSelected(evt);
                            }
                          });
                    }
                  }
                  {
                    label13 = new Label(
                        neuronalNetTableComposite,
                        SWT.SEPARATOR | SWT.HORIZONTAL);
                    GridData label13LData = new GridData();
                    label13LData.grabExcessHorizontalSpace = true;
                    label13LData.horizontalAlignment = GridData.FILL;
                    label13.setLayoutData(label13LData);
                    label13.setText("label13");
                  }
                  {
                    composite4 = new Composite(
                        neuronalNetTableComposite,
                        SWT.NONE);
                    GridLayout composite4Layout = new GridLayout();
                    composite4Layout.makeColumnsEqualWidth = true;
                    GridData composite4LData = new GridData();
                    composite4LData.verticalAlignment = GridData.FILL;
                    composite4LData.horizontalAlignment = GridData.FILL;
                    composite4LData.grabExcessHorizontalSpace = true;
                    composite4LData.grabExcessVerticalSpace = true;
                    composite4
                        .setLayoutData(composite4LData);
                    composite4.setLayout(composite4Layout);
                    {
                      GridData Table1LData = new GridData();
                      Table1LData.grabExcessVerticalSpace = true;
                      Table1LData.horizontalAlignment = GridData.FILL;
                      Table1LData.verticalAlignment = GridData.FILL;
                      Table1LData.grabExcessHorizontalSpace = true;
                      neuronalNetTable = new Table(
                          composite4,
                          SWT.SINGLE
                              | SWT.FULL_SELECTION
                              | SWT.EMBEDDED);
                      neuronalNetTable
                          .setLayoutData(Table1LData);
                      neuronalNetTable
                          .setLinesVisible(true);
                      neuronalNetTable
                          .setHeaderVisible(true);
                      neuronalNetTable.setItemCount(0);
                      neuronalNetTable
                          .setLayoutDeferred(true);
                      neuronalNetTable
                          .addSelectionListener(new SelectionAdapter() {
                            public void widgetSelected(
                                SelectionEvent evt) {
                              neuronalNetWidgetSelected(evt);
                            }
                          });
                      neuronalNetTable.addListener(
                          SWT.MouseDoubleClick,
                          new Listener() {
                            public void handleEvent(
                                Event event) {
                              if (neuronalNetTable
                                  .getSelectionIndex() != -1) {
                                selectNeuronalNet(neuronalNetTable
                                    .getSelectionIndex());
                              }
                            }
                          });

                      {
                        neuronalNetTableColumnName = new TableColumn(
                            neuronalNetTable,
                            SWT.NONE);
                        neuronalNetTableColumnName
                            .setText("Nombre");
                        neuronalNetTableColumnName
                            .setWidth(130);
                      }
                      {
                        neuronalNetTableColumnPath = new TableColumn(
                            neuronalNetTable,
                            SWT.NONE);
                        neuronalNetTableColumnPath
                            .setText("Ruta");
                        neuronalNetTableColumnPath
                            .setWidth(169);
                      }
                      {
                        neuronalNetTableColumnDescription = new TableColumn(
                            neuronalNetTable,
                            SWT.NONE);
                        neuronalNetTableColumnDescription
                            .setText("Descripci�n");
                        neuronalNetTableColumnDescription
                            .setWidth(106);
                      }
                      {
                        neuronalNetTableColumnType = new TableColumn(
                            neuronalNetTable,
                            SWT.NONE);
                        neuronalNetTableColumnType
                            .setText("Tipo");
                        neuronalNetTableColumnType
                            .setWidth(106);
                      }
                      {
                        neuronalNetTableColumnSelected = new TableColumn(
                            neuronalNetTable,
                            SWT.NONE);
                        neuronalNetTableColumnSelected
                            .setText("Seleccionada");
                        neuronalNetTableColumnSelected
                            .setWidth(106);
                      }
                    }
                  }
                  {
                    label18 = new Label(
                        neuronalNetTableComposite,
                        SWT.SEPARATOR | SWT.HORIZONTAL);
                    GridData label18LData = new GridData();
                    label18LData.grabExcessHorizontalSpace = true;
                    label18LData.horizontalAlignment = GridData.FILL;
                    label18.setLayoutData(label18LData);
                    label18.setText("label18");
                  }
                }
                {
                  label12 = new Label(leftMiddlePannel,
                      SWT.SEPARATOR | SWT.VERTICAL);
                  GridData label12LData = new GridData();
                  label12LData.grabExcessVerticalSpace = true;
                  label12LData.verticalAlignment = GridData.FILL;
                  label12.setLayoutData(label12LData);
                  label12.setText("label12");
                }
              }
              {
                leftBottonPannel = new Composite(sashForm3,
                    SWT.NONE);
                GridLayout composite5Layout = new GridLayout();
                composite5Layout.numColumns = 3;
                composite5Layout.verticalSpacing = 0;
                composite5Layout.marginWidth = 0;
                composite5Layout.marginHeight = 0;
                composite5Layout.horizontalSpacing = 0;
                leftBottonPannel.setLayout(composite5Layout);
                leftBottonPannel.setSize(505, 200);
                {
                  label19 = new Label(leftBottonPannel,
                      SWT.SEPARATOR | SWT.VERTICAL);
                  GridData label19LData = new GridData();
                  label19LData.grabExcessVerticalSpace = true;
                  label19LData.verticalAlignment = GridData.FILL;
                  label19.setLayoutData(label19LData);
                  label19.setText("label19");
                }
                {
                  simulationTableComposite = new Composite(
                      leftBottonPannel, SWT.NONE);
                  GridLayout composite12Layout = new GridLayout();
                  composite12Layout.makeColumnsEqualWidth = true;
                  composite12Layout.horizontalSpacing = 0;
                  composite12Layout.marginHeight = 0;
                  composite12Layout.marginWidth = 0;
                  composite12Layout.verticalSpacing = 0;
                  GridData composite12LData = new GridData(
                      SWT.FILL, SWT.TOP, true, false);
                  simulationTableComposite
                      .setLayoutData(composite12LData);
                  simulationTableComposite
                      .setLayout(composite12Layout);
                  {
                    label20 = new Label(
                        simulationTableComposite,
                        SWT.SEPARATOR | SWT.HORIZONTAL);
                    GridData label20LData = new GridData();
                    label20LData.grabExcessHorizontalSpace = true;
                    label20LData.horizontalAlignment = GridData.FILL;
                    label20.setLayoutData(label20LData);
                    label20.setText("label20");
                  }
                  {
                    composite5 = new Composite(
                        simulationTableComposite,
                        SWT.NONE);
                    FillLayout composite5Layout1 = new FillLayout(
                        org.eclipse.swt.SWT.HORIZONTAL);
                    composite5.setLayout(composite5Layout1);
                    GridData composite5LData1 = new GridData();
                    composite5
                        .setLayoutData(composite5LData1);
                    composite5.setFont(SWTResourceManager
                        .getFont("Tahoma", 8, 1, false,
                            false));
                    {
                      cLabel3 = new CLabel(composite5,
                          SWT.SHADOW_NONE);
                      cLabel3.setFont(SWTResourceManager
                          .getFont("Tahoma", 9, 1,
                              false, false));
                      cLabel3.setText("Simulaciones");
                      cLabel3
                          .setImage(SWTResourceManager
                              .getImage("resources/icons/icon32x32/enable/iCandy_Junior-060.png"));
                      cLabel3
                          .setForeground(SWTResourceManager
                              .getColor(91, 91,
                                  91));
                    }
                  }
                  {
                    label21 = new Label(
                        simulationTableComposite,
                        SWT.SEPARATOR | SWT.HORIZONTAL);
                    GridData label21LData = new GridData();
                    label21LData.grabExcessHorizontalSpace = true;
                    label21LData.horizontalAlignment = GridData.FILL;
                    label21.setLayoutData(label21LData);
                    label21.setText("label21");
                  }
                  {
                    GridData toolBar4LData = new GridData();
                    toolBar4LData.grabExcessHorizontalSpace = true;
                    toolBar4LData.horizontalAlignment = GridData.FILL;
                    toolBar4LData.verticalAlignment = GridData.FILL;
                    toolBar4 = new ToolBar(
                        simulationTableComposite,
                        SWT.FLAT);
                    toolBar4.setLayoutData(toolBar4LData);
                    {
                      newSimulationButton = new ToolItem(
                          toolBar4, SWT.NONE);
                      newSimulationButton
                          .setImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/enable/db-add.png"));
                      newSimulationButton
                          .setDisabledImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/disable/db-add-des.png"));
                      newSimulationButton
                          .setToolTipText("Nueva Simulaci�n");
                      newSimulationButton
                          .addSelectionListener(new SelectionAdapter() {
                            public void widgetSelected(
                                SelectionEvent evt) {
                              newSimulationWidgetSelected(evt);
                            }
                          });
                    }
                    {
                      loadSimulationButton = new ToolItem(
                          toolBar4, SWT.NONE);
                      loadSimulationButton
                          .setImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/enable/db-upload.png"));
                      loadSimulationButton
                          .setToolTipText("Cargar Simulaci�n");
                      loadSimulationButton
                          .setEnabled(false);
                      loadSimulationButton
                          .setDisabledImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/disable/db-upload-des.png"));
                      loadSimulationButton
                          .addSelectionListener(new SelectionAdapter() {
                            public void widgetSelected(
                                SelectionEvent evt) {
                              loadSimulationWidgetSelected(evt);
                            }
                          });
                    }
                    {
                      deleteSimulationButton = new ToolItem(
                          toolBar4, SWT.NONE);
                      deleteSimulationButton
                          .setImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/enable/db-remove.png"));
                      deleteSimulationButton
                          .setToolTipText("Eliminar Simulaci�n");
                      deleteSimulationButton
                          .setDisabledImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/disable/db-remove-des.png"));
                      deleteSimulationButton
                          .setEnabled(false);
                      deleteSimulationButton
                          .addSelectionListener(new SelectionAdapter() {
                            public void widgetSelected(
                                SelectionEvent evt) {
                              deleteSimulationWidgetSelected(evt);
                            }
                          });
                    }
                  }
                  {
                    label13 = new Label(
                        simulationTableComposite,
                        SWT.SEPARATOR | SWT.HORIZONTAL);
                    GridData label13LData = new GridData();
                    label13LData.grabExcessHorizontalSpace = true;
                    label13LData.horizontalAlignment = GridData.FILL;
                    label13.setLayoutData(label13LData);
                    label13.setText("label13");
                  }
                  {
                    composite4 = new Composite(
                        simulationTableComposite,
                        SWT.NONE);
                    GridLayout composite4Layout = new GridLayout();
                    composite4Layout.makeColumnsEqualWidth = true;
                    GridData composite4LData = new GridData();
                    composite4LData.verticalAlignment = GridData.FILL;
                    composite4LData.horizontalAlignment = GridData.FILL;
                    composite4LData.grabExcessHorizontalSpace = true;
                    composite4LData.grabExcessVerticalSpace = true;
                    composite4
                        .setLayoutData(composite4LData);
                    composite4.setLayout(composite4Layout);
                    {
                      GridData Table1LData = new GridData();
                      Table1LData.grabExcessVerticalSpace = true;
                      Table1LData.horizontalAlignment = GridData.FILL;
                      Table1LData.verticalAlignment = GridData.FILL;
                      Table1LData.grabExcessHorizontalSpace = true;
                      simulationTable = new Table(
                          composite4,
                          SWT.SINGLE
                              | SWT.FULL_SELECTION
                              | SWT.EMBEDDED);
                      simulationTable
                          .setLayoutData(Table1LData);
                      simulationTable
                          .setLinesVisible(true);
                      simulationTable
                          .setHeaderVisible(true);
                      simulationTable.setItemCount(2);
                      simulationTable
                          .setLayoutDeferred(true);
                      simulationTable
                          .addSelectionListener(new SelectionAdapter() {
                            public void widgetSelected(
                                SelectionEvent evt) {
                              simulationTableWidgetSelected(evt);
                            }
                          });

                      {
                        simulationTableColumnName = new TableColumn(
                            simulationTable,
                            SWT.NONE);
                        simulationTableColumnName
                            .setText("Nombre");
                        simulationTableColumnName
                            .setWidth(130);
                      }
                      {
                        simulationTableColumnDuration = new TableColumn(
                            simulationTable,
                            SWT.NONE);
                        simulationTableColumnDuration
                            .setText("Duraci�n");
                        simulationTableColumnDuration
                            .setWidth(87);
                      }
                      {
                        simulationTableColumnPath = new TableColumn(
                            simulationTable,
                            SWT.NONE);
                        simulationTableColumnPath
                            .setText("Ruta");
                        simulationTableColumnPath
                            .setWidth(169);
                      }
                      {
                        simulationTableColumnDescription = new TableColumn(
                            simulationTable,
                            SWT.NONE);
                        simulationTableColumnDescription
                            .setText("Descripci�n");
                        simulationTableColumnDescription
                            .setWidth(106);
                      }
                    }
                    {

                    }
                  }
                  {
                    label18 = new Label(
                        simulationTableComposite,
                        SWT.SEPARATOR | SWT.HORIZONTAL);
                    GridData label18LData = new GridData();
                    label18LData.grabExcessHorizontalSpace = true;
                    label18LData.horizontalAlignment = GridData.FILL;
                    label18.setLayoutData(label18LData);
                    label18.setText("label18");
                  }
                }
                {
                  label12 = new Label(leftBottonPannel,
                      SWT.SEPARATOR | SWT.VERTICAL);
                  GridData label12LData = new GridData();
                  label12LData.grabExcessVerticalSpace = true;
                  label12LData.verticalAlignment = GridData.FILL;
                  label12.setLayoutData(label12LData);
                  label12.setText("label12");
                }
              }
            }
          }
          {
            sashForm2 = new SashForm(sashForm1, SWT.VERTICAL
                | SWT.V_SCROLL);
            GridData sashForm2LData = new GridData();
            sashForm2LData.grabExcessVerticalSpace = true;
            sashForm2LData.grabExcessHorizontalSpace = true;
            sashForm2LData.horizontalAlignment = GridData.FILL;
            sashForm2LData.verticalAlignment = GridData.FILL;
            sashForm2.setLayoutData(sashForm2LData);
            {
              rigthTopPannel = new Composite(sashForm2, SWT.NONE);
              GridLayout composite11Layout = new GridLayout();
              composite11Layout.verticalSpacing = 0;
              composite11Layout.marginWidth = 0;
              composite11Layout.marginHeight = 0;
              composite11Layout.horizontalSpacing = 0;
              composite11Layout.numColumns = 3;
              rigthTopPannel.setLayout(composite11Layout);
              {
                label14 = new Label(rigthTopPannel,
                    SWT.SEPARATOR | SWT.VERTICAL);
                GridData label14LData = new GridData();
                label14LData.grabExcessVerticalSpace = true;
                label14LData.verticalAlignment = GridData.FILL;
                label14.setLayoutData(label14LData);
                label14.setText("label14");
              }
              {
                simulationPanel = new Composite(rigthTopPannel,
                    SWT.NONE);
                GridLayout composite4Layout = new GridLayout();
                composite4Layout.horizontalSpacing = 0;
                composite4Layout.marginHeight = 0;
                composite4Layout.verticalSpacing = 0;
                composite4Layout.marginWidth = 0;
                composite4Layout.makeColumnsEqualWidth = true;
                GridData simulationPanelLData = new GridData();
                simulationPanelLData.grabExcessHorizontalSpace = true;
                simulationPanelLData.grabExcessVerticalSpace = true;
                simulationPanelLData.horizontalAlignment = GridData.FILL;
                simulationPanelLData.verticalAlignment = GridData.FILL;
                simulationPanelLData.horizontalSpan = 0;
                simulationPanel
                    .setLayoutData(simulationPanelLData);
                simulationPanel.setLayout(composite4Layout);
                {
                  label7 = new Label(simulationPanel,
                      SWT.SEPARATOR | SWT.HORIZONTAL);
                  GridData label7LData = new GridData();
                  label7LData.grabExcessHorizontalSpace = true;
                  label7LData.horizontalAlignment = GridData.FILL;
                  label7LData.verticalAlignment = GridData.BEGINNING;
                  label7.setLayoutData(label7LData);
                  label7.setText("label7");
                }
                {
                  composite7 = new Composite(simulationPanel,
                      SWT.NONE);
                  GridLayout composite7Layout = new GridLayout();
                  composite7Layout.horizontalSpacing = 0;
                  composite7Layout.marginHeight = 0;
                  composite7Layout.marginWidth = 0;
                  composite7Layout.numColumns = 3;
                  composite7Layout.verticalSpacing = 0;
                  GridData composite7LData = new GridData();
                  composite7LData.grabExcessHorizontalSpace = true;
                  composite7LData.horizontalAlignment = GridData.FILL;
                  composite7.setLayoutData(composite7LData);
                  composite7.setLayout(composite7Layout);
                  {
                    cLabel2 = new CLabel(composite7,
                        SWT.SHADOW_NONE);
                    cLabel2.setFont(SWTResourceManager
                        .getFont("Tahoma", 9, 1, false,
                            false));
                    cLabel2
                        .setText("Vista Representaci�n 2D");
                    cLabel2
                        .setImage(SWTResourceManager
                            .getImage("resources/icons/icon32x32/enable/Toolbar-_Public.png"));
                    cLabel2
                        .setForeground(SWTResourceManager
                            .getColor(91, 91, 91));
                    GridData cLabel2LData = new GridData();
                    cLabel2LData.verticalAlignment = GridData.FILL;
                    cLabel2LData.horizontalAlignment = GridData.FILL;
                    cLabel2LData.grabExcessHorizontalSpace = true;
                    cLabel2LData.grabExcessVerticalSpace = true;
                    cLabel2.setLayoutData(cLabel2LData);

                  }
                  {
                    displaySchematicView = new Button(
                        composite7, SWT.RADIO
                            | SWT.LEFT);
                    displaySchematicView
                        .setText("Vista Esquematica");
                    displaySchematicView.setSelection(true);
                    displaySchematicView.setEnabled(false);
                  }
                  {
                    displayRealView = new Button(
                        composite7, SWT.RADIO
                            | SWT.LEFT);
                    displayRealView.setText("Vista Real");
                    displayRealView.setSelection(false);
                    displayRealView.setEnabled(false);
                  }
                }
                {
                  label6 = new Label(simulationPanel,
                      SWT.SEPARATOR | SWT.HORIZONTAL);
                  GridData label6LData = new GridData();
                  label6LData.grabExcessHorizontalSpace = true;
                  label6LData.horizontalAlignment = GridData.FILL;
                  label6LData.verticalAlignment = GridData.BEGINNING;
                  label6.setLayoutData(label6LData);
                  label6.setText("label6");
                }
                {
                  composite8 = new Composite(simulationPanel,
                      SWT.NONE);
                  FillLayout composite8Layout = new FillLayout(
                      org.eclipse.swt.SWT.HORIZONTAL);
                  GridData composite8LData = new GridData();
                  composite8LData.horizontalAlignment = GridData.FILL;
                  composite8LData.grabExcessHorizontalSpace = true;
                  composite8LData.verticalAlignment = GridData.FILL;
                  composite8LData.grabExcessVerticalSpace = true;
                  composite8.setLayoutData(composite8LData);
                  composite8.setLayout(composite8Layout);
                  {
                    sceneCanvas = new Canvas(composite8,
                        SWT.BORDER | SWT.NO_BACKGROUND);
                    sceneCanvas
                        .addPaintListener(new PaintListener() {
                          public void paintControl(
                              PaintEvent evt) {
                            sceneCanvasPaintControl(evt);
                          }
                        });
                  }
                }
                {
                  label2 = new Label(simulationPanel,
                      SWT.SEPARATOR | SWT.HORIZONTAL);
                  GridData label2LData = new GridData();
                  label2LData.horizontalAlignment = GridData.FILL;
                  label2LData.verticalAlignment = GridData.END;
                  label2LData.grabExcessHorizontalSpace = true;
                  label2.setLayoutData(label2LData);
                  label2.setText("label2");
                }
                {
                  composite9 = new Composite(simulationPanel,
                      SWT.NONE);
                  GridLayout composite9Layout = new GridLayout();
                  composite9Layout.numColumns = 7;
                  composite9Layout.verticalSpacing = 0;
                  composite9Layout.marginWidth = 0;
                  composite9Layout.marginHeight = 0;
                  GridData composite9LData = new GridData();
                  composite9LData.horizontalAlignment = GridData.FILL;
                  composite9LData.grabExcessHorizontalSpace = true;
                  composite9LData.verticalAlignment = GridData.FILL;
                  composite9.setLayoutData(composite9LData);
                  composite9.setLayout(composite9Layout);
                  {
                    playControls = new ToolBar(composite9,
                        SWT.FLAT);
                    GridData toolBar2LData = new GridData();
                    toolBar2LData.horizontalAlignment = GridData.FILL;
                    toolBar2LData.grabExcessVerticalSpace = true;
                    playControls
                        .setLayoutData(toolBar2LData);
                    {
                      playButton = new ToolItem(
                          playControls, SWT.NONE);
                      playButton
                          .setToolTipText("Ejecutar");
                      playButton.setWidth(32);
                      playButton
                          .setImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/enable/play.png"));
                      playButton
                          .setDisabledImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/disable/play-despng.png"));
                      playButton.setEnabled(false);
                      playButton
                          .addSelectionListener(new SelectionAdapter() {
                            public void widgetSelected(
                                SelectionEvent evt) {
                              playButtonWidgetSelected(evt);
                            }
                          });
                    }
                    {
                      pauseButton = new ToolItem(
                          playControls, SWT.NONE);
                      pauseButton
                          .setToolTipText("Pausar");
                      pauseButton
                          .setImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/enable/play-pause.png"));
                      pauseButton
                          .setDisabledImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/disable/play-pause-des.png"));
                      pauseButton.setEnabled(false);
                      pauseButton
                          .addSelectionListener(new SelectionAdapter() {
                            public void widgetSelected(
                                SelectionEvent evt) {
                              pauseButtonWidgetSelected(evt);
                            }
                          });
                    }
                    {
                      stopButton = new ToolItem(
                          playControls, SWT.NONE);
                      stopButton
                          .setToolTipText("Detener");
                      stopButton
                          .setImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/enable/play-stop.png"));
                      stopButton
                          .setDisabledImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/disable/play-stop-des.png"));
                      stopButton.setEnabled(false);
                      stopButton
                          .addSelectionListener(new SelectionAdapter() {
                            public void widgetSelected(
                                SelectionEvent evt) {
                              stopButtonWidgetSelected(evt);
                            }
                          });
                    }
                    {
                      recButton = new ToolItem(
                          playControls, SWT.NONE);
                      recButton
                          .setToolTipText("Comenzar Grabaci�n");
                      recButton
                          .setImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/enable/play-rec.png"));
                      recButton
                          .setDisabledImage(SWTResourceManager
                              .getImage("resources/icons/icon24x24/disable/play-rec-des.png"));
                      recButton.setEnabled(false);
                      recButton
                          .addSelectionListener(new SelectionAdapter() {
                            public void widgetSelected(
                                SelectionEvent evt) {
                              recButtonWidgetSelected(evt);
                            }
                          });
                    }
                    {
                      new ToolItem(playControls,
                          SWT.SEPARATOR);
                      // separator = new
                      // ToolItem(playControls,
                      // SWT.SEPARATOR);
                      // toolItem1.setText("toolItem1");
                    }
                  }
                  {
                    cSpeedTitle = new CLabel(composite9,
                        SWT.NONE);
                    cSpeedTitle.setText("Velocidad");
                    GridData cSpeedTitleLData = new GridData();
                    cSpeedTitle
                        .setLayoutData(cSpeedTitleLData);
                    cSpeedTitle
                        .setImage(SWTResourceManager
                            .getImage("resources/icons/icon24x24/enable/clock_hands24x24.png"));
                  }
                  {
                    GridData speedControlLData = new GridData();
                    speedControlLData.widthHint = 183;
                    speedControlLData.heightHint = 42;
                    speedControl = new Scale(composite9,
                        SWT.NONE);
                    speedControl
                        .setLayoutData(speedControlLData);
                    speedControl
                        .setMinimum(Defines.MIN_SPEED_PERCENT);
                    speedControl
                        .setMaximum(Defines.MAX_SPEED_PERCENT);
                    speedControl.setSelection(100);
                    speedControl
                        .setToolTipText("Velocidad de Reproducci�n");
                    speedControl.setEnabled(false);
                    speedControl
                        .addSelectionListener(new SelectionAdapter() {
                          public void widgetSelected(
                              SelectionEvent evt) {
                            double percent = speedControl
                                .getSelection() / 100.0;
                              Simulation.getCurrent().setShell(getShell());
                            Simulation
                                .getCurrent()
                                .setStepTime(
                                    (long) (Defines.DEFAULT_STEP_TIME / percent));
                            speedLabel
                                .setText(formatter
                                    .format(100.0 * percent)
                                    + "%");
                          }
                        });
                  }
                  {
                    speedLabel = new Label(composite9,
                        SWT.NONE);
                    speedLabel.setText("100%");
                    speedLabel.setFont(SWTResourceManager
                        .getFont("Tahoma", 9, 1, false,
                            false));
                    speedLabel
                        .setToolTipText("Velocidad de Reproducci�n");
                  }
                  {
                    speedReset = new Button(composite9,
                        SWT.PUSH | SWT.CENTER);
                    speedReset.setText("Reset");
                    speedReset.setEnabled(false);
                    speedReset
                        .addSelectionListener(new SelectionAdapter() {
                          public void widgetSelected(
                              SelectionEvent evt) {

                            Simulation
                                .getCurrent()
                                .setStepTime(
                                    Defines.DEFAULT_STEP_TIME);
                            speedControl
                                .setSelection(100);
                            speedLabel
                                .setText("100%");
                          }
                        });
                  }
                }
                {
                  label3 = new Label(simulationPanel,
                      SWT.SEPARATOR | SWT.HORIZONTAL);
                  GridData label3LData = new GridData();
                  label3LData.grabExcessHorizontalSpace = true;
                  label3LData.horizontalAlignment = GridData.FILL;
                  label3.setLayoutData(label3LData);
                  label3.setText("label3");
                }
              }
              {
                GridData label22LData = new GridData();
                label22LData.verticalAlignment = GridData.FILL;
                label22LData.horizontalAlignment = GridData.END;
                label22LData.grabExcessVerticalSpace = true;
                label22 = new Label(rigthTopPannel,
                    SWT.SEPARATOR);
                label22.setLayoutData(label22LData);
              }
            }
            {
              rightBottonPannel = new Composite(sashForm2,
                  SWT.NONE);
              GridLayout composite5Layout = new GridLayout();
              composite5Layout.horizontalSpacing = 0;
              composite5Layout.marginHeight = 0;
              composite5Layout.marginWidth = 0;
              composite5Layout.verticalSpacing = 0;
              composite5Layout.numColumns = 3;
              rightBottonPannel.setLayout(composite5Layout);
              rightBottonPannel.setSize(506, 360);
              {
                label11 = new Label(rightBottonPannel,
                    SWT.SEPARATOR | SWT.VERTICAL);
                GridData label11LData = new GridData();
                label11LData.grabExcessVerticalSpace = true;
                label11LData.verticalAlignment = GridData.FILL;
                label11.setLayoutData(label11LData);
                label11.setText("label11");
              }
              {
                propertiesPannel = new Composite(
                    rightBottonPannel, SWT.NONE);
                GridLayout composite11Layout = new GridLayout();
                composite11Layout.marginWidth = 0;
                composite11Layout.verticalSpacing = 0;
                composite11Layout.marginHeight = 0;
                composite11Layout.horizontalSpacing = 0;
                composite11Layout.makeColumnsEqualWidth = true;
                GridData composite11LData = new GridData();
                composite11LData.verticalAlignment = GridData.FILL;
                composite11LData.horizontalAlignment = GridData.FILL;
                composite11LData.grabExcessHorizontalSpace = true;
                composite11LData.grabExcessVerticalSpace = true;
                propertiesPannel
                    .setLayoutData(composite11LData);
                propertiesPannel.setLayout(composite11Layout);
                {
                  label4 = new Label(propertiesPannel,
                      SWT.SEPARATOR | SWT.HORIZONTAL);
                  GridData label4LData = new GridData();
                  label4LData.grabExcessHorizontalSpace = true;
                  label4LData.horizontalAlignment = GridData.FILL;
                  label4.setLayoutData(label4LData);
                  label4.setText("label4");
                }
                {
                  composite6 = new Composite(
                      propertiesPannel, SWT.NONE);
                  FillLayout composite6Layout = new FillLayout(
                      org.eclipse.swt.SWT.HORIZONTAL);
                  GridData composite6LData = new GridData();
                  composite6.setLayoutData(composite6LData);
                  composite6.setLayout(composite6Layout);
                  composite6.setFont(SWTResourceManager
                      .getFont("Tahoma", 8, 1, false,
                          false));
                  {
                    cLabel1 = new CLabel(composite6,
                        SWT.SHADOW_NONE);
                    cLabel1.setText("Propiedades");
                    cLabel1
                        .setImage(SWTResourceManager
                            .getImage("resources/icons/icon32x32/enable/Toolbar_Customize.png"));
                    cLabel1
                        .setForeground(SWTResourceManager
                            .getColor(91, 91, 91));
                    cLabel1.setFont(SWTResourceManager
                        .getFont("Tahoma", 9, 1, false,
                            false));
                  }
                }
                {
                  label5 = new Label(propertiesPannel,
                      SWT.SEPARATOR | SWT.HORIZONTAL);
                  GridData label5LData = new GridData();
                  label5LData.horizontalAlignment = GridData.FILL;
                  label5LData.grabExcessHorizontalSpace = true;
                  label5.setLayoutData(label5LData);
                  label5.setText("label5");
                }
                {
                  GridData robotStatusLData = new GridData();
                  robotStatusLData.horizontalAlignment = GridData.FILL;
                  robotStatusLData.verticalAlignment = GridData.FILL;
                  robotStatusLData.grabExcessHorizontalSpace = true;
                  robotStatusLData.grabExcessVerticalSpace = true;
                  robotStatus = new Composite(
                      propertiesPannel, SWT.NONE);
                  GridLayout robotStatusLayout = new GridLayout();
                  robotStatusLayout.makeColumnsEqualWidth = true;
                  robotStatusLayout.horizontalSpacing = 0;
                  robotStatusLayout.marginHeight = 0;
                  robotStatusLayout.marginWidth = 0;
                  robotStatusLayout.verticalSpacing = 0;
                  robotStatus.setLayout(robotStatusLayout);
                  robotStatus.setLayoutData(robotStatusLData);
                  {
                    customRobotStatus = new Composite(
                        robotStatus, SWT.NONE);
                    GridLayout customRobotStatusLayout = new GridLayout();
                    customRobotStatusLayout.makeColumnsEqualWidth = true;
                    customRobotStatusLayout.marginWidth = 0;
                    customRobotStatusLayout.verticalSpacing = 0;
                    GridData customRobotStatusLData = new GridData();
                    customRobotStatusLData.grabExcessHorizontalSpace = true;
                    customRobotStatusLData.grabExcessVerticalSpace = true;
                    customRobotStatusLData.horizontalAlignment = GridData.FILL;
                    customRobotStatusLData.verticalAlignment = GridData.FILL;
                    customRobotStatus
                        .setLayoutData(customRobotStatusLData);
                    customRobotStatus
                        .setLayout(customRobotStatusLayout);
                  }

                }
                {
                  label8 = new Label(propertiesPannel,
                      SWT.SEPARATOR | SWT.HORIZONTAL);
                  GridData label8LData = new GridData();
                  label8LData.horizontalAlignment = GridData.FILL;
                  label8LData.grabExcessHorizontalSpace = true;
                  label8.setLayoutData(label8LData);
                }
              }
              {
                GridData label24LData = new GridData();
                label24LData.grabExcessVerticalSpace = true;
                label24LData.verticalAlignment = GridData.FILL;
                label24LData.horizontalAlignment = GridData.FILL;
                label24 = new Label(rightBottonPannel,
                    SWT.SEPARATOR);
                label24.setLayoutData(label24LData);
              }
            }
            sashForm2.setWeights(new int[] { 75, 25 });
          }
        }

      }
      refreshTable();
      refreshNeuralNetworkTable();
      this.layout();
    } catch (Exception e) {
      ErrorMessage.customMessage(e.getMessage(),
          ErrorMessage.ERROR_MESSAGE, getParent());
    }
  }

  /**
   * Redibuja la im�gen del escenario (laberinto) en pantalla.
   */
  public void drawMazeImage() {
    sceneCanvas.redraw();
  }

  /**
   * Manejador de eventos de repintado para el canvas del escenario. Cada vez
   * que el escenario (laberinto) debe redibujarse, se invoca autom�ticamente
   * a este m�todo.
   *
   * @param evt
   *            informaci�n del evento.
   */
  private void sceneCanvasPaintControl(PaintEvent evt) {

    if (Simulation.getCurrent() != null) {
      // Hay una simulaci�n cargada.

      if (showSchematic()) {

        // Antes de comenzar a dibujar, se borra todo lo anterior.
        backgroundGC.setBackground(Display.getDefault().getSystemColor(
            SWT.COLOR_WHITE));
        backgroundGC.fillRectangle(0, 0,
            Defines.DEFAULT_IMAGE_RESOLUTION[0],
            Defines.DEFAULT_IMAGE_RESOLUTION[1]);

        // Dibuja las paredes
        if (mazeItems != null && mazeItems.recognizedWalls != null) {
          for (int i = 0; i < mazeItems.recognizedWalls.length; i++) {
            int r = mazeItems.recognizedWalls[i].color.getRed();
            int g = mazeItems.recognizedWalls[i].color.getGreen();
            int b = mazeItems.recognizedWalls[i].color.getBlue();
            backgroundGC.setBackground(new Color(Display
                .getDefault(), r, g, b));

            backgroundGC.fillPolygon(mazeItems.recognizedWalls[i]
                .getPoints());
          }
        }

        // Dibuja los �conos coloreados
        if (mazeItems != null
            && mazeItems.recognizedColoredIcons != null) {
          for (int i = 0; i < mazeItems.recognizedColoredIcons.length; i++) {
            int r = mazeItems.recognizedColoredIcons[i].color
                .getRed();
            int g = mazeItems.recognizedColoredIcons[i].color
                .getGreen();
            int b = mazeItems.recognizedColoredIcons[i].color
                .getBlue();
            backgroundGC.setBackground(new Color(Display
                .getDefault(), r, g, b));

            backgroundGC
                .fillPolygon(mazeItems.recognizedColoredIcons[i]
                    .getPoints());
          }
        }

        // Se redibujan todos los robots
        Vector robots = Simulation.getCurrent().getRobotArray();
        for (int i = 0; i < robots.size(); i++) {
          Robot robot = (Robot) robots.get(i);
          if (robot.isVisible()
              && robot.getStatus() == Defines.STATE_ROBOT_CALIBRATED)
            robot.draw(backgroundGC);
        }

        // Dibuja la imagen 'background' escalada.
        evt.gc.drawImage(background, 0, 0,
            background.getBounds().width,
            background.getBounds().height, 0, 0, sceneCanvas
                .getBounds().width,
            sceneCanvas.getBounds().height);

      } else {
        if (swtImage != null && !swtImage.isDisposed())
          swtImage.dispose();

        BufferedImage awtImage = ((ImageBasedGPS) Simulation
            .getCurrent().getGps()).getImage();
        if (awtImage != null) {
          if (swtImage != null && !swtImage.isDisposed())
            swtImage.dispose();

          swtImage = new Image(Display.getDefault(), ImageUtils
              .convertToSWT(awtImage));

          if (swtImage != null)
            backgroundGC.drawImage(swtImage, 0, 0);

          // Dibuja la imagen 'background' escalada.
          evt.gc.drawImage(background, 0, 0,
              background.getBounds().width, background
                  .getBounds().height, 0, 0, sceneCanvas
                  .getBounds().width,
              sceneCanvas.getBounds().height);
        }

        try {
          Thread.sleep(Defines.REFRESH_DELAY);
        } catch (InterruptedException e) {
        }

      }

    } else {
      // No hay simulaci�n cargada. Se dibuja un rect�ngulo vac�o.

      evt.gc.setBackground(Display.getDefault().getSystemColor(
          SWT.COLOR_WHITE));
      evt.gc.fillRectangle(0, 0, Defines.DEFAULT_IMAGE_RESOLUTION[0],
          Defines.DEFAULT_IMAGE_RESOLUTION[1]);
    }

  }

  /**
   * Este m�todo determina si en la interfaz gr�fica fue seleccionada la
   * opci�n de representaci�n esquem�tica de la imagen del escenario.
   *
   * @return <code>true</code> si se seleccion� la opci�n de representaci�n
   *         esquem�tica.
   */
  private boolean showSchematic() {
    if (this.displaySchematicView.getSelection() == true)
      return true;
    else
      return false;
  }

  /**
   * Acci�n que se ejecuta cuando se presiona el bot�n de nueva simulaci�n.
   *
   * @param evt
   *            informaci�n del evento.
   */
  private void newSimulationWidgetSelected(SelectionEvent evt) {
    if (this.neuralNetworksBase.getSelectedItem() == null) {
      MessageBox messageBox = new MessageBox(this.getShell(), SWT.OK
          | SWT.ICON_INFORMATION);
      messageBox
          .setMessage("Debe seleccionar una red neuronal antes de crear una nueva simulaci�n");
      messageBox.setText("Seleccionar red neuronal");
      messageBox.open();
      return;
    }

    if (Simulation.getCurrent() != null)
      // Hay una simulaci�n corriendo. Se la detiene.
      stopButtonWidgetSelected(null);

    NewSimulationDialog newSimulationDialog = new NewSimulationDialog(this
        .getShell(), SWT.NULL, this);
    newSimulationDialog.open();

    if (Simulation.getCurrent() == null)
      // Se cancel� la creaci�n de la nueva simulaci�n.
      return;

    // Me quedo con las referencias de los elementos reconocidos ac�
    // porque si se llega a resetear el GPS, se pierden la referencias.
    mazeItems = Simulation.getCurrent().getGps().getMazeItems();

    if (Simulation.getCurrent() != null
        && Simulation.getCurrent().isAllOk()) {
      recButton.setEnabled(true);
      speedReset.setEnabled(true);

      speedControl.setSelection(100);
      if (Simulation.getCurrent().getType() == Defines.REAL_SIMULATION)
      {
        displayRealView.setEnabled(true);
        displaySchematicView.setEnabled(false);
        speedControl.setEnabled(false);
        displayRealView.setSelection(true);
        displaySchematicView.setSelection(false);
      }
      else
      {
        displayRealView.setEnabled(false);
        displaySchematicView.setEnabled(true);
        speedControl.setEnabled(true);
        displayRealView.setSelection(false);
        displaySchematicView.setSelection(true);
      }

      // Ahora registra al canvas como "observador" de cada robot creado.
      Vector robots = Simulation.getCurrent().getRobotArray();
      for (int i = 0; i < robots.size(); i++)
        ((Robot) robots.get(i)).addObserver(this);

      // Se refresca el �rbol de robots.
      refreshTree();

      SimulationBaseItem simulationBaseItem = new SimulationBaseItem();
      simulationBaseItem.setName(Simulation.getCurrent().getName());
      simulationBaseItem.setDescription(Simulation.getCurrent()
          .getComment());
      simulationBaseItem.setPath(Simulation.getCurrent()
          .getBaseSimulationDirectory());
      simulationBaseItem.setDuration(Simulation.getCurrent()
          .getFormattedDuration());

      // Agrego la simulaci�n en la base.

      while (simulationBase.insertSimulationBaseItem(simulationBaseItem) == SimulationBase.DUPLICATEK_KEY) {
        SimulationNameChanger dialog = new SimulationNameChanger(this
            .getShell(), SWT.NONE);
        dialog.open();
        simulationBaseItem.setName(Simulation.getCurrent().getName());
      }

      if (simulationBase.updateSimulationBaseItem(simulationBaseItem) == SimulationBase.NO_SUCH_OBJECT)
        simulationBase.insertSimulationBaseItem(simulationBaseItem);

      // En este punto la simulaci�n est� completa.
      // Reci�n ahora puede almacenarse.
      try {
        Simulation.getCurrent().saveSimulationConfig();
      } catch (EasyBotAppException e) {
        ErrorMessage.customMessage(e.getMessage(),
            ErrorMessage.ERROR_MESSAGE, getParent());
      }

      // Refresco la tabla de simulaciones
      refreshTable();

      newSimulationButton.setEnabled(true);
      loadSimulationButton.setEnabled(false);
      deleteSimulationButton.setEnabled(false);

      setNeuralNetToolsEnabled(false);
    }

  }

  private void loadSimulationWidgetSelected(SelectionEvent evt) {
    try {

      if (simulationTable.getSelectionCount() > 0) {

        // Se verifica que la simulaci�n a cargar no sea la actual.
        if (Simulation.getCurrent() != null
            && Simulation.getCurrent().getName().equals(
                simulationTable.getSelection()[0].getText(0)))
          return;

        if (Simulation.getCurrent() != null) {
          // Se detiene y descarga la simulaci�n actual.
          stopButtonWidgetSelected(null);
          /*
           * Simulation.getCurrent().stop();
           * Simulation.getCurrent().unLoad();
           */
        }

        // Carga la simulaci�n desde el sistema de archivos,
        // levantando los documentos XML.
        Simulation.load(simulationTable.getSelection()[0].getText(2));

        // Ahora registra al canvas como "observador" de cada robot
        // creado.
        Vector robots = Simulation.getCurrent().getRobotArray();
        for (int i = 0; i < robots.size(); i++)
          ((Robot) robots.get(i)).addObserver(this);

        // Se refresca el �rbol de robots.
        refreshTree();

        // Se establecen todos los robots en estado "calibrado"
        // (ya que es una reproducci�n)
        for (int i = 0; i < robots.size(); i++)
          ((Robot) robots.get(i))
              .setStatus(Defines.STATE_ROBOT_CALIBRATED);

        mazeItems = Simulation.getCurrent().getGps().getMazeItems();

        sceneCanvas.redraw();

        newSimulationButton.setEnabled(true);
        loadSimulationButton.setEnabled(true);
        deleteSimulationButton.setEnabled(true);

        playButton.setEnabled(true);
        pauseButton.setEnabled(false);
        stopButton.setEnabled(false);
        recButton.setEnabled(false);

        speedControl.setSelection(100);

        displayRealView.setEnabled(false);
        displaySchematicView.setEnabled(true);

        displayRealView.setSelection(false);
        displaySchematicView.setSelection(true);

        speedControl.setEnabled(true);
        speedReset.setEnabled(true);

      } else {
        ErrorMessage.errorMessage(Defines.ERROR_NO_SIMULATION_SELECTED,
            this.getParent());
      }

    } catch (Exception e) {
      ErrorMessage.customMessage("Error cargando la simulaci�n: "
          + e.getMessage(), ErrorMessage.ERROR_MESSAGE, getParent());
    }
  }

  private void deleteNeuronalNetWidgetSelected(SelectionEvent evt) {
    if (neuronalNetTable.getSelectionIndex() != -1) {
      if (ErrorMessage.warningYesNoMessage(
          Defines.WARNING_DELETE_NEURONALNET, this.getParent()) != SWT.YES)
        return;

      NeuralNetworkBaseItem item = neuralNetworksBase
          .getNeuralNetworkBaseItem(neuronalNetTable.getItem(
              neuronalNetTable.getSelectionIndex()).getText(1));
      neuralNetworksBase.removeNeuralNetworkBaseItem(item);

      neuronalNetTable.deselectAll();
      refreshNeuralNetworkTable();

      deleteNeuronalNetButton.setEnabled(false);
    }
  }

  private void deleteSimulationWidgetSelected(SelectionEvent evt) {
    if (simulationTable.getSelectionCount() > 0) {
      SimulationBaseItem item = new SimulationBaseItem();
      item.setName(simulationTable.getSelection()[0].getText(0));
      item.setDuration(simulationTable.getSelection()[0].getText(1));
      item.setPath(simulationTable.getSelection()[0].getText(2));
      item.setDescription(simulationTable.getSelection()[0].getText(3));

      if (ErrorMessage.warningYesNoMessage(
          Defines.WARNING_DELETE_SIMULATION, this.getParent()) != SWT.YES)
        return;

      // Se verifica que la simulaci�n a eliminar no sea la actual.
      if (Simulation.getCurrent() != null
          && Simulation.getCurrent().getName().equals(item.getName())) {
        ErrorMessage.errorMessage(Defines.ERROR_SIMULATION_IN_USE,
            getParent());
        return;
      }

      // Primero se elimina la simulaci�n del sistema de archivos.
      try {
        File simDir = new File(item.getPath());
        if (simDir.exists() && simDir.isDirectory())
        {
          File componentsDir = new File(item.getPath() + "\\components");
          File tracesDir = new File(item.getPath() + "\\traces");
          File robotsDir = new File(item.getPath() + "\\robots");
          if (componentsDir.exists() && componentsDir.isDirectory())
          {
            FileUtils.cleanDirectory(componentsDir);
            componentsDir.delete();
          }
          if (tracesDir.exists() && tracesDir.isDirectory())
          {
            FileUtils.cleanDirectory(tracesDir);
            tracesDir.delete();
          }
          if (robotsDir.exists() && robotsDir.isDirectory())
          {
            FileUtils.cleanDirectory(robotsDir);
            robotsDir.delete();
          }
          File simFile = new File(item.getPath() + "\\simulation.xml");
          if (simFile.exists())
            simFile.delete();
          simFile = new File(item.getPath() + "\\simulation-rules.xml");
          if (simFile.exists())
            simFile.delete();
          //FileUtils.cleanDirectory(simDir);
        }
      } catch (IOException e) {
        ErrorMessage.customMessage("Error eliminando la simulaci�n: "
            + e.getMessage(), ErrorMessage.ERROR_MESSAGE,
            getParent());
        return;
      }

      // Finalmente, se elimina el �tem.
      simulationBase.removeSimulationBaseItem(item);
      simulationTable.deselectAll();

      newSimulationButton.setEnabled(true);
      loadSimulationButton.setEnabled(false);
      deleteSimulationButton.setEnabled(false);

      refreshTable();
    } else {
      ErrorMessage.errorMessage(Defines.ERROR_NO_SIMULATION_SELECTED,
          getParent());
    }
  }

  private void setNeuralNetToolsEnabled(boolean enabled) {
    // this.newNeuronalNetButton.setEnabled(enabled);
    this.deleteNeuronalNetButton.setEnabled(enabled);
    this.loadNeuronalNetButton.setEnabled(enabled);
    this.neuronalNetTable.setEnabled(enabled);
  }

  /**
   * Acci�n que se ejecuta cuando se presiona el bot�n "play".
   *
   * @param evt
   *            informaci�n del evento.
   */
  private void playButtonWidgetSelected(SelectionEvent evt) {
    playButton.setEnabled(false);
    pauseButton.setEnabled(true);
    stopButton.setEnabled(true);
    recButton.setEnabled(false);

    if (Simulation.getCurrent() != null)
      Simulation.getCurrent().play();
    else {
      ErrorMessage.errorMessage(Defines.ERROR_NO_SIMULATION_SELECTED,
          this.getParent());
    }
  }

  /**
   * Acci�n que se ejecuta cuando se presiona el bot�n "pause".
   *
   * @param evt
   *            informaci�n del evento.
   */
  private void pauseButtonWidgetSelected(SelectionEvent evt) {
    Simulation.getCurrent().pause();

    pauseButton.setEnabled(false);
    stopButton.setEnabled(true);

    if (Simulation.getCurrent().isPlaybackSimualtion()) {
      // Si es reproducci�n, habilita "Play".
      playButton.setEnabled(true);
      recButton.setEnabled(false);
    } else {
      // Si es simulaci�n, habilita "Rec".
      playButton.setEnabled(false);
      recButton.setEnabled(true);
    }
  }

  /**
   * Acci�n que se ejecuta cuando se presiona el bot�n "stop".
   *
   * @param evt
   *            informaci�n del evento.
   */
  private void stopButtonWidgetSelected(SelectionEvent evt) {
    Simulation.getCurrent().stop();

    displaySchematicView.setSelection(true);
    displayRealView.setSelection(false);

    if (Simulation.getCurrent().isPlaybackSimualtion()) {
      playButton.setEnabled(true);
      pauseButton.setEnabled(false);
      stopButton.setEnabled(false);
      recButton.setEnabled(false);
    } else {
      playButton.setEnabled(false);
      pauseButton.setEnabled(false);
      stopButton.setEnabled(false);
      recButton.setEnabled(false);

      // Se actualizan los datos para la tabla de simulaciones.
      SimulationBaseItem simulationBaseItem = new SimulationBaseItem();
      simulationBaseItem.setName(Simulation.getCurrent().getName());
      simulationBaseItem.setDescription(Simulation.getCurrent()
          .getComment());
      simulationBaseItem.setPath(Simulation.getCurrent()
          .getBaseSimulationDirectory());
      simulationBaseItem.setDuration(Simulation.getCurrent()
          .getFormattedDuration());

      // Se modifica el registro de la simulaci�n en la base.
      simulationBase.updateSimulationBaseItem(simulationBaseItem);

      // Se descarga la simulaci�n ya que una vez que se hace "stop" no se
      // puede seguir simulando (ahora solo se puede reproducir).
      Simulation.getCurrent().unLoad();

    }

    setNeuralNetToolsEnabled(true);

    cleanStatusPannel();
    customRobotStatus.layout(true);
  }

  /**
   * Acci�n que se ejecuta cuando se presiona el bot�n "rec".
   *
   * @param evt
   *            informaci�n del evento.
   */
  private void recButtonWidgetSelected(SelectionEvent evt) {
    setNeuralNetToolsEnabled(false);

    Simulation.getCurrent().play();

    playButton.setEnabled(false);
    pauseButton.setEnabled(true);
    stopButton.setEnabled(true);
    recButton.setEnabled(false);
  }

  /**
   * Este m�todo permite limpiar el panel de estado de los robots.
   */
  private void cleanStatusPannel() {
    if (customRobotStatus != null && !customRobotStatus.isDisposed())
      customRobotStatus.dispose();

    customRobotStatus = new Composite(robotStatus, SWT.NONE);
    GridLayout customRobotStatusLayout = new GridLayout();
    customRobotStatusLayout.makeColumnsEqualWidth = true;
    customRobotStatusLayout.marginWidth = 0;
    customRobotStatusLayout.verticalSpacing = 0;
    GridData customRobotStatusLData = new GridData();
    customRobotStatusLData.grabExcessHorizontalSpace = true;
    customRobotStatusLData.grabExcessVerticalSpace = true;
    customRobotStatusLData.horizontalAlignment = GridData.FILL;
    customRobotStatusLData.verticalAlignment = GridData.FILL;
    customRobotStatus.setLayoutData(customRobotStatusLData);
    customRobotStatus.setLayout(customRobotStatusLayout);
    robotStatus.layout(true);

    getStatusPanel = true;
  }

  /**
   * Acci�n que se ejecuta cuando se cierra la aplicaci�n.
   */
  public synchronized void dispose() {
    if (Simulation.getCurrent() != null) {
      // Se detiene la simulaci�n que est� corriendo.
      Simulation.getCurrent().stop();

      // Se cierra el GPS.
      GPS gps = Simulation.getCurrent().getGps();
      if (gps != null && !gps.isDisposed()) {
        gps.close();
        gps.dispose();
      }

      // Se liberan todos los recursos asociados a la simulaci�n
      Simulation.getCurrent().dispose();
    }

    // Se fuerza la invocaci�n del m�todo finalize() de todos los objetos.
    System.runFinalization();

    super.dispose();

    Logger.info("La aplicaci�n principal liber� sus recursos. Fin.");
  }

  public void update(Observable o, Object arg) {
    // Hay que lanzar otro thread de esta manera, para que
    // no haya conflictos con el UI-thread

    Display.getDefault().asyncExec(new Runnable() {
      public void run() {
        sceneCanvas.redraw();
      }
    });
  }

  private void worldTreeWidgetSelected(SelectionEvent evt) {
    try {
      if (!getStatusPanel)
        return;

      if (worldTree.getSelectionCount() > 0
          && worldTree.getSelection()[0].getText().compareTo("World") != 0) {
        Robot roboTemp = Simulation.getCurrent().getRobotByName(
            worldTree.getSelection()[0].getText());
        if (roboTemp != null) {
          Plugin plugin = ClassManager.getInstance().getPluginByName(
              roboTemp.getClass().getCanonicalName());

          // Se instancia la clase GUI y se le pasa el robot.

          if (plugin != null) {
            Composite temp = customRobotStatus;
            RobotGUI robotGUI = (RobotGUI) plugin
                .makeGUInstance(roboTemp);
            customRobotStatus = robotGUI.getStatusPannel(
                robotStatus, robotStatus.getStyle());

            if (temp != null && !temp.isDisposed())
              temp.dispose();

            if (customRobotStatus != null) {
              GridData customRobotStatusLData = new GridData();
              customRobotStatusLData.horizontalAlignment = GridData.FILL;
              customRobotStatusLData.verticalAlignment = GridData.FILL;
              customRobotStatusLData.grabExcessHorizontalSpace = true;
              customRobotStatusLData.grabExcessVerticalSpace = true;
              customRobotStatus
                  .setLayoutData(customRobotStatusLData);
            }

            robotStatus.layout(true);
            getStatusPanel = false;
          }
        }
      }
    } catch (Exception e) {
      ErrorMessage.customMessage(e.getMessage(),
          ErrorMessage.ERROR_MESSAGE, getParent());
    }
  }

  private void refreshTree() {
    if (Simulation.getCurrent() == null)
      return;

    rootItem.removeAll(); // Vac�o el �rbol
    Vector robots = Simulation.getCurrent().getRobotArray();
    for (int i = 0; i < robots.size(); i++) {
      TreeItem robotItem = new TreeItem(rootItem, SWT.NONE);
      robotItem.setText(((Robot) robots.get(i)).getName());
      robotItem.setImage(SWTResourceManager
          .getImage("resources/icons/icon24x24/enable/aibo210.png"));
    }
    rootItem.setExpanded(true);
  }

  private void refreshTable() {
    simulationTable.removeAll();
    Vector items = simulationBase.getItems();
    for (int i = 0; i < items.size(); i++) {
      TableItem item = new TableItem(simulationTable, SWT.NONE);
      item.setText(0, ((SimulationBaseItem) items.get(i)).getName());
      item.setText(1, ((SimulationBaseItem) items.get(i)).getDuration());
      item.setText(2, ((SimulationBaseItem) items.get(i)).getPath());
      item.setText(3, ((SimulationBaseItem) items.get(i))
          .getDescription());
    }

  }

  private void newNeuronalNetWidgetSelected(SelectionEvent evt) {
    CreateNeuralNet createNeuralNet = new CreateNeuralNet(getShell(),
        SWT.NONE);
    NeuralNetworkBaseItem newitem = createNeuralNet.open();
    if (newitem != null) {
      try {
        // TODO Con multiples tipos de red deberia ser:
        // FileUtils.copyDirectory(new
        // File(PropertiesLoader.getInstance().getProperty("TemplateNeuralNet")
        // + "_" + newitem.getType()),new File(newitem.getPath()));

        FileUtils.copyDirectory(new File(PropertiesLoader.getInstance()
            .getProperty("TemplateNeuralNet")), new File(newitem
            .getPath()));
        File descriptionFile = new File(newitem.getPath()
            + PropertiesLoader.getInstance().getProperty(
                "TemplateNeuralNetDescriptionFileName"));
        if (descriptionFile.exists())
          descriptionFile.delete();
        descriptionFile.createNewFile();
        FileWriter fout = new FileWriter(descriptionFile);
        fout.write("#ifndef RED_DATOS_DESCRIPCION\n");
        fout.write("#define RED_DATOS_DESCRIPCION\n\n");
        fout.write("#define NOMBRE_RED \""
            + newitem.getName().replace("\"", "\\\"") + "\"\n");
        fout.write("#define DESCRIPCION_RED \""
            + newitem.getDescription().replace("\r\n", "\\r\\n")
                .replace("\"", "\\\"") + "\"\n");
        fout.write("#define TIPO_RED " + newitem.getType());
        fout.write("\n\n#endif\n");
        fout.close();

        ErrorMessage.customMessage(
            "La plantilla fue creada exitosamente en: "
                + newitem.getPath(), ErrorMessage.INFO_MESSAGE,
            getParent());
      } catch (IOException e) {
        ErrorMessage.customMessage("Error creando la plantilla en: "
            + newitem.getPath() + "\nEl mensaje de error es: "
            + e.getMessage(), ErrorMessage.ERROR_MESSAGE,
            getParent());
      }
    }
  }

  private void loadNeuronalNetWidgetSelected(SelectionEvent evt) {
    FileDialog fileDialog;
    fileDialog = new FileDialog(getShell(), SWT.OPEN);

    fileDialog.setFilterExtensions(new String[] { "*.dll" });
    fileDialog
        .setFilterNames(new String[] { "Redes neuronales compiladas (*.dll)" });

    String pathName = fileDialog.open();
    if (pathName != null) {
      NeuralNetworkBaseItem item = new NeuralNetworkBaseItem();
      item.setPath(pathName);
      item.setSelected(false);

      neuralNetworksBase.insertNeuralNetworkBaseItem(item);
      if (item.getType() == -1) {
        ErrorMessage.customMessage("Error al cargar la red neuronal: "
            + pathName, ErrorMessage.ERROR_MESSAGE, getParent());
      }
      refreshNeuralNetworkTable();
    }
  }

  private void selectNeuronalNet(int newidx) {
    System.out.println("---Change neural network---");
    NeuralNetworkBaseItem old = neuralNetworksBase.getSelectedItem();
    NeuralNetworkBaseItem newitem = ((NeuralNetworkBaseItem) neuralNetworksBase
        .getItems().get(newidx));
    if (old != null) {
      old.setSelected(false);
      externalNN.unload_network();
      if (newitem == old) {
        refreshNeuralNetworkTable();
        neuralNetworksBase.saveToFile();
        return;
      }
    }
    if (externalNN.load_network(newitem.getPath()) != 0) {
      ErrorMessage.customMessage("Error al cargar la red neuronal: "
          + newitem.getPath(), ErrorMessage.ERROR_MESSAGE,
          getParent());
      return;
    }
    newitem.setSelected(true);
    refreshNeuralNetworkTable();
    neuralNetworksBase.saveToFile();
  }

  private void neuronalNetWidgetSelected(SelectionEvent evt) {
    deleteNeuronalNetButton.setEnabled(true);
  }

  private void refreshNeuralNetworkTable() {
    neuronalNetTable.removeAll();
    Vector items = neuralNetworksBase.getItems();
    for (int i = 0; i < items.size(); i++) {
      TableItem item = new TableItem(neuronalNetTable, SWT.NONE);
      item.setText(0, ((NeuralNetworkBaseItem) items.get(i)).getName());
      item.setText(1, ((NeuralNetworkBaseItem) items.get(i)).getPath());
      item.setText(2, ((NeuralNetworkBaseItem) items.get(i))
          .getDescription());
      if (((NeuralNetworkBaseItem) items.get(i)).getType() > -1) {
        item.setText(3, ((NeuralNetworkBaseItem) items.get(i))
            .getDescription());
        item.setBackground(new Color(getDisplay(), 255, 255, 255));
      } else {
        item.setBackground(new Color(getDisplay(), 255, 0, 0));
      }
      item.setText(4, ((NeuralNetworkBaseItem) items.get(i))
          .getSelected() ? "X" : "");
    }

  }

  private void simulationTableWidgetSelected(SelectionEvent evt) {
    newSimulationButton.setEnabled(true);
    loadSimulationButton.setEnabled(true);
    deleteSimulationButton.setEnabled(true);

  }

  public NeuralNetworkBase getNeuralNetworkBase() {
    return neuralNetworksBase;
  }

  public ExternalNeuralNetwork getExternalNetwork() {
    return externalNN;
  }

  public static EasyBotApp getInstance() {
    return inst;
  }

  /**
   * M�todo principal, a partir del cual se lanza toda la aplicaci�n.
   *
   * @param args
   *            argumentos de l�nea de comandos (no se utilizan).
   */
  public static void main(String[] args) {
    Display display = Display.getDefault();
    Shell shell = new Shell(display);

    try {
      inst = new EasyBotApp(shell, SWT.NULL);

      Point size = inst.getSize();
      shell.setLayout(new FillLayout());
      shell.setMaximized(true);
      shell.setMinimumSize(new org.eclipse.swt.graphics.Point(800, 600));
      shell.setImage(SWTResourceManager
          .getImage("resources/icons/iconmisc/cubos32.png"));
      shell.setText(".:: EasyBot ::.");
      shell.layout();
      if (size.x == 0 && size.y == 0) {
        inst.pack();
        shell.pack();
      } else {
        Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
        shell.setSize(shellBounds.width, shellBounds.height);
      }
      shell.open();
      while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
          display.sleep();
      }
    } catch (Exception e) {
      MessageBox messageBox = new MessageBox(shell, SWT.OK
          | SWT.ICON_ERROR);
      messageBox.setMessage("Se ha producido un error en la aplicaci�n. "
          + e.getMessage());
      messageBox.setText("Error en EasyBot");
      messageBox.open();
    }
  }

}
TOP

Related Classes of gui.EasyBotApp

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.