draw Shadowed Shape - Java 2D Graphics

Java examples for 2D Graphics:Shape

Description

draw Shadowed Shape

Demo Code

/* Copyright (c) 2001-2011, David A. Clunie DBA Pixelmed Publishing. All rights reserved. */
//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  w w  w  . j av a 2s  .  co  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 Tutorials