예제 #1
0
 private void setRulerVisibility(boolean isVisible) {
   if (isRulerVisible != isVisible) {
     isRulerVisible = isVisible;
     if (diagramViewer != null) {
       setRuler(
           (RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER),
           PositionConstants.NORTH);
       setRuler(
           (RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_VERTICAL_RULER),
           PositionConstants.WEST);
     }
   }
 }
예제 #2
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);
    ScrollBar horizontalBar = editor.getHorizontalBar();
    if (horizontalBar != null) {
      horizontalBar.addListener(SWT.Show, layoutListener);
      horizontalBar.addListener(SWT.Hide, layoutListener);
    }
    ScrollBar verticalBar = editor.getVerticalBar();
    if (verticalBar != null) {
      verticalBar.addListener(SWT.Show, layoutListener);
      verticalBar.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);
  }