Search in sources :

Example 86 with AffineTransform

use of java.awt.geom.AffineTransform in project hid-serial by rayshobby.

the class GAbstractControl method setRotation.

/**
	 * Set the rotation to apply when displaying this control. The center of 
	 * rotation is determined by the mode parameter parameter.
	 * 
	 * @param angle clockwise angle in radians
	 * @param mode PApplet.CORNER / CORNERS / CENTER
	 */
public void setRotation(float angle, GControlMode mode) {
    rotAngle = angle;
    AffineTransform aff = new AffineTransform();
    aff.setToRotation(angle);
    switch(mode) {
        case CORNER:
        case CORNERS:
            // Rotate about top corner
            temp[0] = halfWidth;
            temp[1] = halfHeight;
            aff.transform(temp, 0, temp, 0, 1);
            // - halfWidth;
            cx = (float) temp[0] + x;
            // - halfHeight;
            cy = (float) temp[1] + y;
            break;
        case CENTER:
        default:
            // Rotate about centre
            temp[0] = -halfWidth;
            temp[1] = -halfHeight;
            aff.transform(temp, 0, temp, 0, 1);
            x = cx + (float) temp[0];
            // should this be minus?? I don't think so
            y = cy + (float) temp[1];
            break;
    }
}
Also used : AffineTransform(java.awt.geom.AffineTransform)

Example 87 with AffineTransform

use of java.awt.geom.AffineTransform in project jgnash by ccavanaugh.

the class VerticalTextIcon method paintIcon.

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2 = (Graphics2D) g;
    RenderingHints oldHints = g2.getRenderingHints();
    Font oldFont = g.getFont();
    Color oldColor = g.getColor();
    AffineTransform oldTransform = g2.getTransform();
    if (fm == null) {
        fm = g.getFontMetrics(font);
    }
    g2.setRenderingHints(renderHints);
    g.setFont(font);
    g.setColor(Color.black);
    if (clockwise) {
        g2.translate(x + getIconWidth(), y);
        g2.rotate(Math.PI / 2);
    } else {
        g2.translate(x, y + getIconHeight());
        g2.rotate(-Math.PI / 2);
    }
    //g.drawString(text, 0, fm.getLeading() + fm.getAscent());
    g.drawString(text, 0, fm.getLeading() + fm.getAscent() - (fm.getDescent() / 2));
    g.setFont(oldFont);
    g.setColor(oldColor);
    g2.setTransform(oldTransform);
    g2.setRenderingHints(oldHints);
}
Also used : Color(java.awt.Color) AffineTransform(java.awt.geom.AffineTransform) RenderingHints(java.awt.RenderingHints) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D)

Example 88 with AffineTransform

use of java.awt.geom.AffineTransform in project ddf by codice.

the class GeoPdfParserImpl method getWktFromNeatLine.

/**
     * Parses a given NeatLine and Transformation matrix into a WKT String
     *
     * @param lgidict         - The PDF's LGIDict object
     * @param neatLineArray   - The NeatLine array of points for the PDF
     * @param toDoubleVisitor - A visitor that converts PDF Strings / Ints / Longs into doubles.
     * @return the generated WKT Lat/Lon set
     * @throws IOException
     */
private String getWktFromNeatLine(COSDictionary lgidict, COSArray neatLineArray, ICOSVisitor toDoubleVisitor) throws IOException {
    List<Double> neatline = new LinkedList<>();
    List<String> coordinateList = new LinkedList<>();
    String firstCoordinate = null;
    double[] points = new double[CTM_SIZE];
    for (int i = 0; i < CTM_SIZE; i++) {
        points[i] = (Double) lgidict.getObjectFromPath(CTM + "/[" + i + "]").accept(toDoubleVisitor);
    }
    AffineTransform affineTransform = new AffineTransform(points);
    for (int i = 0; i < neatLineArray.size(); i++) {
        neatline.add((Double) neatLineArray.get(i).accept(toDoubleVisitor));
    }
    for (int i = 0; i < neatline.size(); i += 2) {
        double x = neatline.get(i);
        double y = neatline.get(i + 1);
        Point2D p = new Point2D.Double(x, y);
        Point2D pprime = affineTransform.transform(p, null);
        String xySet = point2dToWkt(pprime);
        if (firstCoordinate == null) {
            firstCoordinate = xySet;
        }
        coordinateList.add(xySet);
    }
    coordinateList.add(firstCoordinate);
    String wktString = StringUtils.join(coordinateList, ", ");
    LOGGER.debug("{}", wktString);
    return wktString.toString();
}
Also used : Point2D(java.awt.geom.Point2D) AffineTransform(java.awt.geom.AffineTransform) COSString(org.apache.pdfbox.cos.COSString) LinkedList(java.util.LinkedList)

Example 89 with AffineTransform

use of java.awt.geom.AffineTransform in project jdk8u_jdk by JetBrains.

the class FontPanel method setFontParams.

public void setFontParams(String name, float size, int style, int transform) {
    boolean fontModified = false;
    if (!name.equals(fontName) || style != fontStyle)
        fontModified = true;
    fontName = name;
    fontSize = size;
    fontStyle = style;
    fontTransform = transform;
    /// Recreate the font as specified
    testFont = new Font(fontName, fontStyle, (int) fontSize);
    if ((float) ((int) fontSize) != fontSize) {
        testFont = testFont.deriveFont(fontSize);
    }
    if (fontTransform != NONE) {
        AffineTransform at = getAffineTransform(fontTransform);
        testFont = testFont.deriveFont(at);
    }
    updateBackBuffer = true;
    updateFontMetrics = true;
    fc.repaint();
    if (fontModified) {
        /// Tell main panel to update the font info
        updateFontInfo();
        f2dt.fireUpdateFontInfo();
    }
}
Also used : AffineTransform(java.awt.geom.AffineTransform) Font(java.awt.Font)

Example 90 with AffineTransform

use of java.awt.geom.AffineTransform in project jdk8u_jdk by JetBrains.

the class XCheckboxPeer method paintCheckbox.

// You'll note this looks suspiciously like paintBorder
public void paintCheckbox(Graphics g, int x, int y, int w, int h) {
    boolean useBufferedImage = false;
    BufferedImage buffer = null;
    Graphics2D g2 = null;
    int rx = x;
    int ry = y;
    if (!(g instanceof Graphics2D)) {
        // Fix for 5045936. While printing, g is an instance of
        //   sun.print.ProxyPrintGraphics which extends Graphics. So
        //   we use a separate buffered image and its graphics is
        //   always Graphics2D instance
        buffer = graphicsConfig.createCompatibleImage(w, h);
        g2 = buffer.createGraphics();
        useBufferedImage = true;
        rx = 0;
        ry = 0;
    } else {
        g2 = (Graphics2D) g;
    }
    try {
        drawMotif3DRect(g2, rx, ry, w - 1, h - 1, armed | selected);
        // then paint the check
        g2.setColor((armed | selected) ? selectColor : getPeerBackground());
        g2.fillRect(rx + 1, ry + 1, w - 2, h - 2);
        if (armed | selected) {
            //Paint the check
            // FIXME: is this the right color?
            g2.setColor(getPeerForeground());
            AffineTransform af = g2.getTransform();
            g2.setTransform(AffineTransform.getTranslateInstance(rx, ry));
            g2.fill(myCheckMark);
            g2.setTransform(af);
        }
    } finally {
        if (useBufferedImage) {
            g2.dispose();
        }
    }
    if (useBufferedImage) {
        g.drawImage(buffer, x, y, null);
    }
}
Also used : AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage)

Aggregations

AffineTransform (java.awt.geom.AffineTransform)370 BufferedImage (java.awt.image.BufferedImage)60 Graphics2D (java.awt.Graphics2D)54 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)42 Rectangle2D (java.awt.geom.Rectangle2D)40 Point2D (java.awt.geom.Point2D)28 Shape (java.awt.Shape)24 Font (java.awt.Font)23 Paint (java.awt.Paint)23 GcSnapshot (com.android.layoutlib.bridge.impl.GcSnapshot)20 ArrayList (java.util.ArrayList)18 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)17 Rectangle (java.awt.Rectangle)16 PathIterator (java.awt.geom.PathIterator)16 Color (java.awt.Color)15 Point (java.awt.Point)15 FontRenderContext (java.awt.font.FontRenderContext)15 Area (java.awt.geom.Area)14 GeneralPath (java.awt.geom.GeneralPath)14 AffineTransformOp (java.awt.image.AffineTransformOp)13