/**
   * This method is used to compute the shapes polygon points. This is currently based on the shapes
   * bounding box.
   *
   * @param rect the rectangle that the shape will fit in
   */
  protected PointList calculatePoints(Rectangle rect) {

    double xOffset = rect.preciseWidth() * factor;
    double yOffset = rect.preciseHeight() * factor;

    PointList points = new PrecisionPointList();

    Point p1 = new PrecisionPoint(rect.preciseX(), rect.preciseY() + yOffset);
    Point p2 = new PrecisionPoint(rect.preciseX() + xOffset, rect.preciseY());
    Point p3 = new PrecisionPoint(rect.preciseX() + rect.preciseWidth() - xOffset, rect.preciseY());
    Point p4 =
        new PrecisionPoint(rect.preciseX() + rect.preciseWidth() - 1, rect.preciseY() + yOffset);
    Point p5 = new PrecisionPoint(p4.preciseX(), rect.preciseY() + rect.preciseHeight() - yOffset);
    Point p6 = new PrecisionPoint(p3.preciseX(), rect.preciseY() + rect.preciseHeight() - 1);
    Point p7 = new PrecisionPoint(p2.preciseX(), p6.preciseY());
    Point p8 = new PrecisionPoint(rect.preciseX(), p5.preciseY());

    points.addPoint(p1);
    points.addPoint(p2);
    points.addPoint(p3);
    points.addPoint(p4);
    points.addPoint(p5);
    points.addPoint(p6);
    points.addPoint(p7);
    points.addPoint(p8);
    points.addPoint(p1);

    return points;
  }
示例#2
0
  public void performLayout() {
    Rectangle fromBox = fromFigure.getLayoutDimensions();
    Rectangle toBox = toFigure.getLayoutDimensions();

    Point fromPoint = pointOnSide(fromBox, exitSide, exitTweak);
    Point toPoint = pointOnSide(toBox, entrySide, entryTweak);

    Point middlePoint;

    if (isHorizontal(exitSide))
      if (isHorizontal(entrySide)) { // both horizontal, ignore entryTweak and entryPoint.y
        middlePoint = new Point((fromPoint.x + toPoint.x) / 2, fromPoint.y);
        toPoint.y = fromPoint.y; // make line vertical
      } else { // from horizontal, to vertical
        middlePoint =
            new Point(
                toBox.x + toBox.width / 2 + entryTweak, fromBox.y + fromBox.height / 2 + exitTweak);
      }
    else if (isHorizontal(entrySide)) { // from vertical, to horizontal
      middlePoint =
          new Point(
              fromBox.x + fromBox.width / 2 + exitTweak, toBox.y + toBox.height / 2 + entryTweak);
    } else { // both vertical, ignore entryTweak and entryPoint.x
      middlePoint = new Point(fromPoint.x, (fromPoint.y + toPoint.y) / 2);
      toPoint.x = fromPoint.x; // make line horizontal
    }

    nonTranslatedPoints = new PointList();
    nonTranslatedPoints.addPoint(fromPoint);
    nonTranslatedPoints.addPoint(middlePoint);
    nonTranslatedPoints.addPoint(toPoint);

    if (actionFigure != null) actionFigure.performCenteredLayout(middlePoint.x, middlePoint.y);
  }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.draw2d.Shape#paintFigure(org.eclipse.draw2d.Graphics)
   */
  @Override
  public void paintFigure(Graphics graphics) {
    graphics.setLineWidth(2);

    Rectangle r = getBounds();

    // Define the points of a diamond
    Point p1 = new Point(r.x, r.y + r.height / 2);
    Point p2 = new Point(r.x + r.width / 2, r.y);
    Point p3 = new Point(r.x + r.width, r.y + r.height / 2);
    Point p4 = new Point(r.x + r.width / 2, r.y + r.height - 1);

    PointList pointList = new PointList();

    pointList.addPoint(p1);
    pointList.addPoint(p2);
    pointList.addPoint(p3);
    pointList.addPoint(p4);

    // Fill the shape
    graphics.fillPolygon(pointList);

    // Draw the outline
    graphics.drawLine(p1, p2);
    graphics.drawLine(p2, p3);
    graphics.drawLine(p3, p4);
    graphics.drawLine(p4, p1);
  }
 static {
   RECTANGLE_TIP.addPoint(-2, 0);
   RECTANGLE_TIP.addPoint(-1, 1);
   RECTANGLE_TIP.addPoint(-0, 0);
   RECTANGLE_TIP.addPoint(-1, -1);
   RECTANGLE_TIP.addPoint(-2, 0);
 }
 protected PointList getTemplate() {
   PointList pl = new PointList();
   pl.addPoint(-1, -2);
   pl.addPoint(1, 0);
   pl.addPoint(-1, 2);
   pl.addPoint(-1, -2);
   return pl;
 }
    /** @generated NOT */
    private RotatableDecoration createTargetDecoration() {
      PolygonDecoration df = new PolygonDecoration();
      df.setLineWidth(1);

      PointList pl = new PointList();

      pl.addPoint(getMapMode().DPtoLP(4), getMapMode().DPtoLP(1));
      pl.addPoint(getMapMode().DPtoLP(3), getMapMode().DPtoLP(3));
      pl.addPoint(getMapMode().DPtoLP(1), getMapMode().DPtoLP(4));
      pl.addPoint(getMapMode().DPtoLP(-1), getMapMode().DPtoLP(4));
      pl.addPoint(getMapMode().DPtoLP(-3), getMapMode().DPtoLP(3));
      pl.addPoint(getMapMode().DPtoLP(-4), getMapMode().DPtoLP(1));
      pl.addPoint(getMapMode().DPtoLP(-4), getMapMode().DPtoLP(-1));
      pl.addPoint(getMapMode().DPtoLP(-3), getMapMode().DPtoLP(-3));
      pl.addPoint(getMapMode().DPtoLP(-1), getMapMode().DPtoLP(-4));
      pl.addPoint(getMapMode().DPtoLP(1), getMapMode().DPtoLP(-4));
      pl.addPoint(getMapMode().DPtoLP(3), getMapMode().DPtoLP(-3));
      pl.addPoint(getMapMode().DPtoLP(4), getMapMode().DPtoLP(-1));
      pl.addPoint(getMapMode().DPtoLP(4), getMapMode().DPtoLP(1));

      df.setTemplate(pl);
      df.setScale(getMapMode().DPtoLP(1), getMapMode().DPtoLP(1));
      df.setBackgroundColor(ColorConstants.white);
      return df;
    }
