List of usage examples for java.awt.geom Point2D getX
public abstract double getX();
From source file:peakml.util.jfreechart.FastSpectrumPlot.java
public void zoomDomainAxes(double factor, PlotRenderingInfo state, Point2D source, boolean useAnchor) { if (useAnchor) { // get the source coordinate - this plot has always a VERTICAL orientation double sourceX = source.getX(); double anchorX = xaxis.java2DToValue(sourceX, state.getDataArea(), RectangleEdge.BOTTOM); xaxis.resizeRange2(factor, anchorX); } else {//from w w w . j a v a 2 s. c om xaxis.resizeRange(factor); } }
From source file:org.kuali.student.repository.viewer.GitGraphTransformer.java
private Point2D place(RevCommit commit, RevCommit parentCommit) { Point2D parentPlacement = findPlacement(parentCommit); if (parentPlacement == null) { parentPlacement = place(parentCommit); }// www . j a v a 2 s .c o m Point2D.Double placement = new Point2D.Double(parentPlacement.getX(), parentPlacement.getY() + 10); while (this.pointToCommitsMap.containsKey(placement)) { // prevent placements on the same point placement = new Point2D.Double(placement.getX() + 10, placement.getY() + 10); } this.placedCommitsMap.put(commit, placement); this.pointToCommitsMap.put(placement, commit); return placement; }
From source file:cl.b9.socialNetwork.jung.SNPajekNetWriter.java
/** * Writes <code>graph</code> to <code>w</code>. Labels for vertices may * be supplied by <code>vs</code> (defaults to no labels if null), * edge weights may be specified by <code>nev</code> * (defaults to weights of 1.0 if null), * and vertex locations may be specified by <code>vld</code> (defaults * to no locations if null). /* w w w . j av a 2 s. c o m*/ */ @SuppressWarnings("unchecked") public void save(Graph<V, E> graph, Writer w, Transformer<V, String> vs, Transformer<E, Number> nev, Transformer<V, Point2D> vld, Transformer<V, String> shape) throws IOException { /* * TODO: Changes we might want to make: * - optionally writing out in list form */ BufferedWriter writer = new BufferedWriter(w); if (nev == null) nev = new Transformer<E, Number>() { public Number transform(E e) { return 1; } }; writer.write("*Vertices " + graph.getVertexCount()); writer.newLine(); List<V> id = new ArrayList<V>(graph.getVertices());//Indexer.getIndexer(graph); for (V currentVertex : graph.getVertices()) { // convert from 0-based to 1-based index int v_id = id.indexOf(currentVertex) + 1; writer.write("" + v_id); if (vs != null) { String label = vs.transform(currentVertex); if (label != null) writer.write(" \"" + label + "\""); } if (vld != null) { Point2D location = vld.transform(currentVertex); if (location != null) writer.write(" " + location.getX() + " " + location.getY()); } if (shape != null) { writer.write(" " + shape.transform(currentVertex) + " x_fact 1"); } writer.newLine(); } Collection<E> d_set = new HashSet<E>(); Collection<E> u_set = new HashSet<E>(); boolean directed = graph instanceof DirectedGraph; boolean undirected = graph instanceof UndirectedGraph; // if it's strictly one or the other, no need to create extra sets if (directed) d_set.addAll(graph.getEdges()); if (undirected) u_set.addAll(graph.getEdges()); if (!directed && !undirected) // mixed-mode graph { u_set.addAll(graph.getEdges()); d_set.addAll(graph.getEdges()); for (E e : graph.getEdges()) { if (graph.getEdgeType(e) == EdgeType.UNDIRECTED) { d_set.remove(e); } else { u_set.remove(e); } } } // write out directed edges if (!d_set.isEmpty()) { writer.write("*Arcs"); writer.newLine(); } for (E e : d_set) { int source_id = id.indexOf(graph.getEndpoints(e).getFirst()) + 1; int target_id = id.indexOf(graph.getEndpoints(e).getSecond()) + 1; // float weight = nev.get(e).floatValue(); float weight = nev.transform(e).floatValue(); writer.write(source_id + " " + target_id + " " + weight); writer.newLine(); } // write out undirected edges if (!u_set.isEmpty()) { writer.write("*Edges"); writer.newLine(); } for (E e : u_set) { Pair<V> endpoints = graph.getEndpoints(e); int v1_id = id.indexOf(endpoints.getFirst()) + 1; int v2_id = id.indexOf(endpoints.getSecond()) + 1; // float weight = nev.get(e).floatValue(); float weight = nev.transform(e).floatValue(); writer.write(v1_id + " " + v2_id + " " + weight); writer.newLine(); } writer.close(); }
From source file:org.squidy.designer.util.ImageUtils.java
public static Shape getShapeOfImage(BufferedImage image) { // Get the data Raster data = image.getData(); ////from w ww .j a va 2s . c o m // System.out.println("num of bands = " + data.getNumBands()); // The colour of the pixel looking at // Shoulld have length of 4 (RGBA) int[] lookAt = null; // The map of all the points Point2D[][] pointMap = new Point2D[data.getWidth()][data.getHeight()]; // The from point Point2D from = null; // The general path GeneralPath path = new GeneralPath(); // Go round height for (int y = 0; y < data.getHeight(); y++) { // Go round width for (int x = 0; x < data.getWidth(); x++) { // Get the colour lookAt = data.getPixel(x, y, lookAt); // The alpha int a = lookAt[3]; // If > then 0 if (a > 0) { // Output 1 //System.out.print(1); // Save point pointMap[x][y] = new Point2D.Double(x, y); if (from == null) { from = pointMap[x][y]; } } // 0 else { // Output 0 //System.out.print(0); // Nothing her pointMap[x][y] = null; } } // New line //System.out.println(); } // Move it to the from if (from != null) { path.moveTo(from.getX(), from.getY()); /* * Make the shape */ // Go round height for (int y = 0; y < data.getHeight(); y++) { // Go round width for (int x = 0; x < data.getWidth(); x++) { // If the point is not null if (pointMap[x][y] != null) { // Draw a line to path.append(new Rectangle2D.Double(pointMap[x][y].getX(), pointMap[x][y].getY(), 1, 1), true); // path.lineTo(pointMap[x][y].getX(), pointMap[x][y].getY()); } } } path.closePath(); // TODO: Put in the middle return path; } return null; }
From source file:edu.uci.ics.jung.io.CustomPajekNetWriter.java
/** * Writes <code>graph</code> to <code>w</code>. Labels for vertices may be * supplied by <code>vs</code> (defaults to no labels if null), edge weights * may be specified by <code>nev</code> (defaults to weights of 1.0 if * null), and vertex locations may be specified by <code>vld</code> * (defaults to no locations if null)./*from ww w . j a v a2s . c om*/ */ public void save(MyGraph<V, E> graph, Writer w, Transformer<V, String> vs, Transformer<E, Number> nev, Transformer<V, Point2D> vld) throws IOException { /* * TODO: Changes we might want to make: * - optionally writing out in list form */ BufferedWriter writer = new BufferedWriter(w); if (nev == null) { nev = new Transformer<E, Number>() { public Number transform(E e) { return 1; } }; } writer.write("*Colors " + graph.getLayoutParameters().getBackgroundColorRgb() + "," + graph.getLayoutParameters().getEdgeColorRgb()); writer.newLine(); writer.write( "*Vertices " + graph.getVertexCount() + "," + graph.getLayoutParameters().areNodeIconsAllowed()); writer.newLine(); List<V> id = new ArrayList<V>(graph.getVertices());//Indexer.getIndexer(graph); for (V currentVertex : graph.getVertices()) { // convert from 0-based to 1-based index int v_id = id.indexOf(currentVertex) + 1; writer.write("" + v_id); if (vs != null) { String label = vs.transform(currentVertex); if (label != null) { writer.write(" \"" + label + "\""); } } if (vld != null) { Point2D location = vld.transform(currentVertex); if (location != null) { writer.write(" " + location.getX() + " " + location.getY() + " 0.0"); } } writer.newLine(); } Collection<E> d_set = new HashSet<E>(); Collection<E> u_set = new HashSet<E>(); boolean directed = graph instanceof DirectedGraph; boolean undirected = graph instanceof UndirectedGraph; // if it's strictly one or the other, no need to create extra sets if (directed) { d_set.addAll(graph.getEdges()); } if (undirected) { u_set.addAll(graph.getEdges()); } if (!directed && !undirected) // mixed-mode graph { u_set.addAll(graph.getEdges()); d_set.addAll(graph.getEdges()); for (E e : graph.getEdges()) { if (graph.getEdgeType(e) == EdgeType.UNDIRECTED) { d_set.remove(e); } else { u_set.remove(e); } } } // write out directed edges if (!d_set.isEmpty()) { writer.write("*Arcs"); writer.newLine(); } for (E e : d_set) { int source_id = id.indexOf(graph.getEndpoints(e).getFirst()) + 1; int target_id = id.indexOf(graph.getEndpoints(e).getSecond()) + 1; float weight = nev.transform(e).floatValue(); writer.write(source_id + " " + target_id + " " + weight); writer.newLine(); } // write out undirected edges if (!u_set.isEmpty()) { writer.write("*Edges"); writer.newLine(); } for (E e : u_set) { Pair<V> endpoints = graph.getEndpoints(e); int v1_id = id.indexOf(endpoints.getFirst()) + 1; int v2_id = id.indexOf(endpoints.getSecond()) + 1; float weight = nev.transform(e).floatValue(); writer.write(v1_id + " " + v2_id + " " + weight); writer.newLine(); } writer.close(); }
From source file:vteaexploration.plotgatetools.gates.PolygonGate.java
@Override public Path2D createPath2D() { Point2D p; Path2D.Double polygon = new Path2D.Double(); ListIterator<Point2D.Double> itr = vertices.listIterator(); p = (Point2D) vertices.get(0); polygon.moveTo(p.getX(), p.getY()); while (itr.hasNext()) { p = (Point2D) itr.next(); polygon.lineTo(p.getX(), p.getY()); }//from w ww. ja v a 2 s .c o m polygon.closePath(); return polygon; }
From source file:org.opensha.sha.calc.IM_EventSet.v03.test.IM_EventSetHazardCurveTest.java
@Test public void testHazardCurve() throws IOException { HazardCurveCalculator calc = new HazardCurveCalculator(); ArbitrarilyDiscretizedFunc realCurve = CyberShakePlotFromDBControlPanel.createUSGS_PGA_Function(); ArbitrarilyDiscretizedFunc rLogHazFunction = getLogFunction(realCurve); System.out.println("IMR Params: " + imr.getAllParamMetadata()); System.out.println("Calculating regular curve"); calc.getHazardCurve(rLogHazFunction, site, imr, erf); realCurve = unLogFunction(realCurve, rLogHazFunction); runHAZ01A();//from ww w. j a v a 2 s . com String fileName = outputDir.getAbsolutePath() + File.separator + HAZ01Writer.HAZ01A_FILE_NAME; ScalarIntensityMeasureRelationshipAPI hIMR = new HAZ01A_FakeAttenRel(fileName); EqkRupForecastAPI hERF = new HAZ01A_FakeERF(erf); hERF.updateForecast(); ArbitrarilyDiscretizedFunc hCurve = CyberShakePlotFromDBControlPanel.createUSGS_PGA_Function(); System.out.println("Calculating IM based curve"); ArbitrarilyDiscretizedFunc hLogHazFunction = getLogFunction(hCurve); calc.getHazardCurve(hLogHazFunction, site, hIMR, hERF); hCurve = unLogFunction(hCurve, hLogHazFunction); // ArbitrarilyDiscretizedFunc realCurve = // ArbitrarilyDiscretizedFunc.loadFuncFromSimpleFile("/tmp/imEventSetTest/curve.txt"); ArrayList<ArbitrarilyDiscretizedFunc> curves = new ArrayList<ArbitrarilyDiscretizedFunc>(); curves.add(realCurve); curves.add(hCurve); boolean xLog = false; boolean yLog = false; boolean customAxis = true; this.gp.drawGraphPanel(imt, "", curves, xLog, yLog, customAxis, "Curves", this); this.gp.setVisible(true); this.gp.togglePlot(null); this.gp.validate(); this.gp.repaint(); ChartUtilities.saveChartAsPNG(new File(outputDir.getAbsolutePath() + File.separator + "curves.png"), gp.getCartPanel().getChart(), 800, 600); double maxDiff = 0; double maxPDiff = 0; for (int i = 0; i < hCurve.getNum(); i++) { Point2D hPt = hCurve.get(i); Point2D rPt = realCurve.get(i); assertEquals(hPt.getX(), rPt.getX(), 0); if (hPt.getX() >= 10.) continue; System.out.println("Comparing point: " + i); System.out.println("\"Real\" point:\t" + rPt.getX() + ", " + rPt.getY()); System.out.println("HAZ01A point:\t" + hPt.getX() + ", " + hPt.getY()); if (hPt.getY() == 0 && rPt.getY() == 0) continue; double absDiff = Math.abs(hPt.getY() - rPt.getY()); if (absDiff > maxDiff) maxDiff = absDiff; double absPDiff = absDiff / rPt.getY() * 100d; if (absPDiff > maxPDiff) maxPDiff = absPDiff; System.out.println("absDiff: " + absDiff + ", abs % diff: " + absPDiff); boolean success = absPDiff < TOL_PERCENT; if (!success) { System.out.println("FAIL!"); } assertTrue(success); } System.out.println("Max Diff: " + maxDiff); System.out.println("Max Diff %: " + maxPDiff); }
From source file:main.MapKit.java
@Override public void paintWaypoint(Graphics2D g, JXMapViewer viewer, MyWaypoint w) { g = (Graphics2D) g.create();/*from ww w.j a v a2 s. c o m*/ Point2D point = viewer.getTileFactory().geoToPixel(w.getPosition(), viewer.getZoom()); int x = (int) point.getX(); int y = (int) point.getY(); if (w.amount == -1) { //means it's an original data point int fontSize = 28 - viewer.getZoom() * 2; //font size is larger when zoom in if (fontSize < 6) fontSize = 6; g.setFont(new Font("Arial", Font.PLAIN, fontSize)); g.setColor(w.color); g.drawString("x", x - fontSize / 2, y + fontSize / 2); g.dispose(); return; } if (origImage == null) { return; } BufferedImage myImg = map.get(w.color); if (myImg == null) { myImg = convert(origImage, w.color); map.put(w.color, myImg); } g.drawImage(myImg, x - myImg.getWidth() / 2, y - myImg.getHeight(), null); String label = String.valueOf(w.amount); // g.setFont(font); FontMetrics metrics = g.getFontMetrics(); int tw = metrics.stringWidth(label); int th = 1 + metrics.getAscent(); // g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.drawString(label, x - tw / 2, y + th); g.dispose(); }
From source file:org.apache.pdfbox.pdmodel.font.PDCIDFontType0.java
@Override public float getWidthFromFont(int code) throws IOException { int cid = codeToCID(code); float width;/* w w w. j av a 2 s .c om*/ if (cidFont != null) { width = getType2CharString(cid).getWidth(); } else if (isEmbedded && t1Font instanceof CFFType1Font) { width = ((CFFType1Font) t1Font).getType2CharString(cid).getWidth(); } else { width = t1Font.getWidth(getGlyphName(code)); } Point2D p = new Point2D.Float(width, 0); fontMatrixTransform.transform(p, p); return (float) p.getX(); }
From source file:ru.jcorp.smartstreets.gui.map.bundle.GraphEditMousePlugin.java
@SuppressWarnings("unchecked") public void mouseReleased(MouseEvent e) { if (checkModifiers(e)) { editor.clearPath();//from w w w. ja v a 2s .co m final VisualizationViewer<GraphNode, GraphLink> vv = (VisualizationViewer<GraphNode, GraphLink>) e .getSource(); final Point2D p = e.getPoint(); Layout<GraphNode, GraphLink> layout = vv.getModel().getGraphLayout(); GraphElementAccessor<GraphNode, GraphLink> pickSupport = vv.getPickSupport(); if (pickSupport != null) { final GraphNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY()); if (vertex != null && startVertex != null) { Graph<GraphNode, GraphLink> graph = vv.getGraphLayout().getGraph(); GraphLink coGraphLink; if (edgeFactory instanceof LinkedLinesFactory) { coGraphLink = ((LinkedLinesFactory) edgeFactory).createLinkedLine(startVertex, vertex); } else { coGraphLink = edgeFactory.create(); } SmartMapLine line = coGraphLink.getMapLine(); if (line.getCodirectionalSign() == null) line.setCodirectionalSign(new RoadSign()); if (line.getOppositelySign() == null) line.setOppositelySign(new RoadSign()); GraphLink opGraphLink = new GraphLink(coGraphLink.getMapLine(), coGraphLink.getMapLine().getOppositelySign()); coGraphLink.setNeighbor(opGraphLink); opGraphLink.setNeighbor(coGraphLink); graph.addEdge(coGraphLink, startVertex, vertex, edgeIsDirected); graph.addEdge(opGraphLink, vertex, startVertex, edgeIsDirected); vv.repaint(); } } startVertex = null; down = null; edgeIsDirected = EdgeType.UNDIRECTED; vv.removePostRenderPaintable(edgePaintable); vv.removePostRenderPaintable(arrowPaintable); } }