Пример #1
0
  /**
   * Places the given end label below the edge.
   *
   * @param node source node of the edge the label belongs to.
   * @param label the label to place.
   * @param port the end port of the edge the label is nearest to.
   * @param labelSpacing space between objects and labels.
   */
  private void placeEndLabelUpwards(
      final LNode node, final LLabel label, final LPort port, final double labelSpacing) {

    // Remember some stuff
    KVector labelPosition = label.getPosition();
    KVector absolutePortPosition = KVector.sum(port.getPosition(), port.getNode().getPosition());
    KVector absolutePortAnchor = port.getAbsoluteAnchor();
    LMargin portMargin = port.getMargin();

    // Actually calculate the coordinates
    switch (port.getSide()) {
      case WEST:
        labelPosition.x =
            Math.min(absolutePortPosition.x, absolutePortAnchor.x)
                - portMargin.left
                - label.getSize().x
                - labelSpacing;
        labelPosition.y = port.getAbsoluteAnchor().y - label.getSize().y - labelSpacing;
        break;

      case EAST:
        labelPosition.x =
            Math.max(absolutePortPosition.x + port.getSize().x, absolutePortAnchor.x)
                + portMargin.right
                + labelSpacing;
        labelPosition.y = port.getAbsoluteAnchor().y - label.getSize().y - labelSpacing;
        break;

      case NORTH:
        labelPosition.x = port.getAbsoluteAnchor().x + labelSpacing;
        labelPosition.y =
            Math.min(absolutePortPosition.y, absolutePortAnchor.y)
                - portMargin.top
                - label.getSize().y
                - labelSpacing;
        break;

      case SOUTH:
        labelPosition.x = port.getAbsoluteAnchor().x + labelSpacing;
        labelPosition.y =
            Math.max(absolutePortPosition.y + port.getSize().y, absolutePortAnchor.y)
                + portMargin.bottom
                + labelSpacing;
        break;
    }
  }