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);
  }
Esempio n. 2
0
 /**
  * Returns a figure corresponding to this image
  *
  * @param image a image
  * @return a figure corresponding to this image
  */
 public IFigure getFigure(Image image) {
   IMapMode mm =
       MapModeUtil.getMapMode(
           ((IGraphicalEditPart) getDecoratorTarget().getAdapter(IGraphicalEditPart.class))
               .getFigure());
   ImageFigure fig = new ImageFigure();
   fig.setImage(image);
   fig.setSize(mm.DPtoLP(image.getBounds().width), mm.DPtoLP(image.getBounds().height));
   return fig;
 }
 /** @generated */
 public View createView(
     IAdaptable semanticAdapter,
     View containerView,
     String semanticHint,
     int index,
     boolean persisted,
     PreferencesHint preferencesHint) {
   Node view =
       (Node)
           super.createView(
               semanticAdapter, containerView, semanticHint, index, persisted, preferencesHint);
   Location location = (Location) view.getLayoutConstraint();
   IMapMode mapMode =
       MeasurementUnitHelper.getMapMode(containerView.getDiagram().getMeasurementUnit());
   location.setX(mapMode.DPtoLP(0));
   location.setY(mapMode.DPtoLP(5));
   return view;
 }
Esempio n. 4
0
  public RegionFigure(IMapMode mapMode) {
    this.mapMode = mapMode;

    GridLayout layoutThis = new GridLayout(1, false);
    layoutThis.verticalSpacing = 2;
    this.setLayoutManager(layoutThis);
    this.setLineWidth(mapMode.DPtoLP(1));
    createContents();
  }
  protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
    IFigure feedback = getDragSourceFeedbackFigure();

    PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
    getHostFigure().translateToAbsolute(rect);

    // Only enable horizontal dragging on lifelines(except lifelines that are result of a create
    // message).
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=364688
    if (this.getHost() instanceof LifelineEditPart) {
      LifelineEditPart lifelineEP = (LifelineEditPart) this.getHost();
      if (!SequenceUtil.isCreateMessageEndLifeline(lifelineEP)) {
        request.getMoveDelta().y = 0;
      }
    }

    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);
  }
  /** @see org.eclipse.draw2d.Figure#paintFigure(Graphics) */
  protected void paintFigure(Graphics g) {
    Rectangle r = getBounds().getCopy();

    IMapMode mm = MapModeUtil.getMapMode(this);
    r.translate(mm.DPtoLP(2), mm.DPtoLP(2));
    r.setSize(mm.DPtoLP(11), mm.DPtoLP(9));

    // Draw the bottom arc of the gate
    r.y += mm.DPtoLP(4);
    r.width = r.width - mm.DPtoLP(1);
    g.fillOval(r);
    r.height--;
    g.drawOval(r);

    // draw gate
    g.translate(getLocation());
    PointList outline = points.getCopy();
    mm.DPtoLP(outline);
    g.fillPolygon(outline);
    g.drawPolyline(outline);
    g.translate(getLocation().getNegated());
  }
