List of usage examples for java.awt.geom AffineTransform translate
public void translate(double tx, double ty)
From source file:org.jcurl.demo.tactics.sg.BroomPromptScenario.java
/** adjust position + rotation */ private static void syncBroomM2V(final Point2D b, final Affine scene) { if (b == null) return;/* ww w . j a va 2 s .co m*/ final AffineTransform t = scene.getAffine(); t.setToIdentity(); t.translate(b.getX(), b.getY()); MathVec.rotate(t, b.getX(), b.getY() - IceSize.FAR_HACK_2_TEE); MathVec.rotate(t, 0, 1); scene.setAffine(t); }
From source file:org.jcurl.demo.tactics.sg.BroomPromptScenario.java
public BroomPromptScenario() { // create the scene final boolean stickUp = false; final boolean bothSides = true; final int pieAngle = 150; final Color sp = Color.BLACK; final Color bgc = new Color(1, 1, 1, 0.5f); final Stroke fine = new BasicStroke(0.01f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); final Stroke bold = new BasicStroke(0.03f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER); // final Font fo = new Font("SansSerif", Font.BOLD, 1); final float halo = RockProps.DEFAULT.getRadius(); final float outer = 0.8f * RockProps.DEFAULT.getRadius(); stickLength = (stickUp ? 1 : -1) * 5 * outer; final float inner = 0.5F * outer; final SGGroup me = new SGGroup(); // the transparent background {/*from w w w . j a va 2 s .c o m*/ final SGShape bg = node(new Arc2D.Float(-halo, -halo, 2 * halo, 2 * halo, 0, 360, Arc2D.OPEN), null, null, scale0); bg.setFillPaint(bgc); bg.addMouseListener(new MoveHandler()); bg.setMouseBlocker(true); bg.setCursor(moveC); me.add(bg); } // the cross-hair and stick { final int off = 90; final int pieOff = 180; final int arrowLengthDegrees = 7; // colored pie: pie = node(new Arc2D.Float(-outer, -outer, 2 * outer, 2 * outer, off - pieOff, pieAngle, Arc2D.PIE), null, null, scale0); me.add(pie); // inner circle: me.add(node(new Arc2D.Float(-inner, -inner, 2 * inner, 2 * inner, off, pieOff + pieAngle, Arc2D.OPEN), fine, sp, scale50)); // outer circle: me.add(node(new Arc2D.Float(-outer, -outer, 2 * outer, 2 * outer, off, pieOff + pieAngle - (14 + arrowLengthDegrees), Arc2D.OPEN), fine, sp, scale50)); // Semantic zooming: me.add(node(new Arc2D.Float(-outer, -outer, 2 * // outer, 2 * outer, // off, pieOff + pieAngle, Arc2D.OPEN), fine, sp, -scale50)); final double ar = Math.PI * (off + pieAngle) / 180.0; // radius // if (pieAngle % 90 != 0) me.add(node(new Line2D.Double(0, 0, -outer * Math.cos(ar), outer * Math.sin(ar)), bold, sp, scale0)); // arrow: final float f = outer / 10; final SGShape s = node(IceShapes.createArrowHead(f, 3 * f, 0.5f * f), null, null, scale50); s.setFillPaint(sp); final double a = Math.PI * (off + pieAngle - arrowLengthDegrees) / 180.0; final AffineTransform a_ = new AffineTransform(); a_.translate(-outer * Math.cos(a), outer * Math.sin(a)); a_.rotate(Math.PI * (90 - (off + pieAngle) + 8 + arrowLengthDegrees) / 180.0); final Affine s_ = SGTransform.createAffine(a_, s); me.add(s_); } { // y-axis: me.add(node(new Line2D.Float(0, -Math.signum(stickLength) * halo, 0, stickLength), fine, sp, scale0)); // x-axis: me.add(node(new Line2D.Float(-halo, 0, halo, 0), fine, sp, scale0)); } { // slider sli = new SGShape(); sli.setShape(IceShapes.createSlider(0.4f * outer, bothSides)); // sli.setFillPaint(sp); sli.setDrawStroke(fine); sli.setDrawPaint(sp); sli.setMode(Mode.STROKE_FILL); sli.setAntialiasingHint(RenderingHints.VALUE_ANTIALIAS_ON); me.add(slider = SGTransform.createAffine(new AffineTransform(), sli)); slider.setCursor(moveC); slider.addMouseListener(new SpeedHandler()); slider.setMouseBlocker(true); } handle = SGTransform.createAffine(new AffineTransform(), me); scene = SGTransform.createAffine(new AffineTransform(), handle); scene.setVisible(false); }
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(); {//from www . j av a2s . co 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:org.jcurl.zui.piccolo.BroomPromptSimple.java
/** adjust position + rotation */ private void setBroom(final Point2D b) { if (b == null) return;/*from w ww . j a va 2 s . com*/ final AffineTransform t = getTransformReference(true); t.setToIdentity(); t.translate(b.getX(), b.getY()); MathVec.rotate(t, b.getX(), b.getY() - IceSize.FAR_HACK_2_TEE); MathVec.rotate(t, 0, 1); invalidateFullBounds(); invalidatePaint(); }
From source file:org.pentaho.di.core.gui.SwingDirectGC.java
public void setTransform(float translationX, float translationY, int shadowsize, float magnification) { AffineTransform transform = new AffineTransform(); transform.translate(translationX + shadowsize * magnification, translationY + shadowsize * magnification); transform.scale(magnification, magnification); gc.setTransform(transform);/*from w w w . j a va2 s .co m*/ }
From source file:org.pentaho.di.core.gui.SwingGC.java
public void setTransform(float translationX, float translationY, int shadowsize, float magnification) { // PDI-9953 - always use original GC's transform. AffineTransform transform = (AffineTransform) originalTransform.clone(); transform.translate(translationX + shadowsize * magnification, translationY + shadowsize * magnification); transform.scale(magnification, magnification); gc.setTransform(transform);/* ww w . j ava 2 s . com*/ }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
@Override public void drawString(final String s, final float x, float y) { if (s.length() == 0) { return;/*from w ww. ja v a2s.com*/ } setFillPaint(); setStrokePaint(); final AffineTransform at = getTransform(); final AffineTransform at2 = getTransform(); at2.translate(x, y); at2.concatenate(font.getTransform()); setTransform(at2); final AffineTransform inverse = this.normalizeMatrix(); final AffineTransform flipper = FLIP_TRANSFORM; inverse.concatenate(flipper); final double[] mx = new double[6]; inverse.getMatrix(mx); cb.beginText(); final float fontSize = font.getSize2D(); if (lastBaseFont == null) { final String fontName = font.getName(); final boolean bold = font.isBold(); final boolean italic = font.isItalic(); final BaseFontFontMetrics fontMetrics = metaData.getBaseFontFontMetrics(fontName, fontSize, bold, italic, null, metaData.isFeatureSupported(OutputProcessorFeature.EMBED_ALL_FONTS), false); final FontNativeContext nativeContext = fontMetrics.getNativeContext(); lastBaseFont = fontMetrics.getBaseFont(); cb.setFontAndSize(lastBaseFont, fontSize); if (fontMetrics.isTrueTypeFont() && bold && nativeContext.isNativeBold() == false) { final float strokeWidth = font.getSize2D() / 30.0f; // right from iText ... if (strokeWidth == 1) { cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL); } else { cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE); cb.setLineWidth(strokeWidth); } } else { cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL); } } else { cb.setFontAndSize(lastBaseFont, fontSize); } cb.setTextMatrix((float) mx[0], (float) mx[1], (float) mx[2], (float) mx[3], (float) mx[4], (float) mx[5]); double width = 0; if (fontSize > 0) { final float scale = 1000 / fontSize; final Font font = this.font.deriveFont(AffineTransform.getScaleInstance(scale, scale)); final Rectangle2D stringBounds = font.getStringBounds(s, getFontRenderContext()); width = stringBounds.getWidth() / scale; } if (s.length() > 1) { final float adv = ((float) width - lastBaseFont.getWidthPoint(s, fontSize)) / (s.length() - 1); cb.setCharacterSpacing(adv); } cb.showText(s); if (s.length() > 1) { cb.setCharacterSpacing(0); } cb.endText(); setTransform(at); if (underline) { // These two are supposed to be taken from the .AFM file // int UnderlinePosition = -100; final int UnderlineThickness = 50; // final double d = PdfGraphics2D.asPoints(UnderlineThickness, (int) fontSize); setStroke(new BasicStroke((float) d)); y = (float) ((y) + PdfGraphics2D.asPoints((UnderlineThickness), (int) fontSize)); final Line2D line = new Line2D.Double(x, y, (width + x), y); draw(line); } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
public boolean drawPdfImage(final com.lowagie.text.Image image, final Image img, AffineTransform xform, final ImageObserver obs) { if (img == null) { throw new NullPointerException("Image must not be null."); }/* w w w.j a v a 2 s . c om*/ if (image == null) { throw new NullPointerException("Image must not be null."); } if (xform == null) { xform = AffineTransform.getTranslateInstance(0, 0); } xform.translate(0, img.getHeight(obs)); xform.scale(img.getWidth(obs), img.getHeight(obs)); final AffineTransform inverse = this.normalizeMatrix(); final AffineTransform flipper = FLIP_TRANSFORM; inverse.concatenate(xform); inverse.concatenate(flipper); try { final double[] mx = new double[6]; inverse.getMatrix(mx); if (currentFillGState != 255) { PdfGState gs = fillGState[255]; if (gs == null) { gs = new PdfGState(); gs.setFillOpacity(1); fillGState[255] = gs; } cb.setGState(gs); } cb.addImage(image, (float) mx[0], (float) mx[1], (float) mx[2], (float) mx[3], (float) mx[4], (float) mx[5]); } catch (Exception ex) { PdfGraphics2D.logger.error("Failed to draw the image: ", ex); // throw new IllegalArgumentException("Failed to draw the image"); } finally { if (currentFillGState != 255) { final PdfGState gs = fillGState[currentFillGState]; cb.setGState(gs); } } return true; }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
private void setPaint(final boolean invert, final double xoffset, final double yoffset, final boolean fill) { if (paint instanceof Color) { final Color color = (Color) paint; final int alpha = color.getAlpha(); if (fill) { if (alpha != currentFillGState) { currentFillGState = alpha; PdfGState gs = fillGState[alpha]; if (gs == null) { gs = new PdfGState(); gs.setFillOpacity(alpha / 255.00f); fillGState[alpha] = gs; }// w ww. j a v a2 s . co m cb.setGState(gs); } cb.setColorFill(color); } else { if (alpha != currentStrokeGState) { currentStrokeGState = alpha; PdfGState gs = strokeGState[alpha]; if (gs == null) { gs = new PdfGState(); gs.setStrokeOpacity(alpha / 255.0f); strokeGState[alpha] = gs; } cb.setGState(gs); } cb.setColorStroke(color); } } else if (paint instanceof GradientPaint) { final GradientPaint gp = (GradientPaint) paint; final Point2D p1 = gp.getPoint1(); transform.transform(p1, p1); final Point2D p2 = gp.getPoint2(); transform.transform(p2, p2); final Color c1 = gp.getColor1(); final Color c2 = gp.getColor2(); final PdfShading shading = PdfShading.simpleAxial(cb.getPdfWriter(), (float) p1.getX(), normalizeY((float) p1.getY()), (float) p2.getX(), normalizeY((float) p2.getY()), c1, c2); final PdfShadingPattern pat = new PdfShadingPattern(shading); if (fill) { cb.setShadingFill(pat); } else { cb.setShadingStroke(pat); } } else if (paint instanceof TexturePaint) { try { final TexturePaint tp = (TexturePaint) paint; final BufferedImage img = tp.getImage(); final Rectangle2D rect = tp.getAnchorRect(); final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null); final PdfPatternPainter pattern = cb.createPattern(image.getWidth(), image.getHeight()); final AffineTransform inverse = this.normalizeMatrix(); inverse.translate(rect.getX(), rect.getY()); inverse.scale(rect.getWidth() / image.getWidth(), -rect.getHeight() / image.getHeight()); final double[] mx = new double[6]; inverse.getMatrix(mx); pattern.setPatternMatrix((float) mx[0], (float) mx[1], (float) mx[2], (float) mx[3], (float) mx[4], (float) mx[5]); image.setAbsolutePosition(0, 0); pattern.addImage(image); if (fill) { cb.setPatternFill(pattern); } else { cb.setPatternStroke(pattern); } } catch (Exception ex) { if (fill) { cb.setColorFill(Color.gray); } else { cb.setColorStroke(Color.gray); } } } else { try { int type = BufferedImage.TYPE_4BYTE_ABGR; if (paint.getTransparency() == Transparency.OPAQUE) { type = BufferedImage.TYPE_3BYTE_BGR; } final BufferedImage img = new BufferedImage((int) width, (int) height, type); final Graphics2D g = (Graphics2D) img.getGraphics(); g.transform(transform); final AffineTransform inv = transform.createInverse(); Shape fillRect = new Rectangle2D.Double(0, 0, img.getWidth(), img.getHeight()); fillRect = inv.createTransformedShape(fillRect); g.setPaint(paint); g.fill(fillRect); if (invert) { final AffineTransform tx = new AffineTransform(); tx.scale(1, -1); tx.translate(-xoffset, -yoffset); g.drawImage(img, tx, null); } g.dispose(); // g = null; final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null); final PdfPatternPainter pattern = cb.createPattern(width, height); image.setAbsolutePosition(0, 0); pattern.addImage(image); if (fill) { cb.setPatternFill(pattern); } else { cb.setPatternStroke(pattern); } } catch (Exception ex) { if (fill) { cb.setColorFill(Color.gray); } else { cb.setColorStroke(Color.gray); } } } }
From source file:org.squidy.nodes.ScreenDispatcher.java
/** * @param image/* ww w. j a v a2 s. c o m*/ * @param width * @param height * @return */ private BufferedImage scaleImageTo(BufferedImage image, int width, int height) { int imageWidth = image.getWidth(null); int imageHeight = image.getHeight(null); double scaleX = (double) width / imageWidth; double scaleY = (double) height / imageHeight; if (flipScreen) { scaleX = (double) width / imageHeight; scaleY = (double) height / imageWidth; } AffineTransform at = AffineTransform.getScaleInstance(scaleX, scaleY); if (flipScreen) { at.rotate(Math.PI / 2); at.translate(0, -imageHeight); } BufferedImage scaledImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = scaledImage.createGraphics(); g2d.drawImage(image, at, null); g2d.dispose(); return scaledImage; }