/*
 * Object Class for Hierarchical Modeling
 * 
 * Don Fussell
 * October 2002
 */

import java.util.*;
import java.awt.*;
import java.awt.geom.*;

public class GrObject {

    private ArrayList shapeList;
    private ArrayList instanceList;
    private ListIterator shapeI;
    private ListIterator instanceI;

    // Constructor, creates lists for the shapes and the
    // subinstances in the object. We use iterators to let
    // us go through these lists when we draw.
    public GrObject() {   
	shapeList = new ArrayList();
	shapeI = shapeList.listIterator();
	instanceList = new ArrayList();
	instanceI = instanceList.listIterator();
    }

    // Add a shape to the object.  The "previous" method is invoked
    // because we want to draw it after we've added it.
    public void addShape(Shape s) {
	shapeI.add(s);
	shapeI.previous();
    }

    // Add an instance to the object.  The "previous" method is invoked
    // because we want to draw it after we've added it.
    public void addInstance(GrInstance i) {
	instanceI.add(i);
	instanceI.previous();
    }

    // Return the next shape in the object. The calling code should use
    // moreShapes first to make sure null is never returned.
    public Shape nextShape() {
	if (this.moreShapes()) return (Shape)shapeI.next();
	return null;
    }

    // Return the next instance in the object. The calling code should use
    // moreInstances first to make sure null is never returned.
    public GrInstance nextInstance() {
	if (this.moreInstances()) return (GrInstance)instanceI.next();
	return null;
    }

    // Are there more shapes to draw?
    public boolean moreShapes() {
	boolean more = shapeI.hasNext();
	if (!more && !shapeList.isEmpty())
	    shapeI = shapeList.listIterator();
	return more;
    }

    // Are there more instances to draw?
    public boolean moreInstances() {
	boolean more = instanceI.hasNext();
	if (!more && !instanceList.isEmpty())
	    instanceI = instanceList.listIterator();
	return more;
    }
}
