001 function choices(name,header,labels,callbacks,inter)
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028 global CHOICELIST
029 global CHOICEHANDLES
030 c = computer;
031 if ~isstr(name) | ~isstr(header) | ~isstr(labels) | ~isstr(callbacks)
032 error('Requires string arguments.');
033 end
034 if nargin < 4
035 error('Not enough input arguments.')
036 end
037 if nargin == 4
038 inter = 0;
039 end
040 if inter
041 yn = 'on';
042 else
043 yn = 'off';
044 end
045 uicok = strcmp(c(1:2),'PC') | strcmp(c(1:2),'MA');
046 if isunix | ~uicok
047 uicok = strcmp(lower(get(0,'TerminalProtocol')),'x');
048 end
049
050 if ~uicok
051 labels = str2mat(labels,'Done');
052 nl = size(labels,1);
053
054
055 ss = deblank(labels(1,:));
056 ss = ss(sort([1:length(ss) find(ss=='''')]));
057 args = ['''',ss,''''];
058 header = header(sort([1:length(header) find(header=='''')]));
059 for i = 2:nl
060 ss = deblank(labels(i,:));
061 ss = ss(sort([1:length(ss) find(ss=='''')]));
062 args = [args, ',''', ss,''''];
063 end
064 k = 1;
065 while k > 0 & k < nl
066 k = eval(['menu(''',header,''',', args,');']);
067 if k == nl | k == 0
068 return
069 else
070 ceval(callbacks(k,:));
071 end
072 end
073 return
074 end
075
076 name = deblank(name);
077 if isempty(name)
078 error('Requires non-blank string argument.')
079 end
080
081 figs = sort(get(0,'Children'));
082 openfigs = size(figs);
083 if ~isempty(figs)
084 cf = gcf;
085 if cf == 1
086 cf = [];
087 end
088 else
089 cf = [];
090 end
091 fig1 = 1;
092 if isempty(figs)
093 CHOICELIST = [];
094 CHOICEHANDLES = [];
095 figs = figure('visible','off');
096 fig1 = 0;
097 end
098 if figs(1) ~= 1
099 figs = [figure('visible','off'); figs];
100 fig1 = 0;
101 end
102 matchn = 0;
103 for i = 1:size(CHOICELIST,1)
104 if strcmp(name,deblank(CHOICELIST(i,:)))
105 matchn = i;
106 break;
107 end
108 end
109 if ~matchn
110 CHOICEHANDLES = [CHOICEHANDLES(:); 0];
111 if isempty(CHOICELIST)
112 CHOICELIST = name;
113 else
114 CHOICELIST = str2mat(CHOICELIST, name);
115 end
116 matchn = size(CHOICEHANDLES,1);
117 else
118 matchh = 0;
119 for i = 1:size(figs,1)
120 if figs(i) == CHOICEHANDLES(matchn)
121 matchh = i;
122 break;
123 end
124 end
125 if matchh
126 figure(CHOICEHANDLES(matchn));
127 return
128 end
129 end
130 ss = get(0,'ScreenSize');
131 xedge = 30;
132 ybord = 30;
133 width = 30;
134 yedge = 35;
135
136
137
138 ha = axes('visible','off');
139
140 hh = text(ones(size(labels,1)+1,1),ones(size(labels,1)+1,1),str2mat(labels,'Close'),'units','pixel');
141 maxwidth = 0;
142 height = 0;
143 for i = 1:length(hh),
144 ext = get(hh(i),'extent');
145 maxwidth = max(maxwidth,ext(3));
146 height = max(height,ext(4));
147 end
148 delete(hh);delete(ha);
149 yedge = 1.5*height;
150 height = 6*yedge/7;
151
152 imax = 1;
153
154 twidth = maxwidth;
155
156 mwwidth = twidth + width + 2*xedge;
157 mwheight = (size(labels,1)+2.5)*yedge;
158 swidth = ss(3); sheight = ss(4);
159 left = 20;
160 bottom = sheight-mwheight-ybord;
161 rect = [left bottom mwwidth mwheight];
162 CHOICEHANDLES(matchn) = figure('Position',rect,'number','off', ...
163 'name','','resize','off','colormap',[],...
164 'Menubar','none','visible','off');
165
166 fg = CHOICEHANDLES(matchn);
167 fgs = CHOICEHANDLES(CHOICEHANDLES ~= fg);
168 set(fgs,'visible','off')
169 set(gca,'Position',[0 0 1 1]); axis off;
170
171
172
173 hdrpos = [.05 1-1/(size(labels,1)+1.6) .9 1/(size(labels,1)+1.6)];
174
175 hh=uicontrol(fg,'style','text','units','normal',...
176 'position',hdrpos,'string',header,...
177 'Horizontal','center');
178 set(hh,'backg',get(gcf,'color'),'foreg',[1 1 1]-get(gcf,'color'))
179
180 sb = ['figure(1),set(1,''visible'',''on'');set(',int2str(fg),',''visible'',''off'');'];
181 se = [';global CHOICEHANDLES;set(CHOICEHANDLES(length(CHOICEHANDLES)),''visible'',''on''),clear CHOICEHANDLES'];
182 for ii=size(labels,1):-1:1
183 i = size(labels,1) + 2 - ii;
184 h1 = uicontrol(fg,'position',[xedge (i-.5)*yedge width+twidth height],...
185 'callback',[sb callbacks(ii,:) se],...
186 'string',[' ',deblank(labels(ii,:)), ' '],...
187 'HorizontalAlignment','left','interruptible',yn);
188
189 end
190
191 uicontrol(fg,'position',[xedge .5*yedge width+twidth height],...
192 'string',' Close ',...
193 'callback',['choicex(''',name,''')'],...
194 'HorizontalAlignment','left');
195
196 set(fg,'HandleVisibility','callback','visible','on')
197
198 if ~isempty(cf)
199 figure(cf)
200 else
201 if ~fig1
202 close(1);
203 end
204 end
205
206