Package sim.portrayal.continuous
Class ContinuousPortrayal2D
java.lang.Object
sim.portrayal.FieldPortrayal
sim.portrayal.FieldPortrayal2D
sim.portrayal.continuous.ContinuousPortrayal2D
- All Implemented Interfaces:
Portrayal
,Portrayal2D
- Direct Known Subclasses:
Continuous3DPortrayal2D
Portrays Continuous2D fields. When asked to portray objects, this field computes the buckets
covered by the requested region, then includes an additional boundary of two buckets in each
direction just in case objects leak over the boundary region.
The 'location' passed
into the DrawInfo2D handed to the SimplePortryal2D is a Double2D.
-
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 TypeMethodDescriptionShould return a portrayal which can portray any object regardless of whether it's valid or notgetLocationPosition
(Object location, DrawInfo2D fieldPortrayalInfo) 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 fieldPortrayalInfo) Returns the Location, in the parlance of the underlying Field, of the given position.getRelativeObjectPosition
(Object location, Object otherObjectLocation, DrawInfo2D otherObjectInfo) Returns the position on-screen of an object at a given location in the field, using another object's location and DrawInfo2D to perform the computation.getScale
(DrawInfo2D info) Returns the width and height, in pixels, of 1.0 x 1.0 units in the underlying field.getWrapper
(Object obj, GUIState gui) 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.boolean
Returns TRUE if the portrayal is displaying objects multiply (in a toroidal fashion) if they overlap on the edges of the field.void
setAxes
(boolean on) Turns axes on or off.void
setAxesColor
(Color val) Sets the axes color.void
setAxesLineFraction
(double val) Sets the axis line fraction.void
setAxesLineMinMaxWidth
(double min, double max) Sets the minimum and maximum width of a border line in pixels.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
setDisplayingToroidally
(boolean val) Set this to TRUE to cause the portrayal to display objects multiply (in a toroidal fashion) if they overlap on the edges of the field.void
Sets the field, and sets the dirtyField flag to true.void
setObjectLocation
(Object object, Object location, GUIState gui) Sets location in the underlying field of the given object, if such a thing is reasonable.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, hitObjects, setBuffering, setObjectPosition
Methods inherited from class sim.portrayal.FieldPortrayal
getAlternatePortrayalOrdering, getDefaultNullPortrayal, getField, getInspector, getName, getPortrayalForAll, getPortrayalForNonNull, getPortrayalForNull, getPortrayalForObject, getPortrayalForRemainder, getStatus, isDirtyField, isImmutableField, reset, setAlternatePortrayalOrdering, 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
-
Constructor Details
-
ContinuousPortrayal2D
public ContinuousPortrayal2D()
-
-
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
-
getRelativeObjectPosition
public Point2D.Double getRelativeObjectPosition(Object location, Object otherObjectLocation, DrawInfo2D otherObjectInfo) Description copied from class:FieldPortrayal2D
Returns the position on-screen of an object at a given location in the field, using another object's location and DrawInfo2D to perform the computation. Returns null if we can't compute it -- this happens by default if the two locations are neither Int2D nor Double2D. This method is largely used by TrailPortrayal2D.- Overrides:
getRelativeObjectPosition
in classFieldPortrayal2D
-
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
-
setObjectLocation
Description copied from class:FieldPortrayal
Sets location in the underlying field of the given object, if such a thing is reasonable. Largely used for setObjectPosition(...), and in the Inspector's LocationWrapper via the Stable classes. Optionally overridable. The default implementation does nothing.- Overrides:
setObjectLocation
in classFieldPortrayal
-
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
-
setDisplayingToroidally
public void setDisplayingToroidally(boolean val) Set this to TRUE to cause the portrayal to display objects multiply (in a toroidal fashion) if they overlap on the edges of the field. Note that this incurs a slight constant overhead. By default this setting is FALSE. -
isDisplayingToroidally
public boolean isDisplayingToroidally()Returns TRUE if the portrayal is displaying objects multiply (in a toroidal fashion) if they overlap on the edges of the field. -
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
-
setAxes
public void setAxes(boolean on) Turns axes on or off. Axes are drawn midway through the field (even though that is NOT the (0,0) location). By default the axes are off. -
setAxesColor
Sets the axes color. By default the color is blue. -
setAxesLineFraction
public void setAxesLineFraction(double val) Sets the axis line fraction. This is the width of a stroked line as a fraction of the width (or height) of a unit in the continuous space. By default the fraction is 1/8.0. -
setAxesLineMinMaxWidth
public void setAxesLineMinMaxWidth(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. -
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.
-