Multivalent API

multivalent.std.span
Class MoveTextSpan

java.lang.Object
  extended by multivalent.VObject
      extended by multivalent.Behavior
          extended by multivalent.Span
              extended by multivalent.std.span.MoveTextSpan
All Implemented Interfaces:
ContextListener, EventListener, java.util.EventListener

public class MoveTextSpan
extends Span

Executable copy editor markup that will move marked text to another point in the document. Set source text span by making selection and invoking menu CopyEd / Move Text. Set destination point by pressing mouse button down in source text, dragging to end point, and releasing (keyboard scrolling is still active in case the end point is not on the same screen). Source range can be moved in same way as other span annotations, that is, by selecting the new destination span and selecting Morph from the span-specific popup menu. Destination point can be moved by removing the current destination by invoking Re-set move to point from that same menu and setting the new one as before. Annotation can subsequently be executed by clicking in the source text.

The illegal operations of trying to place destination point in source text or subsequently moving source text on top of destination are checked and result in the removal of the destination point. If the destination point is one the same line as the start of the source text, the arrow arches up over the intervening text rather that plowing through the middle.

Implementation steps:

  1. Set location of class. (Put in main set of classes but could have put anywhere as long as findable by Java in CLASSPATH.)
  2. UI for setting source text. (Add to Anno menu by adding line to hub via SpanUI in Anno.hub patterned after ReplaceWithSpan.)
  3. Set display for source text, depending on whether not destination point is set. (Model after HyperlinkSpan.appearance(Context, boolean).)
  4. UI in span-specific popup menu. (Add "Re-set move to point" by copying semanticEvent methods from HyperlinkSpan and editing.)
  5. UI for setting destination point. (Model after HyperlinkSpan.eventAfter(AWTEvent, Point, Node).)
  6. Link arrow display to update when an endpoint point changes. (Override Span.moveq(Leaf,int, Leaf,int) and Behavior.formatAfter(Node) and catch Document.MSG_FORMATTED semantic event to recompute display, and destroy() to destroy destination point as well.)
  7. Display of arrow from source to destination. (Override Behavior.paintAfter(Context, Node).)
  8. Implement move text action. (Model after ActionSpan.action().)
  9. Save and restore annotation to disk. (Extend Span.save() and Span.restore(ESISNode, Map, Layer) to include destination point -- superclass already saves range of source text.)
  10. (Tweaking to use java.awt.geom.QuadCurve instead of straight lines and for dragging within active span to revert to setting destination point.)

Version:
$Revision: 1.9 $ $Date: 2003/04/28 03:56:27 $
See Also:
for another elaborately commented example {@link Behavior}.

Field Summary
static java.lang.String MSG_RESET_DEST
          Semantic event that removes the destination point so that it may be placed elsewhere.
 
Fields inherited from class multivalent.Span
GI_END, GI_START, MSG_DELETE, MSG_EDIT, MSG_MORPH, MSG_UNATTACHED, pend, pstart
 
Fields inherited from class multivalent.Behavior
ATTR_BEHAVIOR, name_
 
Fields inherited from class multivalent.VObject
attr_
 
Fields inherited from interface multivalent.ContextListener
LITTLE, LOT, PRIORITY_LENS, PRIORITY_MAX, PRIORITY_MIN, PRIORITY_SELECTION, PRIORITY_SPAN, PRIORITY_STRUCT, SOME
 
Constructor Summary
MoveTextSpan()
           
 
Method Summary
 boolean appearance(Context cx, boolean all)
          Draw source text differently depending on whether executable or waiting for destination point.
 void buildAfter(Document doc)
          Attach destination point as well.
 void destroy()
          Also remove destination point and recompute display (to remove circle and arrow).
 void event(java.awt.AWTEvent e)
          Receives synthesized MouseEvent.MOUSE_ENTERED, MouseEvent.MOUSE_EXITED, MouseEvent.MOUSE_PRESSED, ....
 boolean eventAfter(java.awt.AWTEvent e, java.awt.Point rel, Node obsn)
          If no destination point, click-drag to set (re-fire keyboard events out so can still scroll).
 void execute()
          Remove source text, insert at destination point.
 boolean formatAfter(Node node)
          After formatted affected area, recompute coordinates of circle and arrow.
 void moveq(Leaf ln, int lo, Leaf rn, int ro)
          Also recompute display.
 boolean paintAfter(Context cx, Node node)
          Draw line between source and destination.
 void restore(ESISNode n, java.util.Map<java.lang.String,java.lang.Object> attr, Layer layer)
          Given ESIS subtree, pluck class-specific information from attributes, call super.restore() for locations.
 ESISNode save()
          Source text location saved by superclass, so just need to save endpoint (using a Robust Location, of course).
 boolean semanticEventAfter(SemanticEvent se, java.lang.String msg)
          Handle MSG_RESET_DEST event....
 boolean semanticEventBefore(SemanticEvent se, java.lang.String msg)
          Add "Re-Set move to point" to span-specific popup menu.
