Ejemplo n.º 1
0
  /**
   * Given a label figure object, this will calculate the correct Font needed to display into screen
   * coordinates, taking into account the current mapmode. This will typically be used by direct
   * edit cell editors that need to display independent of the zoom or any coordinate mapping that
   * is taking place on the drawing surface.
   *
   * @param label the label to use for the font calculation
   * @return the <code>Font</code> that is scaled to the screen coordinates. Note: the returned
   *     <code>Font</code> should not be disposed since it is cached by a common resource manager.
   */
  protected Font getScaledFont(IFigure label) {
    Font scaledFont = label.getFont();
    FontData data = scaledFont.getFontData()[0];
    Dimension fontSize = new Dimension(0, MapModeUtil.getMapMode(label).DPtoLP(data.getHeight()));
    label.translateToAbsolute(fontSize);

    if (Math.abs(data.getHeight() - fontSize.height) < 2) fontSize.height = data.getHeight();

    try {
      FontDescriptor fontDescriptor = FontDescriptor.createFrom(data);
      cachedFontDescriptors.add(fontDescriptor);
      return getResourceManager().createFont(fontDescriptor);
    } catch (DeviceResourceException e) {
      Trace.catching(
          DiagramUIPlugin.getInstance(),
          DiagramUIDebugOptions.EXCEPTIONS_CATCHING,
          getClass(),
          "getScaledFont",
          e); //$NON-NLS-1$
      Log.error(
          DiagramUIPlugin.getInstance(),
          DiagramUIStatusCodes.IGNORED_EXCEPTION_WARNING,
          "getScaledFont",
          e); //$NON-NLS-1$
    }
    return JFaceResources.getDefaultFont();
  }
  /**
   * Given an absolute point (pStart) and a list of EditParts, this method finds the closest
   * EditPart (except for the one to be excluded) in the given direction.
   *
   * @param siblings List of sibling EditParts
   * @param pStart The starting point (must be in absolute coordinates) from which the next sibling
   *     is to be found.
   * @param direction PositionConstants
   * @param exclude The EditPart to be excluded from the search
   */
  public IGraphicalEntityPart findSibling(
      List<?> siblings, Point pStart, int direction, EditPart exclude) {
    IGraphicalEntityPart epCurrent;
    IGraphicalEntityPart epFinal = null;
    IFigure figure;
    Point pCurrent;
    int distance = Integer.MAX_VALUE;

    Iterator<?> iter = siblings.iterator();
    while (iter.hasNext()) {
      epCurrent = (IGraphicalEntityPart) iter.next();
      if (epCurrent == exclude || !epCurrent.isSelectable()) continue;
      figure = epCurrent.getFigure();
      pCurrent = getNavigationPoint(figure);
      figure.translateToAbsolute(pCurrent);
      if (pStart.getPosition(pCurrent) != direction) continue;

      Dimension difference = pCurrent.getDifference(pStart);
      int d = Math.abs(difference.width()) + Math.abs(difference.height());
      if (d < distance) {
        distance = d;
        epFinal = epCurrent;
      }
    }
    return epFinal;
  }
Ejemplo n.º 3
0
 @Override
 protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
   Dimension d = getLayoutData().getSize();
   Insets insets = container.getInsets();
   d = new Dimension(d.width + insets.getWidth(), d.height + insets.getHeight());
   return d.union(getBorderPreferredSize(container));
 }
Ejemplo n.º 4
0
 @Override
 protected Dimension calculatePreferredSize(IFigure container, int w, int h) {
   Insets insets = container.getInsets();
   Dimension d = new Dimension(64, 4 * 64);
   d.expand(insets.getWidth(), insets.getHeight());
   return d;
 }
  @Override
  protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
    Insets insets = container.getInsets();
    if (isHorizontal()) {
      wHint = -1;
      if (hHint >= 0) {
        hHint = Math.max(0, hHint - insets.getHeight());
      }
    } else {
      hHint = -1;
      if (wHint >= 0) {
        wHint = Math.max(0, wHint - insets.getWidth());
      }
    }

    List children = container.getChildren();
    Dimension prefSize = calculateChildrenSize(children, wHint, hHint, true);
    // Do a second pass, if necessary
    if (wHint >= 0 && prefSize.width > wHint) {
      prefSize = calculateChildrenSize(children, prefSize.width, hHint, true);
    } else if (hHint >= 0 && prefSize.width > hHint) {
      prefSize = calculateChildrenSize(children, wHint, prefSize.width, true);
    }

    prefSize.height += Math.max(0, children.size() - 1) * spacing;
    return transposer
        .t(prefSize)
        .expand(insets.getWidth(), insets.getHeight())
        .union(getBorderPreferredSize(container));
  }
  /**
   * Used inside the getSizeDeltaToFitAnchors operation. It's goal is to modify a SizeDelta in order
   * to keep fitting an anchor within the figureBounds
   *
   * @param anchor The anchor whose position will be kept
   * @param sizeDelta
   * @param preserveAxis
   * @param figureBounds
   */
  protected static void modifySizeDeltaToFitAnchor(
      IdentityAnchor anchor, Dimension sizeDelta, int preserveAxis, Rectangle figureBounds) {

    if (anchor == null) {
      return;
    }

    PrecisionPoint pp = BaseSlidableAnchor.parseTerminalString(anchor.getId());

    int margin = 6;

    if (preserveAxis == PRESERVE_Y || preserveAxis == PRESERVE_XY) {
      int anchorYPos = (int) Math.round(figureBounds.height * pp.preciseY);

      int newHeight = figureBounds.height + sizeDelta.height;

      if (anchorYPos + margin > newHeight) {
        sizeDelta.height = (anchorYPos - figureBounds.height) + margin;
      }
    }

    if (preserveAxis == PRESERVE_X || preserveAxis == PRESERVE_XY) {
      int anchorXPos = (int) Math.round(figureBounds.width * pp.preciseX);

      int newWidth = figureBounds.width + sizeDelta.width;

      if (anchorXPos + margin > newWidth) {
        sizeDelta.width = (anchorXPos - figureBounds.width) + margin;
      }
    }
  }
  /**
   * Computes actual grid specification (origin + single cell width and height) in the coordinates
   * relative to the diagram content pane.
   *
   * <p>This specification depends only on the grid-relative properties stored in the {@link
   * EditPartViewer}, so client may cache it and rely on {@link
   * EditPartViewer#addPropertyChangeListener(PropertyChangeListener)}
   *
   * @param viewer
   * @return grid specification in the coordinate system relative to diagram content pane, or <code>
   *     null</code> if grid is not enabled
   */
  private static PrecisionRectangle getRelativeGridSpec(EditPartViewer viewer) {
    Boolean enabled = (Boolean) viewer.getProperty(SnapToGrid.PROPERTY_GRID_ENABLED);
    if (enabled == null || !enabled) {
      return null;
    }
    double gridX = 0;
    double gridY = 0;
    Dimension spacing = (Dimension) viewer.getProperty(SnapToGrid.PROPERTY_GRID_SPACING);
    if (spacing != null) {
      gridX = spacing.preciseWidth();
      gridY = spacing.preciseHeight();
    }
    if (gridX <= 0) {
      gridX = SnapToGrid.DEFAULT_GRID_SIZE;
    }
    if (gridY <= 0) {
      gridY = SnapToGrid.DEFAULT_GRID_SIZE;
    }
    Point origin = (Point) viewer.getProperty(SnapToGrid.PROPERTY_GRID_ORIGIN);
    PrecisionRectangle result =
        new PrecisionRectangle( //
            origin == null ? 0 : origin.preciseX(),
            origin == null ? 0 : origin.preciseY(),
            gridX,
            gridY);

    return result;
  }
 @Override
 public Dimension getPreferredSize(int wHint, int hHint) {
   Dimension prefSize = super.getPreferredSize(wHint, hHint);
   int bodyHeight = getParent().getBounds().height - 10;
   Dimension defaultSize = new Dimension(SWT.DEFAULT, bodyHeight);
   prefSize.union(defaultSize);
   return prefSize;
 }
 @Override
 public Dimension getPreferredSize(int wHint, int hHint) {
   Dimension size = super.getPreferredSize(wHint, hHint);
   // FIXME
   if (size.width < DrawUtils.SPACING + getBorder().getPreferredSize(this).width)
     size.width =
         Math.max(size.width, DrawUtils.SPACING + getBorder().getPreferredSize(this).width);
   return size;
 }
    /*
     * (non-Javadoc)
     *
     * @see org.eclipse.draw2d.ToolbarLayout#calculatePreferredSize(org.eclipse.draw2d.IFigure, int, int)
     */
    @Override
    protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
      Insets insets = container.getInsets();
      Dimension prefSize = calculateChildrenSize(container.getChildren(), wHint, hHint);

      return prefSize
          .expand(insets.getWidth(), insets.getHeight())
          .union(getBorderPreferredSize(container));
    }
