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);
}
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);
}
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;
}
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();
}
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);
}
Aggregations