1.106 class node

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.

See also
- graphical<-node
- class tree

1.106.1 Instance variables

node <- collapsed: bool*
When @on, the image related to this node is displayed, but all subnodes will be made invisible. node->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:

@(on)
Show a [+] sign (pce.Tree.collapsedImage). If the user lef-clicks on this sign, a message node->collapsed: @off is sent to the node.
@(off)
Show a [-] sign (pce.Tree.expandedImage). If the user lef-clicks on this sign, a message node->collapsed: @on is sent to the node.
@(nil)
Shows nothing, no events are handled for collapse/expand.

See library(pce_toc) for an example and a starting point the visualisation of a hierarchy. See also tree->direction.

See also
- tree->zoom
- node-displayed
- tree->collapsed_handler
node <- displayed: [bool]
When @off, the node is invisible either because it is above tree <-display_root' or below a node that has node node<-collapsed: @on‘.
See also
- tree->zoom
- node-collapsed
node <- image: graphical
Graphical object that represents the node. This may be any graphical object. Note that class graphical defines some methods that take care of the fact that they are part of a tree. See graphical<-node and graphical<-contained_in.
See also
- graphical<-convert
- graphical<-node
node <- level: int
Integer representing the distance from the tree<-display_root node. The node tree<-display_root has level 0. This variable is updated by tree->compute, which scans the tree depth-first.
node-my_size: int
Height (or width if tree<-direction equals vertical) or the graphical image represented. Part of the layout system.
See also
node-sons_size
node <- parents: chain
Chain of parent nodes of this node. For the tree<-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.
node <- sons: chain
Chain holding all immediate sub-nodes. The nodes are displayed left-to-right or top-to-bottom in the order they appear in this chain. This order may be changed using node->move_after.
See also
node->son
node-sons_size: int
Combined height (width) of the entire subtree starting at this node. Part of the automatic layout mechanism.
See also
node-my_size

1.106.2 Send methods

node ->delete:
Deletes node from the tree. Each of the sons of this node will be connected to each of the parents of this node.

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.

See also
- node->unlink
- node->delete_tree
node ->delete_tree:
Deletes the entire subtree starting at this node. Node that if any subnode of this node is still connected to the root through another chain of parents it will not be deleted from the tree. See also node->unlink
See also
node->delete
node ->event: event
node->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)
        ).
node ->for_all: code
Invokes itself recursively on all node<-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.

See also
- node<-find
- node->for_some
- tree->for_all
node ->for_some: code
Equivalent to node->for_all, but ignores the exit-status of the executed code. Succeeds always.
See also
node->for_all
node ->initialise: image=graphical
Create a node from an arbitrary graphical object. Nodes may be created from any graphical object, including devices, dialog_items and even trees. A typical way to build a tree is the following:
?- new(T, tree(new(Root, node(text(anything))))),
   send(Root, son, new(S0, node(text(living_thing)))),
   ...
See also
node<-convert
node ->is_parent: node
Succeeds if the argument is an (indirect) parent of this node. Fails silently otherwise.
See also
node->is_son
node ->is_son: node
Succeeds if argument node is an (indirect) son of this node. Fails silently otherwise.
See also
node->is_parent
node ->move: node
Make the argument node a direct son of this node.

Succeeds without doing anything if the argument is already a son. Fails silently if one of the following is the case:

  1. The argument node is in another tree
  2. This node is not part of a tree
  3. The argument node is this node
  4. The argument node is a parent of this node @see node->son
node ->move_after: [node]*
If node and the argument are immediate sons of the same parent, the receiver is placed immediately after the argument node. If the argument is @default, the receiver is placed at the end chain of sons (making it the lowest or rightmost node). If the argument is @nil, the receiver is places at the start of the chain of sons.

Bugs: Not well defined when the receiver node has multiple parents.

See also
chain->move_after
node ->son: son=node, before=[node]*
Makes the argument node a son of this node. This is the most common way to build a hierarchy. If before is @nil or @default, the child is added at the end of the node<-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.

node ->sort_sons: code
Sort the chain of node<-nodes, just like chain->sort, and update the hierarchy layout afterwards.
node ->swap: node
Swap the images of the specified nodes.

Bugs: This method manipulates the images rather than the nodes as done by most of the other methods manipulating the layout of the hierarchy.

See also
node->swap_tree
node ->swap_tree: node
Swap the subtrees formed by both nodes. It performs the following steps:

  1. Identify common parents and swap the positions in the parent node<-sons chain.
  2. Swaps the node<-parents chain between both nodes
  3. Destroy and recreate the necessary connections. Diagnostics: Fails silently if:
  4. The nodes are not in the same tree or not in a tree at all
  5. One node is a parent of the other @see node->swap
node ->unlink:
Equivalent to node->delete: removes node from the tree binding all sons to all parents of this node. To remove an entire subtree, see node->delete_tree.
See also
node->delete
node ->unrelate: node
Delete the direct relation between this node and the argument. Removes all nodes that have no relation to the root of the tree anymore.

Diagnostics: Fails if node is not a direct parent or son of the argument.

node ->unzoom:
Invokes tree->unzoom, unzooming the tree to its root.
See also
- node->zoom
- tree->unzoom
node ->zoom:
Invokes tree->zoom, giving this node as the argument. This will make node the root of the visible part of the hierarchy.
See also
- node->unzoom
- tree->zoom

1.106.3 Get methods

node <-contained_in: -> tree
Return node<-tree. Fails if the node is not attached to a tee object. See visual<-contained_in for a general description of this method.
See also
- tree<-contains
- node<-contains
node <-contains: -> chain
@see tree<-contains @see node<-contained_in
node <-convert: graphical -> node
Create node for graphical object. This method may be used to expand the tree by adding graphical objects rather than nodes. Note however that the actually stored object will be the node:
?- new(@t, tree(text(animal))),
?- get(@t, root, Root)

Root = @345263
?- get(@345263, class_name, Class)

Class = node.
See also
node->initialise
node <-find: code -> node
Traverses the tree in a depth-first fashion until code can be executed successfully on a node and then returns this node. See also node->for_all.

Diagnostics: Fails if code fails for all nodes.

See also
- node<-find_node
- node->for_all
node <-find_node: graphical -> node
Find node (either myself or a node in the subtree of which this node is the root) that has node<-image equal to the specified graphical.
See also
- graphical<-node
- node<-find