List of usage examples for java.awt.geom Point2D setLocation
public abstract void setLocation(double x, double y);
From source file:ShapeTransform.java
/** * Resizes a line. Instead of creating a GeneralPath (as AffineTransform's * scale would do) we modify the line itself. * // ww w.j a v a 2s . c om * @param line * the line that should be scaled * @param width * the new width of the line bounds * @param height * the new height of the line bounds * @return the scale Line2D object. */ private static Line2D resizeLine(final Line2D line, final double width, final double height) { final Line2D newLine = getNormalizedLine(line); final Point2D p1 = newLine.getP1(); final Point2D p2 = newLine.getP2(); final double normPointX = (p1.getX() - p2.getX()); final double normPointY = (p1.getY() - p2.getY()); final double scaleX = (normPointX == 0) ? 1 : width / Math.abs(normPointX); final double scaleY = (normPointY == 0) ? 1 : height / Math.abs(normPointY); p2.setLocation((p2.getX() - p1.getX()) * scaleX + p1.getX(), (p2.getY() - p1.getY()) * scaleY + p1.getY()); newLine.setLine(p1, p2); return newLine; }
From source file:com.googlecode.sarasvati.visual.jung.NodeLocationTransformer.java
@Override public Point2D transform(Node node) { GraphTreeNode treeNode = graphTree.getTreeNode(node); Point2D point = new Point2D.Double(); point.setLocation(treeNode.getDepth() * 100 + 50, treeNode.getIndex() * 100 + 50); return point; }
From source file:edu.uci.ics.jung.algorithms.layout.BalloonLayout.java
protected void setPolars(List<V> kids, Point2D parentLocation, double parentRadius) { int childCount = kids.size(); if (childCount == 0) return;/* ww w .java 2 s.com*/ // handle the 1-child case with 0 limit on angle. double angle = Math.max(0, Math.PI / 2 * (1 - 2.0 / childCount)); double childRadius = parentRadius * Math.cos(angle) / (1 + Math.cos(angle)); double radius = parentRadius - childRadius; double rand = Math.random(); for (int i = 0; i < childCount; i++) { V child = kids.get(i); double theta = i * 2 * Math.PI / childCount + rand; radii.put(child, childRadius); PolarPoint pp = new PolarPoint(theta, radius); polarLocations.put(child, pp); Point2D p = PolarPoint.polarToCartesian(pp); p.setLocation(p.getX() + parentLocation.getX(), p.getY() + parentLocation.getY()); locations.put(child, p); setPolars(new ArrayList<V>(graph.getChildren(child)), p, childRadius); } }
From source file:br.unicamp.rctapp.codelets.behaviors.GetClosestJewel.java
@Override public void act() { String jewelName = ""; closestJewel = (Thing) closestJewelMO.getI(); cis = (CreatureInnerSense) innerSenseMO.getI(); //Find distance between closest apple and self //If closer than reachDistance, eat the apple if (closestJewel != null) { double jewelX = 0; double jewelY = 0; try {/*from w ww.j ava 2s.c om*/ jewelX = closestJewel.getX1(); jewelY = closestJewel.getY1(); jewelName = closestJewel.getName(); } catch (Exception e) { e.printStackTrace(); } double selfX = cis.getPosition().getX(); double selfY = cis.getPosition().getY(); Point2D pApple = new Point(); pApple.setLocation(jewelX, jewelY); Point2D pSelf = new Point(); pSelf.setLocation(selfX, selfY); double distance = pSelf.distance(pApple); JSONObject message = new JSONObject(); try { if (distance < reachDistance) { //eat it message.put("OBJECT", jewelName); message.put("ACTION", "PICKUP"); handsMO.updateI(message.toString()); } else { handsMO.updateI(""); //nothing } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { handsMO.updateI(""); //nothing } }
From source file:edu.uci.ics.jung.visualization.layout.PersistentLayoutImpl.java
/** * Sets persisted location for a vertex within the dimensions of the space. * If the vertex has not been persisted, sets a random location. If you want * to initialize in some different way, override this method. * //w w w . j a v a2 s. c o m * @param v * @param coord * @param d */ protected void initializeLocation(V v, Point2D coord, Dimension d) { Point point = map.get(v); coord.setLocation(point.x, point.y); }
From source file:org.jcurl.demo.editor.LocationController.java
/** * Get the world-coordinates where the mouse event happened. * /*w ww .java2 s.co m*/ * @param e * @param dst * wc container. <code>null</code> creates a * <code>Point2D.Float</code> * @return the world-coordinate location */ protected Point2D getWc(final MouseEvent e, Point2D dst) { if (dst == null) dst = new Point2D.Float(e.getX(), e.getY()); else dst.setLocation(e.getX(), e.getY()); return panel.dc2wc(dst, dst); }
From source file:edu.uci.ics.jung.algorithms.layout.AbstractLayout.java
/** * @param v/*from w w w.ja va 2 s.c om*/ * @param xOffset * @param yOffset */ protected void offsetVertex(V v, double xOffset, double yOffset) { Point2D c = getCoordinates(v); c.setLocation(c.getX() + xOffset, c.getY() + yOffset); setLocation(v, c); }
From source file:edu.uci.ics.jung.algorithms.layout.CircleLayout.java
public void initialize() { Dimension d = getSize();/*from ww w . java 2 s .com*/ if (d != null) { if (vertex_ordered_list == null) setVertexOrder(new ArrayList<V>(getGraph().getVertices())); double height = d.getHeight(); double width = d.getWidth(); if (radius <= 0) { radius = 0.45 * (height < width ? height : width); } int i = 0; for (V v : vertex_ordered_list) { Point2D coord = transform(v); double angle = (2 * Math.PI * i) / vertex_ordered_list.size(); coord.setLocation(Math.cos(angle) * radius + width / 2, Math.sin(angle) * radius + height / 2); CircleVertexData data = getCircleData(v); data.setAngle(angle); i++; } } }
From source file:edu.uci.ics.jung.algorithms.layout.AbstractLayout.java
/** * Forcibly moves a vertex to the (x,y) location by setting its x and y * locations to the inputted location. Does not add the vertex to the * "dontmove" list, and (in the default implementation) does not make any * adjustments to the rest of the graph. *//*from w ww. j a va 2s .c om*/ public void setLocation(V picked, double x, double y) { Point2D coord = getCoordinates(picked); coord.setLocation(x, y); }
From source file:net.roboconf.doc.generator.internal.transformers.HierarchicalTransformer.java
/** * Constructor./*w w w . j a v a2s. c o m*/ * @param component the component whose hierarchy must be displayed * @param ancestors its ancestors * @param children its children * @param maxPerLine the maximum number of vertices per line */ public HierarchicalTransformer(Component component, Collection<AbstractType> ancestors, Collection<AbstractType> children, int maxPerLine) { // Store fields this.component = component; this.maxPerLine = maxPerLine; this.typeToLocation = new HashMap<AbstractType, Point2D>(); this.aloneOnRow = new ArrayList<AbstractType>(); // Compute the effective horizontal margin for this graph this.hMargin = computeHMargin(component); for (AbstractType t : ancestors) this.hMargin = Math.max(this.hMargin, computeHMargin(t)); for (AbstractType t : children) this.hMargin = Math.max(this.hMargin, computeHMargin(t)); // Builds the graph this.graph = new DirectedOrderedSparseMultigraph<AbstractType, String>(); int cpt = 1; for (AbstractType t : ancestors) this.graph.addVertex(t); this.graph.addVertex(component); for (AbstractType t : ancestors) this.graph.addEdge("can contain" + cpt++, t, component); for (AbstractType t : children) { this.graph.addVertex(t); this.graph.addEdge("can contain" + cpt++, component, t); } // In these first steps, vertices are aligned on the left if (!ancestors.isEmpty()) { dealWithOthers(ancestors); this.currentHeigth += V_PADDING; } dealWithMainComponent(); if (!children.isEmpty()) { this.currentHeigth += V_PADDING; dealWithOthers(children); } this.currentHeigth += V_MARGIN; // Center alone vertices for (AbstractType t : this.aloneOnRow) { int width = GraphUtils.computeShapeWidth(t); int newX = (this.maxRowWidth - width) / 2; if (newX > this.hMargin) { Point2D p = transform(t); p.setLocation(newX, p.getY()); } } }