gishur.gui2
Class ShapeContainer

java.lang.Object
  |
  +--gishur.gui2.ShapeContainer
All Implemented Interfaces:
java.lang.Cloneable, Cloneable, Shape, java.awt.Shape

public class ShapeContainer
extends java.lang.Object
implements Shape

The ShapeContainer class defines a shape which consists of a set of other Shapes. Because Shapes should be static, ShapeContainer caches the bounding box once calculated. The calculation will be automatically updated, if new Shapes are added to the ShapeContainer. The ShapeContainer class contains also some static methods to extract parts of element names or tokenize element names (see #removeContainerName, #getLocalName, #getContainerName, #getParentName, #tokenizeName).

Version:
1.0
Author:
Thomas Wolf

Inner Class Summary
 class ShapeContainer.ShapeEnumeration
          An Enumeration for ShapeContainers.
 
Constructor Summary
ShapeContainer(int length)
          Constructs a new ShapeContainer, which can store length Shapes.
 
Method Summary
 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.
 boolean empty()
          Returns true, if the container contains no Shape.
 ShapeContainer.ShapeEnumeration enumeration()
          Returns a new ShapeContainer.ShapeEnumeration object which enumerates all Shapes contained in the shape hierachy of this ShapeContainer.
 void fill(java.awt.Graphics g)
          Fills the interior of the Shape using the settings of the Graphics context.
 java.awt.Rectangle getBounds()
          Returns the bounding box of this ShapeContainer.
 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 invalidateBounds()
          Invalidates the bounds of the ShapeContainer.
 boolean isEmpty()
          Determines whether or not the bounding box of this ShapeContainer is empty.
 int length()
          Returns the capacity of this container.
 void setLocation(int x, int y)
          Moves the this Shape to the specified location.
 void setShape(int idx, Shape shape)
          Stores the Shape shape at the index idx in the ShapeContainer.
 Shape shape(int idx)
          Returns the stored Shape at the specified index.
 java.lang.String toString()
          Returns a string representation of the object.
 void translate(int dx, int dy)
          Translates this Shape by the vector (x,y).
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.Shape
contains, contains, contains, contains, getBounds2D, getPathIterator, getPathIterator, intersects, intersects
 

Constructor Detail

ShapeContainer

public ShapeContainer(int length)
Constructs a new ShapeContainer, which can store length Shapes.
Parameters:
name - the name of the shape (must not be null).
length - capacity of the ShapeContainer
Method Detail

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.

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

length

public int length()
Returns the capacity of this container.
Returns:
the capacity of this container.

empty

public boolean empty()
Returns true, if the container contains no Shape.
Returns:
true, if empty.

setShape

public void setShape(int idx,
                     Shape shape)
Stores the Shape shape at the index idx in the ShapeContainer.
Parameters:
idx - store index
id - Shape ID
shape - the Shape to store
Throws:
java.lang.IndexOutOfBoundsException - if index was out of bounds

shape

public Shape shape(int idx)
Returns the stored Shape at the specified index.
Parameters:
idx - the index
Returns:
the Shape at the index idx.
Throws:
java.lang.IndexOutOfBoundsException - if index was out of bounds

invalidateBounds

public void invalidateBounds()
Invalidates the bounds of the ShapeContainer.

enumeration

public ShapeContainer.ShapeEnumeration enumeration()
Returns a new ShapeContainer.ShapeEnumeration object which enumerates all Shapes contained in the shape hierachy of this ShapeContainer.
Returns:
ShapeContainer.ShapeEnumeration that enumerates all Shapes in the shape hierachy

isEmpty

public boolean isEmpty()
Determines whether or not the bounding box of this ShapeContainer is empty.
Returns:
true if the bounding rectangle of this ShapeContainer is empty; false otherwise.

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
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
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)

getBounds

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

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

translate

public void translate(int dx,
                      int dy)
Translates this Shape by the vector (x,y).
Specified by:
translate in interface Shape
Parameters:
dx - x coordinate of the translation vector
dy - y coordinate of the translation vector

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.
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.
Specified by:
fill in interface Shape
Parameters:
g - Graphics context