Java Code Examples for org.eclipse.draw2d.geometry.PointList#size()
The following examples show how to use
org.eclipse.draw2d.geometry.PointList#size() .
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: PointsUtil.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Rotates all points. * * @param points The PoinList, which points should be rotated * @param angle * The angle to rotate * @return The rotated PointList */ public static final PointList rotatePoints(final PointList points, final double angle, final Point center) { PointList newPoints = new PointList(); for (int i = 0; i < points.size(); i++) { newPoints.addPoint(PointsUtil.rotate(points.getPoint(i), angle, center)); } return newPoints; }
Example 3
Source File: PointsUtil.java From nebula with Eclipse Public License 2.0 | 5 votes |
/**Scale the geometry size of a pointlist. * @param points points to be scaled. * @param widthRatio width scale ratio. * @param heightRatio height scale ratio. */ public static final void scalePoints(PointList points, double widthRatio, double heightRatio){ Point p0 = points.getBounds().getLocation(); for(int i=0; i<points.size(); i++){ Point p=points.getPoint(i); p.x=(int) ((p.x-p0.x)*widthRatio) + p0.x; p.y=(int) ((p.y-p0.y)*heightRatio) + p0.y; points.setPoint(p,i); } }
Example 4
Source File: SetLabelsOffsetOperation.java From statecharts with Eclipse Public License 1.0 | 5 votes |
/** * Method to set the newPointList. * * @param newPointList The new points list */ public void setNewPointList(PointList newPointList) { this.newPointList = new PointList(newPointList.size()); for (int i = 0; i < newPointList.size(); i++) { this.newPointList.addPoint(newPointList.getPoint(i)); } }
Example 5
Source File: ConnData.java From statecharts with Eclipse Public License 1.0 | 5 votes |
public List<PrecisionPoint> getVisualPoints() { List<PrecisionPoint> list = new ArrayList<>(); PointList pointList = conn.getPoints(); for (int i = 0; i < pointList.size(); i++) { list.add(new PrecisionPoint(pointList.getPoint(i))); } return list; }
Example 6
Source File: ConnData.java From statecharts with Eclipse Public License 1.0 | 5 votes |
public void printVisualPoints() { System.out.println("Visual Points for " + conn); PointList pointList = conn.getPoints(); for (int i = 0; i < pointList.size(); i++) { Point p = pointList.getPoint(i); System.out.println("- " + p); } }
Example 7
Source File: BPMNShapeFactory.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public BPMNEdge createBPMNEdge(final String bpmnFlowId, EObject bonitaElement) { Edge bonitaEdge = modelExporter.getElementNotationEdge(bonitaElement); if (bonitaEdge != null) { final BPMNEdge edge = DiFactory.eINSTANCE.createBPMNEdge(); edge.setBpmnElement(QName.valueOf(bpmnFlowId)); edge.setId(modelExporter.getEObjectID(bonitaEdge)); PolylineConnection conn = createConnectorFigure(bonitaEdge); PointList points = conn.getPoints(); for (int i = 0; i < points.size(); i++) { final org.omg.spec.dd.dc.Point sourcePoint = DcFactory.eINSTANCE.createPoint(); Point point = points.getPoint(i); sourcePoint.setX(point.x); sourcePoint.setY(point.y); edge.getWaypoint().add(sourcePoint); } if (bonitaElement instanceof SequenceFlow) { bonitaEdge.getPersistedChildren().stream() .filter(DecorationNode.class::isInstance) .findFirst() .ifPresent(decorationNode -> attachEdgeLabel((DecorationNode) decorationNode, edge, ((SequenceFlow) bonitaElement).getName(), bonitaEdge)); } return edge; } return null; }
Example 8
Source File: CustomRectilinearRouter.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
/** * Goes through line segments of a polyline and makes strict straight segments * from nearly straight segments. * * @param line polyline * @param tolerance tolerance value specifying nearly straight lines. */ private void normalizeToStraightLineTolerance(PointList line, int tolerance) { for (int i = 0; i < line.size() - 1; i++) { Point pt1 = line.getPoint(i); Point pt2 = line.getPoint(i + 1); if (Math.abs(pt1.x - pt2.x) < tolerance) { line.setPoint(new Point(pt1.x, pt2.y), i + 1); } else if (Math.abs(pt1.y - pt2.y) < tolerance) { line.setPoint(new Point(pt2.x, pt1.y), i + 1); } } }
Example 9
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 10
Source File: Animation.java From olca-app with Mozilla Public License 2.0 | 5 votes |
static boolean playbackState(Connection conn) { if (!PLAYBACK) { return false; } PointList list1 = (PointList) initialStates.get(conn); PointList list2 = (PointList) finalStates.get(conn); if (list1 == null) { conn.setVisible(false); return true; } if (list1.size() == list2.size()) { Point pt1 = new Point(), pt2 = new Point(); PointList points = conn.getPoints(); points.removeAllPoints(); for (int i = 0; i < list1.size(); i++) { list1.getPoint(pt2, i); list2.getPoint(pt1, i); pt1.x = (int) Math.round(pt1.x * progress + (1 - progress) * pt2.x); pt1.y = (int) Math.round(pt1.y * progress + (1 - progress) * pt2.y); points.addPoint(pt1); } conn.setPoints(points); } return true; }
Example 11
Source File: Animation.java From olca-app with Mozilla Public License 2.0 | 5 votes |
public static void recordInitialState(Connection connection) { if (!RECORDING) { return; } PointList points = connection.getPoints().getCopy(); if (points.size() == 2 && points.getPoint(0).equals(Point.SINGLETON.setLocation(0, 0)) && points.getPoint(1).equals( Point.SINGLETON.setLocation(100, 100))) { initialStates.put(connection, null); } else { initialStates.put(connection, points); } }
Example 12
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); } }
Example 13
Source File: ProcBuilder.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public void addSequenceFlow(final String name, final String sourceId, final String targetId, final boolean isDefault, final Point sourceAnchor, final Point targetAnchor, final PointList bendpoints) throws ProcBuilderException { final String srcId = NamingUtils.convertToId(sourceId); final String trgtId = NamingUtils.convertToId(targetId); final ShapeNodeEditPart sourceNode = editParts.get(srcId); final ShapeNodeEditPart targetNode = editParts.get(trgtId); if (!canSequenceFlowBeCreated(srcId, trgtId, sourceNode, targetNode)) { return; } final CreateConnectionViewAndElementRequest request = new CreateConnectionViewAndElementRequest(ProcessElementTypes.SequenceFlow_4001, ((IHintedType) ProcessElementTypes.SequenceFlow_4001).getSemanticHint(), diagramPart .getDiagramPreferencesHint()); final Command createSequenceFlowCommand = CreateConnectionViewAndElementRequest.getCreateCommand(request, sourceNode, targetNode); if(!createSequenceFlowCommand.canExecute()) { return; } createSequenceFlowCommand.execute(); final ConnectionViewAndElementDescriptor newObject = (ConnectionViewAndElementDescriptor) request.getNewObject(); final Edge edge = (Edge) newObject.getAdapter(Edge.class); final SequenceFlow createdElement = (SequenceFlow) newObject.getElementAdapter().getAdapter(EObject.class); if (createdElement == null) { throw new ProcBuilderException("Impossible to create SequenceFlow " + name); } if (bendpoints != null && bendpoints.size() > 1) { setBendPoints(bendpoints, newObject); } handleSequenceFlowAnchors(sourceAnchor, targetAnchor, newObject); if (name != null) { commandStack.append(SetCommand.create(editingDomain, createdElement, ProcessPackage.Literals.ELEMENT__NAME, name)); } commandStack.append(SetCommand.create(editingDomain, createdElement, ProcessPackage.eINSTANCE.getSequenceFlow_IsDefault(), isDefault)); if (edge != null) { commandStack.append(SetCommand.create(editingDomain, edge.getStyle(NotationPackage.eINSTANCE.getLineStyle()), NotationPackage.eINSTANCE.getLineStyle_LineColor(), FigureUtilities.colorToInteger(ColorConstants.lightGray))); } createdSequenceFlows.add(new Pair<String, String>(srcId, trgtId)); currentElement = createdElement; currentView = edge; execute(); }
Example 14
Source File: Animation.java From olca-app with Mozilla Public License 2.0 | 4 votes |
static void recordFinalState(Connection conn) { PointList points1 = (PointList) initialStates.get(conn); PointList points2 = conn.getPoints().getCopy(); if (points1 != null && points1.size() != points2.size()) { Point p = new Point(), q = new Point(); int size1 = points1.size() - 1; int size2 = points2.size() - 1; int i1 = size1; int i2 = size2; double current1 = 1.0; double current2 = 1.0; double prev1 = 1.0; double prev2 = 1.0; while (i1 > 0 || i2 > 0) { if (Math.abs(current1 - current2) < 0.1 && i1 > 0 && i2 > 0) { // Both points are the same, use them and go on; prev1 = current1; prev2 = current2; i1--; i2--; current1 = (double) i1 / size1; current2 = (double) i2 / size2; } else if (current1 < current2) { // 2 needs to catch up // current1 < current2 < prev1 points1.getPoint(p, i1); points1.getPoint(q, i1 + 1); p.x = (int) ((q.x * (current2 - current1) + p.x * (prev1 - current2)) / (prev1 - current1)); p.y = (int) ((q.y * (current2 - current1) + p.y * (prev1 - current2)) / (prev1 - current1)); points1.insertPoint(p, i1 + 1); prev1 = prev2 = current2; i2--; current2 = (double) i2 / size2; } else { // 1 needs to catch up // current2< current1 < prev2 points2.getPoint(p, i2); points2.getPoint(q, i2 + 1); p.x = (int) ((q.x * (current1 - current2) + p.x * (prev2 - current1)) / (prev2 - current2)); p.y = (int) ((q.y * (current1 - current2) + p.y * (prev2 - current1)) / (prev2 - current2)); points2.insertPoint(p, i2 + 1); prev2 = prev1 = current1; i1--; current1 = (double) i1 / size1; } } } finalStates.put(conn, points2); }
Example 15
Source File: PointsUtil.java From nebula with Eclipse Public License 2.0 | 3 votes |
/**Flip points horizontally. * @param points the points to be flipped. * @param centerX the center X position * @return the flipped points. */ public static final PointList flipPointsHorizontally(PointList points, int centerX){ PointList newPointList = new PointList(); for (int i = 0; i < points.size(); i++) { newPointList.addPoint(flipPointHorizontally(points.getPoint(i), centerX)); } return newPointList; }
Example 16
Source File: PointsUtil.java From nebula with Eclipse Public License 2.0 | 3 votes |
/**Flip points vertically. * @param points the points to be flipped. * @param centerY the center Y position. * @return the flipped points. */ public static final PointList flipPointsVertically(PointList points, int centerY){ PointList newPointList = new PointList(); for (int i = 0; i < points.size(); i++) { newPointList.addPoint(flipPointVertically(points.getPoint(i), centerY)); } return newPointList; }