Package edu.macalester.graphics
Class Line
java.lang.Object
edu.macalester.graphics.GraphicsObject
edu.macalester.graphics.Line
- All Implemented Interfaces:
Strokable
A line segment that can be drawn on the screen.
A line has a "start point" and an "end point". The only distinction is that the start point is
the line’s position
. If you call setPosition()
or moveBy()
, both endpoints will move so the line segment has the same
length and angle, and the start point will end up at the position you specify.
To move one endpoint without affecting the other, use setStartPosition()
and setEndPosition()
.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
For internal use.Returns the bounding box of this graphics object in its local coordinates.protected Object
For internal use only.Returns the color to strokeColor that will be used to stroke this shape if it is stroked.double
Returns the thickness of the stroke in pixels.double
getX1()
Get the shape's x1 positiondouble
getX2()
Get the shape's x2 positiondouble
getY1()
Get the shape's y1 positiondouble
getY2()
Get the shape's y2 positionboolean
Returns true if the interior of this shape will be stroked with the stroke color.void
setEndPosition
(double x, double y) Sets the line's ending position to (x, y) without affecting the start position.void
Sets the line's ending position to the given point without affecting the end position.void
setStartPosition
(double x, double y) Sets the line's starting position to (x, y) without affecting the end position.void
Sets the line's starting position to the given point without affecting the end position.void
setStrokeColor
(Paint strokeColor) Sets the stroke color to the given color.void
setStroked
(boolean stroked) Causes the shape to be stroked with the stroke color when it is drawn.void
setStrokeWidth
(double width) Sets how thick the stroke is.boolean
testHitInLocalCoordinates
(double x, double y) Tests whether the given point is inside the boundary or interior of this object’s shape.toString()
Methods inherited from class edu.macalester.graphics.GraphicsObject
addObserver, changed, equals, getAnchor, getBoundsInParent, getCanvas, getCenter, getElementAt, getElementAtLocalCoordinates, getEmbeddedComponent, getHeight, getPosition, getRotation, getScale, getScaleX, getScaleY, getSize, getSizeInParent, getWidth, getX, getY, hashCode, isInBounds, moveBy, moveBy, removeObserver, renderToBuffer, rotateBy, setAnchor, setAnchor, setCenter, setCenter, setPosition, setPosition, setRotation, setScale, setScale, setScale, setX, setY, testHit
-
Constructor Details
-
Line
public Line(double x1, double y1, double x2, double y2) Creates a line starting at position (x1,y1) and ending at (x2,y2). The line has a 1 pixel black stroke outline by default.- Parameters:
x1
- x position of starting pointy1
- y position of starting pointx2
- x position of ending pointy2
- y position of ending point
-
Line
Creates a line starting at point1 and ending at point2. The line has a 1 pixel black stroke outline by default.
-
-
Method Details
-
drawInLocalCoordinates
Description copied from class:GraphicsObject
For internal use. Draws this graphics object on the screen in its local coordinates, without rotation or scaling.- Specified by:
drawInLocalCoordinates
in classGraphicsObject
-
getStrokeColor
Description copied from interface:Strokable
Returns the color to strokeColor that will be used to stroke this shape if it is stroked. Note that there will still be no stroke if isStroked() is false or the stroke width is zero.- Specified by:
getStrokeColor
in interfaceStrokable
-
setStrokeColor
Description copied from interface:Strokable
Sets the stroke color to the given color. Automatically calls setStroked(true).- Specified by:
setStrokeColor
in interfaceStrokable
-
getStrokeWidth
public double getStrokeWidth()Description copied from interface:Strokable
Returns the thickness of the stroke in pixels.- Specified by:
getStrokeWidth
in interfaceStrokable
-
setStrokeWidth
public void setStrokeWidth(double width) Description copied from interface:Strokable
Sets how thick the stroke is. Automatically calls setStroked(true).- Specified by:
setStrokeWidth
in interfaceStrokable
-
isStroked
public boolean isStroked()Description copied from interface:Strokable
Returns true if the interior of this shape will be stroked with the stroke color. -
setStroked
public void setStroked(boolean stroked) Description copied from interface:Strokable
Causes the shape to be stroked with the stroke color when it is drawn.- Specified by:
setStroked
in interfaceStrokable
-
getX1
public double getX1()Get the shape's x1 position- Returns:
- x position of starting point
-
getY1
public double getY1()Get the shape's y1 position- Returns:
- y position of starting point
-
getX2
public double getX2()Get the shape's x2 position- Returns:
- x position of ending point
-
getY2
public double getY2()Get the shape's y2 position- Returns:
- y position of ending point
-
setStartPosition
public void setStartPosition(double x, double y) Sets the line's starting position to (x, y) without affecting the end position. -
setStartPosition
Sets the line's starting position to the given point without affecting the end position. -
setEndPosition
public void setEndPosition(double x, double y) Sets the line's ending position to (x, y) without affecting the start position. -
setEndPosition
Sets the line's ending position to the given point without affecting the end position. -
testHitInLocalCoordinates
public boolean testHitInLocalCoordinates(double x, double y) Description copied from class:GraphicsObject
Tests whether the given point is inside the boundary or interior of this object’s shape. The point is in this object’s local coordinates.- Specified by:
testHitInLocalCoordinates
in classGraphicsObject
-
getBounds
Description copied from class:GraphicsObject
Returns the bounding box of this graphics object in its local coordinates.- Specified by:
getBounds
in classGraphicsObject
-
getEqualityAttributes
Description copied from class:GraphicsObject
For internal use only. Used to compute equals() and hashCode(). Returns an object whose equals() and hashCode() methods encompass the subclass-specific values that should be used to compute equality for the whole GraphicsObject.- Specified by:
getEqualityAttributes
in classGraphicsObject
-
toString
-