Multivalent API

multivalent
Class Leaf

java.lang.Object
  extended by multivalent.VObject
      extended by multivalent.Node
          extended by multivalent.Leaf
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
FixedLeafShade, LeafBlock, LeafImage, LeafShadow, LeafShape, LeafText, LeafZero, VScrollbar, VSeparator

public class Leaf
extends Node

Leaf nodes are words of text, XDOC words, images, and so on. Many media adaptors subclass Leaf for their own type of nodes.

Version:
$Revision: 1.11 $ $Date: 2003/06/02 05:07:40 $

Field Summary
 
Fields inherited from class multivalent.Node
align, ALIGN_INVALID, ATTR_ID, ATTR_SCRIPT, baseline, BASELINE, bbox, BOTH, BOTTOM, CENTER, CHAR, FILL, floats, INHERIT, JUSTIFY, LEFT, MAXNONSTRUCTDEPTH, MIDDLE, name_, NONE, observers_, parent_, PROBEWIDTH, RIGHT, sticky_, stickycnt_, TOP, valid_, valign
 
Fields inherited from class multivalent.VObject
attr_
 
Constructor Summary
Leaf(java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> attrs, INode parent)
          In most cases a Leaf's attributes are null, as in a word of text, but image nodes have attributes.
 
Method Summary
 void append(Leaf l)
          Append leaf to the end of this one, adjusting content, spans, and so on.
 boolean checkRep()
          Checks "representation invariant" (see MIT SE), and returns true iff object is valid, which should be always
 void clipboardBeforeAfter(java.lang.StringBuffer txt, int start, int end)
           
 void clipboardNode(java.lang.StringBuffer sb)
          To build up selection, pass a StringBuffer to media-specific leaves, which fill it as appropriate for that medium.
 java.lang.String copy(int startoff, Leaf endn, int endoff)
           
 java.lang.String cut(int startoff, Leaf endn, int endoff)
           
 void delete(int startoff, Leaf endn, int endoff)
           
 int dx()
          X-coordinate transformation needed when entering this node's relative coordinate system.
 int dy()
          Y-coordinate transformation needed when entering this node's relative coordinate system.
 java.lang.String eatme(int startoff, Leaf endn, int endoff)
           
 boolean eventBeforeAfter(java.awt.AWTEvent e, java.awt.Point rel)
          Point can be null when it's a semantic event sent to tree nodes.
 boolean eventNode(java.awt.AWTEvent e, java.awt.Point rel)
          unless overridden, leaves see if owner is interested
 boolean formatBeforeAfter(int width, int height, Context cx)
          In the depth-first tree traversal to format tree, Before and after methods of behavior observers invoked here; actual formatting passed on to formatNode().
 boolean formatNode(int width, int height, Context cx)
          Handles span transitions on node and elided portions.
 boolean formatNodeContent(Context cx, int start, int end)
           
 Leaf getFirstLeaf()
           
 Leaf getLastLeaf()
           
 void insert(int startoff, char ch, INode bounds)
          Insert character at point.
 void insert(int startoff, java.lang.String txt, INode bounds)
          Insert string of possibly many words at point.
 boolean isLeaf()
           
 int lengthTo(int starti, Leaf endn, int endi)
           
 void markDirtySubtreeDown(boolean leavestoo)
          Mark dirty all nodes in subtree (down tree only).
 java.awt.Point offset2rel(int offset)
          Given an offset into a Leaf, return corresponding subcomponent geometric point.
 void paintBeforeAfter(java.awt.Rectangle docclip, Context cx)
          The logical size of the node.
 void paintNode(java.awt.Rectangle docclip, Context cx)
          Call paintNodeContent with longest range of unchanged Context.
 boolean paintNodeContent(Context cx, int start, int end)
           
 void paste(int startoff)
           
 void paste(java.lang.String txt, int startoff)
           
 void removeTidy(INode root)
          Remove node from tree tidily: don't leave behind empty INode, recursively up to root, and brush span transitions to the size (Span.stretch(Leaf, INode)).
 void setName(java.lang.String name)
           
 void split(int off)
          Split this node into two nodes starting at same position under current parent, and handling content, spans, and so on.
