Package sim.portrayal.grid
Class ObjectGridPortrayal2D
java.lang.Object
sim.portrayal.FieldPortrayal
sim.portrayal.FieldPortrayal2D
sim.portrayal.grid.ObjectGridPortrayal2D
- All Implemented Interfaces:
Portrayal
,Portrayal2D
- Direct Known Subclasses:
DenseGridPortrayal2D
,FastObjectGridPortrayal2D
,HexaObjectGridPortrayal2D
,ObjectGrid3DPortrayal2D
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.
-
Nested Class Summary
-
Field Summary
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
-
Method Summary
Modifier and TypeMethodDescriptionReturns a default portrayal for null.Should return a portrayal which can portray any object regardless of whether it's valid or notgetLocationPosition
(Object location, DrawInfo2D info) Returns the position on-screen of the provided location in the underlying field.getObjectLocation
(Object object, GUIState gui) Returns the first location in the underlying field of the given object, if such a thing is reasonable.getPositionLocation
(Point2D.Double position, DrawInfo2D info) Returns the Location, in the parlance of the underlying Field, of the given position.getScale
(DrawInfo2D info) Returns the width and height, in pixels, of 1.0 x 1.0 units in the underlying field.getWrapper
(Object object, Int2D location) protected void
hitOrDraw
(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
setBorder
(boolean on) Turns border lines on or off.void
setBorderColor
(Color val) Sets the border color.void
setBorderLineFraction
(double val) Sets the border line fraction.void
setBorderLineMinMaxWidth
(double min, double max) Sets the minimum and maximum width of a border line in pixels.void
Sets the field, and sets the dirtyField flag to true.void
setGridColor
(Color val) Sets the grid color.void
setGridLineFraction
(double val) Sets the grid line fraction.void
setGridLineMinMaxWidth
(double min, double max) Sets the minimum and maximum width of a grid line in pixels.void
setGridLines
(boolean on) Turns grid lines on or off.void
setGridMinSpacing
(double val) Sets the grid min spacing.void
setGridModulus
(int val) Sets the grid modulus.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
getAlternatePortrayalOrdering, getField, getInspector, getName, getPortrayalForAll, getPortrayalForNonNull, getPortrayalForNull, getPortrayalForObject, getPortrayalForRemainder, getStatus, isDirtyField, isImmutableField, reset, setAlternatePortrayalOrdering, setDirtyField, setImmutableField, setObjectLocation, 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 Details
-
locationToPass
-
-
Constructor Details
-
ObjectGridPortrayal2D
public ObjectGridPortrayal2D()
-
-
Method Details
-
setField
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 classFieldPortrayal
-
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 classFieldPortrayal2D
-
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 classFieldPortrayal
-
getScale
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 classFieldPortrayal2D
-
getPositionLocation
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 classFieldPortrayal2D
-
getObjectLocation
Description copied from class:FieldPortrayal
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 classFieldPortrayal
-
getLocationPosition
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 classFieldPortrayal2D
-
hitOrDraw
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 classFieldPortrayal2D
-
getWrapper
-
setSelected
Description copied from class:FieldPortrayal
Selects or deselects all of the provided objects.- Specified by:
setSelected
in interfacePortrayal
- Overrides:
setSelected
in classFieldPortrayal
-
setGridLines
public void setGridLines(boolean on) Turns grid lines on or off. By default the grid is off. -
setGridColor
Sets the grid color. By default the grid is blue. -
setGridModulus
public void setGridModulus(int val) Sets the grid modulus. This is the minimum number of grid cells skipped before another grid line is drawn. By default the modulus is 10. -
setGridMinSpacing
public void setGridMinSpacing(double val) Sets the grid min spacing. This is the minimum number of pixels skipped before another grid line is drawn. The grid modulus is doubled until the grid spacing equals or exceeds the minimum spacing. By default the min spacing is 2.0. -
setGridLineFraction
public void setGridLineFraction(double val) Sets the grid line fraction. This is the width of a stroked line as a fraction of the width (or height) of a grid cell. Grid lines are drawn centered on the borders between cells. By default the fraction is 1/8.0. -
setGridLineMinMaxWidth
public void setGridLineMinMaxWidth(double min, double max) Sets the minimum and maximum width of a grid line in pixels. By default, the minimum is 1.0 and the maximum is positive infinity. -
setBorder
public void setBorder(boolean on) Turns border lines on or off. By default the border is off. -
setBorderColor
Sets the border color. By default the border is red. -
setBorderLineFraction
public void setBorderLineFraction(double val) Sets the border line fraction. This is the width of a stroked line as a fraction of the width (or height) of a grid cell. Grid lines are drawn centered on the borders around the grid. Note that if the grid is being drawn clipped (see Display2D.setClipping(...)), then only HALF of the width of this line will be visible (the half that lies within the grid region). By default the fraction is 1/8.0.. -
setBorderLineMinMaxWidth
public void setBorderLineMinMaxWidth(double min, double max) Sets the minimum and maximum width of a border line in pixels. By default, the minimum is 1.0 and the maximum is positive infinity.
-