public abstract class FieldPortrayal2D extends FieldPortrayal implements Portrayal2D
The default version of getDefaultPortrayal() returns an empty SimplePortrayal: you'll might want to override that as well. These defaults enable you to use FieldPortrayal2D as an "empty field portrayal" to be attached to a Display2D and draw arbitrary things when its draw(...) method is called. In that case, all you need to do is override the draw(...) method and you're set.
The default versions of hitObjects and draw call a protected but empty method called hitOrDraw. It's very common that a field's hitObjects and draw methods will be identical save for a single line which calls hitObjects or draw on an underlying SimplePortrayal. So most fields unify both methods into this single method and unify the line as something like this:
if (graphics == null) { if (portrayal.hitObject(portrayedObject, newinfo)) putInHere.add(getWrapper(portrayedObject, portrayedObjectLocation)); } else portrayal.draw(portrayedObject, graphics, newinfo);
...where getWrapper(...) returns a LocationWrapper appropriate to the Field.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT
Default buffering: let the program decide on its own (typically in a platform-dependent fashion)
|
static int |
DONT_USE_BUFFER
Don't use a buffer
|
static int |
USE_BUFFER
Use a buffer
|
classPortrayals, field, immutableField, portrayalForAll, portrayalForNonNull, portrayalForNull, portrayalForRemainder, portrayals
Constructor and Description |
---|
FieldPortrayal2D() |
Modifier and Type | Method and Description |
---|---|
void |
draw(java.lang.Object object,
java.awt.Graphics2D graphics,
DrawInfo2D info)
Draws the field with its origin at [info.draw.x,info.draw.y], relative to the
scaled coordinate system defined by [info.draw.width,info.draw.height].
|
int |
getBuffering()
Returns whether or not the FieldPortrayal2D will use a buffering "trick" to draw quickly.
|
java.lang.Object |
getClipLocation(DrawInfo2D info)
Deprecated.
use getPositionLocation
|
Portrayal |
getDefaultPortrayal()
Should return a portrayal which can portray any object regardless of
whether it's valid or not
|
java.awt.geom.Point2D.Double |
getLocationPosition(java.lang.Object location,
DrawInfo2D fieldPortrayalInfo)
Returns the position on-screen of the provided location in the underlying field.
|
java.awt.geom.Point2D.Double |
getObjectPosition(java.lang.Object object,
DrawInfo2D fieldPortrayalInfo)
Returns the position-onscreen of the provided object, assuming that the object exists within the underlying field.
|
java.lang.Object |
getPositionLocation(java.awt.geom.Point2D.Double position,
DrawInfo2D fieldPortrayalInfo)
Returns the Location, in the parlance of the underlying Field, of the given position.
|
java.awt.geom.Point2D.Double |
getRelativeObjectPosition(java.lang.Object location,
java.lang.Object otherObjectLocation,
DrawInfo2D otherObjectInfo)
Returns the position on-screen of an object at a given location in the field,
using another object's location and DrawInfo2D to perform the computation.
|
Double2D |
getScale(DrawInfo2D fieldPortrayalInfo)
Returns the width and height, in pixels, of 1.0 x 1.0 units in the underlying field.
|
void |
hitObjects(DrawInfo2D range,
Bag putInHere)
Adds to the provided Bag LocationWrappers for any objects which
overlap the provided hit range.
|
protected void |
hitOrDraw(java.awt.Graphics2D graphics,
DrawInfo2D info,
Bag putInHere)
Instead of overriding the draw and hitObjects methods, you can optionally override
this method to provide both the draw(...) and hitObjects(...)
functionality in a single method, as it's common that these two methods have nearly
identical code.
|
void |
setBuffering(int val)
Sets whether or not the FieldPortrayal2D will use a buffering "trick" to draw quickly.
|
void |
setObjectPosition(java.lang.Object object,
java.awt.geom.Point2D.Double position,
DrawInfo2D fieldPortrayalInfo)
Moves (or tries to move) the object to an internal location equivalent to the given position on-screen of the
provided object, assuming that the object exists within the underlying field and that this
location is acceptable.
|
getDefaultNullPortrayal, getField, getInspector, getName, getObjectLocation, getPortrayalForAll, getPortrayalForNonNull, getPortrayalForNull, getPortrayalForObject, getPortrayalForRemainder, getStatus, isDirtyField, isImmutableField, reset, setDirtyField, setField, setImmutableField, setObjectLocation, setPortrayalForAll, setPortrayalForClass, setPortrayalForNonNull, setPortrayalForNull, setPortrayalForObject, setPortrayalForRemainder, setSelected, setSelected
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getInspector, getName, getStatus, setSelected
public static final int DEFAULT
public static final int USE_BUFFER
public static final int DONT_USE_BUFFER
public java.awt.geom.Point2D.Double getRelativeObjectPosition(java.lang.Object location, java.lang.Object otherObjectLocation, DrawInfo2D otherObjectInfo)
public void draw(java.lang.Object object, java.awt.Graphics2D graphics, DrawInfo2D info)
draw
in interface Portrayal2D
public void hitObjects(DrawInfo2D range, Bag putInHere)
protected void hitOrDraw(java.awt.Graphics2D graphics, DrawInfo2D info, Bag putInHere)
public Portrayal getDefaultPortrayal()
FieldPortrayal
getDefaultPortrayal
in class FieldPortrayal
public void setObjectPosition(java.lang.Object object, java.awt.geom.Point2D.Double position, DrawInfo2D fieldPortrayalInfo)
public Double2D getScale(DrawInfo2D fieldPortrayalInfo)
public java.lang.Object getPositionLocation(java.awt.geom.Point2D.Double position, DrawInfo2D fieldPortrayalInfo)
public java.awt.geom.Point2D.Double getLocationPosition(java.lang.Object location, DrawInfo2D fieldPortrayalInfo)
public java.lang.Object getClipLocation(DrawInfo2D info)
public java.awt.geom.Point2D.Double getObjectPosition(java.lang.Object object, DrawInfo2D fieldPortrayalInfo)
public int getBuffering()
public void setBuffering(int val)