Package gui.dialogs

Source Code of gui.dialogs.AddRobot

package gui.dialogs;

import gui.EasyBotAppException;
import java.util.HashMap;
import java.util.Vector;
import com.cloudgarden.resource.SWTResourceManager;
import core.simulation.Simulation;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.*;
import resources.digesters.ClassManager;
import resources.digesters.Plugin;
import utils.ErrorMessage;
import utils.defines.Defines;


/**
* Esta clase implementa el di�logo para la selecci�n del
* perfil de robot que se agregar� a la simulaci�n.
*/
public class AddRobot extends org.eclipse.swt.widgets.Dialog
{

  private Shell      dialogShell;
  private CLabel      titleLabel;
  private Label      titleSeparator;
  private List      list;
  private Button      configButton;
  private Label      subtitleLabel;
  private Composite    back;
  private HashMap      robotMap;



  public AddRobot(Shell parent, int style)
  {
    super(parent, style);
    robotMap = new HashMap();
  }

 
  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.marginHeight = 0;
      dialogShellLayout.marginWidth = 0;
      dialogShellLayout.verticalSpacing = 0;
      {
        back = new Composite(dialogShell, SWT.NONE);
        GridLayout backLayout = new GridLayout();
        backLayout.makeColumnsEqualWidth = true;
        backLayout.marginHeight = 0;
        backLayout.marginWidth = 0;
        backLayout.verticalSpacing = 0;
        backLayout.horizontalSpacing = 0;
        GridData backLData = new GridData();
        backLData.horizontalAlignment = GridData.FILL;
        backLData.verticalAlignment = GridData.FILL;
        backLData.grabExcessHorizontalSpace = true;
        backLData.grabExcessVerticalSpace = true;
        back.setLayoutData(backLData);
        back.setLayout(backLayout);
        {
          titleLabel = new CLabel(back, SWT.NONE);
          titleLabel.setText("Agregando Nuevo Robot");
          GridData titleLabelLData = new GridData();
          titleLabelLData.horizontalAlignment = GridData.FILL;
          titleLabelLData.grabExcessHorizontalSpace = true;
          titleLabel.setLayoutData(titleLabelLData);
          titleLabel.setImage(SWTResourceManager.getImage("resources/icons/icon32x32/enable/AIBO210.png"));
          titleLabel.setFont(SWTResourceManager.getFont("Tahoma", 9, 1, false, false));
          titleLabel.setForeground(SWTResourceManager.getColor(91, 91, 91));
        }
        {
          titleSeparator = new Label(back, SWT.SEPARATOR
            | SWT.HORIZONTAL);
          GridData titleSeparatorLData = new GridData();
          titleSeparatorLData.horizontalAlignment = GridData.FILL;
          titleSeparatorLData.grabExcessHorizontalSpace = true;
          titleSeparator.setLayoutData(titleSeparatorLData);
        }
        {
          subtitleLabel = new Label(back, SWT.NONE);
          subtitleLabel.setText("Robots Disponibles");
          GridData subtitleLabelLData = new GridData();
          subtitleLabelLData.horizontalAlignment = GridData.CENTER;
          subtitleLabelLData.verticalIndent = 5;
          subtitleLabel.setLayoutData(subtitleLabelLData);
          subtitleLabel.setFont(SWTResourceManager.getFont("Tahoma", 8, 1, false, false));
        }
        {
          GridData listLData = new GridData();
          listLData.horizontalAlignment = GridData.CENTER;
          listLData.widthHint = 145;
          listLData.heightHint = 108;
          listLData.verticalIndent = 5;
          list = new List(back, SWT.SINGLE
            | SWT.V_SCROLL
            | SWT.BORDER);
          list.setLayoutData(listLData);
          list.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent evt) {
              listWidgetSelected(evt);
            }
          });
        }
        {
          configButton = new Button(back, SWT.PUSH | SWT.CENTER);
          GridData configButtonLData = new GridData();
          configButtonLData.verticalIndent = 10;
          configButtonLData.horizontalAlignment = GridData.CENTER;
          configButton.setLayoutData(configButtonLData);
          configButton.setText("Configurar");
          configButton.setEnabled(false);
          configButton.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent evt) {
              try
              {
                configButtonWidgetSelected(evt);
              }
              catch (EasyBotAppException e)
              {
                ErrorMessage.customMessage( e.getMessage() , ErrorMessage.ERROR_MESSAGE, getParent() );
              }
            }
          });
        }
      }
      dialogShell.layout();
      dialogShell.pack();
      dialogShell.setSize(246, 260);
      dialogShell.open();
      Display display = dialogShell.getDisplay();
      fillList();
      while (!dialogShell.isDisposed()) {
        if (!display.readAndDispatch())
          display.sleep();
      }
    }
    catch (Exception e)
    {
      // TODO: qu� hacer ??

    }
  }
 
 
  private void fillList() throws EasyBotAppException
  {
   
    Vector robotVector = ClassManager.getInstance().searchClass(Defines.COMPONENT_ROBOT,Simulation.getCurrent().getType());
   
    if (robotVector!= null && robotVector.size()>0)
      for (int i=0; i<robotVector.size();i++)
      {
        list.add(((Plugin) robotVector.get(i)).getPluginDescription());
        robotMap.put(((Plugin) robotVector.get(i)).getPluginDescription(),((Plugin) robotVector.get(i)).getName());
      }
  }

 
  private void listWidgetSelected(SelectionEvent evt)
  {
    configButton.setEnabled(true);
  }
 
 
  private void configButtonWidgetSelected(SelectionEvent evt) throws EasyBotAppException
  {
    RobotConfigDialog robotConfigDialog = new RobotConfigDialog(this.dialogShell,SWT.NONE,(String) robotMap.get(list.getItem(list.getSelectionIndex())));
    robotConfigDialog.open();
    dialogShell.close();
  }

}
TOP

Related Classes of gui.dialogs.AddRobot

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.