Multivalent API

multivalent.std
Class ClipProvenance

java.lang.Object
  extended by multivalent.VObject
      extended by multivalent.Behavior
          extended by multivalent.std.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 java.lang.String MENU_CATEGORY
          Menu category for pasting-related options ("AuxSelect").
static java.lang.String MSG_SET
          Augment pasted text with provenance or not.
 
Fields inherited from class multivalent.Behavior
ATTR_BEHAVIOR, name_
 
Fields inherited from class multivalent.VObject
attr_
 
Constructor Summary
ClipProvenance()
           
 
Method Summary
 boolean clipboardAfter(java.lang.StringBuffer sb, Node node)
          The clipboard protocol builds up the text in a StringBuffer.
 boolean semanticEventAfter(SemanticEvent se, java.lang.String msg)
          Catch the "setProvenance" event sent in semanticEventBefore, assuming it hasn't been short-circuited by some other behavior.
 boolean semanticEventBefore(SemanticEvent se, java.lang.String msg)
          When the Clipboard menu announces it is being built by sending a semantic event with message VMenu.MSG_CREATE_EDIT and the node of the menu root in the out field, add an entry.
 
Methods inherited from class multivalent.Behavior
buildAfter, buildBefore, checkRep, clipboardBefore, createUI, destroy, eventAfter, eventBefore, formatAfter, formatBefore, getBrowser, getDocument, getInstance, getInstance, getLayer, getLogger, getName, getPreference, getRoot, isEditable, paintAfter, paintBefore, putPreference, redo, restore, restoreChildren, save, setName, toString, undo
 
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

MENU_CATEGORY

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

See Also:
Constant Field Values

MSG_SET

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

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

See Also:
Constant Field Values
Constructor Detail

ClipProvenance

public ClipProvenance()
Method Detail

semanticEventBefore

public boolean semanticEventBefore(SemanticEvent se,
                                   java.lang.String msg)
When the Clipboard menu announces it is being built by sending a semantic event with message VMenu.MSG_CREATE_EDIT and the node of the menu root in the out field, add an entry. The entry uses Behavior.createUI(String, String, Object, INode, String, boolean) 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).

Overrides:
semanticEventBefore in class Behavior

semanticEventAfter

public boolean semanticEventAfter(SemanticEvent se,
                                  java.lang.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 Document.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.

Overrides:
semanticEventAfter in class Behavior

clipboardAfter

public boolean clipboardAfter(java.lang.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.

Overrides:
clipboardAfter in class Behavior

Multivalent API