示例#7
0
 /**
  * Sets the start and end points for the given connection.
  *
  * @param conn The connection
  */
 protected void setEndPoints(Connection conn) {
   PointList points = conn.getPoints();
   points.removeAllPoints();
   Point start = getStartPoint(conn);
   Point end = getEndPoint(conn);
   conn.translateToRelative(start);
   conn.translateToRelative(end);
   points.addPoint(start);
   points.addPoint(end);
   conn.setPoints(points);
 }
示例#8
0
 /**
  * Create a decoration for the composition
  *
  * @return the new decoration
  */
 private PolygonDecoration createCompositionDecoration() {
   PolygonDecoration decoration = new PolygonDecoration();
   PointList decorationPointList = new PointList();
   decorationPointList.addPoint(0, 0);
   decorationPointList.addPoint(-1, 1);
   decorationPointList.addPoint(-2, 0);
   decorationPointList.addPoint(-1, -1);
   decoration.setTemplate(decorationPointList);
   decoration.setScale(10, 5);
   return decoration;
 }
示例#9
0
 public void paintFigure(Graphics g) {
   Rectangle r = bounds;
   PointList pl = new PointList(4);
   pl.addPoint(r.x + r.width / 2, r.y);
   pl.addPoint(r.x, r.y + r.height / 2);
   pl.addPoint(r.x + r.width / 2, r.y + r.height - 1);
   pl.addPoint(r.x + r.width, r.y + r.height / 2);
   g.drawPolygon(pl);
   g.drawText(message, r.x + r.width / 4 + 5, r.y + 3 * r.height / 8);
   g.drawText("N", r.x + 7 * r.width / 8, r.y + 3 * r.height / 8);
   g.drawText("Y", r.x + r.width / 2 - 2, r.y + 3 * r.height / 4);
 }
示例#10
0
 /**
  * Create a decoration for the aggregation
  *
  * @return the new decoration
  */
 private PolygonDecoration createAggregationDecoration() {
   PolygonDecoration decoration = new PolygonDecoration();
   PointList decorationPointList = new PointList();
   decorationPointList.addPoint(0, 0);
   decorationPointList.addPoint(-1, 1);
   decorationPointList.addPoint(-2, 0);
   decorationPointList.addPoint(-1, -1);
   decoration.setBackgroundColor(ModelerColorConstants.white);
   decoration.setTemplate(decorationPointList);
   decoration.setScale(10, 5);
   return decoration;
 }
