Search in sources :

Example 1 with AffineTransform

use of java.awt.geom.AffineTransform in project antlrworks by antlr.

the class XJRotableToggleButton method paint.

@Override
public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform tr = g2d.getTransform();
    switch(rotation) {
        case ROTATE_90:
            tr.rotate(Math.PI / 2);
            tr.translate(0, -computedHeight);
            g2d.setTransform(tr);
            break;
        case ROTATE_270:
            tr.rotate(-Math.PI / 2);
            tr.translate(-computedWidth, 0);
            g2d.setTransform(tr);
            break;
    }
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    drawAquaBackground(g2d);
    TextLayout layout = new TextLayout(title, g2d.getFont(), g2d.getFontRenderContext());
    Rectangle2D r = layout.getBounds();
    int offset = MARGIN_WIDTH;
    if (icon != null) {
        int voffset = (computedHeight - icon.getIconHeight()) / 2;
        g2d.drawImage(icon.getImage(), offset, voffset, null);
        offset += icon.getIconWidth();
        offset += SEPARATOR;
    } else {
        offset = (int) ((computedWidth - r.getWidth()) / 2);
    }
    int voffset = (int) ((computedHeight - r.getHeight()) / 2);
    g2d.setColor(Color.black);
    layout.draw(g2d, offset, computedHeight - voffset - layout.getDescent() / 2);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform) TextLayout(java.awt.font.TextLayout)

Example 2 with AffineTransform

use of java.awt.geom.AffineTransform in project WordCram by danbernier.

the class EngineWord method finalizeLocation.

void finalizeLocation() {
    AffineTransform transform = AffineTransform.getTranslateInstance(currentLocation.x, currentLocation.y);
    shape = transform.createTransformedShape(shape);
    bbTree.setLocation((int) currentLocation.x, (int) currentLocation.y);
    word.setRenderedPlace(currentLocation);
}
Also used : AffineTransform(java.awt.geom.AffineTransform)

Example 3 with AffineTransform

use of java.awt.geom.AffineTransform in project darkFunction-Editor by darkFunction.

the class AnimationCell method rebuild.

public void rebuild() {
    //System.out.println("Attempting to rebuild animation cell volatile image");
    Rectangle r = getSpreadRect();
    if (r.width <= 0 || r.height <= 0) {
        vImage = null;
        return;
    }
    do {
        vImage = ImageUtil.createVolatileImage(r.width, r.height, java.awt.Transparency.TRANSLUCENT);
        Graphics2D g = null;
        try {
            g = vImage.createGraphics();
            // clear to transparent
            g.setComposite(AlphaComposite.Clear);
            g.fillRect(0, 0, r.width, r.height);
            g.setComposite(AlphaComposite.SrcOver);
            //for (Enumeration<GraphicObject> e = graphicNodeDict.keys(); e.hasMoreElements();)
            for (int i = graphicOrderList.size() - 1; i >= 0; i--) {
                //GraphicObject graphic = e.nextElement();
                GraphicObject graphic = graphicOrderList.get(i);
                // backup selected state and remove... don't want to draw it selected in the cell
                boolean isSelected = graphic.isSelected();
                graphic.setSelected(false);
                Graphics2D g2d = (Graphics2D) g;
                AffineTransform transform = new AffineTransform(g2d.getTransform());
                AffineTransform oldTransform = g2d.getTransform();
                Rectangle gr = graphic.getRect();
                transform.rotate(Math.toRadians(graphic.getAngle()), -r.x + gr.x + gr.width / 2, -r.y + gr.y + gr.height / 2);
                g2d.setTransform(transform);
                graphic.draw(g2d, new Point(-r.x, -r.y), 1.0f, 1.0f, false);
                g2d.setTransform(oldTransform);
                // restore selected state
                graphic.setSelected(isSelected);
            }
        } finally {
            g.dispose();
        }
    } while (vImage.contentsLost());
}
Also used : Rectangle(java.awt.Rectangle) AffineTransform(java.awt.geom.AffineTransform) Point(java.awt.Point) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Example 4 with AffineTransform

use of java.awt.geom.AffineTransform in project Fling by entertailion.

the class DragHereIcon method paintIcon.

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.translate(x, y);
    g2.setStroke(new BasicStroke(a));
    g2.setPaint(linec);
    g2.draw(new RoundRectangle2D.Float(a, a, size - 2 * a - 1, size - 2 * a - 1, r, r));
    // draw bounding box
    g2.setStroke(new BasicStroke(b));
    g2.setColor(UIManager.getColor("Panel.background"));
    g2.drawLine(1 * f, 0 * f, 1 * f, 4 * f);
    g2.drawLine(2 * f, 0 * f, 2 * f, 4 * f);
    g2.drawLine(3 * f, 0 * f, 3 * f, 4 * f);
    g2.drawLine(0 * f, 1 * f, 4 * f, 1 * f);
    g2.drawLine(0 * f, 2 * f, 4 * f, 2 * f);
    g2.drawLine(0 * f, 3 * f, 4 * f, 3 * f);
    // draw arrow
    g2.setPaint(linec);
    Rectangle2D b = s.getBounds();
    Point2D.Double p = new Point2D.Double(b.getX() + b.getWidth() / 2d, b.getY() + b.getHeight() / 2d);
    AffineTransform toCenterAT = AffineTransform.getTranslateInstance(size / 2d - p.getX(), size / 2d - p.getY());
    g2.fill(toCenterAT.createTransformedShape(s));
    g2.translate(-x, -y);
    g2.dispose();
}
Also used : BasicStroke(java.awt.BasicStroke) Point2D(java.awt.geom.Point2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Rectangle2D(java.awt.geom.Rectangle2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D) AffineTransform(java.awt.geom.AffineTransform) Graphics2D(java.awt.Graphics2D)

Example 5 with AffineTransform

use of java.awt.geom.AffineTransform in project android_frameworks_base by ParanoidAndroid.

the class Paint_Delegate method updateFontObject.

/**
     * Update the {@link Font} object from the typeface, text size and scaling
     */
@SuppressWarnings("deprecation")
private void updateFontObject() {
    if (mTypeface != null) {
        // Get the fonts from the TypeFace object.
        List<Font> fonts = mTypeface.getFonts();
        // create new font objects as well as FontMetrics, based on the current text size
        // and skew info.
        ArrayList<FontInfo> infoList = new ArrayList<FontInfo>(fonts.size());
        for (Font font : fonts) {
            FontInfo info = new FontInfo();
            info.mFont = font.deriveFont(mTextSize);
            if (mTextScaleX != 1.0 || mTextSkewX != 0) {
                // TODO: support skew
                info.mFont = info.mFont.deriveFont(new AffineTransform(mTextScaleX, mTextSkewX, 0, 1, 0, 0));
            }
            info.mMetrics = Toolkit.getDefaultToolkit().getFontMetrics(info.mFont);
            infoList.add(info);
        }
        mFonts = Collections.unmodifiableList(infoList);
    }
}
Also used : ArrayList(java.util.ArrayList) AffineTransform(java.awt.geom.AffineTransform) Font(java.awt.Font)

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