Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## sim.portrayal
Class FieldPortrayal2D

    java.lang.Object
      sim.portrayal.FieldPortrayal
          sim.portrayal.FieldPortrayal2D

All Implemented Interfaces:
  Portrayal, Portrayal2D, java.io.Serializable

Direct Known Subclasses:
  ContinuousPortrayal2D, NetworkPortrayal2D, ObjectGridPortrayal2D, SparseGridPortrayal2D, ValueGridPortrayal2D

public abstract class FieldPortrayal2D
extends FieldPortrayal
implements Portrayal2D

Superclass of all Field Portrayals in 2D. Implements default versions of the necessary methods, which you should feel free to override (especially portray, hit, and draw!).

The default versions of hitObjects and draw call a protected but empty method called hitOrDraw. It's very common that a field's hitObjects and draw methods will be identical save for a single line which calls hitObjects or draw on an underlying SimplePortrayal. So most fields unify both methods into this single method and unify the line as something like this:

        if (graphics == null)
        {
        if (portrayal.hitObject(portrayedObject, newinfo))
        putInHere.add(getWrapper(portrayedObject, portrayedObjectLocation));
        }
        else
        portrayal.draw(portrayedObject, graphics, newinfo);

...where getWrapper(...) returns a LocationWrapper appropriate to the Field.

See Also:
  Serialized Form

Nested Class Summary

Nested classes inherited from class sim.portrayal.FieldPortrayal
`FieldPortrayal.CustomInspector`

Field Summary
`static int` | `DEFAULT` Default buffering: let the program decide on its own (typically in a platform-dependent fashion)
`static int` | `DONT_USE_BUFFER` Don't use a buffer
`static int` | `USE_BUFFER` Use a buffer

Fields inherited from class sim.portrayal.FieldPortrayal
`classPortrayals, dirtyField, field, immutableField, portrayalForAll, portrayalForNull, portrayalForRemainder, portrayals`

Constructor Summary
`FieldPortrayal2D()`

Method Summary
`void` | `draw(java.lang.Object object, java.awt.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` | `getBuffering()` Returns whether or not the FieldPortrayal2D will use a buffering "trick" to draw quickly.
`void` | `getSelectedObjects(Bag putInHere)` Adds to the Bag LocationWrappers of all selected objects.
`void` | `hitObjects(DrawInfo2D range, Bag putInHere)` Adds to the provided Bag LocationWrappers for any objects which overlap the provided hit range.
`protected void` | `hitOrDraw(java.awt.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.
`void` | `move(Bag locationWrappers, java.awt.geom.Dimension2D distance)` Moves the Bag of LocationWrappers by the provided amount.
`void` | `setBuffering(int val)` Sets whether or not the FieldPortrayal2D will use a buffering "trick" to draw quickly.
`void` | `setSelected(Bag locationWrappers, boolean selected)` Selects or deselects all of the provided objects.

Methods inherited from class sim.portrayal.FieldPortrayal
`getDefaultNullPortrayal, getDefaultPortrayal, getField, getInspector, getName, getPortrayalForAll, getPortrayalForNull, getPortrayalForObject, getPortrayalForRemainder, isImmutableField, setField, setImmutableField, setPortrayalForAll, setPortrayalForClass, 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, setSelected`

Field Detail

### DEFAULT

    public static final int DEFAULT

  Default buffering: let the program decide on its own (typically in a platform-dependent fashion)

  See Also:
    Constant Field Values

### USE_BUFFER

    public static final int USE_BUFFER

  Use a buffer

  See Also:
    Constant Field Values

### DONT_USE_BUFFER

    public static final int DONT_USE_BUFFER

  Don't use a buffer

  See Also:
    Constant Field Values

Constructor Detail

### FieldPortrayal2D

    public FieldPortrayal2D()

Method Detail

### draw

    public void draw(java.lang.Object object,
                     java.awt.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]. 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`

### hitObjects

    public void hitObjects(DrawInfo2D range,
                           Bag putInHere)

  Adds to the provided Bag LocationWrappers for any objects which overlap the provided hit range. The hit range will usually define a single point, but COULD be a range. The object should perceive itself as located at the (range.draw.x,range.draw.y) origin and drawn relative to the (range.draw.width,range.draw.height) scale.

### hitOrDraw

    protected void hitOrDraw(java.awt.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. 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).

### getSelectedObjects

    public void getSelectedObjects(Bag putInHere)

  Adds to the Bag LocationWrappers of all selected objects.

### setSelected

    public void setSelected(Bag locationWrappers,
                            boolean selected)

  Selects or deselects all of the provided objects.

### move

    public void move(Bag locationWrappers,
                     java.awt.geom.Dimension2D distance)

  Moves the Bag of LocationWrappers by the provided amount.

### getBuffering

    public int getBuffering()

  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.

### setBuffering

    public void setBuffering(int val)

  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.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD