private void reposition(int x, int y, int width, int height) {
   if (y == 0) {
     y = Y;
     x = X;
   }
   Rectangle constraints = new Rectangle(x, y, width, height);
   ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), constraints);
   FigureCanvas canvas = (FigureCanvas) getViewer().getControl();
   canvas.getViewport().repaint();
 }
  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;
  }
 public void notifyChanged(Notification notification) {
   super.notifyChanged(notification);
   if (notification.getFeature() instanceof EAttributeImpl) {
     if (notification.getNotifier() instanceof BoundsImpl) {
       reposition(
           ((BoundsImpl) notification.getNotifier()).getX(),
           ((BoundsImpl) notification.getNotifier()).getY(),
           ((BoundsImpl) notification.getNotifier()).getWidth(),
           ((BoundsImpl) notification.getNotifier()).getHeight());
       FigureCanvas canvas = (FigureCanvas) getViewer().getControl();
       canvas.getViewport().repaint();
     }
   }
 }
 public RotationButtonComposite(
     Composite parent, int direction, String lblText, boolean ctrlPressRequired) {
   super(parent, SWT.None);
   this.direction = direction;
   this.lblText = lblText;
   this.ctrlPressRequired = ctrlPressRequired;
   GridLayout layout = new GridLayout();
   layout.marginHeight = 0;
   layout.marginWidth = 0;
   setLayout(layout);
   this.setBackground(ColorConstants.white);
   figCanvas = new FigureCanvas(this);
   figCanvas.setContents(getContents());
   figCanvas.getViewport().setContentsTracksHeight(true);
   figCanvas.getViewport().setContentsTracksWidth(true);
   figCanvas.setLayoutData(new GridData(GridData.FILL_BOTH));
   figCanvas.setBorder(new LineBorder(1));
 }
Example #5
0
 protected void layoutFigures(FigureCanvas fc) {
   Rectangle r = new Rectangle(fc.getViewport().getClientArea());
   if (vertical) r.transpose();
   Dimension size = blockFigure.getPreferredSize();
   Rectangle b =
       new Rectangle(
           r.x + size.width / 2,
           r.y + (r.height - SLOT_HEIGHT) / 2,
           r.width - size.width,
           SLOT_HEIGHT);
   int x = (int) (b.x + b.width * selectionRatio);
   int y = b.y + b.height - b.height / 2;
   Rectangle b2 = new Rectangle(x - size.width / 2, y - size.height / 2, size.width, size.height);
   if (vertical) {
     b.transpose();
     b2.transpose();
   }
   slotFigure.setBounds(b);
   blockFigure.setBounds(b2);
 }