org.alchemy.core
Class AlcShape

java.lang.Object
  extended by org.alchemy.core.AlcShape
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, AlcConstants

public class AlcShape
extends java.lang.Object
implements AlcConstants, java.lang.Cloneable, java.io.Serializable

A shape class used by Alchemy
The main shape is stored as a GeneralPath object with other variables defining the color, style, alpha etc...

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.alchemy.core.AlcConstants
COLOR_UI_BG, COLOR_UI_BOX, COLOR_UI_END, COLOR_UI_HIGHLIGHT, COLOR_UI_LINE, COLOR_UI_LINE_ALPHA, COLOR_UI_START, CURSOR_ARROW, CURSOR_BLANK, CURSOR_CIRCLE, CURSOR_CROSS, CURSOR_EYEDROPPER, CURSOR_HAND, CURSOR_MOVE, CURSOR_TEXT, CURSOR_WAIT, DIR_DESKTOP, DIR_HOME, DIR_SEPARATOR, DIR_TEMP, FONT_LARGE, FONT_LARGE_BOLD, FONT_MEDIUM, FONT_MEDIUM_BOLD, FONT_SMALL, FONT_SMALL_BOLD, FONT_SMALLER, JAVA_VERSION, JAVA_VERSION_NAME, KEY_MODIFIER, LOCALE, MATH_DEG_TO_RAD, MATH_HALF_PI, MATH_PI, MATH_QUARTER_PI, MATH_RAD_TO_DEG, MATH_THIRD_PI, MATH_TWO_PI, MODULE_AFFECT, MODULE_CREATE, OS_LINUX, OS_MAC, OS_NAME, OS_OTHER, OS_WINDOWS, PEN_CURSOR, PEN_ERASER, PEN_STYLUS, STYLE_BOTH, STYLE_CLIP, STYLE_FILL, STYLE_STROKE, TOOLKIT, USER_NAME
 
Constructor Summary
AlcShape()
          Creates a blank AlcShape object
AlcShape(java.awt.geom.GeneralPath path)
          Creates a new instance of AlcShape with the default values
AlcShape(java.awt.geom.GeneralPath path, java.awt.Color color, int alpha, int style, float lineWidth)
          Creates a new instance of AlcShape with defined values
AlcShape(java.awt.Point p)
          Creates a new instance of AlcShape with the default values
AlcShape(java.awt.geom.Point2D.Float p)
          Creates a new instance of AlcShape with the default values
AlcShape(java.awt.geom.Point2D.Float p, java.awt.Color color, int alpha, int style, float lineWidth)
          Creates a new instance of AlcShape with defined values
AlcShape(java.awt.Point p, java.awt.Color color, int alpha, int style, float lineWidth)
          Creates a new instance of AlcShape with defined values
 
Method Summary
 void append(java.awt.geom.GeneralPath newPath, boolean connect)
          Append a GeneralPath to this shape
 java.lang.Object clone()
          'Deep' Clone this object using the existing style/color etc..
 void closePath()
          Closes the current subpath by drawing a straight line back to the coordinates of the last moveTo
 void createSpine()
          Create the spine - redraws the variable width line based on the spine points
 void curveTo(java.awt.Point p)
          Add a curve point to the shape This method uses a simple smoothing algorithm to get rid of hard edges
 void curveTo(java.awt.geom.Point2D.Float p)
          Add a curve point to the shape This method uses a simple smoothing algorithm to get rid of hard edges
 AlcShape customClone(java.util.ArrayList<java.awt.geom.Point2D.Float> spine, java.util.ArrayList<java.lang.Float> spineWidth)
          A custom clone that adds a new spine (variable width line) to the shape the creates the path while keeping all of the style infomation.
 AlcShape customClone(java.awt.geom.GeneralPath tempPath)
          A custom clone that adds a new GeneralPath to the shape while keeping all of the style infomation.
 int getAlpha()
          Get the alpha (transparency) value of this shape
 java.awt.Rectangle getBounds()
          Get the bounds of this shape
 java.awt.Color getColor()
          Get the color of this shape
 java.awt.GradientPaint getGradientPaint()
          Get this shapes Gradient
 java.awt.geom.Point2D.Float getLastPoint()
          Return the last point
 float getLineWidth()
          Get the line width of this shape
 java.awt.geom.GeneralPath getPath()
          Return the GeneralPath path
 java.util.ArrayList<java.awt.geom.Point2D.Float> getPoints()
          Return a simple list of x,y points from this AlcShape object
 java.util.ArrayList<java.awt.geom.Point2D.Float> getSpine()
          Get the spine (used for variable width lines) of this shape
 java.util.ArrayList<java.lang.Float> getSpineWidth()
          Get the spine width (used for variable width lines) of this shape
 int getStyle()
          Get the style of this shape
 int getTotalPoints()
          Return the total number of points in this shape
 boolean hasSpine()
          Return if this shape uses a spine or not
