3 import java
.awt
.Graphics2D
;
7 public class CanvasLine
extends CanvasObject
implements Cloneable
{
10 public final int NEAR
= 6;
13 public CanvasLine(Point start
, Point end
)
20 public void setEnd(Point end
)
25 public Point
getStart()
30 public Point
getEffectiveEnd()
32 Point effectiveEnd
= new Point(0, 0);
34 effectiveEnd
.x
= end
.x
+ getTranslatory().x
;
35 effectiveEnd
.y
= end
.y
+ getTranslatory().y
;
45 public void setColor(Color color
)
50 public Color
getColor()
55 public void setTipo(int i
) {
56 throw new UnsupportedOperationException("Not yet implemented");
59 public void setWidth(float parseFloat
) {
60 throw new UnsupportedOperationException("Not yet implemented");
63 void draw(Graphics2D engine
)
65 engine
.setPaint(color
);
66 engine
.drawLine(getEffectivePosition().x
, getEffectivePosition().y
, getEffectiveEnd().x
, getEffectiveEnd().y
);
69 public boolean contains(Point position
)
71 Point p
[] = new Point
[2];
72 p
[0] = getEffectivePosition();
73 p
[1] = getEffectiveEnd();
75 int denom
= p
[1].x
- p
[0].x
;
76 int iMinorX
= p
[0].x
< p
[1].x ?
0 : 1;
77 int iMinorY
= p
[0].y
< p
[1].y ?
0 : 1;
78 int iMajorX
= 1 - iMinorX
;
79 int iMajorY
= 1 - iMinorY
;
82 if(Math
.abs(position
.x
- p
[0].x
) <= NEAR
&& position
.y
>= p
[iMinorY
].y
&& position
.y
<= p
[iMajorY
].y
)
85 } else // <diabolic>ha ha ha ha ha</diabolic>
86 if(position
.x
>= p
[iMinorX
].x
&& position
.x
<= p
[iMajorX
].x
) {
87 int num
= p
[1].y
- p
[0].y
;
88 float m
= ((float)num
)/denom
;
89 float y
= m
*position
.x
- m
*p
[0].x
+ p
[0].y
;
90 if(Math
.abs(y
- position
.y
) <= NEAR
)
103 public int getHeight()
109 public Object
clone() throws CloneNotSupportedException
111 CanvasLine cl
= (CanvasLine
) super.clone();
112 cl
.setEnd(new Point(end
.x
, end
.y
));