Package components.gps.imagebased

Source Code of components.gps.imagebased.ImageBasedGPSGUI

package components.gps.imagebased;

import gui.EasyBotAppException;
import gui.dialogs.tuningpanels.ImageBasedGPSTuner;

import java.util.Observable;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
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 resources.SWTResourceManager;
import resources.digesters.ClassManager;
import resources.digesters.Plugin;
import utils.ErrorMessage;
import utils.defines.Defines;

import components.Component;
import components.ComponentGUIException;
import components.gps.GPSGUI;
import components.imagecollector.ImageCollectorGUI;

import core.simulation.Simulation;


/**
* Esta clase implementa la interfaz gr�fica que permite configurar
* el sistema de posicionamiento global basado en im�genes.
*/
public class ImageBasedGPSGUI extends GPSGUI
{

  private Composite         gpsConfig;
  private CLabel           webcamImage;
  private ImageCollectorGUI     icGUI;

 
 
  public ImageBasedGPSGUI(Component component)
  {
    super(component);
    Simulation.getCurrent().getGps().addObserver(this);
  }

 
  public Composite getConfigPannel(Composite parent, int style) throws ComponentGUIException
  {
    Button confButton;
    gpsConfig = new Composite(parent, style);
    GridData webcamConfigLData = new GridData();
    webcamConfigLData.horizontalAlignment = GridData.FILL;
    webcamConfigLData.verticalAlignment = GridData.BEGINNING;
    webcamConfigLData.grabExcessVerticalSpace = true;
    webcamConfigLData.horizontalSpan = 1;
    gpsConfig.setLayoutData(webcamConfigLData);
    GridLayout webcamConfigLayout = new GridLayout();
    webcamConfigLayout.numColumns = 2;
    gpsConfig.setLayout(webcamConfigLayout);
    Plugin ic;
   
    try
    {
      ic = ClassManager.getInstance().getPluginByName(((ImageBasedGPS)this.component).getImageCollector().getClass().getCanonicalName());
    }
    catch (EasyBotAppException e1)
    {
      throw new ComponentGUIException(e1.getMessage());
    }
   
    if (ic != null)
    {
   
      try
      {
        icGUI = (ImageCollectorGUI) ic.makeGUInstance(((ImageBasedGPS)component).getImageCollector());
        Composite imageCollectorConfig = icGUI.getConfigPannel(gpsConfig, style);
        GridData icLData = new GridData();
        icLData.horizontalAlignment = GridData.FILL;
        icLData.verticalAlignment = GridData.BEGINNING;
        icLData.grabExcessHorizontalSpace=true;
        icLData.grabExcessVerticalSpace=true;
        icLData.horizontalSpan = 1;
        imageCollectorConfig.setLayoutData(icLData);
       
      }
      catch (Exception e)
      {
        throw new ComponentGUIException( e.getMessage() );
      }
    }
    {
      webcamImage = new CLabel(gpsConfig, SWT.NONE);
      GridData imageLData = new GridData();
      imageLData.horizontalAlignment = SWT.END;
      webcamImage.setLayoutData(imageLData);
      webcamImage.setImage(SWTResourceManager.getImage("resources/icons/iconmisc/Webcam Error.png"));
   
    {
      confButton = new Button(gpsConfig, SWT.PUSH | SWT.CENTER);
      GridData confButtonLData = new GridData();
      confButton.setLayoutData(confButtonLData);
      confButton.setText("Configurar");
      confButton.addSelectionListener(new SelectionAdapter()
          {
            public void widgetSelected(SelectionEvent evt)
            {
              configWidgetSelected( evt);
            }
          });
    }
   
   
    return gpsConfig;
  }
 

  public void configWidgetSelected(SelectionEvent evt)
  {
    if ( Simulation.getCurrent().getRobotArray().size() == 0 )
    {
      // No hay ning�n robot en la simulaci�n, por lo tanto no se
      // permite realizar la calibraci�n del GPS.
      ErrorMessage.errorMessage(Defines.ERROR_NO_ROBOT_DEFINED, evt.display.getActiveShell());
      return;
    }
   
    ImageBasedGPSTuner imageBasedGPSTuner;

   
    try
    {
      icGUI.applyChanges();
      imageBasedGPSTuner = new ImageBasedGPSTuner(gpsConfig.getShell(), gpsConfig.getStyle(), ((ImageBasedGPS)component).getImageCollector());
      imageBasedGPSTuner.open();
    }
    catch (ComponentGUIException e)
    {
      ErrorMessage.customMessage( e.getMessage(), ErrorMessage.ERROR_MESSAGE, gpsConfig.getParent() );
    }
  }
 
 
  public Composite getStatusPannel(Composite parent, int style)
  {
    return null;
  }

 
  public void saveConfig()
  {
    // TODO Auto-generated method stub
  }

 
  public void applyChanges()
  {
    // TODO Auto-generated method stub
  }


  public void update(Observable arg0, Object arg1)
  {
    webcamImage.setImage(SWTResourceManager.getImage("resources/icons/iconmisc/Webcam Connected.png"));
  }

}
TOP

Related Classes of components.gps.imagebased.ImageBasedGPSGUI

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.