//GraphicComposite.java

import java.util.*;
import java.awt.*;

class GraphicComposite extends GraphicComponent {

	/*private*/ Vector componentList;
	protected GraphicComponent currentElement;

	
	
	public GraphicComposite(){
		this(/*0,0*/new Dimension(0,0));
	}
	
	public GraphicComposite(/*int width, int height*/Dimension imgSize){
		super(/*width, height*/imgSize);
		
		this.componentList = new Vector();
	}
	
	
	
	public void draw(Graphics g){
		
		//if it is the first time, 
		if(this.firstTime) {
			drawThisCompFixedImg();
			this.firstTime = false;
		}
		
		//this component has been changed, redraw this component.
		if(this.changed) {
			this.gBuffer.drawImage(this.fixedImg, 0,0, null);
	//		setChanged(false);
		
			Enumeration enum = this.componentList.elements();
		
			while(enum.hasMoreElements()){
				currentElement = (GraphicComponent)enum.nextElement();
				
				if(currentElement.isTranslated())
					this.gBuffer.translate(currentElement.getNewPosition().x,
										   currentElement.getNewPosition().y);
				
				currentElement.draw(this.gBuffer);
				
				if(currentElement.isTranslated())
					this.gBuffer.translate(-1*currentElement.getNewPosition().x,
										   -1*currentElement.getNewPosition().y);			

			}
			
			if(!this.changing) this.setThisComponentChanged(false);			
		}
		g.drawImage(this.bufferImg, 0, 0, null);		
	}
	
	public void addGraphicComponent(GraphicComponent gc){
		this.componentList.addElement(gc);
	}
	
	public void removeGraphicComponent(GraphicComponent gc){
		this.componentList.removeElement(gc);
	}
	
	public void clearGraphicComponents(){
		this.componentList.removeAllElements();
	}

/*	public void constructImages(){
		//create all the images 
		//for all the GraphicComponents(GraphicComposite).
		Enumeration enum = this.componentList.elements();
		Dimension imgSize;
		Image componentImg;
		
		while(enum.hasMoreElements()){
			currentElement = (GraphicComponent)enum.nextElement();
	
			imgSize = currentElement.getImageSize();
			componentImg = createImage(imgSize.width, imgSize.height);
			
			currentElement.setBufferImg(componentImg);
			currentElement.setFixedImg(componentImg);			

			currentElement.constructImages();
		}	
	}
*/	

}