List of usage examples for java.awt.geom AffineTransform AffineTransform
public AffineTransform()
From source file:org.jcurl.model.PathSegment.java
protected PathSegment(boolean isRockCoordinates, double t0, Point2D x0, Point2D v0, final R1R1Function[] c) { super(c);//from w w w. ja v a 2 s. c o m if (c.length != 3) throw new IllegalArgumentException("rock path curve must have 3 dimensions, but had " + c.length); this.isRockCoordinates = isRockCoordinates; this.rc2wc = new AffineTransform(); final double vabs = v0.distance(0, 0); if (vabs != 0.0) rc2wc.rotate(-Math.acos((v0.getX() * 0 + v0.getY() * 1) / vabs), x0.getX(), x0.getY()); rc2wc.translate(x0.getX(), x0.getY()); this.t0 = t0; }
From source file:JXTransformer.java
public JXTransformer(JComponent view) { this(view, new AffineTransform()); }
From source file:org.apache.fop.render.pdf.pdfbox.PDFBoxImageHandler.java
public void handleImage(RenderingContext context, Image image, Rectangle pos) throws IOException { assert context instanceof PDFRenderingContext; PDFRenderingContext pdfContext = (PDFRenderingContext) context; PDFContentGenerator generator = pdfContext.getGenerator(); assert image instanceof ImagePDF; ImagePDF pdfImage = (ImagePDF) image; float x = (float) pos.getX() / 1000f; float y = (float) pos.getY() / 1000f; // float w = (float)pos.getWidth() / 1000f; float h = (float) pos.getHeight() / 1000f; AffineTransform pageAdjust = new AffineTransform(); AffineTransform at = generator.getAffineTransform(); if (at != null) { pageAdjust.setToTranslation((float) (generator.getState().getTransform().getTranslateX()), (float) (generator.getState().getTransform().getTranslateY() - h - y)); }/*from w w w .j a v a2s .c o m*/ FontInfo fontinfo = (FontInfo) context.getHint("fontinfo"); String stream = createStreamForPDF(pdfImage, pdfContext.getPage(), pdfContext.getUserAgent(), pageAdjust, fontinfo, pos, pdfContext.getPageNumbers(), pdfContext.getPdfLogicalStructureHandler(), pdfContext.getCurrentSessionStructElem()); if (stream == null) { return; } if (pageAdjust.getScaleX() != 0) { pageAdjust.translate(x * (1 / pageAdjust.getScaleX()), -y * (1 / -pageAdjust.getScaleY())); } generator.placeImage(pageAdjust, stream); }
From source file:view.BackgroundImageController.java
public void setGraphBackgroundImage(final VisualizationViewer vv, final ImageIcon background, final double xOffset, final double yOffset) { removeBackgroundImage(vv);/*from w ww.j av a 2s.co m*/ preRender = new VisualizationViewer.Paintable() { public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AffineTransform oldXform = g2d.getTransform(); AffineTransform lat = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT) .getTransform(); AffineTransform vat = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW) .getTransform(); AffineTransform at = new AffineTransform(); at.concatenate(g2d.getTransform()); at.concatenate(vat); at.concatenate(lat); g2d.setTransform(at); g.drawImage(background.getImage(), (int) Math.round(-background.getIconWidth() / xOffset), (int) Math.round(-background.getIconHeight() / yOffset), background.getIconWidth(), background.getIconHeight(), vv); g2d.setTransform(oldXform); } public boolean useTransform() { return false; } }; vv.addPreRenderPaintable(preRender); background.getImage().flush(); Runtime.getRuntime().gc(); }
From source file:TransformTransRotation.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // Use antialiasing. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Move the origin to 75, 75. AffineTransform at = AffineTransform.getTranslateInstance(75, 75); g2.transform(at);//from www.j a v a2 s .c om // Draw the shapes in their original locations. g2.setPaint(Color.black); g2.draw(axes); g2.draw(shape); // Transform the Graphics2D. AffineTransform rat = new AffineTransform(); rat.setToTranslation(100, 0); rat.rotate(Math.PI / 6); g2.transform(rat); // Draw the "new" shapes in dashed. Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 }, 0); g2.setStroke(stroke); g2.draw(axes); g2.draw(shape); }
From source file:TransformersRotationTranslation.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // Use antialiasing. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Move the origin to 75, 75. AffineTransform at = AffineTransform.getTranslateInstance(75, 75); g2.transform(at);//from ww w . ja v a2 s . c om // Draw the shapes in their original locations. g2.setPaint(Color.black); g2.draw(axes); g2.draw(shape); // Transform the Graphics2D. AffineTransform rat = new AffineTransform(); rat.setToRotation(Math.PI / 6); rat.translate(100, 100); g2.transform(rat); // Draw the "new" shapes in dashed. Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 }, 0); g2.setStroke(stroke); g2.draw(axes); g2.draw(shape); }
From source file:org.apache.fop.render.pcl.PCLGraphics2DAdapter.java
/** {@inheritDoc} */ public void paintImage(Graphics2DImagePainter painter, RendererContext context, int x, int y, int width, int height) throws IOException { PCLRendererContext pclContext = PCLRendererContext.wrapRendererContext(context); PCLRenderer pcl = (PCLRenderer) context.getRenderer(); PCLGenerator gen = pcl.gen;//from w w w . j av a 2 s . co m // get the 'width' and 'height' attributes of the image/document Dimension dim = painter.getImageSize(); float imw = (float) dim.getWidth(); float imh = (float) dim.getHeight(); boolean painted = false; boolean paintAsBitmap = pclContext.paintAsBitmap(); if (!paintAsBitmap) { ByteArrayOutputStream baout = new ByteArrayOutputStream(); PCLGenerator tempGen = new PCLGenerator(baout, gen.getMaximumBitmapResolution()); try { GraphicContext ctx = (GraphicContext) pcl.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(pclContext.isClippingDisabled()); Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh); painter.paint(graphics, area); //If we arrive here, the graphic is natively paintable, so write the graphic pcl.saveGraphicsState(); pcl.setCursorPos(x, y); gen.writeCommand( "*c" + gen.formatDouble4(width / 100f) + "x" + gen.formatDouble4(height / 100f) + "Y"); gen.writeCommand("*c0T"); gen.enterHPGL2Mode(false); gen.writeText("\nIN;"); gen.writeText("SP1;"); //One Plotter unit is 0.025mm! double scale = imw / UnitConv.mm2pt(imw * 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); pcl.restoreGraphicsState(); 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 int resolution = Math.round(context.getUserAgent().getTargetResolution()); BufferedImage bi = paintToBufferedImage(painter, pclContext, resolution, !pclContext.isColorCanvas(), false); pcl.setCursorPos(x, y); gen.paintBitmap(bi, new Dimension(width, height), pclContext.isSourceTransparency()); } }
From source file:org.apache.fop.render.ps.svg.PSSVGGraphics2D.java
protected void applyPaint(Paint paint, boolean fill) { super.applyPaint(paint, fill); if (paint instanceof LinearGradientPaint) { Pattern pattern = GradientMaker.makeLinearGradient((LinearGradientPaint) paint, new AffineTransform(), new AffineTransform()); try {//from w w w .j a va 2s .co m gen.write(outputPattern(pattern)); } catch (IOException ioe) { handleIOException(ioe); } } else if (paint instanceof RadialGradientPaint) { Pattern pattern = GradientMaker.makeRadialGradient((RadialGradientPaint) paint, new AffineTransform(), new AffineTransform()); try { gen.write(outputPattern(pattern)); } catch (IOException ioe) { handleIOException(ioe); } } }
From source file:RotateImage45Degrees.java
private AffineTransform findTranslation(AffineTransform at, BufferedImage bi) { Point2D p2din, p2dout;//from w ww .jav a 2 s. c o m p2din = new Point2D.Double(0.0, 0.0); p2dout = at.transform(p2din, null); double ytrans = p2dout.getY(); p2din = new Point2D.Double(0, bi.getHeight()); p2dout = at.transform(p2din, null); double xtrans = p2dout.getX(); AffineTransform tat = new AffineTransform(); tat.translate(-xtrans, -ytrans); return tat; }
From source file:org.jfree.graphics2d.demo.ImageTest.java
private static void drawArcTest(Graphics2D g2) { g2.setPaint(Color.GREEN);// www . j av a2 s .c om g2.drawRect(0, 20, 70, 50); g2.setPaint(Color.RED); Path2D path1 = new Path2D.Double(); double[] pts = calculateReferenceArc(90); path1.moveTo(pts[0], pts[1]); path1.curveTo(pts[2], pts[3], pts[4], pts[5], pts[6], pts[7]); AffineTransform t = new AffineTransform(); t.translate(35, 45); t.scale(35, 25); t.rotate(Math.PI / 4); path1.transform(t); g2.draw(path1); Path2D path2 = new Path2D.Double(); path2.moveTo(pts[0], pts[1]); path2.curveTo(pts[2], pts[3], pts[4], pts[5], pts[6], pts[7]); AffineTransform t2 = new AffineTransform(); t2.rotate(3 * Math.PI / 4); t2.scale(35, 25); t2.translate(35, 35); path2.transform(t2); //g2.draw(path2); Path2D arc = new Path2D.Double(); arc.append(path1, false); arc.append(path2, false); //g2.draw(arc); //g2.draw(path1); //g2.transform(t); g2.setPaint(Color.BLUE); g2.drawArc(0, 20, 70, 50, 0, -270); //Arc2D arc2d = new Arc2D.Double(0d, 20d, 70d, 50d, 0d, 90, Arc2D.OPEN); //g2.draw(arc2d); }