All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sim.portrayal.grid.DenseGridPortrayal2D Maven / Gradle / Ivy

Go to download

MASON is a fast discrete-event multiagent simulation library core in Java, designed to be the foundation for large custom-purpose Java simulations, and also to provide more than enough functionality for many lightweight simulation needs. MASON contains both a model library and an optional suite of visualization tools in 2D and 3D.

The newest version!
/*
  Copyright 2006 by Sean Luke and George Mason University
  Licensed under the Academic Free License version 3.0
  See the file "LICENSE" for more information
*/

package sim.portrayal.grid;
import sim.portrayal.*;
import sim.portrayal.simple.*;
import sim.field.grid.*;
import java.awt.*;
import java.awt.geom.*;
import sim.util.*;
import java.util.*;
import sim.display.*;

/**
   Portrayal for Dense grids: grids of Bags of objects.
   
   The 'location' passed
   into the DrawInfo2D handed to the SimplePortryal2D is a MutableInt2D.
*/

public class DenseGridPortrayal2D extends ObjectGridPortrayal2D
    {
    public DrawPolicy policy;

    public DenseGridPortrayal2D()
        {
        super();
        }
        
    /** @IgnoreWarnings 
        @deprecated Use setDrawPolicy. */
    public DenseGridPortrayal2D (DrawPolicy policy)
        {
        super();
        this.policy = policy;
        }

    public void setDrawPolicy(DrawPolicy policy)
        {
        this.policy = policy;
        }

    public DrawPolicy getDrawPolicy()
        {
        return policy;
        }

    public void setField(Object field)
        {
        if (field instanceof DenseGrid2D ) super.setField(field);
        else throw new RuntimeException("Invalid field for DenseGridPortrayal2D: " + field);
        }
        
    public Object getObjectLocation(Object object, GUIState gui)
        {
        synchronized(gui.state.schedule)
            {
            final DenseGrid2D field = (DenseGrid2D) this.field;
            if (field==null) return null;

            int maxX = field.getWidth(); 
            int maxY = field.getHeight();
            if (maxX == 0 || maxY == 0) return null;

            // find the object.
            for(int x=0; x < maxX; x++)
                {
                Object[] fieldx = field.field[x];
                for(int y = 0; y < maxY; y++)
                    {
                    Bag objects = (Bag)(fieldx[y]);
                    if (objects == null) continue;
                    for(int i=0;i maxX) endx = maxX;
        if (endy > maxY) endy = maxY;
        if( startx < 0 ) startx = 0;
        if( starty < 0 ) starty = 0;
        for(int x=startx;x




© 2015 - 2025 Weber Informatics LLC | Privacy Policy