multivalent.devel

Class MyBehavior

public class MyBehavior extends Behavior

Template to use in writing new behaviors -- copy the source code and edit; don't subclass. This class is not packaged in the browser, and so cannot be subclassed. Use this for a fully general behavior. Better to take as model some behavior more closely matching what the new behavior will do, and cut and paste from it; Behavior has a long list of subclasses. However, other behaviors are specialized and drop protocols not used; find those here. If don't do anything special in some protocol, don't override. If do override, always invoke superclass; do this before new code in before phases, after new code in after phases, as shown in models below. Just guidelines; some behaviors may violate patterns, but one should do so knowingly. If you don't need to do anything in a particular protocol, simply delete the corresponding method.

In my code, I use Java's assert for conditions that if violated represent an error in the caller. Exceptions are thrown for those conditions, like parsing errors on bad input, that even correct code can suffer. Sun's code throws exceptions in both cases.

Version: $Revision: 1.4 $ $Date: 2003/02/12 22:20:26 $

Field Summary
static StringATTR_XRAY
Document use of attribute in hub document (convention: "ATTR_" prefix).
static StringMSG_NEWCMD1
New semantic command defined (convention: "MSG_" prefix).
static StringMSG_NEWCMD2
Another semantic command, which should be given more descriptive name.
static StringPREF_SPEED
Document use of Preferences by listing key/variable name and the type of value.
static StringPREF_XRAY
Document use of Preferences (convention: "PREF_" prefix) by listing key/variable name and the type of value.
Method Summary
voidbuildAfter(Document doc)
voidbuildBefore(Document doc)
booleancheckRep()
booleanclipboardAfter(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.
booleanclipboardBefore(StringBuffer sb, Node node)
voiddestroy()
booleaneventAfter(AWTEvent e, Point rel, Node n)
booleaneventBefore(AWTEvent e, Point rel, Node n)
booleanformatAfter(Node node)
booleanformatBefore(Node node)
booleanpaintAfter(Context cx, Node node)
booleanpaintBefore(Context cx, Node node)
voidrestore(ESISNode n, Map<String,Object> attr, Layer layer)
ESISNodesave()
booleansemanticEventAfter(SemanticEvent se, String msg)
On "NewCommand2", do something else.
booleansemanticEventBefore(SemanticEvent se, String msg)
Creates widgets: menu items, ....
voidstats(String type)
StringtoString()

Field Detail

ATTR_XRAY

public static final String ATTR_XRAY
Document use of attribute in hub document (convention: "ATTR_" prefix).

MSG_NEWCMD1

public static final String MSG_NEWCMD1
New semantic command defined (convention: "MSG_" prefix). All "high level" actions should be carried out through sending and receiving semantic events, rather than through direct method invocation, so that other behaviors have a chance to modify the action. In order to publish to clients, behaviors must define the java.lang.String name to use in string-based scripts and in case symbolic reference to this constant is impractical because the defining class may or may not be available (if the symbol is in a multivalent.* class, then it's guaranteed to be available, and so the symbolc reference should be used), and define the use of arg, in, and out fields. There is a form of method overloading, since events with the same message can have arguments of different types. Thus, clients should always check the type of the arguments. A possible definition is the following:

"NewCommand1": arg= java.util.HashMap attributes, in= INode root of tree, out=unused.

A behavior that takes action on the semantic event should document this in its MyBehavior and MyBehavior methods.

See Also: more more examples.

MSG_NEWCMD2

public static final String MSG_NEWCMD2
Another semantic command, which should be given more descriptive name.

"NewCommand2": arg= java.util.HashMap attributes, in= INode root of tree, out=unused.

PREF_SPEED

public static final String PREF_SPEED
Document use of Preferences by listing key/variable name and the type of value. String that is one of "fast", "slow", "stopped".

PREF_XRAY

public static final String PREF_XRAY
Document use of Preferences (convention: "PREF_" prefix) by listing key/variable name and the type of value. Boolean value (Object) indicating whether to show x-rays or not.

Method Detail

buildAfter

public void buildAfter(Document doc)

buildBefore

public void buildBefore(Document doc)

checkRep

public boolean checkRep()

clipboardAfter

public boolean clipboardAfter(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. As a special case, observers on the root are always called, even if the selection is for only a part of the document.

clipboardBefore

public boolean clipboardBefore(StringBuffer sb, Node node)

destroy

public void destroy()

eventAfter

public boolean eventAfter(AWTEvent e, Point rel, Node n)

eventBefore

public boolean eventBefore(AWTEvent e, Point rel, Node n)

formatAfter

public boolean formatAfter(Node node)

formatBefore

public boolean formatBefore(Node node)

paintAfter

public boolean paintAfter(Context cx, Node node)

paintBefore

public boolean paintBefore(Context cx, Node node)

restore

public void restore(ESISNode n, Map<String,Object> attr, Layer layer)

save

public ESISNode save()

semanticEventAfter

public boolean semanticEventAfter(SemanticEvent se, String msg)
On "NewCommand2", do something else.

semanticEventBefore

public boolean semanticEventBefore(SemanticEvent se, String msg)
Creates widgets: menu items, .... Responds to "NewCommand1" by recording in statistics, and sending "NewCommand2".

stats

public void stats(String type)

toString

public String toString()