multivalent.std.span

Class MoveTextSpan

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.)
  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.)
  6. Link arrow display to update when an endpoint point changes. (Override Span and Span and catch 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.)
  8. Implement move text action. (Model after action.)
  9. Save and restore annotation to disk. (Extend save and Span 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 Behavior.

Field Summary
static StringMSG_RESET_DEST
Semantic event that removes the destination point so that it may be placed elsewhere.
Method Summary
booleanappearance(Context cx, boolean all)
Draw source text differently depending on whether executable or waiting for destination point.
voidbuildAfter(Document doc)
Attach destination point as well.
voiddestroy()
Also remove destination point and recompute display (to remove circle and arrow).
voidevent(AWTEvent e)
booleaneventAfter(AWTEvent e, Point rel, Node obsn)
If no destination point, click-drag to set (re-fire keyboard events out so can still scroll).
voidexecute()
Remove source text, insert at destination point.
booleanformatAfter(Node node)
After formatted affected area, recompute coordinates of circle and arrow.
voidmoveq(Leaf ln, int lo, Leaf rn, int ro)
Also recompute display.
booleanpaintAfter(Context cx, Node node)
Draw line between source and destination.
voidrestore(ESISNode n, Map<String,Object> attr, Layer layer)
ESISNodesave()
Source text location saved by superclass, so just need to save endpoint (using a Robust Location, of course).
booleansemanticEventAfter(SemanticEvent se, String msg)
Handle MSG_RESET_DEST event....
booleansemanticEventBefore(SemanticEvent se, String msg)
Add "Re-Set move to point" to span-specific popup menu.
protected voidsetDisplay()
Set observer, compute coordinates.
protected voidspanExit()
Several exit points in event(), so collect together.

Field Detail

MSG_RESET_DEST

public static final 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.

Method Detail

appearance

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

buildAfter

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

destroy

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

event

public void event(AWTEvent e)

eventAfter

public boolean eventAfter(AWTEvent e, 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.

execute

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

formatAfter

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

moveq

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

paintAfter

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

restore

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

save

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

semanticEventAfter

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

semanticEventBefore

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

setDisplay

protected void setDisplay()
Set observer, compute coordinates.

spanExit

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