Package components.neuralnetwork

Source Code of components.neuralnetwork.NeuralNetworkGUI

package components.neuralnetwork;

import gui.EasyBotApp;
import gui.NeuralNetworkBaseItem;

import java.util.Observable;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

import com.cloudgarden.resource.*;
import components.*;


/**
* Esta clase implementa la interfaz gr�fica que permite configurar
* una red neuronal. <br><br>
*
* En construcci�n.
*/
public class NeuralNetworkGUI extends ComponentGUI
{

  private Label  numMov;
  private Label  currPlace;
  private Combo  combo;
 
 
  /**
   * Crea una nueva interfaz gr�fica (GUI) para configuraci�n de una
   * red neuronal.
   * @param neuralNetwork  red neuronal a configurar.
   */
  public NeuralNetworkGUI(Component neuralNetwork)
  {
    super(neuralNetwork);
    //neuralNetwork.addObserver(this);
  }
 
 
  /**
   * Abre un dialogo donde se muestra la matriz de pesos de la red neronal
   * @param evt
   */
  private void showMatrixEvent(SelectionEvent evt)
  {
    NeuralNetworkState weights = ((NeuralNetwork)component).getWeights();
    MatrixDialog mDialog = new MatrixDialog(((Button)evt.getSource()).getShell(),SWT.NONE, weights);
    mDialog.open();
  }
 
   
  public void saveConfig()
  {
    // TODO Auto-generated method stub
   
   
  }

 
  public void applyChanges()
  {
    component.setAllOK(true);
  }


  public Composite getConfigPannel(Composite parent, int style)
  {
    Composite config = new Composite(parent,SWT.NONE);
    GridLayout composite1Layout = new GridLayout();
    composite1Layout.makeColumnsEqualWidth = true;
    config.setLayout(composite1Layout);
    {
      Label label= new Label(config,SWT.NONE);
      label.setText("Configuraci�n de la red neuronal en construcci�n");
      combo = new Combo(config, SWT.READ_ONLY);
      //String[] itemsCombo = new String[EasyBotApp.getInstance().getNeuralNetworkBase().getItems().size()];
      //for (int i=0;i<itemsCombo.length;i++)
      //  itemsCombo[i]=((NeuralNetworkBaseItem)(EasyBotApp.getInstance().getNeuralNetworkBase().getItems().get(i))).getName();
      String[] itemsCombo = new String[1];
      itemsCombo[0]=((NeuralNetworkBaseItem)(EasyBotApp.getInstance().getNeuralNetworkBase().getSelectedItem())).getName();
      combo.setItems(itemsCombo);
      combo.select(0);

      Button matrixButton = new Button(config,SWT.NONE);
      matrixButton.setText("Importar Matriz de Pesos");
      matrixButton.addSelectionListener(
          new SelectionAdapter ()
          {
            public void widgetSelected(SelectionEvent evt)
            {
              importWeightsEvent(evt);
            }
          });
    }
    return config;
  }


  public Composite getStatusPannel(Composite parent, int style)
  {
    Composite statusPannel = new Composite(parent,style);
    {
      CLabel label = new CLabel(statusPannel, SWT.NONE);
      label.setText("Estados:");
      GridData labelLData = new GridData();
      labelLData.horizontalAlignment = GridData.FILL;
      labelLData.grabExcessHorizontalSpace = true;
      label.setLayoutData(labelLData);
      label.setFont(SWTResourceManager.getFont("Tahoma",9,1,false,false));
      label.setForeground(SWTResourceManager.getColor(128,128,128));
      currPlace = new Label(statusPannel,SWT.NONE);
      currPlace.setText("Lugar Pr�ximo: " + String.valueOf(((NeuralNetwork)this.component).getCurrentPlace()));
      numMov = new Label(statusPannel,SWT.NONE);
      numMov.setText("N�mero de Movimientos: " + String.valueOf(((NeuralNetwork)this.component).getNumMovements()));
      Button matrixButton = new Button(statusPannel,SWT.NONE);
      matrixButton.setText("Mostrar Matriz de Pesos");
      matrixButton.addSelectionListener(
          new SelectionAdapter ()
          {
            public void widgetSelected(SelectionEvent evt)
            {
              showMatrixEvent(evt);
            }
          });
    }
    return statusPannel;
  }


  public void update(Observable arg0, Object arg1)
  {
    final int currPlaceLocal  = ((NeuralNetwork)this.component).getCurrentPlace();
    final int numMovsLocal    = ((NeuralNetwork)this.component).getNumMovements();
   
    Display.getDefault().asyncExec(
        new Runnable()
        {
          public void run()
          {
            if ( currPlace != null  &&  !currPlace.isDisposed()  &&  numMov != null  &&  !numMov.isDisposed() )
            {
              currPlace.setText("Lugar Pr�ximo: " + String.valueOf(currPlaceLocal));
              numMov.setText("N�mero de Movimientos: " + String.valueOf(numMovsLocal));
            }
          }
        });
  }

 
  public void importWeightsEvent(SelectionEvent evt)
  {
    FileDialog fileDialog = new FileDialog(((Button)evt.getSource()).getShell(),SWT.OPEN);
    fileDialog.setText("Importar Pesos");
    String importFile = fileDialog.open()
   
    if ( importFile != null )
    { 
      NeuralNetworkState weights = new NeuralNetworkState(importFile);
     
      // TODO: Quizas sea necasario setear los lugares antes. Ver c�mo hacerlo.
      ((NeuralNetwork)this.component).setNeuralNetworkState(weights);
    }
  }

}
TOP

Related Classes of components.neuralnetwork.NeuralNetworkGUI

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.