static boolean isLineSmoothing()
          Check if line smoothing is on or off
 boolean isPathClosed()
          Return if the path has been closed or not
 boolean isPenShape()
          Return if this shape has been created with pen strokes or not
 void lineTo(java.awt.Point p)
          Add a straight line point to the shape
 void lineTo(java.awt.geom.Point2D.Float p)
          Add a straight line point to the shape
 void move(double x, double y)
          Move the shape by the specified distance.
 void moveTo(java.awt.Point p)
          Move to the given Point
 void moveTo(java.awt.geom.Point2D.Float p)
          Move to the given Point
 void recalculateTotalPoints()
          Recalculates the number of points for this shape Useful when shapes have been merged together
static java.awt.geom.Point2D.Float rightAngle(java.awt.geom.Point2D.Float p1, java.awt.geom.Point2D.Float p2, double distance)
          Calculate a right angle perpendicular to the two given points at the given distance
 void rotate(double theta)
          Rotate the shape using the shapes centre as the anchor point
 void rotate(double theta, double x, double y)
          Rotate the shape
 void scale(double sx, double sy)
          Scale the shape by a certain factor
 void setAlpha(int alpha)
          Set the alpha (transparency) value of this shape
 void setAlphaColor(java.awt.Color color)
          Set a color with alpha directly
 void setColor(java.awt.Color color)
          Set the color of this shape
 void setGradientPaint(java.awt.GradientPaint gradientPaint)
          Set this shapes gradient
 void setLastPoint(java.awt.geom.Point2D.Float lastPt)
          Set the last point for this shape Useful when creating a duplicate object
static void setLineSmoothing(boolean lineSmoothing)
          Set the line smoothing variable for AlcShape
 void setLineWidth(float lineWidth)
          Set the line width of this shape
 void setPath(java.awt.geom.GeneralPath path)
          Set the path using a GeneralPath
 void setPoint(java.awt.Point p)
          Set (or reset perhaps) the shape with a single Point
 void setPoint(java.awt.geom.Point2D.Float p)
          Set (or reset perhaps) the shape with a single Point
 void setSpine(java.util.ArrayList<java.awt.geom.Point2D.Float> spine)
          Set the spine (used for variable width lines) of this shape
 void setSpineWidth(java.util.ArrayList<java.lang.Float> spineWidth)
          Set the spine width (used for variable width lines) of this shape
 void setStyle(int style)
          Set the style of this shape
 void setTotalPoints(int totalPoints)
          Set the total number of points for this shape Useful when creating a duplicate object
 void setup()
          Set the attributes of this shape (Alpha/Color/Style/LineWidth) to the current values of the canvas
 void setup(java.awt.Color color, int alpha, int style, float lineWidth)
          Setup the attributes of a shape
 void spineTo(java.awt.geom.Point2D.Float p, float width)
          Add a spine point for variable width lines
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AlcShape

public AlcShape(java.awt.Point p)
Creates a new instance of AlcShape with the default values

Parameters:
p - Initial point to set the GeneralPath moveto

AlcShape

public AlcShape(java.awt.geom.Point2D.Float p)
Creates a new instance of AlcShape with the default values

Parameters:
p - Initial point to set the GeneralPath moveto

AlcShape

public AlcShape(java.awt.Point p,
                java.awt.Color color,
                int alpha,
                int style,
                float lineWidth)
Creates a new instance of AlcShape with defined values

Parameters:
p - Initial point to set the GeneralPath moveto
color - Color of the shape
alpha - Alpha value of the shape
style - Style of the shape - (1) LINE or (2) SOLID FILL
lineWidth - Line width of the shape

AlcShape

public AlcShape(java.awt.geom.Point2D.Float p,
                java.awt.Color color,
                int alpha,
                int style,
                float lineWidth)
Creates a new instance of AlcShape with defined values

Parameters:
p - Initial point to set the GeneralPath moveto
color - color of the shape
alpha - Alpha value of the shape
style - Style of the shape - (1) LINE or (2) SOLID FILL
lineWidth - Line width of the shape