Ejemplo n.º 11
0
  // We override reveal to show the Handles of the selected EditPart when
  // scrolling
  public void reveal(EditPart part) {
    // In some case, the editor control is not created, but get the sync selection event.
    // Fix this problem temporary.
    if (getFigureCanvas() == null || getFigureCanvas().isDisposed()) {
      return;
    }

    Viewport port = getFigureCanvas().getViewport();
    IFigure target = ((GraphicalEditPart) part).getFigure();

    Rectangle exposeRegion = target.getBounds().getCopy();

    // Get the primary editpolicy
    EditPolicy policy = part.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);

    // If the policy let us access the handles, proceed, otherwise
    // default to original behaviour
    if (!(policy instanceof ISelectionHandlesEditPolicy)) {
      super.reveal(part);
      return;
    }

    // First translate exposeRegion to the root level
    target = target.getParent();
    while (target != null && target != port) {
      target.translateToParent(exposeRegion);
      target = target.getParent();
    }

    // Merge selection handles if any to the exposeRegion
    List handles = ((ISelectionHandlesEditPolicy) policy).getHandles();
    for (Iterator iter = handles.iterator(); iter.hasNext(); ) {
      AbstractHandle handle = (AbstractHandle) iter.next();

      Locator locator = handle.getLocator();
      locator.relocate(handle);
      exposeRegion.union(handle.getBounds().getCopy());
    }

    exposeRegion.getExpanded(5, 5);

    Dimension viewportSize = port.getClientArea().getSize();

    Point topLeft = exposeRegion.getTopLeft();
    Point bottomRight = exposeRegion.getBottomRight().translate(viewportSize.getNegated());
    Point finalLocation = new Point();
    if (viewportSize.width < exposeRegion.width)
      finalLocation.x = Math.min(bottomRight.x, Math.max(topLeft.x, port.getViewLocation().x));
    else finalLocation.x = Math.min(topLeft.x, Math.max(bottomRight.x, port.getViewLocation().x));

    if (viewportSize.height < exposeRegion.height)
      finalLocation.y = Math.min(bottomRight.y, Math.max(topLeft.y, port.getViewLocation().y));
    else finalLocation.y = Math.min(topLeft.y, Math.max(bottomRight.y, port.getViewLocation().y));

    getFigureCanvas().scrollSmoothTo(finalLocation.x, finalLocation.y);
  }
Ejemplo n.º 12
0
  /*
   * (non-Javadoc)
   *
   * @see henshineditor.figure.condition.FormulaFigure#getPreferredDimension()
   */
  @Override
  protected Dimension getPreferredDimension() {
    Dimension dimension = super.getPreferredDimension();

    FormulaFigure<?> childFigure = getChildFigure();
    if (childFigure != null) {
      Dimension childDimension = childFigure.getPreferredDimension();
      dimension.height += childDimension.height;
      dimension.width = childDimension.width;
    }

    return dimension;
  }
 /**
  * Calculate the best size for this label using the class's width to height ratio. This is done by
  * calculating the area that the text would occupy if it was in only one line, then calculate a
  * new width that would give the same area using the width to height ratio, and finally it sends
  * this width to the {@link FlowPage}'s {@link FlowPage#getPreferredSize(int, int)} method which
  * calculates the real height using line breaks.
  *
  * @return A close match to the size that this figure should have to match the required width to
  *     height ratio.
  */
 public Dimension calculateSize() {
   try {
     Dimension lineDimensions =
         TextUtilities.INSTANCE.getStringExtents(textFlow.getText(), getFont());
     double area = lineDimensions.width() * lineDimensions.height();
     double width = Math.sqrt(area / ratio) * ratio;
     invalidate();
     Dimension pSize = textFlow.getPreferredSize((int) width, -1).getCopy();
     if (pSize.width < OPPFigureConstants.MINIMUM_NODE_SIZE) pSize.width = pSize.height;
     return pSize;
   } catch (Exception e) {
     return new Dimension(0, 0);
   }
 }
