public class OrientedPortrayal2D extends SimplePortrayal2D
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.
Modifier and Type | Field and Description |
---|---|
SimplePortrayal2D |
child |
static int |
DEFAULT_OFFSET |
static double |
DEFAULT_SCALE |
boolean |
drawFilled |
int |
offset
The post-scaling length offset
|
java.awt.Paint |
paint
The Paint or Color of the line
|
double |
scale
The pre-scaling length
|
static int |
SHAPE_ARROW |
static int |
SHAPE_COMPASS |
static int |
SHAPE_INVERTED_T |
static int |
SHAPE_KITE |
static int |
SHAPE_LINE |
static int |
SHAPE_LINE_ARROW |
static int |
SHAPE_TRIANGLE |
TYPE_HIT_OBJECT, TYPE_SELECTED_OBJECT
Constructor and Description |
---|
OrientedPortrayal2D(SimplePortrayal2D child)
Draw 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,
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 offset,
double scale,
java.awt.Paint paint,
int shape) |
OrientedPortrayal2D(SimplePortrayal2D child,
java.awt.Paint paint)
Draw a line of length scale = 0.5, offset = 0.
|
Modifier and Type | Method and Description |
---|---|
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.
|
boolean |
getOnlyDrawWhenSelected() |
double |
getOrientation(java.lang.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,
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 |
isDrawFilled() |
boolean |
isLineShowing()
Deprecated.
use isOrientationShowing()
|
boolean |
isOrientationHittable()
Returns true if the orientation marker can be hit as part of the object.
|
boolean |
isOrientationShowing() |
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) |
getStatus
public static final double DEFAULT_SCALE
public static final int DEFAULT_OFFSET
public static final int SHAPE_LINE
public static final int SHAPE_LINE_ARROW
public static final int SHAPE_KITE
public static final int SHAPE_COMPASS
public static final int SHAPE_TRIANGLE
public static final int SHAPE_INVERTED_T
public static final int SHAPE_ARROW
public double scale
public int offset
public java.awt.Paint paint
public SimplePortrayal2D child
public boolean drawFilled
public OrientedPortrayal2D(SimplePortrayal2D child, int offset, double scale, java.awt.Paint paint, int shape)
public OrientedPortrayal2D(SimplePortrayal2D child, int offset, double scale, java.awt.Paint paint)
public OrientedPortrayal2D(SimplePortrayal2D child)
public OrientedPortrayal2D(SimplePortrayal2D child, int offset, double scale)
public OrientedPortrayal2D(SimplePortrayal2D child, java.awt.Paint paint)
public void setShape(int val)
public int getShape()
public void setDrawFilled(boolean val)
public boolean isDrawFilled()
public boolean isOrientationShowing()
public void setOrientationShowing(boolean val)
public boolean isLineShowing()
public void setLineShowing(boolean val)
public void setOnlyDrawWhenSelected(boolean val)
public boolean getOnlyDrawWhenSelected()
public SimplePortrayal2D getChild(java.lang.Object object)
public double getOrientation(java.lang.Object object, DrawInfo2D info)
public void draw(java.lang.Object object, java.awt.Graphics2D graphics, DrawInfo2D info)
Portrayal2D
draw
in interface Portrayal2D
draw
in class SimplePortrayal2D
public boolean isOrientationHittable()
public void setOrientationHittable(boolean val)
public boolean hitObject(java.lang.Object object, DrawInfo2D range)
SimplePortrayal2D
hitObject
in class SimplePortrayal2D
public boolean setSelected(LocationWrapper wrapper, boolean selected)
Portrayal
setSelected
in interface Portrayal
setSelected
in class SimplePortrayal2D
public Inspector getInspector(LocationWrapper wrapper, GUIState state)
Portrayal
getInspector
in interface Portrayal
getInspector
in class SimplePortrayal2D
public java.lang.String getName(LocationWrapper wrapper)
Portrayal
getName
in interface Portrayal
getName
in class SimplePortrayal2D
public boolean handleMouseEvent(GUIState guistate, Manipulating2D manipulating, LocationWrapper wrapper, java.awt.event.MouseEvent event, DrawInfo2D fieldPortrayalDrawInfo, int type)
SimplePortrayal2D
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.
handleMouseEvent
in class SimplePortrayal2D