List of usage examples for java.awt.geom Point2D getX
public abstract double getX();
From source file:org.jcurl.core.swing.RockEditDisplay.java
protected static void circleDC(final Graphics2D g, final Point2D center, final int radius) { final int cx = (int) center.getX(); final int cy = (int) center.getY(); g.drawArc(cx - radius, cy - radius, 2 * radius, 2 * radius, 0, 360); }
From source file:FindHullWindowLogic.java
static public void fullfilTableWithConvexHull(JTable jTableDest, ArrayList<Point2D> convexHull) { DefaultTableModel jTableDestModel = (DefaultTableModel) jTableDest.getModel(); jTableDestModel.setRowCount(0);//from w ww. j a va2s . com int i = 1; for (Point2D onePoint : convexHull) { if (i != 1 && areTheSamePoints(onePoint, convexHull.get(0))) break; jTableDestModel.addRow(new Object[] { i + ".", onePoint.getX(), onePoint.getY() }); i++; } }
From source file:net.sf.mcf2pdf.mcfelements.util.ImageUtil.java
/** * Rotates the given buffered image by the given angle, and returns a newly * created image, containing the rotated image. * * @param img Image to rotate.// w w w . j a v a 2 s . co m * @param angle Angle, in radians, by which to rotate the image. * @param drawOffset Receives the offset which is required to draw the image, * relative to the original (0,0) corner, so that the center of the image is * still on the same position. * * @return A newly created image containing the rotated image. */ public static BufferedImage rotateImage(BufferedImage img, float angle, Point drawOffset) { int w = img.getWidth(); int h = img.getHeight(); AffineTransform tf = AffineTransform.getRotateInstance(angle, w / 2.0, h / 2.0); // get coordinates for all corners to determine real image size Point2D[] ptSrc = new Point2D[4]; ptSrc[0] = new Point(0, 0); ptSrc[1] = new Point(w, 0); ptSrc[2] = new Point(w, h); ptSrc[3] = new Point(0, h); Point2D[] ptTgt = new Point2D[4]; tf.transform(ptSrc, 0, ptTgt, 0, ptSrc.length); Rectangle rc = new Rectangle(0, 0, w, h); for (Point2D p : ptTgt) { if (p.getX() < rc.x) { rc.width += rc.x - p.getX(); rc.x = (int) p.getX(); } if (p.getY() < rc.y) { rc.height += rc.y - p.getY(); rc.y = (int) p.getY(); } if (p.getX() > rc.x + rc.width) rc.width = (int) (p.getX() - rc.x); if (p.getY() > rc.y + rc.height) rc.height = (int) (p.getY() - rc.y); } BufferedImage imgTgt = new BufferedImage(rc.width, rc.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = imgTgt.createGraphics(); // create a NEW rotation transformation around new center tf = AffineTransform.getRotateInstance(angle, rc.getWidth() / 2, rc.getHeight() / 2); g2d.setTransform(tf); g2d.drawImage(img, -rc.x, -rc.y, null); g2d.dispose(); drawOffset.x += rc.x; drawOffset.y += rc.y; return imgTgt; }
From source file:MainWindowLogic.java
static void readPointsFile(File fil_hndl, JTable tabela) throws IOException, InvalidFormatInFileException { ReadPointsFromFile pointsReader = new ReadPointsFromFile(fil_hndl.getPath()); System.out.println("cieka wcztytywanego pliku: " + fil_hndl.getPath()); Point2D[] readed = pointsReader.readPoints(); DefaultTableModel defaultModelTabeli = (DefaultTableModel) tabela.getModel(); for (Point2D point : readed) { defaultModelTabeli.addRow(/*from w ww .j a v a 2 s . c o m*/ new Object[] { defaultModelTabeli.getRowCount() + 1 + ".", point.getX(), point.getY(), false }); } }
From source file:PaintUtils.java
private static double calcAngle(Point2D p1, Point2D p2) { double x_off = p2.getX() - p1.getX(); double y_off = p2.getY() - p1.getY(); double angle = Math.atan(y_off / x_off); if (x_off < 0) { angle = angle + Math.PI;//from ww w .ja v a 2 s . c o m } if (angle < 0) { angle += 2 * Math.PI; } if (angle > 2 * Math.PI) { angle -= 2 * Math.PI; } return angle; }
From source file:inflor.core.utils.ChartUtils.java
public static Point2D getPlotCoordinates(MouseEvent e, FCSChartPanel panel) { Point2D p = panel.translateScreenToJava2D(e.getPoint()); Rectangle2D plotArea = panel.getScreenDataArea(); XYPlot plot = panel.getChart().getXYPlot(); double x = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge()); double y = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge()); return new Point2D.Double(x, y); }
From source file:net.panthema.BispanningGame.GraphString.java
public static String write_graph(MyGraph g, Transformer<Integer, Point2D> gl) { ByteArrayOutputStream ba = new ByteArrayOutputStream(); PrintWriter pw = new PrintWriter(ba); // print the vertex list pw.print('V'); pw.print(g.getVertexCount());/*from ww w. j av a 2 s.c om*/ pw.print(':'); Collection<Integer> vcoll = g.getVertices(); ArrayList<Integer> vlist = new ArrayList<Integer>(vcoll); Collections.sort(vlist, new Comparator<Integer>() { public int compare(Integer arg0, Integer arg1) { return arg0 - arg1; } }); for (Integer v : vlist) { pw.print('i'); pw.print(v); Point2D pos = gl.transform(v); pw.print('x'); pw.print((int) pos.getX()); pw.print('y'); pw.print((int) pos.getY()); pw.print('/'); } pw.print(';'); // print the edge list pw.print('E'); pw.print(g.getEdgeCount()); pw.print(':'); Collection<MyEdge> ecoll = g.getEdges(); ArrayList<MyEdge> elist = new ArrayList<MyEdge>(ecoll); Collections.sort(elist, new Comparator<MyEdge>() { public int compare(MyEdge arg0, MyEdge arg1) { return arg0.id - arg1.id; } }); for (MyEdge e : elist) { Integer e_x = g.getEndpoints(e).getFirst(); Integer e_y = g.getEndpoints(e).getSecond(); pw.print('i'); pw.print(e.id); pw.print('t'); pw.print(e_x); pw.print('h'); pw.print(e_y); pw.print('c'); pw.print(e.color); pw.print('/'); } pw.print(';'); pw.flush(); return ba.toString(); }
From source file:org.jcurl.core.swing.RockEditDisplay.java
/** * @param g// ww w.j a v a 2 s. c om * @param abs1_dc * @param abs2_dc */ protected static void lineDC(final Graphics2D g, final Point2D abs1_dc, final Point2D abs2_dc) { // perpendicular line for the "strength" g.drawLine((int) abs1_dc.getX(), (int) abs1_dc.getY(), (int) abs2_dc.getX(), (int) abs2_dc.getY()); }
From source file:org.jax.bham.util.JFreeChartUtil.java
/** * Convert from a Java2D point to a graph point * @param java2DPoint//from w w w. j a v a 2 s.c om * the java 2D point to convert * @param chartPanel * the chart panel to convert * @return * the point */ public static Point2D java2DPointToGraphPoint(Point2D java2DPoint, ChartPanel chartPanel) { JFreeChart chart = chartPanel.getChart(); ChartRenderingInfo info = chartPanel.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); XYPlot xyPlot = chart.getXYPlot(); double graphX = xyPlot.getDomainAxis().java2DToValue(java2DPoint.getX(), dataArea, xyPlot.getDomainAxisEdge()); double graphY = xyPlot.getRangeAxis().java2DToValue(java2DPoint.getY(), dataArea, xyPlot.getRangeAxisEdge()); return new Point2D.Double(graphX, graphY); }
From source file:mulavito.gui.components.LayerViewer.java
public static void autoZoomViewer(VisualizationViewer<?, ?> vv, LayerViewer<?, ?> home, Directions direction) { if (vv == null || home == null) return;//from w w w . j ava2 s . c om // reset transforms MutableTransformer layoutTrans = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(edu.uci.ics.jung.visualization.Layer.LAYOUT); layoutTrans.setToIdentity(); MutableTransformer viewTrans = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(edu.uci.ics.jung.visualization.Layer.VIEW); viewTrans.setToIdentity(); Dimension dim = vv.getSize(); Rectangle2D.Double graphBounds = home.getGraphBoundsCache(); CrossoverScalingControl scaler = new CrossoverScalingControl(); // Scale using crossover scaler, so vertices will not grow // larger than they are in original double factor = Double.POSITIVE_INFINITY; if (direction == Directions.HORIZONTAL || direction == Directions.BOTH) factor = dim.getWidth() / graphBounds.width; if (direction == Directions.VERTICAL || direction == Directions.BOTH || Double.isInfinite(factor)) factor = Math.min(factor, dim.getHeight() / graphBounds.height); scaler.scale(vv, (float) factor, vv.getCenter()); // Translate center of graph to center of vv. Point2D lvc = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(vv.getCenter()); double dx = (lvc.getX() - graphBounds.getCenterX()); double dy = (lvc.getY() - graphBounds.getCenterY()); layoutTrans.translate(dx, dy); }