/** * This method is called on either the first or last node in the connection. Depending on where it * attaches to the node, the drag point can only be moved in the direction of the attaching side. * * @param indexInConnection the index within the connection * @param node the attached node * @param diffx the x amount to move * @param diffy the y amount to move */ private void moveConstrained(int indexInConnection, Node node, double diffx, double diffy) { double amountX = diffx, amountY = diffy; int mappedIndex = mapToEditPointIndex(indexInConnection); Point2D p = getConnection().getPoints().get(indexInConnection); if (p.getX() == node.getAbsoluteX1() || p.getX() == node.getAbsoluteX2()) { amountX = 0; } if (p.getY() == node.getAbsoluteY1() || p.getY() == node.getAbsoluteY2()) { amountY = 0; } editpoints.get(mappedIndex).setLocation(p.getX() + amountX, p.getY() + amountY); }
/** * Inserts a new point at the specified position. This is called only if the point previously * connecting to node was dragged off it. * * @param node the Node * @param outcode the position of the dragged off point, relative to the node * @param index if 0, the point is added at the start, otherwise at the end */ private void insertConnectionPointToNode(Node node, int outcode, int index) { Point2D newpoint = new Point2D.Double(); Point2D segmentPoint = getConnection().getPoints().get(index); if (outcode == Rectangle2D.OUT_BOTTOM) { newpoint.setLocation(segmentPoint.getX(), node.getAbsoluteY2()); addEditPoint(index, newpoint); } else if (outcode == Rectangle2D.OUT_TOP) { newpoint.setLocation(segmentPoint.getX(), node.getAbsoluteY1()); addEditPoint(index, newpoint); } else if (outcode == Rectangle2D.OUT_LEFT) { newpoint.setLocation(node.getAbsoluteX1(), segmentPoint.getY()); addEditPoint(index, newpoint); } else if (outcode == Rectangle2D.OUT_RIGHT) { newpoint.setLocation(node.getAbsoluteX2(), segmentPoint.getY()); addEditPoint(index, newpoint); } }