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 SimplePortrayal2D

    java.lang.Object
      sim.portrayal.SimplePortrayal2D

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

Direct Known Subclasses:
  SimpleEdgePortrayal2D

public class SimplePortrayal2D
extends java.lang.Object
implements Portrayal2D

A useful abstract superclass for objects. Doesn't draw itself at all. Responds to hit testing by intersecting the hit testing rect with a width by height rectangle centered at 0,0. Responds to requests for inspectors by providing a basic LabelledList which shows all the portrayed object's object properties (see sim.util.SimpleProperties). Responds to inspector update requests by updating this same LabelledList.

When portray(obj) is called, SimplePortrayal2D simply stores obj in a protected field called lastPortrayedObject. Subclasses of SimplePortrayal2D are welcome to access lastPortrayedObject to know what the object the Portrayal is portraying.

See Also:
  Serialized Form

Constructor Summary
`SimplePortrayal2D()`

Method Summary
`void` | `draw(java.lang.Object object, java.awt.Graphics2D graphics, DrawInfo2D info)` Draw a portrayed object centered at the origin in info, and with the given scaling factors.
`Inspector` | `getInspector(LocationWrapper wrapper, GUIState state)` Provide an inspector for an object.
`java.lang.String` | `getName(LocationWrapper wrapper)` Returns a name for the given object that is useful for a human to distinguish it from other objects.
`boolean` | `hitObject(java.lang.Object object, DrawInfo2D range)` If drawing area intersects selected area, return true.
`boolean` | `setSelected(LocationWrapper wrapper, boolean selected)` Change the portrayal state to reflect the fact that you've been selected or not selected.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### SimplePortrayal2D

    public SimplePortrayal2D()

Method Detail

### draw

    public void draw(java.lang.Object object,
                     java.awt.Graphics2D graphics,
                     DrawInfo2D info)

  Description copied from interface: `Portrayal2D`
  Draw a portrayed object centered at the origin in info, and with the given scaling factors. draw(...) will not be called until portray(obj) has been called on a Portrayal2D at least once. But you should have some default null drawing capability just in case.

  Specified by:
    `draw` in interface `Portrayal2D`

### hitObject

    public boolean hitObject(java.lang.Object object,
                             DrawInfo2D range)

  If drawing area intersects selected area, return true. The default computes the intersection with the (-0.5,-0.5) to (0.5,0.5) rectangle.

### setSelected

    public boolean setSelected(LocationWrapper wrapper,
                               boolean selected)

  Description copied from interface: `Portrayal`
  Change the portrayal state to reflect the fact that you've been selected or not selected. Always return true, except if you've received a setSelected(true) and in fact do not wish to be selectable, in which case return false in that sole situation.

  Specified by:
    `setSelected` in interface `Portrayal`

### getInspector

    public Inspector getInspector(LocationWrapper wrapper,
                                  GUIState state)

  Description copied from interface: `Portrayal`
  Provide an inspector for an object.

  Specified by:
    `getInspector` in interface `Portrayal`

### getName

    public java.lang.String getName(LocationWrapper wrapper)

  Description copied from interface: `Portrayal`
  Returns a name for the given object that is useful for a human to distinguish it from other objects. A simple default would be just to return "" + object.

  Specified by:
    `getName` in interface `Portrayal`

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