}
}
public void invokeStep(InputEvent inputEvent, int x, int y, int anchorX, int anchorY, DrawingView view) {
ElbowConnection2 line = ownerConnection();
if (fSegment == 0) {
if ((inputEvent != null) && (inputEvent.isShiftDown())) {//������ʼ�˵����ӷ�ʽ(H <-> V)
Point p1 = line.pointAt(fSegment);
line.insertPointAt(new Point(p1), fSegment + 1);
int displayMode = ((Integer) line.getAttribute(ElbowConnection2.DISPLAY_MODE)).intValue();
if (displayMode == ElbowConnection2.V_V_MODE) {
line.setAttribute(ElbowConnection2.DISPLAY_MODE, new Integer(ElbowConnection2.H_V_MODE));
} else if (displayMode == ElbowConnection2.H_H_MODE) {
line.setAttribute(ElbowConnection2.DISPLAY_MODE, new Integer(ElbowConnection2.V_H_MODE));
} else if (displayMode == ElbowConnection2.H_V_MODE) {
line.setAttribute(ElbowConnection2.DISPLAY_MODE, new Integer(ElbowConnection2.V_V_MODE));
} else if (displayMode == ElbowConnection2.V_H_MODE) {
line.setAttribute(ElbowConnection2.DISPLAY_MODE, new Integer(ElbowConnection2.H_H_MODE));
} else {
//should not go here
System.out.println("ElbowHandle2: should not go here");
}
fSegment = 1;
} else if ((inputEvent != null) && (inputEvent.isControlDown())) {//�ı俪ʼ������������ӵ�ƫ��
int displayMode = ((Integer) line.getAttribute(ElbowConnection2.DISPLAY_MODE)).intValue();
Point startOffset = (Point) line.getAttribute(ElbowConnection2.START_OFFSET);
if (startOffset == null)
startOffset = new Point(0, 0);
if (displayMode == ElbowConnection2.V_V_MODE || displayMode == ElbowConnection2.V_H_MODE) {
startOffset.x = x - anchorX + initStartOffset.x;
line.setAttribute(ElbowConnection2.START_OFFSET, startOffset);
line.layoutConnection();
} else if (displayMode == ElbowConnection2.H_H_MODE || displayMode == ElbowConnection2.H_V_MODE) {
startOffset.y = y - anchorY + initStartOffset.y;
line.setAttribute(ElbowConnection2.START_OFFSET, startOffset);
line.layoutConnection();
} else {
//should not go here
System.out.println("ElbowHandle2: should not go here");
}
} else {//���ѿ�ʼ��
Point p1 = line.pointAt(fSegment);
Point p2 = line.pointAt(fSegment + 1);
int _x = (p1.x + p2.x) / 2;
int _y = (p1.y + p2.y) / 2;
line.insertPointAt(new Point(_x, _y), fSegment + 1);
line.insertPointAt(new Point(_x, _y), fSegment + 1);
fSegment = 2;
}
} else if (fSegment == line.pointCount() - 2) {//����ĩ�˵����ӷ�ʽ(H <-> V)
if ((inputEvent != null) && (inputEvent.isShiftDown())) {
Point p2 = line.pointAt(fSegment + 1);
line.insertPointAt(new Point(p2), fSegment + 1);
int displayMode = ((Integer) line.getAttribute(ElbowConnection2.DISPLAY_MODE)).intValue();
if (displayMode == ElbowConnection2.V_V_MODE) {
line.setAttribute(ElbowConnection2.DISPLAY_MODE, new Integer(ElbowConnection2.V_H_MODE));
} else if (displayMode == ElbowConnection2.H_H_MODE) {
line.setAttribute(ElbowConnection2.DISPLAY_MODE, new Integer(ElbowConnection2.H_V_MODE));
} else if (displayMode == ElbowConnection2.H_V_MODE) {
line.setAttribute(ElbowConnection2.DISPLAY_MODE, new Integer(ElbowConnection2.H_H_MODE));
} else if (displayMode == ElbowConnection2.V_H_MODE) {
line.setAttribute(ElbowConnection2.DISPLAY_MODE, new Integer(ElbowConnection2.V_V_MODE));
} else {
//should not go here
System.out.println("ElbowHandle2: should not go here");
}
} else if ((inputEvent != null) && (inputEvent.isControlDown())) {//�ı�ĩ������������ӵ�ƫ��
int displayMode = ((Integer) line.getAttribute(ElbowConnection2.DISPLAY_MODE)).intValue();
Point endOffset = (Point) line.getAttribute(ElbowConnection2.END_OFFSET);
if (endOffset == null)
endOffset = new Point(0, 0);
if (displayMode == ElbowConnection2.V_V_MODE || displayMode == ElbowConnection2.H_V_MODE) {
endOffset.x = x - anchorX + initEndOffset.x;
line.setAttribute(ElbowConnection2.END_OFFSET, endOffset);
line.layoutConnection();
} else if (displayMode == ElbowConnection2.V_H_MODE || displayMode == ElbowConnection2.H_H_MODE) {
endOffset.y = y - anchorY + initEndOffset.y;
line.setAttribute(ElbowConnection2.END_OFFSET, endOffset);
line.layoutConnection();
} else {
//should not go here
System.out.println("ElbowHandle2: should not go here");
}
} else {//����ĩ��
Point p1 = line.pointAt(fSegment);
Point p2 = line.pointAt(fSegment + 1);
int _x = (p1.x + p2.x) / 2;
int _y = (p1.y + p2.y) / 2;
line.insertPointAt(new Point(_x, _y), fSegment + 1);
line.insertPointAt(new Point(_x, _y), fSegment + 1);
}
} else {
Point p1 = line.pointAt(fSegment);
Point p2 = line.pointAt(fSegment + 1);
int ddx = x - fLastX;
int ddy = y - fLastY;
boolean _isCurrentVertical = isCurrentVertical();
Point np1;
Point np2;
//if (isVertical(p1, p2)) {
if (_isCurrentVertical) {
int cx = constrainX(p1.x + ddx);
np1 = new Point(cx, p1.y);
np2 = new Point(cx, p2.y);
} else {
int cy = constrainY(p1.y + ddy);
np1 = new Point(p1.x, cy);
np2 = new Point(p2.x, cy);
}
line.setPointAt(np1, fSegment);
line.setPointAt(np2, fSegment + 1);
fLastX = x;
fLastY = y;
}
}