Java Draw Shadow drawShadowedShape(Shape shape, Graphics2D g2d)

Here you can find the source of drawShadowedShape(Shape shape, Graphics2D g2d)

Description

draw Shadowed Shape

License

Open Source License

Parameter

Parameter Description
shape the shape to be drawn
g2d the drawing context

Declaration

public static void drawShadowedShape(Shape shape, Graphics2D g2d) 

Method Source Code


//package com.java2s;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;

import java.awt.Shape;

import java.awt.geom.AffineTransform;

public class Main {
    /**//from www .  j av  a2 s .c  o m
     * @param   shape   the shape to be drawn
     * @param   g2d   the drawing context
     */
    public static void drawShadowedShape(Shape shape, Graphics2D g2d) {
        Color holdColor = g2d.getColor();
        g2d.setColor(Color.black);
        AffineTransform holdTransform = g2d.getTransform();
        // want the shadow to be one line width pixel offset
        float lineWidth = g2d.getStroke() instanceof BasicStroke ? ((BasicStroke) (g2d.getStroke())).getLineWidth()
                : 1.0f;
        //System.err.println("DrawingUtilities.drawShadowedShape(): lineWidth = "+lineWidth);
        g2d.translate(lineWidth, lineWidth);
        g2d.draw(shape);
        g2d.setColor(holdColor);
        g2d.setTransform(holdTransform);
        g2d.draw(shape);
    }
}

Related

  1. drawShadedLine(java.awt.Graphics2D g2, float x0, float y0, float x1, float y1, java.awt.Paint topLeftPaint, java.awt.Paint otherPaint, java.awt.Paint bottomRightPaint, java.awt.geom.GeneralPath buffer)
  2. drawShadow(Graphics2D g2d, Color topColor, float opacity, int shadowWidth, int cornerRadius, int x, int y, int width, int height)
  3. drawShadowedString(Graphics2D g2d, String label, Color textColor, Color shadowColor, int x, int y)
  4. drawShadowedString(String string, int x, int y, Graphics2D g2d)