function V = tstool(varargin)
% TSTOOL Method to open the time series editor
% 
% V = TSTOOL returns the handles to the tsviewer

% Author(s):  
% Revised: 
% Copyright 1986-2004 The MathWorks, Inc.
% $Revision: 1.1.6.1 $ $Date: 2004/12/26 21:46:32 $

%% Explorer GUI and UDD root node handles
%mlock
persistent TSVIEWER;

%% Get the time series feature. For integration purposes protect against
%% the feature being unresistered.
try
    thisfeatureon = feature('TimeSeriesTools');
catch
    thisfeatureon = true;
end
if ~thisfeatureon
    error('This feature has not been enabled')
end

% Check for valid platform for Java Swing
if ~usejava('Swing')
  error('The Time Series tool requires Java Swing to run.');
end

% Check for a valid viewer
if isempty(TSVIEWER) || ~ishandle(TSVIEWER) || ...
        isempty(TSVIEWER.TreeManager) || ~ishandle(TSVIEWER.TreeManager) || ...
        isempty(TSVIEWER.TreeManager.Figure) || ~ishandle(TSVIEWER.TreeManager.Figure)
        % Create the viewer
        TSVIEWER = tsguis.tsviewer;
        TSVIEWER.open;
else
    set(TSVIEWER.TreeManager,'visible','on')
end

    
%% Add the new time series
if nargin>0
    TSVIEWER.Tsnode.createChild(varargin{1});
end
    
% Lang workaround for returned persistent variables
V = TSVIEWER;

