package edu.calpoly.csc480.Corral.Tile;

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

abstract public class TileView extends BaseTileView {
	public TileView() {
	}

	final public Color getColor()		{return color;}
	final public String getText()		{return text;}
	
	public void setBounds(int x, int y, int width, int height) {
		super.setBounds(x, y, width, height);

		shape     = new Rectangle(x + 1, y + 1, width - 2, height - 2);
		liteShape = new Rectangle(x + 0, y + 0, width - 0, height - 0);
		darkShape = new Rectangle(x + 1, y + 1, width - 1, height - 1);
	}
	
	public void setColor(Color color) {
		this.color = color;
		this.liteColor = color.brighter().brighter().brighter();
		this.darkColor = color.darker();
	}
	
	public void setText(String text) {
		final int fontSize = 10;
		
		this.text = text;
		this.font = new Font("Serif", Font.BOLD, fontSize);
		this.fontColor = Color.white;
	}

	public void paint(Graphics drawBase) {
		Color oldColor;
		Graphics2D draw = (Graphics2D)drawBase;

		oldColor = draw.getColor();

		draw.setColor(liteColor);
		draw.fill(liteShape);
		
		draw.setColor(darkColor);
		draw.fill(darkShape);

		draw.setColor(color);
		draw.fill(shape);
		
		if (text != null && !text.equals("")) {
			paintText(draw);
		}

		draw.setColor(oldColor);
	}

	protected Color color;
	protected Color liteColor, darkColor;
	
	protected Shape shape;
	protected Shape liteShape, darkShape;
	
	protected Color fontColor;
	protected Font font;
	protected String text;
	
	protected void paintText(Graphics2D draw) {
		int x, y;
		Font oldFont;

		oldFont = draw.getFont();
		
		draw.setColor(fontColor);
		draw.setFont(font);

		x = bounds.x + 2;
		y = bounds.y + bounds.height - 2;

		draw.drawString(text, x, y);
		draw.setFont(oldFont);
	}
}