/*
   * (non-Javadoc)
   *
   * @see net.refractions.udig.style.sld.SLDEditorPart#createPartControl(org.eclipse.swt.widgets.Composite)
   */
  protected Control createPartControl(Composite parent) {
    myparent = parent;
    RowLayout layout = new RowLayout();
    myparent.setLayout(layout);
    layout.pack = false;
    layout.wrap = true;
    layout.type = SWT.HORIZONTAL;

    /* Border Opacity */
    Group borderOpacityArea = new Group(myparent, SWT.NONE);
    borderOpacityArea.setLayout(new GridLayout(2, false));
    borderOpacityArea.setText("Raster Opacity"); // $NON-NLS-1$

    opacityScale = new Scale(borderOpacityArea, SWT.HORIZONTAL);
    opacityScale.setMinimum(0);
    opacityScale.setMaximum(100);
    opacityScale.setPageIncrement(10);
    opacityScale.setBounds(0, 0, 10, SWT.DEFAULT);
    opacityScale.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            opacityText.setText(String.valueOf(opacityScale.getSelection()) + "%"); // $NON-NLS-1$
            opacityText.pack(true);
          }
        });
    opacityScale.addSelectionListener(this);

    opacityText = new Text(borderOpacityArea, SWT.BORDER | SWT.READ_ONLY);
    opacityText.pack(true);

    return parent;
  }
  public void testRenderPageIncrement() throws IOException {
    Scale scale = new Scale(shell, SWT.NONE);

    scale.setPageIncrement(20);
    lca.renderChanges(scale);

    Message message = Fixture.getProtocolMessage();
    assertEquals(new Integer(20), message.findSetProperty(scale, "pageIncrement"));
  }
  public void testRenderPageIncrementUnchanged() throws IOException {
    Scale scale = new Scale(shell, SWT.NONE);
    Fixture.markInitialized(display);
    Fixture.markInitialized(scale);

    scale.setPageIncrement(20);
    Fixture.preserveWidgets();
    lca.renderChanges(scale);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(scale, "pageIncrement"));
  }
예제 #4
0
 private void createScalingControls(Composite client) {
   final Scale scale = new Scale(client, SWT.NONE);
   scale.setMinimum(1);
   scale.setMaximum(100);
   scale.setSelection(50);
   scale.setPageIncrement(5);
   scale.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
           int selection = scale.getSelection();
           if (selection > 50) {
             selection = selection - 50;
             scaleFactor.setText(String.valueOf(1.0d * selection));
           } else if (selection == 50) {
             scaleFactor.setText(String.valueOf(1.0d));
           } else {
             selection = 50 - selection;
             scaleFactor.setText(String.valueOf(1.0d / selection));
           }
           applyScaleFactor();
         }
       });
   GridDataFactory.fillDefaults().span(3, 0).applyTo(scale);
   Label label = kit.createLabel(client, "scale factor: ");
   GridDataFactory.fillDefaults().grab(true, false).applyTo(label);
   scaleFactor = kit.createText(client, "1.0");
   GridDataFactory.fillDefaults().grab(true, false).applyTo(scaleFactor);
   final Button setScale = kit.createButton(client, "apply", SWT.PUSH);
   setScale.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
           applyScaleFactor();
         }
       });
   GridDataFactory.fillDefaults().applyTo(setScale);
 }
예제 #5
0
  @Override
  public void createPartControl(Composite parent) {
    plotViewName = getViewSite().getRegisteredName();
    plotServer.addIObserver(this);
    setPartName(plotViewName);
    this.parent = parent;
    parent.setLayout(new GridLayout(1, true));

    locationRow = new Composite(parent, SWT.NONE);
    locationRow.setLayout(new GridLayout(4, false));
    {
      btnHistoryBack = new Button(locationRow, SWT.LEFT);
      btnHistoryBack.setEnabled(false);
      btnHistoryBack.setToolTipText("Go back in history");
      btnHistoryBack.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/arrow_left.png").createImage());
      btnHistoryBack.addSelectionListener(this);
      btnHistoryForw = new Button(locationRow, SWT.LEFT);
      btnHistoryForw.setEnabled(false);
      btnHistoryForw.setToolTipText("Go forward in history");
      btnHistoryForw.addSelectionListener(this);
      btnHistoryForw.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/arrow_right.png").createImage());
      lblLocation = new Label(locationRow, SWT.LEFT);
      lblLocation.setText("Location:");

      cmbDirectoryLocation = new Combo(locationRow, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
      cmbDirectoryLocation.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
      cmbDirectoryLocation.addSelectionListener(this);
    }
    locationRow.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false));

    canvas = new Canvas(parent, SWT.DOUBLE_BUFFERED | SWT.V_SCROLL | SWT.H_SCROLL);
    canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    compHUD = new Group(parent, SWT.NONE);
    compHUD.setLayout(new GridLayout(6, false));
    compHUD.setText("Image Playback");
    {
      btnRewind = new Button(compHUD, SWT.PUSH);
      btnRewind.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/control_start.png").createImage());
      btnRewind.addSelectionListener(this);
      btnRewind.setToolTipText("Rewind");
      btnPlay = new Button(compHUD, SWT.TOGGLE);
      imgPlay = AnalysisRCPActivator.getImageDescriptor("icons/control_play.png").createImage();
      imgStill = AnalysisRCPActivator.getImageDescriptor("icons/control_pause.png").createImage();
      btnPlay.setImage(imgPlay);
      btnPlay.addSelectionListener(this);
      btnPlay.setToolTipText("Play/Pause");
      btnStop = new Button(compHUD, SWT.PUSH);
      btnStop.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/control_stop.png").createImage());
      btnStop.addSelectionListener(this);
      btnStop.setToolTipText("Stop playback");
      btnForward = new Button(compHUD, SWT.PUSH);
      btnForward.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/control_end.png").createImage());
      btnForward.addSelectionListener(this);
      btnForward.setToolTipText("Forward");
      btnPlayLoop = new Button(compHUD, SWT.TOGGLE);
      btnPlayLoop.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/control_repeat.png").createImage());
      btnPlayLoop.setToolTipText("Playback loop (On/off)");
      btnPlayLoop.addSelectionListener(this);
      sldProgress = new Scale(compHUD, SWT.HORIZONTAL);
      sldProgress.setPageIncrement(1);
      sldProgress.addSelectionListener(this);
      sldProgress.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    }
    compHUD.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));

    imageGrid = new PlotServerSWTImageGrid(canvas, plotViewName);
    imageGrid.setThumbnailSize(getPreferenceImageSize());
    retainStateFromServer();

    if (dirPath != null && dirPath.length() > 0) {
      dirPath.trim();
      updateDirectory.setUser(true);
      updateDirectory.setPriority(Job.DECORATE);
      updateDirectory.schedule(1000);
      cmbDirectoryLocation.setText(dirPath);
      currentDir = dirPath;
    }
    playback =
        new ImagePlayBack(
            parent,
            getPreferencePlaybackView(),
            getViewSite().getPage(),
            sldProgress,
            getPreferenceTimeDelay(),
            getPreferencePlaybackRate());

    isDisposed = false;

    // listen to preference changes to update the Live plot play back view and colour map
    AnalysisRCPActivator.getDefault()
        .getPreferenceStore()
        .addPropertyChangeListener(
            new IPropertyChangeListener() {
              @Override
              public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(PreferenceConstants.IMAGEEXPLORER_PLAYBACKVIEW)) {
                  playback.setPlotView(getPreferencePlaybackView());
                }
                if (event.getProperty().equals(PreferenceConstants.IMAGEEXPLORER_COLOURMAP)
                    || event.getProperty().equals(PreferenceConstants.IMAGEEXPLORER_IMAGESIZE)) {
                  List<GridImageEntry> images = imageGrid.getListOfEntries();
                  imageGrid.setThumbnailSize(getPreferenceImageSize());
                  String colourScheme = getPreferenceColourMapChoice();
                  for (GridImageEntry entry : images) {
                    IDataset data = entry.getData();
                    SWTGridEntry gridEntry =
                        new SWTGridEntry(
                            entry.getFilename(),
                            data,
                            canvas,
                            colourScheme,
                            getPreferenceAutoContrastLo(),
                            getPreferenceAutoContrastHi());
                    imageGrid.addEntry(gridEntry, entry.getGridColumnPos(), entry.getGridRowPos());
                  }
                  // Check the colour menu accordingly
                  IAction currentColour = colorMenu.findAction(colourScheme);
                  if (currentColour != null) currentColour.setChecked(true);
                }
              }
            });
  }
  public RoomDataComposite(Composite parent, RoomController control) {
    super(parent, SWT.NONE);
    setLayout(new GridLayout(3, false));

    this.roomC = control;
    container = Manager.getCurrentShip();
    final ShipController shipC = container.getShipController();

    label = new Label(this, SWT.NONE);
    label.setAlignment(SWT.CENTER);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    label.setText("Room");

    Label separator = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
    separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));

    Label lblSystem = new Label(this, SWT.NONE);
    lblSystem.setText("System: ");

    btnSystem = new Button(this, SWT.NONE);
    GridData gd_btnSystem = new GridData(SWT.RIGHT, SWT.CENTER, true, false, 2, 1);
    gd_btnSystem.widthHint = 100;
    btnSystem.setLayoutData(gd_btnSystem);
    btnSystem.setText("");

    btnAvailable = new Button(this, SWT.CHECK);
    btnAvailable.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 3, 1));
    btnAvailable.setText("Available At Start");

    lblSysLevel = new Label(this, SWT.NONE);
    lblSysLevel.setText("Starting Level:");

    scaleSysLevel = new Scale(this, SWT.NONE);
    scaleSysLevel.setMaximum(2);
    scaleSysLevel.setMinimum(1);
    scaleSysLevel.setPageIncrement(1);
    scaleSysLevel.setIncrement(1);
    scaleSysLevel.setSelection(1);
    scaleSysLevel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));

    txtSysLevel = new Text(this, SWT.BORDER | SWT.READ_ONLY);
    txtSysLevel.setText("");
    txtSysLevel.setTextLimit(3);
    GridData gd_txtSysLevel = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
    gd_txtSysLevel.widthHint = 20;
    txtSysLevel.setLayoutData(gd_txtSysLevel);

    scaleSysLevel.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            Systems sys = container.getActiveSystem(roomC.getGameObject());
            SystemController system = container.getSystemController(sys);
            system.setLevel(scaleSysLevel.getSelection());
            txtSysLevel.setText("" + scaleSysLevel.getSelection());
          }
        });

    if (!Manager.getCurrentShip().getShipController().isPlayerShip()) {
      lblMaxLevel = new Label(this, SWT.NONE);
      lblMaxLevel.setText("Max Level:");

      scaleMaxLevel = new Scale(this, SWT.NONE);
      scaleMaxLevel.setMaximum(2);
      scaleMaxLevel.setMinimum(1);
      scaleMaxLevel.setPageIncrement(1);
      scaleMaxLevel.setIncrement(1);
      scaleMaxLevel.setSelection(1);
      scaleMaxLevel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));

      txtMaxLevel = new Text(this, SWT.BORDER | SWT.READ_ONLY);
      txtMaxLevel.setText("");
      txtMaxLevel.setTextLimit(3);
      GridData gd_txtMaxLevel = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
      gd_txtMaxLevel.widthHint = 20;
      txtMaxLevel.setLayoutData(gd_txtMaxLevel);

      scaleMaxLevel.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              Systems sys = container.getActiveSystem(roomC.getGameObject());
              SystemController system = container.getSystemController(sys);
              system.setLevelMax(scaleMaxLevel.getSelection());
              txtMaxLevel.setText("" + scaleMaxLevel.getSelection());
              if (!shipC.isPlayerShip()) {
                scaleSysLevel.setMaximum(scaleMaxLevel.getSelection());
                scaleSysLevel.notifyListeners(SWT.Selection, null);
                scaleSysLevel.setEnabled(scaleMaxLevel.getSelection() > 1);
                scaleSysLevel.setSelection(
                    Math.min(scaleSysLevel.getSelection(), scaleSysLevel.getMaximum()));
              }
            }
          });
    } else {
      imagesComposite = new Composite(this, SWT.NONE);
      GridLayout gl_imagesComposite = new GridLayout(4, false);
      gl_imagesComposite.marginHeight = 0;
      gl_imagesComposite.marginWidth = 0;
      imagesComposite.setLayout(gl_imagesComposite);
      imagesComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1));

      // Interior widgets
      Label lblInterior = new Label(imagesComposite, SWT.NONE);
      lblInterior.setText("Interior image:");

      btnInteriorView = new Button(imagesComposite, SWT.NONE);
      btnInteriorView.setEnabled(false);
      btnInteriorView.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
      btnInteriorView.setText("View");

      btnInteriorBrowse = new Button(imagesComposite, SWT.NONE);
      btnInteriorBrowse.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
      btnInteriorBrowse.setText("Browse");

      btnInteriorClear = new Button(imagesComposite, SWT.NONE);
      btnInteriorClear.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
      btnInteriorClear.setText("Reset");

      txtInterior = new Text(imagesComposite, SWT.BORDER | SWT.READ_ONLY);
      txtInterior.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));

      // Glow widgets
      lblGlow = new Label(imagesComposite, SWT.NONE);
      lblGlow.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
      lblGlow.setText("Manning glow:");

      btnGlow = new Button(imagesComposite, SWT.NONE);
      GridData gd_btnGlow = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 3, 1);
      gd_btnGlow.widthHint = 120;
      btnGlow.setLayoutData(gd_btnGlow);
      btnGlow.setText("None");

      SelectionAdapter imageViewListener =
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              Systems sys = container.getActiveSystem(roomC.getGameObject());
              SystemController system = container.getSystemController(sys);
              File file = new File(system.getInteriorPath());

              if (file != null && file.exists()) {
                if (Desktop.isDesktopSupported()) {
                  Desktop desktop = Desktop.getDesktop();
                  if (desktop != null) {
                    try {
                      desktop.open(file.getParentFile());
                    } catch (IOException ex) {
                    }
                  }
                } else {
                  Superluminal.log.error(
                      "Unable to open file location - AWT Desktop not supported.");
                }
              }
            }
          };
      btnInteriorView.addSelectionListener(imageViewListener);

      SelectionAdapter imageBrowseListener =
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              Systems sys = container.getActiveSystem(roomC.getGameObject());
              SystemController system = container.getSystemController(sys);
              FileDialog dialog = new FileDialog(EditorWindow.getInstance().getShell());
              dialog.setFilterExtensions(new String[] {"*.png"});
              String path = dialog.open();

              // path == null only when user cancels
              if (path != null) {
                system.setInteriorPath("file:" + path);
                updateData();
              }
            }
          };
      btnInteriorBrowse.addSelectionListener(imageBrowseListener);

      SelectionAdapter imageClearListener =
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              Systems sys = container.getActiveSystem(roomC.getGameObject());
              SystemController system = container.getSystemController(sys);

              system.setInteriorPath(null);
              updateData();
            }
          };
      btnInteriorClear.addSelectionListener(imageClearListener);

      btnGlow.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              Systems sys = container.getActiveSystem(roomC.getGameObject());
              SystemObject systemObject = container.getSystemController(sys).getGameObject();

              GlowSelectionDialog dialog =
                  new GlowSelectionDialog(EditorWindow.getInstance().getShell());
              GlowSet glowSet = dialog.open(systemObject);

              if (glowSet != null) {
                btnGlow.setText(glowSet.getIdentifier());
                systemObject.setGlowSet(glowSet);
              }
            }
          });
    }

    btnSystem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            Point p = btnSystem.getLocation();
            SystemsMenu sysMenu = SystemsMenu.getInstance();
            sysMenu.setLocation(toDisplay(p.x, p.y + btnSystem.getSize().y));
            sysMenu.open();
          }
        });

    btnAvailable.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            Systems sys = container.getActiveSystem(roomC.getGameObject());
            SystemController system = container.getSystemController(sys);
            system.setAvailableAtStart(btnAvailable.getSelection());
            roomC.redraw();
          }
        });

    updateData();

    pack();
  }
예제 #7
0
  private void initialize(Composite parentComposite) {
    // Create logging composite under parent composite
    Composite loggingComposite = new Composite(parentComposite, SWT.NONE);
    loggingComposite.setLayout(new GridLayout(5, false));
    loggingComposite.setLayoutData(new GridData(SWT.BEGINNING));

    // 1. Log category label
    CLabel logCategoryLabel = new CLabel(loggingComposite, SWT.NONE);
    logCategoryLabel.setText("Log category:");
    logCategoryLabel.setLayoutData(new GridData(SWT.BEGINNING));

    // 2. Log categories list
    logCategoryCombo = new Combo(loggingComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
    logCategoryCombo.setEnabled(false);
    populateLogCategory();
    logCategoryCombo.addSelectionListener(
        new org.eclipse.swt.events.SelectionListener() {
          @Override
          public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            String logCategoryText = ((Combo) e.widget).getText();
            handleLogCategoryChange(LogCategoryExt.fromExternalValue(logCategoryText));
          }

          private void handleLogCategoryChange(LogCategoryExt logCategoryExt) {
            // fchang: hook for display diff log category w/o requesting server again. - per bill:
            // not possible
            // w/o refactoring server-side code.
            logLevelScale.setEnabled(true); // enable scale only after logCategory is set.
            LoggingInfo loggingInfo =
                loggingService.getLoggingInfoByCategory(
                    project, logCategoryExt, supportedFeatureEnum);
            setLoggingInfo(loggingInfo);
          }

          @Override
          public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {}
        });

    // 3. Log level label
    CLabel logLevel = new CLabel(loggingComposite, SWT.NONE);
    logLevel.setText("Log level:   --");
    logLevel.setLayoutData(new GridData(SWT.BEGINNING));

    // 4. Log levels scale
    logLevelScale = new Scale(loggingComposite, SWT.NULL);
    logLevelScale.setIncrement(1);
    logLevelScale.setMaximum(7);
    logLevelScale.setEnabled(false);
    logLevelScale.setPageIncrement(1);
    logLevelScale.setLayoutData(new GridData(SWT.BEGINNING));
    logLevelScale.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            LoggingInfo loggingInfo =
                LoggingInfo.getLoggingInfo(
                    logLevelScale.getSelection(), logCategoryCombo.getText());
            loggingService.setLoggingInfo(project, loggingInfo, supportedFeatureEnum);
            logLevelDesc.setText(PLUS_PREFIX + loggingInfo.getLevelLabelText());
            layout(true, true);
          }
        });

    // 5. Log level description label
    logLevelDesc = new CLabel(loggingComposite, SWT.NONE);
    logLevelDesc.setText(INIT_PLUS_PREFIX);
    GridData logLevelDescGd = new GridData();
    logLevelDesc.setLayoutData(logLevelDescGd);
  }