Esempio n. 7
0
  /** @see org.eclipse.draw2d.Figure#paintFigure(Graphics) */
  protected void paintFigure(Graphics g) {
    IMapMode mm = MapModeUtil.getMapMode(this);
    Rectangle displayRectangle =
        new Rectangle(mm.DPtoLP(15), mm.DPtoLP(11), mm.DPtoLP(31), mm.DPtoLP(25));
    Rectangle displayShadow =
        new Rectangle(mm.DPtoLP(14), mm.DPtoLP(10), mm.DPtoLP(32), mm.DPtoLP(26));
    Rectangle displayHighlight =
        new Rectangle(mm.DPtoLP(15), mm.DPtoLP(11), mm.DPtoLP(32), mm.DPtoLP(26));
    Point valuePoint = new Point(mm.DPtoLP(16), mm.DPtoLP(10));

    int Y1 = mm.DPtoLP(0);
    int Y2 = mm.DPtoLP(44);

    Rectangle r = getBounds().getCopy();

    g.translate(r.getLocation());
    g.fillRectangle(mm.DPtoLP(0), mm.DPtoLP(0), r.width, r.height /*- MapMode.DPtoLP(4)*/);
    int right = r.width - 1;
    g.drawLine(mm.DPtoLP(0), Y1, right, Y1);
    g.drawLine(mm.DPtoLP(0), Y1, mm.DPtoLP(0), Y2);

    g.drawLine(mm.DPtoLP(0), Y2, right, Y2);
    g.drawLine(right, Y1, right, Y2);

    // Draw the display
    RGB whiteColor = ColorConstants.white.getRGB();
    RGB backgroundColor = getBackgroundColor().getRGB();
    RGB newHightlightRGB =
        new RGB(
            (whiteColor.red + backgroundColor.red) / 2,
            (whiteColor.green + backgroundColor.green) / 2,
            (whiteColor.blue + backgroundColor.blue) / 2);
    g.setBackgroundColor(DiagramColorRegistry.getInstance().getColor(newHightlightRGB));
    g.fillRectangle(displayHighlight);
    RGB blackColor = ColorConstants.black.getRGB();
    RGB newShadowRGB =
        new RGB(
            (blackColor.red + backgroundColor.red) / 2,
            (blackColor.green + backgroundColor.green) / 2,
            (blackColor.blue + backgroundColor.blue) / 2);
    g.setBackgroundColor(DiagramColorRegistry.getInstance().getColor(newShadowRGB));
    g.fillRectangle(displayShadow);

    g.setBackgroundColor(ColorConstants.black);
    g.fillRectangle(displayRectangle);

    // Draw the value
    g.setForegroundColor(getFontColor());
    g.drawText(value, valuePoint);
  }
  /**
   *
   *
   * <pre>
   * {@inheritDoc}
   *
   * This method override parent implementation to add a new set of
   * predefined decoration type.
   *
   * The arrowType available constants are given in {@link EdgeDecorationType}.
   * </pre>
   */
  @Override
  protected RotatableDecoration getArrowDecoration(int arrowType) {
    RotatableDecoration decoration = null;
    int width = getLineWidth();
    if (width < 0) {
      width = 1;
    }
    if (arrowType == EdgeDecorationType.OPEN_ARROW) {
      IMapMode mm = getMapMode();
      decoration = new PolylineDecoration();
      ((PolylineDecoration) decoration).setScale(mm.DPtoLP(15 + width), mm.DPtoLP(5 + width));
      ((PolylineDecoration) decoration).setTemplate(PolylineDecoration.TRIANGLE_TIP);
      ((PolylineDecoration) decoration).setLineWidth(mm.DPtoLP(width));

    } else if (arrowType == EdgeDecorationType.SOLID_ARROW_FILLED) {
      IMapMode mm = getMapMode();
      decoration = new PolygonDecoration();
      ((PolygonDecoration) decoration).setScale(mm.DPtoLP(15 + width), mm.DPtoLP(5 + width));
      ((PolygonDecoration) decoration).setTemplate(PolygonDecoration.TRIANGLE_TIP);
      ((PolygonDecoration) decoration).setLineWidth(mm.DPtoLP(width));
      ((PolygonDecoration) decoration).setFill(true);

    } else if (arrowType == EdgeDecorationType.SOLID_ARROW_EMPTY) {
      IMapMode mm = getMapMode();
      decoration = new PolygonDecoration();
      ((PolygonDecoration) decoration).setScale(mm.DPtoLP(15 + width), mm.DPtoLP(5 + width));
      ((PolygonDecoration) decoration).setTemplate(PolygonDecoration.TRIANGLE_TIP);
      ((PolygonDecoration) decoration).setLineWidth(mm.DPtoLP(width));

      // Not really empty... filled with white color.
      ((PolygonDecoration) decoration).setFill(true);
      ((PolygonDecoration) decoration).setBackgroundColor(ColorConstants.white);

    } else if (arrowType == EdgeDecorationType.SOLID_DIAMOND_FILLED) {
      IMapMode mm = getMapMode();
      decoration = new PolygonDecoration();
      ((PolygonDecoration) decoration).setScale(mm.DPtoLP(12 + width), mm.DPtoLP(6 + width));

      PointList diamondPointList = new PointList();
      diamondPointList.addPoint(0, 0);
      diamondPointList.addPoint(-1, 1);
      diamondPointList.addPoint(-2, 0);
      diamondPointList.addPoint(-1, -1);

      ((PolygonDecoration) decoration).setTemplate(diamondPointList);
      ((PolygonDecoration) decoration).setLineWidth(mm.DPtoLP(width));
      ((PolygonDecoration) decoration).setFill(true);

    } else if (arrowType == EdgeDecorationType.SOLID_DIAMOND_EMPTY) {
      IMapMode mm = getMapMode();
      decoration = new PolygonDecoration();
      ((PolygonDecoration) decoration).setScale(mm.DPtoLP(12 + width), mm.DPtoLP(6 + width));

      PointList diamondPointList = new PointList();
      diamondPointList.addPoint(0, 0);
      diamondPointList.addPoint(-1, 1);
      diamondPointList.addPoint(-2, 0);
      diamondPointList.addPoint(-1, -1);

      ((PolygonDecoration) decoration).setTemplate(diamondPointList);
      ((PolygonDecoration) decoration).setLineWidth(mm.DPtoLP(width));

      // Not really empty... filled with white color.
      ((PolygonDecoration) decoration).setFill(true);
      ((PolygonDecoration) decoration).setBackgroundColor(ColorConstants.white);
    }

    return decoration;
  }