package gizmoball.ui.r2;

import gizmoball.NotImplementedException;
import gizmoball.game.AbstractGizmo;
import gizmoball.game.GameBoard;
import gizmoball.ui.AbstractGameBoardComponent;
import gizmoball.ui.InteractionModeType;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Iterator;

import javax.swing.JPanel;

import org.apache.log4j.Logger;

/**
 * An R2 implementation of a gameboard component.  The 
 * R2 gameboard component represents gizmos in a Graphics2D
 * context using drawers from the <code>R2DrawerFactory</code>.
 * The corresponding R2 interaction modes are used to interface
 * with user control.<p>
 * 
 * @see R2DrawerFactory
 * @see R2EditingInteractionMode
 * @see R2PlayingInteractionMode
 * @see AbstractGameBoardComponent
 * @author Albert Leung
 * @version 1.0
 * 
 */
public class R2GameBoardComponent extends AbstractGameBoardComponent {

	private R2EditingInteractionMode editingMode;
	private R2PlayingInteractionMode playingMode;

	private static Logger logger = Logger.getLogger(R2GameBoardComponent.class);

	public R2GameBoardComponent() {
		super();
		this.editingMode =new R2EditingInteractionMode(this);
		this.playingMode =new R2PlayingInteractionMode(this);
	}

	/* (non-Javadoc)
	 * @see gizmoball.ui.AbstractGameBoardComponent#createGizmoPalette()
	 */
	public JPanel createGizmoPalette() {
		// TODO Auto-generated method stub
		throw new NotImplementedException();
	}

	/* (non-Javadoc)
	 * @see gizmoball.ui.AbstractGameBoardComponent#setMode(gizmoball.ui.InteractionModeType)
	 */
	public void setMode(InteractionModeType type) {
		if (type == InteractionModeType.EDITING) {
			super.setCurrentInteractionMode(editingMode);
		}
		else if (type == InteractionModeType.PLAYING) {
			super.setCurrentInteractionMode(playingMode);
		}
		//else signal error?
	}

	public void paint(Graphics g) {
		Graphics2D g2 =(Graphics2D)g;
		GameBoard gameboard =super.getGameBoard();
		R2DrawerFactory.getDrawer(gameboard).drawGameBoard(g2, gameboard);
		for (Iterator it =gameboard.getGizmos().iterator(); it.hasNext();) {
			AbstractGizmo gizmo =(AbstractGizmo)it.next();
			R2DrawerFactory.getDrawer(gizmo).drawGizmo(g2, gizmo);
//			logger.debug("painting gizmo " + gizmo.getName());
		}
	}

}
