|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsim.portrayal.SimplePortrayal2D
sim.portrayal.simple.MovablePortrayal2D
public class MovablePortrayal2D
A wrapper for other Portrayal2Ds which makes it possible to drag and move objects with the mouse.
This portrayal is used simply by wrapping around another portrayal or around null (if the object portrays itself).
If you declare a MovablePortrayal2D for an object, you will be able to move it in any field portrayal which supports the basic functions for moving objects. These at present are the various Sparse portrayals and the Continuous2D portrayal.
Moving an object also selects it and deselects other objects.
It's possible that an object wants to control how it's moved. For example, you may have objects which maintain their own internal location and don't like to be moved without being informed. You can still use them with MovablePortrayal2D if they implement the Fixed2D interface, implementing its sole method to move themselves in their field, and then returning false. Similarly objects can implement this interface to simply deny moving at all, for example at certain points of time in the simulation.
IMPORTANT NOTE: If using AdjustablePortrayal2D in conjunction with MovablePortrayal2D, always wrap the MovablePortrayal2D inside the AdjustablePortrayal2D, not the other way around.
Field Summary | |
---|---|
SimplePortrayal2D |
child
|
Fields inherited from class sim.portrayal.SimplePortrayal2D |
---|
TYPE_HIT_OBJECT, TYPE_SELECTED_OBJECT |
Constructor Summary | |
---|---|
MovablePortrayal2D(SimplePortrayal2D child)
|
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. |
boolean |
handleMouseEvent(Manipulating2D manipulating,
LocationWrapper wrapper,
java.awt.event.MouseEvent event,
DrawInfo2D range,
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 sim.portrayal.SimplePortrayal2D |
---|
getStatus |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public SimplePortrayal2D child
Constructor Detail |
---|
public MovablePortrayal2D(SimplePortrayal2D child)
Method Detail |
---|
public SimplePortrayal2D getChild(java.lang.Object object)
public void draw(java.lang.Object object, java.awt.Graphics2D graphics, DrawInfo2D info)
Portrayal2D
draw
in interface Portrayal2D
draw
in class SimplePortrayal2D
public boolean handleMouseEvent(Manipulating2D manipulating, LocationWrapper wrapper, java.awt.event.MouseEvent event, DrawInfo2D range, 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.
handleMouseEvent
in class SimplePortrayal2D
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
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |