Ejemplo n.º 1
0
  private void initialize() {
    nameText.setText(annotation.getName());
    nameText.setSelection(0, nameText.getText().length());
    snapToTrace.setSelection(!annotation.isFree());
    xAxisLabel.setText(
        snapToTrace.getSelection() ? Messages.Annotation_Trace : Messages.Annotation_XAxis);
    xAxisOrTraceCombo.removeAll();
    if (!annotation.isFree()) {
      for (Trace trace : xyGraph.getPlotArea().getTraceList())
        xAxisOrTraceCombo.add(trace.getName());
      xAxisOrTraceCombo.select(xyGraph.getPlotArea().getTraceList().indexOf(annotation.getTrace()));
    } else {
      for (Axis axis : xyGraph.getXAxisList()) xAxisOrTraceCombo.add(axis.getTitle());
      xAxisOrTraceCombo.select(xyGraph.getXAxisList().indexOf(annotation.getXAxis()));
    }
    for (Axis axis : xyGraph.getYAxisList()) yAxisCombo.add(axis.getTitle());
    yAxisCombo.select(xyGraph.getYAxisList().indexOf(annotation.getYAxis()));
    yAxisLabel.setVisible(!snapToTrace.getSelection());
    yAxisCombo.setVisible(!snapToTrace.getSelection());
    useDefaultColorButton.setSelection(annotation.getAnnotationColor() == null);
    colorLabel.setVisible(!useDefaultColorButton.getSelection());
    colorSelector.getButton().setVisible(annotation.getAnnotationColor() != null);
    colorSelector.setColorValue(
        annotation.getAnnotationColor() == null
            ? annotation.getYAxis().getForegroundColor().getRGB()
            : annotation.getAnnotationColor().getRGB());

    fontLabel.setText(
        Messages.Annotation_Font
            + (font == null ? Messages.Annotation_SystemDefault : font.getFontData()[0].getName()));
    fontLabel.setFont(font);
    cursorLineCombo.select(annotation.getCursorLineStyle().getIndex());
    showNameButton.setSelection(annotation.isShowName());
    showSampleInfoButton.setSelection(annotation.isShowSampleInfo());
    showPositionButton.setSelection(annotation.isShowPosition());
  }
