Search in sources :

Example 1 with Rectangle2D

use of java.awt.geom.Rectangle2D 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 Rectangle2D

use of java.awt.geom.Rectangle2D in project tomcat by apache.

the class DrawMessage method draw.

/**
     * Draws this DrawMessage onto the given Graphics2D.
     *
     * @param g The target for the DrawMessage
     */
public void draw(Graphics2D g) {
    g.setStroke(new BasicStroke((float) thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
    g.setColor(new Color(colorR & 0xFF, colorG & 0xFF, colorB & 0xFF, colorA & 0xFF));
    if (x1 == x2 && y1 == y2) {
        // Always draw as arc to meet the behavior in the HTML5 Canvas.
        Arc2D arc = new Arc2D.Double(x1, y1, 0, 0, 0d, 360d, Arc2D.OPEN);
        g.draw(arc);
    } else if (type == 1 || type == 2) {
        // Draw a line.
        Line2D line = new Line2D.Double(x1, y1, x2, y2);
        g.draw(line);
    } else if (type == 3 || type == 4) {
        double x1 = this.x1, x2 = this.x2, y1 = this.y1, y2 = this.y2;
        if (x1 > x2) {
            x1 = this.x2;
            x2 = this.x1;
        }
        if (y1 > y2) {
            y1 = this.y2;
            y2 = this.y1;
        }
        if (type == 3) {
            // Draw a rectangle.
            Rectangle2D rect = new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1);
            g.draw(rect);
        } else if (type == 4) {
            // Draw an ellipse.
            Arc2D arc = new Arc2D.Double(x1, y1, x2 - x1, y2 - y1, 0d, 360d, Arc2D.OPEN);
            g.draw(arc);
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) Arc2D(java.awt.geom.Arc2D) Line2D(java.awt.geom.Line2D)

Example 3 with Rectangle2D

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

the class PlacerHeatMap method draw.

public void draw(PApplet sketch) {
    RectStack rectStack = new RectStack();
    for (int i = 0; i < words.length; i++) {
        Word word = words[i];
        PFont wordFont = word.getFont(fonter);
        float wordSize = word.getSize(sizer, i, words.length);
        float wordAngle = word.getAngle(angler);
        Shape shape = shaper.getShapeFor(word.word, wordFont, wordSize, wordAngle);
        Rectangle2D rect = shape.getBounds2D();
        //return r.getHeight() < minShapeSize || r.getWidth() < minShapeSize;
        int wordImageWidth = (int) rect.getWidth();
        int wordImageHeight = (int) rect.getHeight();
        PVector desiredLocation = word.getTargetPlace(placer, i, words.length, wordImageWidth, wordImageHeight, sketch.width, sketch.height);
        //sketch.rect(desiredLocation.x, desiredLocation.y, wordImageWidth, wordImageHeight);
        rectStack.add((int) desiredLocation.x, (int) desiredLocation.y, wordImageWidth, wordImageHeight);
    }
    RectGrid grid = new RectGrid(rectStack);
    grid.draw(sketch);
}
Also used : PVector(processing.core.PVector) Shape(java.awt.Shape) PFont(processing.core.PFont) Rectangle2D(java.awt.geom.Rectangle2D)

Example 4 with Rectangle2D

use of java.awt.geom.Rectangle2D 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 Rectangle2D

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

the class Paint_Delegate method nativeGetCharArrayBounds.

@LayoutlibDelegate
static /*package*/
void nativeGetCharArrayBounds(int nativePaint, char[] text, int index, int count, int bidiFlags, Rect bounds) {
    // get the delegate from the native int.
    Paint_Delegate delegate = sManager.getDelegate(nativePaint);
    if (delegate == null) {
        return;
    }
    // See MeasureText
    if (delegate.mFonts.size() > 0) {
        FontInfo mainInfo = delegate.mFonts.get(0);
        Rectangle2D rect = mainInfo.mFont.getStringBounds(text, index, index + count, delegate.mFontContext);
        bounds.set(0, 0, (int) rect.getWidth(), (int) rect.getHeight());
    }
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Aggregations

Rectangle2D (java.awt.geom.Rectangle2D)211 AffineTransform (java.awt.geom.AffineTransform)33 Graphics2D (java.awt.Graphics2D)24 Point2D (java.awt.geom.Point2D)24 BufferedImage (java.awt.image.BufferedImage)20 FontMetrics (java.awt.FontMetrics)19 RoundRectangle2D (java.awt.geom.RoundRectangle2D)17 Color (java.awt.Color)16 Dimension (java.awt.Dimension)15 Font (java.awt.Font)14 FontRenderContext (java.awt.font.FontRenderContext)13 Paint (java.awt.Paint)12 Rectangle (java.awt.Rectangle)9 GradientPaint (java.awt.GradientPaint)8 ArrayList (java.util.ArrayList)8 Shape (java.awt.Shape)7 TextLayout (java.awt.font.TextLayout)7 GeneralPath (java.awt.geom.GeneralPath)6 Line2D (java.awt.geom.Line2D)6 Test (org.junit.Test)6