1 import java.awt.*;
2 import java.awt.geom.*;
3
4 /**
5
6 */
7 public class HouseShape extends SelectableShape
8 {
9 /**
10
11 @param x
12 @param y
13 @param width
14 */
15 public HouseShape(int x, int y, int width)
16 {
17 this.x = x;
18 this.y = y;
19 this.width = width;
20 }
21
22 public void draw(Graphics2D g2)
23 {
24 Rectangle2D.Double base
25 = new Rectangle2D.Double(x, y + width, width, width);
26
27 //
28 Point2D.Double r1
29 = new Point2D.Double(x, y + width);
30 //
31 Point2D.Double r2
32 = new Point2D.Double(x + width / 2, y);
33 //
34 Point2D.Double r3
35 = new Point2D.Double(x + width, y + width);
36
37 Line2D.Double roofLeft
38 = new Line2D.Double(r1, r2);
39 Line2D.Double roofRight
40 = new Line2D.Double(r2, r3);
41
42 g2.draw(base);
43 g2.draw(roofLeft);
44 g2.draw(roofRight);
45 }
46
47 public void drawSelection(Graphics2D g2)
48 {
49 Rectangle2D.Double base
50 = new Rectangle2D.Double(x, y + width, width, width);
51 g2.fill(base);
52 }
53
54 public boolean contains(Point2D p)
55 {
56 return x <= p.getX() && p.getX() <= x + width
57 && y <= p.getY() && p.getY() <= y + 2 * width;
58 }
59
60 public void translate(int dx, int dy)
61 {
62 x += dx;
63 y += dy;
64 }
65
66 private int x;
67 private int y;
68 private int width;
69 }