Ejemplo n.º 14
0
 private void refreshLabelBounds(IFigure figure, GraphLabel label) {
   Rectangle figureBounds = figure.getBounds();
   if (figureBounds.width * figureBounds.height > 0) {
     label.setText(label.getText()); // hack: resets label's size
     Dimension labelSize = label.getSize();
     labelSize.expand(-6, -4);
     Point anchorPoint = figure.getBounds().getBottomRight();
     anchorPoint.x -= labelSize.width / 2;
     anchorPoint.y -= labelSize.height / 2;
     Rectangle bounds = new Rectangle(anchorPoint, labelSize);
     label.setBounds(bounds);
     label.getParent().setConstraint(label, bounds);
   } else {
     label.getParent().setConstraint(label, new Rectangle(figureBounds.x, figureBounds.y, 0, 0));
     label.setBounds(new Rectangle(figureBounds.x, figureBounds.y, 0, 0));
   }
 }
  /** {@inheritDoc} */
  @Override
  protected void updateTargetRequest() {

    super.updateTargetRequest();
    Dimension delta = getDragMoveDelta();

    if (getSourceEditPart() instanceof GraphicalEditPart) {
      Rectangle childRect = ((GraphicalEditPart) getSourceEditPart()).getFigure().getBounds();
      if (getSourceEditPart().getParent() instanceof GraphicalEditPart) {
        Rectangle parentRect =
            ((GraphicalEditPart) getSourceEditPart().getParent()).getFigure().getBounds();
        IFigure fig = ((GraphicalEditPart) getSourceEditPart().getParent()).getFigure();

        IFigure contentPane =
            ((GraphicalEditPart) getSourceEditPart().getParent()).getContentPane();

        // calculate the virtual position
        Rectangle virtualPosition = childRect.getCopy();
        virtualPosition.x = virtualPosition.x + delta.width;
        virtualPosition.y = virtualPosition.y + delta.height;

        if (virtualPosition.x < 0) {
          delta.width = 0 - childRect.x;
        }
        if (virtualPosition.y < 0) {
          delta.height = 0 - childRect.y;
        }

        if (virtualPosition.x + virtualPosition.width + getBorder() > parentRect.width) {
          delta.width = parentRect.width - childRect.width - childRect.x - getBorder();
        }

        if (virtualPosition.y + virtualPosition.height + 2 * getBorder() > parentRect.height) {
          delta.height = parentRect.height - childRect.height - childRect.y - 2 * getBorder();
        }
        ChangeBoundsRequest request = (ChangeBoundsRequest) getTargetRequest();
        Point moveDelta = new Point(delta.width, delta.height);
        request.setMoveDelta(moveDelta);

        // Very important the child element to block inside the container
        // if not test first the target editPart.
        // let the default algorithm if the target is not its parent.
        setTargetEditPart(getSourceEditPart().getParent());
      }
    }
  }
Ejemplo n.º 16
0
 /** @see org.eclipse.draw2d.LayoutManager#layout(org.eclipse.draw2d.IFigure) */
 public void layout(IFigure container) {
   List children = container.getChildren();
   Rectangle rulerSize = container.getClientArea();
   for (int i = 0; i < children.size(); i++) {
     IFigure child = (IFigure) children.get(i);
     Dimension childSize = child.getPreferredSize();
     int position = ((Integer) getConstraint(child)).intValue();
     if (((RulerFigure) container).isHorizontal()) {
       childSize.height = rulerSize.height - 1;
       Rectangle.getSINGLETON().setLocation(position - (childSize.width / 2), rulerSize.y);
     } else {
       childSize.width = rulerSize.width - 1;
       Rectangle.getSINGLETON().setLocation(rulerSize.x, position - (childSize.height / 2));
     }
     Rectangle.getSINGLETON().setSize(childSize);
     child.setBounds(Rectangle.getSINGLETON());
   }
 }
