A node represents a node in a tree
object. A node is a kind of
wrapper around an arbitrary graphical representing the
image of the node.
A node maintains it's relations to the tree, it's parent node(s)
and it's child nodes.
Class node defines
the methods to make a tree editable. See node->delete,
node->son, node->delete_tree,
etc. The HierarchyEditor demo may be used as a starting point for
manipulating hierarchies.
->collapsed
and tree->zoom
make it possible to visualise only a small part of a large tree. A tree
might contain multiple collapsed nodes.
If the tree is displayed using tree->direction,
an image is displayed at the left-hand of the line connecting the node
to its parent. This image depends on the value of
node<-collapsed:
.Tree.collapsedImage). If
the user lef-clicks on this sign, a message node->collapsed: @off
is sent to the node.
.Tree.expandedImage). If
the user lef-clicks on this sign, a message node->collapsed: @on
is sent to the node.
See library(pce_toc) for an example and a starting point
the visualisation of a hierarchy. See also tree->direction.
tree <-display_root' or below a node that has node node<-collapsed: @on‘.
<-node
and graphical<-contained_in.
<-display_root
node. The node tree<-display_root
has level 0. This variable is updated by
tree->compute,
which scans the tree depth-first.<-direction
equals vertical) or the graphical image represented. Part of the layout
system.
<-root
node this is the empty chain. Nodes may have multiple parents, but many
methods of the classes tree and node are ill-defined for this case.->move_after.
The root of the tree may be deleted with this method. If this node
has no sons, tree<-root
will be set to @nil.
Otherwise the first son of this node will be made the new root of the
tree.
When the tree<-display_root
is deleted, it is set to the first parent of this node.
Bugs: Deleting the root of a tree that has multiple sons is not well defined.
->unlink
->event
is a little different from the other refinements of graphical->event
as class node is not a
subclass of graphical. It is invoked from tree->event
and allows for adding behaviour to nodes regardless of the underlying
graphicals.
The default method uses central handler
objects from the associated node<-tree:
a) If it is collapsed, run <-collapsed_handlers b) If it is a leaf, run <-leaf_handlers c) If it is the display_root, run <-root_handlers d) else, run <-node_handlers
In each of the cases a) to d), run means invoke the
following message for each of the members of the handler-chain:
`event ->post: graphical, recogniser`
If you wish to refine this method, please be aware that the normal
schema described with graphical->event
does not work for nodes. Here is a skeleton implementation:
:- pce_global(@my_node_recogniser,
make_my_node_recogniser).
make_my_node_recogniser(G) :-
...
event(Node, Ev:event) :->
( send_super(Node, event, Ev)
-> true
; send(Ev, post, Node?image,
@my_node_recogniser)
).
<-sons
of this node and finally runs code on the receiving node.
Note that multiple-inheritance will cause some nodes to be visited more than once. Argument binding:
@arg1: Node object.
See also node<-find.
NOTE: Upto version 5.0.9, the execution
order was different: code was first executed on the node and then on the node<-sons.
The current order allows for deleting nodes.
Diagnostics: Terminates immediately with failure if code could not be executed fro some node
Bugs:
node->for_all
is not safe when the executed code manipulates the subtree below this
node.
->for_all,
but ignores the exit-status of the executed code. Succeeds always.
?- new(T, tree(new(Root, node(text(anything))))), send(Root, son, new(S0, node(text(living_thing)))), ...
Succeeds without doing anything if the argument is already a son. Fails silently if one of the following is the case:
->son
Bugs: Not well defined when the receiver node has multiple parents.
<-sons
chain. Otherwise it is added just in front of the before argument.
Diagnostics: # <Node> already in a tree Argument node is member of another tree.
<-nodes, just like chain->sort,
and update the hierarchy layout afterwards.Bugs: This method manipulates the images rather than the nodes as done by most of the other methods manipulating the layout of the hierarchy.
<-sons
chain.
<-parents
chain between both nodes
->swap
->delete:
removes node from the tree binding all sons to all parents of this node.
To remove an entire subtree, see node->delete_tree.
Diagnostics: Fails if node is not a direct parent or son of the argument.
->unzoom,
unzooming the tree to its root.
->zoom,
giving this node as the argument. This will make node the root of the
visible part of the hierarchy.
<-tree. Fails if the node is
not attached to a tee object. See visual<-contained_in
for a general description of this method.
<-contains
@see node<-contained_in?- new(@t, tree(text(animal))), ?- get(@t, root, Root) Root = @345263 ?- get(@345263, class_name, Class) Class = node.
->for_all.
Diagnostics: Fails if code fails for all nodes.
<-image
equal to the specified graphical.