/*
 * Created on Jan 30, 2004
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package org.lucci.madhoc.gui;

import java.awt.Dimension;

import javax.swing.Icon;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;

import org.lucci.madhoc.simulation.Configurable;
import org.lucci.madhoc.simulation.Monitor;


/**
 * @author luc.hogie
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public abstract class MonitorView extends JPanel implements Configurable
{
    private boolean active = false;
    private ProjectionComponent projectionComponent;
    private Monitor monitor;
    private int preferredHeight = 1;

    public MonitorView()
    {   
        setBorder(new EtchedBorder());
        setOpaque(true);
    }

    public Dimension getPreferredSize()
    {
        if ( getParent() == null )
        {
            return new Dimension(50, 50);
        }
        else
        {
            int sum = 0;
            
            for (int i = 0; i < getParent().getComponentCount(); ++i)
            {
                MonitorView sibbling = ((MonitorView) getParent().getComponent(i));
                sum += sibbling.getPreferredHeight(); 
            }

            Dimension dimension = new Dimension(getParent().getSize().width, getParent().getSize().height);
            dimension.height = dimension.height * getPreferredHeight() / sum;
            return dimension; 
        }
    }
    
    public int getPreferredHeight()
    {
        return preferredHeight;
    }

    public void setPreferredHeight(int i)
    {
        preferredHeight = i;
    }


    public Icon getIcon()
    {
        return getMonitor().getIcon();
    }

    
    public ProjectionComponent getProjectionComponent()
    {
        return projectionComponent;
    }
    public void setProjectionComponent(ProjectionComponent projectionComponent)
    {
        if (projectionComponent == null)
            throw new IllegalArgumentException();

        this.projectionComponent = projectionComponent;
    }
    
    public Monitor getMonitor()
    {
        return monitor;
    }
    public void setMonitor(Monitor simulationApplication)
    {
        if (simulationApplication == null)
            throw new IllegalArgumentException();

        this.monitor = simulationApplication;
    }

    public double getSimulatedTimeMillis()
    {
        return getMonitor().getNetwork().getSimulation().getSimulatedTime();
    }

    public boolean isActive()
    {
        return active;
    }

    public void setActive(boolean b)
    {
        active = b;
    }

    public abstract void updateViewContent();

}