private void createConnector(ITreeElement from, ITreeElement to, int connectorType) { int xPos1 = from.getX(); int yPos1 = from.getY(); int xPos2 = to.getX(); int yPos2 = to.getY(); Point begin = new Point(0, 0); Point end = new Point(0, 0); int mode = Connector.HORIZONTAL; // connect horizontal if x offset is equal int sy1 = height / 2, sy2 = height / 2; if (yPos2 > yPos1) { sy1 = height; sy2 = 0; } else if (yPos2 < yPos1) { sy1 = 0; sy2 = height; } int sx1 = width / 2, sx2 = width / 2; if (xPos2 > xPos1) { sx1 = width; sx2 = 0; } if (xPos2 < xPos1) { sx1 = 0; sx2 = width; } begin.x = BORDER + xPos1 * (hspacing + width) + sx1; begin.y = BORDER + yPos1 * (vspacing + height) + sy1; end.x = BORDER + xPos2 * (hspacing + width) + sx2; end.y = BORDER + yPos2 * (vspacing + height) + sy2; int dX = end.x - begin.x; int dY = end.y - begin.y; int arrowLength = (int) Math.sqrt((dX * dX) + (dY * dY)); if (arrowLength > 0) { if (mode == Connector.RIGHT) { ConnectArrow arrow = new ConnectArrow(begin, end); connectors.addConnectArrow(arrow); } else { ConnectArrow arrow = new ConnectArrow(end, begin); connectors.addConnectArrow(arrow); } } else { VersionTreePlugin.log( IStatus.ERROR, "Attempt to draw a line between the same begin and end points."); return; } }
public void drawConnectors(ITreeElement node) { for (ITreeElement child : node.getChildren()) { if (child instanceof IRevision) { createConnector(node, child, MergePoint.INITIAL); for (MergePoint mergeToPoint : ((IRevision) child).getMergeToRevisions()) { IRevision mergeToRevision = mergeToPoint.getMergeRevision(); for (String brTo : mergeToRevision.getBranchTags()) { if (isBranchVisible(brTo)) { createConnector(child, mergeToRevision, MergePoint.MERGE); break; } } } drawConnectors(child); } else if (child instanceof IBranch) { IBranch childBranch = (IBranch) child; if ((!childBranch.isEmpty() || this.getTreeViewConfig().drawEmptyBranches()) && isBranchVisible(childBranch.getName())) { // case when parent is dead revision and child element is branch if (!(node instanceof IRevision && ((IRevision) node).getLogEntry().isDeletion())) { createConnector(node, child, MergePoint.INITIAL); } drawConnectors(child); } } } }