コード例 #1
0
  public void setActions(IAction[] actions) {
    if (actions != null) {
      if (toolbar != null) {
        while (toolbar.getItemCount() > 0) {
          ToolItem item = toolbar.getItem(0);
          IAction action = (IAction) actionMap.get(item);
          if (action != null) action.removePropertyChangeListener(this);
          item.dispose();
        }
        actionMap.clear();
        toolbar.dispose();
      }

      toolbar = new ToolBar(label, SWT.FLAT);
      toolbar.setBackground(gbg);
      GridData gd = new GridData();
      gd.grabExcessHorizontalSpace = true;
      gd.horizontalAlignment = SWT.END;
      gd.grabExcessVerticalSpace = true;
      gd.verticalAlignment = SWT.CENTER;
      toolbar.setLayoutData(gd);

      for (int i = 0; i < actions.length; i++) {
        IAction action = actions[i];
        int flags = SWT.PUSH;
        if (action != null) {
          int style = action.getStyle();
          if (style == IAction.AS_CHECK_BOX) {
            flags = SWT.CHECK;
          } else if (style == IAction.AS_RADIO_BUTTON) {
            flags = SWT.RADIO;
          } else if (style == IAction.AS_DROP_DOWN_MENU) {
            flags = SWT.DROP_DOWN;
          }
        }
        ToolItem item = new ToolItem(toolbar, flags);
        item.addListener(SWT.Selection, getToolItemListener());
        action.addPropertyChangeListener(this);
        actionMap.put(item, action);
      }
      updateToolBar();
      label.layout();
    } else {
      if (toolbar != null) {
        toolbar.dispose();
        toolbar = null;
      }
    }
  }
コード例 #2
0
ファイル: Flight.java プロジェクト: lucdono/xbladecopter
  public static void updateFlight() {
    try {
      if (!sensorData.isDisposed() && sensorData.isVisible()) {
        rollText.setText(String.format("%3.3f", rpy.getRoll()));
        pitchText.setText(String.format("%3.3f", rpy.getPitch()));
        headingText.setText(String.format("%3.3f", rpy.getHeading()));

        accXText.setText(String.format("%3.3f", rpy.getAccX()));
        accYText.setText(String.format("%3.3f", rpy.getAccY()));
        accZText.setText(String.format("%3.3f", rpy.getAccZ()));

        awXText.setText(String.format("%3.3f", rpy.getGyroX()));
        awYText.setText(String.format("%3.3f", rpy.getGyroY()));
        awZText.setText(String.format("%3.3f", rpy.getGyroZ()));

        magXText.setText(String.format("%3.3f", rpy.getMagX()));
        magYText.setText(String.format("%3.3f", rpy.getMagY()));
        magZText.setText(String.format("%3.3f", rpy.getMagZ()));

        if (rpy.getM3() <= 100 && rpy.getM3() >= 0) {
          gM1.setBackground(
              new Color[] {
                Display.getDefault().getSystemColor(SWT.COLOR_GREEN),
                Display.getDefault().getSystemColor(SWT.COLOR_YELLOW),
                Display.getDefault().getSystemColor(SWT.COLOR_RED)
              },
              new int[] {(int) (100 - rpy.getM3()), 100});
          m1Text.setText(String.format("%3.1f", rpy.getM3()));
          gM1.layout();
        }

        if (rpy.getM2() <= 100 && rpy.getM2() >= 0) {
          gM0.setBackground(
              new Color[] {
                Display.getDefault().getSystemColor(SWT.COLOR_GREEN),
                Display.getDefault().getSystemColor(SWT.COLOR_YELLOW),
                Display.getDefault().getSystemColor(SWT.COLOR_RED)
              },
              new int[] {(int) (100 - rpy.getM2()), 100});
          m0Text.setText(String.format("%3.1f", rpy.getM2()));
          gM0.layout();
        }

        if (rpy.getM0() <= 100 && rpy.getM0() >= 0) {
          gM3.setBackground(
              new Color[] {
                Display.getDefault().getSystemColor(SWT.COLOR_GREEN),
                Display.getDefault().getSystemColor(SWT.COLOR_YELLOW),
                Display.getDefault().getSystemColor(SWT.COLOR_RED)
              },
              new int[] {(int) (100 - rpy.getM0()), 100});
          m3Text.setText(String.format("%3.1f", rpy.getM0()));
          gM3.layout();
        }

        if (rpy.getM1() <= 100 && rpy.getM1() >= 0) {
          gM2.setBackground(
              new Color[] {
                Display.getDefault().getSystemColor(SWT.COLOR_GREEN),
                Display.getDefault().getSystemColor(SWT.COLOR_YELLOW),
                Display.getDefault().getSystemColor(SWT.COLOR_RED)
              },
              new int[] {(int) (100 - rpy.getM1()), 100});
          m2Text.setText(String.format("%3.1f", rpy.getM1()));
          gM2.layout();
        }
      }
    } catch (Exception e) {
    }
  }