Package sim.portrayal.simple
Class FacetedPortrayal2D
java.lang.Object
sim.portrayal.SimplePortrayal2D
sim.portrayal.simple.FacetedPortrayal2D
- All Implemented Interfaces:
Serializable
,Portrayal
,Portrayal2D
A wrapper for multiple Portrayal2Ds which calls on one or the other one according to the
underlying state of the object, which must be Valuable or a Number of some sort. The
particular sub-portrayal (called a "facet") chosen is based on the integer value returned
(or converted to an integer if it's a double). Optionally FacetedPortrayal2D will call on
all* its underlying portrayals at one time. If any array element is null, FacetedPortrayal2D
will assume it represents the object itself (assuming the object itself is also a SimplePortrayal2D).
- See Also:
-
Field Summary
Fields inherited from class sim.portrayal.SimplePortrayal2D
TYPE_HIT_OBJECT, TYPE_SELECTED_OBJECT
-
Constructor Summary
ConstructorDescriptionFacetedPortrayal2D
(SimplePortrayal2D[] children) If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used.FacetedPortrayal2D
(SimplePortrayal2D[] children, boolean portrayAllChildren) If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used. -
Method Summary
Modifier and TypeMethodDescriptionvoid
draw
(Object object, Graphics2D graphics, DrawInfo2D info) Draw a the given object with an origin at (info.draw.x, info.draw.y), and with the coordinate system scaled by so that 1 unit is in the x and y directions are equal to info.draw.width and info.draw.height respectively in pixels.int
getChildIndex
(Object object, int numIndices) Returns the child index to use for the given object.getInspector
(LocationWrapper wrapper, GUIState state) If portrayAllChildren, Calls on the first child to return the inspector.getName
(LocationWrapper wrapper) If portrayAllChildren, Calls on the first child to return the name.boolean
hitObject
(Object object, DrawInfo2D range) Return true if the given object, when drawn, intersects with a provided rectangle, for hit testing purposes.boolean
setSelected
(LocationWrapper wrapper, boolean selected) If portrayAllChildren, Returns true if any ONE of the children returns true.Methods inherited from class sim.portrayal.SimplePortrayal2D
getStatus, handleMouseEvent
-
Field Details
-
children
-
-
Constructor Details
-
FacetedPortrayal2D
If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used. -
FacetedPortrayal2D
If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used.
-
-
Method Details
-
getChildIndex
Returns the child index to use for the given object. The value must be >= 0 and invalid input: '<' numIndices. The default implementation returns the value of the object if it's a Number or is sim.util.Valuable and if the value is within the given range (and is an integer). Otherwise 0 is returned. -
draw
Description copied from interface:Portrayal2D
Draw a the given object with an origin at (info.draw.x, info.draw.y), and with the coordinate system scaled by so that 1 unit is in the x and y directions are equal to info.draw.width and info.draw.height respectively in pixels. The rectangle given by info.clip specifies the only region in which it is necessary to draw. If info.precise is true, try to draw using real-valued high-resolution drawing rather than faster integer drawing. It is possible that object is null. The location of the object in the field may (and may not) be stored in info.location. The form of that location varies depending on the kind of field used.- Specified by:
draw
in interfacePortrayal2D
- Overrides:
draw
in classSimplePortrayal2D
-
hitObject
Description copied from class:SimplePortrayal2D
Return true if the given object, when drawn, intersects with a provided rectangle, for hit testing purposes. The object is drawn with an origin at (info.draw.x, info.draw.y), and with the coordinate system scaled by so that 1 unit is in the x and y directions are equal to info.draw.width and info.draw.height respectively in pixels. The rectangle given by info.clip specifies the region to do hit testing in; often this region is actually of 0 width or height, which might represent a single point. It is possible that object is null. The location of the object in the field may (and may not) be stored in info.location. The form of that location varies depending on the kind of field used.- Overrides:
hitObject
in classSimplePortrayal2D
-
setSelected
If portrayAllChildren, Returns true if any ONE of the children returns true.- Specified by:
setSelected
in interfacePortrayal
- Overrides:
setSelected
in classSimplePortrayal2D
-
getInspector
If portrayAllChildren, Calls on the first child to return the inspector.- Specified by:
getInspector
in interfacePortrayal
- Overrides:
getInspector
in classSimplePortrayal2D
-
getName
If portrayAllChildren, Calls on the first child to return the name.- Specified by:
getName
in interfacePortrayal
- Overrides:
getName
in classSimplePortrayal2D
-