/** * setReferencePoints * * @param request void */ private void setReferencePoints(BendpointRequest request) { PointList points = getConnection().getPoints(); int bpIndex = -1; List bendPoints = (List)getConnection().getRoutingConstraint(); Point bp = ((Bendpoint)bendPoints.get(request.getIndex())).getLocation(); int smallestDistance = -1; for (int i = 0; i < points.size(); i++) { if (smallestDistance == -1 || points.getPoint(i).getDistance2(bp) < smallestDistance) { bpIndex = i; smallestDistance = points.getPoint(i).getDistance2(bp); if (smallestDistance == 0) break; } } points.getPoint(ref1, bpIndex - 1); getConnection().translateToAbsolute(ref1); points.getPoint(ref2, bpIndex + 1); getConnection().translateToAbsolute(ref2); }
/** * Shows feedback when a bendpoint is being created. The original figure is used for * feedback and the original constraint is saved, so that it can be restored when feedback * is erased. * @param request the BendpointRequest */ protected void showCreateBendpointFeedback(BendpointRequest request) { Point p = new Point(request.getLocation()); List constraint; getConnection().translateToRelative(p); Bendpoint bp = new AbsoluteBendpoint(p); if (originalConstraint == null) { saveOriginalConstraint(); constraint = (List)getConnection().getRoutingConstraint(); constraint.add(request.getIndex(), bp); } else { constraint = (List)getConnection().getRoutingConstraint(); } constraint.set(request.getIndex(), bp); getConnection().setRoutingConstraint(constraint); }
/** * Shows feedback when a bendpoint is being moved. Also checks to see if the bendpoint * should be deleted and then calls {@link #showDeleteBendpointFeedback(BendpointRequest)} * if needed. The original figure is used for feedback and the original constraint is * saved, so that it can be restored when feedback is erased. * @param request the BendpointRequest */ protected void showMoveBendpointFeedback(BendpointRequest request) { Point p = new Point(request.getLocation()); if (!isDeleting) setReferencePoints(request); if (lineContainsPoint(ref1, ref2, p)) { if (!isDeleting) { isDeleting = true; eraseSourceFeedback(request); showDeleteBendpointFeedback(request); } return; } if (isDeleting) { isDeleting = false; eraseSourceFeedback(request); } if (originalConstraint == null) saveOriginalConstraint(); List constraint = (List)getConnection().getRoutingConstraint(); getConnection().translateToRelative(p); Bendpoint bp = new AbsoluteBendpoint(p); constraint.set(request.getIndex(), bp); getConnection().setRoutingConstraint(constraint); }
private void setReferencePoints(BendpointRequest request) { PointList points = getConnection().getPoints(); int bpIndex = -1; List bendPoints = (List) getConnection().getRoutingConstraint(); Point bp = ((Bendpoint) bendPoints.get(request.getIndex())) .getLocation(); int smallestDistance = -1; for (int i = 0; i < points.size(); i++) { if (smallestDistance == -1 || points.getPoint(i).getDistance2(bp) < smallestDistance) { bpIndex = i; smallestDistance = points.getPoint(i).getDistance2(bp); if (smallestDistance == 0) break; } } points.getPoint(ref1, bpIndex - 1); getConnection().translateToAbsolute(ref1); points.getPoint(ref2, bpIndex + 1); getConnection().translateToAbsolute(ref2); }
/** * Shows feedback when a bendpoint is being created. The original figure is * used for feedback and the original constraint is saved, so that it can be * restored when feedback is erased. * * @param request * the BendpointRequest */ protected void showCreateBendpointFeedback(BendpointRequest request) { Point p = new Point(request.getLocation()); List constraint; getConnection().translateToRelative(p); Bendpoint bp = new AbsoluteBendpoint(p); if (originalConstraint == null) { saveOriginalConstraint(); constraint = (List) getConnection().getRoutingConstraint(); constraint.add(request.getIndex(), bp); } else { constraint = (List) getConnection().getRoutingConstraint(); } constraint.set(request.getIndex(), bp); getConnection().setRoutingConstraint(constraint); }
/** * Shows feedback when a bendpoint is being moved. Also checks to see if the * bendpoint should be deleted and then calls * {@link #showDeleteBendpointFeedback(BendpointRequest)} if needed. The * original figure is used for feedback and the original constraint is * saved, so that it can be restored when feedback is erased. * * @param request * the BendpointRequest */ protected void showMoveBendpointFeedback(BendpointRequest request) { Point p = new Point(request.getLocation()); if (!isDeleting) setReferencePoints(request); if (lineContainsPoint(ref1, ref2, p)) { if (!isDeleting) { isDeleting = true; eraseSourceFeedback(request); showDeleteBendpointFeedback(request); } return; } if (isDeleting) { isDeleting = false; eraseSourceFeedback(request); } if (originalConstraint == null) saveOriginalConstraint(); List constraint = (List) getConnection().getRoutingConstraint(); getConnection().translateToRelative(p); Bendpoint bp = new AbsoluteBendpoint(p); constraint.set(request.getIndex(), bp); getConnection().setRoutingConstraint(constraint); }
protected void refreshBendpoints() { List<Bendpoint> modelConstraint = ((Connection) getModel()).getBendpoints(); List<RelativeBendpoint> figureConstraint = new ArrayList<RelativeBendpoint>(); for (int i = 0; i < modelConstraint.size(); i++) { ConnectionBendpoint connectionBendpoint = (ConnectionBendpoint) modelConstraint.get(i); RelativeBendpoint rbp = new RelativeBendpoint(getConnectionFigure()); rbp.setRelativeDimensions(connectionBendpoint.getFirstRelativeDimension(), connectionBendpoint.getSecondRelativeDimension()); rbp.setWeight((i + 1) / ((float) modelConstraint.size() + 1)); figureConstraint.add(rbp); } getConnectionFigure().setRoutingConstraint(figureConstraint); }
private void writeBendpoints(Element elementConnection, List<Bendpoint> list) { ConnectionBendpoint b = null; for (Bendpoint bendpoint : list) { b = (ConnectionBendpoint) bendpoint; Element element = document.createElement(ConnectionBendpoint.SIMPLE_NAME); writeElement(element, ConnectionBendpoint.DX1, b.getFirstRelativeDimension().width); writeElement(element, ConnectionBendpoint.DY1, b.getFirstRelativeDimension().height); writeElement(element, ConnectionBendpoint.DX2, b.getSecondRelativeDimension().width); writeElement(element, ConnectionBendpoint.DY2, b.getSecondRelativeDimension().height); elementConnection.appendChild(element); } }
public void execute() { ConnectionBendpoint bp = new ConnectionBendpoint(); bp.setRelativeDimensions(getFirstRelativeDimension(), getSecondRelativeDimension()); setOldBendpoint((Bendpoint) getConn().getBendpoints().get(getIndex())); getConn().setBendpoint(getIndex(), bp); super.execute(); }
/** * createHandlesForUserBendpoints * * @return List */ private List createHandlesForUserBendpoints() { List list = new ArrayList(); ConnectionEditPart connEP = (ConnectionEditPart)getHost(); PointList points = getConnection().getPoints(); List bendPoints = (List)getConnection().getRoutingConstraint(); int bendPointIndex = 0; Point currBendPoint = null; if (bendPoints == null) bendPoints = NULL_CONSTRAINT; else if (!bendPoints.isEmpty()) currBendPoint = ((Bendpoint)bendPoints.get(0)).getLocation(); for (int i = 0; i < points.size() - 1; i++) { //Put a create handle on the middle of every segment list.add(new SequenceBendpointCreationHandle(connEP, bendPointIndex, i)); //If the current user bendpoint matches a bend location, show a move handle if (i < points.size() - 1 && bendPointIndex < bendPoints.size() && currBendPoint.equals(points.getPoint(i + 1))) { list.add(new SequenceBendpointCreationHandle(connEP, bendPointIndex, i + 1)); //Go to the next user bendpoint bendPointIndex++; if (bendPointIndex < bendPoints.size()) currBendPoint = ((Bendpoint)bendPoints.get(bendPointIndex)).getLocation(); } } return list; }
private List createHandlesForUserBendpoints() { List list = new ArrayList(); ConnectionEditPart connEP = (ConnectionEditPart) getHost(); PointList points = getConnection().getPoints(); List bendPoints = (List) getConnection().getRoutingConstraint(); int bendPointIndex = 0; Point currBendPoint = null; if (bendPoints == null) bendPoints = NULL_CONSTRAINT; else if (!bendPoints.isEmpty()) currBendPoint = ((Bendpoint) bendPoints.get(0)).getLocation(); for (int i = 0; i < points.size() - 1; i++) { // Put a create handle on the middle of every segment list.add(new BendpointCreationHandle(connEP, bendPointIndex, i)); // If the current user bendpoint matches a bend location, show a // move handle if (i < points.size() - 1 && bendPointIndex < bendPoints.size() && currBendPoint.equals(points.getPoint(i + 1))) { list.add(new BendpointMoveHandle(connEP, bendPointIndex, i + 1)); // Go to the next user bendpoint bendPointIndex++; if (bendPointIndex < bendPoints.size()) currBendPoint = ((Bendpoint) bendPoints.get(bendPointIndex)) .getLocation(); } } return list; }
public void insertBendpoint(int index, Bendpoint point) { getBendpoints().add(index, point); firePropertyChange(BENDPOINT, null, null); }
public void setBendpoint(int index, Bendpoint point) { getBendpoints().set(index, point); firePropertyChange(BENDPOINT, null, null); }
public List<Bendpoint> getBendpoints() { return bendpoints; }
public void setBendpoints(List<Bendpoint> bendpoints) { this.bendpoints = bendpoints; }
public void execute() { bendpoint = (Bendpoint) getConn().getBendpoints().get(getIndex()); getConn().removeBendpoint(getIndex()); super.execute(); }
protected Bendpoint getOldBendpoint() { return oldBendpoint; }
public void setOldBendpoint(Bendpoint bp) { oldBendpoint = bp; }