|
Multivalent API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmultivalent.VObject
multivalent.Behavior
The Behavior is the primary way to extend the system. In fact, behaviors realize all user-level functionality. Behaviors have great power and access to all parts of the system.
behavior creation
getName()
, getLayer()
,
restore
,
build (before
/ after
,
format (before
/ after
,
paint (before
/ paintAfter(Context, Node)
,
clipboard (clipboardBefore(StringBuffer, Node)
/ clipboardAfter(StringBuffer, Node)
,
semantic events (semanticEventBefore(SemanticEvent, String)
/ semanticEventAfter(SemanticEvent, String)
,
low-level events (eventBefore(AWTEvent, Point, Node)
/ eventAfter(AWTEvent, Point, Node)
),
destroy
.
getDocument()
, getRoot()
, getBrowser()
, preferences get
/ set
getLogger()
, checkRep()
createUI(String, String, Object, INode, String, boolean)
)
All behaviors must subclass this class and override the proper protocol methods (build, format, paint, and so on, most with before and after phases) and take the appropriate action when called upon by the system framework. The system framework coordinates behaviors along protocols, and if a behavior adheres to proper implementation of the protocols, it should cooperate well with arbitrary other behaviors.
Behaviors should not define constructors.
The system needs a public no-argument constructor,
to restore by name (with getInstance(String, String, ESISNode, Map, Layer)
which in turn uses Class.forName(String)
and Class.newInstance()
).
The easiest way to accomplish this is to declare the class public and rely on the default no-argument constructor.
(Do initialization in restore(ESISNode, Map, Layer)
.)
The file multivalent/devel/MyBehavior.java in the source code .zip file
is a convenient template for writing general behaviors.
If a behavior is a Span
or Lens
or resembles the function of another behavior,
you can instead copy that source code and modify it.
Field Summary | |
---|---|
static java.lang.String |
ATTR_BEHAVIOR
Class name to instantiate for behavior. |
protected java.lang.String |
name_
Logical name. |
Fields inherited from class multivalent.VObject |
---|
attr_ |
Constructor Summary | |
---|---|
Behavior()
|
Method Summary | |
---|---|
void |
buildAfter(Document doc)
Traverses all behaviors from lowest to highest priority, during which tweaks hack their content into the tree, |
void |
buildBefore(Document doc)
A round robin protocol, here traversing all behaviors from highest to lowest priority, during which main contributors of document content (called media adaptors) hack their content into the tree, and annotators set Marks to robust anchor to locations to hack in buildAfter so as not to disturb positioning by other annotations. |
boolean |
checkRep()
Checks "representation invariant" (see MIT SE), and returns true iff object is valid, which should be always |
boolean |
clipboardAfter(java.lang.StringBuffer sb,
Node node)
A tree walk protocol, called after observed node has been given a chance to contribute to the growing selection content in the passed StringBuffer. |
boolean |
clipboardBefore(java.lang.StringBuffer sb,
Node node)
A tree walk protocol, called before observed node has been given a chance to contribute to the growing selection content in the passed StringBuffer. |
Node |
createUI(java.lang.String type,
java.lang.String title,
java.lang.Object script,
INode parent,
java.lang.String category,
boolean disabled)
Convenience function for UI building. |
void |
destroy()
Protocol. |
boolean |
eventAfter(java.awt.AWTEvent e,
java.awt.Point rel,
Node n)
During eventBefore(AWTEvent, Point, Node) , the behaviors that take primary action to that event should do so,
after having given other behaviors the opportunity to filter it during eventBefore. |
boolean |
eventBefore(java.awt.AWTEvent e,
java.awt.Point rel,
Node n)
|
boolean |
formatAfter(Node node)
A tree walk protocol, called after observed node has been formatted. |
boolean |
formatBefore(Node node)
A tree walk protocol, called before observed node has been formatted. |
Browser |
getBrowser()
Convenience method to fetch Browser from Layer. |
Document |
getDocument()
Convenience method to fetch Document from Layer. |
static Behavior |
getInstance(java.lang.String logicalname,
java.lang.String behaviorclass,
ESISNode children,
java.util.Map<java.lang.String,java.lang.Object> attr,
Layer layer)
Centralized behavior instantiation factory: instantiate all behaviors through this method -- never use new behavior(...) |
static Behavior |
getInstance(java.lang.String logicalname,
java.lang.String behaviorclass,
java.util.Map<java.lang.String,java.lang.Object> attr,
Layer layer)
Used in hub instantiation. |
Layer |
getLayer()
Link to containing layer, which links to Document and so on to Root, Browser, Multivalent. |
static java.util.logging.Logger |
getLogger()
|
java.lang.String |
getName()
Returns the String used to instantiate the Behavior via getInstance(String, String, Map, Layer) . |
java.lang.String |
getPreference(java.lang.String name,
java.lang.String defaultval)
Convenience method for getting preference in class Multivalent. |
Root |
getRoot()
Convenience method to fetch Root from Browser. |
boolean |
isEditable()
|
boolean |
paintAfter(Context cx,
Node node)
A tree walk protocol, called before observed node has been painted. |
boolean |
paintBefore(Context cx,
Node node)
A tree walk protocol, called before observed node has been painted. |
void |
putPreference(java.lang.String name,
java.lang.String val)
Convenience method for putting preference in class Multivalent. |
void |
redo()
Future protocol: Name and all overloads reserved for future use. |
void |
restore(ESISNode n,
java.util.Map<java.lang.String,java.lang.Object> attr,
Layer layer)
Takes the place of a constructor's initialization functions; that is, it is invoked exactly once immediately after object instantiation. |
void |
restoreChildren(ESISNode n,
Layer layer)
Recursively process ESIS children, restore children as behaviors. |
ESISNode |
save()
Build up save data as ESIS tree, then write that out. |
boolean |
semanticEventAfter(SemanticEvent se,
java.lang.String msg)
Round robin distribution to all behaviors. |
boolean |
semanticEventBefore(SemanticEvent se,
java.lang.String msg)
Round robin distribution to all behaviors. |
void |
setName(java.lang.String name)
|
java.lang.String |
toString()
Dump name of behavior and identifying/distinguishing short excerpt of content. |
void |
undo()
Future protocol: Name and all overloads reserved for future use. |
Methods inherited from class multivalent.VObject |
---|
attrEntrySetIterator, attrKeysIterator, clearAttributes, getAttr, getAttr, getAttributes, getGlobal, getValue, hasAttributes, putAttr, removeAttr, setAttributes |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String ATTR_BEHAVIOR
protected java.lang.String name_
Constructor Detail |
---|
public Behavior()
Method Detail |
---|
public java.lang.String getName()
getInstance(String, String, Map, Layer)
.
This can be the same as getClass().getName(), such as multivalent.std.lens.Note
,
but usually should be a short name referring to the type of behavior, such as "Note",
which can then be mapped into a specific Java class name via the table in a user's Preferences.txt file.
getName
in class VObject
public void setName(java.lang.String name)
public Layer getLayer()
public Document getDocument()
public Root getRoot()
public Browser getBrowser()
public java.lang.String getPreference(java.lang.String name, java.lang.String defaultval)
public void putPreference(java.lang.String name, java.lang.String val)
public boolean isEditable()
public static Behavior getInstance(java.lang.String logicalname, java.lang.String behaviorclass, ESISNode children, java.util.Map<java.lang.String,java.lang.Object> attr, Layer layer)
new behavior(...)
.
restore(ESISNode, Map, Layer)
is called as part of instantiation, serving the place of arguments to a constructor.
Logical names are normalized to all lowercase.
public static Behavior getInstance(java.lang.String logicalname, java.lang.String behaviorclass, java.util.Map<java.lang.String,java.lang.Object> attr, Layer layer)
public ESISNode save()
super.save()
.
Always have ATTR_BEHAVIOR
from save (short) classname.
public void restore(ESISNode n, java.util.Map<java.lang.String,java.lang.Object> attr, Layer layer)
public void restoreChildren(ESISNode n, Layer layer)
public void buildBefore(Document doc)
Mark
public void buildAfter(Document doc)
public boolean formatBefore(Node node)
public boolean formatAfter(Node node)
public boolean paintBefore(Context cx, Node node)
public boolean paintAfter(Context cx, Node node)
public boolean clipboardBefore(java.lang.StringBuffer sb, Node node)
public boolean clipboardAfter(java.lang.StringBuffer sb, Node node)
public boolean semanticEventBefore(SemanticEvent se, java.lang.String msg)
public boolean semanticEventAfter(SemanticEvent se, java.lang.String msg)
public boolean eventBefore(java.awt.AWTEvent e, java.awt.Point rel, Node n)
SemanticEvent
,
AWTEvent
,
Browser
,
LensMan
public boolean eventAfter(java.awt.AWTEvent e, java.awt.Point rel, Node n)
eventBefore(AWTEvent, Point, Node)
, the behaviors that take primary action to that event should do so,
after having given other behaviors the opportunity to filter it during eventBefore.
public final void undo()
public final void redo()
public void destroy()
public static java.util.logging.Logger getLogger()
public Node createUI(java.lang.String type, java.lang.String title, java.lang.Object script, INode parent, java.lang.String category, boolean disabled)
type
- is one of "button", "checkbox", "radiobox", "menubutton", "separator", "entry", "label".title
- can be HTML fragment.script
- can be a String
or SemanticEvent
SemanticUI
public boolean checkRep()
VObject
checkRep
in class VObject
public java.lang.String toString()
toString
in class java.lang.Object
|
Multivalent API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |