自定义Decoration

大家都知道new PolygonDecoration就表示带箭头,但有的时候不想是箭头,想搞个圆圈,或者方块,那怎么做呢?那就只能自定义PolygonDecoration咯,我昨天自定义了一个圆圈,给大家看看吧
package com.netunit.workbench.parts;

import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.RotatableDecoration;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;

public class CircleDecoration extends Ellipse implements RotatableDecoration {
private int myRadius = 5;
private Point myCenter = new Point();

public void setRadius(int radius){
erase();
myRadius = Math.abs(radius);
bounds = null;
repaint();
}

public void setLineWidth(int width){
super.setLineWidth(width);
}

public Rectangle getBounds() {
if (bounds == null){
int diameter = myRadius * 2;
bounds = new Rectangle(myCenter.x - myRadius, myCenter.y - myRadius, diameter, diameter);
bounds.expand(lineWidth / 2, lineWidth / 2);
}
return bounds;
}

public void setLocation(Point p) {
if (myCenter.equals(p)){
return;
}
myCenter.setLocation(p);
bounds = null;
}

public void setReferencePoint(Point p) {
//ignore, does not make sense to rotate circle
}

}

下面是效果图:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值