Package edu.macalester.graphics
Class Path
java.lang.Object
edu.macalester.graphics.GraphicsObject
edu.macalester.graphics.Path
- Direct Known Subclasses:
Polygon
An arbitrary path or polygon with straight sides, possibly self-intersecting.
The path is internally represented as a list of points, with an edge of the path connecting each adjacent pair of points in the list. The order of the list is thus important. Incorrectly ordering the list can lead to self-intersecting polygon, which are neat, but possibly not what you want.
An optional final edge connects the first and last point in the list. You can disable this by passing `false` to the second argument of setPoints().
A path’s position is the upper left corner of the bounding box of all its
points, and its size is the size of that bounding box.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a closed polygon from vertices passed as separate arguments.Create a closed polygon whose vertices comes from the given list of points.Create an optionally closed path whose vertices comes from the given list of points. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidFor internal use.Returns the bounding box of this graphics object in its local coordinates.protected ObjectFor internal use only.Returns the color to fillColor that will be used to fill this shape if it is filled.Returns the color to strokeColor that will be used to stroke this shape if it is stroked.doubleReturns the thickness of the stroke in pixels.booleanisClosed()Returns true if this path loops back to its starting point.booleanisFilled()Returns true if the interior of this shape will be filled with the fill color.booleanReturns true if the interior of this shape will be stroked with the stroke color.static PathmakeTriangle(double x0, double y0, double x1, double y1, double x2, double y2) Convenience method to create a triangle from three individual coordinates.voidsetFillColor(Paint fillColor) Sets the fill color to the given color.voidsetFilled(boolean filled) Causes the shape to be filled with the fill color when it is drawn.voidsetStrokeColor(Paint strokeColor) Sets the stroke color to the given color.voidsetStroked(boolean stroked) Causes the shape to be stroked with the stroke color when it is drawn.voidsetStrokeWidth(double width) Sets how thick the stroke is.voidsetVertices(List<Point> points) Replaces the path's coordinates, preserving its open/close status.voidsetVertices(List<Point> points, boolean closed) Changes the verices of this path, replacing any existing ones.booleantestHitInLocalCoordinates(double x, double y) Tests whether the given point is on the interior of this path.toString()Returns a string representation of the PolygonMethods inherited from class edu.macalester.graphics.GraphicsObject
addObserver, changed, equals, getAnchor, getBoundsInParent, getCanvas, getCenter, getElementAt, getElementAtLocalCoordinates, getEmbeddedComponent, getHeight, getParent, 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
-
Path
Create a closed polygon whose vertices comes from the given list of points. The list of points must not non-null. -
Path
Creates a closed polygon from vertices passed as separate arguments. -
Path
Create an optionally closed path whose vertices comes from the given list of points. The list of points must not non-null.- Parameters:
closed- If true, a final line connects the end of the path back to the start, forming a polygon.
-
-
Method Details
-
makeTriangle
Convenience method to create a triangle from three individual coordinates. -
setVertices
Replaces the path's coordinates, preserving its open/close status. The coordinates are relative to the path’s container; the method ignores the path’s current position. -
setVertices
Changes the verices of this path, replacing any existing ones. The coordinates are relative to the path’s container; the method ignores the path’s current position.- Parameters:
closed- If true, a final line connects the end of the path back to the start, forming a polygon.
-
drawInLocalCoordinates
Description copied from class:GraphicsObjectFor internal use. Draws this graphics object on the screen in its local coordinates, without rotation or scaling.- Specified by:
drawInLocalCoordinatesin classGraphicsObject
-
getFillColor
Description copied from interface:FillableReturns the color to fillColor that will be used to fill this shape if it is filled. Note that there will still be no fill if isFilled() is false.- Specified by:
getFillColorin interfaceFillable
-
setFillColor
Description copied from interface:FillableSets the fill color to the given color. Automatically calls setFilled(true).- Specified by:
setFillColorin interfaceFillable
-
getStrokeColor
Description copied from interface:StrokableReturns 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:
getStrokeColorin interfaceStrokable
-
setStrokeColor
Description copied from interface:StrokableSets the stroke color to the given color. Automatically calls setStroked(true).- Specified by:
setStrokeColorin interfaceStrokable
-
isFilled
public boolean isFilled()Description copied from interface:FillableReturns true if the interior of this shape will be filled with the fill color. -
setFilled
public void setFilled(boolean filled) Description copied from interface:FillableCauses the shape to be filled with the fill color when it is drawn. -
isStroked
public boolean isStroked()Description copied from interface:StrokableReturns true if the interior of this shape will be stroked with the stroke color. -
setStroked
public void setStroked(boolean stroked) Description copied from interface:StrokableCauses the shape to be stroked with the stroke color when it is drawn.- Specified by:
setStrokedin interfaceStrokable
-
getStrokeWidth
public double getStrokeWidth()Description copied from interface:StrokableReturns the thickness of the stroke in pixels.- Specified by:
getStrokeWidthin interfaceStrokable
-
setStrokeWidth
public void setStrokeWidth(double width) Description copied from interface:StrokableSets how thick the stroke is. Automatically calls setStroked(true).- Specified by:
setStrokeWidthin interfaceStrokable
-
isClosed
public boolean isClosed()Returns true if this path loops back to its starting point. -
testHitInLocalCoordinates
public boolean testHitInLocalCoordinates(double x, double y) Tests whether the given point is on the interior of this path. Does not account for stroke width.- Specified by:
testHitInLocalCoordinatesin classGraphicsObject
-
getBounds
Description copied from class:GraphicsObjectReturns the bounding box of this graphics object in its local coordinates.- Specified by:
getBoundsin classGraphicsObject
-
getEqualityAttributes
Description copied from class:GraphicsObjectFor 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:
getEqualityAttributesin classGraphicsObject
-
toString
Returns a string representation of the Polygon
-