Example usage for java.awt Stroke createStrokedShape

List of usage examples for java.awt Stroke createStrokedShape

Introduction

In this page you can find the example usage for java.awt Stroke createStrokedShape.

Prototype

Shape createStrokedShape(Shape p);

Source Link

Document

Returns an outline Shape which encloses the area that should be painted when the Shape is stroked according to the rules defined by the object implementing the Stroke interface.

Usage

From source file:org.jfree.experimental.swt.SWTGraphics2D.java

/**
 * Returns <code>true</code> if the rectangle (in device space) intersects
 * with the shape (the interior, if <code>onStroke</code> is false, 
 * otherwise the stroked outline of the shape).
 * //from  ww w  .j av a  2 s. c  o m
 * @param rect  a rectangle (in device space).
 * @param s the shape.
 * @param onStroke  test the stroked outline only?
 * 
 * @return A boolean. 
 */
@Override
public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
    AffineTransform transform = getTransform();
    Shape ts;
    if (onStroke) {
        Stroke stroke = getStroke();
        ts = transform.createTransformedShape(stroke.createStrokedShape(s));
    } else {
        ts = transform.createTransformedShape(s);
    }
    if (!rect.getBounds2D().intersects(ts.getBounds2D())) {
        return false;
    }
    Area a1 = new Area(rect);
    Area a2 = new Area(ts);
    a1.intersect(a2);
    return !a1.isEmpty();
}