Highlight.java :  » Math » migen » uk » ac » lkl » common » ui » jft » Java Open Source

Java Open Source » Math » migen 
migen » uk » ac » lkl » common » ui » jft » Highlight.java
///////////////////////////////////////////////////////////////////////////
//
//   Copyright 2010 Alberto Gonzlez Palomo
//   Author: Alberto Gonzlez Palomo - http://matracas.org/
//
//   This file is part of Java Feedback Toolkit, abbreviated as JFT.
//
//   JFT 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 3 of the License, or
//   (at your option) any later version.
//
//   JFT 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 JFT; if not, see <http://www.gnu.org/licenses/>.
//
/////////////////////////////////////////////////////////////////////////////

package uk.ac.lkl.common.ui.jft;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.Stroke;
import java.awt.geom.Area;

/**
 * Basic highlight style, a box around the target.
 */
public class Highlight
{
    protected Paint strokePaint;
    protected Stroke stroke;
    protected float strokeThickness;
    
    public Highlight()
    {
        setStroke(Color.RED, 4.0f);
    }
    
    /**
     * Set the stroke for border drawing.
     *
     * @param paint colour, texture, etc.
     * @param thickness floating-point number in pixels, e.g. 2.0f
     */
    public void setStroke(Paint paint, float thickness)
    {
        strokePaint = paint;
        strokeThickness = thickness;
        stroke = new BasicStroke(thickness,
                                 BasicStroke.CAP_BUTT,
                                 BasicStroke.JOIN_BEVEL);
    }
    
    /**
     * Paint the highlight around the given rectangle.
     *
     * @param bounds position and size for the region to be highlighted
     * @param g graphics context
     */
    public void paintAround(Rectangle bounds, Graphics2D g)
    {
        g.setPaint(strokePaint);
        g.setStroke(stroke);
        g.draw(stroke.createStrokedShape(new Area(bounds)));
    }
    
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.