Search in sources :

Example 96 with AffineTransform

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

the class EventIconRenderer method draw.

@Override
public void draw(Component parent, Graphics2D g2d, AffineTransform transform, double length) {
    Icon icon = UIUtil.isUnderDarcula() ? myDarkThemeIcon : myLightThemeIcon;
    AffineTransform originalTransform = g2d.getTransform();
    g2d.setTransform(transform);
    icon.paintIcon(parent, g2d, -myIconWidth / 2, 0);
    g2d.setTransform(originalTransform);
}
Also used : AffineTransform(java.awt.geom.AffineTransform)

Example 97 with AffineTransform

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

the class MockupViewPanel method paintMockup.

/**
   * Paint the mockup using the provided graphic context
   *
   * @param g2d the graphic context
   */
private void paintMockup(Graphics2D g2d) {
    if (myDisplayedImage == null) {
        return;
    }
    final AffineTransform tx = g2d.getTransform();
    int sw = getWidth();
    int sh = getHeight();
    int iw = myDisplayedImage.getWidth();
    int ih = myDisplayedImage.getHeight();
    float scale = (float) (myZoom * min(sw / (double) iw, sh / (double) ih));
    updateTransform(sw, sh, iw, ih, scale);
    if (!isValid()) {
        doLayout();
    }
    g2d.transform(myImageTransform);
    g2d.drawImage(myDisplayedImage, 0, 0, iw, ih, null);
    painScaled(g2d);
    g2d.setTransform(tx);
}
Also used : AffineTransform(java.awt.geom.AffineTransform)

Example 98 with AffineTransform

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

the class ImageUtils method createScaledImage.

/**
   * Create a scaled version of image with the same aspect ratio and with
   * the size of the longest edge equal to maxImageSize
   *
   * @param image        The image to create the scaled version from
   * @param maxImageSize The size of the longest edge of the scaled image
   * @return A new BufferedImage.
   */
@VisibleForTesting
public static BufferedImage createScaledImage(BufferedImage image, int maxImageSize) {
    int longestEdge = Math.max(image.getHeight(), image.getWidth());
    if (longestEdge < maxImageSize) {
        return image;
    }
    double scale = maxImageSize / (double) longestEdge;
    AffineTransform transform = new AffineTransform();
    transform.scale(scale, scale);
    int newWidth = (int) Math.round(image.getWidth() * scale);
    int newHeight = (int) Math.round(image.getHeight() * scale);
    BufferedImage newImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = newImage.createGraphics();
    g.drawImage(image, transform, null);
    return newImage;
}
Also used : AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 99 with AffineTransform

use of java.awt.geom.AffineTransform in project JMRI by JMRI.

the class PositionableShape method rotate.

@Override
public void rotate(int deg) {
    _degrees = deg % 360;
    if (_degrees == 0) {
        _transform = null;
    } else {
        double rad = Math.toRadians(_degrees);
        _transform = new AffineTransform();
        // use bit shift to avoid FindBugs paranoia
        _transform.setToRotation(rad, (_width >>> 1), (_height >>> 1));
    }
    updateSize();
}
Also used : AffineTransform(java.awt.geom.AffineTransform)

Example 100 with AffineTransform

use of java.awt.geom.AffineTransform in project JMRI by JMRI.

the class RpsTrackingPanel method paint.

@Override
public void paint(Graphics g) {
    // draw everything else
    super.paint(g);
    log.debug("paint invoked");
    // Now show regions
    // First, Graphics2D setup
    Graphics2D g2 = (Graphics2D) g;
    double xscale = this.getWidth() / (xmax - xorigin);
    double yscale = this.getHeight() / (ymax - yorigin);
    Stroke stroke = new BasicStroke((float) (2. / xscale), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    g2.setStroke(stroke);
    // Save the current transform
    AffineTransform saveAT = g2.getTransform();
    // Install the new one
    currentAT = new AffineTransform();
    currentAT.translate(0, this.getHeight());
    currentAT.scale(xscale, -yscale);
    // put origin in bottom corner
    currentAT.translate(-xorigin, -yorigin);
    g2.setTransform(currentAT);
    if (showRegions) {
        // Draw the regions
        List<Region> l = Model.instance().getRegions();
        for (int i = 0; i < l.size(); i++) {
            g2.setPaint(regionOutlineColor);
            // border (same color)
            g2.draw(l.get(i).getPath());
            g2.setPaint(regionFillColor);
            g2.fill(l.get(i).getPath());
        }
    }
    // Draw the measurements; changes graphics
    for (int i = 0; i < measurementRepList.size(); i++) {
        measurementRepList.get(i).draw(g2);
    }
    if (showReceivers) {
        // draw receivers
        for (int i = 1; i < Engine.instance().getMaxReceiverNumber() + 1; i++) {
            // indexed from 1
            Receiver r = Engine.instance().getReceiver(i);
            Point3d p = Engine.instance().getReceiverPosition(i);
            if (p != null && r != null) {
                if (r.isActive()) {
                    g2.setPaint(Color.BLACK);
                } else {
                    g2.setPaint(Color.GRAY);
                }
                Shape s = new Ellipse2D.Double(p.x - RECEIVER_SIZE / 2, p.y - RECEIVER_SIZE / 2, RECEIVER_SIZE, RECEIVER_SIZE);
                g2.draw(s);
                g2.fill(s);
            }
        }
    }
    // restore original transform
    g2.setTransform(saveAT);
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape) Point3d(javax.vecmath.Point3d) AffineTransform(java.awt.geom.AffineTransform) Region(jmri.jmrix.rps.Region) Receiver(jmri.jmrix.rps.Receiver) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Aggregations

AffineTransform (java.awt.geom.AffineTransform)335 BufferedImage (java.awt.image.BufferedImage)55 Graphics2D (java.awt.Graphics2D)43 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)42 Rectangle2D (java.awt.geom.Rectangle2D)38 Point2D (java.awt.geom.Point2D)26 Paint (java.awt.Paint)22 Font (java.awt.Font)21 Shape (java.awt.Shape)21 GcSnapshot (com.android.layoutlib.bridge.impl.GcSnapshot)20 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)17 PathIterator (java.awt.geom.PathIterator)16 ArrayList (java.util.ArrayList)16 FontRenderContext (java.awt.font.FontRenderContext)15 Color (java.awt.Color)14 Area (java.awt.geom.Area)14 GeneralPath (java.awt.geom.GeneralPath)14 Rectangle (java.awt.Rectangle)11 Path2D (java.awt.geom.Path2D)11 Test (org.junit.Test)11