给图元去掉句柄,且选中时改变图元的框子颜色
给图元去掉句柄,且选中时改变图元的边框颜色
用GEF实现过拖拽例子的朋友都应该知道拖拽用的是CustomXYLyoutEditPolicy实现的,改变图元大小也是它实现的,那么我们就在这里做文章了
首先重写CustomXYLayoutEditPolicy中的createChildEditPolicy方法,代码如下
然后新建NeSelectionHandlesEditPolicy继承ResizableEditPolicy,实现createSelectionHandles方法,代码如下:
用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; }带注释的那几行则是与句柄有关的,大家自己试试吧