sim.portrayal.simple
Class OrientedPortrayal2D

java.lang.Object
  extended by sim.portrayal.SimplePortrayal2D
      extended by sim.portrayal.simple.OrientedPortrayal2D
All Implemented Interfaces:
java.io.Serializable, Portrayal, Portrayal2D

public class OrientedPortrayal2D
extends SimplePortrayal2D

A wrapper for other Portrayal2Ds which provides some kind of pointing object (typically a line) along the object's specified orientation angle. This is a very simple way to show orientation. The underlying Portrayal2D may also be automatically rotated if autoRotate() is turned on (it's off by default, as rotation is expensive.

For the line to be drawn, the underlying object must adhere to the Oriented2D interface, which provides the orientation2D() method. The line starts at the origin and is of length:


   length:     (int)(or * max(info.draw.width,info.draw.height)) + dr;
   

... that is, or is a value which scales when you zoom in, and dr adds additional fixed pixels. The default is or = 0.5, dr = 0, with a red color.

You can specify other shapes than a simple line. We provide two others: kites and compasses.

Note: One oddity of OrientedPortrayal2D is due to the fact that the line is only drawn if the object is being drawn. While most FieldPortrayals ask objects just off-screen to draw themselves just to be careful, if an object is significantly off-screen, it may not be asked to draw itself, and so the orientation line will not be drawn -- even though part of the orientation line could be on-screen at the time! C'est la vie.

See Also:
Serialized Form

Field Summary
 SimplePortrayal2D child
           
static int DEFAULT_DR
           
static double DEFAULT_OR
           
 int dr
          The post-scaling length offset
 double or
          The pre-scaling length
 java.awt.Paint paint
          The Paint or Color of the line
static int SHAPE_COMPASS
           
static int SHAPE_KITE
           
static int SHAPE_LINE
           
 
Fields inherited from class sim.portrayal.SimplePortrayal2D
TYPE_HIT_OBJECT, TYPE_SELECTED_OBJECT
 
Constructor Summary
OrientedPortrayal2D(SimplePortrayal2D child)
          Draw a line of length or = 0.5 dr = 0, in red.
OrientedPortrayal2D(SimplePortrayal2D child, int dr, double or)
          Draw a line of the given length in red.
OrientedPortrayal2D(SimplePortrayal2D child, int dr, double or, java.awt.Paint paint)
          If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used.
OrientedPortrayal2D(SimplePortrayal2D child, int dr, double or, java.awt.Paint paint, int shape)
           
OrientedPortrayal2D(SimplePortrayal2D child, java.awt.Paint paint)
          Draw a line of length or = 0.5, dr = 0.
 
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.
 SimplePortrayal2D getChild(java.lang.Object object)
           
 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.
 int getShape()
           
 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 isLineShowing()
           
 boolean isOrientationHittable()
          Returns true if the orientation marker can be hit as part of the object.
 void setLineShowing(boolean val)
           
 void setOrientationHittable(boolean val)
          Sets whether or not the orientation marker can be hit as part of the object.
 boolean setSelected(LocationWrapper wrapper, boolean selected)
          Change the portrayal state to reflect the fact that you've been selected or not selected.
 void setShape(int val)
           
 
Methods inherited from class sim.portrayal.SimplePortrayal2D
getStatus, handleMouseEvent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_OR

public static final double DEFAULT_OR
See Also:
Constant Field Values

DEFAULT_DR

public static final int DEFAULT_DR
See Also:
Constant Field Values

SHAPE_LINE

public static final int SHAPE_LINE
See Also:
Constant Field Values

SHAPE_KITE

public static final int SHAPE_KITE
See Also:
Constant Field Values

SHAPE_COMPASS

public static final int SHAPE_COMPASS
See Also:
Constant Field Values

or

public double or
The pre-scaling length


dr

public int dr
The post-scaling length offset


paint

public java.awt.Paint paint
The Paint or Color of the line


child

public SimplePortrayal2D child
Constructor Detail

OrientedPortrayal2D

public OrientedPortrayal2D(SimplePortrayal2D child,
                           int dr,
                           double or,
                           java.awt.Paint paint,
                           int shape)

OrientedPortrayal2D

public OrientedPortrayal2D(SimplePortrayal2D child,
                           int dr,
                           double or,
                           java.awt.Paint paint)
If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used.


OrientedPortrayal2D

public OrientedPortrayal2D(SimplePortrayal2D child)
Draw a line of length or = 0.5 dr = 0, in red. If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used.


OrientedPortrayal2D

public OrientedPortrayal2D(SimplePortrayal2D child,
                           int dr,
                           double or)
Draw a line of the given length in red. If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used.


OrientedPortrayal2D

public OrientedPortrayal2D(SimplePortrayal2D child,
                           java.awt.Paint paint)
Draw a line of length or = 0.5, dr = 0. If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used.

Method Detail

setShape

public void setShape(int val)

getShape

public int getShape()

isLineShowing

public boolean isLineShowing()

setLineShowing

public void setLineShowing(boolean val)

getChild

public SimplePortrayal2D getChild(java.lang.Object object)

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
Overrides:
draw in class SimplePortrayal2D

isOrientationHittable

public boolean isOrientationHittable()
Returns true if the orientation marker can be hit as part of the object. By default the answer is YES.


setOrientationHittable

public void setOrientationHittable(boolean val)
Sets whether or not the orientation marker can be hit as part of the object.


hitObject

public boolean hitObject(java.lang.Object object,
                         DrawInfo2D range)
Description copied from class: SimplePortrayal2D
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.

Overrides:
hitObject in class SimplePortrayal2D

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
Overrides:
setSelected in class SimplePortrayal2D

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
Overrides:
getInspector in class SimplePortrayal2D

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
Overrides:
getName in class SimplePortrayal2D