gishur.gui2
Class PolygonShape

java.lang.Object
  |
  +--java.awt.Polygon
        |
        +--gishur.gui2.PolygonShape
All Implemented Interfaces:
java.lang.Cloneable, Cloneable, java.io.Serializable, Shape, java.awt.Shape
Direct Known Subclasses:
LineShape

public class PolygonShape
extends java.awt.Polygon
implements Shape

A PolygonShape represents a polygon. PolygonShape extends Polygon and implements the Shape interface.

Version:
1.0
Author:
Thomas Wolf
See Also:
Serialized Form

Fields inherited from class java.awt.Polygon
bounds, npoints, xpoints, ypoints
 
Constructor Summary
PolygonShape()
          Creates an empty PolygonShape.
PolygonShape(int[] xpoints, int[] ypoints, int length)
          Constructs and initializes a PolygonShape from the specified parameters.
PolygonShape(java.awt.Point[] points)
          Constructs and initializes a PolygonShape from the specified point list.
PolygonShape(java.awt.Point[] points, int start, int len)
          Constructs and initializes a PolygonShape from the specified point list.
PolygonShape(java.awt.Polygon pol)
          Creates a PolygonShape from the specified polygon.
 
Method Summary
 void clear()
           
 java.lang.Object clone()
          Creates a new object of the same class as this object.
 boolean contains(int x, int y)
          Tests if a given coordinate is inside the boundary of the Shape.
 boolean contains(int x, int y, int w, int h)
          Tests if the interior of the Shape entirely contains the specified rectangular area.
 boolean contains(java.awt.Point p)
          Tests if a specified Point is inside the boundary of the Shape.
 void draw(java.awt.Graphics g)
          Strokes the outline of the Shape using the settings of the Graphics context (if visible).
 void fill(java.awt.Graphics g)
          Fills the interior of the Shape using the settings of the Graphics context (if visible).
 java.awt.Rectangle getBounds()
          Returns the bounding box of this EllipseShape.
 RectangleShape getBoundShape()
          Return the bounding box of the Shape.
 java.awt.Point getCenter()
          Returns the center point of the framing rectangle of the Shape.
 int getCenterX()
          Returns the X coordinate of the center of the framing rectangle of the Shape.
 int getCenterY()
          Returns the Y coordinate of the center of the framing rectangle of the Shape.
 boolean intersects(int x, int y, int w, int h)
          Tests if the interior of the Shape intersects the interior of a specified rectangular area.
 void set(int[] xpoints, int[] ypoints)
          Sets the polygon shape to the given points array.
 void set(java.awt.Point[] points, int idx, int len)
          Sets the polygon shape to the given points array.
static void setArrow(boolean right, int x1, int y1, int x2, int y2, int width, int height, int[] xp, int[] yp, int idx)
          Stores the arrow point for a right/left arrow at the given position in the coordinate array.
static void setCurve(int x1, int y1, int x2, int y2, int x3, int y3, int width, int steps, int[] xp, int[] yp, int idx1, int idx2)
          Stores a bezier curve in the given coordinate arrays.
static void setLine(int x1, int y1, int x2, int y2, int width, int[] xp, int[] yp, int idx1, int idx2)
          Stores a line segment (x1,y1)-(x2,y2) with the line width width in the given coordinate arrays.
 void setLocation(int x, int y)
          Moves the this Shape to the specified location.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.awt.Polygon
addPoint, contains, contains, contains, contains, getBoundingBox, getBounds2D, getPathIterator, getPathIterator, inside, intersects, intersects, translate
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gishur.gui2.Shape
translate
 
Methods inherited from interface java.awt.Shape
contains, contains, contains, contains, getBounds2D, getPathIterator, getPathIterator, intersects, intersects
 

Constructor Detail

PolygonShape

public PolygonShape()
Creates an empty PolygonShape.

PolygonShape

public PolygonShape(int[] xpoints,
                    int[] ypoints,
                    int length)
Constructs and initializes a PolygonShape from the specified parameters.
Parameters:
xpoints - an array of x coordinates.
ypoints - an array of y coordinates.
length - the total number of points in the polygon.

PolygonShape

public PolygonShape(java.awt.Polygon pol)
Creates a PolygonShape from the specified polygon.
Parameters:
pol - the polygon.

PolygonShape

public PolygonShape(java.awt.Point[] points)
Constructs and initializes a PolygonShape from the specified point list.
Parameters:
points - array with polygon points

PolygonShape

public PolygonShape(java.awt.Point[] points,
                    int start,
                    int len)
Constructs and initializes a PolygonShape from the specified point list.
Parameters:
points - array with polygon points
start - the start index in the point array
len - the length of the subarray
Method Detail

clone

public java.lang.Object clone()
Creates a new object of the same class as this object.
Specified by:
clone in interface Cloneable
Overrides:
clone in class java.lang.Object
Returns:
a clone of this instance.
Throws:
OutOfMemoryError - if there is not enough memory.
See Also:
Cloneable

toString

public java.lang.String toString()
Returns a string representation of the object.
Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object.

setLine

public static final void setLine(int x1,
                                 int y1,
                                 int x2,
                                 int y2,
                                 int width,
                                 int[] xp,
                                 int[] yp,
                                 int idx1,
                                 int idx2)
Stores a line segment (x1,y1)-(x2,y2) with the line width width in the given coordinate arrays.
Parameters:
x1,y1 - first segment endpoint
x2,y2 - second segment endpoint
width - linewidth
xp - array with the x-coordinates
yp - array with the y-coordinates
idx1 - start index for lower line part
idx2 - start index for upper line part

