Class ContinuousPortrayal2D

java.lang.Object
sim.portrayal.FieldPortrayal
sim.portrayal.FieldPortrayal2D
sim.portrayal.continuous.ContinuousPortrayal2D
All Implemented Interfaces:
Portrayal, Portrayal2D
Direct Known Subclasses:
Continuous3DPortrayal2D

public class ContinuousPortrayal2D extends FieldPortrayal2D
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.
  • Constructor Details

    • ContinuousPortrayal2D

      public ContinuousPortrayal2D()
  • Method Details

    • setField

      public void setField(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
    • 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 class FieldPortrayal2D
    • 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 Object getPositionLocation(Point2D.Double position, DrawInfo2D fieldPortrayalInfo)
      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
    • setObjectLocation

      public void setObjectLocation(Object object, Object location, GUIState gui)
      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 class FieldPortrayal
    • getObjectLocation

      public Object getObjectLocation(Object object, GUIState gui)
      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 class FieldPortrayal
    • getLocationPosition

      public Point2D.Double getLocationPosition(Object location, DrawInfo2D fieldPortrayalInfo)
      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
    • 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

      protected void hitOrDraw(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(Object obj, GUIState gui)
    • 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
    • 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

      public void setAxesColor(Color val)
      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

      public void setBorderColor(Color val)
      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.