Here you can find the source of paint3DRectEffect(Graphics graphics, int x, int y, int width, int height)
Parameter | Description |
---|---|
graphics | a <code>Graphics</code> value |
public static void paint3DRectEffect(Graphics graphics, int x, int y, int width, int height)
//package com.java2s; /*/*from ww w .java 2 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.Graphics2D; public class Main { /** Maximum shadow alpha channel value */ private static final double MAXSHADOWALPHA = 100d; /** Maximum light alpha channel value */ private static final double MAXLIGHTALPHA = 100d; /** Helper class for shadow smoothing */ private static Color[] shadowColorArray; /** Helper class for light smoothing */ private static Color[] lightColorArray; /** * Paint a 3D effect to a Rectangle * * @param graphics a <code>Graphics</code> value * @nowarn */ public static void paint3DRectEffect(Graphics graphics, int x, int y, int width, int height) { paint3DRectEffect(graphics, x, y, width, height, 5); } /** * Paint a 3D effect to a Rectangle. * * @param graphics a <code>Graphics</code> value * @param depth an <code>int</code> value * @nowarn */ public static void paint3DRectEffect(Graphics graphics, int x, int y, int width, int height, int depth) { if (shadowColorArray == null) createArrays(); if (!(graphics instanceof Graphics2D)) return; Graphics2D g = (Graphics2D) graphics; int smooth = (int) Math.min((double) width, (double) height) / 2; if (smooth > depth) smooth = depth; for (int i = 0; i < smooth; i++) { g.setColor(shadowColorArray[(int) (MAXSHADOWALPHA / smooth * (smooth - i)) - 1]); //south of the Rectangle g.drawLine(x + i + 1, y + height - i, x + width - i - 1, y + height - i); // area in th east of the Rectangle g.drawLine(x + width - i, y + i, x + width - i, y + height - i); g.setColor(lightColorArray[(int) (MAXLIGHTALPHA / smooth * i)]); // area in the north of the Rectangle g.drawLine(x + i + 1, y + i, x + width - i - 1, y + i); //area in the west of the Rectangle g.drawLine(x + i, y + i, x + i, y + height - i); } } private static void createArrays() { shadowColorArray = new Color[100]; lightColorArray = new Color[100]; for (int i = 0; i < 100; i++) { shadowColorArray[i] = new Color(0, 0, 0, i); lightColorArray[i] = new Color(255, 255, 255, i); } } }