acm.graphics
Class GCompound

java.lang.Object
  |
  +--acm.graphics.GObject
        |
        +--acm.graphics.GCompound

public class GCompound extends GObject implements GContainer

This class defines a graphical object that consists of a collection of other graphical objects. Once assembled, the internal objects can be manipulated as a unit.


Field Summary
static int BACK_TO_FRONT
Specifies that iterators should run from back to front
static int FRONT_TO_BACK
Specifies that iterators should run from front to back
 
Constructor Summary
GCompound()
Creates a new GCompound object with no internal components.
 
Method Summary
void add(GObject gobj)
Adds a new graphical object to this GCompound.
void add(GObject gobj, double x, double y)
Adds a new graphical object to this GCompound and sets its location to the point (xy).
void add(GObject gobj, java.awt.Point pt)
Adds the graphical object to this and sets its location to the specified point.
Rectangle getBounds()
Returns the bounding rectangle for this compound object, which consists of the union of the bounding rectangles for each of the components.
GObject getElement(int index)
Returns the graphical object at the specified index, numbering from back to front in the stacking order.
GObject getElementAt(double x, double y)
Returns the topmost graphical object that contains the point (x, y), or null if no such object exists.
GObject getElementAt(Point pt)
Returns the topmost graphical object that contains the specified point, or null if no such object exists.
int getElementCount()
Returns the number of graphical objects stored in this container.
double getHeight()
Returns the height of this compound object, which is the vertical extent of its components.
Dimension getSize()
Returns the size of this compound object, which is defined to be the size of the bounding box containing all of its components.
double getWidth()
Returns the width of this compound object, which is the horizontal extent of its components.
Iterator iterator()
Returns an Iterator that cycles through the elements within this container in the default direction, which is from back to front.
Iterator iterator(int direction)
Returns an Iterator that cycles through the elements within this container in the specified direction, which must be one of the constants FRONT_TO_BACK or BACK_TO_FRONT.
void paint(Graphics g)
Implements the paint operation for this graphical object.
void remove(GObject gobj)
Removes a graphical object from this GCompound.
void removeAll()
Removes all graphical objects from this GCompound.
void scale(double sx, double sy)
Scales every object contained in this compound by the scale factors sx and sy.
 

Inherited Method Summary
void addMouseListener(MouseListener listener)
Adds a mouse listener to this graphical object. [Inherited from GObject]
void addMouseMotionListener(MouseMotionListener listener)
Adds a mouse motion listener to this graphical object. [Inherited from GObject]
boolean contains(double x, double y)
Checks to see whether a point is inside the object. [Inherited from GObject]
Point getLocation()
Returns the nearest Point corresponding to the location of this object. [Inherited from GObject]
double getX()
Returns the x-coordinate of the object. [Inherited from GObject]
double getY()
Returns the y-coordinate of the object. [Inherited from GObject]
boolean isVisible()
Checks to see whether this object is visible. [Inherited from GObject]
void moveToBack()
Moves this object to the back of the display in stacking order. [Inherited from GObject]
void moveToFront()
Moves this object to the front of the display in stacking order. [Inherited from GObject]
void removeMouseListener(MouseListener listener)
Removes a mouse listener from this graphical object. [Inherited from GObject]
void removeMouseMotionListener(MouseMotionListener listener)
Removes a mouse motion listener from this graphical object. [Inherited from GObject]
void scale(double sf)
Scales the object on the screen by the scale factor sf, which applies in both dimensions. [Inherited from GObject]
void setLocation(double x, double y)
Sets the location of this object to the point (x, y). [Inherited from GObject]
void setVisible(boolean visible)
Sets whether this object is visible. [Inherited from GObject]
void translate(double dx, double dy)
Moves the object on the screen using the displacements dx and dy. [Inherited from GObject]

Field Detail

public static final int BACK_TO_FRONT

Specifies that iterators should run from back to front

public static final int FRONT_TO_BACK

Specifies that iterators should run from front to back
Constructor Detail

public GCompound()

Creates a new GCompound object with no internal components.
 
Usage: GCompound gcomp = new GCompound();
 
Method Detail

public void add(GObject gobj)

Adds a new graphical object to this GCompound.
 
Usage: gcomp.add(gobj);
Parameter: 
gobj  The graphical object to add
Specified by: add in interface GContainer
 

public void add(GObject gobj, double x, double y)

Adds a new graphical object to this GCompound and sets its location to the point (xy).
 
