private Point2D calculateLabelPoint(Line2D line,RectangleAnchor anchor,double deltaX,double deltaY){
  double x, y;
  boolean left=(anchor == RectangleAnchor.BOTTOM_LEFT || anchor == RectangleAnchor.LEFT || anchor == RectangleAnchor.TOP_LEFT);
  boolean right=(anchor == RectangleAnchor.BOTTOM_RIGHT || anchor == RectangleAnchor.RIGHT || anchor == RectangleAnchor.TOP_RIGHT);
  boolean top=(anchor == RectangleAnchor.TOP_LEFT || anchor == RectangleAnchor.TOP || anchor == RectangleAnchor.TOP_RIGHT);
  boolean bottom=(anchor == RectangleAnchor.BOTTOM_LEFT || anchor == RectangleAnchor.BOTTOM || anchor == RectangleAnchor.BOTTOM_RIGHT);
  Rectangle rect=line.getBounds();
  if (line.getX1() == line.getX2()) {
    x=line.getX1();
    y=(line.getY1() + line.getY2()) / 2.0;
    if (left) {
      x=x - deltaX;
    }
    if (right) {
      x=x + deltaX;
    }
    if (top) {
      y=Math.min(line.getY1(),line.getY2()) + deltaY;
    }
    if (bottom) {
      y=Math.max(line.getY1(),line.getY2()) - deltaY;
    }
  }
 else {
    x=(line.getX1() + line.getX2()) / 2.0;
    y=line.getY1();
    if (left) {
      x=Math.min(line.getX1(),line.getX2()) + deltaX;
    }
    if (right) {
      x=Math.max(line.getX1(),line.getX2()) - deltaX;
    }
    if (top) {
      y=y - deltaY;
    }
    if (bottom) {
      y=y + deltaY;
    }
  }
  return new Point2D.Double(x,y);
}

private Point2D calculateLabelPoint ( Line2D line , RectangleAnchor anchor , double deltaX , double deltaY ) { double x , y ; boolean left = ( anchor == RectangleAnchor . BOTTOM_LEFT || anchor == RectangleAnchor . LEFT || anchor == RectangleAnchor . TOP_LEFT ) ; boolean right = ( anchor == RectangleAnchor . BOTTOM_RIGHT || anchor == RectangleAnchor . RIGHT || anchor == RectangleAnchor . TOP_RIGHT ) ; boolean top = ( anchor == RectangleAnchor . TOP_LEFT || anchor == RectangleAnchor . TOP || anchor == RectangleAnchor . TOP_RIGHT ) ; boolean bottom = ( anchor == RectangleAnchor . BOTTOM_LEFT || anchor == RectangleAnchor . BOTTOM || anchor == RectangleAnchor . BOTTOM_RIGHT ) ; Rectangle rect = line . getBounds ( ) ; if ( line . getX1 ( ) == line . getX2 ( ) ) { x = line . getX1 ( ) ; y = ( line . getY1 ( ) + line . getY2 ( ) ) / 2.0 ; if ( left ) { x = x - deltaX ; } if ( right ) { x = x + deltaX ; } if ( top ) { y = Math . min ( line . getY1 ( ) , line . getY2 ( ) ) + deltaY ; } if ( bottom ) { y = Math . max ( line . getY1 ( ) , line . getY2 ( ) ) - deltaY ; } } else { x = ( line . getX1 ( ) + line . getX2 ( ) ) / 2.0 ; y = line . getY1 ( ) ; if ( left ) { x = Math . min ( line . getX1 ( ) , line . getX2 ( ) ) + deltaX ; } if ( right ) { x = Math . max ( line . getX1 ( ) , line . getX2 ( ) ) - deltaX ; } if ( top ) { y = y - deltaY ; } if ( bottom ) { y = y + deltaY ; } } return new Point2D . Double ( x , y ) ; }
calculates the anchor point for a label .
