Java Code Examples for org.eclipse.draw2d.geometry.PointList#getLastPoint()
The following examples show how to use
org.eclipse.draw2d.geometry.PointList#getLastPoint() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CursorTimingsLayer.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * Clip cursor connectors at the left/right side of the screen. This is a performance optimization for windows. When a connection is much larger than * the screen size, drawing takes ages. */ @Override public PointList getPoints() { final PointList originalPoints = super.getPoints(); if (originalPoints.size() == 2) { final Point targetPoint = originalPoints.getLastPoint(); final Rectangle layerBounds = CursorTimingsLayer.this.getBounds(); if (targetPoint.x() < layerBounds.x()) { // clip cursor on the left screen border targetPoint.setX(layerBounds.x()); originalPoints.setPoint(targetPoint, 1); } else if (targetPoint.x() > layerBounds.right()) { // clip cursor on the right screen border targetPoint.setX(layerBounds.right()); originalPoints.setPoint(targetPoint, 1); } } return originalPoints; }
Example 2
Source File: CursorTimingsLayer.java From nebula with Eclipse Public License 2.0 | 5 votes |
@Override protected Point getLocation(PointList points) { final IFigure cursorLabel = (IFigure) getConnection().getChildren().get(1); final Dimension labelSize = cursorLabel.getPreferredSize(); final Point firstPoint = points.getFirstPoint(); final Point lastPoint = points.getLastPoint(); final int direction = (lastPoint.x() > firstPoint.x()) ? 1 : -1; final Point point = super.getLocation(points); point.translate(((labelSize.width() / 2) + fDistance) * direction, 0); return point; }
Example 3
Source File: CustomRectilinearRouter.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
/** * Rectilinear polyline is invalid if: * 1. First bend point is within the source * 2. Last bend point is within the target * 3. First bend point and source anchor are on different sides of the source shape * 4. Last bend point and target anchor are on different sides of the target shape * * @param conn connection * @param line rectilinear polyline * @return <code>true</code> if the line is valid */ private boolean isValidRectilinearLine(Connection conn, PointList line) { if (!(conn.getSourceAnchor().getOwner() instanceof Connection)) { Rectangle source = new PrecisionRectangle( getAnchorableFigureBounds(conn.getSourceAnchor().getOwner())); conn.getSourceAnchor().getOwner().translateToAbsolute(source); conn.translateToRelative(source); if (source.contains(line.getPoint(1))) { return false; } int firstSegmentOrientation = line.getFirstPoint().x == line.getPoint(1).x ? PositionConstants.VERTICAL : PositionConstants.HORIZONTAL; if (getOutisePointOffRectanglePosition(line.getPoint(1), source) != getAnchorLocationBasedOnSegmentOrientation( line.getFirstPoint(), source, firstSegmentOrientation)) { return false; } } if (!(conn.getTargetAnchor().getOwner() instanceof Connection)) { Rectangle target = new PrecisionRectangle( getAnchorableFigureBounds(conn.getTargetAnchor().getOwner())); conn.getTargetAnchor().getOwner().translateToAbsolute(target); conn.translateToRelative(target); if (target.contains(line.getPoint(line.size() - 2))) { return false; } int lastSegmentOrientation = line.getLastPoint().x == line.getPoint(line.size() - 2).x ? PositionConstants.VERTICAL : PositionConstants.HORIZONTAL; if (getOutisePointOffRectanglePosition(line.getPoint(line.size() - 2), target) != getAnchorLocationBasedOnSegmentOrientation(line.getLastPoint(), target, lastSegmentOrientation)) { return false; } } return true; }
Example 4
Source File: CustomRectilinearRouter.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
/** * Iterates through points of a polyline and does the following: * if 3 points lie on the same line the middle point is removed * * @param line polyline's points */ private boolean removeRedundantPoints(PointList line) { int initialNumberOfPoints = line.size(); if (line.size() > 2) { PointList newLine = new PointList(line.size()); newLine.addPoint(line.removePoint(0)); while (line.size() >= 2) { Point p0 = newLine.getLastPoint(); Point p1 = line.getPoint(0); Point p2 = line.getPoint(1); if (p0.x == p1.x && p0.x == p2.x) { // Have two vertical segments in a row // get rid of the point between line.removePoint(0); } else if (p0.y == p1.y && p0.y == p2.y) { // Have two horizontal segments in a row // get rid of the point between line.removePoint(0); } else { newLine.addPoint(line.removePoint(0)); } } while (line.size() > 0) { newLine.addPoint(line.removePoint(0)); } line.removeAllPoints(); line.addAll(newLine); } return line.size() != initialNumberOfPoints; }
Example 5
Source File: TreeConnectionRouter.java From olca-app with Mozilla Public License 2.0 | 5 votes |
@Override public void route(Connection conn) { // pre route NULL.route(conn); // get points PointList points = conn.getPoints(); Point first = points.getFirstPoint(); Point last = points.getLastPoint(); // distance from to point to connection anchor final int trans = GraphLayoutManager.verticalSpacing / 4; // create new list PointList newPoints = new PointList(); // add first point newPoints.addPoint(first); // add 2 new points newPoints.addPoint(first.x, first.y - trans); newPoints.addPoint(last.x, last.y + trans); // add last point newPoints.addPoint(last); // set new list conn.setPoints(newPoints); }
Example 6
Source File: ConnectionRouterImp.java From olca-app with Mozilla Public License 2.0 | 5 votes |
@Override public void route(Connection conn) { NULL.route(conn); PointList points = conn.getPoints(); Point start = points.getFirstPoint(); Point end = points.getLastPoint(); points.removeAllPoints(); points.addPoint(start); if (start.y > end.y) routeBottomToTop(start, end, points); else routeTopToBottom(start, end, points); points.addPoint(end); }
Example 7
Source File: CustomRectilinearRouter.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public void routeLine( Connection conn, int nestedRoutingDepth, PointList newLine) { boolean skipNormalization = (routerFlags & ROUTER_FLAG_SKIPNORMALIZATION) != 0; // if we are reorienting, then just default to the super class implementation and // don't try to do rectilinear routing. if (isReorienting(conn)) { super.routeLine(conn, nestedRoutingDepth, newLine); return; } // Handle special routing: self connections and intersecting shapes connections if (checkSelfRelConnection(conn, newLine) || checkShapesIntersect(conn, newLine)) { resetEndPointsToEdge(conn, newLine); OrthogonalRouterUtilities .transformToOrthogonalPointList(newLine, getOffShapeDirection(getAnchorOffRectangleDirection( newLine.getFirstPoint(), sourceBoundsRelativeToConnection(conn))), getOffShapeDirection(getAnchorOffRectangleDirection( newLine.getLastPoint(), targetBoundsRelativeToConnection(conn)))); removeRedundantPoints(newLine); return; } if (conn.getSourceAnchor().getOwner() == conn.getTargetAnchor().getOwner()) { nestedRoutingDepth = maxNestedRoutingDepth; } /* * Remove and store former anchor points. Anchor points will be re-calculated anyway. * However, the old anchor points may be useful if connection didn't have any bend points * except the anchor points. */ Point lastStartAnchor = newLine.removePoint(0); Point lastEndAnchor = newLine.removePoint(newLine.size() - 1); /* * Check if connection is rectilinear and if not make it rectilinear */ if (!OrthogonalRouterUtilities.isRectilinear(newLine)) { OrthogonalRouterUtilities.transformToOrthogonalPointList(newLine, PositionConstants.NONE, PositionConstants.NONE); } removeRedundantPoints(newLine); /* * Remove unnecessary points that are contained within source and/or target shapes * as well as insert extra points if all points are within source and/or target shapes */ removePointsInViews(conn, newLine, lastStartAnchor, lastEndAnchor); Dimension tolerance = new Dimension(3, 0); /* * Normalize polyline to eliminate extra segments. (This makes 3 segments collapsing into * one, while line segments are moved) */ if (!skipNormalization) { if (PointListUtilities.normalizeSegments(newLine, tolerance.width)) { /* * Normalization can make our polyline not rectilinear. Hence, we need to normalize * segments of polyline to straight line tolerance. */ normalizeToStraightLineTolerance(newLine, tolerance.width); } } /* * Normalization is not touching the end points, hence we'd like to handle this here. * If distance between start and end (which are the only points in a polyline) points * is too short we'll remove one of the points */ if (newLine.size() == 2) { Ray middleSeg = new Ray(newLine.getFirstPoint(), newLine.getLastPoint()); if (middleSeg.length() <= tolerance.width) { newLine.removePoint(0); } } /* * Calculate connection anchor points and possibly some extra routing work to keep * the connection rectilinear if anchor points make it not rectilinear. */ resetEndPointsToEdge(conn, newLine); if (nestedRoutingDepth < maxNestedRoutingDepth && !isValidRectilinearLine(conn, newLine)) { routeLine(conn, ++nestedRoutingDepth, newLine); } }