コード例 #1
0
 @Override
 protected void okPressed() {
   // I need to save these values in local variables as the GUI stuff is
   // deleted after he close
   SelectedRate = Integer.parseInt(BaudRates.getCombo().getText());
   SelectedPort = SerialPorts.getCombo().getText();
   ArduinoInstancePreferences.setGlobalValue(
       ArduinoConst.KEY_SERIAlRATE, BaudRates.getCombo().getText());
   ArduinoInstancePreferences.setGlobalValue(ArduinoConst.KEY_SERIAlPORT, SelectedPort);
   super.okPressed();
 }
コード例 #2
0
  @Override
  protected Control createDialogArea(Composite parent) {
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    // layout.horizontalAlignment = GridData.FILL;
    parent.setLayout(layout);

    // The text fields will grow with the size of the dialog
    GridData gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;

    // Create the serial port combo box to allow to select a serial port
    Label label1 = new Label(parent, SWT.NONE);
    label1.setText("Serial port to connect to:");

    // If there are no comports allow to provide one
    String[] comPorts = Common.listComPorts();
    if (comPorts.length == 0) {
      SerialPorts = new ComboViewer(parent, SWT.DROP_DOWN);
    } else {
      SerialPorts = new ComboViewer(parent, SWT.READ_ONLY | SWT.DROP_DOWN);
    }
    SerialPorts.getControl().setLayoutData(new GridData(SWT.LEFT, SWT.NONE, false, false));
    SerialPorts.setContentProvider(new ArrayContentProvider());
    SerialPorts.setLabelProvider(new LabelProvider());
    SerialPorts.setInput(comPorts);

    // Create baud rate selection combo box to select the baud rate
    Label label2 = new Label(parent, SWT.NONE);
    label2.setText("Select the baudrate:");
    BaudRates = new ComboViewer(parent, SWT.READ_ONLY | SWT.DROP_DOWN);
    BaudRates.getControl().setLayoutData(new GridData(SWT.LEFT, SWT.NONE, false, false));
    BaudRates.setContentProvider(new ArrayContentProvider());
    BaudRates.setLabelProvider(new LabelProvider());
    BaudRates.setInput(Common.listBaudRates());

    BaudRates.getCombo()
        .setText(ArduinoInstancePreferences.getGlobalValue(ArduinoConst.KEY_SERIAlRATE));
    SerialPorts.getCombo()
        .setText(ArduinoInstancePreferences.getGlobalValue(ArduinoConst.KEY_SERIAlPORT));
    return parent;
  }