/*
 * (c) 1998-2000 The Brookings Institution, All Rights Reserved
 *
 * Permission to use this software and its documentation for non-commercial
 * purposes and without fee is hereby granted, provided this copyright statement
 * is included. Please contact us for permission for redistribution and other uses.
 * 
 * BROOKINGS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, 
 * OR NON-INFRINGEMENT. BROOKINGS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
 * LICENSEE AS A RESULT OF USING THIS SOFTWARE OR ITS DERIVATIVES.
 *
 * _Sugarscape_
 * See _Growing Artificial Societies: Social Science from the Ground Up_
 * Brookings Institution Press, The MIT Press
 * Joshua Epstein
 * jepstein@brook.edu
 * Robert Axtell
 * raxtell@brook.edu
 *
 * Miles Parker
 * mparker@brook.edu

 * http://www.brook.edu/es/dynamics/models/ascape
 * The Brookings Institution
 * Washington, D.C.
 */

package edu.brook.sugarscape;

import java.lang.*;
import java.awt.*;
import java.applet.*;

import edu.brook.ascape.model.*;
import edu.brook.ascape.view.*;
import edu.brook.ascape.util.*;

public class GAS_II_8 extends GAS_II_2 {

    protected Overhead2DView pollutionView;

    public void createScape() {
        super.createScape();
        sugarscape.setPrototypeAgent(new PollutableSugarCell());
        PollutingSugarAgent agent = new PollutingSugarAgent();
        agent.setHostScape(sugarscape);
		agents.setPrototypeAgent(agent);
		agents.setExtent(new Coordinate1DDiscrete(300));
	}
	
	public void createViews() {
		super.createViews();
		sugarView = new Overhead2DView();
		ColorFeatureGradiated cellColor = new ColorFeatureGradiated("Sugar");
		cellColor.setDataPoint(new UnitIntervalDataPoint() {
            public double getValue(Object object) {
                return ((double) (double) ((SugarCell) object).getSugarQuantity() / (double) SugarCell.MAX_SUGAR);
            }
		});
		cellColor.setMaximumColor(Color.yellow);
		sugarView.setCellColorFeature(cellColor);
		sugarView.setAgentColorFeature(ColorFeatureFixed.red);
		sugarView.setCellSize(6);
		//sugarscape.addView(sugarView);
		if (ViewFrameBridge.isInApplet()) {
		    ViewFrameBridge.getAppletModelPanel().add("Center", sugarView);
		}
		pollutionView = new Overhead2DView();
		ColorFeatureGradiated pollutionCellColor = new ColorFeatureGradiated("Pollution Level");
		pollutionCellColor.setDataPoint(new UnitIntervalDataPoint() {
            public double getValue(Object object) {
                return ((double) (double) ((PollutableSugarCell) object).getPollution() / (double) ((PollutableSugarCell) object).getMaxPollution());
            }
		});
		pollutionCellColor.setMaximumColor(Color.green);
		pollutionView.setCellColorFeature(pollutionCellColor);
		pollutionView.setCellSize(6);
		pollutionView.setAgentColorFeature(ColorFeatureFixed.red);
		ComponentView[] views = new ComponentView[2];
		views[0] = sugarView;
		views[1] = pollutionView;
		sugarscape.addViews(views);
		if (ViewFrameBridge.isInApplet()) {
	        ViewFrameBridge.getAppletModelPanel().setLayout(new GridLayout(2, 2));
		    ViewFrameBridge.getAppletModelPanel().removeAll();
		    ViewFrameBridge.getAppletModelPanel().add(sugarView);
		    ViewFrameBridge.getAppletModelPanel().add(pollutionView);
		    ViewFrameBridge.getAppletModelPanel().setSize(600, 600);
		}
    }
}
