Java Swing UIManager paintFocus(Graphics2D g, Shape shape, int biggestStroke)

Here you can find the source of paintFocus(Graphics2D g, Shape shape, int biggestStroke)

Description

Paints 3 different strokes around a shape to indicate focus.

License

Open Source License

Parameter

Parameter Description
g the graphics to paint to
shape the shape to outline
biggestStroke the widest stroke to use.

Declaration

public static void paintFocus(Graphics2D g, Shape shape, int biggestStroke) 

Method Source Code


//package com.java2s;
/*/*from www . j  ava  2  s  .  com*/
Copyright 2008-2010 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
    
This file is part of Gephi.
    
Gephi is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
    
Gephi 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 Affero General Public License for more details.
    
You should have received a copy of the GNU Affero General Public License
along with Gephi.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.awt.BasicStroke;
import java.awt.Color;

import java.awt.Graphics2D;

import java.awt.Shape;

import javax.swing.UIManager;

public class Main {
    /** Paints 3 different strokes around a shape to indicate focus.
     * The widest stroke is the most transparent, so this achieves a nice
     * "glow" effect.
     * <P>The catch is that you have to render this underneath the shape,
     * and the shape should be filled completely.
     *
     * @param g the graphics to paint to
     * @param shape the shape to outline
     * @param biggestStroke the widest stroke to use.
     */
    public static void paintFocus(Graphics2D g, Shape shape, int biggestStroke) {
        Color focusColor = getFocusRingColor();
        Color[] focusArray = new Color[] {
                new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 255),
                new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 170),
                new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 110) };
        g.setStroke(new BasicStroke(biggestStroke));
        g.setColor(focusArray[2]);
        g.draw(shape);
        g.setStroke(new BasicStroke(biggestStroke - 1));
        g.setColor(focusArray[1]);
        g.draw(shape);
        g.setStroke(new BasicStroke(biggestStroke - 2));
        g.setColor(focusArray[0]);
        g.draw(shape);
        g.setStroke(new BasicStroke(1));
    }

    /** @return the color used to indicate when a component has
     * focus.  By default this uses the color (64,113,167), but you can
     * override this by calling:
     * <BR><code>UIManager.put("focusRing",customColor);</code>
     */
    public static Color getFocusRingColor() {
        Object obj = UIManager.getColor("focusRing");
        if (obj instanceof Color) {
            return (Color) obj;
        }
        return new Color(64, 113, 167);
    }
}

Related

  1. loadUIManager()
  2. makeNative()
  3. makeSplitpaneNice()
  4. makeToolbarNice()
  5. noAltBg()
  6. paintFocus(Graphics2D g, Shape shape, int biggestStroke)
  7. paintFocus(Graphics2D g, Shape shape, int biggestStroke)
  8. paintUnderlying(Graphics g, JComponent c)
  9. paintXpTabHeader(int type, Graphics g, int x, int y, int width)