Search in sources :

Example 6 with Graphics2D

use of java.awt.Graphics2D in project groovy by apache.

the class JCaricature method paintComponent.

protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (empty) {
        return;
    }
    Graphics2D g2 = (Graphics2D) g.create();
    Image image = getImage("face", getFaceStyle());
    int iw = image.getWidth(null);
    int ih = image.getHeight(null);
    //        g2.translate(iw / 2, ih / 2);
    g2.translate(getWidth() / 2, getHeight() / 2);
    if (iw != getWidth()) {
        float forcedScale = (float) getWidth() / (float) iw;
        g2.scale(forcedScale, forcedScale);
    }
    float scale = getScale();
    if (scale != 1) {
        g2.scale((double) scale, (double) scale);
    }
    int rotation = getRotation();
    if (rotation != 0) {
        g2.rotate(Math.toRadians(rotation));
    }
    drawImage(g2, "face", getFaceStyle());
    drawImage(g2, "hair", getHairStyle());
    drawImage(g2, "eyes", getEyeStyle());
    drawImage(g2, "nose", getNoseStyle());
    drawImage(g2, "mouth", getMouthStyle());
    g2.dispose();
}
Also used : Image(java.awt.Image) Graphics2D(java.awt.Graphics2D)

Example 7 with Graphics2D

use of java.awt.Graphics2D in project screenbird by adamhub.

the class ResizeHandle method paint.

@Override
public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) this.getGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(Color.white);
    g2d.fillOval(0, 0, this.getWidth() - 1, this.getHeight() - 1);
    g2d.setColor(STROKE_COLOR);
    g2d.drawOval(0, 0, this.getWidth() - 1, this.getHeight() - 1);
}
Also used : Graphics2D(java.awt.Graphics2D)

Example 8 with Graphics2D

use of java.awt.Graphics2D in project screenbird by adamhub.

the class JRoundBorderSB method paintBorder.

@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int r = height - 1;
    RoundRectangle2D round = new RoundRectangle2D.Float(x, y, width - 1, height - 1, r, r);
    Container parent = c.getParent();
    if (parent != null) {
        g2.setColor(parent.getBackground());
        Area corner = new Area(new Rectangle2D.Float(x, y, width, height));
        corner.subtract(new Area(round));
        g2.fill(corner);
    }
    g2.setColor(Color.lightGray);
    g2.draw(round);
    g2.dispose();
}
Also used : Container(java.awt.Container) Area(java.awt.geom.Area) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Rectangle2D(java.awt.geom.Rectangle2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Graphics2D(java.awt.Graphics2D)

Example 9 with Graphics2D

use of java.awt.Graphics2D in project screenbird by adamhub.

the class JRoundedPanel method paintComponent.

//    public JRoundedPanel(CardLayout cardLayout) {
//        super(cardLayout);
//        setOpaque(false);
//        Color backgrnd = new Color(Color.darkGray.getRed(),Color.darkGray.getGreen(), Color.darkGray.getBlue(),180);
//        this.setBackground(backgrnd);
//    }
@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    int width = getWidth();
    int height = getHeight();
    int shadowGap = this.shadowGap;
    Color shadowColorA = new Color(shadowColor.getRed(), shadowColor.getGreen(), shadowColor.getBlue(), shadowAlpha);
    Graphics2D graphics = (Graphics2D) g;
    //Sets antialiasing if HQ.
    if (highQuality) {
        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }
    //Draws shadow borders if any.
    if (shady) {
        graphics.setColor(shadowColorA);
        graphics.fillRoundRect(// X position
        shadowOffset, // Y position
        shadowOffset, // width
        width - strokeSize - shadowOffset, // height
        height - strokeSize - shadowOffset, arcs.width, // arc Dimension
        arcs.height);
    } else {
        shadowGap = 1;
    }
    //Draws the rounded opaque panel with borders.
    graphics.setColor(getBackground());
    graphics.fillRoundRect(0, 0, width - shadowGap, height - shadowGap, arcs.width, arcs.height);
    graphics.setColor(getForeground());
    //graphics.setStroke(new BasicStroke(strokeSize));
    //graphics.drawRoundRect(0, 0, width - shadowGap, height - shadowGap, arcs.width, arcs.height);
    //Sets strokes to default, is better.
    graphics.setStroke(new BasicStroke());
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) Graphics2D(java.awt.Graphics2D)

Example 10 with Graphics2D

use of java.awt.Graphics2D in project android_frameworks_base by ParanoidAndroid.

the class NinePatch_Delegate method draw.

// ---- Private Helper methods ----
private static void draw(int canvas_instance, final int left, final int top, final int right, final int bottom, int bitmap_instance, byte[] c, int paint_instance_or_null, final int destDensity, final int srcDensity) {
    // get the delegate from the native int.
    final Bitmap_Delegate bitmap_delegate = Bitmap_Delegate.getDelegate(bitmap_instance);
    if (bitmap_delegate == null) {
        return;
    }
    if (c == null) {
        // not a 9-patch?
        BufferedImage image = bitmap_delegate.getImage();
        Canvas_Delegate.native_drawBitmap(canvas_instance, bitmap_instance, new Rect(0, 0, image.getWidth(), image.getHeight()), new Rect(left, top, right, bottom), paint_instance_or_null, destDensity, srcDensity);
        return;
    }
    final NinePatchChunk chunkObject = getChunk(c);
    assert chunkObject != null;
    if (chunkObject == null) {
        return;
    }
    Canvas_Delegate canvas_delegate = Canvas_Delegate.getDelegate(canvas_instance);
    if (canvas_delegate == null) {
        return;
    }
    // this one can be null
    Paint_Delegate paint_delegate = Paint_Delegate.getDelegate(paint_instance_or_null);
    canvas_delegate.getSnapshot().draw(new GcSnapshot.Drawable() {

        @Override
        public void draw(Graphics2D graphics, Paint_Delegate paint) {
            chunkObject.draw(bitmap_delegate.getImage(), graphics, left, top, right - left, bottom - top, destDensity, srcDensity);
        }
    }, paint_delegate, true, /*compositeOnly*/
    false);
}
Also used : GcSnapshot(com.android.layoutlib.bridge.impl.GcSnapshot) NinePatchChunk(com.android.ninepatch.NinePatchChunk) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Aggregations

Graphics2D (java.awt.Graphics2D)1716 BufferedImage (java.awt.image.BufferedImage)809 Color (java.awt.Color)394 BasicStroke (java.awt.BasicStroke)186 Font (java.awt.Font)161 Point (java.awt.Point)145 AffineTransform (java.awt.geom.AffineTransform)140 Rectangle (java.awt.Rectangle)139 IOException (java.io.IOException)112 Rectangle2D (java.awt.geom.Rectangle2D)100 Dimension (java.awt.Dimension)92 Image (java.awt.Image)91 GradientPaint (java.awt.GradientPaint)90 FontMetrics (java.awt.FontMetrics)87 Paint (java.awt.Paint)82 Graphics (java.awt.Graphics)79 File (java.io.File)65 Point2D (java.awt.geom.Point2D)59 Stroke (java.awt.Stroke)55 ImageIcon (javax.swing.ImageIcon)50