www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@xregGui/@tree/addNode.m
function p= addNode(h,p_rel,relation,tag,lyt,varargin) %ADDNODE Add a node to the tree % % new_p=h.addnode(p_rel,relationship,tag,layout) % % p_rel is the relative node. relationship defines where % the new node is in relation to the relative. These % constants are defined by the tree: % % h.relFirst - The new node is a sibling of the relation % and is placed as first in the sibling list. % h.relLast - The new node is a sibling of the relation % and is placed last in the sibling list. % h.relNext - The new node is placed after the relation. % h.relPrevious - The new node is placed before the relation. % h.relChild - The new node is a child of the relation. % % tag is an optional argument that defines the tag of the new % node object. % layout is an optional argument that specifies the layout % object of the new node. % % if p_rel is omitted/empty then the new node is added as a root % of the tree. % % Copyright 2000-2004 The MathWorks, Inc. and Ford Global Technologies, Inc. p=xregGui.treenode('tree',h); if nargin>3 p.tag=tag; end if nargin>4 p.Layout=lyt; end h.NodeDelL= [h.NodeDelL; handle.listener(p,'ObjectBeingDestroyed',@i_nodedel)]; h.NodeLytL= [h.NodeLytL; handle.listener(p,p.findprop('Layout'),'PropertyPostSet',{@i_redraw,h})]; h.NodeExpandL= [h.NodeExpandL; handle.listener(p,p.findprop('IsExpanded'),'PropertyPostSet',{@i_redraw,h})]; if nargin<3 relation=h.relChild; end if nargin<2 | isempty(p_rel) p.connect(h.VirtualRoot,'up'); if h.MaxLvls<1 h.MaxLvls=1; end else switch relation case h.relFirst case h.relLast case h.relNext case h.relPrevious case h.relChild p.connect(p_rel,'up'); lvl=i_getlevel(p); if h.MaxLvls<lvl h.MaxLvls=lvl; end end end h.Nodes=[h.Nodes; p]; h.redraw; function n=i_getlevel(h) n=0; h=h.up; while ~isempty(h); n=n+1; h=h.up; end return function i_nodedel(srcobj,evt) h=srcobj.Tree; h.removeNode(srcobj); return function i_redraw(srcobj,evt,h) h.redraw; return