Multivalent API

multivalent
Class INode

java.lang.Object
  extended by multivalent.VObject
      extended by multivalent.Node
          extended by multivalent.INode
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
FixedI, IClip, INodeZero, IParaBox, IRootAbs, IRootScreen, IScrollPane, IVBox, IZoom, VFrame

public class INode
extends Node

Internal nodes have children. To implement most protocols, pass protocol on to children. Superclass for all internal--that is, structural--nodes in the doc tree.

Bounding box contains border, padding, and content, but not margin, which is taken into account in (x,y) location.

Version:
$Revision: 1.10 $ $Date: 2003/06/02 05:06:47 $
See Also:
Leaf, Span

Field Summary
 java.awt.Insets border
          Border, with possible different widths on each side (counted in bounding box dimensions).
static java.awt.Insets[] INSETS
          Canonical Insets with equal bounds to use to save space over creating new Insets for these common cases.
static java.awt.Insets INSETS_ZERO
          Special name, points to INSETS[0].
 java.awt.Insets margin
          Transparent external space around bounding box (not part of bounding box width or height, as effects incorporated into bounding box (x,y) location).
 java.awt.Insets padding
          Internal space inside border, with same background as content (counted in bounding box dimensions).
 
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
INode(java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> attr, INode parent)
           
 
Method Summary
 Node addCategory(Node n, java.lang.String category)
          Add child to correct category, as in UI panel or menu with groups.
 void appendChild(Node child)
          Adds child to end of list of children.
 boolean breakAfter()
           
 boolean breakBefore()
           
 boolean checkRep()
          Checks "representation invariant" (see MIT SE), and returns true iff object is valid, which should be always
 Node childAt(int num)
          Returns child at given offset, 0 .. size()-1, inclusive.
 int childNum(Node n)
          Returns sequence number node in list of children, -1 iff no such child.
 void clipboardNode(java.lang.StringBuffer txt)
          To select structural region, select all children
protected  java.lang.Object clone()
          Deep copy of Rectangle; observers and sticky set to null.
 boolean contains(Node n)
          Passed node (null OK) somewhere in subtree?
 void dump(int level, int maxlevel)
          Dump more verbose than toString().
 int dx()
          Skip over border, padding to content area.
 int dy()
          Skip over border, padding to content area.
 boolean eventBeforeAfter(java.awt.AWTEvent e, java.awt.Point rel)
          Adjust for bbox (which itself has been adjusted for margins), padding, border.
 boolean eventNode(java.awt.AWTEvent e, java.awt.Point rel)
          Internal nodes pass on to children.
protected  Node findDFS(java.lang.String searchname, java.lang.String attrname, java.lang.String attrval, int level, int maxlevel)
           
 boolean formatBeforeAfter(int width, int height, Context cx)
          Internal nodes might have a structural style LATER: externalize format to a behavior and choose with style sheet.
 boolean formatNode(int width, int height, Context cx)
          Children report dimensions (width and height), parent places at (x,y).
 Node getElementById(java.lang.String elementId)
           
 Node getFirstChild()
          Returns first child, or null if no children.
 Leaf getFirstLeaf()
          If first child is leaf, returns that.
 Node getLastChild()
          Returns last child, or null if no children.
 Leaf getLastLeaf()
          If last child is leaf, returns that.
 Node getNextSibling()
          DOM2 -- childAt() more efficient.
 Node getPreviousSibling()
          DOM2 -- childAt() more efficient.
 void insertChildAt(Node child, int num)
           
 boolean isStruct()
           
 void markDirtySubtreeDown(boolean leavestoo)
          Mark dirty all nodes in subtree (down tree only).
 void paintBeforeAfter(java.awt.Rectangle docclip, Context cx)
           Check to see subtree area within clipping region.
 void paintNode(java.awt.Rectangle docclip, Context cx)
          To paint internal node, paint all children.
 void removeAllChildren()
          Faster than removing one at a time.
 void removeChild(Node child)
          Removes child if it exists among list of children.
 Node removeChildAt(int num)
           
 void setChildAt(Node child, int num)
           
 void setName(java.lang.String name)
          Names of internal nodes are normalized to all-lowercase (but not interned).
 int size()
          Number of addressable components in node: number of children in INode, number of letters in text leaf, zero for invisible nodes such as comments, and otherwise usually one (the default).
 Node structChildAt(int num)
          Some nonstructural nodes (internal nodes with name==null) may be used to better balance trees for better performance.
 int structChildNum(Node n)
           
 int structsize()
          WARNING: This doesn't climb up to lowest structural parent, inconsistently with structChildNum
 
