Ejemplo n.º 1
0
  private static Figure createContents() {
    Figure contents = new Figure();
    XYLayout layout = new XYLayout();
    contents.setLayoutManager(layout);

    Button button = new Button("Hello World");
    layout.setConstraint(button, new Rectangle(0, 0, -1, -1));
    contents.add(button);

    button.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent actionevent) {
            setBrightness();
          }
        });

    String path = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Oryx Antelope.jpg";
    image = new Image(Display.getDefault(), path);
    imageFigure = new ImageFigure(image);

    layout.setConstraint(imageFigure, new Rectangle(0, 30, -1, -1));

    contents.add(imageFigure);

    return contents;
  }
Ejemplo n.º 2
0
 private void addSnapshotButton() {
   Button snapShotButton =
       new Button(XYGraphMediaFactory.getInstance().getImage("images/camera.png"));
   snapShotButton.setToolTip(new Label("Save Snapshot to PNG file"));
   addButton(snapShotButton);
   snapShotButton.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent event) {
           // Have valid name, so get image
           ImageLoader loader = new ImageLoader();
           Image image = xyGraph.getImage();
           loader.data = new ImageData[] {image.getImageData()};
           image.dispose();
           // Prompt for file name
           String path = SingleSourceHelper2.getImageSavePath();
           if (path == null || path.length() <= 0) return;
           // Assert *.png at end of file name
           if (!path.toLowerCase().endsWith(".png")) path = path + ".png";
           // Save
           loader.save(path, SWT.IMAGE_PNG);
         }
       });
 }
Ejemplo n.º 3
0
  public ComboBox() {
    super();
    setOpaque(true);
    setLayoutManager(new BorderLayout());
    setBackgroundColor(VisualEditorPlugin.getDefault().getColorManager().getAirColor());

    label = new Label();
    label.setBackgroundColor(ColorConstants.white);
    label.setVisible(false);
    add(label, BorderLayout.CENTER);
    label.setText("         ");

    button = new ArrowButton(Orientable.SOUTH);
    button.setBorder(null);
    button.setOpaque(false);
    button.setEnabled(false);
    button.setPreferredSize(15, 13);
    add(button, BorderLayout.RIGHT);

    setBorder(
        new SchemeBorder(
            new ButtonScheme(
                new Color[] {buttonLightest}, new Color[] {buttonDarkest, buttonDarker})));
  }
Ejemplo n.º 4
0
  /**
   * Use {@link #XYGraphToolbar(IXYGraph, int)} instead<br>
   * Initialize
   *
   * @param xyGraph XYGraph on which this toolbar operates
   * @param flags Bitwise 'or' of flags
   * @see XYGraphFlags#COMBINED_ZOOM
   * @see XYGraphFlags#SEPARATE_ZOOM
   */
  @Deprecated
  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();
            }
          });
    }

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

    addSeparator();
    addUndoRedoButtons();

    addSeparator();
    if (!SWT.getPlatform().startsWith("rap")) // $NON-NLS-1$
    addSnapshotButton();
  }
Ejemplo n.º 5
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();
  }