示例#11
0
 /** @generated */
 private RotatableDecoration createTargetDecoration() {
   PolygonDecoration df = new PolygonDecoration();
   df.setFill(true);
   df.setBackgroundColor(ColorConstants.black);
   PointList pl = new PointList();
   pl.addPoint(getMapMode().DPtoLP(0), getMapMode().DPtoLP(0));
   pl.addPoint(getMapMode().DPtoLP(-1), getMapMode().DPtoLP(1));
   pl.addPoint(getMapMode().DPtoLP(-1), getMapMode().DPtoLP(-1));
   pl.addPoint(getMapMode().DPtoLP(0), getMapMode().DPtoLP(0));
   df.setTemplate(pl);
   df.setScale(getMapMode().DPtoLP(7), getMapMode().DPtoLP(3));
   return df;
 }
  /** @see IFigure#validate() */
  @Override
  public void validate() {
    super.validate();
    Rectangle r = new Rectangle();
    r.setBounds(getBounds());
    r.crop(getInsets());
    r.resize(-1, -1);
    int size;
    switch (direction & (NORTH | SOUTH)) {
      case 0: // East or west.
        size = Math.min(r.height / 2, r.width);
        r.x += (r.width - size) / 2;
        break;
      default: // North or south
        size = Math.min(r.height, r.width / 2);
        r.y += (r.height - size) / 2;
        break;
    }

    size = Math.max(size, 1); // Size cannot be negative

    Point head, p2, p3;

    switch (direction) {
      case NORTH:
        head = new Point(r.x + r.width / 2, r.y);
        p2 = new Point(head.x - size, head.y + size);
        p3 = new Point(head.x + size, head.y + size);
        break;
      case SOUTH:
        head = new Point(r.x + r.width / 2, r.y + size);
        p2 = new Point(head.x - size, head.y - size);
        p3 = new Point(head.x + size, head.y - size);
        break;
      case WEST:
        head = new Point(r.x, r.y + r.height / 2);
        p2 = new Point(head.x + size, head.y - size);
        p3 = new Point(head.x + size, head.y + size);
        break;
      default:
        head = new Point(r.x + size, r.y + r.height / 2);
        p2 = new Point(head.x - size, head.y - size);
        p3 = new Point(head.x - size, head.y + size);
    }
    triangle.removeAllPoints();
    triangle.addPoint(head);
    triangle.addPoint(p2);
    triangle.addPoint(p3);
  }
 public DsToExcelConnectionFigure(DatasetToGridConnection con) {
   super();
   this.con = con;
   PolygonDecoration pd = new PolygonDecoration();
   PointList pl = new PointList();
   pl.addPoint(0, 0);
   pl.addPoint(-2, 2);
   pl.addPoint(0, 0);
   pl.addPoint(-2, -2);
   pd.setTemplate(pl);
   setLineStyle(SWT.LINE_DASH);
   setTargetDecoration(pd);
   setConnectionRouter(new BendpointConnectionRouter());
   setForegroundColor(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_YELLOW));
 }
 protected FlowFigure createFlowFigure(boolean directed) {
   FlowFigure flowFigure = new FlowFigure();
   if (directed) {
     PolygonDecoration decoration = new PolygonDecoration();
     PointList template = new PointList();
     template.addPoint(0, -LINE_WIDTH / 2);
     template.addPoint(0, LINE_WIDTH / 2);
     template.addPoint(-ARROW_LENGTH, LINE_WIDTH / 2 + 10);
     template.addPoint(-ARROW_LENGTH, -(LINE_WIDTH / 2 + 10));
     decoration.setTemplate(template);
     decoration.setScale(1, 1);
     flowFigure.setTargetDecoration(decoration);
   }
   flowFigure.setForegroundColor(DASHBOARD_FG);
   flowFigure.setLineWidth(LINE_WIDTH);
   return flowFigure;
 }
