Пример #1
0
  /**
   * Create buttons enumerated in <code>ZoomType</code>
   *
   * @param flags Bitwise 'or' of flags
   * @see XYGraphFlags#COMBINED_ZOOM
   * @see XYGraphFlags#SEPARATE_ZOOM
   */
  private void createZoomButtons(final int flags) {
    for (final ZoomType zoomType : ZoomType.values()) {
      if (!zoomType.useWithFlags(flags)) continue;
      final ImageFigure imageFigure = new ImageFigure(zoomType.getIconImage());
      final Label tip = new Label(zoomType.getDescription());
      final ToggleButton button = new ToggleButton(imageFigure);
      button.setBackgroundColor(ColorConstants.button);
      button.setOpaque(true);
      final ToggleModel model = new ToggleModel();
      model.addChangeListener(
          new ChangeListener() {
            public void handleStateChanged(ChangeEvent event) {
              if (event.getPropertyName().equals("selected") && button.isSelected()) {
                xyGraph.setZoomType(zoomType);
              }
            }
          });

      button.setModel(model);
      zoomButtonModelMap.put(zoomType, model);
      button.setToolTip(tip);
      addButton(button);
      zoomGroup.add(model);

      if (zoomType == ZoomType.NONE) zoomGroup.setDefault(model);
    }
    xyGraph.addPropertyChangeListener(
        IXYGraph.PROPERTY_ZOOMTYPE,
        new PropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            zoomGroup.setSelected(zoomButtonModelMap.get(evt.getNewValue()));
          }
        });
  }
