예제 #1
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;
  }
예제 #2
0
 private void disposeRulerViewer(GraphicalViewer viewer) {
   if (viewer == null) return;
   /*
    * There's a tie from the editor's range model to the RulerViewport (via a listener)
    * to the RulerRootEditPart to the RulerViewer.  Break this tie so that the viewer
    * doesn't leak and can be garbage collected.
    */
   RangeModel rModel = new DefaultRangeModel();
   Viewport port = ((FigureCanvas) viewer.getControl()).getViewport();
   port.setHorizontalRangeModel(rModel);
   port.setVerticalRangeModel(rModel);
   rulerEditDomain.removeViewer(viewer);
   viewer.getControl().dispose();
 }