Package components.commchannel.serial

Source Code of components.commchannel.serial.SerialCommunicationChannelGUI

package components.commchannel.serial;

import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Observable;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

import resources.SWTResourceManager;
import utils.ErrorMessage;
import utils.defines.Defines;

import components.Component;
import components.commchannel.*;


/**
* Esta clase implementa la interfaz gr�fica que permite configurar
* un canal de comunicaciones serie.
*/
public class SerialCommunicationChannelGUI extends CommunicationChannelGUI
{

  private CCombo      frontCamPortCombo;
  private CLabel      frontCamPortLabel;
  private CCombo      commCombo;
  private CLabel      commLabel;
  private CLabel      speedLabel;
  private  CCombo      speedCombo;
  private HashMap     serialParams;
  private CLabel      dataBitsLabel;
  private CCombo      dataBitsCombo;
  private CLabel      parityLabel;
  private  CCombo      parityCombo;
  private CLabel      stopBitLabel;
  private CCombo      stopBitCombo;
  private CLabel       headLabel;
 
 
  /**
   * Crea una nueva interfaz gr�fica (GUI) para configuraci�n de un
   * canal de comunicaciones serie.
   * @param commChannel  canal de comunicaciones serie a configurar.
   */
  public SerialCommunicationChannelGUI( Component commChannel)
  {
    super(commChannel);
    serialParams = new HashMap();
    serialParams.put("5 bits", SerialPort.DATABITS_5);
    serialParams.put("6 bits", SerialPort.DATABITS_6);
    serialParams.put("7 bits", SerialPort.DATABITS_7);
    serialParams.put("8 bits", SerialPort.DATABITS_8);
    serialParams.put("Par", SerialPort.PARITY_EVEN);
    serialParams.put("Impar", SerialPort.PARITY_ODD);
    serialParams.put("Ninguno", SerialPort.PARITY_NONE);
    serialParams.put("Marca", SerialPort.PARITY_MARK);
    serialParams.put("Espacio", SerialPort.PARITY_SPACE);
    serialParams.put("1", SerialPort.STOPBITS_1);
    serialParams.put("2", SerialPort.STOPBITS_2);
    serialParams.put("1.5", SerialPort.STOPBITS_1_5);
  }

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

 
  public Composite getConfigPannel( Composite composite, int style)
  {
    Composite customContainer = new Composite(composite,style);
    GridLayout buttonLayout = new GridLayout();
    buttonLayout.makeColumnsEqualWidth = false;
    buttonLayout.numColumns=2;
    GridData bottonLData = new GridData();
    bottonLData.grabExcessHorizontalSpace = true;
    bottonLData.horizontalAlignment = GridData.FILL;
    bottonLData.verticalAlignment = GridData.FILL;
    bottonLData.grabExcessVerticalSpace = true;
    customContainer.setLayoutData(bottonLData);
    customContainer.setLayout(buttonLayout);
    {
      headLabel = new CLabel(customContainer, SWT.NONE);
      headLabel.setText("Cofiguracion del Canal de Comunicaci�n");
      headLabel.setFont(SWTResourceManager.getFont("Tahoma", 8, 1, false, false));
      GridData headLabelLayout = new GridData();
      headLabelLayout.horizontalSpan=2;
      headLabelLayout.horizontalAlignment=GridData.FILL;
      headLabelLayout.grabExcessHorizontalSpace=true;
      headLabel.setLayoutData(headLabelLayout);
     
      frontCamPortLabel = new CLabel(customContainer,SWT.NONE);
      frontCamPortLabel.setText("Puerto C�mara Frontal: ");
      frontCamPortCombo = new CCombo(customContainer,SWT.NONE);     
     
      commLabel = new CLabel(customContainer,SWT.NONE);
      commLabel.setText("Puerto: ");     
      commCombo = new CCombo(customContainer,SWT.NONE);
      fillPortCombo();
      speedLabel = new CLabel(customContainer,SWT.NONE);
      speedLabel.setText("Velocidad: ");
      speedCombo = new CCombo(customContainer,SWT.NONE);
      speedCombo.add("9600");
      speedCombo.add("19200");
      speedCombo.add("38400");
      speedCombo.add("57600");
      speedCombo.select(2);
      dataBitsLabel = new CLabel(customContainer,SWT.NONE);
      dataBitsLabel.setText("Bits de Datos");
      dataBitsCombo = new CCombo(customContainer,SWT.NONE);
      dataBitsCombo.add("5 bits");
      dataBitsCombo.add("6 bits");
      dataBitsCombo.add("7 bits");
      dataBitsCombo.add("8 bits");
      dataBitsCombo.select(3);
      parityLabel = new CLabel(customContainer,SWT.NONE);
      parityLabel.setText("Paridad");
      parityCombo = new CCombo(customContainer,SWT.NONE);
      parityCombo.add("Ninguno");
      parityCombo.add("Par");
      parityCombo.add("Impar");
      parityCombo.add("Marca");
      parityCombo.add("Espacio");
      parityCombo.select(0);
      stopBitLabel = new CLabel(customContainer,SWT.NONE);
      stopBitLabel.setText("Bit de Stop");
      stopBitCombo = new CCombo(customContainer,SWT.NONE);
      stopBitCombo.add("1");
      stopBitCombo.add("1.5");
      stopBitCombo.add("2");
      stopBitCombo.select(0);
    }
   
    return customContainer;
  }

 
  private void fillPortCombo()
  {
    Enumeration pList = CommPortIdentifier.getPortIdentifiers();
      // Process the list.
      while (pList.hasMoreElements())
      {
        CommPortIdentifier cpi = (CommPortIdentifier) pList.nextElement();
        if (cpi.getPortType() == CommPortIdentifier.PORT_SERIAL)
          if (cpi.isCurrentlyOwned()) {
            commCombo.add(cpi.getName()+ "(usado)");           
            frontCamPortCombo.add(cpi.getName()+ "(usado)");
          }
          else {
            commCombo.add(cpi.getName());
            frontCamPortCombo.add(cpi.getName());
          }
      } 
  }
 
 
  public void applyChanges()
  {
    if (commCombo.getText().length()==0)
    {
      ErrorMessage.errorMessage(Defines.ERROR_NO_COMPORT_SELECTED,commCombo.getParent());
      return;
    }
    ((SerialCommunicationChannel)component).setRobotComPort(commCombo.getText());
    ((SerialCommunicationChannel)component).setFrontCameraPort(frontCamPortCombo.getText());   
    ((SerialCommunicationChannel)component).setSpeed(Integer.valueOf(speedCombo.getText()).intValue());
    ((SerialCommunicationChannel)component).setParity(((Integer)serialParams.get(parityCombo.getText())).intValue());
    ((SerialCommunicationChannel)component).setStopBit(((Integer)serialParams.get(stopBitCombo.getText())).intValue());
    ((SerialCommunicationChannel)component).setDataBits(((Integer)serialParams.get(dataBitsCombo.getText())).intValue());
    component.setAllOK(true);
  }

 
  public Composite getStatusPannel(Composite parent, int style)
  {
    Composite returnComposite = new Composite(parent,style);
    Label label = new Label(returnComposite,SWT.NONE);
    label.setText("Canal de Comunicaciones: "+ ((SerialCommunicationChannel)component).getName()
        + "\n\t Velocidad: " + ((SerialCommunicationChannel)component).getSpeed()
        + "\n\t Paridad: " + ((SerialCommunicationChannel)component).getParity()
        + "\n\t StopBit: " + ((SerialCommunicationChannel)component).getStopBit()
        + "\n\t Data Bits: " + ((SerialCommunicationChannel)component).getDataBits());
    return returnComposite;
  }


  public Composite getConfigPannel(Composite parent)
  {
    // TODO Auto-generated method stub
    return null;
  }


  public void update(Observable arg0, Object arg1)
  {
    // TODO Auto-generated method stub
   
  }

}
TOP

Related Classes of components.commchannel.serial.SerialCommunicationChannelGUI

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.