Package edu.macalester.graphics
Class Rectangle
java.lang.Object
edu.macalester.graphics.GraphicsObject
edu.macalester.graphics.Rectangle
A rectangle that can be drawn on the screen.
A rectangle’s position is its upper left corner.
-
Constructor Summary
Constructors -
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.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.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.voidsetSize(double width, double height) Changes the width and height of the rectangle, preserving its upper left corner's position.voidChanges the width and height of the rectangle, preserving its upper left corner's position.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.booleantestHitInLocalCoordinates(double x, double y) Tests whether the given point is inside the boundary or interior of this object’s shape.toString()Returns a string representation of the rectangleMethods 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
-
Rectangle
public Rectangle(double x, double y, double width, double height) Creates a rectangle whose upper left is at (x,y) with the specified width and height. The rectangle has a 1 pixel black stroke outline by default. -
Rectangle
Creates a rectangle with the given upper left corner and size. The rectangle has a 1 pixel black stroke outline by default.
-
-
Method Details
-
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
-
setSize
public void setSize(double width, double height) Changes the width and height of the rectangle, preserving its upper left corner's position. -
setSize
Changes the width and height of the rectangle, preserving its upper left corner's position. -
testHitInLocalCoordinates
public boolean testHitInLocalCoordinates(double x, double y) Description copied from class:GraphicsObjectTests 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:
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 rectangle
-