Here you can find the source of paintBorderGlow(final Graphics2D g2, final Shape shape, final int glowWidth)
Parameter | Description |
---|---|
g2 | a parameter |
shape | a parameter |
glowWidth | a parameter |
public static void paintBorderGlow(final Graphics2D g2, final Shape shape, final int glowWidth)
//package com.java2s; /* Copyright (C) 2015, University of Kansas Center for Research * //from w w w . j a va 2 s.c o m * Specify Software Project, specify@ku.edu, Biodiversity Institute, * 1345 Jayhawk Boulevard, Lawrence, Kansas, 66045, USA * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics2D; import java.awt.Shape; public class Main { private static final Color clrGlowInnerHi = new Color(253, 239, 175, 148); private static final Color clrGlowInnerLo = new Color(255, 209, 0); private static final Color clrGlowOuterHi = new Color(253, 239, 175, 124); private static final Color clrGlowOuterLo = new Color(255, 179, 0); /** * @param g2 * @param shape * @param glowWidth */ public static void paintBorderGlow(final Graphics2D g2, final Shape shape, final int glowWidth) { int gw = glowWidth * 2; for (int i = gw; i >= 2; i -= 2) { float pct = (float) (gw - i) / (gw - 1); Color mixHi = getMixedColor(clrGlowInnerHi, pct, clrGlowOuterHi, 1.0f - pct); Color mixLo = getMixedColor(clrGlowInnerLo, pct, clrGlowOuterLo, 1.0f - pct); g2.setPaint(new GradientPaint(0.0f, 40 * 0.25f, mixHi, 0.0f, 40, mixLo)); g2.setColor(Color.WHITE); // See my "Java 2D Trickery: Soft Clipping" entry for more // on why we use SRC_ATOP here g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, pct)); g2.setStroke(new BasicStroke(i)); g2.draw(shape); } } /** * @param c1 * @param pct1 * @param c2 * @param pct2 * @return */ public static Color getMixedColor(Color c1, float pct1, Color c2, float pct2) { float[] clr1 = c1.getComponents(null); float[] clr2 = c2.getComponents(null); for (int i = 0; i < clr1.length; i++) { clr1[i] = (clr1[i] * pct1) + (clr2[i] * pct2); } return new Color(clr1[0], clr1[1], clr1[2], clr1[3]); } }