Initial commit
[pftoolbox.git] / GUI / sis_edit.m
blob97705138dd155d000888b3287bb5098123f76d18
1 function sis_edit(action, varargin)\r
2 % Sorry, I didn't have enough time to write nice and documented GUI code.\r
3 \r
4 % Toolbox for nonlinear filtering.\r
5 % Copyright (C) 2005  Jakob Rosén <jakob.rosen@gmail.com>\r
6 %\r
7 % This program is free software; you can redistribute it and/or\r
8 % modify it under the terms of the GNU General Public License\r
9 % as published by the Free Software Foundation; either version 2\r
10 % of the License, or (at your option) any later version.\r
11 %\r
12 % This program is distributed in the hope that it will be useful,\r
13 % but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 % GNU General Public License for more details.\r
16 %\r
17 % You should have received a copy of the GNU General Public License\r
18 % along with this program; if not, write to the Free Software\r
19 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
21 myfont='default';\r
22 %myfont='FixedWidth';\r
24 if strcmp(action,'init');\r
25         parentfig=varargin{1};\r
26         obj=varargin{2};\r
27         caller=varargin{3};\r
28         callback=varargin{4};\r
30         resample_functions={@rs_regularized, @rs_simple, @rs_stratified, @rs_systematic};\r
31         resample_names={'Residual resampling', 'Simple resampling', 'Stratified resampling', 'Systematic resampling'};\r
32         resample_str=cell2str(resample_names);\r
34         resampler_str=func2str(obj.resampler);\r
36         resample_value=2;\r
37         for i=1:length(resample_functions)\r
38                 if strcmp(resampler_str, func2str(resample_functions{i}))\r
39                         resample_value=i;\r
40                         break;\r
41                 end;\r
42         end;\r
44         N=obj.N;\r
45         Nth=obj.Nth;\r
47 %       hf=figure('Name','sis object editor','NumberTitle','off','Units','normalized','Position',[0.3 0.5 0.5 0.4]);\r
48         hf=figure('Name','sis object editor');\r
50 p=0.6;\r
52         uicontrol(hf,'Style','Text','String','Number of particles (N):','Units','normalized','Position',[0 p+0.15 0.4 0.05],'HorizontalAlign','Left','Fontname',myfont);\r
53         uicontrol(hf,'Style','Edit','String',num2str(N),'Units','normalized','Position',[0.45 p+0.15 0.18 0.05],'Callback',['sis_edit(''N_edit'',',num2str(hf),')'],'Tag','N_edit','Fontname',myfont);\r
55         uicontrol(hf,'Style','Text','String','Resampling function:','Units','normalized','Position',[0.0 p+0.07 0.4 0.05],'HorizontalAlign','Left','Fontname',myfont);\r
56         uicontrol(hf,'Style','Popup','String',resample_str,'Value',resample_value,'Units','normalized','Position',[0.45 p+0.07 0.4 0.05],'Tag','resampler_select','Fontname',myfont);\r
58 %       uicontrol(hf,'Style','Frame','Units','Characters','Position',[55 0 0.1 5]);\r
60         uicontrol('Style','Pushbutton','String','Save','Units','normalized','Position',[0.65,p+0.15,0.1,0.05],'Callback',['sis_edit(''save'',',num2str(hf),')'],'Fontname',myfont);\r
61         uicontrol('Style','Pushbutton','String','Cancel','Units','normalized','Position',[0.75,p+0.15,0.1,0.05],'Callback',['delete(',num2str(hf),')'],'Fontname',myfont);\r
63         uicontrol(hf,'Style','Text','String','Resampling threshold (Nth):','Units','normalized','Position',[0 p+(-0.01) 0.4 0.05],'HorizontalAlign','Left','Fontname',myfont);\r
64         uicontrol(hf,'Style','Edit','String',num2str(Nth),'Units','normalized','Position',[0.45 p+(-0.01) 0.18 0.05],'Callback',['sis_edit(''Nth_edit'',',num2str(hf),')'],'Tag','Nth_edit','Fontname',myfont);\r
65         uicontrol(hf,'Style','Text','String','0 <= Nth <= N','Units','normalized','Position',[0.65 p+(-0.01) 0.2 0.05],'HorizontalAlign','center','Fontname',myfont);\r
68         handles=guihandles(hf);\r
69         handles.obj=obj;\r
70         handles.caller=caller;\r
71         handles.callback=callback;\r
72         handles.parentfig=parentfig;\r
73         handles.N=N;\r
74         handles.Nth=Nth;\r
75         handles.resample_functions=resample_functions;\r
76         guidata(hf,handles);\r
78 elseif strcmp(action,'save');\r
80         hf=varargin{1};\r
81         handles=guidata(hf);\r
83         caller=handles.caller;\r
84         obj=handles.obj;\r
86         resampler_index=get(handles.resampler_select,'value');\r
88         set(obj,'N',handles.N);\r
89         set(obj,'resampler',handles.resample_functions{resampler_index});\r
90         set(obj,'Nth',handles.Nth);\r
92         parentfig=handles.parentfig;\r
93         parenthandles=guidata(parentfig);\r
95         parenthandles.(caller)=obj;\r
96         guidata(parentfig,parenthandles);       % Save data\r
97         \r
98         eval(handles.callback);\r
99         close(hf)\r
101 elseif strcmp(action,'N_edit');\r
102         hf=varargin{1};\r
103         handles=guidata(hf);\r
105         N_str=get(handles.N_edit,'String');\r
106         if isempty(N_str)\r
107                 msgbox('Please enter a value');\r
108         end;\r
109         N=str2num(N_str);\r
110         if N<1\r
111                 msgbox('Please enter a POSITIVE value');\r
112                 return\r
113         elseif round(N)~=N\r
114                 msgbox('Please enter a positive INTEGER');\r
115                 return\r
116         end     \r
118         if N<handles.Nth\r
119                 handles.Nth=N;\r
120                 set(handles.Nth_edit,'String',num2str(N));\r
121         end\r
123         handles.N=N;\r
124         guidata(hf,handles);\r
126 elseif strcmp(action,'Nth_edit');\r
127         hf=varargin{1};\r
128         handles=guidata(hf);\r
130         Nth_str=get(handles.Nth_edit,'String');\r
131         if isempty(Nth_str)\r
132                 msgbox('Please enter a value');\r
133         end;\r
134         Nth=str2num(Nth_str);\r
135         if Nth<0\r
136                 msgbox('Please enter a POSITIVE value');\r
137                 return\r
138         elseif Nth>handles.N\r
139                 msgbox('Nth must not be greater than N!');\r
140                 return\r
141         end     \r
142         handles.Nth=Nth;\r
143         set(handles.Nth_edit,'String',num2str(Nth));    % Format!\r
144         guidata(hf,handles);\r
145 end\r