Class OrientedPortrayal2D
- All Implemented Interfaces:
Serializable
,Portrayal
,Portrayal2D
- Direct Known Subclasses:
VectorPortrayal2D
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)(scale * max(info.draw.width,info.draw.height)) + offset;
... that is, or is a value which scales when you zoom in, and dr adds additional fixed pixels. The default is scale = 1.0, offset = 0, with a red color. Note that though the scale is 1.0, the shape is actually drawn effectively with a scale of 2.0 (that is, filling a 2x2 square rather than a 1x1 square) so as to be seen to some degree outside the underlying child portrayal.
You can specify other shapes than a simple line. We provide several others: a line arrow, a kite, compass, triangle, inverted T dagger shape, and arrow.
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:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final double
boolean
int
The post-scaling length offsetThe Paint or Color of the linedouble
The pre-scaling lengthstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
Fields inherited from class sim.portrayal.SimplePortrayal2D
TYPE_HIT_OBJECT, TYPE_SELECTED_OBJECT
-
Constructor Summary
ConstructorDescriptionDraw a line of length scale = 0.5, offset = 0, in red.OrientedPortrayal2D
(SimplePortrayal2D child, int offset, double scale) Draw a line of the given length in red.OrientedPortrayal2D
(SimplePortrayal2D child, int offset, double scale, 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 offset, double scale, Paint paint, int shape) OrientedPortrayal2D
(SimplePortrayal2D child, Paint paint) Draw a line of length scale = 0.5, offset = 0. -
Method Summary
Modifier and TypeMethodDescriptionvoid
draw
(Object object, 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.getInspector
(LocationWrapper wrapper, GUIState state) Provide an inspector for an object.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.boolean
double
getOrientation
(Object object, DrawInfo2D info) Returns the orientation of the underlying object, or NaN if there is no such orientation.int
getShape()
boolean
handleMouseEvent
(GUIState guistate, Manipulating2D manipulating, LocationWrapper wrapper, MouseEvent event, DrawInfo2D fieldPortrayalDrawInfo, int type) Optionally handles a mouse event.boolean
hitObject
(Object object, DrawInfo2D range) Return true if the given object, when drawn, intersects with a provided rectangle, for hit testing purposes.boolean
boolean
Deprecated.use isOrientationShowing()boolean
Returns true if the orientation marker can be hit as part of the object.boolean
void
setDrawFilled
(boolean val) void
setLineShowing
(boolean val) Deprecated.use setOrientationShowing()void
setOnlyDrawWhenSelected
(boolean val) void
setOrientationHittable
(boolean val) Sets whether or not the orientation marker can be hit as part of the object.void
setOrientationShowing
(boolean val) 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
-
Field Details
-
DEFAULT_SCALE
public static final double DEFAULT_SCALE- See Also:
-
DEFAULT_OFFSET
public static final int DEFAULT_OFFSET- See Also:
-
SHAPE_LINE
public static final int SHAPE_LINE- See Also:
-
SHAPE_LINE_ARROW
public static final int SHAPE_LINE_ARROW- See Also:
-
SHAPE_KITE
public static final int SHAPE_KITE- See Also:
-
SHAPE_COMPASS
public static final int SHAPE_COMPASS- See Also:
-
SHAPE_TRIANGLE
public static final int SHAPE_TRIANGLE- See Also:
-
SHAPE_INVERTED_T
public static final int SHAPE_INVERTED_T- See Also:
-
SHAPE_ARROW
public static final int SHAPE_ARROW- See Also:
-
scale
public double scaleThe pre-scaling length -
offset
public int offsetThe post-scaling length offset -
paint
The Paint or Color of the line -
child
-
drawFilled
public boolean drawFilled
-
-
Constructor Details
-
OrientedPortrayal2D
public OrientedPortrayal2D(SimplePortrayal2D child, int offset, double scale, Paint paint, int shape) -
OrientedPortrayal2D
If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used. -
OrientedPortrayal2D
Draw a line of length scale = 0.5, offset = 0, in red. If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used. -
OrientedPortrayal2D
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
Draw a line of length scale = 0.5, offset = 0. If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used.
-
-
Method Details
-
setShape
public void setShape(int val) -
getShape
public int getShape() -
setDrawFilled
public void setDrawFilled(boolean val) -
isDrawFilled
public boolean isDrawFilled() -
isOrientationShowing
public boolean isOrientationShowing() -
setOrientationShowing
public void setOrientationShowing(boolean val) -
isLineShowing
public boolean isLineShowing()Deprecated.use isOrientationShowing() -
setLineShowing
public void setLineShowing(boolean val) Deprecated.use setOrientationShowing() -
setOnlyDrawWhenSelected
public void setOnlyDrawWhenSelected(boolean val) -
getOnlyDrawWhenSelected
public boolean getOnlyDrawWhenSelected() -
getChild
-
getOrientation
Returns the orientation of the underlying object, or NaN if there is no such orientation. The default implementation assumes that the object is non-null and is an instance of Oriented2D, and calls orientation2D() on it; else it returns NaN. -
draw
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 interfacePortrayal2D
- Overrides:
draw
in classSimplePortrayal2D
-
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
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 classSimplePortrayal2D
-
setSelected
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 interfacePortrayal
- Overrides:
setSelected
in classSimplePortrayal2D
-
getInspector
Description copied from interface:Portrayal
Provide an inspector for an object.- Specified by:
getInspector
in interfacePortrayal
- Overrides:
getInspector
in classSimplePortrayal2D
-
getName
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 interfacePortrayal
- Overrides:
getName
in classSimplePortrayal2D
-
handleMouseEvent
public boolean handleMouseEvent(GUIState guistate, Manipulating2D manipulating, LocationWrapper wrapper, MouseEvent event, DrawInfo2D fieldPortrayalDrawInfo, int type) Description copied from class:SimplePortrayal2D
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.
If you're modifying or querying the model as a result of this event, be sure to lock on guistate.state.schedule before you do so.
- Overrides:
handleMouseEvent
in classSimplePortrayal2D
-