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 String | ATTR_XRAY
Document use of attribute in hub document (convention: "ATTR_" prefix). |
static String | MSG_NEWCMD1
New semantic command defined (convention: "MSG_" prefix).
|
static String | MSG_NEWCMD2
Another semantic command, which should be given more descriptive name.
|
static String | PREF_SPEED
Document use of Preferences by listing key/variable name and the type of value.
|
static String | PREF_XRAY
Document use of Preferences (convention: "PREF_" prefix) by listing key/variable name and the type of value.
|
Method Summary |
void | buildAfter(Document doc) |
void | buildBefore(Document doc) |
boolean | checkRep() |
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.
|
boolean | clipboardBefore(StringBuffer sb, Node node) |
void | destroy() |
boolean | eventAfter(AWTEvent e, Point rel, Node n) |
boolean | eventBefore(AWTEvent e, Point rel, Node n) |
boolean | formatAfter(Node node) |
boolean | formatBefore(Node node) |
boolean | paintAfter(Context cx, Node node) |
boolean | paintBefore(Context cx, Node node) |
void | restore(ESISNode n, Map<String,Object> attr, Layer layer) |
ESISNode | save() |
boolean | semanticEventAfter(SemanticEvent se, String msg)
On "NewCommand2", do something else. |
boolean | semanticEventBefore(SemanticEvent se, String msg)
Creates widgets: menu items, ....
|
void | stats(String type) |
String | toString() |
public static final String ATTR_XRAY
Document use of attribute in hub document (convention: "ATTR_" prefix).
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.
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.
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".
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.
public boolean checkRep()
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.
public boolean clipboardBefore(StringBuffer sb,
Node node)
public void destroy()
public boolean eventAfter(AWTEvent e, Point rel,
Node n)
public boolean eventBefore(AWTEvent e, Point rel,
Node n)
public boolean formatAfter(
Node node)
public boolean formatBefore(
Node node)
public void restore(
ESISNode n, Map<String,Object> attr,
Layer layer)
On "NewCommand2", do something else.
Creates widgets: menu items, ....
Responds to "NewCommand1" by recording in statistics, and sending "NewCommand2".
public void stats(String type)
public String toString()