示例#15
0
 /**
  * Due to the on the fly creation of bendpoints we must gather the points using the routing
  * constraint as the connection may not be routed yet, meaning the points in the connection are
  * not up to date
  *
  * @param connectionFigure
  * @return
  */
 private PointList getPoints(Connection connectionFigure) {
   PointList points = new PointList();
   if (connectionFigure.getConnectionRouter() instanceof RectilinearRouter) {
     points.addAll(connectionFigure.getPoints());
     ((RectilinearRouter) connectionFigure.getConnectionRouter()).route(connectionFigure);
     return points;
   } else {
     List<?> bendpoints =
         (List<?>) connectionFigure.getConnectionRouter().getConstraint(connectionFigure);
     if (bendpoints == null) {
       bendpoints = Collections.EMPTY_LIST;
     }
     Point firstPoint = connectionFigure.getPoints().getFirstPoint();
     Point lastPoint = connectionFigure.getPoints().getLastPoint();
     if ((firstPoint.x == 100 && firstPoint.y == 100)
         || (lastPoint.x == 100 && lastPoint.y == 100)) {
       // the connection may need to be routed
       // as well as the source and target if connectors
       if (parent instanceof ConnectorEditPart) {
         ConnectorEditPart con = (ConnectorEditPart) parent;
         if (con.getSource() instanceof ConnectorEditPart) {
           ConnectorEditPart source = (ConnectorEditPart) con.getSource();
           source.getConnectionFigure().getConnectionRouter().route(source.getConnectionFigure());
         }
         if (con.getTarget() instanceof ConnectorEditPart) {
           ConnectorEditPart target = (ConnectorEditPart) con.getTarget();
           target.getConnectionFigure().getConnectionRouter().route(target.getConnectionFigure());
         }
       }
       connectionFigure.getConnectionRouter().route(connectionFigure);
     }
     if (connectionFigure.getPoints().size() != bendpoints.size()) {
       // rectilinear will have the start and end points in the
       // routing constraint
       points.addPoint(connectionFigure.getPoints().getFirstPoint());
     }
     for (int i = 0; i < bendpoints.size(); i++) {
       Bendpoint bp = (Bendpoint) bendpoints.get(i);
       points.addPoint(bp.getLocation());
     }
     if (connectionFigure.getPoints().size() != bendpoints.size()) {
       points.addPoint(connectionFigure.getPoints().getLastPoint());
     }
   }
   return points;
 }
  /** {@inheritDoc} */
  public PointList getDrawPoints() {
    PointList result = new PointList();
    Rectangle bounds = getBounds();
    double cellWidth = bounds.preciseWidth() * 0.618;
    double cellHeight = bounds.preciseHeight() / 2;

    result.addPoint(new PrecisionPoint(0.0, 0.0));
    //		result.addPoint(new PrecisionPoint(cellWidth * 2, 0.0));
    result.addPoint(new PrecisionPoint(cellWidth, 0.0));
    result.addPoint(new PrecisionPoint(bounds.preciseWidth(), cellHeight));
    result.addPoint(new PrecisionPoint(cellWidth, bounds.preciseHeight()));

    //		result.addPoint(new PrecisionPoint(cellWidth * 2, bounds.preciseHeight()));
    result.addPoint(new PrecisionPoint(0.0, bounds.preciseHeight()));
    //		result.addPoint(new PrecisionPoint(cellWidth, cellHeight));

    return result;
  }
  /**
   * getPointsFromConstraint Utility method retrieve the PointList equivalent of the bendpoint
   * constraint set in the Connection.
   *
   * @param conn Connection to retrieve the constraint from.
   * @return PointList list of points that is the direct equivalent of the set constraint.
   */
  public PointList getPointsFromConstraint(final Connection conn) {
    final List bendpoints = (List) conn.getRoutingConstraint();
    if (bendpoints == null) {
      return new PointList();
    }

    final PointList points = new PointList(bendpoints.size());
    for (int i = 0; i < bendpoints.size(); i++) {
      final Bendpoint bp = (Bendpoint) bendpoints.get(i);
      points.addPoint(bp.getLocation());
    }

    DTreeRouter.straightenPoints(points, MapModeUtil.getMapMode(conn).DPtoLP(3));
    return points;
  }
 static {
   points.addPoint(2, 10);
   points.addPoint(2, 2);
   points.addPoint(4, 4);
   points.addPoint(6, 5);
   points.addPoint(7, 5);
   points.addPoint(8, 5);
   points.addPoint(10, 4);
   points.addPoint(12, 2);
   points.addPoint(12, 10);
 }
  private void processStaleConnections() {
    Iterator<Connection> iter = staleConnections.iterator();
    if (iter.hasNext() && connectionToPaths == null) {
      connectionToPaths = new HashMap<Connection, Path>();
      hookAll();
    }

    while (iter.hasNext()) {
      Connection conn = (Connection) iter.next();

      Path path = (Path) connectionToPaths.get(conn);
      if (path == null) {
        path = new Path(conn);
        connectionToPaths.put(conn, path);
        algorithm.addPath(path);
      }

      List<?> constraint = (List<?>) getConstraint(conn);
      if (constraint == null) {
        constraint = Collections.EMPTY_LIST;
      }

      Point start = conn.getSourceAnchor().getReferencePoint().getCopy();
      Point end = conn.getTargetAnchor().getReferencePoint().getCopy();

      container.translateToRelative(start);
      container.translateToRelative(end);

      path.setStartPoint(start);
      path.setEndPoint(end);

      if (!constraint.isEmpty()) {
        PointList bends = new PointList(constraint.size());
        for (int i = 0; i < constraint.size(); i++) {
          Bendpoint bp = (Bendpoint) constraint.get(i);
          bends.addPoint(bp.getLocation());
        }
        path.setBendPoints(bends);
      } else {
        path.setBendPoints(null);
      }

      isDirty |= path.isDirty;
    }
    staleConnections.clear();
  }
示例#20
0
 @Override
 public void execute() {
   // configure the request
   EditPart source = request.getSourceEditPart();
   EditPart target = request.getTargetEditPart();
   PointList list = feedback.getPoints();
   DiagramEditPart diagramEditPart = null;
   if (source.getParent() instanceof DiagramEditPart) {
     diagramEditPart = (DiagramEditPart) source.getParent();
   } else if (source instanceof DiagramEditPart) {
     diagramEditPart = (DiagramEditPart) source;
   } else {
     if (source.getParent().getParent() instanceof DiagramEditPart) {
       diagramEditPart = (DiagramEditPart) source.getParent().getParent();
     }
   }
   if (diagramEditPart == null) {
     return;
   }
   if (!(source instanceof DiagramEditPart || target instanceof DiagramEditPart)) {
     // one must be whitespace, we make it the target
     request.setTargetEditPart(diagramEditPart);
     // additionally we must cut the drawn connection
     // in half to share room with the element that will
     // be auto-created
     PointList newList = new PointList();
     newList.addPoint(list.getFirstPoint());
     if (list.size() == 4) {
       // rectilinear routing will have a three points
       newList.addPoint(list.getPoint(1));
     }
     newList.addPoint(list.getMidpoint());
     feedback.setPoints(newList);
   }
   // create the active tool's element first
   CreateConnectionCommand command = new CreateConnectionCommand(request, feedback);
   command.execute();
   Connector_c newConnector = command.result;
   if (newConnector == null) {
     return;
   }
   // we need to now refresh the diagram to get the new edit part
   source.refresh();
   source.getParent().refresh();
   GraphicalEditPart newPart =
       (GraphicalEditPart) source.getViewer().getEditPartRegistry().get(newConnector);
   // transfer the feedback connection points to the newly created
   // edit part
   ((Connection) newPart.getFigure()).setPoints(feedback.getPoints().getCopy());
   // now adjust the request for the new element to be created for each
   // terminal specification that requires auto-creation
   createElementForTerminalSpec(
       autoStartSpec,
       ((NonRootModelElement) diagramEditPart.getModel()).getModelRoot(),
       list,
       newPart,
       target,
       diagramEditPart);
   createElementForTerminalSpec(
       autoEndSpec,
       ((NonRootModelElement) diagramEditPart.getModel()).getModelRoot(),
       list,
       newPart,
       target,
       diagramEditPart);
 }
    /**
     * Update the arrow polyline taking in account new figure's size
     *
     * @param figureWidth the new figure width
     * @param figureHeight the new figure height
     */
    public void updateArrow(int figureWidth, int figureHeight) {
      // handle insets to avoid figure growing indefinitely
      figureWidth -= getInsets().left + getInsets().right;
      figureHeight -= getInsets().top + getInsets().bottom;
      if (getDurationArrow() != null) {
        int halfLineWidth = getLineWidth() / 2;
        if (vertical) {
          PointList points = new PointList(8);
          int centerX = figureWidth / 2;
          points.addPoint(centerX - ARROW_SEMI_WIDTH, halfLineWidth + ARROW_HEIGHT);
          points.addPoint(centerX, halfLineWidth);
          points.addPoint(centerX + ARROW_SEMI_WIDTH, halfLineWidth + ARROW_HEIGHT);
          points.addPoint(centerX, halfLineWidth);
          points.addPoint(centerX, figureHeight - halfLineWidth);
          points.addPoint(centerX - ARROW_SEMI_WIDTH, figureHeight - halfLineWidth - ARROW_HEIGHT);
          points.addPoint(centerX, figureHeight - halfLineWidth);
          points.addPoint(centerX + ARROW_SEMI_WIDTH, figureHeight - halfLineWidth - ARROW_HEIGHT);
          getDurationArrow().setPoints(points);
          Point topLeft = getLocation().getTranslated(getInsets().left, getInsets().top);
          getDurationArrow()
              .setBounds(new Rectangle(topLeft, new Dimension(figureWidth, figureHeight)));
        } else {
          PointList points = new PointList(8);
          int centerY = figureHeight / 2;
          points.addPoint(halfLineWidth + ARROW_HEIGHT, centerY - ARROW_SEMI_WIDTH);
          points.addPoint(halfLineWidth, centerY);
          points.addPoint(halfLineWidth + ARROW_HEIGHT, centerY + ARROW_SEMI_WIDTH);
          points.addPoint(halfLineWidth, centerY);
          points.addPoint(figureWidth - halfLineWidth, centerY);

          points.addPoint(figureWidth - halfLineWidth - ARROW_HEIGHT, centerY - ARROW_SEMI_WIDTH);
          points.addPoint(figureWidth - halfLineWidth, centerY);
          points.addPoint(figureWidth - halfLineWidth - ARROW_HEIGHT, centerY + ARROW_SEMI_WIDTH);

          getDurationArrow().setPoints(points);
          Point topLeft = getLocation().getTranslated(getInsets().left, getInsets().top);
          getDurationArrow()
              .setBounds(new Rectangle(topLeft, new Dimension(figureWidth, figureHeight)));
        }
      }
    }
  @Override
  protected void drawSymbol(Graphics g) {
    PointList points = null;

    super.drawSymbol(g);

    int centerPointX = (int) Math.ceil((H_EXTENT / 2.0f)); // Center point of odd #.

    switch (this.featureCategory) {
      case BUS_ACCESS:
      case DATA_ACCESS:
        // Configure GC.
        g.setForegroundColor(this.getForegroundColor());
        g.setBackgroundColor(ColorConstants.white);
        g.setLineWidth(2);

        // Create point list that defines the symbol.
        points = new PointList();

        /* Populate point list. */
        points.addPoint(centerPointX, 0);
        points.addPoint(0, V_EXTENT - 8);
        points.addPoint(0, V_EXTENT);
        points.addPoint(centerPointX, V_EXTENT - 2);
        points.addPoint(H_EXTENT, V_EXTENT);
        points.addPoint(H_EXTENT, V_EXTENT - 8);

        // Fill symbol.
        g.fillPolygon(points);
        // Draw symbol.
        g.drawPolygon(points);

        break;
      case SUBPROGRAM_ACCESS:
      case SUBPROGRAM_GROUP_ACCESS:
        // Configure GC
        if (this.featureCategory == FeatureAdapterCategory.SUBPROGRAM_ACCESS) {
          g.setBackgroundColor(ColorConstants.white);
          g.setForegroundColor(ColorConstants.black);
        } else {
          g.setBackgroundColor(ColorConstants.black);
          g.setForegroundColor(ColorConstants.white);
        }

        g.setLineCap(SWT.CAP_ROUND);
        g.setLineWidth(2);

        int ovalWidth = H_EXTENT;
        int ovalHeight = V_EXTENT;
        // Draw oval.
        Rectangle ovalRect =
            new Rectangle(
                (int) (0.5f * (H_EXTENT - ovalWidth)),
                (int) (0.5f * (V_EXTENT - ovalHeight)),
                ovalWidth,
                ovalHeight);
        g.fillOval(ovalRect);

        if (this.featureCategory == FeatureAdapterCategory.SUBPROGRAM_ACCESS) g.drawOval(ovalRect);

        int triangleWidth = 7;
        int triangleHeight = 5;
        int triangleStartX = (int) Math.ceil((0.5f * (H_EXTENT - triangleWidth)));
        int triangleStartY = (int) Math.ceil((0.5f * (V_EXTENT - triangleHeight)));

        // Draw triangle.
        g.drawLine(triangleStartX, triangleStartY, centerPointX, triangleStartY + triangleHeight);
        g.drawLine(
            triangleStartX + triangleWidth,
            triangleStartY,
            centerPointX,
            triangleStartY + triangleHeight);

        break;
    }
  }
