Package sim.portrayal.grid
Class FastHexaObjectGridPortrayal2D
java.lang.Object
sim.portrayal.FieldPortrayal
sim.portrayal.FieldPortrayal2D
sim.portrayal.grid.ObjectGridPortrayal2D
sim.portrayal.grid.HexaObjectGridPortrayal2D
sim.portrayal.grid.FastHexaObjectGridPortrayal2D
- All Implemented Interfaces:
Portrayal
,Portrayal2D
A "Fast" version of HexaObjectGridPortrayal2D, which draws objects as rectangles of specified colors,
rather than using the provided SimplePortrayal2Ds. FastHexaObjectGridPortrayal2D contains an underlying
FastHexaValueGridPortrayal2D. When the field needs to be drawn, it is first mapped into a DoubleGrid2D,
using the mapping function doubleValue(...) (which you can override to provide specialized
behavior). This DoubleGrid2D is then handed to the underlying FastHexaValueGridPortrayal2D to draw with
the provided ColorMap.
-
Nested Class Summary
Nested classes/interfaces inherited from class sim.portrayal.grid.ObjectGridPortrayal2D
ObjectGridPortrayal2D.Message
-
Field Summary
Fields inherited from class sim.portrayal.grid.ObjectGridPortrayal2D
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
ConstructorDescriptionEquivalent to FastHexaObjectGridPortrayal2D(false);FastHexaObjectGridPortrayal2D
(boolean immutableField) If immutableField is true, we presume that the grid doesn't change. -
Method Summary
Modifier and TypeMethodDescriptiondouble
doubleValue
(Object obj) Override this as necessary to map the provided object into a double value.void
draw
(Object object, Graphics2D graphics, DrawInfo2D info) Draws the field with its origin at [info.draw.x,info.draw.y], relative to the scaled coordinate system defined by [info.draw.width,info.draw.height].int
Returns whether or not the FieldPortrayal2D will use a buffering "trick" to draw quickly.getMap()
boolean
void
reset()
Deprecated.Resets the underlying FastHexaValueGridPortrayal2D.void
setBuffering
(int val) Sets whether or not the FieldPortrayal2D will use a buffering "trick" to draw quickly.void
setDirtyField
(boolean val) void
Sets the field, and sets the dirtyField flag to true.void
setImmutableField
(boolean immutableField) Specifies that the underlying field is (or is not) to be assumed unchanging -- thus there's no reason to update once we're created.void
Methods inherited from class sim.portrayal.grid.HexaObjectGridPortrayal2D
getLocationPosition, getPositionLocation, getScale, hitOrDraw, setBorder, setGridLines
Methods inherited from class sim.portrayal.grid.ObjectGridPortrayal2D
getDefaultNullPortrayal, getDefaultPortrayal, getObjectLocation, getWrapper, setBorderColor, setBorderLineFraction, setBorderLineMinMaxWidth, setGridColor, setGridLineFraction, setGridLineMinMaxWidth, setGridMinSpacing, setGridModulus, setSelected
Methods inherited from class sim.portrayal.FieldPortrayal2D
getClipLocation, getObjectPosition, getRelativeObjectPosition, hitObjects, setObjectPosition
Methods inherited from class sim.portrayal.FieldPortrayal
getAlternatePortrayalOrdering, getField, getInspector, getName, getPortrayalForAll, getPortrayalForNonNull, getPortrayalForNull, getPortrayalForObject, getPortrayalForRemainder, getStatus, isImmutableField, setAlternatePortrayalOrdering, 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
-
Constructor Details
-
FastHexaObjectGridPortrayal2D
public FastHexaObjectGridPortrayal2D(boolean immutableField) If immutableField is true, we presume that the grid doesn't change. This allows us to just re-splat the buffer. -
FastHexaObjectGridPortrayal2D
public FastHexaObjectGridPortrayal2D()Equivalent to FastHexaObjectGridPortrayal2D(false);
-
-
Method Details
-
setImmutableField
public void setImmutableField(boolean immutableField) Description copied from class:FieldPortrayal
Specifies that the underlying field is (or is not) to be assumed unchanging -- thus there's no reason to update once we're created. Not all FieldPortrayals will care about whether or not a field is immutable. Also sets dirtyField to true regardless.- Overrides:
setImmutableField
in classFieldPortrayal
-
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 classObjectGridPortrayal2D
-
doubleValue
Override this as necessary to map the provided object into a double value. Objects selected from the field will be mapped through this function to double values, which in turn will be passed to an underlying FastHexaValueGridPortrayal2D, which will map them to appropriate colors using the map provided in setMap.The default form of this function is:
- If the object is null, return 0.
- Else if the object is a Number or is sim.util.Valuable, return obj.doubleValue();
- Else return 1.
-
reset
public void reset()Deprecated.Resets the underlying FastHexaValueGridPortrayal2D.- Overrides:
reset
in classFieldPortrayal
-
setDirtyField
public void setDirtyField(boolean val) - Overrides:
setDirtyField
in classFieldPortrayal
-
isDirtyField
public boolean isDirtyField()- Overrides:
isDirtyField
in classFieldPortrayal
-
getMap
-
setMap
-
getBuffering
public int getBuffering()Description copied from class:FieldPortrayal2D
Returns whether or not the FieldPortrayal2D will use a buffering "trick" to draw quickly. This optional property is in FieldPortrayal2D but is only taken advantage of by one or two subclasses. Some FieldPortrayal2Ds primarily draw lots of rectangles in a grid. Certain ones can draw this in one of two ways: either by drawing each rectangle separately, or by filling a buffer (an image) with individual points, then stretching the buffer over the area, causing the points to enlarge into rectangles. The second is often faster, especially if given lots of memory (and always faster on Macs regardless). The FieldPortrayal2D's behavior in this regard will depend on the value of the buffering property. The property can take on one of three values: DEFAULT (let the machine decide on its own in a platform-dependent fashion -- the default), USE_BUFFER, or DONT_USE_BUFFER.- Overrides:
getBuffering
in classFieldPortrayal2D
-
setBuffering
public void setBuffering(int val) Description copied from class:FieldPortrayal2D
Sets whether or not the FieldPortrayal2D will use a buffering "trick" to draw quickly. This optional property is in FieldPortrayal2D but is only taken advantage of by one or two subclasses. Some FieldPortrayal2Ds primarily draw lots of rectangles in a grid. Certain ones can draw this in one of two ways: either by drawing each rectangle separately, or by filling a buffer (an image) with individual points, then stretching the buffer over the area, causing the points to enlarge into rectangles. The second is often faster, especially if given lots of memory (and always faster on Macs regardless). The FieldPortrayal2D's behavior in this regard will depend on the value of the buffering property. The property can take on one of three values: DEFAULT (let the machine decide on its own in a platform-dependent fashion -- the default), USE_BUFFER, or DONT_USE_BUFFER.- Overrides:
setBuffering
in classFieldPortrayal2D
-
draw
Description copied from class:FieldPortrayal2D
Draws the field with its origin at [info.draw.x,info.draw.y], relative to the scaled coordinate system defined by [info.draw.width,info.draw.height]. The only parts that need be drawn are those which fall within the [info.clip] rectangle. Since your draw and hitObjects methods are likely to be nearly identical, you can choose instead to override the hitOrDraw method to handle both of them. By default this method simply calls hitOrDraw. FieldPortrayals will receive null for the object; they should just draw their own fields.- Specified by:
draw
in interfacePortrayal2D
- Overrides:
draw
in classFieldPortrayal2D
-