|
Multivalent API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmultivalent.VObject
multivalent.Node
Base class for nodes of the document tree (both user interface and content), providing common tree manipulation methods
as well as implementing before and after phases of tree walk protocols,
calling another method that can be easily overridden.
Do not subclass this class; use or subclass either of INode
for internal nodes or Leaf
for leaves.
name
, parent
, bbox
, baseline
, align
, valign
, floats
remove()
,
getParentNode()
, getNextNode()
, getPrevNode()
, getFirstLeaf()
, getLastLeaf()
,
commonAncestor(Node)
, cmp(Node, int, Node, int, INode)
,
findDFS(String, String, String, int)
, findBFS(String, String, String, int)
isValid()
, setValid(boolean)
, markDirty()
, markDirtySubtree(boolean)
, markDirtyTo(Node)
Behavior
's protocols:
dx()
and dy()
, getAbsLocation()
, getRelLocation(Node)
observers
Browser
, Root
, Document
, IScrollPane
.
stickies
, or summary information in leaves
MediaAdaptor
,
Root
,
Document
,
Behavior
Field Summary | |
---|---|
byte |
align
Justification (LEFT, RIGHT, CENTER, FILL/JUSTIFY) -- set with style sheet if possible. |
static byte |
ALIGN_INVALID
Alignment. |
static java.lang.String |
ATTR_ID
|
static java.lang.String |
ATTR_SCRIPT
Associated VScript script. |
int |
baseline
Baseline, relative to top of bounding box. |
static byte |
BASELINE
Alignment. |
java.awt.Rectangle |
bbox
Bounding box, in pixels, location relative to parent node. |
static byte |
BOTH
Alignment. |
static byte |
BOTTOM
Alignment. |
static byte |
CENTER
Alignment. |
static byte |
CHAR
Alignment. |
static byte |
FILL
Alignment. |
byte |
floats
If floating object, side (LEFT or RIGHT) -- set with style sheet if possible. |
static byte |
INHERIT
Alignment. |
static byte |
JUSTIFY
Alignment. |
static byte |
LEFT
Alignment. |
protected static int |
MAXNONSTRUCTDEPTH
|
static byte |
MIDDLE
Alignment. |
protected java.lang.String |
name_
Name of node, like PARA or SECT for structural nodes, ASCII translation for leaves. |
static byte |
NONE
Alignment. |
protected java.util.List<Behavior> |
observers_
Behaviors that have registered interest in this node. |
protected INode |
parent_
Parent node in tree - access with getParentNode() . |
static int |
PROBEWIDTH
Some layouts ask contents how big they'd like to be, and some content will take all they can get, as when centering or HTML HR. |
static byte |
RIGHT
Alignment. |
protected Mark[] |
sticky_
List<> of marks on leaves, subtree summaries on internal nodes. |
protected short |
stickycnt_
|
static byte |
TOP
Alignment. |
protected boolean |
valid_
Layout dirty bit. |
byte |
valign
Vertical alignment -- set with style sheet if possible. |
Fields inherited from class multivalent.VObject |
---|
attr_ |
Constructor Summary | |
---|---|
Node(java.lang.String name,
java.util.Map<java.lang.String,java.lang.Object> attrs,
INode parent)
Create a node with the given name, attributes and parent, any of which can be null. |
Method Summary | |
---|---|
void |
addObserver(Behavior be)
Observers get called when node is encountered in tree walk protocols (format, paint, low-level event), protocolBefore and protocolAfter methods. |
void |
addSticky(Mark m)
|
void |
addSticky(Mark m,
boolean sequence)
|
boolean |
breakAfter()
|
boolean |
breakBefore()
|
boolean |
checkRep()
Checks "representation invariant" (see MIT SE), and returns true iff object is valid, which should be always |
int |
childNum()
|
void |
clipboardBeforeAfter(java.lang.StringBuffer txt)
Depth-first tree traversal to build selection. |
abstract void |
clipboardNode(java.lang.StringBuffer txt)
To build up selection, pass a StringBuffer to media-specific leaves, which fill it as appropriate for that medium. |
protected java.lang.Object |
clone()
Deep copy of Rectangle; observers and sticky set to null. |
static int |
cmp(Node ln,
int lo,
Node rn,
int ro,
INode top)
Does first (node,offset) come before (-1), at (0), or after (1) second (node,offset)? |
Node |
commonAncestor(Node b)
|
Node |
commonAncestor(Node b,
Node top)
|
boolean |
contains(Node n)
|
boolean |
contains(java.awt.Point p)
Nodes say whether it wants to see activity at point, regardless of bbox. |
void |
deleteObserver(Behavior be)
|
void |
dump()
|
void |
dump(int maxlevel)
|
void |
dump(int level,
int maxlevel)
Dump more verbose than toString(). |
abstract int |
dx()
X-coordinate transformation needed when entering this node's relative coordinate system. |
abstract int |
dy()
Y-coordinate transformation needed when entering this node's relative coordinate system. |
boolean |
eventBeforeAfter(java.awt.AWTEvent e,
java.awt.Point rel)
Pass tree event. |
abstract boolean |
eventNode(java.awt.AWTEvent e,
java.awt.Point rel)
Process java.awt.Event or multivalent.TreeEvent (not multivalent.SemanticEvent). |
Node |
findBFS(java.lang.String searchname)
Breath-first search for node with given name (generic identifier). |
Node |
findBFS(java.lang.String searchname,
java.lang.String attrname,
java.lang.String attrval)
|
Node |
findBFS(java.lang.String searchname,
java.lang.String attrname,
java.lang.String attrval,
int maxlevel)
Breadth-first search for node with given name (generic identifier), attribute name, and attribute value. |
Node |
findDFS(java.lang.String searchname)
Depth-first search for Node with given name. |
Node |
findDFS(java.lang.String searchname,
java.lang.String attrname,
java.lang.String attrval)
Depth-first search for Node with given name and (name, val) attribute pair. |
Node |
findDFS(java.lang.String searchname,
java.lang.String attrname,
java.lang.String attrval,
int maxlevel)
Depth-first search for node with requested combination of name, attribute name, and attribute value. |
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)
In the depth-first tree traversal to format tree, Before and after methods of behavior observers invoked here; actual formatting passed on to formatNode(). |
abstract boolean |
formatNode(int width,
int height,
Context cx)
Override this to specialize the natual layout of a node. |
java.awt.Point |
getAbsLocation()
Determine location of node in absolute coordinates, as opposed to parent-relative. |
java.util.List<ContextListener> |
getActivesAt(int offset)
|
java.util.List<ContextListener> |
getActivesAt(int offset,
boolean spansonly)
|
java.util.List<ContextListener> |
getActivesAt(int offset,
java.util.List<ContextListener> base,
boolean spansonly)
Collect active behaviors at point: spans, style sheet settings. |
java.awt.Rectangle |
getBbox()
Return node bounding box. |
Browser |
getBrowser()
Chains up parent links. |
Document |
getDocument()
Chains up parent links until find (lowest enclosing) Document. |
Node |
getElementById(java.lang.String elementId)
|
abstract Leaf |
getFirstLeaf()
|
IScrollPane |
getIScrollPane()
Chains up parent links. |
abstract Leaf |
getLastLeaf()
|
java.lang.String |
getName()
|
Leaf |
getNextLeaf()
Get the following leaf in a left-to-right traversal, returning null if none. |
Node |
getNextNode()
Get the node immediately following in a depth-first tree walk, returning null if none. |
java.lang.String |
getNodeName()
DOM2 nomenclature -- since method on a Node, why not "getName()"? |
java.util.List<Behavior> |
getObservers()
Needed by Document to do clipboardBeforeAfter on root before selection. |
INode |
getParentNode()
DOM2 nomenclature (why not "getParent()"?). |
Leaf |
getPrevLeaf()
Get the previous leaf in a left-to-right traversal, returning null if none. |
Node |
getPrevNode()
Get the node immediately previous in a depth-first tree walk, returning null if none. |
java.awt.Point |
getRelLocation(Node relto)
Determine location of node relative to passed node, as for instance location of image relative to its Document. |
Root |
getRoot()
Chains up parent links. |
Mark |
getSticky(int inx)
|
int |
indexSticky(Mark m)
|
boolean |
intersects(java.awt.Rectangle r)
Nodes say whether it wants to see activity in rectangular region, regardless of bbox. |
boolean |
isLeaf()
|
boolean |
isStruct()
|
boolean |
isValid()
|
void |
markDirty()
Mark dirty--setValid(false)--and chain of nodes up to lowest IScrollPane. |
void |
markDirtySubtree(boolean leavestoo)
Mark dirty all nodes in subtree and path to root (up and down tree). |
abstract void |
markDirtySubtreeDown(boolean leavestoo)
Mark dirty all nodes in subtree (down tree only). |
void |
markDirtyTo(Node rn)
Mark dirty all nodes in a span, parents included. |
void |
morphInto(Node l)
Transfers content into passed Node, destroying original and replacing it in tree. |
void |
paintBeforeAfter(java.awt.Rectangle docclip,
Context cx)
Depth-first tree traversal to paint tree. |
abstract void |
paintNode(java.awt.Rectangle docclip,
Context cx)
|
void |
reformat(Node bogus)
High performance reformatting of subtree. |
void |
remove()
Simple remove node from parent. |
void |
removeSticky(int inx)
|
void |
removeSticky(Mark m)
|
void |
removeTidy(INode root)
Remove node from tree tidily: don't leave behind empty INode, recursively up to root. |
void |
repaint()
|
void |
repaint(int x,
int y,
int w,
int h)
|
void |
repaint(long ms)
Repaint node itself -- not in content coordinates. |
void |
repaint(long ms,
int x,
int y,
int w,
int h)
Redraw portion of node within ms milliseconds. |
void |
scrollTo()
Scroll to show the node on the screen. |
void |
scrollTo(int dx,
int dy,
boolean pickplace)
Scroll to show the node on the screen. |
abstract void |
setName(java.lang.String name)
|
void |
setParentNode(INode p)
Used by IScrollPane to point scrollbars at it without it pointing at scrollbar. |
void |
setValid(boolean state)
Set dirty bit in this node only. |
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). |
int |
sizeSticky()
|
static Node[] |
spanChunky(Mark l,
Mark r)
|
static Node[] |
spanChunky(Node l,
Node r)
|
int |
structChildNum()
|
java.lang.String |
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 |
---|
public static final java.lang.String ATTR_SCRIPT
VScript
script.
VButton
,
Constant Field Valuespublic static final java.lang.String ATTR_ID
public static final byte ALIGN_INVALID
public static final byte NONE
public static final byte INHERIT
public static final byte LEFT
public static final byte RIGHT
public static final byte BOTH
public static final byte FILL
public static final byte JUSTIFY
public static final byte CENTER
public static final byte CHAR
public static final byte TOP
public static final byte BOTTOM
public static final byte MIDDLE
public static final byte BASELINE
public static final int PROBEWIDTH
protected static final int MAXNONSTRUCTDEPTH
protected java.lang.String name_
protected INode parent_
getParentNode()
.
public java.awt.Rectangle bbox
public int baseline
public byte align
public byte valign
public byte floats
protected java.util.List<Behavior> observers_
protected Mark[] sticky_
protected short stickycnt_
protected boolean valid_
Constructor Detail |
---|
public Node(java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> attrs, INode parent)
INode
Method Detail |
---|
protected java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public void morphInto(Node l)
public final java.lang.String getNodeName()
public final java.lang.String getName()
getName
in class VObject
public abstract void setName(java.lang.String name)
public java.awt.Rectangle getBbox()
public int size()
public boolean breakBefore()
public boolean breakAfter()
public boolean isLeaf()
public boolean isStruct()
public final INode getParentNode()
public void setParentNode(INode p)
public final java.util.List<Behavior> getObservers()
public final void addObserver(Behavior be)
Observable
public void deleteObserver(Behavior be)
public Browser getBrowser()
public Root getRoot()
public IScrollPane getIScrollPane()
public Document getDocument()
public abstract int dx()
public abstract int dy()
public boolean intersects(java.awt.Rectangle r)
public boolean contains(java.awt.Point p)
public boolean contains(Node n)
public Mark getSticky(int inx)
public int sizeSticky()
public int indexSticky(Mark m)
public void removeSticky(Mark m)
public void removeSticky(int inx)
public void addSticky(Mark m)
public void addSticky(Mark m, boolean sequence)
public void remove()
removeTidy(INode)
public void removeTidy(INode root)
remove()
public final int childNum()
public final int structChildNum()
public abstract Leaf getFirstLeaf()
public abstract Leaf getLastLeaf()
public Node getNextNode()
public Node getPrevNode()
public Leaf getNextLeaf()
public Leaf getPrevLeaf()
public Node commonAncestor(Node b)
public Node commonAncestor(Node b, Node top)
top
- - guaranteed common ancestor of ln and rn, e.g., some Document, or null if unknown.
public static int cmp(Node ln, int lo, Node rn, int ro, INode top)
top
- - guaranteed common ancestor of ln and rn, e.g., some Document, or null if unknown.public boolean formatBeforeAfter(int width, int height, Context cx)
width
- of screen, or fraction thereof available to be taken by nodeheight
- of screen, or fraction thereof available to be taken by node (largely ignored in HTML, which has infinitely long scroll, except in FRAME)Behavior
public abstract boolean formatNode(int width, int height, Context cx)
public void reformat(Node bogus)
However some applications, such as interactive editing and the display of status messages, need the best possible performance. If the range of changes can be bounded in some subtree, such that if the dimensions (width and height) of the subtree remain the same after reformatting, then reformatting can be speeded up. This rules out floats and HTML tables that compute cell widths based on the needs of their contents. (If the new dimensions are not the same, then fall back to the above guaranteed correct but possibly slower reformatting.)
Subclasses override this method for correctness for that node or for greater performance.
An HTML table may compute cell widths based on the relative needs of cell contents,
and so for correctness, in general, needs a complete reformat of the table.
IParaBox
can improve performance by skipping over
previous words in the paragraph, and stop reformatting if the change fits on the same line.
To use, first setValid(boolean)
with false
on node that contains all the changes,
then make changes in the subtree, and then invoke this method on that node.
smallerok
- set to true
if reformatting should be considered complete
if the dimensions of the new subtree are smaller, in addition to the case where they are exactly the same.public void paintBeforeAfter(java.awt.Rectangle docclip, Context cx)
Subclasses should check to see that node overlaps clip, and if so, update origin and clip, call super.paintBeforeAfter() (which will call paintNode()), then restore origin and clip. Determine if node within the current clipping region; if so, translate origin and clip, call observers (paintBeforeAfter), paint self (and children if any), restore origin and clip. Classes INode and Leaf do that, and almost nodes subclasses them, so subclasses can freely override paintNode (by INode's) and paintNodeContent (by Leaf's). Use Graphics.translate() and Graphics.setClipBounds() in place of any temptation to use Graphics.create() as sometimes new Graphics objects are substituted and Graphics.create() doesn't copy the tweaks.
LATER: parallel physical layout trees rather that on structure tree, for more flexible layout and multiple views. LATER: pass in List<> of flow regions (Dimension's), cut out what you need, protocol to ask for more (new column or page).
public abstract void paintNode(java.awt.Rectangle docclip, Context cx)
public final void clipboardBeforeAfter(java.lang.StringBuffer txt)
public abstract void clipboardNode(java.lang.StringBuffer txt)
public boolean eventBeforeAfter(java.awt.AWTEvent e, java.awt.Point rel)
public abstract boolean eventNode(java.awt.AWTEvent e, java.awt.Point rel)
TreeEvent
,
SemanticEvent
public final boolean isValid()
public final void setValid(boolean state)
markDirty()
public final void markDirty()
public void markDirtySubtree(boolean leavestoo)
public abstract void markDirtySubtreeDown(boolean leavestoo)
public void markDirtyTo(Node rn)
public void repaint(long ms, int x, int y, int w, int h)
public void repaint(int x, int y, int w, int h)
public void repaint()
public void repaint(long ms)
public java.awt.Point getAbsLocation()
public final java.awt.Point getRelLocation(Node relto)
public void scrollTo()
public void scrollTo(int dx, int dy, boolean pickplace)
for explanation of pickplace option.
public java.util.List<ContextListener> getActivesAt(int offset)
public java.util.List<ContextListener> getActivesAt(int offset, boolean spansonly)
public java.util.List<ContextListener> getActivesAt(int offset, java.util.List<ContextListener> base, boolean spansonly)
public Node findDFS(java.lang.String searchname, java.lang.String attrname, java.lang.String attrval, int maxlevel)
findBFS(String)
.
For example, this can be used to find node with given id attribute
with the following doc.findDFS(null, "id", desired-id-value, Integer.MAX_VALUE)
.
protected Node findDFS(java.lang.String searchname, java.lang.String attrname, java.lang.String attrval, int level, int maxlevel)
public final Node findDFS(java.lang.String searchname)
public final Node findDFS(java.lang.String searchname, java.lang.String attrname, java.lang.String attrval)
public Node findBFS(java.lang.String searchname, java.lang.String attrname, java.lang.String attrval, int maxlevel)
null
if don't care/match anything, e.g., set node name and attribute value to
null
if just want any node that has the given attribute.
Setting attribute name to null and attribute value to non-null has the same effect as setting both to null.
public final Node findBFS(java.lang.String searchname)
public final Node findBFS(java.lang.String searchname, java.lang.String attrname, java.lang.String attrval)
public static Node[] spanChunky(Mark l, Mark r)
public static Node[] spanChunky(Node l, Node r)
public Node getElementById(java.lang.String elementId)
public boolean checkRep()
VObject
checkRep
in class VObject
public void dump()
public void dump(int maxlevel)
public void dump(int level, int maxlevel)
public java.lang.String toString()
toString
in class java.lang.Object
|
Multivalent API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |