Search in sources :

Example 91 with Rectangle2D

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

the class SunGraphics2D method transformShape.

protected static Shape transformShape(AffineTransform tx, Shape clip) {
    if (clip == null) {
        return null;
    }
    if (clip instanceof Rectangle2D && (tx.getType() & NON_RECTILINEAR_TRANSFORM_MASK) == 0) {
        Rectangle2D rect = (Rectangle2D) clip;
        double[] matrix = new double[4];
        matrix[0] = rect.getX();
        matrix[1] = rect.getY();
        matrix[2] = matrix[0] + rect.getWidth();
        matrix[3] = matrix[1] + rect.getHeight();
        tx.transform(matrix, 0, matrix, 0, 2);
        fixRectangleOrientation(matrix, rect);
        return new Rectangle2D.Double(matrix[0], matrix[1], matrix[2] - matrix[0], matrix[3] - matrix[1]);
    }
    if (tx.isIdentity()) {
        return cloneShape(clip);
    }
    return tx.createTransformedShape(clip);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D)

Example 92 with Rectangle2D

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

the class SunGraphics2D method transformShape.

protected static Shape transformShape(int tx, int ty, Shape s) {
    if (s == null) {
        return null;
    }
    if (s instanceof Rectangle) {
        Rectangle r = s.getBounds();
        r.translate(tx, ty);
        return r;
    }
    if (s instanceof Rectangle2D) {
        Rectangle2D rect = (Rectangle2D) s;
        return new Rectangle2D.Double(rect.getX() + tx, rect.getY() + ty, rect.getWidth(), rect.getHeight());
    }
    if (tx == 0 && ty == 0) {
        return cloneShape(s);
    }
    AffineTransform mat = AffineTransform.getTranslateInstance(tx, ty);
    return mat.createTransformedShape(s);
}
Also used : Rectangle(java.awt.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform)

Example 93 with Rectangle2D

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

the class TextLine method getCharBounds.

public Rectangle2D getCharBounds(int logicalIndex) {
    if (logicalIndex < 0) {
        throw new IllegalArgumentException("Negative logicalIndex.");
    }
    int tlcStart = 0;
    for (int i = 0; i < fComponents.length; i++) {
        int tlcLimit = tlcStart + fComponents[i].getNumCharacters();
        if (tlcLimit > logicalIndex) {
            TextLineComponent tlc = fComponents[i];
            int indexInTlc = logicalIndex - tlcStart;
            Rectangle2D chBounds = tlc.getCharVisualBounds(indexInTlc);
            int vi = getComponentVisualIndex(i);
            chBounds.setRect(chBounds.getX() + locs[vi * 2], chBounds.getY() + locs[vi * 2 + 1], chBounds.getWidth(), chBounds.getHeight());
            return chBounds;
        } else {
            tlcStart = tlcLimit;
        }
    }
    throw new IllegalArgumentException("logicalIndex too large.");
}
Also used : TextLineComponent(sun.font.TextLineComponent) Rectangle2D(java.awt.geom.Rectangle2D)

Example 94 with Rectangle2D

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

the class TextLine method getItalicBounds.

public Rectangle2D getItalicBounds() {
    float left = Float.MAX_VALUE, right = -Float.MAX_VALUE;
    float top = Float.MAX_VALUE, bottom = -Float.MAX_VALUE;
    for (int i = 0, n = 0; i < fComponents.length; i++, n += 2) {
        TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];
        Rectangle2D tlcBounds = tlc.getItalicBounds();
        float x = locs[n];
        float y = locs[n + 1];
        left = Math.min(left, x + (float) tlcBounds.getX());
        right = Math.max(right, x + (float) tlcBounds.getMaxX());
        top = Math.min(top, y + (float) tlcBounds.getY());
        bottom = Math.max(bottom, y + (float) tlcBounds.getMaxY());
    }
    return new Rectangle2D.Float(left, top, right - left, bottom - top);
}
Also used : TextLineComponent(sun.font.TextLineComponent) Rectangle2D(java.awt.geom.Rectangle2D)

Example 95 with Rectangle2D

use of java.awt.geom.Rectangle2D in project processdash by dtuma.

the class ReportsAndToolsIcon method paintLargeIconImpl.

