multivalent.std

Class ClipProvenance

public class ClipProvenance extends Behavior

Augment selection for clipboard with source URL. (Would like to augment with author and title, but that sort of metadata usually isn't available.) Elaborately commented to serve as a simple example of translating Multivalent protocols into Java methods.

Version: $Revision: 1.2 $ $Date: 2002/02/01 04:24:17 $

See Also: for another elaborately commented behavior.

Field Summary
static StringMENU_CATEGORY
Menu category for pasting-related options ("AuxSelect").
static StringMSG_SET
Augment pasted text with provenance or not.
Method Summary
booleanclipboardAfter(StringBuffer sb, Node node)
The clipboard protocol builds up the text in a StringBuffer.
booleansemanticEventAfter(SemanticEvent se, String msg)
Catch the "setProvenance" event sent in semanticEventBefore, assuming it hasn't been short-circuited by some other behavior.
booleansemanticEventBefore(SemanticEvent se, String msg)
When the Clipboard menu announces it is being built by sending a semantic event with message MSG_CREATE_EDIT and the node of the menu root in the out field, add an entry.

Field Detail

MENU_CATEGORY

public static final String MENU_CATEGORY
Menu category for pasting-related options ("AuxSelect").

MSG_SET

public static final String MSG_SET
Augment pasted text with provenance or not.

"setProvenance": arg= bollean or null to toggle.

Method Detail

clipboardAfter

public boolean clipboardAfter(StringBuffer sb, Node node)
The clipboard protocol builds up the text in a StringBuffer. Since this is the after phase, we know that the tree walk has taken place, and therefore the StringBuffer holds the text one expects from copying the selection into the clipboard. If the behavior is active (as set by its GUI, slip the URL in at the head of the StringBuffer.

semanticEventAfter

public boolean semanticEventAfter(SemanticEvent se, String msg)
Catch the "setProvenance" event sent in semanticEventBefore, assuming it hasn't been short-circuited by some other behavior. This just sets the internal active flag, to determine whether to take action in the next clipboard procotol. Note that any behavior can communicate with ClipProvenance at this high level by sending the message it understands, namely "setProvenance"; other behaviors don't have to work through its GUI or have hardcoded to some particular method signature--they just send in the event the right String as socially agreed upon (or proclaimed, that is, documented, by ClipProvenance).

This behavior has its effect (if it's active) during the clipboard protocol, but that protocol is based on a tree walk, so if it is to know of the tree walk, it has to hook into the tree. So catch the MSG_OPENED semantic event and hook onto its document field. It registers interest on the root of the document in order to pick up clipboard extractions everywhere in the tree. It's common for a behavior to register interest at the root as opposed to smaller subtrees.

semanticEventBefore

public boolean semanticEventBefore(SemanticEvent se, String msg)
When the Clipboard menu announces it is being built by sending a semantic event with message MSG_CREATE_EDIT and the node of the menu root in the out field, add an entry. The entry uses Behavior to create a "checkbox" widget with title "Provenance", which when invoked will execute the script which sends a semantic event named "setProvenance", added to the menu in category "AuxSelect", and which is not disabled (diabled flag = false).