protected  void subelement()
           
 void subelementCalc(Context cx)
          Media leaves override this to map an (x,y) point into an internal location.
 int subelementHit(java.awt.Point rel)
          Given a geometric point within the leaf, return index of corresponding subcomponent (e.g., letter within word).
 
Methods inherited from class multivalent.Node
addObserver, addSticky, addSticky, breakAfter, breakBefore, childNum, clipboardBeforeAfter, clone, cmp, commonAncestor, commonAncestor, contains, contains, deleteObserver, dump, dump, dump, findBFS, findBFS, findBFS, findDFS, findDFS, findDFS, findDFS, getAbsLocation, getActivesAt, getActivesAt, getActivesAt, getBbox, getBrowser, getDocument, getElementById, getIScrollPane, getName, getNextLeaf, getNextNode, getNodeName, getObservers, getParentNode, getPrevLeaf, getPrevNode, getRelLocation, getRoot, getSticky, indexSticky, intersects, isStruct, isValid, markDirty, markDirtySubtree, markDirtyTo, morphInto, reformat, remove, removeSticky, removeSticky, repaint, repaint, repaint, repaint, scrollTo, scrollTo, setParentNode, setValid, size, sizeSticky, spanChunky, spanChunky, structChildNum, toString
 
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
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Leaf

public Leaf(java.lang.String name,
            java.util.Map<java.lang.String,java.lang.Object> attrs,
            INode parent)
In most cases a Leaf's attributes are null, as in a word of text, but image nodes have attributes.

Method Detail

setName

public void setName(java.lang.String name)
Specified by:
setName in class Node

isLeaf

public final boolean isLeaf()
Overrides:
isLeaf in class Node

dx

public int dx()
Description copied from class: Node
X-coordinate transformation needed when entering this node's relative coordinate system.

Specified by:
dx in class Node

dy

public int dy()
Description copied from class: Node
Y-coordinate transformation needed when entering this node's relative coordinate system.

Specified by:
dy in class Node

getFirstLeaf

public final Leaf getFirstLeaf()
Specified by:
getFirstLeaf in class Node

getLastLeaf

public final Leaf getLastLeaf()
Specified by:
getLastLeaf in class Node

formatBeforeAfter

public boolean formatBeforeAfter(int width,
                                 int height,
                                 Context cx)
Description copied from class: Node
In the depth-first tree traversal to format tree, Before and after methods of behavior observers invoked here; actual formatting passed on to formatNode(). In documents with layed out content, children set their dimensions and parents set their location. In documents with absolutely positioned content, usually leaves position themselves and internal nodes compute relative coordinates. If node is valid, its entire subtree is assumed formatted and this method returns without doing anything. Behavior observers return true to shortcircuit traversal of subtree, which this method on Node passes back up the tree.

Overrides:
formatBeforeAfter in class Node
Parameters:
width - of screen, or fraction thereof available to be taken by node
height - of screen, or fraction thereof available to be taken by node (largely ignored in HTML, which has infinitely long scroll, except in FRAME)
See Also:
Behavior

formatNode

public boolean formatNode(int width,
                          int height,
                          Context cx)
