给图元去掉句柄,且选中时改变图元的边框颜色

用GEF实现过拖拽例子的朋友都应该知道拖拽用的是CustomXYLyoutEditPolicy实现的,改变图元大小也是它实现的,那么我们就在这里做文章了
首先重写CustomXYLayoutEditPolicy中的createChildEditPolicy方法,代码如下
@Override
protected EditPolicy createChildEditPolicy(EditPart child) {
// TODO Auto-generated method stub
return new NeSelectionHandlesEditPolicy();
}

然后新建NeSelectionHandlesEditPolicy继承ResizableEditPolicy,实现createSelectionHandles方法,代码如下:
@Override
protected List<MoveHandle> createSelectionHandles() {

final List<MoveHandle> handle = new ArrayList<MoveHandle>();

handle.add(new MoveHandle((GraphicalEditPart) getHost()) {

protected void initialize() {
super.initialize();
setBorder(new LineBorder(1) {
public void paint(IFigure figure, Graphics graphics,
Insets insets) {
tempRect
.setBounds(getPaintRectangle(figure, insets));
if (getWidth() % 2 == 1) {
tempRect.width--;
tempRect.height--;
}
tempRect.shrink(getWidth() / 2, getWidth() / 2);
graphics.setLineWidth(getWidth());
if (getColor() != null)
graphics.setForegroundColor(getColor());
// draw roundRectangle with red color

graphics.setAntialias(SWT.ON);
graphics.setForegroundColor(ColorConstants.red);
graphics.drawRectangle(tempRect);
}
});

// add resize handle
// ResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
// handle, PositionConstants.EAST);
// ResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
// handle, PositionConstants.SOUTH);
// ResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
// handle, PositionConstants.WEST);
// ResizableHandleKit.addHandle((GraphicalEditPart) getHost(),
// handle, PositionConstants.NORTH);
}

});

return handle;

}
带注释的那几行则是与句柄有关的,大家自己试试吧
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值