protected  void setDisplay()
          Set observer, compute coordinates.
protected  void spanExit()
          Several exit points in event(), so collect together.
 
Methods inherited from class multivalent.Span
checkRep, close, closeAll, contains, contains, getEnd, getPriority, getStart, isSet, markDirty, move, move, move, moveq, moveq, moveqSwap, open, repaint, repaint, stretch, toString
 
Methods inherited from class multivalent.Behavior
buildBefore, clipboardAfter, clipboardBefore, createUI, eventBefore, formatBefore, getBrowser, getDocument, getInstance, getInstance, getLayer, getLogger, getName, getPreference, getRoot, isEditable, paintBefore, putPreference, redo, restoreChildren, setName, 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

MSG_RESET_DEST

public static final java.lang.String MSG_RESET_DEST
Semantic event that removes the destination point so that it may be placed elsewhere.

"resetMoveTo": arg= MoveTextSpan instance, in= MoveTextSpan instance.

See Also:
Constant Field Values
Constructor Detail

MoveTextSpan

public MoveTextSpan()
Method Detail

semanticEventBefore

public boolean semanticEventBefore(SemanticEvent se,
                                   java.lang.String msg)
Add "Re-Set move to point" to span-specific popup menu.

Overrides:
semanticEventBefore in class Span

semanticEventAfter

public boolean semanticEventAfter(SemanticEvent se,
                                  java.lang.String msg)
Handle MSG_RESET_DEST event....

Overrides:
semanticEventAfter in class Span

appearance

public boolean appearance(Context cx,
                          boolean all)
Draw source text differently depending on whether executable or waiting for destination point.

Specified by:
appearance in interface ContextListener
Overrides:
appearance in class Span
all - all attributes or exclude those that are not inherited

eventAfter

public boolean eventAfter(java.awt.AWTEvent e,
                          java.awt.Point rel,
                          Node obsn)
If no destination point, click-drag to set (re-fire keyboard events out so can still scroll). If destination set, execute.

Overrides:
eventAfter in class Behavior

event

public void event(java.awt.AWTEvent e)
Description copied from class: Span
Receives synthesized MouseEvent.MOUSE_ENTERED, MouseEvent.MOUSE_EXITED, MouseEvent.MOUSE_PRESSED, .... For the purposes of event passing, functions more as tree node than behavior (with before/after).

Specified by:
event in interface EventListener
Overrides:
event in class Span

spanExit

protected void spanExit()
Several exit points in event(), so collect together.


setDisplay

protected void setDisplay()
Set observer, compute coordinates.


paintAfter

public boolean paintAfter(Context cx,
                          Node node)
Draw line between source and destination.

Overrides:
paintAfter in class Behavior

formatAfter

public boolean formatAfter(Node node)
After formatted affected area, recompute coordinates of circle and arrow.

Overrides:
formatAfter in class Behavior
Returns:
true to short-circuit formatting of rest of protocol, which consists exclusively of higher-priority behaviors, which almost never want to do.

destroy

public void destroy()
Also remove destination point and recompute display (to remove circle and arrow).

Overrides:
destroy in class Span

moveq

public void moveq(Leaf ln,
                  int lo,
                  Leaf rn,
                  int ro)
Also recompute display.

Overrides:
moveq in class Span

execute

public void execute()
Remove source text, insert at destination point.


save

public ESISNode save()
Source text location saved by superclass, so just need to save endpoint (using a Robust Location, of course).

Overrides:
save in class Span

restore

public void restore(ESISNode n,
                    java.util.Map<java.lang.String,java.lang.Object> attr,
                    Layer layer)
Description copied from class: Span
Given ESIS subtree, pluck class-specific information from attributes, call super.restore() for locations. Attributes named start and end are reserved to hold Robust Location data.

Overrides:
restore in class Span
See Also:
RobustLocation

buildAfter

public void buildAfter(Document doc)
Attach destination point as well.

Overrides:
buildAfter in class Span

Multivalent API