List of usage examples for java.awt.geom Point2D getX
public abstract double getX();
From source file:edu.uci.ics.jung.algorithms.layout.AbstractLayout.java
/** * @param v// w w w .jav a 2 s . com * @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:com.sciaps.listener.JFreeChartMouseListener.java
@Override public void chartMouseClicked(ChartMouseEvent cme) { if (cme.getTrigger().isControlDown()) { Point2D p = cme.getTrigger().getPoint(); Rectangle2D plotArea = chartPanel_.getScreenDataArea(); XYPlot plot = (XYPlot) jFreeChart_.getPlot(); double chartX = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge()); double chartY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge()); if (callback_ != null) { callback_.jFreeChartOnClicked(chartX, chartY); }/* www . jav a 2s.c om*/ } }
From source file:org.apache.fop.render.pcl.PCLImageHandlerGraphics2D.java
/** {@inheritDoc} */ public void handleImage(RenderingContext context, Image image, Rectangle pos) throws IOException { PCLRenderingContext pclContext = (PCLRenderingContext) context; ImageGraphics2D imageG2D = (ImageGraphics2D) image; Dimension imageDim = imageG2D.getSize().getDimensionMpt(); PCLGenerator gen = pclContext.getPCLGenerator(); Point2D transPoint = pclContext.transformedPoint(pos.x, pos.y); gen.setCursorPos(transPoint.getX(), transPoint.getY()); boolean painted = false; ByteArrayOutputStream baout = new ByteArrayOutputStream(); PCLGenerator tempGen = new PCLGenerator(baout, gen.getMaximumBitmapResolution()); tempGen.setDitheringQuality(gen.getDitheringQuality()); try {//from w w w. ja v a 2 s . c o m GraphicContext ctx = (GraphicContext) pclContext.getGraphicContext().clone(); AffineTransform prepareHPGL2 = new AffineTransform(); prepareHPGL2.scale(0.001, 0.001); ctx.setTransform(prepareHPGL2); PCLGraphics2D graphics = new PCLGraphics2D(tempGen); graphics.setGraphicContext(ctx); graphics.setClippingDisabled(false /*pclContext.isClippingDisabled()*/); Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imageDim.getWidth(), imageDim.getHeight()); imageG2D.getGraphics2DImagePainter().paint(graphics, area); //If we arrive here, the graphic is natively paintable, so write the graphic gen.writeCommand( "*c" + gen.formatDouble4(pos.width / 100f) + "x" + gen.formatDouble4(pos.height / 100f) + "Y"); gen.writeCommand("*c0T"); gen.enterHPGL2Mode(false); gen.writeText("\nIN;"); gen.writeText("SP1;"); //One Plotter unit is 0.025mm! double scale = imageDim.getWidth() / UnitConv.mm2pt(imageDim.getWidth() * 0.025); gen.writeText("SC0," + gen.formatDouble4(scale) + ",0,-" + gen.formatDouble4(scale) + ",2;"); gen.writeText("IR0,100,0,100;"); gen.writeText("PU;PA0,0;\n"); baout.writeTo(gen.getOutputStream()); //Buffer is written to output stream gen.writeText("\n"); gen.enterPCLMode(false); painted = true; } catch (UnsupportedOperationException uoe) { log.debug( "Cannot paint graphic natively. Falling back to bitmap painting. Reason: " + uoe.getMessage()); } if (!painted) { //Fallback solution: Paint to a BufferedImage FOUserAgent ua = context.getUserAgent(); ImageManager imageManager = ua.getFactory().getImageManager(); ImageRendered imgRend; try { imgRend = (ImageRendered) imageManager.convertImage(imageG2D, new ImageFlavor[] { ImageFlavor.RENDERED_IMAGE }/*, hints*/); } catch (ImageException e) { throw new IOException("Image conversion error while converting the image to a bitmap" + " as a fallback measure: " + e.getMessage()); } gen.paintBitmap(imgRend.getRenderedImage(), new Dimension(pos.width, pos.height), pclContext.isSourceTransparencyEnabled()); } }
From source file:at.knowcenter.wag.egov.egiz.pdf.operator.path.construction.CurveToReplicateFinalPoint.java
@Override public void process(PDFOperator operator, List<COSBase> operands) throws IOException { try {/* ww w. ja v a 2 s .c o m*/ PDFPage pdfPage = (PDFPage) context; COSNumber x1 = (COSNumber) operands.get(0); COSNumber y1 = (COSNumber) operands.get(1); COSNumber x3 = (COSNumber) operands.get(2); COSNumber y3 = (COSNumber) operands.get(3); Point2D p1 = transform(x1.doubleValue(), y1.doubleValue()); Point2D p3 = transform(x3.doubleValue(), y3.doubleValue()); pdfPage.getCurrentPath().curveTo((float) p1.getX(), (float) p1.getY(), (float) p3.getX(), (float) p3.getY(), (float) p3.getX(), (float) p3.getY()); if (log.isTraceEnabled()) { log.trace("Appending cubic Bezier curve with x1:" + p1.getX() + ",y1:" + p1.getY() + ", x3:" + p3.getX() + ",y3:" + p3.getY()); } } catch (Exception e) { log.warn("Error processing operator 'y'.", e); } }
From source file:ddf.catalog.transformer.input.pdf.GeoPdfParser.java
/** * Convert a Point2d into WKT Lat/Lon// w ww. j a v a 2 s .co m * * @param point2D * @return a String representation of a WKT Lat/Lon pair */ private String point2dToWkt(Point2D point2D) { return point2D.getX() + " " + point2D.getY(); }
From source file:edu.uci.ics.jung.visualization.util.VertexShapeFactory.java
/** * Returns a regular <code>num_sides</code>-sided * <code>Polygon</code> whose bounding * box's width and height are defined by this instance's size and * aspect ratio functions for this vertex. * @param num_sides the number of sides of the polygon; must be >= 3. *//*from ww w . j a va 2 s . c om*/ public Shape getRegularPolygon(V v, int num_sides) { if (num_sides < 3) throw new IllegalArgumentException("Number of sides must be >= 3"); Rectangle2D frame = getRectangle(v); float width = (float) frame.getWidth(); float height = (float) frame.getHeight(); // generate coordinates double angle = 0; thePolygon.reset(); thePolygon.moveTo(0, 0); thePolygon.lineTo(width, 0); double theta = (2 * Math.PI) / num_sides; for (int i = 2; i < num_sides; i++) { angle -= theta; float delta_x = (float) (width * Math.cos(angle)); float delta_y = (float) (width * Math.sin(angle)); Point2D prev = thePolygon.getCurrentPoint(); thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y); } thePolygon.closePath(); // scale polygon to be right size, translate to center at (0,0) Rectangle2D r = thePolygon.getBounds2D(); double scale_x = width / r.getWidth(); double scale_y = height / r.getHeight(); float translationX = (float) (r.getMinX() + r.getWidth() / 2); float translationY = (float) (r.getMinY() + r.getHeight() / 2); AffineTransform at = AffineTransform.getScaleInstance(scale_x, scale_y); at.translate(-translationX, -translationY); Shape shape = at.createTransformedShape(thePolygon); return shape; }
From source file:org.jcurl.model.PathSegmentTest.java
public void testTrafo() throws NoninvertibleTransformException { final Point2D x0 = new Point2D.Double(1.5, 2.5); // final Point2D x0 = new Point2D.Double(0, 0); final Point2D v0 = new Point2D.Double(2, 1); // build the trafo final AffineTransform rc2wc = new AffineTransform(); {/*w w w.j a v a 2 s.c o m*/ rc2wc.rotate(-Math.acos((v0.getX() * 0 + v0.getY() * 1) / v0.distance(0, 0)), x0.getX(), x0.getY()); rc2wc.translate(x0.getX(), x0.getY()); } // check some points. // wc(x0) -> rc(0,0) Point2D tmp = rc2wc.inverseTransform(x0, null); assertEquals("", 0, tmp.getX(), 1e-9); assertEquals("", 0, tmp.getY(), 1e-9); // rc(0,1) -> wc(x0) tmp = rc2wc.transform(new Point2D.Double(0, 1), null); assertEquals("", x0.getX() + 0.8944271909999, tmp.getX(), 1e-6); assertEquals("", x0.getY() + 0.4472135954999, tmp.getY(), 1e-6); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.legend.CustomLegendGraphic.java
@Override public void draw(Graphics2D g2, Rectangle2D area) { area = trimMargin(area);/*from ww w . j a v a 2 s .co m*/ drawBorder(g2, area); area = trimBorder(area); area = trimPadding(area); if (isLineVisible()) { Point2D location = RectangleAnchor.coordinates(area, getShapeLocation()); Shape aLine = ShapeUtilities.createTranslatedShape(getLine(), getShapeAnchor(), location.getX(), location.getY()); g2.setPaint(getLinePaint()); g2.setStroke(getLineStroke()); g2.draw(aLine); } if (isShapeVisible()) { Point2D location = RectangleAnchor.coordinates(area, getShapeLocation()); Shape s = ShapeUtilities.createTranslatedShape(getShape(), getShapeAnchor(), location.getX(), location.getY()); if (isShapeFilled()) { Paint p = getFillPaint(); if (p instanceof GradientPaint) { GradientPaint gp = (GradientPaint) getFillPaint(); p = getFillPaintTransformer().transform(gp, s); } else if (p instanceof LinearGradientPaint) { LinearGradientPaint gradient = (LinearGradientPaint) p; Rectangle2D bounds = s.getBounds2D(); p = getTranslatedLinearGradientPaint(gradient, new Point2D.Double(bounds.getMinX(), bounds.getMinY()), new Point2D.Double(bounds.getMaxX(), bounds.getMaxY()), false); } g2.setPaint(p); g2.fill(s); } if (isShapeOutlineVisible()) { g2.setPaint(getOutlinePaint()); g2.setStroke(getOutlineStroke()); g2.draw(s); } } }
From source file:at.knowcenter.wag.egov.egiz.pdfbox2.pdf.operator.path.construction.CurveToReplicateFinalPoint.java
@Override public void process(Operator operator, List<COSBase> operands) throws IOException { try {//from w w w . j ava 2 s . c o m PDFPage pdfPage = (PDFPage) context; COSNumber x1 = (COSNumber) operands.get(0); COSNumber y1 = (COSNumber) operands.get(1); COSNumber x3 = (COSNumber) operands.get(2); COSNumber y3 = (COSNumber) operands.get(3); Point2D p1 = transform(x1.doubleValue(), y1.doubleValue()); Point2D p3 = transform(x3.doubleValue(), y3.doubleValue()); pdfPage.getCurrentPath().curveTo((float) p1.getX(), (float) p1.getY(), (float) p3.getX(), (float) p3.getY(), (float) p3.getX(), (float) p3.getY()); if (log.isTraceEnabled()) { log.trace("Appending cubic Bezier curve with x1:" + p1.getX() + ",y1:" + p1.getY() + ", x3:" + p3.getX() + ",y3:" + p3.getY()); } } catch (Exception e) { log.warn("Error processing operator 'y'.", e); } }
From source file:edu.uci.ics.jung.visualization.util.VertexShapeFactory.java
/** * Returns a regular <code>Polygon</code> of <code>num_points</code> * points whose bounding /* www.j a va 2s. c o m*/ * box's width and height are defined by this instance's size and * aspect ratio functions for this vertex. * @param num_points the number of points of the polygon; must be >= 5. */ public Shape getRegularStar(V v, int num_points) { if (num_points < 5) throw new IllegalArgumentException("Number of sides must be >= 5"); Rectangle2D frame = getRectangle(v); float width = (float) frame.getWidth(); float height = (float) frame.getHeight(); // generate coordinates double theta = (2 * Math.PI) / num_points; double angle = -theta / 2; thePolygon.reset(); thePolygon.moveTo(0, 0); float delta_x = width * (float) Math.cos(angle); float delta_y = width * (float) Math.sin(angle); Point2D prev = thePolygon.getCurrentPoint(); thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y); for (int i = 1; i < num_points; i++) { angle += theta; delta_x = width * (float) Math.cos(angle); delta_y = width * (float) Math.sin(angle); prev = thePolygon.getCurrentPoint(); thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y); angle -= theta * 2; delta_x = width * (float) Math.cos(angle); delta_y = width * (float) Math.sin(angle); prev = thePolygon.getCurrentPoint(); thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y); } thePolygon.closePath(); // scale polygon to be right size, translate to center at (0,0) Rectangle2D r = thePolygon.getBounds2D(); double scale_x = width / r.getWidth(); double scale_y = height / r.getHeight(); float translationX = (float) (r.getMinX() + r.getWidth() / 2); float translationY = (float) (r.getMinY() + r.getHeight() / 2); AffineTransform at = AffineTransform.getScaleInstance(scale_x, scale_y); at.translate(-translationX, -translationY); Shape shape = at.createTransformedShape(thePolygon); return shape; }