setCurve

public static final void setCurve(int x1,
                                  int y1,
                                  int x2,
                                  int y2,
                                  int x3,
                                  int y3,
                                  int width,
                                  int steps,
                                  int[] xp,
                                  int[] yp,
                                  int idx1,
                                  int idx2)
Stores a bezier curve in the given coordinate arrays. The curve will be approximated be step points, that means it needs 2*step points to store that curve. The first part (lower part) will be stored beginning at index idx1, the second part (upper part) will be stored beginning at index idx2.
Parameters:
x1,y1 - first bezier point
x2,y2 - second bezier point
x3,y3 - third bezier point
width - line width
step - approximation steps
xp - array of x-coordinates
yp - array of y-coordinates
idx1 - start index for lower part of the curve
idx2 - start index for upper part of the curve

setArrow

public static final void setArrow(boolean right,
                                  int x1,
                                  int y1,
                                  int x2,
                                  int y2,
                                  int width,
                                  int height,
                                  int[] xp,
                                  int[] yp,
                                  int idx)
Stores the arrow point for a right/left arrow at the given position in the coordinate array.
Parameters:
right - if true arrow will point to the right
x1,y1 - source point (if left arrow, this point will be the peek)
x2,y2 - target point (if rigth arrow, this point will be the peek)
width - the arrow width
height - the arrow height
xp - array with the x-coordinates
yp - array with the y-coordinates
idx - start index, where to store arrow

clear

public void clear()

set

public void set(java.awt.Point[] points,
                int idx,
                int len)
Sets the polygon shape to the given points array. All points must not be null and the specified subarray must be valid.
Parameters:
points - the array with points
idx - start index of the subarray
len - the length of the subarray

set

public void set(int[] xpoints,
                int[] ypoints)
Sets the polygon shape to the given points array. All points must not be null and the specified subarray must be valid.
Parameters:
xpoints - the array with x-coordinates of the points
ypoints - the array with y-coordinates of the points

getBounds

public java.awt.Rectangle getBounds()
Returns the bounding box of this EllipseShape.
Specified by:
getBounds in interface java.awt.Shape
Overrides:
getBounds in class java.awt.Polygon
Returns:
a Rectangle that is the bounding box of this EllipseShape.

contains

public boolean contains(int x,
                        int y)
Tests if a given coordinate is inside the boundary of the Shape.
Specified by:
contains in interface Shape
Overrides:
contains in class java.awt.Polygon
Parameters:
x - x-coordinate of the point
y - y-coordinate of the point
Returns:
true if the specified point is inside the boundary of the Shape; false otherwise.

contains

public boolean contains(java.awt.Point p)
Tests if a specified Point is inside the boundary of the Shape.
Specified by:
contains in interface Shape
Overrides:
contains in class java.awt.Polygon
Parameters:
p - a specified point
Returns:
true if the specified point is inside the boundary of the Shape; false otherwise.

intersects

public boolean intersects(int x,
                          int y,
                          int w,
                          int h)
Tests if the interior of the Shape intersects the interior of a specified rectangular area. The rectangular area is considered to intersect the Shape if any point is contained in both the interior of the Shape and the specified rectangular area.
Specified by:
intersects in interface Shape
Parameters:
x, y - the coordinates of the specified rectangular area
w - the width of the specified rectangular area
h - the height of the specified rectangular area
Returns:
true if the interior of the Shape and the interior of the rectangular area intersect; false otherwise.

contains

public boolean contains(int x,
                        int y,
                        int w,
                        int h)
Tests if the interior of the Shape entirely contains the specified rectangular area. All coordinates that lie inside the rectangular area must lie within the Shape for the entire rectanglar area to be considered contained within the Shape.
Specified by:
contains in interface Shape
Parameters:
x, y - the coordinates of the specified rectangular area
w - the width of the specified rectangular area
h - the height of the specified rectangular area
Returns:
true if the interior of the Shape entirely contains the specified rectangular area; false otherwise.
See Also:
intersects(int, int, int, int)

getBoundShape

public RectangleShape getBoundShape()
Return the bounding box of the Shape.
Specified by:
getBoundShape in interface Shape
Returns:
bounding box.

getCenterX

public int getCenterX()
Returns the X coordinate of the center of the framing rectangle of the Shape.
Specified by:
getCenterX in interface Shape
Returns:
X coordinate of the Shape

getCenterY

public int getCenterY()
Returns the Y coordinate of the center of the framing rectangle of the Shape.
Specified by:
getCenterY in interface Shape
Returns:
Y coordinate of the Shape

getCenter

public java.awt.Point getCenter()
Returns the center point of the framing rectangle of the Shape.
Specified by:
getCenter in interface Shape
Returns:
center point of the shape

setLocation

public void setLocation(int x,
                        int y)
Moves the this Shape to the specified location. The location of a polygon is the upper left corner of its bounding box.
Specified by:
setLocation in interface Shape
Parameters:
dx - x coordinate of point to move to
dy - y coordinate of point to move to

draw

public void draw(java.awt.Graphics g)
Strokes the outline of the Shape using the settings of the Graphics context (if visible).
Specified by:
draw in interface Shape
Parameters:
g - Graphics context

fill

public void fill(java.awt.Graphics g)
Fills the interior of the Shape using the settings of the Graphics context (if visible).
Specified by:
fill in interface Shape
Parameters:
g - Graphics context