Ejemplo n.º 17
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.draw2d.Figure#getMinimumSize(int, int)
   */
  private Dimension getMinimumSize(
      int wHint, int hHint, boolean isFix, boolean forceWidth, boolean forceHeight) {
    if (DesignChoiceConstants.DISPLAY_NONE.equals(display)) {
      return ZERO_DIMENSION;
    }

    int rx = recommendSize != null ? recommendSize.width : 0;
    int ry = recommendSize != null ? recommendSize.height : 0;

    rx = getRealRecommendSizeX(rx, wHint);

    if (wHint == -1 && hHint == -1) {
      int maxWidth = calcMaxSegment();

      // use recommend size if specified, otherwise use max segment size
      Dimension dim = super.getMinimumSize(rx == 0 ? maxWidth : rx, -1);

      dim.height = Math.max(dim.height, Math.max(getInsets().getHeight(), ry));

      return dim;
    }
    Dimension dim;
    // return the true minimum size with minimum width;
    if (isFix) {
      int tempHint = wHint;
      int maxWidth = calcMaxSegment();
      if (wHint < maxWidth && !forceWidth) {
        tempHint = maxWidth;
      }
      dim = super.getMinimumSize(tempHint <= 0 ? -1 : tempHint, hHint);

      return new Dimension(Math.max(dim.width, rx), Math.max(dim.height, ry));
    } else {
      dim = super.getMinimumSize(rx == 0 ? -1 : rx, hHint);
    }

    if (dim.width < wHint) {
      return new Dimension(Math.max(dim.width, rx), Math.max(dim.height, ry));
    }

    dim = super.getMinimumSize(wHint, hHint);

    return new Dimension(Math.max(dim.width, rx), Math.max(dim.height, ry));
  }
 /**
  * Returns the size set specified by setPreferredImageSize() or the size specified by the image.
  * In the case of meta-images a preferred size of 32x32 is returned.
  */
 public Dimension getPreferredSize(int wHint, int hHint) {
   if (preferredSize.height == -1 && preferredSize.width == -1) {
     int extent = MapModeUtil.getMapMode(this).DPtoLP(32);
     preferredSize = new Dimension(extent, extent);
     if (getFlag(FLAG_USE_DEFAULT_IMAGESIZE)) {
       if (getRenderedImage() != null) {
         setRenderedImage(getRenderedImage(new Dimension(0, 0)));
         Image swtImage = null;
         if (getRenderedImage() != null) swtImage = getRenderedImage().getSWTImage();
         if (swtImage != null) {
           org.eclipse.swt.graphics.Rectangle imgRect = swtImage.getBounds();
           preferredSize.width = MapModeUtil.getMapMode(this).DPtoLP(imgRect.width);
           preferredSize.height = MapModeUtil.getMapMode(this).DPtoLP(imgRect.height);
         }
       }
     }
   }
   return preferredSize;
 }
  protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
    IFigure feedback = getDragSourceFeedbackFigure();

    PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
    getHostFigure().translateToAbsolute(rect);
    rect.translate(request.getMoveDelta());
    rect.resize(request.getSizeDelta());

    IFigure f = getHostFigure();
    Dimension min = f.getMinimumSize().getCopy();
    Dimension max = f.getMaximumSize().getCopy();
    IMapMode mmode = MapModeUtil.getMapMode(f);
    min.height = mmode.LPtoDP(min.height);
    min.width = mmode.LPtoDP(min.width);
    max.height = mmode.LPtoDP(max.height);
    max.width = mmode.LPtoDP(max.width);

    if (min.width > rect.width) rect.width = min.width;
    else if (max.width < rect.width) rect.width = max.width;

    if (min.height > rect.height) rect.height = min.height;
    else if (max.height < rect.height) rect.height = max.height;

    feedback.translateToRelative(rect);
    feedback.setBounds(rect);
  }
Ejemplo n.º 20
0
  private double getFitXZoomLevel(int which) {
    IFigure fig = getScalableFigure();

    Dimension available = getViewport().getClientArea().getSize();
    Dimension desired;
    if (fig instanceof FreeformFigure) {
      desired = ((FreeformFigure) fig).getFreeformExtent().getCopy().union(0, 0).getSize();
    } else {
      desired = fig.getPreferredSize().getCopy();
    }

    desired.width -= fig.getInsets().getWidth();
    desired.height -= fig.getInsets().getHeight();

    while (fig != getViewport()) {
      available.width -= fig.getInsets().getWidth();
      available.height -= fig.getInsets().getHeight();
      fig = fig.getParent();
    }

    double scaleX = Math.min(available.width * zoom / desired.width, getMaxZoom());
    double scaleY = Math.min(available.height * zoom / desired.height, getMaxZoom());
    if (which == 0) {
      return scaleX;
    }
    if (which == 1) {
      return scaleY;
    }
    return Math.min(scaleX, scaleY);
  }
Ejemplo n.º 21
0
  /**
   * Return the default draw2D dimension according to the specified DNode.
   *
   * @return the default draw2D dimension according to the specified DNode.
   */
  public Dimension getDefaultDimension() {
    final Dimension result = DEFAULT_NODE_DIMENSION.getCopy();

    if (node.getStyle() instanceof WorkspaceImage) {
      final WorkspaceImage workspaceImage = (WorkspaceImage) node.getStyle();
      final String path = workspaceImage.getWorkspacePath();
      final Image image;
      image = WorkspaceImageFigure.getImageInstanceFromPath(path);
      if (image != null) {
        // Use default image size
        if (node.getWidth() == null || Integer.valueOf(node.getWidth()) == -1) {
          result.width = image.getBounds().width;
          result.height = image.getBounds().height;
        } else {
          // width is already defined, adapt height thanks to
          // image ratio
          final double ratio = (double) image.getBounds().width / image.getBounds().height;
          double newHeight = node.getWidth().intValue() / ratio;

          // Adapt to draw2D
          result.width = node.getWidth().intValue() * LayoutUtils.SCALE;
          result.height = (int) (newHeight * LayoutUtils.SCALE);
        }
      }
    } else {
      if (node.getWidth() != null) {
        result.width = node.getWidth().intValue();
      }
      if (node.getHeight() != null) {
        result.height = node.getHeight().intValue();
      }

      // Adapt to draw2D
      result.width = result.width * LayoutUtils.SCALE;
      result.height = result.height * LayoutUtils.SCALE;
    }

    return result;
  }
