package edu.calpoly.csc480.Entomo.Tile;

import java.awt.*;
import javax.swing.*;

abstract public class TileView implements Icon {
	protected static final Dimension defaultSize = new Dimension(50, 10);

	static public Dimension getDefaultSize()	{return defaultSize;}

	public TileView() {
		updateScheme();
		setBounds(0, 0, defaultSize.width, defaultSize.height);
	}

	final public int getIconWidth()			{return width;}
	final public int getIconHeight() 		{return height;}

	public void setDocument(Tile tile)	{
		this.tile = tile;
	}
	
	public void setBounds(int x, int y, int width, int height) {
		this.x = x;
		this.y = y;
		this.width  = width;
		this.height = height;
	}
	
	public abstract void updateScheme();

	public void paintIcon(Component c, Graphics draw, int x, int y) {
		draw.setColor(scheme.dark);
		draw.fillRect(x+0, y+0, width-0, height-0);
		
		draw.setColor(scheme.lite);
		draw.fillRect(x+1, y+1, width-1, height-1);

		draw.setColor(scheme.base);
		draw.fillRect(x+1, y+1, width-2, height-2);
		
		if (text != null && !text.equals("")) {
			draw.setColor(scheme.font);
			draw.drawString(text, x+2, y+height-2);
		}
	}

	final public void paint(Graphics draw) {
		paintIcon(null, draw, x, y);
	}

	protected static class ColorScheme {
		public ColorScheme() {
		}

		public ColorScheme(Color base) {
			this.base = base;
			this.lite = base.brighter().brighter();
			this.dark = base.darker();
			this.font = Color.white;
		}

		public Color base, lite, dark;
		public Color font;
	}

	protected Tile tile;

	protected int x, y, width, height;

	protected ColorScheme scheme;
	
	protected Font font;
	protected String text;
}