Package sim.portrayal
Interface Constrained
public interface Constrained
A Constrained object has control over how it is moved by a Field Portrayal, notably
via MovablePortrayal2D.
Objects which implement this method can:
- Prevent MovablePortrayal2D or other portrayals from moving the object in the field.
- Revise the location to which they are being moved (for example, to only allow movement along a vertical line, say).
- Discover that they're about to be moved and update their internal belief about their location accordingly.
Objects which do NOT implement this interface have no say: MovablePortrayal2D will have FieldPortrayals go directly to their fields and move them about.
-
Method Summary
Modifier and TypeMethodDescriptionconstrainLocation
(Object field, Object location) Given a field and a proposed location to move the Object to, returns a new location to which the Object should actually be moved, or (optionally) null, which means that the Object should not be moved.
-
Method Details
-
constrainLocation
Given a field and a proposed location to move the Object to, returns a new location to which the Object should actually be moved, or (optionally) null, which means that the Object should not be moved.- If you are fine with being moved to location, just return location.
- If you don't want to be moved, return null.
- If you want to override the proposed location and change it to somewhere else, simply return a revised location.
-