acm.graphics
Class GLine

java.lang.Object
  extended by acm.graphics.GObject
      extended by acm.graphics.GLine
All Implemented Interfaces:
GScalable, Serializable, Cloneable

public class GLine
extends GObject
implements GScalable

The GLine class is a graphical object whose appearance consists of a line segment.

See Also:
Serialized Form

Field Summary
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 Summary
GLine(double x0, double y0, double x1, double y1)
          Constructs a line segment from its endpoints.
 
Method Summary
 boolean contains(double x, double y)
          Checks to see whether a point is inside the object.
 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.
 void paint(Graphics g)
          Implements the paint operation for this graphical object.
 String paramString()
          Returns a string indicating the parameters of this object.
 void scale(double sf)
          Scales the object on the screen by the scale factor sf, which applies in both dimensions.
 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 (xy).
 void setStartPoint(double x, double y)
          Sets the initial point in the line to (xy), leaving the end point unchanged.
 
Methods inherited from class acm.graphics.GObject
addActionListener, addMouseListener, addMouseMotionListener, areMouseListenersEnabled, colorName, contains, fireActionEvent, fireActionEvent, fireMouseListeners, getColor, getComponent, getHeight, getLocation, getObjectColor, getParent, getSize, getWidth, getX, getY, isVisible, move, movePolar, paintObject, pause, removeActionListener, removeMouseListener, removeMouseMotionListener, repaint, sendBackward, sendForward, sendToBack, sendToFront, setColor, setLocation, setLocation, setParent, setVisible, start, start, toString, updateEnabledList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LINE_TOLERANCE

public static final 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.

See Also:
Constant Field Values
Constructor Detail

GLine

public GLine(double x0,
             double y0,
             double x1,
             double y1)
Constructs a line segment from its endpoints. The point (x0y0) defines the start of the line and the point (x1y1) defines the end.

Parameters:
x0 - The x-coordinate of the start of the line
y0 - The y-coordinate of the start of the line
x1 - The x-coordinate of the end of the line
y1 - The y-coordinate of the end of the line
Method Detail

contains

public boolean contains(double x,
                        double y)
Checks to see whether a point is inside the object. For the GLine class, containment is defined to mean that the point is within LINE_TOLERANCE pixels of the line.

Overrides:
contains in class GObject
Parameters:
x - The x-coordinate of the point being tested
y - The y-coordinate of the point being tested
Returns:
true if the point (xy) is inside

getBounds

public GRectangle getBounds()
Returns the bounding box for this object.

Specified by:
getBounds in class GObject
Returns:
The bounding box for this object

getEndPoint

public GPoint getEndPoint()
Returns the end point of the line as a GPoint object.

Returns:
The coordinates of the end point of the line

getStartPoint

public GPoint getStartPoint()
Returns the coordinates of the initial point in the line. This method is identical to getLocation and exists only to provide symmetry with setStartPoint.

Returns:
The coordinates of the origin of the line

paint

public void paint(Graphics g)
Implements the paint operation for this graphical object. This method is not called directly by clients.

Specified by:
paint in class GObject
Parameters:
g - The graphics context into which the painting is done

paramString

public String paramString()
Returns a string indicating the parameters of this object.

Overrides:
paramString in class GObject

scale

public final void scale(double sf)
Scales the object on the screen by the scale factor sf, which applies in both dimensions.

Specified by:
scale in interface GScalable
Parameters:
sf - The factor used to scale all coordinates in both dimensions

scale

public void scale(double sx,
                  double sy)
Scales the line on the screen by the scale factors sx and sy. This method changes only the end point of the line, leaving the start of the line fixed.

Specified by:
scale in interface GScalable
Parameters:
sx - The factor used to scale all coordinates in the x direction
sy - The factor used to scale all coordinates in the y direction

setEndPoint

public void setEndPoint(double x,
                        double y)
Sets the end point of the line to the point (xy). The origin of the line remains unchanged.

Parameters:
x - The new x-coordinate of the end point
y - The new y-coordinate of the end point

setStartPoint

public void setStartPoint(double x,
                          double y)
Sets the initial point in the line to (xy), leaving the end point unchanged. This method is therefore different from setLocation, which moves both components of the line segment.

Parameters:
x - The new x-coordinate of the origin
y - The new y-coordinate of the origin