Usage: gcomp.add(gobj);
Parameters: 
gobj  The graphical object to add
x  The new x-coordinate for the object
y  The new y-coordinate for the object
Specified by: add in interface GContainer
 

public final void add(GObject gobj, Point pt)

Adds the graphical object to this and sets its location to the specified point.
 
Usage: gcomp.add(gobj, pt);
Parameters: 
gobj  The graphical object to add
pt  A Point object giving the coordinates of the point
Specified by: add in interface GContainer
 

public Rectangle getBounds()

Returns the bounding rectangle for this compound object, which consists of the union of the bounding rectangles for each of the components.
 
Usage: Rectangle bounds = gcomp.getBounds();
Returns: A Rectangle that bounds the components of this object
 

public GObject getElement(int index)

Returns the graphical object at the specified index, numbering from back to front in the stacking order.
 
Usage: GObject gobj = gcomp.getElement(index);
Parameter: 
index  The index of the component to return
Returns: The graphical object at the specified index
Specified by: getElement in interface GContainer
 

public GObject getElementAt(double x, double y)

Returns the topmost graphical object that contains the point (x, y), or null if no such object exists. Note that these coordinates are relative to the location of the compound object and not to the canvas in which it is displayed.
 
Usage: GObject gobj = gcomp.getElementAt(x, y);
Parameters: 
x  The x-coordinate of the point being tested
y  The y-coordinate of the point being tested
Returns: The graphical object at the specified location, or null if no such object exists
Specified by: getElementAt in interface GContainer
 

public final GObject getElementAt(Point pt)

Returns the topmost graphical object that contains the specified point, or null if no such object exists.
 
Usage: GObject gobj = gc.getElementAt(pt);
Parameter: 
pt  The coordinates being tested
Returns: The graphical object at the specified location, or null if no such object exists
Specified by: getElementAt in interface GContainer
 

public int getElementCount()

Returns the number of graphical objects stored in this container.
 
Usage: int n = gcomp.getElementCount();
Returns: The number of graphical objects in this container
Specified by: getElementCount in interface GContainer
 

public double getHeight()

Returns the height of this compound object, which is the vertical extent of its components.
 
Usage: double height = gcomp.getHeight();
Returns: The height of this object on the screen
 

public Dimension getSize()

Returns the size of this compound object, which is defined to be the size of the bounding box containing all of its components.
 
Usage: Dimension size = gcomp.getSize();
Returns: The size of this object
 

public double getWidth()

Returns the width of this compound object, which is the horizontal extent of its components.
 
Usage: double width = gcomp.getWidth();
Returns: The width of this object
 

public Iterator iterator()

Returns an Iterator that cycles through the elements within this container in the default direction, which is from back to front. You can also run the iterator in the opposite direction by using the iterator(direction) form of this method.

Applets that want to run in browsers, however, should avoid using this method, because Iterator is not supported on 1.1 browsers. For maximum portability, you should rely instead on the getElementCount and getElement methods, which provide the same functionality in a browser-compatible way.

 
Usage: Iterator i = gc.iterator();
Returns: An Iterator ranging over the elements of the container from back to front
 

public Iterator iterator(int direction)

Returns an Iterator that cycles through the elements within this container in the specified direction, which must be one of the constants FRONT_TO_BACK or BACK_TO_FRONT.

  for (Iterator i = gc.iterator(direction); i.hasNext(); )

Applets that want to run in browsers, however, should avoid using this method, because Iterator is not supported on 1.1 browsers. For maximum portability, you should rely instead on the getElementCount and getElement methods, which provide the same functionality in a browser-compatible way.

 
Usage: Iterator i = gc.iterator(direction);
Returns: An Iterator ranging over the elements of the container in the specified direction
 

public void paint(Graphics g)

Implements the paint operation for this graphical object. This method is not called directly by clients.

public void remove(GObject gobj)

Removes a graphical object from this GCompound.
 
Usage: gcomp.remove(gobj);
Parameter: 
gobj  The graphical object to remove
Specified by: remove in interface GContainer
 

public void removeAll()

Removes all graphical objects from this GCompound.
 
Usage: gcomp.removeAll();
Specified by: removeAll in interface GContainer
 

public void scale(double sx, double sy)

Scales every object contained in this compound by the scale factors sx and sy. Automatic repaint is turned off during the scaling operation so that at most one repaint is performed.
 
Usage: gcomp.scale(sx, sy);
Parameters: 
sx  The factor used to scale all coordinates in the x direction
sy  The factor used to scale all coordinates in the y direction