Class Star2D
- java.lang.Object
-
- org.jdesktop.swingx.geom.Star2D
-
- All Implemented Interfaces:
java.awt.Shape
public class Star2D extends java.lang.Object implements java.awt.ShapeThis class provides a star shape. A star is defined by two radii and a number of branches. Each branch spans between the two radii. The inner radius is the distance between the center of the star and the origin of the branches. The outer radius is the distance between the center of the star and the tips of the branches.
-
-
Field Summary
Fields Modifier and Type Field Description private intbranchesCountprivate doubleinnerRadiusprivate doubleouterRadiusprivate java.awt.ShapestarShapeprivate doublexprivate doubley
-
Constructor Summary
Constructors Constructor Description Star2D(double x, double y, double innerRadius, double outerRadius, int branchesCount)Creates a new star whose center is located at the specifiedxandycoordinates.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(double x, double y)booleancontains(double x, double y, double w, double h)booleancontains(java.awt.geom.Point2D p)booleancontains(java.awt.geom.Rectangle2D r)private static java.awt.ShapegenerateStar(double x, double y, double innerRadius, double outerRadius, int branchesCount)java.awt.RectanglegetBounds()java.awt.geom.Rectangle2DgetBounds2D()intgetBranchesCount()Returns the number of branches of the star.doublegetInnerRadius()Returns the distance between the center of the star and the origin of the branches.doublegetOuterRadius()Returns the distance between the center of the star and the tips of the branches.java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform at)java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform at, double flatness)doublegetX()Returns the location of the center of star.doublegetY()Returns the location of the center of star.booleanintersects(double x, double y, double w, double h)booleanintersects(java.awt.geom.Rectangle2D r)voidsetBranchesCount(int branchesCount)Sets the number branches of the star.voidsetInnerRadius(double innerRadius)Sets the inner radius of the star, that is the distance between its center and the origin of the branches.voidsetOuterRadius(double outerRadius)Sets the outer radius of the star, that is the distance between its center and the tips of the branches.voidsetX(double x)Sets location of the center of the star.voidsetY(double y)Sets the location of the center of the star.
-
-
-
Constructor Detail
-
Star2D
public Star2D(double x, double y, double innerRadius, double outerRadius, int branchesCount)Creates a new star whose center is located at the specified
xandycoordinates. The number of branches and their length can be specified.- Parameters:
x- the location of the star centery- the location of the star centerinnerRadius- the distance between the center of the star and the origin of the branchesouterRadius- the distance between the center of the star and the tip of the branchesbranchesCount- the number of branches in this star; must be >= 3- Throws:
java.lang.IllegalArgumentException- ifbranchesCountis < 3 or ifinnerRadiusis >=outerRadius
-
-
Method Detail
-
generateStar
private static java.awt.Shape generateStar(double x, double y, double innerRadius, double outerRadius, int branchesCount)
-
setInnerRadius
public void setInnerRadius(double innerRadius)
Sets the inner radius of the star, that is the distance between its center and the origin of the branches. The inner radius must always be lower than the outer radius.
- Parameters:
innerRadius- the distance between the center of the star and the origin of the branches- Throws:
java.lang.IllegalArgumentException- if the inner radius is >= outer radius
-
setX
public void setX(double x)
Sets location of the center of the star.
- Parameters:
x- the x location of the center of the star
-
setY
public void setY(double y)
Sets the location of the center of the star.
- Parameters:
y- the x location of the center of the star
-
setOuterRadius
public void setOuterRadius(double outerRadius)
Sets the outer radius of the star, that is the distance between its center and the tips of the branches. The outer radius must always be greater than the inner radius.
- Parameters:
outerRadius- the distance between the center of the star and the tips of the branches- Throws:
java.lang.IllegalArgumentException- if the inner radius is >= outer radius
-
setBranchesCount
public void setBranchesCount(int branchesCount)
Sets the number branches of the star. A star must always have at least 3 branches.
- Parameters:
branchesCount- the number of branches- Throws:
java.lang.IllegalArgumentException- ifbranchesCountis <=2
-
getX
public double getX()
Returns the location of the center of star.
- Returns:
- the x coordinate of the center of the star
-
getY
public double getY()
Returns the location of the center of star.
- Returns:
- the y coordinate of the center of the star
-
getInnerRadius
public double getInnerRadius()
Returns the distance between the center of the star and the origin of the branches.
- Returns:
- the inner radius of the star
-
getOuterRadius
public double getOuterRadius()
Returns the distance between the center of the star and the tips of the branches.
- Returns:
- the outer radius of the star
-
getBranchesCount
public int getBranchesCount()
Returns the number of branches of the star.
- Returns:
- the number of branches, always >= 3
-
getBounds
public java.awt.Rectangle getBounds()
- Specified by:
getBoundsin interfacejava.awt.Shape
-
getBounds2D
public java.awt.geom.Rectangle2D getBounds2D()
- Specified by:
getBounds2Din interfacejava.awt.Shape
-
contains
public boolean contains(double x, double y)- Specified by:
containsin interfacejava.awt.Shape
-
contains
public boolean contains(java.awt.geom.Point2D p)
- Specified by:
containsin interfacejava.awt.Shape
-
intersects
public boolean intersects(double x, double y, double w, double h)- Specified by:
intersectsin interfacejava.awt.Shape
-
intersects
public boolean intersects(java.awt.geom.Rectangle2D r)
- Specified by:
intersectsin interfacejava.awt.Shape
-
contains
public boolean contains(double x, double y, double w, double h)- Specified by:
containsin interfacejava.awt.Shape
-
contains
public boolean contains(java.awt.geom.Rectangle2D r)
- Specified by:
containsin interfacejava.awt.Shape
-
getPathIterator
public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
- Specified by:
getPathIteratorin interfacejava.awt.Shape
-
getPathIterator
public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at, double flatness)- Specified by:
getPathIteratorin interfacejava.awt.Shape
-
-