jdraw.graphics
Class GraphicObject

java.lang.Object
  |
  +--jdraw.graphics.GraphicObject
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
CurvedShapeObject, CurveObject, EllipseObject, LineObject, PolygonObject, PolylineObject, RectangleObject, TextObject

public abstract class GraphicObject
extends java.lang.Object
implements java.io.Serializable

Class GraphicObject is the abstract class whose extensions are used to build the Graphics List. Each node contains a Shape object and all the relevant properties of that shape.

See Also:
Serialized Form

Field Summary
protected  int arrowsOn
          A boolean to indicate whether arrows are to be drawn.
protected  java.awt.Color backgroundColor
          A Color object which holds the background color of this.shape.
protected  java.awt.Color color
          A Color object which holds the color of this.shape.
protected  java.util.Vector controlPoints
          A Vector holding all of the control Points of this.shape.
protected  int graphicType
          An int to indicate which type of graphic shape is.
protected  java.util.Vector paint
          An int representing the paint used to fill this.shape.
protected  java.awt.Shape shape
          A Shape object holds the Shape object of this Graphic.
protected  java.awt.BasicStroke stroke
          A BasicStroke object used to draw this.shape.
 
Constructor Summary
GraphicObject(java.awt.Color c, java.awt.Color bgc, java.util.Vector paint, java.util.Vector cPoints, java.awt.BasicStroke bs)
          Construct this with the given Shape, Color, FillStyle, and ControlPoints objects.
 
Method Summary
 void addPoint(java.awt.Point p)
          Method addPoint is overwritten in PolygonObject, PolylineObject, CurveObject, and CurvedShapeObject.
 java.lang.Object clone()
          Method clone() is overwritten by each individual ShapeObject class.
 boolean containedIn(java.awt.Polygon selectionBounds)
          Returns a boolean value representing whether this.shape resides within given Polygon.
 java.awt.geom.GeneralPath deriveImage(float zoom)
          Method deriveImage creates the GeneralPath object which will represent this shape on screen, given the passed in zoom factor.
 void draw(java.awt.Graphics2D g2D, float zoom)
          Draws this.shape on the given Graphics2D object.
 void flipHorizontally()
          Flips this.shape horizontally.
 void flipVertically()
          Flips this.shape vertically.
 java.awt.Color getBackgroundColor()
           
 java.awt.Color getColor()
           
 java.util.Vector getControlPoints()
           
 int getGraphicType()
           
 int getMaxX()
           
 int getMaxY()
           
 int getMinX()
           
 int getMinY()
           
 java.util.Vector getSaveBundle()
          Returns a saveBundle (Vector) derived from the information contained in this.
 java.awt.Shape getShape()
           
 java.awt.BasicStroke getStroke()
           
 int getTouchedControlPoint(java.awt.Point clickedPoint)
          Returns the index of the last Point in Vector controlPoints which is close enough to Point clickedPoint to be considered "clicked".
 boolean isPointOnShape(java.awt.Point clickedPoint)
          Returns a boolean value representing whether the given Point resides on this.shape.
 void rotate(double theta, double anchorX, double anchorY)
          Rotates this.shape around point (anchorX, anchorY) by theta radians.
 void setArrows(int arrows)
          Empty method which is overwritten in Line, Polyline, and Curve.
 void setBackgroundColor(java.awt.Color c)
           
 void setColor(java.awt.Color c)
           
 void setControlPoints()
          Empty methods which are overwritten if needed.
 void setHorizontalCenter(float newCenterX)
          Translates this.shape by the X-coordinate given by newCenterX - CenterOfThisX.
 void setLastPoint(java.awt.Point p)
          Method setLastPoint is overwritten in PolygonObject, PolylineObject, CurveObject, and CurvedShapeObject.
 void setMaxX(int newMaxX)
           
 void setMaxY(int newMaxY)
           
 void setMinX(int newMinX)
           
 void setMinY(int newMinY)
           
 void setPaint(java.util.Vector p)
           
 void setSecondPoint(java.awt.Point p)
          Method setSecondPoint is overwritten in EllipseObject, RectangleObject, and LineObject.
 void setShape()
          Empty methods which are overwritten if needed.
 void setStroke(java.awt.BasicStroke bs)
           
 void setVerticalCenter(float newCenterY)
          Translates this.shape by the Y-coordinate given by newCenterY - CenterOfThisY.
 void translate(float deltaX, float deltaY)
          Translates the position of this.shape by the given deltaX and deltaY values.
 void translateControlPoint(int controlPointIndex, float deltaX, float deltaY)
          Translates the Control Point (in Vector controlPoints) whose index is passed in by the passed in values of deltaX and deltaY.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

shape

protected java.awt.Shape shape
A Shape object holds the Shape object of this Graphic.

color

protected java.awt.Color color
A Color object which holds the color of this.shape.

backgroundColor

protected java.awt.Color backgroundColor
A Color object which holds the background color of this.shape.

controlPoints

protected java.util.Vector controlPoints
A Vector holding all of the control Points of this.shape.

paint

protected java.util.Vector paint
An int representing the paint used to fill this.shape.

stroke

protected java.awt.BasicStroke stroke
A BasicStroke object used to draw this.shape.

graphicType

protected int graphicType
An int to indicate which type of graphic shape is.

arrowsOn

protected int arrowsOn
A boolean to indicate whether arrows are to be drawn.
Constructor Detail

GraphicObject

public GraphicObject(java.awt.Color c,
                     java.awt.Color bgc,
                     java.util.Vector paint,
                     java.util.Vector cPoints,
                     java.awt.BasicStroke bs)
Construct this with the given Shape, Color, FillStyle, and ControlPoints objects.
Parameters:
c - - The Color object to store in this.color.
bgc - - The Color object to store in this.backgroundColor.
paint - - The Vector object with the paint properties.
cPoints - - Vector object to store in this.controlPoints.
bs - - The BasicStroke object used to draw the shape to the screen.
Method Detail

getTouchedControlPoint

public int getTouchedControlPoint(java.awt.Point clickedPoint)
Returns the index of the last Point in Vector controlPoints which is close enough to Point clickedPoint to be considered "clicked".
Parameters:
clickedPoint - - The Point object representing the position of a mouse click.
Returns:
- The int value representing the index of the last Point in Vector controlPoints which is close enough to Point clickedPoint to be considered "clicked". If none of the Points in controlPoints are close enough, -1 is returned.

deriveImage

public java.awt.geom.GeneralPath deriveImage(float zoom)
Method deriveImage creates the GeneralPath object which will represent this shape on screen, given the passed in zoom factor.
Parameters:
zoom - - The float value indicating the current zoom factor.

translateControlPoint

public void translateControlPoint(int controlPointIndex,
                                  float deltaX,
                                  float deltaY)
Translates the Control Point (in Vector controlPoints) whose index is passed in by the passed in values of deltaX and deltaY.
Parameters:
controlPointIndex - - The int value representing the index of the relevant Point in controlPoints.
deltaX - - The int value to be translated in the X direction.
deltaY - - The int value to be translated in the Y direction.

isPointOnShape

public boolean isPointOnShape(java.awt.Point clickedPoint)
Returns a boolean value representing whether the given Point resides on this.shape.
Parameters:
clickedPoint - - The Point object represent the position of a mouse click.
Returns:
- The boolean value described above.

containedIn

public boolean containedIn(java.awt.Polygon selectionBounds)
Returns a boolean value representing whether this.shape resides within given Polygon.
Parameters:
selectionBounds - - The Polygon which defines the bounds of selection.
Returns:
- The boolean value described above.

translate

public void translate(float deltaX,
                      float deltaY)