示例#23
0
  @Override
  public void paint(Graphics graphics) {

    Rectangle r = getBounds();
    if (getShape() == 0) {

      // Define the points of a parallelogram
      Point p1 = new Point(r.x + r.width / 12, r.y);
      Point p2 = new Point(r.x + r.width, r.y);
      Point p3 = new Point(r.x, r.y + r.height);
      Point p4 = new Point(r.x + 11 * r.width / 12, r.y + r.height);

      PointList pointList = new PointList();
      pointList.addPoint(p1);
      pointList.addPoint(p2);
      pointList.addPoint(p3);
      pointList.addPoint(p4);

      // Fill the shape
      graphics.fillPolygon(pointList);
      // Draw the outline
      graphics.drawLine(p1, p2);
      graphics.drawLine(p1, p3);
      graphics.drawLine(p3, p4);
      graphics.drawLine(p2, p4);

    } else {
      // Define the points of a parallelogram
      Point p1 = new Point(r.x + r.width / 12, r.y);
      Point p2 = new Point(r.x + r.width, r.y);
      Point p3 = new Point(r.x, r.y + 3 * r.height / 4);
      Point p4 = new Point(r.x + 11 * r.width / 12, r.y + 3 * r.height / 4);

      PointList pointList = new PointList();
      pointList.addPoint(p1);
      pointList.addPoint(p2);
      pointList.addPoint(p3);
      pointList.addPoint(p4);
      // undeveloped element status
      if (getShape() == 1) {
        Point p5 = new Point(r.x + r.width / 2, r.y + 3 * r.height / 4);
        Point p6 = new Point(r.x + 5 * r.width / 8, r.y + 7 * r.height / 8);
        Point p7 = new Point(r.x + r.width / 2, r.y + r.height);
        Point p8 = new Point(r.x + 3 * r.width / 8, r.y + 7 * r.height / 8);

        pointList.addPoint(p5);
        pointList.addPoint(p6);
        pointList.addPoint(p7);
        pointList.addPoint(p8);
        // Fill the shape
        graphics.fillPolygon(pointList);

        // Draw the outline
        graphics.drawLine(p1, p2);
        graphics.drawLine(p1, p3);
        graphics.drawLine(p3, p4);
        graphics.drawLine(p2, p4);

        // Draw the outline
        graphics.drawLine(p5, p6);
        graphics.drawLine(p6, p7);
        graphics.drawLine(p7, p8);
        graphics.drawLine(p5, p8);

      }
      // uninstantiated element status
      else if (getShape() == 2) {

        Point p5 = new Point(r.x + r.width / 2, r.y + 3 * r.height / 4);
        Point p6 = new Point(r.x + 5 * r.width / 8, r.y + 7 * r.height / 8);
        Point p7 = new Point(r.x + r.width / 2, r.y + r.height);
        Point p8 = new Point(r.x + 3 * r.width / 8, r.y + 7 * r.height / 8);

        pointList.addPoint(p5);
        pointList.addPoint(p6);
        pointList.addPoint(p7);
        pointList.addPoint(p8);
        // Fill the shape
        graphics.fillPolygon(pointList);

        // Draw the outline
        graphics.drawLine(p1, p2);
        graphics.drawLine(p1, p3);
        graphics.drawLine(p3, p4);
        graphics.drawLine(p2, p4);

        // Draw the outline
        graphics.drawLine(p5, p6);
        graphics.drawLine(p6, p8);
        graphics.drawLine(p5, p8);

      }
      // undeveloped and uninstantiated element status
      else if (getShape() == 3) {

        Point p5 = new Point(r.x + r.width / 2, r.y + 3 * r.height / 4);
        Point p6 = new Point(r.x + 5 * r.width / 8, r.y + 7 * r.height / 8);
        Point p7 = new Point(r.x + r.width / 2, r.y + r.height);
        Point p8 = new Point(r.x + 3 * r.width / 8, r.y + 7 * r.height / 8);

        pointList.addPoint(p5);
        pointList.addPoint(p6);
        pointList.addPoint(p7);
        pointList.addPoint(p8);
        // Fill the shape
        graphics.fillPolygon(pointList);

        // Draw the outline
        graphics.drawLine(p1, p2);
        graphics.drawLine(p1, p3);
        graphics.drawLine(p3, p4);
        graphics.drawLine(p2, p4);

        // Draw the outline
        graphics.drawLine(p5, p6);
        graphics.drawLine(p6, p7);
        graphics.drawLine(p7, p8);
        graphics.drawLine(p5, p8);
        graphics.drawLine(p6, p8);
      }
    }

    // Move the first label to the center of the parallelogram
    WrappingLabel label = (WrappingLabel) getChildren().get(0);
    LayoutUtil.moveToCenterAndUp(label, this, graphics);
    label.paint(graphics);
    // Move the second label to the center of the parallelogram
    label = (WrappingLabel) getChildren().get(1);
    LayoutUtil.moveToCenterAndDown(label, this, graphics);
    label.paint(graphics);
  }
