Class FastObjectGridPortrayal2D

All Implemented Interfaces:
Portrayal, Portrayal2D

public class FastObjectGridPortrayal2D extends ObjectGridPortrayal2D
A "Fast" version of ObjectGridPortrayal2D, which draws objects as rectangles of specified colors, rather than using the provided SimplePortrayal2Ds. FastObjectGridPortrayal2D contains an underlying FastValueGridPortrayal2D. 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 FastValueGridPortrayal2D to draw with the provided ColorMap.
  • Constructor Details

    • FastObjectGridPortrayal2D

      public FastObjectGridPortrayal2D(boolean immutableField)
      If immutableField is true, we presume that the grid doesn't change. This allows us to just re-splat the buffer.
    • FastObjectGridPortrayal2D

      public FastObjectGridPortrayal2D()
      Equivalent to FastObjectGridPortrayal2D(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 class FieldPortrayal
    • 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 ObjectGridPortrayal2D
    • doubleValue

      public double doubleValue(Object obj)
      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 FastValueGridPortrayal2D, which will map them to appropriate colors using the map provided in setMap.

      The default form of this function is:

      1. If the object is null, return 0.
      2. Else if the object is a Number or is sim.util.Valuable, return obj.doubleValue();
      3. Else return 1.
    • reset

      public void reset()
      Deprecated.
      Use setDirtyField(false); Resets the underlying FastValueGridPortrayal2D.
      Overrides:
      reset in class FieldPortrayal
    • setDirtyField

      public void setDirtyField(boolean val)
      Overrides:
      setDirtyField in class FieldPortrayal
    • isDirtyField

      public boolean isDirtyField()
      Overrides:
      isDirtyField in class FieldPortrayal
    • getMap

      public ColorMap getMap()
    • setMap

      public void setMap(ColorMap m)
    • 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 class FieldPortrayal2D
    • 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 class FieldPortrayal2D
    • draw

      public void draw(Object object, Graphics2D graphics, DrawInfo2D info)
      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 interface Portrayal2D
      Overrides:
      draw in class FieldPortrayal2D