Chinaunix首页 | 论坛 | 博客
  • 博客访问: 515548
  • 博文数量: 95
  • 博客积分: 5168
  • 博客等级: 大校
  • 技术积分: 1271
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-28 23:31
文章分类

全部博文(95)

文章存档

2013年(2)

2012年(3)

2011年(1)

2010年(8)

2009年(81)

分类:

2009-10-13 00:07:21

 

   当我们点击tool栏的创建节点工具时,Tool就会是CreationTool,

 

然后在绘图区移动时会执行如下:

protected boolean handleMove() {

    updateTargetRequest();

    updateTargetUnderMouse();

    setCurrentCommand(getCommand());

    showTargetFeedback();

//feedback

    return true;

}

 

protected void updateTargetRequest() {

    CreateRequest req = getCreateRequest();

    if (isInState(STATE_DRAG_IN_PROGRESS)) {

       Point loq = getStartLocation();

       Rectangle bounds = new Rectangle(loq, loq);

       bounds.union(loq.getTranslated(getDragMoveDelta()));

       req.setSize(bounds.getSize());

       req.setLocation(bounds.getLocation());

       req.getExtendedData().clear();

       if (!getCurrentInput().isAltKeyDown() && helper != null) {

           PrecisionRectangle baseRect = new PrecisionRectangle(bounds);

           PrecisionRectangle result = baseRect.getPreciseCopy();

           helper.snapRectangle(req, PositionConstants.NSEW,

              baseRect, result);

           req.setLocation(result.getLocation());

           req.setSize(result.getSize());

       }

    } else {

       req.setSize(null);

       req.setLocation(getLocation());

    }

}

当我们从tool栏选择工具,然后在绘图区单击放开时就会创建这个图形。

 

protected boolean handleButtonUp(int button) {

    if (stateTransition(STATE_DRAG | STATE_DRAG_IN_PROGRESS, STATE_TERMINAL)) {

       eraseTargetFeedback();

       unlockTargetEditPart();

       performCreation(button);

    }

 

    setState(STATE_TERMINAL);

    handleFinished();

 

    return true;

}

 

protected void performCreation(int button) {

    EditPartViewer viewer = getCurrentViewer();

    executeCurrentCommand();

    selectAddedObject(viewer);

}

 

protected void handleFinished() {

    if (unloadWhenFinished())

       getDomain().loadDefaultTool();

    else

       reactivate();

}

对于上面的过程targetEditPart都是contentEditpart.所以command都是执行contentEditpartgetCommand(REQ_CREATE);

 

对于feedback,contentEditpartpolicyxylayoutpolicy,showTargetFeedback如下:

public void showTargetFeedback(Request request) {

    if (REQ_ADD.equals(request.getType())

           || REQ_CLONE.equals(request.getType())

           || REQ_MOVE.equals(request.getType())

           || REQ_RESIZE_CHILDREN.equals(request.getType())

           || REQ_CREATE.equals(request.getType()))

       showLayoutTargetFeedback(request);

 

    if (REQ_CREATE.equals(request.getType())) {

       CreateRequest createReq = (CreateRequest)request;

       if (createReq.getSize() != null)

           showSizeOnDropFeedback(createReq);

    }

}

故会执行showSizeOnDropFeedback

protected void showSizeOnDropFeedback(CreateRequest request) {

    Point p = new Point(request.getLocation().getCopy());

    IFigure feedback = getSizeOnDropFeedback(request);

    feedback.translateToRelative(p);

    Dimension size = request.getSize().getCopy();

    feedback.translateToRelative(size);

    feedback.setBounds(new Rectangle(p, size).expand(getCreationFeedbackOffset(request)));

}

阅读(1113) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~