Example #1
0
  /**
   * Creates rulers for the given graphical viewer.
   *
   * <p>The primaryViewer or its Control cannot be <code>null</code>. The primaryViewer's Control
   * should be a FigureCanvas and a child of this Composite. This method should only be invoked
   * once.
   *
   * <p>To create ruler(s), simply add the RulerProvider(s) (with the right key:
   * RulerProvider.PROPERTY_HORIZONTAL_RULER or RulerProvider.PROPERTY_VERTICAL_RULER) as a property
   * on the given viewer. It can be done after this method is invoked.
   * RulerProvider.PROPERTY_RULER_VISIBILITY can be used to show/hide the rulers.
   *
   * @param primaryViewer The graphical viewer for which the rulers have to be created
   */
  public void setGraphicalViewer(ScrollingGraphicalViewer primaryViewer) {
    // pre-conditions
    Assert.isNotNull(primaryViewer);
    Assert.isNotNull(primaryViewer.getControl());
    Assert.isTrue(diagramViewer == null);

    diagramViewer = primaryViewer;
    editor = (FigureCanvas) diagramViewer.getControl();

    // layout whenever the scrollbars are shown or hidden, and whenever the RulerComposite
    // is resized
    layoutListener =
        new Listener() {
          public void handleEvent(Event event) {
            // @TODO:Pratik  If you use Display.asyncExec(runnable) here, some flashing
            // occurs.  You can see it when the palette is in the editor, and you hit
            // the button to show/hide it.
            layout(true);
          }
        };
    addListener(SWT.Resize, layoutListener);
    editor.getHorizontalBar().addListener(SWT.Show, layoutListener);
    editor.getHorizontalBar().addListener(SWT.Hide, layoutListener);
    editor.getVerticalBar().addListener(SWT.Show, layoutListener);
    editor.getVerticalBar().addListener(SWT.Hide, layoutListener);

    propertyListener =
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {
            String property = evt.getPropertyName();
            if (RulerProvider.PROPERTY_HORIZONTAL_RULER.equals(property)) {
              setRuler(
                  (RulerProvider)
                      diagramViewer.getProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER),
                  PositionConstants.NORTH);
            } else if (RulerProvider.PROPERTY_VERTICAL_RULER.equals(property)) {
              setRuler(
                  (RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_VERTICAL_RULER),
                  PositionConstants.WEST);
            } else if (RulerProvider.PROPERTY_RULER_VISIBILITY.equals(property))
              setRulerVisibility(
                  ((Boolean) diagramViewer.getProperty(RulerProvider.PROPERTY_RULER_VISIBILITY))
                      .booleanValue());
          }
        };
    diagramViewer.addPropertyChangeListener(propertyListener);
    Boolean rulerVisibility =
        (Boolean) diagramViewer.getProperty(RulerProvider.PROPERTY_RULER_VISIBILITY);
    if (rulerVisibility != null) setRulerVisibility(rulerVisibility.booleanValue());
    setRuler(
        (RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER),
        PositionConstants.NORTH);
    setRuler(
        (RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_VERTICAL_RULER),
        PositionConstants.WEST);
  }
Example #2
0
  private GraphicalViewer createRulerContainer(int orientation) {
    ScrollingGraphicalViewer viewer = new RulerViewer();
    final boolean isHorizontal =
        orientation == PositionConstants.NORTH || orientation == PositionConstants.SOUTH;

    // Finish initializing the viewer
    viewer.setRootEditPart(new RulerRootEditPart(isHorizontal));
    viewer.setEditPartFactory(new RulerEditPartFactory(diagramViewer));
    viewer.createControl(this);
    ((GraphicalEditPart) viewer.getRootEditPart())
        .getFigure()
        .setBorder(new RulerBorder(isHorizontal));
    viewer.setProperty(GraphicalViewer.class.toString(), diagramViewer);

    // Configure the viewer's control
    FigureCanvas canvas = (FigureCanvas) viewer.getControl();
    canvas.setScrollBarVisibility(FigureCanvas.NEVER);
    if (font == null) {
      FontData[] data = canvas.getFont().getFontData();
      for (int i = 0; i < data.length; i++) {
        data[i].setHeight(data[i].getHeight() - 1);
      }
      font = new Font(Display.getCurrent(), data);
    }
    canvas.setFont(font);
    if (isHorizontal) {
      canvas.getViewport().setHorizontalRangeModel(editor.getViewport().getHorizontalRangeModel());
    } else {
      canvas.getViewport().setVerticalRangeModel(editor.getViewport().getVerticalRangeModel());
    }

    // Add the viewer to the rulerEditDomain
    if (rulerEditDomain == null) {
      rulerEditDomain = new EditDomain();
      rulerEditDomain.setCommandStack(diagramViewer.getEditDomain().getCommandStack());
    }
    rulerEditDomain.addViewer(viewer);

    return viewer;
  }
Example #3
0
 /**
  * @see
  *     com.architexa.org.eclipse.gef.EditPartViewer#setContents(com.architexa.org.eclipse.gef.EditPart)
  */
 public void setContents(EditPart editpart) {
   super.setContents(editpart);
   setFocus(getContents());
 }
Example #4
0
 /**
  * Requests to reveal a ruler are ignored since that causes undesired scrolling to the origin of
  * the ruler
  *
  * @see
  *     com.architexa.org.eclipse.gef.EditPartViewer#reveal(com.architexa.org.eclipse.gef.EditPart)
  */
 public void reveal(EditPart part) {
   if (part != getContents()) super.reveal(part);
 }
Example #5
0
 /**
  * @see
  *     com.architexa.org.eclipse.gef.EditPartViewer#appendSelection(com.architexa.org.eclipse.gef.EditPart)
  */
 public void appendSelection(EditPart editpart) {
   if (editpart instanceof RootEditPart) editpart = ((RootEditPart) editpart).getContents();
   setFocus(editpart);
   super.appendSelection(editpart);
 }