示例#24
0
  private void createElementForTerminalSpec(
      TerminalSpecification_c autoCreationSpec,
      ModelRoot modelRoot,
      PointList line,
      EditPart newPart,
      EditPart targetPart,
      final DiagramEditPart diagramEditPart) {
    ElementSpecification_c specification =
        ElementSpecification_c.getOneGD_ESOnR209(autoCreationSpec);
    if (specification != null && request instanceof GraphicsConnectionCreateRequest) {
      // deactivate the current tool
      ModelTool_c activeTool =
          ModelTool_c.ModelToolInstance(
              modelRoot,
              new ClassQueryInterface_c() {

                @Override
                public boolean evaluate(Object candidate) {
                  return ((ModelTool_c) candidate).getActive();
                }
              });
      activeTool.setActive(false);
      // find the new tool and activate it
      ModelTool_c newTool =
          ModelTool_c.getOneCT_MTLOnR103(
              specification,
              new ClassQueryInterface_c() {

                @Override
                public boolean evaluate(Object candidate) {
                  ModelTool_c tool = (ModelTool_c) candidate;
                  return Model_c.getOneGD_MDOnR100(tool) == diagramEditPart.getModel();
                }
              });
      newTool.setActive(true);
      // create the new element
      if (specification.getSymboltype().equals("connector")) { // $NON-NLS-1$
        // creating a connector
        // we want to create the new connector from the
        // midpoint of the drawn line to the end of the
        // drawn line
        PointList newLine = new PointList();
        newLine.addPoint(line.getLastPoint());
        if (line.size() == 4) {
          // rectilinear routing will have a three points
          newLine.addPoint(line.getPoint(2));
        }
        newLine.addPoint(line.getMidpoint());
        feedback.setPoints(newLine);
        // we also need to adjust the request's source and
        // target edit part, we swap the original target as the
        // source as if the new connection was drawn from
        // the original destination element
        request.setTargetEditPart(newPart);
        request.setSourceEditPart(targetPart);
        // need to update the location in the request for
        // those connectors that end on whitespace
        request.setLocation(line.getMidpoint());
        // we need to configure the proper tool id in the
        // request
        GraphicsConnectionCreateRequest gRequest = (GraphicsConnectionCreateRequest) request;
        gRequest.setToolId(newTool.getTool_id());
        CreateConnectionCommand command = new CreateConnectionCommand(request, feedback);
        command.disableCropping();
        command.execute();
        // reset the active tool states
        newTool.setActive(false);
        activeTool.setActive(true);
      } else if (specification.getSymboltype().equals("shape")) { // $NON-NLS-1$
        // TODO: support shape auto creation
      }
    }
    // otherwise this is not an auto create specification
  }
 public ZeroToOneDecoration() {
   this.setFill(true);
   this.setForegroundColor(DF_FORE);
   this.setBackgroundColor(DF_BACK);
   PointList pl = new PointList();
   pl.addPoint(0, 0);
   pl.addPoint(-7, 0);
   pl.addPoint(-7, 7);
   pl.addPoint(-7, 0);
   pl.addPoint(-7, 1);
   pl.addPoint(-8, 3);
   pl.addPoint(-10, 4);
   pl.addPoint(-12, 4);
   pl.addPoint(-14, 3);
   pl.addPoint(-15, 1);
   pl.addPoint(-15, -1);
   pl.addPoint(-14, -3);
   pl.addPoint(-12, -4);
   pl.addPoint(-10, -4);
   pl.addPoint(-7, -1);
   pl.addPoint(-7, 0);
   pl.addPoint(-7, -7);
   pl.addPoint(-7, 0);
   pl.addPoint(0, 0);
   this.setTemplate(pl);
   this.setScale(1, 1);
 }
 static {
   DIAMOND_TIP.addPoint(-4, 0);
   DIAMOND_TIP.addPoint(-2, 1);
   DIAMOND_TIP.addPoint(0, 0);
   DIAMOND_TIP.addPoint(-2, -1);
 }
  /**
   *
   *
   * <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;
  }