Here you can find the source of paintRectShadow(Graphics g, int x, int y, int width, int height)
Parameter | Description |
---|---|
g | a <code>Graphics</code> value |
public static void paintRectShadow(Graphics g, int x, int y, int width, int height)
//package com.java2s; /*// w ww . j a v a2 s .com * Copyright 2007 skynamics AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import java.awt.Shape; import java.awt.geom.Area; import java.awt.geom.RoundRectangle2D; public class Main { /** The default radius in the Sky LookAndFeel package */ public static final int RADIUS = 4; /** Shadow color */ private static final Color SHADOWCOLOR = new Color(0, 0, 0, 20); /** * Draw a shadow shaped as a Rectangle with smooth edges with a depth of 5 if possible. * * @param g a <code>Graphics</code> value * @nowarn */ public static void paintRectShadow(Graphics g, int x, int y, int width, int height) { paintRectShadow(g, x, y, width, height, 5); } /** * Draw a shadow shaped as a Rectangle with smooth edges and a depth of shadowsteps if possible. * * @param g a <code>Graphics</code> value * @param shadowsteps an <code>int</code> value * @nowarn */ public static void paintRectShadow(Graphics g, int x, int y, int width, int height, int shadowsteps) { Shape clip = g.getClip(); int smooth = (int) Math.min((double) width, (double) height) / 2; if (smooth > shadowsteps) smooth = shadowsteps; // calculate clip for shadow Area area = new Area(new RoundRectangle2D.Double(x, y, width, height, RADIUS, RADIUS)); area.subtract(new Area(new Rectangle(x, y, width - smooth, height - smooth))); // Be sure we don't paint in a foreign area. area.intersect(new Area(clip.getBounds())); g.setClip(area); g.setColor(SHADOWCOLOR); for (int i = 0; i < smooth; i++) { g.fillRoundRect(x + i, y + i, (width - (2 * i)), (height - (2 * i)), (RADIUS - i < 0) ? 0 : RADIUS - i, (RADIUS - i < 0) ? 0 : RADIUS - i); } // set old clip g.setClip(clip); } }