AlcShape

public AlcShape()
Creates a blank AlcShape object


AlcShape

public AlcShape(java.awt.geom.GeneralPath path)
Creates a new instance of AlcShape with the default values

Parameters:
path - GeneralPath path

AlcShape

public AlcShape(java.awt.geom.GeneralPath path,
                java.awt.Color color,
                int alpha,
                int style,
                float lineWidth)
Creates a new instance of AlcShape with defined values

Parameters:
path - GeneralPath path
color - Color of the shape
alpha - Alpha value of the shape
style - Style of the shape - (1) LINE or (2) SOLID FILL
lineWidth - Line width of the shape
Method Detail

setup

public void setup(java.awt.Color color,
                  int alpha,
                  int style,
                  float lineWidth)
Setup the attributes of a shape

Parameters:
color - Color of the shape
alpha - Alpha value of the shape
style - Style of the shape - (1) LINE or (2) SOLID FILL
lineWidth - Line width of the shape

setup

public void setup()
Set the attributes of this shape (Alpha/Color/Style/LineWidth) to the current values of the canvas


curveTo

public void curveTo(java.awt.Point p)
Add a curve point to the shape This method uses a simple smoothing algorithm to get rid of hard edges

Parameters:
p - Point to curve to

curveTo

public void curveTo(java.awt.geom.Point2D.Float p)
Add a curve point to the shape This method uses a simple smoothing algorithm to get rid of hard edges

Parameters:
p - Point to curve to

lineTo

public void lineTo(java.awt.Point p)
Add a straight line point to the shape

Parameters:
p - Point to draw a line to

lineTo

public void lineTo(java.awt.geom.Point2D.Float p)
Add a straight line point to the shape

Parameters:
p - Point to draw a line to

spineTo

public void spineTo(java.awt.geom.Point2D.Float p,
                    float width)
Add a spine point for variable width lines

Parameters:
p - The point to add
width - The width of the line

createSpine

public void createSpine()
Create the spine - redraws the variable width line based on the spine points


append

public void append(java.awt.geom.GeneralPath newPath,
                   boolean connect)
Append a GeneralPath to this shape

Parameters:
newPath - The path to be appended
connect - Connect the two paths together or not

moveTo

public void moveTo(java.awt.Point p)
Move to the given Point

Parameters:
p - Point to draw a line to

moveTo

public void moveTo(java.awt.geom.Point2D.Float p)
Move to the given Point

Parameters:
p - Point to draw a line to

closePath

public void closePath()
Closes the current subpath by drawing a straight line back to the coordinates of the last moveTo


move

public void move(double x,
                 double y)
Move the shape by the specified distance. Consecutive calls will accumulate the overall distance

Parameters:
x - x distance
y - y distance

scale

public void scale(double sx,
                  double sy)
Scale the shape by a certain factor

Parameters:
sx - X scale factor
sy - Y scale factor

rotate

public void rotate(double theta)
Rotate the shape using the shapes centre as the anchor point

Parameters:
theta - The angle of rotation in radians

rotate

public void rotate(double theta,
                   double x,
                   double y)
Rotate the shape

Parameters:
theta - The angle of rotation in radians
x - The coordinates of the x anchor point
y - The coordinates of the y anchor point

getPath

public java.awt.geom.GeneralPath getPath()
Return the GeneralPath path

Returns:
GeneralPath path

setPath

public void setPath(java.awt.geom.GeneralPath path)
Set the path using a GeneralPath

Parameters:
path -

setPoint

public void setPoint(java.awt.Point p)
Set (or reset perhaps) the shape with a single Point

Parameters:
p -

setPoint

public void setPoint(java.awt.geom.Point2D.Float p)
Set (or reset perhaps) the shape with a single Point

Parameters:
p -

getTotalPoints

public int getTotalPoints()
Return the total number of points in this shape

Returns:
Total number of points

setTotalPoints

public void setTotalPoints(int totalPoints)
Set the total number of points for this shape Useful when creating a duplicate object

Parameters:
totalPoints - Total number of points

recalculateTotalPoints

public void recalculateTotalPoints()
Recalculates the number of points for this shape Useful when shapes have been merged together


getLastPoint

public java.awt.geom.Point2D.Float getLastPoint()
Return the last point

Returns:
The last point

setLastPoint

public void setLastPoint(java.awt.geom.Point2D.Float lastPt)
Set the last point for this shape Useful when creating a duplicate object

Parameters:
lastPt - The last point

getColor