Methods inherited from class multivalent.Node
addObserver, addSticky, addSticky, childNum, clipboardBeforeAfter, cmp, commonAncestor, commonAncestor, contains, deleteObserver, dump, dump, findBFS, findBFS, findBFS, findDFS, findDFS, findDFS, getAbsLocation, getActivesAt, getActivesAt, getActivesAt, getBbox, getBrowser, getDocument, getIScrollPane, getName, getNextLeaf, getNextNode, getNodeName, getObservers, getParentNode, getPrevLeaf, getPrevNode, getRelLocation, getRoot, getSticky, indexSticky, intersects, isLeaf, isValid, markDirty, markDirtySubtree, markDirtyTo, morphInto, reformat, remove, removeSticky, removeSticky, removeTidy, repaint, repaint, repaint, repaint, scrollTo, scrollTo, setParentNode, setValid, 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
 

Field Detail

INSETS

public static final java.awt.Insets[] INSETS
Canonical Insets with equal bounds to use to save space over creating new Insets for these common cases. For example, INSETS[5] has top == bottom == left == right == 5. Treat all Insets as read-only.


INSETS_ZERO

public static final java.awt.Insets INSETS_ZERO
Special name, points to INSETS[0].


margin

public java.awt.Insets margin
Transparent external space around bounding box (not part of bounding box width or height, as effects incorporated into bounding box (x,y) location). Usually layout node will collapse bottom margin of previous Node and top of this; likewise with left and right. Stored here rather than being passed about during formatting so that incremental formatting is simpler (and there aren't that many internal nodes). In other words, margin is used during formatting, but otherwise drops out as its effect is incorporated into bbox.x and bbox.y. Components (top, left, bottom, right) should be treated read only;


border

public java.awt.Insets border
Border, with possible different widths on each side (counted in bounding box dimensions). Components (top, left, bottom, right) should be treated read only.


padding

public java.awt.Insets padding
Internal space inside border, with same background as content (counted in bounding box dimensions). Components (top, left, bottom, right) should be treated read only.

Constructor Detail

INode

public INode(java.lang.String name,
             java.util.Map<java.lang.String,java.lang.Object> attr,
             INode parent)
Method Detail

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException
Description copied from class: Node
Deep copy of Rectangle; observers and sticky set to null. Need to clone when edit and split a Node.

Overrides:
clone in class Node
Throws:
java.lang.CloneNotSupportedException

setName

public void setName(java.lang.String name)
Names of internal nodes are normalized to all-lowercase (but not interned). If name set to null, this indicates a nonstructural node in an otherwise structural tree. Nonstructural nodes can be useful to better balance trees leaning to improved performance. Nonstructural nodes are ignored by Location and other classes.

Specified by:
setName in class Node

isStruct

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

dx

public int dx()
Skip over border, padding to content area.

Specified by:
dx in class Node

dy

public int dy()
Skip over border, padding to content area.

Specified by:
dy in class Node

breakBefore

public boolean breakBefore()
Overrides:
breakBefore in class Node

breakAfter

public boolean breakAfter()
Overrides:
breakAfter in class Node

getFirstLeaf

public final Leaf getFirstLeaf()
If first child is leaf, returns that. If first child is INode, recursively returns that node's getFirstLeaf(). If no chldren, returns null.

Specified by:
getFirstLeaf in class Node

getLastLeaf

public final Leaf getLastLeaf()
If last child is leaf, returns that. If last child is INode, recursively returns that node's getLastLeaf(). If no chldren, returns null.

Specified by:
getLastLeaf in class Node

getFirstChild

public final Node getFirstChild()
Returns first child, or null if no children. Same as childAt(0).


getLastChild

public final Node getLastChild()
Returns last child, or null if no children. Same as childAt(size()-1).


size

public int size()
Description copied from class: Node
Number of addressable components in node: number of children in INode, number of letters in text leaf, zero for invisible nodes such as comments, and otherwise usually one (the default).

Overrides:
size in class Node
Returns:
number of children.

childNum

public int childNum(Node n)
Returns sequence number node in list of children, -1 iff no such child.


childAt

public Node childAt(int num)
Returns child at given offset, 0 .. size()-1, inclusive.


getPreviousSibling

public Node getPreviousSibling()
DOM2 -- childAt() more efficient.


getNextSibling

public Node getNextSibling()
DOM2 -- childAt() more efficient.


appendChild

public void appendChild(Node child)
Adds child to end of list of children. Child automatically removed from old parent, if any. If child alread among children, child moved to end of child list. Node constructors take a parent, which automatically calls appendChild(), or you can pass null as parent and appendChild() or insertChildAt() later.


addCategory

public Node addCategory(Node n,
                        java.lang.String category)
Add child to correct category, as in UI panel or menu with groups.


setChildAt

public void setChildAt(Node child,
                       int num)

insertChildAt

public void insertChildAt(Node child,
                          int num)

removeChildAt

public Node removeChildAt(int num)
Returns:
child removed

removeChild

public void removeChild(Node child)
Removes child if it exists among list of children.


removeAllChildren

public void removeAllChildren()
Faster than removing one at a time.


contains

public boolean contains(Node n)
Passed node (null OK) somewhere in subtree?

Overrides:
contains in class Node

structsize

public int structsize()
WARNING: This doesn't climb up to lowest structural parent, inconsistently with structChildNum


structChildNum

public int structChildNum(Node n)

structChildAt

public final Node structChildAt(int num)
Some nonstructural nodes (internal nodes with name==null) may be used to better balance trees for better performance. This method bypasses nonstructural nodes.


formatBeforeAfter

public boolean formatBeforeAfter(int width,
                                 int height,
                                 Context cx)
Internal nodes might have a structural style LATER: externalize format to a behavior and choose with style sheet.

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)
Children report dimensions (width and height), parent places at (x,y). Bbox = union of children's bboxes Children stacked vertically like TeX vbox; override to implement other layout strategies To implement a new layout manager, override this method.