Ejemplo n.º 22
0
  /**
   * Fix for #422827
   *
   * <p>We would better override the Dimension.max() logic from the super class but it itself calls
   * super.super so we can't easily do that.
   *
   * <p>So we have to explicitly call {@link #getMinimumSizeForHint(GraphicalEditPart, Dimension)}
   * and ensure that Dimension.max() logic in super-class does not affect results by returning
   * something small from {@link #getMinimumSizeFor(GraphicalEditPart)}
   */
  @Override
  protected Object getConstraintFor(Request request, GraphicalEditPart child, Rectangle rect) {
    if (isReflowable(child) && request instanceof ChangeBoundsRequest) {
      ChangeBoundsRequest reqImpl = (ChangeBoundsRequest) request;

      Dimension sizeDelta = reqImpl.getSizeDelta();
      if (sizeDelta.width != 0 || sizeDelta.height != 0) {
        Dimension correctedMinSize = getMinimumSizeForHint(child, rect.getSize());
        rect.setSize(Dimension.max(correctedMinSize, rect.getSize()));
      }
    }
    return super.getConstraintFor(request, child, rect);
  }
Ejemplo n.º 23
0
    public void layout(IFigure container) {
      Rectangle area = container.getClientArea();
      area.height -= 1;
      Dimension scaleSize = new Dimension(0, 0);
      Dimension markerSize = new Dimension(0, 0);

      if (scale != null) {
        if (scale.isVisible()) {
          scaleSize = scale.getPreferredSize(-1, area.height);
          scale.setBounds(new Rectangle(area.x, area.y, scaleSize.width, scaleSize.height));
        } else {
          scaleSize = scale.getPreferredSize(-1, area.height + 2 * scale.getMargin());
          scale.setBounds(
              new Rectangle(area.x, area.y - scale.getMargin(), scaleSize.width, scaleSize.height));
          scaleSize.height = 0;
          scaleSize.width = 0;
        }
      }

      if (marker != null && marker.isVisible()) {
        markerSize = marker.getPreferredSize();
        marker.setBounds(
            new Rectangle(
                area.x + area.width - markerSize.width,
                marker.getScale().getBounds().y,
                markerSize.width,
                markerSize.height));
      }

      if (tank != null) {
        tank.setBounds(
            new Rectangle(
                area.x + scaleSize.width,
                scale.getValuePosition(scale.getRange().getUpper(), false),
                area.width - scaleSize.width - markerSize.width,
                scale.getTickLength() + tank.getLineWidth()));
      }
    }
Ejemplo n.º 24
0
 /**
  * Shows or updates feedback for a change bounds request. The request is updated by the way so
  * that the shape stays a square.
  *
  * @param request the request
  */
 @Override
 protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
   // adapt the request for a square resize
   Point move = request.getMoveDelta();
   Dimension delta = request.getSizeDelta();
   int dH = delta.height;
   int dW = delta.width;
   int signum = 0;
   if (dH <= 0 && dW <= 0) {
     signum = -1;
   } else {
     signum = 1;
   }
   int positiveResize = Math.max(dH, dW);
   if (positiveResize <= 0) {
     if (dH == 0) {
       positiveResize = -dW;
     } else if (dW == 0) {
       positiveResize = -dH;
     } else {
       positiveResize = Math.min(-dH, -dW);
     }
   }
   int newDH = signum * positiveResize;
   int newDW = newDH;
   int dir = request.getResizeDirection();
   // adjust new position if impacted by resizing
   if ((dir & PositionConstants.NORTH) > 0) {
     move.y += dH - newDH;
   }
   if ((dir & PositionConstants.WEST) > 0) {
     move.x += dW - newDW;
   }
   request.setMoveDelta(move);
   delta.height = newDH;
   delta.width = newDW;
   super.showChangeBoundsFeedback(request);
 }
  /** creates the command to move the shapes left or right. */
  protected Command getCommand() {
    if (_container == null) {
      return null;
    }
    CompoundCommand command = new CompoundCommand("Multiple Shape Move");
    TransactionalEditingDomain editingDomain = _container.getEditingDomain();

    Point moveDelta = ((ChangeBoundsRequest) getSourceRequest()).getMoveDelta().getCopy();
    Dimension spSizeDelta = new Dimension(moveDelta.x, moveDelta.y);
    ZoomManager zoomManager =
        ((DiagramRootEditPart) getCurrentViewer().getRootEditPart()).getZoomManager();
    spSizeDelta.scale(1 / zoomManager.getZoom());
    command.add(_container.getCommand(getSourceRequest()));

    for (IGraphicalEditPart sp : _subProcesses) {
      Dimension spDim = sp.getFigure().getBounds().getSize().getCopy();
      spDim.expand(spSizeDelta);
      SetBoundsCommand setBounds =
          new SetBoundsCommand(editingDomain, "MultipleShape Move", sp, spDim);
      command.add(new ICommandProxy(setBounds));
    }
    return command;
  }