예제 #8
0
  public void createPartControl(final Composite parent) {

    parent.setLayout(new GridLayout(3, false));

    final Composite comp = new Composite(parent, SWT.BORDER);
    comp.setLayout(new FillLayout());
    comp.setLayoutData(new GridData(GridData.FILL_BOTH));

    final Scale scale = new Scale(parent, SWT.BORDER | SWT.VERTICAL);
    scale.setLayoutData(new GridData(GridData.FILL_VERTICAL));
    scale.setMaximum(100);
    scale.setMinimum(0);
    scale.setPageIncrement(1);
    scale.setSelection(100);
    scale.setToolTipText("Throttle Command.");
    scale.addListener(
        SWT.Selection,
        new Listener() {

          @Override
          public void handleEvent(Event event) {
            int value = 100 - scale.getSelection();
            // Inverted! from 100 to 0.
            if (throttleText != null) throttleText.setText(String.valueOf(value) + " %");

            commandThread.getData().setM2(value);
            commandThread.getData().setM3(value);
            commandThread.getData().setM1(value);
            commandThread.getData().setM0(value);
          }
        });

    canvas = new Canvas(comp, SWT.DOUBLE_BUFFERED);

    final Composite data = new Composite(parent, SWT.NONE);
    data.setLayout(new GridLayout(1, true));
    data.setLayoutData(new GridData(GridData.FILL_VERTICAL));

    Group groupThrottle = new Group(data, SWT.NONE);
    groupThrottle.setText("Throttle Command");
    groupThrottle.setLayout(new GridLayout(2, true));
    groupThrottle.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Label label = new Label(groupThrottle, SWT.NONE);
    label.setText("Throttle:");

    throttleText = new Text(groupThrottle, SWT.BORDER);
    throttleText.setEditable(false);
    throttleText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    throttleText.setText("0 %");

    Group groupRoll = new Group(data, SWT.NONE);
    groupRoll.setText("Roll Command");
    groupRoll.setLayout(new GridLayout(2, true));
    groupRoll.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Group groupPitch = new Group(data, SWT.NONE);
    groupPitch.setText("Pitch Command");
    groupPitch.setLayout(new GridLayout(2, true));
    groupPitch.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    label = new Label(groupRoll, SWT.NONE);
    label.setText("Lock Roll:");

    lockRoll = new Button(groupRoll, SWT.CHECK);

    label = new Label(groupRoll, SWT.NONE);
    label.setText("Roll (°):");

    rollText = new Text(groupRoll, SWT.BORDER);
    rollText.setEditable(false);
    rollText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    label = new Label(groupPitch, SWT.NONE);
    label.setText("Lock Pitch:");

    lockPitch = new Button(groupPitch, SWT.CHECK);

    label = new Label(groupPitch, SWT.NONE);
    label.setText("Pitch (°):");

    pitchText = new Text(groupPitch, SWT.BORDER);
    pitchText.setEditable(false);
    pitchText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    label = new Label(groupRoll, SWT.NONE);
    label.setText("Max Roll (°):");

    rollMax = new Text(groupRoll, SWT.BORDER);
    rollMax.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    rollMax.addFocusListener(
        new FocusListener() {

          @Override
          public void focusLost(FocusEvent e) {
            String value = ((Text) e.widget).getText();
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();

            int intVal = 0;
            try {
              intVal = Integer.valueOf(value);
            } catch (NumberFormatException e1) {
              ((Text) e.widget).setText(store.getString(PreferenceConstants.P_CMD_ROLL));
            }

            if (intVal > 90 || intVal < 0)
              ((Text) e.widget).setText(store.getString(PreferenceConstants.P_CMD_ROLL));
          }

          @Override
          public void focusGained(FocusEvent arg0) {}
        });

    label = new Label(groupPitch, SWT.NONE);
    label.setText("Max Pitch (°):");

    pitchMax = new Text(groupPitch, SWT.BORDER);
    pitchMax.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    pitchMax.addFocusListener(
        new FocusListener() {

          @Override
          public void focusLost(FocusEvent e) {
            String value = ((Text) e.widget).getText();
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();

            int intVal = 0;
            try {
              intVal = Integer.valueOf(value);
            } catch (NumberFormatException e1) {
              ((Text) e.widget).setText(store.getString(PreferenceConstants.P_CMD_PITCH));
            }

            if (intVal > 90 || intVal < 0)
              ((Text) e.widget).setText(store.getString(PreferenceConstants.P_CMD_PITCH));
          }

          @Override
          public void focusGained(FocusEvent arg0) {}
        });

    final Composite buttons = new Composite(data, SWT.NONE);
    buttons.setLayout(new GridLayout(2, true));
    buttons.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    final Button recordBtn = new Button(buttons, SWT.TOGGLE);
    recordBtn.addListener(
        SWT.Selection,
        new Listener() {

          @Override
          public void handleEvent(Event event) {
            if (recordBtn.getSelection()) TelemetryDataSingleton.getInstance().setLogEnabled(true);
            else TelemetryDataSingleton.getInstance().setLogEnabled(false);

            recordBtn.setSelection(TelemetryDataSingleton.getInstance().getLogEnabled());

            logger.logInfo(
                "Data recording " + (recordBtn.getSelection() ? "enabled." : "disabled."),
                this.getClass());
          }
        });
    recordBtn.setImage(
        PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_STOP));
    recordBtn.setLayoutData(new GridData(GridData.FILL_BOTH));
    recordBtn.setToolTipText("Record telemetry to file.");

    final Button enableBtn = new Button(buttons, SWT.TOGGLE);
    enableBtn.addListener(
        SWT.Selection,
        new Listener() {

          @Override
          public void handleEvent(Event event) {
            if (enableBtn.getSelection()) commandThread.setPause(true);
            else commandThread.setPause(false);

            recordBtn.setSelection(TelemetryDataSingleton.getInstance().getLogEnabled());

            if (enableBtn.getSelection())
              logger.logInfo("Command data sent enabled.", this.getClass());
            else logger.logWarning("Command data sent disabled.", this.getClass());
          }
        });
    enableBtn.setImage(
        PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_COLLAPSEALL));
    enableBtn.setLayoutData(new GridData(GridData.FILL_BOTH));
    enableBtn.setToolTipText("Enable command data sent.");

    canvas.setToolTipText("Pitch [left] & Roll [right] Commands.");
    canvas.addPaintListener(
        new PaintListener() {

          @Override
          public void paintControl(PaintEvent e) {
            // Get the canvas for drawing and its width and height
            Canvas canvas = (Canvas) e.widget;

            int width = canvas.getSize().x;
            int height = canvas.getSize().y - comp.getBorderWidth();

            drawAttitudeControls(e.gc, width, height);
          }
        });

    canvas.addMouseListener(
        new MouseListener() {

          @Override
          public void mouseUp(MouseEvent e) {
            enable = false;
            roll = 0;
            pitch = 0;

            update();
          }

          @Override
          public void mouseDown(MouseEvent e) {
            enable = true;
            prevX = e.x;
            prevY = e.y;
          }

          @Override
          public void mouseDoubleClick(MouseEvent e) {
            if (enableDoubleClick) {
              enableDoubleClick = false;
              roll = 0;
              pitch = 0;

              update();
            } else enableDoubleClick = true;
          }
        });

    canvas.addMouseMoveListener(
        new MouseMoveListener() {

          private float pitchAngleStep;
          private float rollAngleStep;

          @Override
          public void mouseMove(MouseEvent e) {

            if (enable || enableDoubleClick) {
              int maxRoll = Integer.valueOf(rollMax.getText());
              int maxPitch = Integer.valueOf(pitchMax.getText());

              // Calculate deltas and scale value
              rollAngleStep = Math.abs(e.x - prevX) * 0.5f;
              pitchAngleStep = Math.abs(e.y - prevY) * 1.5f;

              if (roll >= maxRoll) {
                roll = maxRoll;
              } else if (roll <= -maxRoll) {
                roll = -maxRoll;
              }

              if (pitch >= maxPitch) {
                pitch = maxPitch;
              } else if (pitch <= -maxPitch) {
                pitch = -maxPitch;
              }

              if (e.x < prevX && !lockRoll.getSelection()) roll -= rollAngleStep;
              else if (e.x > prevX && !lockRoll.getSelection()) roll += rollAngleStep;
              else if (e.y < prevY && !lockPitch.getSelection()) pitch -= pitchAngleStep;
              else if (e.y > prevY && !lockPitch.getSelection()) pitch += pitchAngleStep;

              prevX = e.x;
              prevY = e.y;

              update();
            }
          }
        });

    updateFromPreferences();
  }