List of usage examples for java.awt.geom Point2D setLocation
public abstract void setLocation(double x, double y);
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
private void placeStructures(Vector<AnnotationObject> annotations, boolean init) { // get starting point double y = thePlot.getRangeAxis().getRange().getUpperBound(); double cur_x = thePlot.getDomainAxis().getRange().getLowerBound(); double all_width = 0.; for (AnnotationObject a : annotations) { if (a.hasAnnotations()) all_width += screenToDataX(rectangles_complete.get(a).width); }/*from ww w . jav a 2 s . c o m*/ double min_pp_x = annotations.firstElement().getPeakPoint().getX(); double max_pp_x = annotations.lastElement().getPeakPoint().getX(); double center_pp_x = (max_pp_x + min_pp_x) / 2; cur_x = Math.max(cur_x, center_pp_x - all_width / 2); // place annotations for (AnnotationObject a : annotations) { Point2D pp = a.getPeakPoint(); if (a.hasAnnotations()) { double cur_width = screenToDataX(rectangles_complete.get(a).width); double x = cur_x + cur_width / 2.; theDocument.getAnchor(a).setLocation(x, y); theDocument.getControlPoints().put(a, theDocument.computeControlPoint(new Point2D.Double(x, y), pp)); cur_x += cur_width; } else { theDocument.getAnchor(a).setLocation(pp.getX(), pp.getY()); theDocument.getControlPoints().put(a, theDocument.computeControlPoint(pp, pp)); } } // refine control points for (int i = 0; i < annotations.size(); i++) { AnnotationObject ai = annotations.get(i); Point2D aai = theDocument.getAnchor(ai); Point2D cpi = theDocument.getControlPoint(ai); if (aai.getX() < cpi.getX()) { for (int l = i + 1; l < annotations.size(); l++) { AnnotationObject al = annotations.get(l); Point2D aal = theDocument.getAnchor(al); Point2D cpl = theDocument.getControlPoint(al); if (aal.getX() > cpi.getX()) break; if (cpl.getY() < cpi.getY()) { cpl.setLocation(cpl.getX(), cpi.getY()); ai = al; aai = aal; cpi = cpl; } else break; } } else { for (int l = i - 1; l >= 0; l--) { AnnotationObject al = annotations.get(l); Point2D aal = theDocument.getAnchor(al); Point2D cpl = theDocument.getControlPoint(al); if (aal.getX() < cpi.getX()) break; if (cpl.getY() < cpi.getY()) { cpl.setLocation(cpl.getX(), cpi.getY()); ai = al; aai = aal; cpi = cpl; } else break; } } } // fire events if (init) theDocument.fireDocumentInit(); else theDocument.fireDocumentChanged(); }
From source file:util.ModSpringLayout2.java
protected void moveNodes() { synchronized (getSize()) { try {//from ww w. j ava 2 s .co m for (V v : getGraph().getVertices()) { if (isLocked(v)) continue; SpringVertexData vd = getSpringData(v); if (vd == null) continue; Point2D xyd = transform(v); vd.dx += vd.repulsiondx + vd.edgedx; vd.dy += vd.repulsiondy + vd.edgedy; // int currentCount = currentIteration % this.loopCountMax; // System.err.println(averageCounter+" --- vd.dx="+vd.dx+", vd.dy="+vd.dy); // System.err.println("averageDelta was "+averageDelta); averageDelta.setLocation( ((averageDelta.getX() * averageCounter) + vd.dx) / (averageCounter + 1), ((averageDelta.getY() * averageCounter) + vd.dy) / (averageCounter + 1)); // System.err.println("averageDelta now "+averageDelta); // System.err.println(); averageCounter++; // 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(); } } }
From source file:lu.lippmann.cdb.graph.GraphUtil.java
/** * //w ww . ja v a 2 s . com * @param layout * @param picked */ public static Layout<CNode, CEdge> reorganize(Layout<CNode, CEdge> layout, Set<CNode> picked) { Layout<CNode, CEdge> subLayout = null; //create map that copy the transformer of existing layout final HashMap<CNode, CPoint> mapTransform1 = new LinkedHashMap<CNode, CPoint>(); for (CNode v : layout.getGraph().getVertices()) { final Point2D tmp = layout.transform(v); mapTransform1.put(v, new CPoint(tmp.getX(), tmp.getY())); } // final Graph<CNode, CEdge> graph = layout.getGraph(); final AggregateLayout<CNode, CEdge> clusteringLayout = new AggregateLayout<CNode, CEdge>(layout); // put the picked vertices into a new sublayout //final Set<CNode> picked = vv.getPickedVertexState().getPicked(); if (picked != null && picked.size() >= 1) { final Point2D initCenter = GraphUtil.getCenter(picked, layout); final Graph<CNode, CEdge> subGraph = new DirectedSparseGraph<CNode, CEdge>(); try { for (CNode vertex : picked) { subGraph.addVertex(vertex); final Collection<CEdge> incidentEdges = graph.getIncidentEdges(vertex); if (incidentEdges != null) { for (final CEdge edge : incidentEdges) { final Pair<CNode> endpoints = graph.getEndpoints(edge); if (picked.containsAll(endpoints)) { subGraph.addEdge(edge, endpoints.getFirst(), endpoints.getSecond()); } } } } subLayout = buildMinimumSpanningForestLayout(subGraph); subLayout.setInitializer(layout); if (!(subLayout instanceof TreeLayout)) { subLayout.setSize(clusteringLayout.getSize()); } final Point2D subGraphCenter = GraphUtil.getCenter(picked, subLayout); final Point2D subLayoutCenter = new Point2D.Double(subLayout.getSize().getWidth() / 2, subLayout.getSize().getHeight() / 2); //System.out.println("Initial init center : " + initCenter); initCenter.setLocation(initCenter.getX() + (subLayoutCenter.getX() - subGraphCenter.getX()), initCenter.getY() + (subLayoutCenter.getY() - subGraphCenter.getY())); //System.out.println("Corrected init center : " + initCenter); clusteringLayout.put(subLayout, initCenter); //create map that copy the transformer of new layout final HashMap<CNode, CPoint> mapTransform2 = new LinkedHashMap<CNode, CPoint>(); for (CNode v : layout.getGraph().getVertices()) { final Point2D tmp = clusteringLayout.transform(v); mapTransform2.put(v, new CPoint(tmp.getX(), tmp.getY())); } // /** save the new layout and historize it !! */ ((GraphWithOperations) layout.getGraph()).changeLayout(mapTransform1, mapTransform2); } catch (Exception e) { e.printStackTrace(); } } return subLayout; }
From source file:edu.ucla.stat.SOCR.chart.demo.SOCR_EM_MixtureModelChartDemo.java
public Point2D getPointInChart(MouseEvent e) { Insets insets = getInsets();/*from www. j av a2 s . c o m*/ //System.out.println("inset.top="+insets.top+" inset.left="+insets.left); //System.out.println("scaleX="+chartPaneltest.getScaleX()+" scaleY="+chartPaneltest.getScaleY()); //System.out.println(e.getX()); // int mouseX = (int) ((e.getX() - insets.left) / chartPaneltest.getScaleX()); // int mouseY = (int) ((e.getY() - insets.top) / chartPaneltest.getScaleY()); int mouseX = (int) (e.getX() - insets.left); int mouseY = (int) (e.getY() - insets.top); // Point2D pt = new Point2D.Double(); //pt.setLocation(mouseX, mouseY); //return pt; // System.out.println("x = " + mouseX + ", y = " + mouseY); Point2D p = chartPaneltest.translateScreenToJava2D(new Point(mouseX, mouseY)); XYPlot plot = (XYPlot) chart.getPlot(); ChartRenderingInfo info = chartPaneltest.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); ValueAxis domainAxis = plot.getDomainAxis(); RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); ValueAxis rangeAxis = plot.getRangeAxis(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); double chartX = domainAxis.java2DToValue(p.getX(), dataArea, domainAxisEdge); double chartY = rangeAxis.java2DToValue(p.getY(), dataArea, rangeAxisEdge); Point2D pt2 = new Point2D.Double(); //double scale = (double)CHART_SIZE_X/(double)CHART_SIZE_Y; //System.out.println("scale="+scale); pt2.setLocation(chartX, chartY); //System.out.println("Chart: x = " + (chartX) + ", y = " + chartY); return pt2; }
From source file:org.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java
public Point2D normalize(final Point2D e) { final double topBorder = getTopBorder(); final double leftBorder = getLeftBorder(); final float scaleFactor = getRenderContext().getZoomModel().getZoomAsPercentage(); final double x = (e.getX() / scaleFactor) - leftBorder; final double y = (e.getY() / scaleFactor) - topBorder; final Point2D o = getOffset(); o.setLocation(x, y + o.getY()); return o;//from w ww . j a v a 2s . c om }
From source file:org.apache.fop.svg.AbstractFOPTextPainter.java
/** * Paint a single text run on the Graphics2D at a given location. * @param run the text run to paint/*from w ww.jav a2s . c o m*/ * @param g2d the Graphics2D to paint to * @param loc the current location of the "cursor" * @return the new location of the "cursor" after painting the text run */ protected Point2D paintTextRun(StrokingTextPainter.TextRun run, Graphics2D g2d, Point2D loc) { AttributedCharacterIterator aci = run.getACI(); aci.first(); updateLocationFromACI(aci, loc); AffineTransform at = g2d.getTransform(); loc = at.transform(loc, null); // font Font font = getFont(aci); if (font != null) { nativeTextHandler.setOverrideFont(font); } // color TextPaintInfo tpi = (TextPaintInfo) aci .getAttribute(GVTAttributedCharacterIterator.TextAttribute.PAINT_INFO); if (tpi == null) { return loc; } Paint foreground = tpi.fillPaint; if (foreground instanceof Color) { Color col = (Color) foreground; g2d.setColor(col); } g2d.setPaint(foreground); // text anchor TextNode.Anchor anchor = (TextNode.Anchor) aci .getAttribute(GVTAttributedCharacterIterator.TextAttribute.ANCHOR_TYPE); // text String txt = getText(aci); float advance = getStringWidth(txt, font); float tx = 0; if (anchor != null) { switch (anchor.getType()) { case TextNode.Anchor.ANCHOR_MIDDLE: tx = -advance / 2; break; case TextNode.Anchor.ANCHOR_END: tx = -advance; break; default: //nop } } // draw string double x = loc.getX(); double y = loc.getY(); try { try { nativeTextHandler.drawString(g2d, txt, (float) x + tx, (float) y); } catch (IOException ioe) { if (g2d instanceof AFPGraphics2D) { ((AFPGraphics2D) g2d).handleIOException(ioe); } } } finally { nativeTextHandler.setOverrideFont(null); } loc.setLocation(loc.getX() + advance, loc.getY()); return loc; }
From source file:dk.dma.epd.common.prototype.notification.MsiNmNotification.java
/** * Returns if the MSI-NM is close the the new route * * NB: This code was from the old MsiLayer. Should be optimized! * * @param route the new route// w w w . j av a2 s. c om * @param mousePosition the mouse position * @param projection the projection * @return if the MSI-NM is close the the new route */ public boolean nearNewRoute(Route route, Position mousePosition, Projection projection) { double visibilityFromNewWaypoint = EPD.getInstance().getSettings().getEnavSettings() .getMsiVisibilityFromNewWaypoint(); // Check if MSI messages should be visible on route. boolean visibleOnRoute = false; // Go through each waypoint of the route to check if the MSI message should be visible. for (int i = 0; !visibleOnRoute && i < route.getWaypoints().size(); i++) { RouteWaypoint rWaypoint = route.getWaypoints().get(i); Point2D pointA = null; Point2D pointB = null; Point2D pnt; // If the waypoint is not the last placed waypoint compare it to the next in line. // Else compare it to the mouse location. if (rWaypoint == route.getWaypoints().getLast()) { pointA = projection.forward(rWaypoint.getPos().getLatitude(), rWaypoint.getPos().getLongitude()); pointB = projection.forward(mousePosition.getLatitude(), mousePosition.getLongitude()); } else if (rWaypoint != route.getWaypoints().getLast()) { RouteWaypoint nWaypoint = route.getWaypoints().get(i + 1); pointA = projection.forward(rWaypoint.getPos().getLatitude(), rWaypoint.getPos().getLongitude()); pointB = projection.forward(nWaypoint.getPos().getLatitude(), nWaypoint.getPos().getLongitude()); } // The slope of the line. double slope = Math.round(((pointB.getY() - pointA.getY()) / (pointB.getX() - pointA.getX())) * visibilityFromNewWaypoint); // If the value of slope is more than the value of visibilityFromNewWaypoint, // change the slop reverse the x and y axis. if (Math.abs(slope) > visibilityFromNewWaypoint) { double dy = Math.abs(pointB.getY() - pointA.getY()); slope = Math.round(((pointB.getX() - pointA.getX()) / (pointB.getY() - pointA.getY())) * visibilityFromNewWaypoint); for (int j = 0; j * visibilityFromNewWaypoint < dy; j++) { pnt = pointA; // The first point should be placed a point where the mouse was clicked. if (j == 0) { visibleOnRoute = setMessageVisible(visibilityFromNewWaypoint, visibleOnRoute, projection, pnt); continue; } //Mouse placed on the right side of the last placed waypoint. if (pointA.getX() <= pointB.getX()) { if (slope > 0) { pnt.setLocation(pointA.getX() + slope, pointA.getY() + visibilityFromNewWaypoint); } else if (slope < 0) { double posSlope = Math.abs(slope); pnt.setLocation(pointA.getX() + posSlope, pointA.getY() - visibilityFromNewWaypoint); } // mouse placed on the left side. } else if (pointA.getX() > pointB.getX()) { if (slope > 0) { pnt.setLocation(pointA.getX() - slope, pointA.getY() - visibilityFromNewWaypoint); } else if (slope < 0) { double posSlope = Math.abs(slope); pnt.setLocation(pointA.getX() - posSlope, pointA.getY() + visibilityFromNewWaypoint); } } // Handles placing of point on a vertical line. if (pointA.getY() < pointB.getY() && slope == 0) { pnt.setLocation(pointA.getX(), pointA.getY() + visibilityFromNewWaypoint); } else if (pointA.getY() > pointB.getY() && slope == 0) { pnt.setLocation(pointA.getX(), pointA.getY() - visibilityFromNewWaypoint); } visibleOnRoute = setMessageVisible(visibilityFromNewWaypoint, visibleOnRoute, projection, pnt); } } else { double dx = Math.abs(pointB.getX() - pointA.getX()); for (int j = 0; j * visibilityFromNewWaypoint < dx; j++) { pnt = pointA; if (j == 0) { visibleOnRoute = setMessageVisible(visibilityFromNewWaypoint, visibleOnRoute, projection, pnt); continue; } // Mouse placed on the right side of the last placed waypoint. if (pointA.getX() <= pointB.getX()) { if (slope > 0) { pnt.setLocation(pointA.getX() + visibilityFromNewWaypoint, pointA.getY() + slope); } else if (slope < 0) { double posSlope = Math.abs(slope); pnt.setLocation(pointA.getX() + visibilityFromNewWaypoint, pointA.getY() - posSlope); } // Mouse placed on the left side of the last placed waypoint. } else if (pointA.getX() > pointB.getX()) { if (slope > 0) { pnt.setLocation(pointA.getX() - visibilityFromNewWaypoint, pointA.getY() - slope); } else if (slope < 0) { double posSlope = Math.abs(slope); pnt.setLocation(pointA.getX() - visibilityFromNewWaypoint, pointA.getY() + posSlope); } } if (pointA.getX() < pointB.getX() && slope == 0) { pnt.setLocation(pointA.getX() + visibilityFromNewWaypoint, pointA.getY()); } else if (pointA.getX() > pointB.getX() && slope == 0) { pnt.setLocation(pointA.getX() - visibilityFromNewWaypoint, pointA.getY()); } visibleOnRoute = setMessageVisible(visibilityFromNewWaypoint, visibleOnRoute, projection, pnt); } } } return visibleOnRoute; }
From source file:Distortions.java
public void showWithRadialTangential(String[] preTitles, String title, double[][] preData, // [0] - dx, [1] - dy int width, int deciamte, double x0, double y0) { int indexDx = 0; int indexDy = 1; int indexDr = 0; int indexDt = 1; int indexDa = 2; String[] extraTitles = { "R-corr(pix)", "T-corr{pix)", "A-corr(pix)" }; int newImages = extraTitles.length; int length = preData[0].length; int height = length / width; double[][] data = new double[preData.length + newImages][length]; String[] titles = new String[preTitles.length + newImages]; for (int i = 0; i < preData.length; i++) { data[i + newImages] = preData[i]; titles[i + newImages] = preTitles[i]; }//from w w w .j ava 2 s. c o m for (int i = 0; i < newImages; i++) { titles[i] = extraTitles[i]; data[i] = new double[length]; } Point2D Z = new Point2D.Double(0.0, 0.0); for (int i = 0; i < length; i++) { Point2D R = new Point2D.Double((deciamte * (i % width)) - x0, (deciamte * (i / width)) - y0); double r = R.distance(Z); Point2D uR = new Point2D.Double(1.0, 0.0); if (r > 0) uR.setLocation(R.getX() / r, R.getY() / r); Point2D dXY = new Point2D.Double(preData[indexDx][i], preData[indexDy][i]); data[indexDr][i] = dXY.getX() * uR.getX() + dXY.getY() * uR.getY(); data[indexDt][i] = -dXY.getX() * uR.getY() + dXY.getY() * uR.getX(); data[indexDa][i] = dXY.distance(Z); } this.SDFA_INSTANCE.showArrays(data, width, height, true, title, titles); }