Ejemplo n.º 26
0
  @Override
  protected void updateSourceRequest() {
    ChangeBoundsRequest request = (ChangeBoundsRequest) getSourceRequest();
    Dimension d = getDragMoveDelta();

    Point location = new Point(getLocation());
    Point moveDelta = new Point(0, 0);
    Dimension resizeDelta = new Dimension(0, 0);

    request.setConstrainedResize(false);

    request.setCenteredResize(getCurrentInput().isModKeyDown(SWT.MOD1));

    if ((getResizeDirection() & PositionConstants.NORTH) != 0) {
      moveDelta.y += d.height;
      resizeDelta.height -= d.height;
    }
    if ((getResizeDirection() & PositionConstants.SOUTH) != 0) {
      resizeDelta.height += d.height;
    }
    if ((getResizeDirection() & PositionConstants.WEST) != 0) {
      moveDelta.x += d.width;
      resizeDelta.width -= d.width;
    }
    if ((getResizeDirection() & PositionConstants.EAST) != 0) {
      resizeDelta.width += d.width;
    }

    request.setMoveDelta(moveDelta);
    request.setSizeDelta(resizeDelta);
    request.setLocation(location);
    request.setEditParts(getOperationSet());

    request.getExtendedData().clear();

    // TODO: snapping
  }
    /*
     * (non-Javadoc)
     *
     * @see org.eclipse.draw2d.ToolbarLayout#layout(org.eclipse.draw2d.IFigure)
     */
    @Override
    public void layout(IFigure parent) {
      final Rectangle clientArea = parent.getClientArea();
      int x = clientArea.x;
      int y = clientArea.y;
      final List children = parent.getChildren();
      int numChildren = children.size();

      int maxHeight = 0;
      for (int i = 0; i < numChildren; i++) {
        IFigure child = (IFigure) children.get(i);
        Dimension prefSize = getChildPreferredSize(child, clientArea.width, -1);
        maxHeight = Math.max(maxHeight, prefSize.height);
      }
      maxHeight = Math.max(maxHeight, clientArea.height);

      if (numChildren == 1) {
        IFigure child = (IFigure) children.get(0);
        Dimension prefSize = child.getPreferredSize(clientArea.width, -1);
        prefSize.width = Math.max(prefSize.width, clientArea.width);
        Rectangle newBounds = new Rectangle(x, y, prefSize.width, maxHeight);
        child.setBounds(newBounds);
      } else if (numChildren == 2) {
        int initExpressionWidth =
            (xmlTreePart.getViewer().getControl().getSize().x / 3 - 80 - 10) / 2;
        IFigure child = (IFigure) children.get(0);
        Rectangle newBounds = new Rectangle(x, y, initExpressionWidth, maxHeight);
        child.setBounds(newBounds);

        child = (IFigure) children.get(1);
        Dimension prefSize = child.getPreferredSize(clientArea.width, -1);
        prefSize.width = Math.max(prefSize.width, clientArea.width - initExpressionWidth);
        newBounds = new Rectangle(x + initExpressionWidth, y, prefSize.width, maxHeight);
        child.setBounds(newBounds);
      }
    }