Specified by:
formatNode in class Node
See Also:
FixedI

paintBeforeAfter

public void paintBeforeAfter(java.awt.Rectangle docclip,
                             Context cx)
  1. Check to see subtree area within clipping region. If not and span transitions, mark cx.valid=false and return.
  2. Add styles from style sheet, if any.
  3. Draw background if differs from enclosing subtree.
  4. Call superclass paintBeforeAfter, which sets coordinate space, calls observers, calls paintNode.
  5. Draw border, if any.
  6. Undo styles

Overrides:
paintBeforeAfter in class Node

paintNode

public void paintNode(java.awt.Rectangle docclip,
                      Context cx)
To paint internal node, paint all children.

Specified by:
paintNode in class Node

clipboardNode

public void clipboardNode(java.lang.StringBuffer txt)
To select structural region, select all children

Specified by:
clipboardNode in class Node

eventBeforeAfter

public boolean eventBeforeAfter(java.awt.AWTEvent e,
                                java.awt.Point rel)
Adjust for bbox (which itself has been adjusted for margins), padding, border.

Overrides:
eventBeforeAfter in class Node

eventNode

public boolean eventNode(java.awt.AWTEvent e,
                         java.awt.Point rel)
Internal nodes pass on to children. Events are propogated from last child to first (and painted first to last), which means that later children have implicitly higher priority as they get first chance at setting a grab. Event passed on only if (x,y) within child's bounding box, or if TreeEvent.VALIDATE event. Event is translated to be in child's coordinate system (that is, (0,0) corresponds to the child's origin).

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

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

getElementById

public Node getElementById(java.lang.String elementId)
Overrides:
getElementById in class Node

findDFS

protected Node findDFS(java.lang.String searchname,
                       java.lang.String attrname,
                       java.lang.String attrval,
                       int level,
                       int maxlevel)
Overrides:
findDFS in class Node

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

dump

public void dump(int level,
                 int maxlevel)
Description copied from class: Node
Dump more verbose than toString().

Overrides:
dump in class Node

Multivalent API