function h = statsdlg(varargin)

%% Show the (singleton) shift dialog

persistent dlg;
 
%% If necessary build the stats dialog. If the tsviewer has been reopened,
%% then the SrcNode will have changed, and the statsdlg must be rebuilt so
%% the listener to the TreeManager visibility will remain valid for the new
%% TreeManager.
if isempty(dlg) || ~ishandle(dlg) || dlg.SrcNode~=varargin{1}
    dlg = tsguis.statsdlg;
    if nargin>=2
        % The viewnode must be set for the viewnode grandparent to be set
        dlg.SrcNode = varargin{1};
        dlg.initialize(varargin{2});
        dlg.Visible = 'on';
        centerfig(dlg.Figure,0);
    end
end

%% Return the handle
h = dlg;