Пример #2
0
  /**
   * Initialize
   *
   * @param xyGraph XYGraph on which this toolbar operates
   * @param flags Bitwise 'or' of flags
   * @see XYGraphFlags#COMBINED_ZOOM
   * @see XYGraphFlags#SEPARATE_ZOOM
   */
  public XYGraphToolbar(final XYGraph xyGraph, final int flags) {
    this.xyGraph = xyGraph;
    setLayoutManager(new WrappableToolbarLayout());

    final Button configButton =
        new Button(XYGraphMediaFactory.getInstance().getImage("images/Configure.png"));
    configButton.setToolTip(new Label("Configure Settings..."));
    addButton(configButton);
    configButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            XYGraphConfigDialog dialog =
                new XYGraphConfigDialog(Display.getCurrent().getActiveShell(), xyGraph);
            dialog.open();
          }
        });

    final Button addAnnotationButton =
        new Button(XYGraphMediaFactory.getInstance().getImage("images/Add_Annotation.png"));
    addAnnotationButton.setToolTip(new Label("Add Annotation..."));
    addButton(addAnnotationButton);
    addAnnotationButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            AddAnnotationDialog dialog =
                new AddAnnotationDialog(Display.getCurrent().getActiveShell(), xyGraph);
            if (dialog.open() == Window.OK) {
              xyGraph.addAnnotation(dialog.getAnnotation());
              xyGraph
                  .getOperationsManager()
                  .addCommand(new AddAnnotationCommand(xyGraph, dialog.getAnnotation()));
            }
          }
        });

    final Button delAnnotationButton =
        new Button(XYGraphMediaFactory.getInstance().getImage("images/Del_Annotation.png"));
    delAnnotationButton.setToolTip(new Label("Remove Annotation..."));
    addButton(delAnnotationButton);
    delAnnotationButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            RemoveAnnotationDialog dialog =
                new RemoveAnnotationDialog(Display.getCurrent().getActiveShell(), xyGraph);
            if (dialog.open() == Window.OK && dialog.getAnnotation() != null) {
              xyGraph.removeAnnotation(dialog.getAnnotation());
              xyGraph
                  .getOperationsManager()
                  .addCommand(new RemoveAnnotationCommand(xyGraph, dialog.getAnnotation()));
            }
          }
        });

    addSeparator();
    if ((flags & XYGraphFlags.STAGGER) > 0) { // stagger axes button
      final Button staggerButton =
          new Button(XYGraphMediaFactory.getInstance().getImage("images/stagger.png"));
      staggerButton.setToolTip(new Label("Stagger axes so they don't overlap"));
      addButton(staggerButton);
      staggerButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              xyGraph.performStagger();
            }
          });
    } else { // auto scale button
      final Button autoScaleButton =
          new Button(XYGraphMediaFactory.getInstance().getImage("images/AutoScale.png"));
      autoScaleButton.setToolTip(new Label("Perform Auto Scale"));
      addButton(autoScaleButton);
      autoScaleButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              xyGraph.performAutoScale();
            }
          });
    }

    // Allow to turn on/off the axis trace and the value labels using the same button
    if (Preferences.isCombineLabelsAndTraces()) {
      final ToggleButton valueLabelsButton =
          new ToggleButton(
              new ImageFigure(
                  XYGraphMediaFactory.getInstance().getImage("images/HoverLabels.png")));
      valueLabelsButton.setBackgroundColor(ColorConstants.button);
      valueLabelsButton.setOpaque(true);
      final ToggleModel valueLabelsModel = new ToggleModel();
      valueLabelsModel.addChangeListener(
          new ChangeListener() {
            public void handleStateChanged(ChangeEvent event) {
              if (event.getPropertyName().equals("selected")) {
                xyGraph.setShowValueLabels(valueLabelsButton.isSelected());
                xyGraph.setShowAxisTrace(valueLabelsButton.isSelected());
              }
            }
          });
      xyGraph.addPropertyChangeListener(
          "showValueLabels",
          new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
              xyGraph.setShowAxisTrace(xyGraph.isShowValueLabels());
              valueLabelsModel.setSelected(xyGraph.isShowValueLabels());
            }
          });
      xyGraph.addPropertyChangeListener(
          "showAxisTrace",
          new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
              xyGraph.setShowValueLabels(xyGraph.isShowAxisTrace());
              valueLabelsModel.setSelected(xyGraph.isShowAxisTrace());
            }
          });
      valueLabelsModel.setSelected(xyGraph.isShowValueLabels());
      valueLabelsButton.setModel(valueLabelsModel);
      valueLabelsButton.setToolTip(new Label(Messages.HoverLabels));
      addButton(valueLabelsButton);
    } else {
      final ToggleButton valueLabelsButton =
          new ToggleButton(
              new ImageFigure(
                  XYGraphMediaFactory.getInstance().getImage("images/HoverLabels.png")));
      valueLabelsButton.setBackgroundColor(ColorConstants.button);
      valueLabelsButton.setOpaque(true);
      final ToggleModel valueLabelsModel = new ToggleModel();
      valueLabelsModel.addChangeListener(
          new ChangeListener() {
            public void handleStateChanged(ChangeEvent event) {
              if (event.getPropertyName().equals("selected")) {
                xyGraph.setShowValueLabels(valueLabelsButton.isSelected());
              }
            }
          });
      xyGraph.addPropertyChangeListener(
          "showValueLabels",
          new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
              valueLabelsModel.setSelected(xyGraph.isShowValueLabels());
            }
          });
      valueLabelsModel.setSelected(xyGraph.isShowValueLabels());
      valueLabelsButton.setModel(valueLabelsModel);
      valueLabelsButton.setToolTip(new Label(Messages.HoverLabels));
      addButton(valueLabelsButton);

      final ToggleButton axisTraceButton =
          new ToggleButton(
              new ImageFigure(XYGraphMediaFactory.getInstance().getImage("images/AxisTrace.png")));
      axisTraceButton.setBackgroundColor(ColorConstants.button);
      axisTraceButton.setOpaque(true);
      final ToggleModel axisTraceModel = new ToggleModel();
      axisTraceModel.addChangeListener(
          new ChangeListener() {
            public void handleStateChanged(ChangeEvent event) {
              if (event.getPropertyName().equals("selected")) {
                xyGraph.setShowAxisTrace(axisTraceButton.isSelected());
              }
            }
          });
      xyGraph.addPropertyChangeListener(
          "showAxisTrace",
          new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
              axisTraceModel.setSelected(xyGraph.isShowAxisTrace());
            }
          });
      axisTraceModel.setSelected(xyGraph.isShowAxisTrace());
      axisTraceButton.setModel(axisTraceModel);
      axisTraceButton.setToolTip(new Label(Messages.AxisTrace));
      addButton(axisTraceButton);
    }

    // zoom buttons
    addSeparator();
    zoomGroup = new ButtonGroup();
    createZoomButtons(flags);

    addSeparator();
    addUndoRedoButtons();

    addSeparator();
    if (!SWT.getPlatform().startsWith("rap")) // $NON-NLS-1$
    addSnapshotButton();
  }