List of usage examples for java.awt.geom Point2D setLocation
public abstract void setLocation(double x, double y);
From source file:edu.uci.ics.jung.algorithms.layout.ISOMLayout.java
private synchronized void adjustVertex(V v, Point2D tempXYD) { queue.clear();/*from w w w. j ava2s . c o m*/ ISOMVertexData ivd = getISOMVertexData(v); ivd.distance = 0; ivd.visited = true; queue.add(v); V current; while (!queue.isEmpty()) { current = queue.remove(0); ISOMVertexData currData = getISOMVertexData(current); Point2D currXYData = transform(current); double dx = tempXYD.getX() - currXYData.getX(); double dy = tempXYD.getY() - currXYData.getY(); double factor = adaption / Math.pow(2, currData.distance); currXYData.setLocation(currXYData.getX() + (factor * dx), currXYData.getY() + (factor * dy)); if (currData.distance < radius) { Collection<V> s = getGraph().getNeighbors(current); while (true) { try { for (V child : s) { ISOMVertexData childData = getISOMVertexData(child); if (childData != null && !childData.visited) { childData.visited = true; childData.distance = currData.distance + 1; queue.add(child); } } break; } catch (ConcurrentModificationException cme) { } } } } }
From source file:org.opennms.features.topology.app.internal.jung.D3TopoLayout.java
@Override public void step() { double currentForce; //guass-seidel relaxation for links for (E e : getGraph().getEdges()) { Pair<V> endPoints = getGraph().getEndpoints(e); VertexData srcVertexData = getVertexData(endPoints.getFirst()); VertexData targetVertexData = getVertexData(endPoints.getSecond()); double xDelta = targetVertexData.getX() - srcVertexData.getX(); double yDelta = targetVertexData.getY() - srcVertexData.getY(); double l = xDelta * xDelta + yDelta * yDelta; if (l != 0) { EdgeData edgeData = getEdgeData(e); double lSqrt = Math.sqrt(l); double distance = m_alpha * edgeData.getStrength() * (lSqrt - edgeData.getDistance()) / lSqrt; //double distance = edgeData.getStrength() * (lSqrt - edgeData.getDistance()) / lSqrt; xDelta *= distance;/* w ww .ja va 2 s. c o m*/ yDelta *= distance; currentForce = srcVertexData.getWeight() / (targetVertexData.getWeight() + srcVertexData.getWeight()); //currentForce = 0.5; targetVertexData.offset(-(xDelta * currentForce), -(yDelta * currentForce)); currentForce = 1 - currentForce; srcVertexData.offset(xDelta * currentForce, yDelta * currentForce); } } //Apply gravity forces currentForce = m_alpha * getGravity(); if (currentForce != 0) { double centerX = getSize().getWidth() / 2; double centerY = getSize().getHeight() / 2; for (V v : getGraph().getVertices()) { VertexData vData = getVertexData(v); vData.offset((centerX - vData.getX()) * currentForce, (centerY - vData.getY()) * currentForce); } } //Compute quad tree center of mass and apply charge force if (getDefaultCharge() != 0) { for (V v1 : getGraph().getVertices()) { VertexData vData1 = getVertexData(v1); for (V v2 : getGraph().getVertices()) { VertexData vData2 = getVertexData(v2); double dx = vData2.getX() - vData1.getX(); double dy = vData2.getY() - vData1.getY(); double d = dx * dx + dy * dy; if (d > 0) { double k = m_alpha * vData2.getCharge() / d; double px = dx * k; double py = dy * k; //vData1.offsetPrevious(px, py); vData1.offset(px, py); } else { //vData1.offsetPrevious(0.5-Math.random(), 0.5-Math.random()); vData1.offset(0.5 - Math.random(), 0.5 - Math.random()); } } } } // position verlet integration for (V v : getGraph().getVertices()) { VertexData vData = getVertexData(v); double tempX = vData.getX(); double tempY = vData.getY(); double x = vData.getX() + (vData.getPrevious().getX() - vData.getX()) * getFriction(); double y = vData.getY() + (vData.getPrevious().getY() - vData.getY()) * getFriction(); vData.setLocation(x, y); vData.setPrevious(tempX, tempY); Point2D location = transform(v); location.setLocation(vData.getX(), vData.getY()); } m_alpha *= 0.99; }
From source file:org.opennms.features.topology.app.internal.jung.D3TopoLayout.java
public void stepOld() { double currentForce; //guass-seidel relaxation for links for (E e : getGraph().getEdges()) { Pair<V> endPoints = getGraph().getEndpoints(e); VertexData srcVertexData = getVertexData(endPoints.getFirst()); VertexData targetVertexData = getVertexData(endPoints.getSecond()); double xDelta = targetVertexData.getX() - srcVertexData.getX(); double yDelta = targetVertexData.getY() - srcVertexData.getY(); double l = xDelta * xDelta + yDelta * yDelta; if (l != 0) { EdgeData edgeData = getEdgeData(e); double lSqrt = Math.sqrt(l); double distance = m_alpha * edgeData.getStrength() * (lSqrt - edgeData.getDistance()) / lSqrt; xDelta *= distance;/*from w w w . jav a 2s .co m*/ yDelta *= distance; currentForce = srcVertexData.getWeight() / (targetVertexData.getWeight() + srcVertexData.getWeight()); targetVertexData.offset(-(xDelta * currentForce), -(yDelta * currentForce)); currentForce = 1 - currentForce; srcVertexData.offset(xDelta * currentForce, yDelta * currentForce); } } //Apply gravity forces currentForce = m_alpha * getGravity(); if (currentForce != 0) { double centerX = getSize().getWidth() / 2; double centerY = getSize().getHeight() / 2; for (V v : getGraph().getVertices()) { VertexData vData = getVertexData(v); vData.offset((centerX - vData.getX()) * currentForce, (centerY - vData.getY()) * currentForce); } } //Compute quad tree center of mass and apply charge force if (getDefaultCharge() != 0) { DblBoundingBox bounds = new DblBoundingBox(0, 0, getSize().getWidth(), getSize().getHeight()); QuadTree<VertexData> quadTree = new QuadTree<VertexData>(bounds); for (V v : getGraph().getVertices()) { VertexData vData = getVertexData(v); quadTree.insert(vData, vData.getCharge(), vData); } for (V v : getGraph().getVertices()) { final VertexData vData = getVertexData(v); quadTree.visit(new Visitor<VertexData>() { @Override public boolean visitNode(Node<VertexData> n) { if (n.isLeaf() && vData == n.getValue()) return true; double dx = n.getX() - vData.getX(); double dy = n.getY() - vData.getY(); double dw = n.getWidth(); double dSquared = dx * dx + dy * dy; if (dw * dw / m_thetaSquared < dSquared) { double force = n.getCharge() / dSquared; vData.offset(-(dx * force), -(dy * force)); return true; } if (n.isLeaf()) { if (dSquared == 0) { vData.offset(1, 1); } else { double force = n.getCharge() / dSquared; vData.offset(-(dx * force), -(dy * force)); } return true; } return false; } }); } } for (V v : getGraph().getVertices()) { VertexData vData = getVertexData(v); Point2D location = transform(v); location.setLocation(vData.getX(), vData.getY()); } m_alpha *= 0.998235; }
From source file:edu.uci.ics.jung.algorithms.layout.FRLayout2.java
protected void calcAttraction(E e) { Pair<V> endpoints = getGraph().getEndpoints(e); V v1 = endpoints.getFirst();/* w w w . ja v a 2 s .com*/ V v2 = endpoints.getSecond(); boolean v1_locked = isLocked(v1); boolean v2_locked = isLocked(v2); if (v1_locked && v2_locked) { // both locked, do nothing return; } Point2D p1 = transform(v1); Point2D p2 = transform(v2); if (p1 == null || p2 == null) return; double xDelta = p1.getX() - p2.getX(); double yDelta = p1.getY() - p2.getY(); double deltaLength = Math.max(EPSILON, p1.distance(p2)); double force = deltaLength / attraction_constant; assert Double.isNaN(force) == false : "Unexpected mathematical result in FRLayout:calcPositions [force]"; double dx = xDelta * force; double dy = yDelta * force; Point2D fvd1 = frVertexData.get(v1); Point2D fvd2 = frVertexData.get(v2); if (v2_locked) { // double the offset for v1, as v2 will not be moving in // the opposite direction fvd1.setLocation(fvd1.getX() - 2 * dx, fvd1.getY() - 2 * dy); } else { fvd1.setLocation(fvd1.getX() - dx, fvd1.getY() - dy); } if (v1_locked) { // double the offset for v2, as v1 will not be moving in // the opposite direction fvd2.setLocation(fvd2.getX() + 2 * dx, fvd2.getY() + 2 * dy); } else { fvd2.setLocation(fvd2.getX() + dx, fvd2.getY() + dy); } }
From source file:edu.uci.ics.jung.algorithms.layout.SpringLayout.java
protected void moveNodes() { synchronized (getSize()) { try {/*from w w w . j a va 2 s .c o m*/ for (V v : getGraph().getVertices()) { if (isLocked(v)) continue; SpringVertexData vd = springVertexData.get(v); if (vd == null) continue; Point2D xyd = transform(v); vd.dx += vd.repulsiondx + vd.edgedx; vd.dy += vd.repulsiondy + vd.edgedy; // keeps nodes from moving any faster than 5 per time unit xyd.setLocation(xyd.getX() + Math.max(-5, Math.min(5, vd.dx)), xyd.getY() + Math.max(-5, Math.min(5, vd.dy))); Dimension d = getSize(); int width = d.width; int height = d.height; if (xyd.getX() < 0) { xyd.setLocation(0, xyd.getY()); } else if (xyd.getX() > width) { xyd.setLocation(width, xyd.getY()); } if (xyd.getY() < 0) { xyd.setLocation(xyd.getX(), 0); } else if (xyd.getY() > height) { xyd.setLocation(xyd.getX(), height); } } } catch (ConcurrentModificationException cme) { moveNodes(); } } }
From source file:util.ModSpringLayout.java
protected void moveNodes() { synchronized (getSize()) { try {/*from w w w. j a v a 2 s.co m*/ for (V v : getGraph().getVertices()) { if (isLocked(v)) { continue; } SpringVertexData vd = springVertexData.get(v); if (vd == null) { continue; } Point2D xyd = transform(v); vd.dx += vd.repulsiondx + vd.edgedx; vd.dy += vd.repulsiondy + vd.edgedy; // keeps nodes from moving any faster than 5 per time unit xyd.setLocation(xyd.getX() + Math.max(-5, Math.min(5, vd.dx)), xyd.getY() + Math.max(-5, Math.min(5, vd.dy))); Dimension d = getSize(); int width = d.width; int height = d.height; if (xyd.getX() < 0) { xyd.setLocation(0, xyd.getY()); } else if (xyd.getX() > width) { xyd.setLocation(width, xyd.getY()); } if (xyd.getY() < 0) { xyd.setLocation(xyd.getX(), 0); } else if (xyd.getY() > height) { xyd.setLocation(xyd.getX(), height); } } } catch (ConcurrentModificationException cme) { moveNodes(); } } }
From source file:Visualizer.SpringLayoutWeighted.java
protected void moveNodes() { synchronized (getSize()) { try {/* w w w .j a v a 2s . c o m*/ for (Functionality.Node v : getGraph().getVertices()) { if (isLocked(v)) continue; SpringVertexData vd = springVertexData.get(v); if (vd == null) continue; Point2D xyd = transform(v); vd.dx += vd.repulsiondx + vd.edgedx; vd.dy += vd.repulsiondy + vd.edgedy; // keeps nodes from moving any faster than 5 per time unit xyd.setLocation(xyd.getX() + Math.max(-5, Math.min(5, vd.dx)), xyd.getY() + Math.max(-5, Math.min(5, vd.dy))); Dimension d = getSize(); int width = d.width; int height = d.height; if (xyd.getX() < 0) { xyd.setLocation(0, xyd.getY()); } else if (xyd.getX() > width) { xyd.setLocation(width, xyd.getY()); } if (xyd.getY() < 0) { xyd.setLocation(xyd.getX(), 0); } else if (xyd.getY() > height) { xyd.setLocation(xyd.getX(), height); } } } catch (ConcurrentModificationException cme) { moveNodes(); } } }
From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PDFAsVisualSignatureBuilder.java
public void createSignatureRectangle(PDSignatureField signatureField, PDFAsVisualSignatureDesigner properties, float degrees) throws IOException { PDRectangle rect = new PDRectangle(); Point2D upSrc = new Point2D.Float(); upSrc.setLocation(properties.getxAxis() + properties.getWidth(), properties.getPageHeight() - properties.getyAxis()); Point2D llSrc = new Point2D.Float(); llSrc.setLocation(properties.getxAxis(), properties.getPageHeight() - properties.getyAxis() - properties.getHeight()); rect.setUpperRightX((float) upSrc.getX()); rect.setUpperRightY((float) upSrc.getY()); rect.setLowerLeftY((float) llSrc.getY()); rect.setLowerLeftX((float) llSrc.getX()); logger.debug("orig rectangle of signature has been created: {}", rect.toString()); AffineTransform transform = new AffineTransform(); transform.setToIdentity();//from w ww .jav a2 s .c o m if (degrees % 360 != 0) { transform.setToRotation(Math.toRadians(degrees), llSrc.getX(), llSrc.getY()); } Point2D upDst = new Point2D.Float(); transform.transform(upSrc, upDst); Point2D llDst = new Point2D.Float(); transform.transform(llSrc, llDst); float xPos = properties.getxAxis(); float yPos = properties.getPageHeight() - properties.getyAxis(); logger.debug("POS {} x {}", xPos, yPos); logger.debug("SIZE {} x {}", properties.getWidth(), properties.getHeight()); // translate according to page! rotation int pageRotation = properties.getPageRotation(); AffineTransform translate = new AffineTransform(); switch (pageRotation) { case 90: translate.setToTranslation( properties.getPageHeight() - (properties.getPageHeight() - properties.getyAxis()) - properties.getxAxis() + properties.getHeight(), properties.getxAxis() + properties.getHeight() - (properties.getPageHeight() - properties.getyAxis())); break; case 180: // translate.setToTranslation(properties.getPageWidth() - // properties.getxAxis() - properties.getxAxis(), // properties.getPageHeight() - properties.getyAxis() + // properties.getHeight()); translate.setToTranslation(properties.getPageWidth() - 2 * xPos, properties.getPageHeight() - 2 * (yPos - properties.getHeight())); break; case 270: translate.setToTranslation(-properties.getHeight() + yPos - xPos, properties.getPageWidth() - (yPos - properties.getHeight()) - xPos); break; } translate.transform(upDst, upDst); translate.transform(llDst, llDst); rect.setUpperRightX((float) upDst.getX()); rect.setUpperRightY((float) upDst.getY()); rect.setLowerLeftY((float) llDst.getY()); rect.setLowerLeftX((float) llDst.getX()); logger.debug("rectangle of signature has been created: {}", rect.toString()); signatureField.getWidget().setRectangle(rect); getStructure().setSignatureRectangle(rect); logger.debug("rectangle of signature has been created"); }
From source file:com.net2plan.gui.utils.topologyPane.jung.JUNGCanvas.java
/** * Converts a point from the SWING coordinates system into a point from the JUNG coordinates system. * * @param jungLayoutCoord (@code Point2D) on the SWING canvas. * @return (@code Point2D) on the JUNG canvas. *//*from www . ja va 2 s . com*/ @Override public Point2D getCanvasPointFromNetPlanPoint(Point2D npCoord) { Point2D layoutOrViewCoordinates = vv.getRenderContext().getMultiLayerTransformer() .inverseTransform(Layer.LAYOUT, npCoord); layoutOrViewCoordinates.setLocation(layoutOrViewCoordinates.getX(), -layoutOrViewCoordinates.getY()); return layoutOrViewCoordinates; }
From source file:util.ModSpringLayout1.java
protected void moveNodes() { synchronized (getSize()) { try {// w w w . j av a 2 s. c o m for (V v : getGraph().getVertices()) { if (isLocked(v)) { continue; } SpringVertexData vd = getSpringVertexData(v); if (vd == null) { continue; } Point2D xyd = transform(v); vd.dx += vd.repulsiondx + vd.edgedx; vd.dy += vd.repulsiondy + vd.edgedy; // keeps nodes from moving any faster than 5 per time unit xyd.setLocation(xyd.getX() + Math.max(-5, Math.min(5, vd.dx)), xyd.getY() + Math.max(-5, Math.min(5, vd.dy))); Dimension d = getSize(); int width = d.width; int height = d.height; if (xyd.getX() < 0) { xyd.setLocation(0, xyd.getY());// setX(0); } else if (xyd.getX() > width) { xyd.setLocation(width, xyd.getY()); //setX(width); } if (xyd.getY() < 0) { xyd.setLocation(xyd.getX(), 0);//setY(0); } else if (xyd.getY() > height) { xyd.setLocation(xyd.getX(), height); //setY(height); } } } catch (ConcurrentModificationException cme) { moveNodes(); } } }