Search in sources :

Example 6 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 7 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 8 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 9 with Rectangle2D

use of java.awt.geom.Rectangle2D in project android-selector-intellij-plugin by importre.

the class ColorIcon method paintIcon.

public void paintIcon(Component c, Graphics g, int x, int y) {
    JBColor color = getColor();
    if (color == null) {
        g.setColor(JBColor.WHITE);
        g.fillRect(1, 1, getIconWidth(), getIconHeight());
        g.setColor(JBColor.DARK_GRAY);
        if (g instanceof Graphics2D) {
            RenderingHints.Key key = RenderingHints.KEY_TEXT_ANTIALIASING;
            Object value = RenderingHints.VALUE_TEXT_ANTIALIAS_ON;
            ((Graphics2D) g).setRenderingHint(key, value);
        }
        String q = "?";
        FontMetrics fm = g.getFontMetrics();
        Rectangle2D r = fm.getStringBounds(q, g);
        x = (int) ((getIconWidth() - (int) r.getWidth()) * 0.7f);
        y = (getIconHeight() - (int) r.getHeight()) / 2 + fm.getAscent();
        g.drawString(q, x, y);
    } else {
        g.setColor(color);
        g.fillRect(1, 1, getIconWidth(), getIconHeight());
    }
    g.setColor(JBColor.DARK_GRAY);
    g.drawRect(1, 1, getIconWidth(), getIconHeight());
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) JBColor(com.intellij.ui.JBColor)

Example 10 with Rectangle2D

use of java.awt.geom.Rectangle2D in project openblocks by mikaelhg.

the class CBorderlessButton method paint.

/**
     * re paints this
     */
@Override
public void paint(Graphics g) {
    // Set up graphics and buffer
    //super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Set up first layer
    int buttonHeight = this.getHeight() - (INSET * 2);
    int buttonWidth = this.getWidth() - (INSET * 2);
    if (this.focus) {
        int arc = buttonHeight / 3;
        Color topColoring;
        Color bottomColoring;
        if (this.pressed || this.selected) {
            topColoring = this.selectedColor.darker();
            bottomColoring = CGraphite.blue;
        } else {
            topColoring = this.buttonColor;
            bottomColoring = this.buttonColor;
        }
        // Paint the first layer
        g2.setPaint(new GradientPaint(0, 0, topColoring, 0, buttonHeight, bottomColoring, false));
        g2.fillRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
        g2.setColor(Color.darkGray);
        g2.drawRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
        // set up paint data fields for second layer
        int highlightHeight = buttonHeight / 2 - HIGHLIGHT_INSET;
        int highlightWidth = buttonWidth - (HIGHLIGHT_INSET * 2) + 1;
        if (this.pressed || this.selected) {
            topColoring = Color.white;
            bottomColoring = this.selectedColor;
        } else {
            topColoring = Color.white;
            bottomColoring = Color.darkGray;
        }
        // Paint the second layer
        g2.setPaint(new GradientPaint(0, 0, topColoring, 0, buttonHeight, bottomColoring, false));
        g2.fillRoundRect(INSET + HIGHLIGHT_INSET, INSET + HIGHLIGHT_INSET + 1, highlightWidth, highlightHeight, arc, arc);
    }
    // Draw the text (if any)
    if (this.getText() != null) {
        g2.setColor(Color.white);
        Font font = g2.getFont().deriveFont((float) (((float) buttonHeight) * .5));
        g2.setFont(font);
        FontMetrics metrics = g2.getFontMetrics();
        Rectangle2D textBounds = metrics.getStringBounds(this.getText(), g2);
        float x = (float) ((this.getWidth() / 2) - (textBounds.getWidth() / 2));
        float y = (float) ((this.getHeight() / 2) + (textBounds.getHeight() / 2)) - metrics.getDescent();
        g2.drawString(this.getText(), x, y);
    }
}
Also used : FontMetrics(java.awt.FontMetrics) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) GradientPaint(java.awt.GradientPaint) GradientPaint(java.awt.GradientPaint) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D)

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