java中的anchor属性,Java RectangleAnchor.BOTTOM_RIGHT属性代码示例

/**

* Calculates the anchor point for a label.

*

* @param line the line for the crosshair.

* @param anchor the anchor point.

* @param deltaX the x-offset.

* @param deltaY the y-offset.

*

* @return The anchor point.

*/

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();

// we expect the line to be vertical or horizontal

if (line.getX1() == line.getX2()) { // vertical

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 { // horizontal

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);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值