]> AND Private Git Repository - these_gilles.git/blob - THESE/codes/meanshift/Ms_segmenter/My_inputdlg.m
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
28/08 matin
[these_gilles.git] / THESE / codes / meanshift / Ms_segmenter / My_inputdlg.m
1 function Answer=My_inputdlg(Prompt, Title, NumLines, DefAns)\r
2 %INPUTDLG Input dialog box.\r
3 %  Answer = inputdlg(Prompt) creates a modal dialog box that returns\r
4 %  user input for multiple prompts in the cell array Answer.  Prompt\r
5 %  is a cell array containing the Prompt strings.\r
6 %\r
7 %  Answer = inputdlg(Prompt,Title) specifies the Title for the dialog.\r
8 %\r
9 %  Answer = inputdlg(Prompt,Title,LineNo) specifies the number of lines\r
10 %  for each answer in LineNo.  LineNo may be a constant value or a \r
11 %  vector having one element per Prompt.\r
12 %\r
13 %  Answer = inputdlg(Prompt,Title,LineNo,DefAns) specifies the default\r
14 %  answer to display for each Prompt.  DefAns must contain the same\r
15 %  number of elements as Prompt and must be a cell array.\r
16 %  Example:\r
17 %  prompt={'Enter the matrix size:','Enter the colormap name:'};\r
18 %  def={'20','hsv'};\r
19 %  title='Input for Peaks function';\r
20 %  lineNo=1;\r
21 %  answer=inputdlg(prompt,title,lineNo,def);\r
22 %\r
23 %  See also TEXTWRAP.\r
24 \r
25 %  Loren Dean   May 24, 1995.\r
26 %  Copyright (c) 1984-97 by The MathWorks, Inc.\r
27 %  $Revision: 1.36 $\r
28 \r
29 %%%%%%%%%%%%%%%%%%%%%\r
30 %%% General Info. %%%\r
31 %%%%%%%%%%%%%%%%%%%%%\r
32 Black      =[0       0        0      ]/255;\r
33 LightGray  =[192     192      192    ]/255;\r
34 LightGray2 =[160     160      164    ]/255;\r
35 MediumGray =[128     128      128    ]/255;\r
36 White      =[255     255      255    ]/255;\r
37 \r
38 %%%%%%%%%%%%%%%%%%%%\r
39 %%% Nargin Check %%%\r
40 %%%%%%%%%%%%%%%%%%%%\r
41 if nargout~=1,error('Wrong number of output arguents for INPUTDLG');end\r
42 if nargin<1,error('Too few arguments for INPUTDLG');end\r
43 \r
44 if nargin==1,Title=' ';end\r
45 if nargin<=2, NumLines=1;end\r
46 \r
47 if ~iscell(Prompt),\r
48   Prompt={Prompt};\r
49 end\r
50 \r
51 NumQuest=prod(size(Prompt));    \r
52 \r
53 if nargin<=3, \r
54   DefAns=cell(NumQuest,1);\r
55   for lp=1:NumQuest, DefAns{lp}=''; end\r
56 end\r
57 if nargin>4,error('Too many input arguments');end\r
58 \r
59 % Backwards Compatibility\r
60 if isstr(NumLines),\r
61   warning(['Please see the INPUTDLG help for correct input syntax.' 10 ...\r
62            '         OKCallback no longer supported.' ]);\r
63   NumLines=1;\r
64 end\r
65 \r
66 if length(NumLines)~=NumQuest,NumLines=ones(NumQuest,1)*NumLines(1);end\r
67 \r
68 if ~iscell(DefAns),\r
69   error('Default Answer must be a cell array in INPUTDLG.');  \r
70 end\r
71 \r
72 %%%%%%%%%%%%%%%%%%%%%%%\r
73 %%% Create InputFig %%%\r
74 %%%%%%%%%%%%%%%%%%%%%%%\r
75 FigWidth=300;FigHeight=100;\r
76 FigPos(3:4)=[FigWidth FigHeight];\r
77 FigColor=get(0,'Defaultuicontrolbackgroundcolor');\r
78 InputFig=dialog(                            ...\r
79                'Visible'         ,'off'   , ...\r
80                'Name'            ,Title   , ...\r
81                'Pointer'         ,'arrow' , ...\r
82                'Units'           ,'points', ...\r
83                'UserData'        ,''      , ...\r
84                'Tag'             ,Title   , ...\r
85                'HandleVisibility','on'    , ...               \r
86                'Color'           ,FigColor, ...               \r
87                'NextPlot'        ,'add'     ...\r
88                );\r
89   \r
90 \r
91 %%%%%%%%%%%%%%%%%%%%%\r
92 %%% Set Positions %%%\r
93 %%%%%%%%%%%%%%%%%%%%%\r
94 DefOffset=5;\r
95 SmallOffset=2;\r
96 \r
97 DefBtnWidth=50;\r
98 BtnHeight=20;\r
99 BtnYOffset=DefOffset;\r
100 BtnFontSize=get(0,'FactoryUIControlFontSize');\r
101 BtnWidth=DefBtnWidth;\r
102 TxtBackClr=FigColor;\r
103 TxtForeClr=Black;\r
104 \r
105 StInfo.Style              ='text'     ;\r
106 StInfo.Units              ='points'   ;   \r
107 StInfo.FontSize           =BtnFontSize;\r
108 StInfo.HorizontalAlignment='left'     ;\r
109 StInfo.BackgroundColor    =TxtBackClr ;\r
110 StInfo.ForegroundColor    =TxtForeClr ;\r
111 StInfo.HandleVisibility   ='callback' ;\r
112 \r
113 \r
114 EdInfo=StInfo;\r
115 EdInfo.Style='edit';\r
116 EdInfo.BackgroundColor=White;\r
117 \r
118 BtnInfo=StInfo;\r
119 BtnInfo.Style='pushbutton';\r
120 BtnInfo.HorizontalAlignment='center';\r
121 \r
122 % Determine # of lines for all Prompts\r
123 ExtControl=uicontrol(StInfo, ...\r
124                      'String'   ,''         , ...    \r
125                      'Position' ,[DefOffset                  DefOffset  ...\r
126                                  0.95*(FigWidth-2*DefOffset) BtnHeight  ...\r
127                                 ]            , ...\r
128                      'Visible'  ,'off'         ...\r
129                      );\r
130                      \r
131 WrapQuest=cell(NumQuest,1);\r
132 QuestPos=zeros(NumQuest,4);\r
133 \r
134 for ExtLp=1:NumQuest,\r
135   [WrapQuest{ExtLp},QuestPos(ExtLp,1:4)]= ...\r
136             textwrap(ExtControl,Prompt(ExtLp),75);\r
137 end % for ExtLp\r
138 delete(ExtControl);\r
139 \r
140 QuestHeight=QuestPos(:,4);\r
141 \r
142 TxtHeight=QuestHeight(1)/size(WrapQuest{1,1},1);\r
143 EditHeight=TxtHeight*NumLines;\r
144 EditHeight(NumLines==1)=EditHeight(NumLines==1)+4;\r
145 \r
146 FigHeight=(NumQuest+2)*DefOffset    + ...\r
147           BtnHeight+sum(EditHeight) + ...\r
148           sum(QuestHeight);%          + ...\r
149                            %NumQuest*SmallOffset;\r
150 \r
151 FigWidth=max(175,max(QuestPos(:,3)))+2*DefOffset;\r
152 FigPos=get(InputFig,'Position');\r
153 \r
154 Temp=get(0,'Units');\r
155 set(0,'Units','points');\r
156 ScreenSize=get(0,'ScreenSize');\r
157 set(0,'Units',Temp);\r
158 \r
159 FigPos(1)=(ScreenSize(3)-FigWidth)/2;\r
160 FigPos(2)=(ScreenSize(4)-FigHeight)/2;\r
161 FigPos(3)=FigWidth;\r
162 FigPos(4)=FigHeight;\r
163 set(InputFig,'Position',FigPos);\r
164 \r
165 TxtXOffset=DefOffset;\r
166 TxtWidth=FigWidth-2*DefOffset;\r
167 TxtForeClr=Black;\r
168 TxtBackClr=get(InputFig,'Color');\r
169 \r
170 QuestYOffset=zeros(NumQuest,1);\r
171 EditYOffset=zeros(NumQuest,1);\r
172 QuestYOffset(1)=FigHeight-DefOffset-QuestHeight(1);\r
173 EditYOffset(1)=QuestYOffset(1)-EditHeight(1);% -SmallOffset;\r
174 \r
175 for YOffLp=2:NumQuest,\r
176   QuestYOffset(YOffLp)=EditYOffset(YOffLp-1)-QuestHeight(YOffLp)-DefOffset;\r
177   EditYOffset(YOffLp)=QuestYOffset(YOffLp)-EditHeight(YOffLp); %-SmallOffset;\r
178 end % for YOffLp\r
179 \r
180 QuestHandle=[];\r
181 EditHandle=[];\r
182 for lp=1:NumQuest,\r
183   QuestTag=['Prompt' num2str(lp)];\r
184   EditTag=['Edit' num2str(lp)];\r
185   QuestHandle(lp)=uicontrol(InputFig  ,                         ...\r
186                            StInfo     , ...\r
187                            'Max'      ,size(Prompt{lp},1), ...\r
188                            'Position' ,[ TxtXOffset QuestYOffset(lp) ...\r
189                                          TxtWidth   QuestHeight(lp)  ...\r
190                                        ]                      , ...\r
191                            'String'   ,WrapQuest{lp}       , ...\r
192                            'Tag'      ,QuestTag                 ...\r
193                            );\r
194 \r
195   EditHandle(lp)=uicontrol(InputFig   ,                       ...\r
196                            EdInfo     , ...\r
197                           'Max'       ,NumLines(lp)         , ...\r
198                           'Position'  ,[ TxtXOffset EditYOffset(lp) ...\r
199                                          TxtWidth   EditHeight(lp)  ...\r
200                                        ]                    , ...\r
201                           'String'    ,DefAns{lp}           , ...\r
202                           'Tag'       ,QuestTag               ...\r
203                           );\r
204                                    \r
205 end % for lp\r
206 \r
207 CBString='set(gcf,''UserData'',''Cancel'');uiresume';\r
208 \r
209 CancelHandle=uicontrol(InputFig   ,              ...\r
210                       BtnInfo     , ...\r
211                       'Position'  ,[ DefOffset DefOffset ...\r
212                                     BtnWidth  BtnHeight  ...\r
213                                    ]           , ...\r
214                       'String'    ,'Cancel'    , ...\r
215                       'Callback'  ,CBString    , ...\r
216                       'Tag'       ,'Cancel'      ...\r
217                       );\r
218                                    \r
219                                    \r
220 CBString='set(gcf,''UserData'',''OK'');uiresume';\r
221 \r
222 OKHandle=uicontrol(InputFig    ,              ...\r
223                    BtnInfo     , ...\r
224                    'Position'  ,[ FigWidth-BtnWidth-DefOffset DefOffset ...\r
225                                   BtnWidth                    BtnHeight ...\r
226                                 ]           , ...\r
227                   'Callback'   ,CBString    , ...\r
228                   'String'     ,'OK'        , ...\r
229                   'Tag'        ,'OK'          ...\r
230                   );\r
231     \r
232 set(InputFig, 'KeyPressFcn', CBString);\r
233 set(InputFig ,'Visible','on');\r
234 set(findobj(InputFig),'Units','normalized','HandleVisibility','callback');\r
235 set(InputFig,'Units','points');\r
236 \r
237 uiwait(InputFig);\r
238 \r
239 TempHide=get(0,'ShowHiddenHandles');\r
240 set(0,'ShowHiddenHandles','on');\r
241 \r
242 if any(get(0,'Children')==InputFig),\r
243   Answer={};\r
244   if strcmp(get(InputFig,'UserData'),'OK'),\r
245     Answer=cell(NumQuest,1);\r
246     for lp=1:NumQuest,\r
247       Answer(lp)=get(EditHandle(lp),{'String'});\r
248     end % for\r
249   end % if strcmp\r
250   delete(InputFig);\r
251 else,\r
252   Answer={};\r
253 end % if any\r
254 \r
255 set(0,'ShowHiddenHandles',TempHide);\r