Package components.neuralnetwork

Source Code of components.neuralnetwork.MatrixDialog

package components.neuralnetwork;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

import utils.ErrorMessage;

import com.cloudgarden.resource.SWTResourceManager;



/**
* Esta clase implementa un di�logo para mostrar una matriz de pesos de
* una red neuronal, y da la posibilidad de exportarla a un archivo.
*/
public class MatrixDialog extends Dialog
{

  private Shell           dialogShell;
  private CLabel           label;
  private Composite         back;
  private Label           separador2;
  private Button           saveButton;
  private StyledText         textArea;
  private Label           separador;
  private NeuralNetworkState     weights;

 
  public MatrixDialog(Shell parent, int style, NeuralNetworkState weights)
  {
    super(parent, style);
    this.weights = weights;
  }

 
  public void open()
  {
    try {
      Shell parent = getParent();
      dialogShell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

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


      GridLayout dialogShellLayout = new GridLayout();
      dialogShell.setLayout(dialogShellLayout);
      dialogShellLayout.horizontalSpacing = 0;
      dialogShellLayout.marginHeight = 0;
      dialogShellLayout.marginWidth = 0;
      dialogShellLayout.verticalSpacing = 3;
      dialogShellLayout.marginLeft = 3;
      dialogShellLayout.marginRight = 3;
      dialogShell.layout();
      dialogShell.pack();
      dialogShell.setSize(336, 278);
      dialogShell.setImage(SWTResourceManager.getImage("resources/icons/icon32x32/enable/neuron.png"));
      dialogShell.setText("Red Neuronal");
      {
        back = new Composite(dialogShell, SWT.NONE);
        GridLayout backLayout = new GridLayout();
        backLayout.makeColumnsEqualWidth = true;
        backLayout.horizontalSpacing = 0;
        backLayout.verticalSpacing = 2;
        backLayout.marginHeight = 2;
        backLayout.marginWidth = 2;
        GridData backLData = new GridData();
        backLData.horizontalAlignment = GridData.FILL;
        backLData.grabExcessHorizontalSpace = true;
        backLData.verticalAlignment = GridData.FILL;
        back.setLayoutData(backLData);
        back.setLayout(backLayout);
        {
          label = new CLabel(back, SWT.NONE);
          label.setText("Matriz de Pesos");
          GridData labelLData = new GridData();
          labelLData.horizontalAlignment = GridData.FILL;
          labelLData.grabExcessHorizontalSpace = true;
          label.setLayoutData(labelLData);
          label.setImage(SWTResourceManager.getImage("resources/icons/icon32x32/enable/neuron.png"));
          label.setFont(SWTResourceManager.getFont("Tahoma",9,1,false,false));
          label.setForeground(SWTResourceManager.getColor(128,128,128));
        }
        {
          GridData separadorLData = new GridData();
          separadorLData.horizontalAlignment = GridData.FILL;
          separador = new Label(back, SWT.SEPARATOR | SWT.HORIZONTAL);
          separador.setLayoutData(separadorLData);
        }
        {
          GridData textAreaLData = new GridData();
          textAreaLData.horizontalAlignment = GridData.FILL;
          textAreaLData.heightHint = 142;
          textArea = new StyledText(back, SWT.NONE);
          textArea.setLayoutData(textAreaLData);
         
          // Se llena la matriz de pesos en el campo texto.
          textArea.setText(this.weights.toString());
        }
        {
          GridData separador2LData = new GridData();
          separador2LData.horizontalAlignment = GridData.FILL;
          separador2 = new Label(back, SWT.SEPARATOR | SWT.HORIZONTAL);
          separador2.setLayoutData(separador2LData);
        }
        {
          saveButton = new Button(back, SWT.PUSH | SWT.CENTER);
          GridData saveButtonLData = new GridData();
          saveButtonLData.horizontalAlignment = GridData.CENTER;
          saveButtonLData.widthHint = 71;
          saveButtonLData.heightHint = 23;
          saveButton.setLayoutData(saveButtonLData);
          saveButton.setText("Exportar");
          saveButton.addSelectionListener(
              new SelectionAdapter ()
              {
                public void widgetSelected(SelectionEvent evt)
                {
                  exportMatrix(evt);
                }
              });

        }
      }
      dialogShell.open();
      Display display = dialogShell.getDisplay();
      while (!dialogShell.isDisposed()) {
        if (!display.readAndDispatch())
          display.sleep();
      }
    }
    catch (Exception e)
    {
      ErrorMessage.customMessage( e.getMessage() , ErrorMessage.ERROR_MESSAGE , getParent() );
    }
  }
 
 
  private void exportMatrix(SelectionEvent evt)
  {
    FileDialog fileDialog = new FileDialog(this.getParent(),SWT.OPEN);
    fileDialog.setText("Exportar Pesos");
    String exportFile = fileDialog.open();
   
    if ( exportFile != null )
      weights.toFile(exportFile);
  }

}
TOP

Related Classes of components.neuralnetwork.MatrixDialog

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.