package gizmoball.ui.r2;

import gizmoball.NotImplementedException;
import gizmoball.game.AbstractGizmo;
import gizmoball.game.AbstractGizmoWithPolygonalGeometry;
import gizmoball.game.BallGizmo;
import gizmoball.game.CircleBumperGizmo;
import gizmoball.game.FlipperGizmo;
import gizmoball.game.GameBoard;

/**
 * A factory for the R2 drawers used to paint gizmos and other
 * components onto the gameboard component.  The factory dispatches
 * on gizmo/object type and returns the appropriate R2GizmoDrawer or
 * miscellaneous R2Drawer to paint the object.
 * 
 * @author Albert Leung
 * @version $Id: R2DrawerFactory.java,v 1.6 2004/04/27 19:55:20 aleung Exp $
 * 
 */
public class R2DrawerFactory {
	
	/**
	 * The factory method for R2GizmoDrawer instances.  Dispatches 
	 * on object type and retrieves the singleton drawer for the
	 * given object.
	 * 
	 * @param gizmo the gizmo for which to get a drawer
	 * @return the R2GizmoDrawer that will paint the gizmo
	 * @throws NotImplementedException if no drawers can handle
	 * the gizmo
	 * 
	 */
	public static R2GizmoDrawer getDrawer(AbstractGizmo gizmo) {
		if (gizmo instanceof AbstractGizmoWithPolygonalGeometry) {
			return R2PolygonDrawer.getInstance();
		}
		else if (gizmo instanceof CircleBumperGizmo) {
			return R2CircleDrawer.getInstance();
		}
		else if (gizmo instanceof BallGizmo) {
			return R2BallDrawer.getInstance();
		}
		else if (gizmo instanceof FlipperGizmo) {
		 	return R2FlipperDrawer.getInstance();
		}
		throw new NotImplementedException();
	}

	/**
	 * The factory method for a drawer for the gameboard.
	 * 
	 * @param board the gameboard for which to get a drawer
	 * @return the R2GameBoardDrawer that will paint the board
	 * 
	 */
	public static R2GameBoardDrawer getDrawer(GameBoard board) {
		return R2GameBoardDrawer.getInstance();
	}

}
