コード例 #1
0
    public Setting(Composite comp, String title) {
      final Composite settingComp = new Composite(comp, SWT.BORDER);
      settingComp.setLayout(new FillLayout(SWT.VERTICAL));

      final RowLayout infoLayout = new RowLayout();
      infoLayout.center = true;

      final Composite infoComp = new Composite(settingComp, SWT.NONE);
      infoComp.setLayout(infoLayout);

      final Label settingLabel = new Label(infoComp, SWT.CENTER);
      settingLabel.setText(title);

      settingValue = new Text(infoComp, SWT.BORDER | SWT.SINGLE);
      settingValue.setText("000");

      settingScale = new Scale(settingComp, SWT.BORDER);
      settingScale.setSize(200, 64);
      settingScale.setMaximum(50);
      settingScale.addListener(
          SWT.Selection,
          new Listener() {
            @Override
            public void handleEvent(Event e) {
              settingValue.setText("" + settingScale.getSelection());
            }
          });
    }
コード例 #2
0
 public void addListener() {
   settingScale.addListener(
       SWT.Selection,
       new Listener() {
         @Override
         public void handleEvent(Event arg0) {}
       });
 }
コード例 #3
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);
  }
コード例 #4
0
ファイル: Command.java プロジェクト: lucdono/xbladecopter
  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();
  }