* .gwt-connectors-line { font-size: 1px; line-height:1px; background-color: black }
* .gwt-connectors-line-vertical { width:1px } .gwt-connectors-line-horizontal { height:1px }
*/
this.style = style;
AbsolutePanel panel = diagram.boundaryPanel;
boolean allowHorizontalDragging = false;
boolean allowVerticalDragging = false;
// Set line look and behavior
if (isVertical()) {
if (isSelected) {
this.setHTML(selectedVerticalLine(this.height + additionalHeight, style));
} else {
this.setHTML(verticalLine(this.height + additionalHeight, style));
}
allowHorizontalDragging = true;
} else if (isHorizontal()) {
if (isSelected) {
this.setHTML(selectedHorizontalLine(this.width + additionalWidth, style));
} else {
this.setHTML(horizontalLine(this.width + additionalWidth, style));
}
allowVerticalDragging = true;
}
// Set Section's cursor
if (isVertical()) {
DOM.setStyleAttribute(this.getElement(), "cursor", "w-resize");
} else if (isHorizontal()) {
DOM.setStyleAttribute(this.getElement(), "cursor", "n-resize");
}
// Add drag and drop functionality
this.sectionDragController = new AxisXYDragController(panel, true, allowHorizontalDragging, allowVerticalDragging) {
@Override
public void dragStart() {
// If dragged section startPoint or dragged section endPoint
// is glued to connectionPoint then split section into three
// to draw new lines to connectionPoint
try {
if (Section.this.startPointIsGluedToConnectionPoint() || Section.this.endPointIsGluedToConnectionPoint()) {
// Calculate new CornerPoints
ArrayList<CornerPoint> newCornerPoints = new ArrayList<CornerPoint>();
Point sp = Section.this.startPoint;
Point ep = Section.this.endPoint;
CornerPoint cp1 =
new CornerPoint(sp.getLeft() + (ep.getLeft() - sp.getLeft()) / 2, sp.getTop()
+ (ep.getTop() - sp.getTop()) / 2);
CornerPoint cp2 =
new CornerPoint(sp.getLeft() + (ep.getLeft() - sp.getLeft()) / 2, sp.getTop()
+ (ep.getTop() - sp.getTop()) / 2);
newCornerPoints.add(cp1);
newCornerPoints.add(cp2);
// Split Section
Section.this.splitSection(newCornerPoints);
}
} catch (Exception e) {
LOG.info("Section drag start error " + e.getMessage());
e.printStackTrace();
}
try {
super.dragStart();
} catch (Exception e) {
LOG.info("Section (super) drag start error " + e.getMessage());
e.printStackTrace();
}
}
@Override
public void dragMove() {
try {
if (isAllowHorizontalDragging()) {
if (Section.this.startPoint.getLeft() < Section.this.endPoint.getLeft()) {
Section.this.startPoint.setLeft(context.draggable.getAbsoluteLeft()
- context.boundaryPanel.getAbsoluteLeft());
Section.this.endPoint.setLeft(context.draggable.getAbsoluteLeft()
- context.boundaryPanel.getAbsoluteLeft() + width);
} else {
Section.this.startPoint.setLeft(context.draggable.getAbsoluteLeft()
- context.boundaryPanel.getAbsoluteLeft() + width);
Section.this.endPoint.setLeft(context.draggable.getAbsoluteLeft()
- context.boundaryPanel.getAbsoluteLeft());
}
}
if (isAllowVerticalDragging()) {
if (Section.this.startPoint.getTop() < Section.this.endPoint.getTop()) {
Section.this.startPoint.setTop(context.draggable.getAbsoluteTop()
- context.boundaryPanel.getAbsoluteTop());
Section.this.endPoint.setTop(context.draggable.getAbsoluteTop() - context.boundaryPanel.getAbsoluteTop()
+ height);
} else {
Section.this.startPoint.setTop(context.draggable.getAbsoluteTop()
- context.boundaryPanel.getAbsoluteTop() + height);
Section.this.endPoint.setTop(context.draggable.getAbsoluteTop() - context.boundaryPanel.getAbsoluteTop());
}
}
if (Section.this.connector.getNextSection(Section.this) != null) {
Section.this.connector.getNextSection(Section.this).update();
};
if (Section.this.connector.getPrevSection(Section.this) != null) {
Section.this.connector.getPrevSection(Section.this).update();
};
Section.this.connector.endEndPoint.update();
Section.this.connector.startEndPoint.update();
if (startPointDecoration != null) {
startPointDecoration.update(calculateStartPointDecorationDirection(), startPoint.getLeft(), startPoint
.getTop());
}
if (endPointDecoration != null) {
endPointDecoration.update(calculateEndPointDecorationDirection(), endPoint.getLeft(), endPoint.getTop());
}
} catch (Exception e) {
LOG.info("Section drag move error " + e.getMessage());
e.printStackTrace();
}
try {
// super.dragMove();
// To provide XY drag feature (BEGIN)
if (isAllowHorizontalDragging() == false) {
context.desiredDraggableX = initialDraggableLocation.getLeft() + boundaryOffsetX;
}
if (isAllowVerticalDragging() == false) {
context.desiredDraggableY = initialDraggableLocation.getTop() + boundaryOffsetY;
}
// To provide XY drag feature (END)
int desiredLeft = context.desiredDraggableX - boundaryOffsetX;
int desiredTop = context.desiredDraggableY - boundaryOffsetY;
if (getBehaviorConstrainedToBoundaryPanel()) {
desiredLeft =
Math.max(0, Math.min(desiredLeft, dropTargetClientWidth - context.draggable.getOffsetWidth()));
desiredTop =
Math.max(0, Math.min(desiredTop, dropTargetClientHeight - context.draggable.getOffsetHeight()));
}
if (isAllowHorizontalDragging()) {
if (startPoint.getTop().intValue() > endPoint.getTop().intValue()) {
desiredTop = endPoint.getTop();
} else {
desiredTop = startPoint.getTop();
}
}
if (isAllowVerticalDragging()) {
if (startPoint.getLeft().intValue() > endPoint.getLeft().intValue()) {
desiredLeft = endPoint.getLeft();
} else {
desiredLeft = startPoint.getLeft();
}
}
DOMUtil.fastSetElementPosition(movablePanel.getElement(), desiredLeft, desiredTop);
DropController newDropController = getIntersectDropController(context.mouseX, context.mouseY);
if (context.dropController != newDropController) {
if (context.dropController != null) {
context.dropController.onLeave(context);
}
context.dropController = newDropController;
if (context.dropController != null) {
context.dropController.onEnter(context);
}
}
if (context.dropController != null) {
context.dropController.onMove(context);
}
} catch (Exception e) {
LOG.info("Section (super) drag move error " + e.getMessage());
e.printStackTrace();
}
}
@Override
public void dragEnd() {
// If after dragging two or more neighbor Sections are aligned to the line
// (they form one single line), those neighbor Sections are merged to one.
if (Section.this.connector.sections.size() > 2) {
if ((Section.this.connector.getPrevSection(Section.this) != null)
&& (Section.this.connector.getPrevSection(Section.this).hasNoDimensions())) {
System.out.println("merge with preceding Section");
// Loop 2 times to remove two preceding Sections
try {
for (int i = 0; i < 2; i++) {
Section.this.startPoint = Section.this.connector.getPrevSection(Section.this).startPoint;
Section.this.startPointDecoration =
Section.this.connector.getPrevSection(Section.this).startPointDecoration;
Section.this.connector.getPrevSection(Section.this).removeFromDiagram();
Section.this.connector.sections.remove(Section.this.connector.getPrevSection(Section.this));
}
} catch (Exception e) {
// LOG.e("error merging sections", e);
}
}
if ((Section.this.connector.getNextSection(Section.this) != null)
&& (Section.this.connector.getNextSection(Section.this).hasNoDimensions())) {
System.out.println("merge with succeeding Section");
// Loop 2 times to remove two succeeding Sections
for (int i = 0; i < 2; i++) {
try {
Section.this.endPoint = Section.this.connector.getNextSection(Section.this).endPoint;
Section.this.endPointDecoration =
Section.this.connector.getNextSection(Section.this).endPointDecoration;
Section.this.connector.getNextSection(Section.this).removeFromDiagram();
Section.this.connector.sections.remove(Section.this.connector.getNextSection(Section.this));
} catch (Exception e) {
// LOG.e("Error while connecting sections...");
}
}
}
}
super.dragEnd();
connector.updateCornerPoints();
}
};
// Add line to given panel
panel.add(this, Math.min(this.startPoint.getLeft(), this.endPoint.getLeft()), Math.min(this.startPoint.getTop(),
this.endPoint.getTop()));
this.sectionDragController.makeDraggable(this);
this.sectionDragController.setBehaviorDragStartSensitivity(5);
this.sectionDragController.addDragHandler(new DragHandlerAdapter() {