sim.portrayal
Class SimplePortrayal2D

java.lang.Object
  extended by sim.portrayal.SimplePortrayal2D
All Implemented Interfaces:
java.io.Serializable, Portrayal, Portrayal2D
Direct Known Subclasses:
AdjustablePortrayal2D, FacetedPortrayal2D, LabelledPortrayal2D, MovablePortrayal2D, OrientedPortrayal2D, OvalPortrayal2D, RectanglePortrayal2D, ShapePortrayal2D, SimpleEdgePortrayal2D, TrailedPortrayal2D, TransformedPortrayal2D

public class SimplePortrayal2D
extends java.lang.Object
implements Portrayal2D

The superclass of all 2D Simple Portrayals. 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.

See Also:
Serialized Form

Field Summary
static int TYPE_HIT_OBJECT
           
static int TYPE_SELECTED_OBJECT
           
 
Constructor Summary
SimplePortrayal2D()
           
 
Method Summary
 void draw(java.lang.Object object, java.awt.Graphics2D graphics, DrawInfo2D info)
          Draw a the given object with an origin at (info.draw.x, info.draw.y), and with the coordinate system scaled by so that 1 unit is in the x and y directions are equal to info.draw.width and info.draw.height respectively in pixels.
 Inspector getInspector(LocationWrapper wrapper, GUIState state)
          Provide an inspector for an object.
 java.lang.String getName(LocationWrapper wrapper)
          Returns a static, one-line name for the given object that is useful for a human to distinguish it from other objects.
 java.lang.String getStatus(LocationWrapper wrapper)
          Returns a simple, informative one-line description of the current status of the object, which may change at any time to reflect how the object is changing.
 boolean handleMouseEvent(Manipulating2D manipulating, LocationWrapper wrapper, java.awt.event.MouseEvent event, DrawInfo2D fieldPortrayalDrawInfo, int type)
          Optionally handles a mouse event.
 boolean hitObject(java.lang.Object object, DrawInfo2D range)
          Return true if the given object, when drawn, intersects with a provided rectangle, for hit testing purposes.
 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
 

Field Detail

TYPE_SELECTED_OBJECT

public static int TYPE_SELECTED_OBJECT

TYPE_HIT_OBJECT

public static int TYPE_HIT_OBJECT
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 the given object with an origin at (info.draw.x, info.draw.y), and with the coordinate system scaled by so that 1 unit is in the x and y directions are equal to info.draw.width and info.draw.height respectively in pixels. The rectangle given by info.clip specifies the only region in which it is necessary to draw. If info.precise is true, try to draw using real-valued high-resolution drawing rather than faster integer drawing. It is possible that object is null. The location of the object in the field may (and may not) be stored in info.location. The form of that location varies depending on the kind of field used.

Specified by:
draw in interface Portrayal2D

hitObject

public boolean hitObject(java.lang.Object object,
                         DrawInfo2D range)
Return true if the given object, when drawn, intersects with a provided rectangle, for hit testing purposes. The object is drawn with an origin at (info.draw.x, info.draw.y), and with the coordinate system scaled by so that 1 unit is in the x and y directions are equal to info.draw.width and info.draw.height respectively in pixels. The rectangle given by info.clip specifies the region to do hit testing in; often this region is actually of 0 width or height, which might represent a single point. It is possible that object is null. The location of the object in the field may (and may not) be stored in info.location. The form of that location varies depending on the kind of field used.


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

handleMouseEvent

public boolean handleMouseEvent(Manipulating2D manipulating,
                                LocationWrapper wrapper,
                                java.awt.event.MouseEvent event,
                                DrawInfo2D fieldPortrayalDrawInfo,
                                int type)
Optionally handles a mouse event. At present, events are sent to SimplePortrayal2Ds representing objects which have been either selected or are presently hit by the event coordinates. The wrapper provides the field portrayal, object location, and object. Also provided are the display, event, the DrawInfo2D for the field portrayal, and the type of mouse event situation (either because the object was SELECTED or because it was HIT).

To indicate that the event was handled, return true. The default blank implementation of this method simply returns false. Events are first sent to portrayals selected objects, until one of them handles the event. If none handled the event, then events are sent to portrayals of objects hit by the event, until one of *them* handles the event. If still no one has handled the event, then the Display2D will route the event to built-in mechanisms such selecting the object or inspecting it.


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

getStatus

public java.lang.String getStatus(LocationWrapper wrapper)
Description copied from interface: Portrayal
Returns a simple, informative one-line description of the current status of the object, which may change at any time to reflect how the object is changing. A simple default would be just to return getName(wrapper).

Specified by:
getStatus in interface Portrayal

getName

public java.lang.String getName(LocationWrapper wrapper)
Description copied from interface: Portrayal
Returns a static, one-line 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