public java.awt.Color getColor()
Get the color of this shape

Returns:
The color

setColor

public void setColor(java.awt.Color color)
Set the color of this shape

Parameters:
color - The color

getAlpha

public int getAlpha()
Get the alpha (transparency) value of this shape

Returns:
Alpha value

setAlpha

public void setAlpha(int alpha)
Set the alpha (transparency) value of this shape

Parameters:
alpha - Alpha value

setAlphaColor

public void setAlphaColor(java.awt.Color color)
Set a color with alpha directly

Parameters:
color -

getStyle

public int getStyle()
Get the style of this shape

Returns:
The style of this shape as AlcConstants.STYLE_STROKE or AlcConstants.STYLE_FILL

setStyle

public void setStyle(int style)
Set the style of this shape

Parameters:
style - The style of this shape either AlcConstants.STYLE_STROKE or AlcConstants.STYLE_FILL

getGradientPaint

public java.awt.GradientPaint getGradientPaint()
Get this shapes Gradient

Returns:
The gradient

setGradientPaint

public void setGradientPaint(java.awt.GradientPaint gradientPaint)
Set this shapes gradient

Parameters:
gradientPaint - The gradient

getLineWidth

public float getLineWidth()
Get the line width of this shape

Returns:
The line width

setLineWidth

public void setLineWidth(float lineWidth)
Set the line width of this shape

Parameters:
lineWidth - The line width

isLineSmoothing

public static boolean isLineSmoothing()
Check if line smoothing is on or off

Returns:
boolean for line smoothing

setLineSmoothing

public static void setLineSmoothing(boolean lineSmoothing)
Set the line smoothing variable for AlcShape

Parameters:
lineSmoothing - boolean to set line smoothing on or off

getBounds

public java.awt.Rectangle getBounds()
Get the bounds of this shape

Returns:
Rectangle representing the shapes bounds

isPathClosed

public boolean isPathClosed()
Return if the path has been closed or not

Returns:
True if the path has been closed else false

isPenShape

public boolean isPenShape()
Return if this shape has been created with pen strokes or not

Returns:
True if this shape has been created with pen strokes or else false

hasSpine

public boolean hasSpine()
Return if this shape uses a spine or not

Returns:
True if the path uses a spine else false

getSpine

public java.util.ArrayList<java.awt.geom.Point2D.Float> getSpine()
Get the spine (used for variable width lines) of this shape

Returns:
An arraylist containing the spine

setSpine

public void setSpine(java.util.ArrayList<java.awt.geom.Point2D.Float> spine)
Set the spine (used for variable width lines) of this shape

Parameters:
spine - An arraylist containing the new spine

getSpineWidth

public java.util.ArrayList<java.lang.Float> getSpineWidth()
Get the spine width (used for variable width lines) of this shape

Returns:
An arraylist containing the spine width

setSpineWidth

public void setSpineWidth(java.util.ArrayList<java.lang.Float> spineWidth)
Set the spine width (used for variable width lines) of this shape

Parameters:
spineWidth - An arraylist containing the new spine width

getPoints

public java.util.ArrayList<java.awt.geom.Point2D.Float> getPoints()
Return a simple list of x,y points from this AlcShape object

Returns:
ArrayList containing x,y points

rightAngle

public static java.awt.geom.Point2D.Float rightAngle(java.awt.geom.Point2D.Float p1,
                                                     java.awt.geom.Point2D.Float p2,
                                                     double distance)
Calculate a right angle perpendicular to the two given points at the given distance

Parameters:
p1 - The first point
p2 - The second point
distance - The distance away from the two points
Returns:
The point at a perpendicular right angle

clone

public java.lang.Object clone()
'Deep' Clone this object using the existing style/color etc.. values

Overrides:
clone in class java.lang.Object
Returns:
An new cloned object of this shape

customClone

public AlcShape customClone(java.awt.geom.GeneralPath tempPath)
A custom clone that adds a new GeneralPath to the shape while keeping all of the style infomation. Note that this function does not clone the spine.

Parameters:
tempPath - A GeneralPath to be added to the AlcShape
Returns:
The cloned shape

customClone

public AlcShape customClone(java.util.ArrayList<java.awt.geom.Point2D.Float> spine,
                            java.util.ArrayList<java.lang.Float> spineWidth)
A custom clone that adds a new spine (variable width line) to the shape the creates the path while keeping all of the style infomation.

Parameters:
spine - The spine of the shape
spineWidth - The width of the spine
Returns:
The cloned shape