java.lang.Objectobjectdraw.ObjectDrawObject
objectdraw.ObjectDrawShape
objectdraw.Line
public class Line
A Line
represents a line segment connecting two points on the screen. The end
points may be altered individually to move the line. It is also possible to set the color,
thickness, and stroke style of the line.
Field Summary |
---|
Fields inherited from interface objectdraw.DrawableStrokeInterface |
---|
CLICK_SIZE, DEFAULT_STROKE |
Constructor Summary | |
---|---|
Line(double x1,
double y1,
double x2,
double y2,
Color color,
DrawingCanvas canvas)
Create a Line from (x1 , y1 ) to (x2 ,
y2 ), in the given color . |
|
Line(double x1,
double y1,
double x2,
double y2,
DrawingCanvas canvas)
Create a Line from (x1 , y1 ) to (x2 ,
y2 ), colored black. |
|
Line(Location start,
Location end,
Color color,
DrawingCanvas canvas)
Create a Line from start to end ,
in the given color . |
|
Line(Location start,
Location end,
DrawingCanvas canvas)
Create a Line from start to end ,
colored black. |
Method Summary | |
---|---|
void |
addToCanvas(DrawingCanvas c)
Place this object on the specified canvas. |
boolean |
contains(Location point)
Return true if the given location is inside this object, false
otherwise. |
DrawingCanvas |
getCanvas()
Return the canvas that this object is on. |
Color |
getColor()
Return the color of this object |
Location |
getEnd()
Get the location of the end of the line. |
double |
getLineWidth()
Return the width of this object's lines. |
Location |
getStart()
Get the location of the start of the line. |
BasicStroke |
getStroke()
Return the stroke used for this object's lines. |
void |
hide()
Make this object invisible. |
boolean |
isHidden()
Return true if this object has been rendered invisible with a call to its
hide() method, false if it is still being drawn. |
void |
move(double dx,
double dy)
Shift (translate) this object left or right by an amount dx , and up or
down by an amount dy . |
void |
moveTo(double x,
double y)
Move the reference point of this object to the given location. |
void |
moveTo(Location point)
Move the reference point of this object to the given location. |
void |
removeFromCanvas()
Remove this object from its canvas. |
void |
sendBackward()
Move this object one step backward in the draw order, causing it to be drawn underneath the objects that are in front of it. |
void |
sendForward()
Move this object one step forward in the draw order, causing it to be drawn on top of the objects that are behind it. |
void |
sendToBack()
Move this object to the very back of the draw order, causing it to be drawn underneath all the other objects. |
void |
sendToFront()
Move this object to the very front of the draw order, causing it to be drawn on top of all the other objects. |
void |
setColor(Color c)
Change the color of this object. |
void |
setEnd(double x,
double y)
Move the end of the line to a new location |
void |
setEnd(Location point)
Move the end of the line to a new location |
void |
setEndPoints(double x1,
double y1,
double x2,
double y2)
Move both endpoints of the line. |
void |
setEndPoints(Location start,
Location end)
Move both endpoints of the line. |
void |
setLineWidth(double width)
Set the width of this object's lines |
void |
setStart(double x,
double y)
Move the start of the line to a new location |
void |
setStart(Location point)
Move the start of the line to a new location |
void |
setStroke(BasicStroke stroke)
Set the stroke used for this object's lines |
void |
show()
Make an object visible again after it had been hidden. |
String |
toString()
Return a string describing how this object might be constructed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Line(double x1, double y1, double x2, double y2, Color color, DrawingCanvas canvas)
Line
from (x1
, y1
) to (x2
,
y2
), in the given color
.
x1
- x coordinate of the start pointy1
- y coordinate of the start pointx2
- x coordinate of the end pointy2
- y coordinate of the end pointcolor
- Color
of the linecanvas
- DrawingCanvas
to place the Line
public Line(double x1, double y1, double x2, double y2, DrawingCanvas canvas)
Line
from (x1
, y1
) to (x2
,
y2
), colored black.
x1
- x coordinate of the start pointy1
- y coordinate of the start pointx2
- x coordinate of the end pointy2
- y coordinate of the end pointcanvas
- DrawingCanvas
to place the Line
public Line(Location start, Location end, Color color, DrawingCanvas canvas)
Line
from start
to end
,
in the given color
.
start
- Location
of the start pointend
- Location
of the end pointcolor
- Color
of the linecanvas
- DrawingCanvas
to place the Line
public Line(Location start, Location end, DrawingCanvas canvas)
Line
from start
to end
,
colored black.
start
- Location
of the start pointend
- Location
of the end pointcanvas
- DrawingCanvas
to place the Line
Method Detail |
---|
public void addToCanvas(DrawingCanvas c)
null
the object is simply removed from its current canvas.
addToCanvas
in interface DrawableInterface
addToCanvas
in class objectdraw.ObjectDrawShape
c
- DrawingCanvas
to place this object onpublic boolean contains(Location point)
true
if the given location is inside this object, false
otherwise. Because Line
s and FramedArc
s have no "inside", a
point is considered to be contained in one of them as long as it is within a few pixels
of the line.
contains
in interface DrawableInterface
point
- Location
to test
public DrawingCanvas getCanvas()
null
.
getCanvas
in interface DrawableInterface
getCanvas
in class objectdraw.ObjectDrawShape
DrawingCanvas
that this object is on.public Color getColor()
getColor
in interface DrawableInterface
getColor
in class objectdraw.ObjectDrawShape
Color
of this objectpublic Location getEnd()
Location
object
will have the same effect as changing the end point. So, the following three lines
of code are equivalent:
line.setEnd(line.getEnd().getX() + 10, line.getEnd().getY() + 20);
line.setEnd(line.getEnd().offset(10, 20));
line.getEnd().translate(10, 20);
Location
offset by some
amount from the end Location
of this line, without actually
moving this line, use the offset()
method in Location
,
which creates a new Location
.
getEnd
in interface Drawable1DInterface
Location
of the end of the line.public double getLineWidth()
getLineWidth
in interface DrawableStrokeInterface
public Location getStart()
Location
object
will have the same effect as changing the start point. So, the following three lines
of code are equivalent:
line.setStart(line.getStart().getX() + 10, line.getStart().getY() + 20);
line.setStart(line.getStart().offset(10, 20));
line.getStart().translate(10, 20);
Location
offset by some
amount from the start Location
of this line, without actually
moving this line, use the offset()
method in Location
,
which creates a new Location
.
getStart
in interface Drawable1DInterface
Location
of the start of the line.public BasicStroke getStroke()
getStroke
in interface DrawableStrokeInterface
public void hide()
hide
in interface DrawableInterface
hide
in class objectdraw.ObjectDrawShape
public boolean isHidden()
true
if this object has been rendered invisible with a call to its
hide()
method, false
if it is still being drawn.
isHidden
in interface DrawableInterface
isHidden
in class objectdraw.ObjectDrawShape
public void move(double dx, double dy)
dx
, and up or
down by an amount dy
. A negative dx
indicates a shift to the
left; a negative dy
indicates a shift up
move
in interface DrawableInterface
move
in class objectdraw.ObjectDrawShape
dx
- amount of x translationdy
- amount of y translationpublic void moveTo(double x, double y)
moveTo
in interface DrawableInterface
moveTo
in class objectdraw.ObjectDrawShape
x
- x coordinate to move toy
- y coordinate to move topublic void moveTo(Location point)
moveTo
in interface DrawableInterface
moveTo
in class objectdraw.ObjectDrawShape
point
- Location
to move topublic void removeFromCanvas()
removeFromCanvas
in interface DrawableInterface
removeFromCanvas
in class objectdraw.ObjectDrawShape
public void sendBackward()
sendBackward
in interface DrawableInterface
sendBackward
in class objectdraw.ObjectDrawShape
public void sendForward()
sendForward
in interface DrawableInterface
sendForward
in class objectdraw.ObjectDrawShape
public void sendToBack()
sendToBack
in interface DrawableInterface
sendToBack
in class objectdraw.ObjectDrawShape
public void sendToFront()
sendToFront
in interface DrawableInterface
sendToFront
in class objectdraw.ObjectDrawShape
public void setColor(Color c)
setColor
in interface DrawableInterface
setColor
in class objectdraw.ObjectDrawShape
c
- new Color
for this objectpublic void setEnd(double x, double y)
setEnd
in interface Drawable1DInterface
x
- x coordinate to which the end of the line should be movedy
- y coordinate to which the end of the line should be movedpublic void setEnd(Location point)
setEnd
in interface Drawable1DInterface
point
- Location
to which the end of the line should be movedpublic void setEndPoints(double x1, double y1, double x2, double y2)
setEndPoints
in interface Drawable1DInterface
x1
- x1 coordinate to which the start of the line should be movedy1
- y1 coordinate to which the start of the line should be movedx2
- x coordinate to which the end of the line should be movedy2
- y coordinate to which the end of the line should be movedpublic void setEndPoints(Location start, Location end)
setEndPoints
in interface Drawable1DInterface
start
- Location
to which the start of the line should be movedend
- Location
to which the end of the line should be movedpublic void setLineWidth(double width)
setLineWidth
in interface DrawableStrokeInterface
width
- the new width of this object's linespublic void setStart(double x, double y)
setStart
in interface Drawable1DInterface
x
- x coordinate to which the start of the line should be movedy
- y coordinate to which the start of the line should be movedpublic void setStart(Location point)
setStart
in interface Drawable1DInterface
point
- Location
to which the start of the line should be movedpublic void setStroke(BasicStroke stroke)
setStroke
in interface DrawableStrokeInterface
stroke
- the new stroke for this object's linespublic void show()
show
in interface DrawableInterface
show
in class objectdraw.ObjectDrawShape
public String toString()
toString
in class objectdraw.ObjectDrawObject