|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsim.portrayal.FieldPortrayal
public abstract class FieldPortrayal
A FieldPortrayal is an object which knows how to portray some kind of Field.
This abstract version of FieldPortrayal provides some basic functionality that many FieldPortrayals may find handy. This functionality allows a FieldPortrayal to store Portrayal objects responsible for drawing various objects within the Field. For example, a SparseGrid2D holds a bunch of objects: the SparseGridPortrayal2D, which is a FieldPortrayal, lets you store Portrayal objects which know how to draw the various objects in the SparseGrid2D.
You can associate a Portrayal object with an object stored in the Field in several ways. First, you can specify one Portrayal object to be used for ALL objects stored in the field, using setPortrayalForAll. Second, you can specify a Portrayal object to be used for objects in a Field all belonging to the same class, using setPortrayalForClassOf. Third, you can specify a Portrayal for a specific object, using setPortrayalForObject.
You can get the desired Portrayal for an object by calling getPortrayalForObject. This method looks up the Portrayal for an object by going down the following checklist until a Portrayal is found (earlier checklist items take precedence over later ones):
FieldPortrayals store Portrayal objects in WeakHashMaps. This means that if you register a Portrayal explicitly for an object, and then later the object is eliminated from your model, the FieldPortrayal will not hold onto the object or onto its Portrayal, but will allow them to garbage collect as well. Thus you don't have to worry about de-registering an object.
Some FieldPortrayals benefit (draw faster) if they know that their underlying field is immutable, that is, it never changes. Notably, most FieldPortrayal3Ds benefit, as well as various ValueGrid2DPortrayals.
Nested Class Summary | |
---|---|
class |
FieldPortrayal.CustomInspector
|
Field Summary | |
---|---|
java.util.WeakHashMap |
classPortrayals
|
protected boolean |
dirtyField
This flag is available for Fields to set and clear as they like: but its intended function is to be set during setField(field) to warn drawing that even though the field is immutable, it may have changed to another field and needs to be redrawn. |
protected java.lang.Object |
field
|
protected boolean |
immutableField
|
Portrayal |
portrayalForAll
|
Portrayal |
portrayalForNonNull
|
Portrayal |
portrayalForNull
|
Portrayal |
portrayalForRemainder
|
java.util.WeakHashMap |
portrayals
|
Constructor Summary | |
---|---|
FieldPortrayal()
|
Method Summary | |
---|---|
Portrayal |
getDefaultNullPortrayal()
Returns a default portrayal for null. |
abstract Portrayal |
getDefaultPortrayal()
Should return a portrayal which can portray any object regardless of whether it's valid or not |
java.lang.Object |
getField()
Returns the field. |
Inspector |
getInspector(LocationWrapper wrapper,
GUIState state)
|
java.lang.String |
getName(LocationWrapper wrapper)
|
Portrayal |
getPortrayalForAll()
|
Portrayal |
getPortrayalForNonNull()
|
Portrayal |
getPortrayalForNull()
|
Portrayal |
getPortrayalForObject(java.lang.Object obj)
Returns the appropriate Portrayal. |
Portrayal |
getPortrayalForRemainder()
|
java.lang.String |
getStatus(LocationWrapper wrapper)
|
boolean |
isImmutableField()
Returns true if the underlying field is assumed to be unchanging -- thus there's no reason to update once we're created. |
abstract void |
setField(java.lang.Object field)
Sets the field. |
void |
setImmutableField(boolean val)
Specifies that the underlying field is (or is not) to be assumed unchanging -- thus there's no reason to update once we're created. |
void |
setPortrayalForAll(Portrayal portrayal)
Set the portrayal to null to remove it. |
void |
setPortrayalForClass(java.lang.Class cls,
Portrayal portrayal)
Sets a portrayal for a class -- objects must be of EXACTLY this class (not subclasses) to respond to this. |
void |
setPortrayalForNonNull(Portrayal portrayal)
Set the portrayal to null to remove it. |
void |
setPortrayalForNull(Portrayal portrayal)
Set the portrayal to null to remove it. |
void |
setPortrayalForObject(java.lang.Object obj,
Portrayal portrayal)
Sets a portrayal for a class -- objects must be equal(...) to the provided object here to respond to this. |
void |
setPortrayalForRemainder(Portrayal portrayal)
Set the portrayal to null to remove it. |
boolean |
setSelected(LocationWrapper wrapper,
boolean selected)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public Portrayal portrayalForAll
public Portrayal portrayalForNull
public Portrayal portrayalForNonNull
public Portrayal portrayalForRemainder
public java.util.WeakHashMap portrayals
public java.util.WeakHashMap classPortrayals
protected java.lang.Object field
protected boolean immutableField
protected boolean dirtyField
Constructor Detail |
---|
public FieldPortrayal()
Method Detail |
---|
public void setPortrayalForAll(Portrayal portrayal)
public Portrayal getPortrayalForAll()
public void setPortrayalForNull(Portrayal portrayal)
public Portrayal getPortrayalForNull()
public void setPortrayalForNonNull(Portrayal portrayal)
public Portrayal getPortrayalForNonNull()
public void setPortrayalForRemainder(Portrayal portrayal)
public Portrayal getPortrayalForRemainder()
public void setPortrayalForClass(java.lang.Class cls, Portrayal portrayal)
public void setPortrayalForObject(java.lang.Object obj, Portrayal portrayal)
public Portrayal getDefaultNullPortrayal()
public abstract Portrayal getDefaultPortrayal()
public Portrayal getPortrayalForObject(java.lang.Object obj)
public boolean isImmutableField()
public void setImmutableField(boolean val)
public java.lang.Object getField()
public abstract void setField(java.lang.Object field)
public Inspector getInspector(LocationWrapper wrapper, GUIState state)
public java.lang.String getName(LocationWrapper wrapper)
public java.lang.String getStatus(LocationWrapper wrapper)
public boolean setSelected(LocationWrapper wrapper, boolean selected)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |