List of usage examples for java.awt Rectangle getBounds2D
public Rectangle2D getBounds2D()
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Rectangle r = new Rectangle(100, 100, 200, 200); g2.fill(r);/*from w ww.j ava2s. co m*/ System.out.println(r.getBounds2D()); }
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). * //w ww . j a va 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(); }