summaryrefslogtreecommitdiffstats
path: root/kjsembed/docs/examples/treeview/showtree.js
blob: ea6b62d9b004a0f3ba44d3b621e8d497a76b8a9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env kjscmd

function buildViewNode( node, parent )
{
    var l = new TQLabel( parent, 'node' );
    l.text = '<center><table cellspacing=0>'
	+ '<tr><th bgcolor="#aaaaee"><b>' + node.text + '</b></th></tr>'
	+ '<tr><td bgcolor="#ccccee">' + node.text + '</td></tr>'
	+ '<tr><td bgcolor="#ccccee">' + node.text + '</td></tr>'
	+ '</table></center>';
    
    return l;
}

function buildView( node, parent )
{
    // No children
    if ( node.children.length == 0 ) {
	return buildViewNode( node, parent );
    }

    // Create container node
    var vbox = new TQVBox( parent, 'subtree' );
    vbox.margin = 8;
    vbox.spacing = 6;

    var vnode = buildViewNode( node, vbox );

    // Create children
    var hbox = new TQHBox( vbox, 'child_nodes' );
    hbox.spacing = 6;

    for ( var i = 0 ; i < node.children.length ; i++ ) {
	buildView( node.children[i], hbox );
    }

    return vbox;
}

function buildNode( ttl )
{
    var node = new Object();
    node.text = ttl;
    node.children = [];
    return node;
}

// Create Tree Model
var root = buildNode( 'Root' );

root.children = [ buildNode('One'), buildNode('Two'), buildNode('Three') ];
root.children[0].children = [ buildNode('One'), buildNode('Two') ];
root.children[0].children = [ buildNode('One'), buildNode('Two') ];
root.children[1].children = [ buildNode('One'), buildNode('Two') ];
root.children[1].children = [ buildNode('One'), buildNode('Two'), buildNode('Three') ];
root.children[2].children = [ buildNode('One') ];
root.children[2].children = [ buildNode('One'), buildNode('Two'), buildNode('Three') ];

// Create View
var box = new TQVBox( 'tree_view' );
box.margin = 6;

var view = buildView( root, box );
var spacer = new TQLabel( box );

box.show();