sim.portrayal.grid
Class ObjectGridPortrayal2D

java.lang.Object
  extended by sim.portrayal.FieldPortrayal
      extended by sim.portrayal.FieldPortrayal2D
          extended by sim.portrayal.grid.ObjectGridPortrayal2D
All Implemented Interfaces:
java.io.Serializable, Portrayal, Portrayal2D
Direct Known Subclasses:
DenseGridPortrayal2D, FastObjectGridPortrayal2D, HexaObjectGridPortrayal2D

public class ObjectGridPortrayal2D
extends FieldPortrayal2D

A portrayal for grids containing objects, such as maybe agents or agent bodies.

By default this portrayal describes objects as gray ovals (that's what getDefaultPortrayal() returns) and null values as empty regions (that's what getDefaultNullPortrayal() returns). You may wish to override this for your own purposes. The 'location' passed into the DrawInfo2D handed to the SimplePortryal2D is a MutableInt2D.

See Also:
Serialized Form

Nested Class Summary
static class ObjectGridPortrayal2D.Message
           
 
Field Summary
protected  MutableInt2D locationToPass
           
 
Fields inherited from class sim.portrayal.FieldPortrayal2D
DEFAULT, DONT_USE_BUFFER, USE_BUFFER
 
Fields inherited from class sim.portrayal.FieldPortrayal
classPortrayals, field, immutableField, portrayalForAll, portrayalForNonNull, portrayalForNull, portrayalForRemainder, portrayals
 
Constructor Summary
ObjectGridPortrayal2D()
           
 
Method Summary
 Portrayal getDefaultNullPortrayal()
          Returns a default portrayal for null.
 Portrayal getDefaultPortrayal()
          Should return a portrayal which can portray any object regardless of whether it's valid or not
 java.awt.geom.Point2D.Double getLocationPosition(java.lang.Object location, DrawInfo2D info)
          Returns the position on-screen of the provided location in the underlying field.
 java.lang.Object getObjectLocation(java.lang.Object object, GUIState gui)
          Returns the first location in the underlying field of the given object, if such a thing is reasonable.
 java.lang.Object getPositionLocation(java.awt.geom.Point2D.Double position, DrawInfo2D info)
          Returns the Location, in the parlance of the underlying Field, of the given position.
 Double2D getScale(DrawInfo2D info)
          Returns the width and height, in pixels, of 1.0 x 1.0 units in the underlying field.
 LocationWrapper getWrapper(java.lang.Object object, Int2D location)
           
protected  void hitOrDraw(java.awt.Graphics2D graphics, DrawInfo2D info, Bag putInHere)
          Instead of overriding the draw and hitObjects methods, you can optionally override this method to provide both the draw(...) and hitObjects(...) functionality in a single method, as it's common that these two methods have nearly identical code.
 void setField(java.lang.Object field)
          Sets the field, and sets the dirtyField flag to true.
 boolean setSelected(LocationWrapper wrapper, boolean selected)
          Selects or deselects all of the provided objects.
 
Methods inherited from class sim.portrayal.FieldPortrayal2D
draw, getBuffering, getClipLocation, getObjectPosition, getRelativeObjectPosition, hitObjects, setBuffering, setObjectPosition
 
Methods inherited from class sim.portrayal.FieldPortrayal
getField, getInspector, getName, getPortrayalForAll, getPortrayalForNonNull, getPortrayalForNull, getPortrayalForObject, getPortrayalForRemainder, getStatus, isDirtyField, isImmutableField, reset, setDirtyField, setImmutableField, setPortrayalForAll, setPortrayalForClass, setPortrayalForNonNull, setPortrayalForNull, setPortrayalForObject, setPortrayalForRemainder, setSelected
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface sim.portrayal.Portrayal
getInspector, getName, getStatus
 

Field Detail

locationToPass

protected final MutableInt2D locationToPass
Constructor Detail

ObjectGridPortrayal2D

public ObjectGridPortrayal2D()
Method Detail

setField

public void setField(java.lang.Object field)
Description copied from class: FieldPortrayal
Sets the field, and sets the dirtyField flag to true. May throw an exception if the field is inappropriate. The default version just sets the field and sets the dirtyField flag.

Overrides:
setField in class FieldPortrayal

getDefaultPortrayal

public Portrayal getDefaultPortrayal()
Description copied from class: FieldPortrayal
Should return a portrayal which can portray any object regardless of whether it's valid or not

Overrides:
getDefaultPortrayal in class FieldPortrayal2D

getDefaultNullPortrayal

public Portrayal getDefaultNullPortrayal()
Description copied from class: FieldPortrayal
Returns a default portrayal for null. By default this is set to the same as getDefaultPortrayal(). Override this to provide a more interesting default portrayals for null.

Overrides:
getDefaultNullPortrayal in class FieldPortrayal

getScale

public Double2D getScale(DrawInfo2D info)
Description copied from class: FieldPortrayal2D
Returns the width and height, in pixels, of 1.0 x 1.0 units in the underlying field. Optionally overridable. The default version thows an error if called.

Overrides:
getScale in class FieldPortrayal2D

getPositionLocation

public java.lang.Object getPositionLocation(java.awt.geom.Point2D.Double position,
                                            DrawInfo2D info)
Description copied from class: FieldPortrayal2D
Returns the Location, in the parlance of the underlying Field, of the given position. If there is no such Location, then null is returned. Optionally overridable. By default null is returned.

Overrides:
getPositionLocation in class FieldPortrayal2D

getObjectLocation

public java.lang.Object getObjectLocation(java.lang.Object object,
                                          GUIState gui)
Description copied from class: FieldPortrayal2D
Returns the first location in the underlying field of the given object, if such a thing is reasonable. Largely used for getObjectPosition(...). If null is returned, then the portrayal is unable to determine the position of the field location. Optionally overridable. The default implementation returns null.

Overrides:
getObjectLocation in class FieldPortrayal2D

getLocationPosition

public java.awt.geom.Point2D.Double getLocationPosition(java.lang.Object location,
                                                        DrawInfo2D info)
Description copied from class: FieldPortrayal2D
Returns the position on-screen of the provided location in the underlying field. Negative positions are acceptable. If null is returned, then the portrayal is unable to perform the requested action on the given location. Optionally overridable. The default implementation returns null.

Overrides:
getLocationPosition in class FieldPortrayal2D

hitOrDraw

protected void hitOrDraw(java.awt.Graphics2D graphics,
                         DrawInfo2D info,
                         Bag putInHere)
Description copied from class: FieldPortrayal2D
Instead of overriding the draw and hitObjects methods, you can optionally override this method to provide both the draw(...) and hitObjects(...) functionality in a single method, as it's common that these two methods have nearly identical code. You should test which operation to do based on whether or not graphics is null (if it is, you're hitting, else you're drawing).

Overrides:
hitOrDraw in class FieldPortrayal2D

getWrapper

public LocationWrapper getWrapper(java.lang.Object object,
                                  Int2D location)

setSelected

public boolean setSelected(LocationWrapper wrapper,
                           boolean selected)
Description copied from class: FieldPortrayal
Selects or deselects all of the provided objects.

Specified by:
setSelected in interface Portrayal
Overrides:
setSelected in class FieldPortrayal