private void paintLargeIconImpl(Graphics2D g2, int pw, int ph) {
    // draw a white page with a black outline.
    int pageHeight = ph - 1;
    int pageWidth = ph * 9 / 11;
    g2.setColor(Color.white);
    g2.fillRect(0, 0, pageWidth, pageHeight);
    g2.setColor(Color.gray);
    g2.drawRect(0, 0, pageWidth, pageHeight);
    // draw text onto the page
    int pad = 1 + ph / 20;
    float lineSpacing = Math.max(2, ph / 14);
    float fontSize = 0.85f * lineSpacing;
    float y = pad + lineSpacing;
    g2.setClip(pad + 1, pad, pageWidth - 2 * pad, pageHeight - 2 * pad);
    g2.setFont(new Font("Dialog", Font.PLAIN, 10).deriveFont(fontSize));
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.setColor(Color.darkGray);
    String s = TEXT;
    while (y <= ph) {
        g2.drawString(s, pad + 1, y);
        s = s.substring(20);
        if (s.charAt(0) == ' ')
            s = s.substring(1);
        y += lineSpacing;
    }
    // calculate the geometry for the chart in the lower-left corner
    int barWidth = pageWidth / 5;
    int chartHeight = (int) (pageHeight * 0.4);
    int chartTop = pageHeight - pad - chartHeight;
    Rectangle2D[] bars = new Rectangle2D[BAR_DELTA.length];
    for (int i = bars.length; i-- > 0; ) {
        float barGap = chartHeight * BAR_DELTA[i];
        bars[i] = new Rectangle2D.Float(pad + 1 + barWidth * i, chartTop + barGap, barWidth, chartHeight);
    }
    // draw white areas to ensure the text doesn't run into the bars
    g2.setColor(Color.white);
    g2.setStroke(new BasicStroke(Math.max(3, 1 + pad * 1.2f)));
    for (int i = bars.length; i-- > 0; ) g2.draw(bars[i]);
    // draw the bars themselves
    for (int i = bars.length; i-- > 0; ) {
        Color light = PaintUtils.mixColors(BAR_COLORS[i], Color.white, 0.7);
        g2.setPaint(new GradientPaint((int) bars[i].getX(), 0, BAR_COLORS[i], (int) bars[i].getMaxX(), 0, light));
        g2.fill(bars[i]);
    }
    // draw the calculator
    ImageIcon calc = loadImage("calc.png");
    int calcHeight = ph * 2 / 3;
    float calcScale = calcHeight / (float) calc.getIconHeight();
    int calcWidth = (int) (0.5 + calc.getIconWidth() * calcScale);
    int calcLeft = (int) (pageWidth - pad * 2 / 3);
    int calcTop = ph / 4;
    Image scaledCalc = new ImageIcon(//
    calc.getImage().getScaledInstance(calcWidth, calcHeight, Image.SCALE_SMOOTH)).getImage();
    g2.setClip(null);
    g2.drawImage(scaledCalc, calcLeft, calcTop, null);
}
Also used : BasicStroke(java.awt.BasicStroke) ImageIcon(javax.swing.ImageIcon) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) GradientPaint(java.awt.GradientPaint) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) GradientPaint(java.awt.GradientPaint) Font(java.awt.Font)

Aggregations

Rectangle2D (java.awt.geom.Rectangle2D)262 Graphics2D (java.awt.Graphics2D)42 AffineTransform (java.awt.geom.AffineTransform)34 Color (java.awt.Color)33 Paint (java.awt.Paint)28 Point2D (java.awt.geom.Point2D)26 BufferedImage (java.awt.image.BufferedImage)23 Font (java.awt.Font)21 FontMetrics (java.awt.FontMetrics)20 Dimension (java.awt.Dimension)19 RoundRectangle2D (java.awt.geom.RoundRectangle2D)18 Rectangle (java.awt.Rectangle)16 FontRenderContext (java.awt.font.FontRenderContext)15 Point (java.awt.Point)11 BasicStroke (java.awt.BasicStroke)10 ArrayList (java.util.ArrayList)10 GradientPaint (java.awt.GradientPaint)9 TextLayout (java.awt.font.TextLayout)9 RadialGradientPaint (java.awt.RadialGradientPaint)8 Shape (java.awt.Shape)7