package edu.calpoly.csc480.Corral.Agent;

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

abstract public class BaseAgentView
{
	public BaseAgentView() {
		final Dimension smallScreenSize = new Dimension(800, 600);

		Dimension screenSize;

		screenSize = Toolkit.getDefaultToolkit().getScreenSize();

		if (
		 screenSize.width  <= smallScreenSize.width ||
		 screenSize.height <= smallScreenSize.height) {
			iconFileName = getSmallIconFileName();
		}
		else {
			iconFileName = getIconFileName();
		}
	}
	
	final public BaseAgent getDocument()		{return agent;}
	
	final public Icon getIcon()					{return icon;}
	final public Dimension getPreferredSize()	{return size;}
	
	public void setDocument(BaseAgent agent) {
		this.agent = agent;

		try {
			icon = new ImageIcon(iconFileName, agent.getName());

			if (icon.getImageLoadStatus() != MediaTracker.COMPLETE) {
			   icon = new ImageIcon(
			    this.getClass().getResource(iconFileName), agent.getName());
			}
		}
		catch (Exception err) {
			err.printStackTrace(System.err);
			icon = new ImageIcon();
		}

		size = new Dimension(icon.getIconWidth(), icon.getIconHeight());
	}
	
	protected BaseAgent agent;
	
	protected ImageIcon icon;
	protected Dimension size;
	protected String iconFileName;

	protected String getSmallIconFileName() {
		return getIconFileName();
	}

	abstract protected String getIconFileName();
}