Translates the position of this.shape by the given deltaX and deltaY values.
Parameters:
deltaX - - The int value by which to alter the X position of this.shape.
deltaY - - The int value by which to alter the Y position of this.shape.

draw

public void draw(java.awt.Graphics2D g2D,
                 float zoom)
Draws this.shape on the given Graphics2D object.
Parameters:
g2D - - The Graphics2D object on which to draw this.shape.
zoom - - The float value indicating the current zoom factor.

getMinX

public int getMinX()

getMinY

public int getMinY()

getMaxX

public int getMaxX()

getMaxY

public int getMaxY()

setMinX

public void setMinX(int newMinX)
Parameters:
newMinX - - The int value to be set as the left side of the Rectangle which bounds this.shape.

setMinY

public void setMinY(int newMinY)
Parameters:
newMinY - - The int value to be set as the top side of the Rectangle which bounds this.shape.

setMaxX

public void setMaxX(int newMaxX)
Parameters:
newMaxX - - The int value to be set as the right side of the Rectangle which bounds this.shape.

setMaxY

public void setMaxY(int newMaxY)
Parameters:
newMaxY - - The int value to be set as the bottom side of the Rectangle which bounds this.shape.

setVerticalCenter

public void setVerticalCenter(float newCenterY)
Translates this.shape by the Y-coordinate given by newCenterY - CenterOfThisY.
Parameters:
newCenterY - - The float value from which to determine deltaY.

setHorizontalCenter

public void setHorizontalCenter(float newCenterX)
Translates this.shape by the X-coordinate given by newCenterX - CenterOfThisX.
Parameters:
newCenterX - - The float value from which to determine deltaX.

rotate

public void rotate(double theta,
                   double anchorX,
                   double anchorY)
Rotates this.shape around point (anchorX, anchorY) by theta radians.
Parameters:
theta - - A double value representing an angle in radians.
anchorX - - A double value representing the x-coordinate of the anchor point.
anchorY - - A double value representing the y-coordinate of the anchor point.

flipHorizontally

public void flipHorizontally()
Flips this.shape horizontally.

flipVertically

public void flipVertically()
Flips this.shape vertically.

getSaveBundle

public java.util.Vector getSaveBundle()
Returns a saveBundle (Vector) derived from the information contained in this.

setColor

public void setColor(java.awt.Color c)
Parameters:
c - - The Color object to store in this.color.

setBackgroundColor

public void setBackgroundColor(java.awt.Color c)
Parameters:
c - - The Color object to store in this.backgroundColor.

setPaint

public void setPaint(java.util.Vector p)
Parameters:
p - - The Vector object to store in this.paintType.

getBackgroundColor

public java.awt.Color getBackgroundColor()

setStroke

public void setStroke(java.awt.BasicStroke bs)
Parameters:
bs - - The BasicStroke object to store in this.stroke.

getStroke

public java.awt.BasicStroke getStroke()

getShape

public java.awt.Shape getShape()

getColor

public java.awt.Color getColor()

getControlPoints

public java.util.Vector getControlPoints()

getGraphicType

public int getGraphicType()

setLastPoint

public void setLastPoint(java.awt.Point p)
Method setLastPoint is overwritten in PolygonObject, PolylineObject, CurveObject, and CurvedShapeObject.

addPoint

public void addPoint(java.awt.Point p)
Method addPoint is overwritten in PolygonObject, PolylineObject, CurveObject, and CurvedShapeObject.

setSecondPoint

public void setSecondPoint(java.awt.Point p)
Method setSecondPoint is overwritten in EllipseObject, RectangleObject, and LineObject.

clone

public java.lang.Object clone()
Method clone() is overwritten by each individual ShapeObject class.
Overrides:
clone in class java.lang.Object

setControlPoints

public void setControlPoints()
Empty methods which are overwritten if needed.

setShape

public void setShape()
Empty methods which are overwritten if needed.

setArrows

public void setArrows(int arrows)
Empty method which is overwritten in Line, Polyline, and Curve.