Handles span transitions on node and elided portions. Called medium-specific leaf formatNodeContent in hunks of maximum-length homogeneous span coverage to get content size. Marks node valid, so if node not (e.g., LeafImage's image not loaded), set valid_=false in formatNodeContent.

Specified by:
formatNode in class Node

formatNodeContent

public boolean formatNodeContent(Context cx,
                                 int start,
                                 int end)

paintBeforeAfter

public void paintBeforeAfter(java.awt.Rectangle docclip,
                             Context cx)
The logical size of the node. Spans can be anchored from 0..size().

Overrides:
paintBeforeAfter in class Node

paintNode

public void paintNode(java.awt.Rectangle docclip,
                      Context cx)
Call paintNodeContent with longest range of unchanged Context.

Specified by:
paintNode in class Node

paintNodeContent

public boolean paintNodeContent(Context cx,
                                int start,
                                int end)

subelement

protected void subelement()

subelementHit

public int subelementHit(java.awt.Point rel)
Given a geometric point within the leaf, return index of corresponding subcomponent (e.g., letter within word). See offset2rel().


offset2rel

public java.awt.Point offset2rel(int offset)
Given an offset into a Leaf, return corresponding subcomponent geometric point. See offset2rel().


subelementCalc

public void subelementCalc(Context cx)
Media leaves override this to map an (x,y) point into an internal location. For example, ASCII maps the point into a character position. Since the internal location must be represented as an integer, an image could encode an internal (x,y) position as (y*width)+x


clipboardNode

public void clipboardNode(java.lang.StringBuffer sb)
Description copied from class: Node
To build up selection, pass a StringBuffer to media-specific leaves, which fill it as appropriate for that medium. Need to fix this to respect subelement addressing

Specified by:
clipboardNode in class Node

clipboardBeforeAfter

public void clipboardBeforeAfter(java.lang.StringBuffer txt,
                                 int start,
                                 int end)

eventBeforeAfter

public boolean eventBeforeAfter(java.awt.AWTEvent e,
                                java.awt.Point rel)
Point can be null when it's a semantic event sent to tree nodes.

Overrides:
eventBeforeAfter in class Node

eventNode

public boolean eventNode(java.awt.AWTEvent e,
                         java.awt.Point rel)
unless overridden, leaves see if owner is interested

Specified by:
eventNode in class Node
See Also:
TreeEvent, SemanticEvent

removeTidy

public void removeTidy(INode root)
Remove node from tree tidily: don't leave behind empty INode, recursively up to root, and brush span transitions to the size (Span.stretch(Leaf, INode)).

Overrides:
removeTidy in class Node
See Also:
Node.remove()

markDirtySubtreeDown

public void markDirtySubtreeDown(boolean leavestoo)
Description copied from class: Node
Mark dirty all nodes in subtree (down tree only).

Specified by:
markDirtySubtreeDown in class Node

lengthTo

public int lengthTo(int starti,
                    Leaf endn,
                    int endi)

insert

public void insert(int startoff,
                   char ch,
                   INode bounds)
Insert character at point.


insert

public void insert(int startoff,
                   java.lang.String txt,
                   INode bounds)
Insert string of possibly many words at point. Preserves validity of marks and spans. If inserting at cursor, cursor moved to point after inserted text (that may be too much policy, or centralizing that at the lowest level here is exactly the right place).. MOVE TO LeafText, since bogus for everything else (images, ...).


append

public void append(Leaf l)
Append leaf to the end of this one, adjusting content, spans, and so on. The appended leaf must either immediately follow this one in the tree, or be unattached to the tree. The appended leaf should be considered invalid and not used subsequently.


split

public void split(int off)
Split this node into two nodes starting at same position under current parent, and handling content, spans, and so on.


delete

public void delete(int startoff,
                   Leaf endn,
                   int endoff)

cut

public java.lang.String cut(int startoff,
                            Leaf endn,
                            int endoff)

eatme

public java.lang.String eatme(int startoff,
                              Leaf endn,
                              int endoff)

copy

public java.lang.String copy(int startoff,
                             Leaf endn,
                             int endoff)

paste

public void paste(int startoff)

paste

public void paste(java.lang.String txt,
                  int startoff)

checkRep

public boolean checkRep()
Description copied from class: VObject
Checks "representation invariant" (see MIT SE), and returns true iff object is valid, which should be always.

Overrides:
checkRep in class Node

Multivalent API