function gui_time(varargin)
global zeng
action=varargin{1};
switch action
case 'initial'
Parent_Size=get(varargin{2},'position');
FG_Size=[Parent_Size(1) Parent_Size(2)-116-25 220 116];
ScreenSize=get(0,'ScreenSize');
if FG_Size(2)<200;
FG_Size(2)=Parent_Size(2)+Parent_Size(4)+45;
end
temp=findobj('type','figure','tag','gui_time');
if ~isempty(temp)
set(temp,'position',FG_Size);
figure(temp)
else
settime.parent=varargin{2};
settime.figure = figure('Color',[0.8 0.8 0.8], ...
'DeleteFcn','delete(gcbf);',...
'Position',FG_Size, ...
'menu','none',...
'Name','Setting : Time',...
'NumberTitle','off',...
'Resize','off',...
'tag','gui_time',...
'ToolBar','none');
set(settime.figure,'position',FG_Size) %stupid, but I need it for WinXp
if zeng.dtmode==1 %fix
dt_enable='on';
else %2 = variable
dt_enable='off';
end
settime.pop.dt = uicontrol('Parent',settime.figure, ...
'Units','pixel', ...
'callback','gui_time(''set dt'');',...
'BackgroundColor',[1 1 1], ...
'HorizontalAlignment','right',...
'ListboxTop',0, ...
'Position',[10 49 125 24], ...
'String',{'Fixed step (1-20us)','Variable step (Coarse)','Variable step (Fine)'}, ...
'Style','popupmenu',...
'value',zeng.dtmode);
settime.edit.dt = uicontrol('Parent',settime.figure, ...
'Units','pixel', ...
'BackgroundColor',[1 1 1], ...
'ListboxTop',0, ...
'Position',[145 49 55 22], ...
'String',num2str(zeng.dt), ...
'Style','edit', ...
'enable',dt_enable,...
'Tag','Edittext1');
settime.text.tf = uicontrol('Parent',settime.figure, ...
'Units','pixel', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'HorizontalAlignment','right', ...
'ListboxTop',0, ...
'Position',[10 79 125 22], ...
'String','Time(ms)', ...
'Style','text', ...
'Tag','Statictext1');
settime.edit.tf = uicontrol('Parent',settime.figure, ...
'Units','pixel', ...
'BackgroundColor',[1 1 1], ...
'ListboxTop',0, ...
'Position',[145 79 55 22], ...
'String',zeng.tf, ...
'Style','edit', ...
'Tag','Edittext1');
settime.button.okay = uicontrol('Parent',settime.figure, ...
'Units','pixel', ...
'BackgroundColor',[0.847058823529412 0.8 0.7215686274509801], ...
'ListboxTop',0, ...
'Position',[25 11 50 22], ...
'String','Ok', ...
'callback','gui_time(''okay'')',...
'Tag','Pushbutton');
settime.button.cancel = uicontrol('Parent',settime.figure, ...
'Units','pixel', ...
'BackgroundColor',[0.847058823529412 0.8 0.7215686274509801], ...
'ListboxTop',0, ...
'Position',[85 11 50 22], ...
'String','Close', ...
'callback','delete(gcbf)',...
'Tag','Pushbutton');
settime.button.apply = uicontrol('Parent',settime.figure, ...
'Units','pixel', ...
'BackgroundColor',[0.847058823529412 0.8 0.7215686274509801], ...
'ListboxTop',0, ...
'Position',[145 11 50 22], ...
'String','Apply', ...
'callback','gui_time(''okay'',''apply'')',...
'Tag','Pushbutton');
set(settime.figure,'userdata',settime);
end %if ~isempty(temp)
case 'set dt'
settime=get(gcbf,'userdata');
setdt=get(gcbo,'value');
if setdt==1 %fix
set(settime.edit.dt,'enable','on')
else %2=variable
set(settime.edit.dt,'enable','off')
end
case 'okay'
settime=get(gcbf,'userdata');
dtval=get(settime.pop.dt,'value');
tf=str2num(get(settime.edit.tf,'string')); %we need to convert from us to ms
if isempty(tf)| tf<=0 | ~isreal(tf)
zexst('err','I prefer a positive number for time length, You know?');
%set(exst.edit.Dia,'string',num2str(exst.default.tf));
set(gcbo,'enable','on')
return
end
dt=str2num(get(settime.edit.dt,'string')); %we need to convert from us to ms
if dtval==1
if isempty(dt)| dt<(zeng.dtmin*1000) | dt>(zeng.dtmax*1000) | ~isreal(dt)
zexst('err',['"dt" needs to be in between ' num2str(zeng.dtmin*1000) '-' num2str(zeng.dtmax*1000) 'us !!!, You know?']);
set(gcbo,'enable','on')
return
end
end
zeng.dt=dt;
zeng.tf=tf;
zeng.dtmode=dtval;
if nargin==1
%from "okay"
%close(gcbf)
else
%from "apply"
zexst('calculate')
end
end %switch