自定义反馈,比如定制椭圆形图形的选择柄

覆盖布局策略中的createChildEditPolicy方法
@Override
 protected EditPolicy createChildEditPolicy(EditPart child) {
  return new CustomResizableEditPolicy();
 }
 
 
 package tutogef.policies;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.FigureUtilities;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.editpolicies.ResizableEditPolicy;
import org.eclipse.gef.handles.ResizableHandleKit;

/*
 * 自定义反馈
 * 反馈分源反馈和目标反馈
 * 目标就是你鼠标指向的方向,如果你鼠标停留在一个椭圆上,那这个椭圆就是目标,由目标提供的反馈就叫做目标反馈
 *
 */
public class CustomResizableEditPolicy extends ResizableEditPolicy {
 /*
  * createDragSourceFeedbackFigure() 方法决定用户拖动图形时,随鼠标移动的反馈图形的形状和颜色
  *
  */
 @Override
 protected IFigure createDragSourceFeedbackFigure() {

  GraphicalEditPart host = (GraphicalEditPart) getHost();
  IFigure figure = host.getFigure();
  if (figure instanceof Ellipse) {
   // Use a ghost rectangle for feedback
   Ellipse r = new Ellipse();
   r.setLayoutManager(new FlowLayout());
   FigureUtilities.makeGhostShape(r);
   r.setLineStyle(Graphics.LINE_DOT);
   r.setForegroundColor(ColorConstants.white);
   r.setBounds(getInitialFeedbackBounds());

   /*
    * Label label = new Label("我是反馈");
    * label.setBackgroundColor(ColorConstants.red);
    * label.setForegroundColor(ColorConstants.red); r.add(label);
    */
   addFeedback(r);// 添加至反馈层
   return r;
  } else {
   return super.createDragSourceFeedbackFigure();
  }

 }

 /*
  * createSelectionHandles() 方法决定"控制柄"( ResizeHandle )
  */
 @Override
 protected List createSelectionHandles() {
  GraphicalEditPart host = (GraphicalEditPart) getHost();
  IFigure figure = host.getFigure();
  if(figure instanceof Ellipse){
  List list = new ArrayList();
//  ResizableHandleKit.addMoveHandle(host, list);
  // ResizableHandleKit.addMoveHandle(host, handles);
  ResizableHandleKit.addHandle(host, list, PositionConstants.EAST);
  ResizableHandleKit.addHandle(host, list, PositionConstants.SOUTH);
  ResizableHandleKit.addHandle(host, list, PositionConstants.WEST);
  ResizableHandleKit.addHandle(host, list, PositionConstants.NORTH);
  return list;
  }else{
   return super.createSelectionHandles();
  }
 }
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值