Ejemplo n.º 2
0
  public XYGraphTest() {

    xyGraph = new XYGraph();
    xyGraph.setTitle("XY Graph Test");
    xyGraph.setFont(XYGraphMediaFactory.getInstance().getFont(XYGraphMediaFactory.FONT_TAHOMA));
    xyGraph.primaryXAxis.setTitle("Time");
    xyGraph.primaryYAxis.setTitle("Amplitude");
    xyGraph.primaryXAxis.setRange(new Range(0, 200));
    xyGraph.primaryXAxis.setDateEnabled(true);
    xyGraph.primaryYAxis.setAutoScale(true);
    xyGraph.primaryXAxis.setAutoScale(true);
    xyGraph.primaryXAxis.setShowMajorGrid(true);
    xyGraph.primaryYAxis.setShowMajorGrid(true);
    xyGraph.primaryXAxis.setAutoScaleThreshold(0);

    final Axis x2Axis = new Axis("X-2", false);
    x2Axis.setTickLableSide(LabelSide.Secondary);
    // x2Axis.setAutoScale(true);
    xyGraph.addAxis(x2Axis);

    final Axis y2Axis = new Axis("Log Scale", true);
    y2Axis.setRange(10, 500);
    y2Axis.setLogScale(true);
    // y2Axis.setAutoScale(true);
    y2Axis.setForegroundColor(
        XYGraphMediaFactory.getInstance().getColor(XYGraphMediaFactory.COLOR_PINK));
    y2Axis.setTickLableSide(LabelSide.Secondary);
    xyGraph.addAxis(y2Axis);

    Axis y3Axis = new Axis("Y-3", true);
    y3Axis.setForegroundColor(
        XYGraphMediaFactory.getInstance().getColor(XYGraphMediaFactory.COLOR_BLUE));
    y3Axis.setTickLableSide(LabelSide.Secondary);
    y3Axis.setRange(new Range(-2, 3));
    y3Axis.setShowMajorGrid(false);
    y3Axis.setAutoScale(true);
    //		xyGraph.addAxis(y3Axis);

    trace2Provider = new CircularBufferDataProvider(true);
    trace2Provider.setBufferSize(100);
    trace2Provider.setUpdateDelay(100);

    trace2 = new Trace("Trace 2", xyGraph.primaryXAxis, xyGraph.primaryYAxis, trace2Provider);
    trace2.setDataProvider(trace2Provider);
    trace2.setTraceType(TraceType.SOLID_LINE);
    trace2.setLineWidth(1);
    trace2.setPointStyle(PointStyle.POINT);
    trace2.setPointSize(4);
    trace2.setBaseLine(BaseLine.NEGATIVE_INFINITY);
    trace2.setAreaAlpha(100);
    trace2.setAntiAliasing(true);
    trace2.setErrorBarEnabled(false);
    // trace2.setDrawYErrorInArea(true);
    trace2.setYErrorBarType(ErrorBarType.BOTH);
    trace2.setXErrorBarType(ErrorBarType.NONE);
    trace2.setErrorBarCapWidth(3);

    final CircularBufferDataProvider trace3Provider = new CircularBufferDataProvider(true);
    trace3 = new Trace("Trace3", xyGraph.primaryXAxis, xyGraph.primaryYAxis, trace3Provider);
    trace3.setPointStyle(PointStyle.XCROSS);
    trace3.setTraceType(TraceType.BAR);
    trace3.setLineWidth(4);
    trace3Provider.setUpdateDelay(100);
    xyGraph.addTrace(trace3);
    xyGraph.addTrace(trace2);

    final CircularBufferDataProvider trace4Provider = new CircularBufferDataProvider(false);
    trace4 = new Trace("Trace 4-Lissajous", x2Axis, y2Axis, trace4Provider);
    //		trace4.setPointStyle(PointStyle.POINT);
    trace4.setPointSize(2);

    trace4Provider.setUpdateDelay(100);
    trace4Provider.setBufferSize(100);
    xyGraph.addTrace(trace4);

    toolbarArmedXYGraph = new ToolbarArmedXYGraph(xyGraph);
    add(toolbarArmedXYGraph);

    // add key listener to XY-Graph. The key pressing will only be monitored when the
    // graph gains focus.

    xyGraph.setFocusTraversable(true);
    xyGraph.setRequestFocusEnabled(true);

    xyGraph
        .getPlotArea()
        .addMouseListener(
            new MouseListener.Stub() {
              @Override
              public void mousePressed(final MouseEvent me) {
                xyGraph.requestFocus();
              }
            });

    xyGraph.addKeyListener(
        new KeyListener.Stub() {
          @Override
          public void keyPressed(final KeyEvent ke) {
            if ((ke.getState() == SWT.CONTROL) && (ke.keycode == 'z')) {
              xyGraph.getOperationsManager().undo();
            }
            if ((ke.getState() == SWT.CONTROL) && (ke.keycode == 'y')) {
              xyGraph.getOperationsManager().redo();
            }
            if ((ke.getState() == SWT.CONTROL) && (ke.keycode == 'x')) {
              xyGraph.performAutoScale();
            }
            if ((ke.getState() == SWT.CONTROL) && (ke.keycode == 's')) {
              final ImageLoader loader = new ImageLoader();
              loader.data = new ImageData[] {xyGraph.getImage().getImageData()};
              final FileDialog dialog =
                  new FileDialog(Display.getDefault().getShells()[0], SWT.SAVE);
              dialog.setFilterNames(new String[] {"PNG Files", "All Files (*.*)"});
              dialog.setFilterExtensions(new String[] {"*.png", "*.*"}); // Windows
              final String path = dialog.open();
              if ((path != null) && !path.equals("")) {
                loader.save(path, SWT.IMAGE_PNG);
              }
            }
            if ((ke.getState() == SWT.CONTROL) && (ke.keycode + 'a' - 97 == 't')) {
              switch (xyGraph.getZoomType()) {
                case RUBBERBAND_ZOOM:
                  xyGraph.setZoomType(ZoomType.HORIZONTAL_ZOOM);
                  break;
                case HORIZONTAL_ZOOM:
                  xyGraph.setZoomType(ZoomType.VERTICAL_ZOOM);
                  break;
                case VERTICAL_ZOOM:
                  xyGraph.setZoomType(ZoomType.ZOOM_IN);
                  break;
                case ZOOM_IN:
                  xyGraph.setZoomType(ZoomType.ZOOM_OUT);
                  break;
                case ZOOM_OUT:
                  xyGraph.setZoomType(ZoomType.PANNING);
                  break;
                case PANNING:
                  xyGraph.setZoomType(ZoomType.NONE);
                  break;
                case NONE:
                  xyGraph.setZoomType(ZoomType.RUBBERBAND_ZOOM);
                  break;
                default:
                  break;
              }
            }
          }
        });

    updater =
        new Runnable() {
          public void run() {
            t += 60000;
            trace3Provider.setCurrentYData(Math.cos(updateIndex), t);
            if (((updateIndex >= 10) && (updateIndex <= 10.5))
                || ((updateIndex >= 20) && (updateIndex <= 20.2))) {
              trace2Provider.addSample(new Sample(t, Double.NaN));
              running = false;
            } else {
              final Sample sampe =
                  new Sample(
                      t,
                      Math.sin(updateIndex),
                      0.1 * Math.random(),
                      0.1 * Math.random(),
                      t * 0.0000001 * Math.random(),
                      t * 0.0000001 * Math.random(),
                      "sdfsf");
              trace2Provider.addSample(sampe);
            }

            trace2Provider.setCurrentYDataTimestamp(t);
            trace4Provider.setCurrentXData(Math.sin(updateIndex + 10) * 20 + 50);
            trace4Provider.setCurrentYData(Math.cos(updateIndex) * 30 + 50);
            updateIndex += 0.1;

            if (running) {
              Display.getCurrent().timerExec(100, this);
            }
          }
        };

    Display.getCurrent().timerExec(100, updater);
    running = true;
    t = Calendar.getInstance().getTimeInMillis();
  }