public class GLine extends GObject implements GScalable
GLine
class is a graphical object whose appearance consists
of a line segment.Modifier and Type | Field and Description |
---|---|
static double |
LINE_TOLERANCE
This constant defines how close (measured in pixel units) a point has to
be to a line before that point is considered to be "contained" within the
line.
|
Constructor and Description |
---|
GLine()
Constructs a line segment of length 0 at position (0, 0).
|
GLine(double x0,
double y0)
Constructs a line segment of length 0 at position (x0, y0).
|
GLine(double x0,
double y0,
double x1,
double y1)
Constructs a line segment from its endpoints.
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(double x,
double y)
Checks to see whether a point is inside the object.
|
static double |
distanceSquared(double x0,
double y0,
double x1,
double y1)
Returns the square of the distance between (
x0 ,
y0 ) and (x1 , y1 ). |
GRectangle |
getBounds()
Returns the bounding box for this object.
|
GPoint |
getEndPoint()
Returns the end point of the line as a
GPoint object. |
GPoint |
getStartPoint()
Returns the coordinates of the initial point in the line.
|
static boolean |
intersects(double x,
double y,
double x0,
double y0,
double x1,
double y1,
double lineWidth)
Returns whether the given x/y point intersects the line from x0,y0 to x1,y1 of the given width.
|
void |
paint2d(Graphics2D g)
Implements the
paint2d operation for this graphical object. |
String |
paramString()
Returns a string indicating the parameters of this object.
|
void |
scale(double sx,
double sy)
Scales the line on the screen by the scale factors
sx and
sy . |
void |
setEndPoint(double x,
double y)
Sets the end point of the line to the point (
x ,
y ). |
void |
setEndPointPolar(double r,
double theta)
Sets the end point of the line using polar coordinates.
|
void |
setStartPoint(double x,
double y)
Sets the initial point in the line to (
x ,
y ), leaving the end point unchanged. |
addActionListener, addMouseListener, addMouseMotionListener, areMouseListenersEnabled, clone, colorName, colorName, colorNameFriendly, contains, createTransformedGraphics, fireActionEvent, fireActionEvent, fireMouseListeners, getBottomY, getCenterLocation, getCenterX, getCenterY, getColor, getComponent, getHeight, getLineWidth, getLocation, getMatrix, getObjectColor, getParent, getRightX, getSize, getWidth, getX, getY, intersects, isAntiAliasing, isVisible, move, movePolar, paint, pause, removeActionListener, removeMouseListener, removeMouseMotionListener, repaint, rotate, scale, sendBackward, sendForward, sendToBack, sendToFront, setAntiAliasing, setBottomY, setCenterLocation, setCenterLocation, setCenterX, setCenterY, setColor, setLineWidth, setLocation, setLocation, setParent, setRightX, setVisible, setX, setY, start, start, toString, updateEnabledList
public static final double LINE_TOLERANCE
public GLine()
public GLine(double x0, double y0)
public GLine(double x0, double y0, double x1, double y1)
x0
, y0
) defines the start of the line and the point (
x1
, y1
) defines the end.x0
- The x-coordinate of the start of the liney0
- The y-coordinate of the start of the linex1
- The x-coordinate of the end of the liney1
- The y-coordinate of the end of the linepublic boolean contains(double x, double y)
GLine
class, containment is defined to mean that the point
is within LINE_TOLERANCE
pixels of the line.public static double distanceSquared(double x0, double y0, double x1, double y1)
x0
,
y0
) and (x1
, y1
).public GRectangle getBounds()
public GPoint getEndPoint()
GPoint
object.public GPoint getStartPoint()
getLocation
and
exists only to provide symmetry with setStartPoint
.public static boolean intersects(double x, double y, double x0, double y0, double x1, double y1, double lineWidth)
public void paint2d(Graphics2D g)
paint2d
operation for this graphical object.
This method is not called directly by clients.public String paramString()
paramString
in class GObject
public void scale(double sx, double sy)
sx
and
sy
. This method changes only the end point of the line,
leaving the start of the line fixed.public void setEndPoint(double x, double y)
x
,
y
). The origin of the line remains unchanged.x
- The new x-coordinate of the end pointy
- The new y-coordinate of the end pointpublic void setEndPointPolar(double r, double theta)
r
- The polar radius length from start pointtheta
- The polar angle in degreespublic void setStartPoint(double x, double y)
x
,
y
), leaving the end point unchanged. This method is
therefore different from
setLocation
, which moves both components of the line
segment.x
- The new x-coordinate of the originy
- The new y-coordinate of the origin