Ejemplo n.º 28
0
  /* (non-Javadoc)
   * @see streamit.eclipse.debugger.graph.IStream#setHorizontalLocation(org.eclipse.draw2d.geometry.Point, int, int)
   */
  public int setHorizontalLocation(
      int currentHeight,
      boolean stretchTopChannel,
      boolean stretchBottomChannel,
      int stretchHeight,
      int currentWidth) {
    Dimension topSize = fTopChannel.getSize();
    Dimension pipelineSize = getSize();
    Dimension bottomSize = fBottomChannel.getSize();

    // expand channels
    if (stretchTopChannel) {
      topSize.height = stretchHeight - pipelineSize.height - bottomSize.height;
      fTopChannel.setSize(topSize);
    }
    if (stretchBottomChannel) {
      bottomSize.height = stretchHeight - pipelineSize.height - topSize.height;
      fBottomChannel.setSize(bottomSize);
    }

    setVerticalLocation(new Point(currentWidth + pipelineSize.width / 2, currentHeight), 0);
    currentWidth = currentWidth + pipelineSize.width + IStreamItGraphConstants.MARGIN / 2;
    return currentWidth;
  }
Ejemplo n.º 29
0
    protected LayoutData getLayoutData() {
      Dimension initSize = initFigure.getPreferredSize();
      initSize.width = Math.min(initSize.width, MAX_BOX_WIDTH);
      Dimension methodoSize = methodoFigure.getPreferredSize();
      methodoSize.width = Math.min(methodoSize.width, MAX_BOX_WIDTH);
      Dimension processSize = processFigure.getPreferredSize();
      processSize.width = Math.min(processSize.width, MAX_BOX_WIDTH);
      Dimension endSize = endFigure.getPreferredSize();
      endSize.width = Math.min(endSize.width, MAX_BOX_WIDTH);

      LayoutData data = new LayoutData();

      // boxes
      int initY = BOX_SPACING;
      int methodoY = initY + initSize.height + BOX_SPACING;
      int processY = methodoY + methodoSize.height + BOX_SPACING;
      int endY = processY + processSize.height + BOX_SPACING;
      int gap = processSize.width - methodoSize.width;
      data.initBox = new Rectangle(processSize.width / 2, initY, initSize.width, initSize.height);
      data.methodoBox = new Rectangle(gap / 2, methodoY, methodoSize.width, methodoSize.height);
      data.processBox = new Rectangle(0, processY, processSize.width, processSize.height);
      data.endBox = new Rectangle(processSize.width / 2, endY, endSize.width, endSize.height);
      // points
      int pointH = data.initBox.x + data.initBox.width / 2;
      data.init2methodoPoints = new PointList(2);
      data.init2methodoPoints.addPoint(pointH, data.initBox.y + data.initBox.height);
      data.init2methodoPoints.addPoint(pointH, data.methodoBox.y);
      data.methodo2processPoints = new PointList(2);
      data.methodo2processPoints.addPoint(pointH, data.methodoBox.y + data.methodoBox.height);
      data.methodo2processPoints.addPoint(pointH, data.processBox.y);
      data.process2endPoints = new PointList(2);
      data.process2endPoints.addPoint(pointH, data.processBox.y + data.processBox.height);
      data.process2endPoints.addPoint(pointH, data.endBox.y);
      // logo and status
      Dimension logoSize = logoFigure.getPreferredSize();
      data.logoBox = new Rectangle(0, 0, logoSize.width, logoSize.height);
      Dimension statusSize = statusFigure.getPreferredSize();
      int statusX =
          Math.max(
              data.methodoBox.x + data.methodoBox.width - statusSize.width,
              data.processBox.x + data.processBox.width + BOX_SPACING);
      data.statusBox = new Rectangle(statusX, 0, statusSize.width, statusSize.height);
      return data;
    }
Ejemplo n.º 30
0
  protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
    Dimension extent = null;

    for (Iterator i = container.getChildren().iterator(); i.hasNext(); ) {
      IFigure child = (IFigure) i.next();

      Dimension childSize = null;
      if (!(child instanceof FreeformFigure)) {
        childSize = child.getPreferredSize();
      }
      if (null != childSize) {
        if (null == extent) {
          extent = childSize.getCopy();
        } else {
          extent.width += childSize.width + getMinorSpacing();
          extent.height = Math.max(extent.height, childSize.height);
        }
      }
    }

    if (null != extent) {
      extent.union(container.getMinimumSize());
    } else {
      extent = container.getMinimumSize();
    }

    Insets insets = container.getInsets();
    if (null == extent) {
      extent = new Dimension(insets.getWidth(), insets.getHeight());
    } else {
      // compartment.translateToParent(extent);
      extent.expand(insets.getWidth(), insets.getHeight());
    }

    return extent;
  }