function varargout = ltpdalauncher(varargin)

% LTPDALAUNCHER presents the user with a control panel from which they can
% launch other LTPDA GUIs.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DESCRIPTION: LTPDALAUNCHER presents the user with a control panel from
%              which they can launch other LTPDA GUIs.
%
% CALL:        ltpdalauncher
%
%
%
% VERSION:     $Id: ltpdalauncher.m,v 1.13 2009/09/28 08:12:05 hewitson Exp $
%
% HISTORY: 07-03-08 M Hewitson
%             Creation
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%% Check if I exist already
hs = findall(0);
found = -1;
for j=1:length(hs)
  h = hs(j);
  if strcmp(get(h, 'Tag'), 'LTPDAlauncher')
    found = h;
  end
end
if found ~= -1
  figure(found);
  return
end

% id = findobj('Tag', 'LTPDAlauncher');
% if ~isempty(id)
%   figure(id)
%   return
% end

%% Some initial setup

Gproperties.Gcol    = [240 240 240]/255;
Gproperties.Gwidth  = 400;
Gproperties.Gheight = 400;
Gproperties.Gborder = 10;
fontsize = getappdata(0, 'ltpda_repo_gui_fontsize');

Gproperties.Screen   = get(0,'screensize');
Gproperties.Gposition = [150 ...
  150 ...
  Gproperties.Gwidth...
  Gproperties.Gheight];

%  Initialize and hide the GUI as it is being constructed.
mainfig = figure('Name', 'LTPDA Launch Bay',...
  'NumberTitle', 'off',...
  'Visible','off',...
  'Position',Gproperties.Gposition,...
  'Color', Gproperties.Gcol,...
  'Toolbar', 'none',...
  'Resize', 'off',...
  'ToolBar',      'none',           ...
  'NextPlot',     'new',            ...
  'HandleVisibility', 'callback', ...
  'MenuBar', 'none',...
  'Tag', 'LTPDAlauncher');

% Set mainfig callbacks
set(mainfig, 'CloseRequestFcn', {'ltpda_launcher_close', mainfig});

% Set Application data
setappdata(mainfig, 'Gproperties', Gproperties);

%% Add  Logo
M = 0.01;
ax   = axes('Position', [M M 1-2*M 1-2*M], 'Parent', mainfig);
logo = imread('images/ltpda_blue.jpg');
image(logo, 'Parent', ax) 
set(ax,'Visible', 'on', 'Box', 'off', 'Xtick', [], 'Ytick', []);
axis(ax, 'off');

%% Add launch buttons

BtnHeight = 20;
BtnWidth  = Gproperties.Gwidth - 20;
BtnLeft   = 10;
BtnBottom = Gproperties.Gheight - BtnHeight - 10;

%-- LTPDA GUI
BtnBottom = BtnBottom - BtnHeight - 10;
pbh = uicontrol(mainfig,'Style','pushbutton','String','LTPDA Workbench',...
  'Position',[BtnLeft BtnBottom BtnWidth BtnHeight ],...
  'Tag', 'LTPDAworkbench'); 
set(pbh, 'Callback', {'ltpda_launcher_workbench'});

%-- preferences
pos       = get(pbh, 'Position');
BtnBottom = pos(2) - BtnHeight - 10;
pbh = uicontrol(mainfig,'Style','pushbutton','String','LTPDA Preferences',...
  'Position',[BtnLeft BtnBottom BtnWidth BtnHeight ],...
  'Tag', 'LTPDA_preferences');
set(pbh, 'Callback', 'LTPDAprefs');


%-- workspace browser
pos       = get(pbh, 'Position');
BtnBottom = pos(2) - BtnHeight - 10;
pbh = uicontrol(mainfig,'Style','pushbutton','String','Workspace Browser',...
  'Position',[BtnLeft BtnBottom BtnWidth BtnHeight ],...
  'Tag', 'workspaceBrowser');
set(pbh, 'Callback', {@start_workspaceBrowser});

%-- LTPDA Repogui
% pos       = get(pbh, 'Position');
% BtnBottom = pos(2) - BtnHeight - 10;
% pbh = uicontrol(mainfig,'Style','pushbutton','String','LTPDA REPO GUI',...
%   'Position',[BtnLeft BtnBottom BtnWidth BtnHeight ],...
%   'Tag', 'ltpda_launcher_repogui');
% set(pbh, 'Callback', {'ltpda_launcher_launch_repogui'});

%-- PZmodel helper
pos       = get(pbh, 'Position');
BtnBottom = pos(2) - BtnHeight - 10;
pbh = uicontrol(mainfig,'Style','pushbutton','String','Pole/Zero Model Helper',...
  'Position',[BtnLeft BtnBottom BtnWidth BtnHeight ],...
  'Tag', 'ltpda_launcher_pzmodel');
set(pbh, 'Callback', {'ltpda_launcher_launch_pzmodel'});

%-- specwin helper
pos       = get(pbh, 'Position');
BtnBottom = pos(2) - BtnHeight - 10;
pbh = uicontrol(mainfig,'Style','pushbutton','String','Spectral Windows GUI',...
  'Position',[BtnLeft BtnBottom BtnWidth BtnHeight ],...
  'Tag', 'ltpda_launcher_specwin');
set(pbh, 'Callback', {'ltpda_launcher_specwinViewer'});

%-- constructor helper
pos       = get(pbh, 'Position');
BtnBottom = pos(2) - BtnHeight - 10;
pbh = uicontrol(mainfig,'Style','pushbutton','String','Constructor Helper',...
  'Position',[BtnLeft BtnBottom BtnWidth BtnHeight ],...
  'Tag', 'ltpda_constructor_helper');
set(pbh, 'Callback', {'ltpda_launcher_constructor'});

%-- object explorer
pos       = get(pbh, 'Position');
BtnBottom = pos(2) - BtnHeight - 10;
pbh = uicontrol(mainfig,'Style','pushbutton','String','Object Explorer',...
  'Position',[BtnLeft BtnBottom BtnWidth BtnHeight ],...
  'Tag', 'ltpda_object_explorer');
set(pbh, 'Callback', {@call_explore_ao});

% %-- quicklook
% pos       = get(pbh, 'Position');
% BtnBottom = pos(2) - BtnHeight - 10;
% pbh = uicontrol(mainfig,'Style','pushbutton','String','Quicklook',...
%   'Position',[BtnLeft BtnBottom BtnWidth BtnHeight ],...
%   'Tag', 'ltpdaquicklook');
% set(pbh, 'Callback', {'ltpdaquicklook'});



%-- signal builder
pos       = get(pbh, 'Position');
BtnBottom = pos(2) - BtnHeight - 10;
pbh = uicontrol(mainfig,'Style','pushbutton','String','Signal Builder',...
  'Position',[BtnLeft BtnBottom BtnWidth BtnHeight ],...
  'Tag', 'SigBuilder');
set(pbh, 'Callback', 'sigBuilder');

%-- version string
v  = ver('LTPDA');

sth = uicontrol(mainfig,'Style','text',...
  'String',sprintf('%s %s', v.Name, v.Version),...
  'HorizontalAlignment', 'left', ...
  'BackgroundColor', [130 190 250]/255, ...
  'ForegroundColor', 'w', ...
  'Position',[10 10 120 25]);




%% Start the GUI

% Make the GUI visible.
set(mainfig,'Visible','on')
 

  function start_workspaceBrowser(varargin)
    workspaceBrowser;
  end

  function call_explore_ao(varargin)
    
    ltpda_explorer;
    
  end

end
