分类:
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都是执行contentEditpart的getCommand(REQ_CREATE);
对于feedback,contentEditpart的policy是xylayoutpolicy,其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)));
}