1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
---|
2 | "http://www.w3.org/TR/REC-html40/loose.dtd"> |
---|
3 | <html> |
---|
4 | <head> |
---|
5 | <title>Description of tablegui</title> |
---|
6 | <meta name="keywords" content="tablegui"> |
---|
7 | <meta name="description" content="TABLEGUI - Spreadsheet like display and edition of a generic 2D array. By generic it is"> |
---|
8 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
---|
9 | <meta name="generator" content="m2html © 2003 Guillaume Flandin"> |
---|
10 | <meta name="robots" content="index, follow"> |
---|
11 | <link type="text/css" rel="stylesheet" href="../../m2html.css"> |
---|
12 | </head> |
---|
13 | <body> |
---|
14 | <a name="_top"></a> |
---|
15 | <div><a href="../../index.html">Home</a> > <a href="#">applications</a> > <a href="index.html">common</a> > tablegui.m</div> |
---|
16 | |
---|
17 | <!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png"> Master index</a></td> |
---|
18 | <td align="right"><a href="index.html">Index for applications/common <img alt=">" border="0" src="../../right.png"></a></td></tr></table>--> |
---|
19 | |
---|
20 | <h1>tablegui |
---|
21 | </h1> |
---|
22 | |
---|
23 | <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
24 | <div class="box"><strong>TABLEGUI - Spreadsheet like display and edition of a generic 2D array. By generic it is</strong></div> |
---|
25 | |
---|
26 | <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
27 | <div class="box"><strong>function out = tableGUI(varargin) </strong></div> |
---|
28 | |
---|
29 | <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
30 | <div class="fragment"><pre class="comment"> TABLEGUI - Spreadsheet like display and edition of a generic 2D array. By generic it is |
---|
31 | mean that the array can be a numeric MxN matrix or a MxN cell array (with mixed |
---|
32 | number and text strings). This function imitates the table cells with edit boxes |
---|
33 | which may become slow if the number of elements required is large. However, it |
---|
34 | works fast for small matrices. If the default number of rows is exceeded a vertical |
---|
35 | slider is created. The slider works by changing the position of the table elements, |
---|
36 | which again may become slow if the default number of visible rows is large. Otherwise |
---|
37 | it works pretty fast. |
---|
38 | |
---|
39 | USAGE: |
---|
40 | OUT = TABLEGUI(varargin) |
---|
41 | |
---|
42 | Inputs are in property/value pairs. All properties are strings but the values are |
---|
43 | of different types depending on the case. |
---|
44 | |
---|
45 | PROPERTY VALUE TYPE |
---|
46 | |
---|
47 | 'array' It can be either an numeric matrix or a MxN numeric or cell array |
---|
48 | cell array. |
---|
49 | 'NumRows' Total number of rows to create. Use this when the integer |
---|
50 | 'array' option is not used, or when you want to |
---|
51 | create extra empty rows. |
---|
52 | 'NumCol' Total number of columns to create. Use this when integer |
---|
53 | the 'array' option is not used, but ignored if it was. |
---|
54 | 'MAX_ROWS' Number of visible rows. If NumRows > MAX_ROWS integer |
---|
55 | a vertical slider is created (DEF = 10) |
---|
56 | 'RowHeight' editboxes height in pixels (DEF = 20) integer |
---|
57 | 'ColWidth' editboxes width in pixels (DEF = 60) scalar or row vector |
---|
58 | If a vector is transmited, it must contains NumCol |
---|
59 | elements which set individual column widths. |
---|
60 | 'bd_size' space between editboxes width in pixels (DEF = 0) integer |
---|
61 | 'HorAlin' editboxes 'HorizontalAlignment' property. It can string |
---|
62 | be either 'left', 'center' or 'right' (DEF = 'center') |
---|
63 | 'HdrButtons' create a first row of buttons to hold column string - either '' or 'y' |
---|
64 | names. Give an empty string ('') if you don't want |
---|
65 | column names (DEF = 'Y'). |
---|
66 | 'ColNames' Cell array of strings for column names. If not 1xN cell array of strings |
---|
67 | provided the columns are named 'A', 'B', ... |
---|
68 | 'RowNumbers' Add a first column with row numbers. Note that this string - either '' or 'y' |
---|
69 | column is set to 'inactive' and its not transmited |
---|
70 | on the output (DEF = ''). |
---|
71 | 'checks' If = 'Y' it creates a vertical line of checkboxes string - either '' or 'y' |
---|
72 | This affects what is send as output. Only rows that |
---|
73 | have it's checkbox checked will be returned. |
---|
74 | 'FigName' Name that appears in the title bar (DEF = 'Table'). string |
---|
75 | 'position' Screen location to be used in the call to MOVEGUI string |
---|
76 | See doc of that function for valid position |
---|
77 | strings (DEF = 'east'). |
---|
78 | 'modal' By default the window works in MODAL mode. Give an string - either '' or 'y' |
---|
79 | empty string ('') if you don't want it to be MODAL. |
---|
80 | In this later case the output OUT, if requested, will |
---|
81 | contain the figure handle but see more about this below. |
---|
82 | |
---|
83 | OUT - the output - contains different things depending whether or not the |
---|
84 | figure works in MODAL mode. If yes, OUT is a MxN cell array with the |
---|
85 | elements retrived from the contents of the edit boxes. Otherwise, OUT |
---|
86 | will contain the figure's handle. This handle has the 'UserData' property |
---|
87 | filled with a structure (called hand) which contains the handles of all |
---|
88 | uicontrols. Use this option if you want to interact with the TABLEGUI |
---|
89 | figure inside your own code. |
---|
90 | |
---|
91 | Examples: |
---|
92 | - Display a 12x6 numeric matrix with two extra blank rows appended to the end |
---|
93 | out = tableGUI('array',rand(12,6),'ColNames',{'1' '2' '3' '4' '5' '6'},'NumRows',14); |
---|
94 | |
---|
95 | - Create a cell array with the first column filled with the row number and use |
---|
96 | columns with different widths. Create also check boxes. |
---|
97 | zz=cell(4,5); zz(:,1) = num2cell(1:4)'; |
---|
98 | out = tableGUI('array',zz,'ColNames',{'N','A','B','C','D'},'ColWidth',[20 60 60 60 60],'checks','y'); |
---|
99 | |
---|
100 | - Create a similar table as in the previous example but with the row numbers option. |
---|
101 | out = tableGUI('array',cell(4,5),'RowNumbers','y','checks','y'); |
---|
102 | |
---|
103 | - Display the Control Points of the Image Processing Toolbox example |
---|
104 | "Registering an Aerial Photo to an Orthophoto" |
---|
105 | load westconcordpoints % load some points that were already picked |
---|
106 | gcp = [base_points input_points]; |
---|
107 | out = tableGUI('array',gcp,'RowNumbers','y','ColNames',{'Base Points - X','Base Points - Y',... |
---|
108 | 'Input Points - X','Input Points - Y'},'ColWidth',110,'FigName','GCP Table'); |
---|
109 | |
---|
110 | - Create an empty 12x6 empty table |
---|
111 | out = tableGUI; |
---|
112 | |
---|
113 | Acknowledgment |
---|
114 | This function uses the parse_pv_pairs of John d'Errico |
---|
115 | |
---|
116 | AUTHOR |
---|
117 | Joaquim Luis (jluis@ualg.pt) 17-Feb-2006</pre></div> |
---|
118 | |
---|
119 | <!-- crossreference --> |
---|
120 | <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
121 | This function calls: |
---|
122 | <ul style="list-style-image:url(../../matlabicon.gif)"> |
---|
123 | </ul> |
---|
124 | This function is called by: |
---|
125 | <ul style="list-style-image:url(../../matlabicon.gif)"> |
---|
126 | </ul> |
---|
127 | <!-- crossreference --> |
---|
128 | |
---|
129 | <h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
130 | <ul style="list-style-image:url(../../matlabicon.gif)"> |
---|
131 | <li><a href="#_sub1" class="code">function slider_Callback(obj,event,hand)</a></li><li><a href="#_sub2" class="code">function params = parse_pv_pairs(params,pv_pairs)</a></li></ul> |
---|
132 | <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
133 | <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function out = tableGUI(varargin)</a> |
---|
134 | 0002 <span class="comment">% TABLEGUI - Spreadsheet like display and edition of a generic 2D array. By generic it is</span> |
---|
135 | 0003 <span class="comment">% mean that the array can be a numeric MxN matrix or a MxN cell array (with mixed</span> |
---|
136 | 0004 <span class="comment">% number and text strings). This function imitates the table cells with edit boxes</span> |
---|
137 | 0005 <span class="comment">% which may become slow if the number of elements required is large. However, it</span> |
---|
138 | 0006 <span class="comment">% works fast for small matrices. If the default number of rows is exceeded a vertical</span> |
---|
139 | 0007 <span class="comment">% slider is created. The slider works by changing the position of the table elements,</span> |
---|
140 | 0008 <span class="comment">% which again may become slow if the default number of visible rows is large. Otherwise</span> |
---|
141 | 0009 <span class="comment">% it works pretty fast.</span> |
---|
142 | 0010 <span class="comment">%</span> |
---|
143 | 0011 <span class="comment">% USAGE:</span> |
---|
144 | 0012 <span class="comment">% OUT = TABLEGUI(varargin)</span> |
---|
145 | 0013 <span class="comment">%</span> |
---|
146 | 0014 <span class="comment">% Inputs are in property/value pairs. All properties are strings but the values are</span> |
---|
147 | 0015 <span class="comment">% of different types depending on the case.</span> |
---|
148 | 0016 <span class="comment">%</span> |
---|
149 | 0017 <span class="comment">% PROPERTY VALUE TYPE</span> |
---|
150 | 0018 <span class="comment">%</span> |
---|
151 | 0019 <span class="comment">% 'array' It can be either an numeric matrix or a MxN numeric or cell array</span> |
---|
152 | 0020 <span class="comment">% cell array.</span> |
---|
153 | 0021 <span class="comment">% 'NumRows' Total number of rows to create. Use this when the integer</span> |
---|
154 | 0022 <span class="comment">% 'array' option is not used, or when you want to</span> |
---|
155 | 0023 <span class="comment">% create extra empty rows.</span> |
---|
156 | 0024 <span class="comment">% 'NumCol' Total number of columns to create. Use this when integer</span> |
---|
157 | 0025 <span class="comment">% the 'array' option is not used, but ignored if it was.</span> |
---|
158 | 0026 <span class="comment">% 'MAX_ROWS' Number of visible rows. If NumRows > MAX_ROWS integer</span> |
---|
159 | 0027 <span class="comment">% a vertical slider is created (DEF = 10)</span> |
---|
160 | 0028 <span class="comment">% 'RowHeight' editboxes height in pixels (DEF = 20) integer</span> |
---|
161 | 0029 <span class="comment">% 'ColWidth' editboxes width in pixels (DEF = 60) scalar or row vector</span> |
---|
162 | 0030 <span class="comment">% If a vector is transmited, it must contains NumCol</span> |
---|
163 | 0031 <span class="comment">% elements which set individual column widths.</span> |
---|
164 | 0032 <span class="comment">% 'bd_size' space between editboxes width in pixels (DEF = 0) integer</span> |
---|
165 | 0033 <span class="comment">% 'HorAlin' editboxes 'HorizontalAlignment' property. It can string</span> |
---|
166 | 0034 <span class="comment">% be either 'left', 'center' or 'right' (DEF = 'center')</span> |
---|
167 | 0035 <span class="comment">% 'HdrButtons' create a first row of buttons to hold column string - either '' or 'y'</span> |
---|
168 | 0036 <span class="comment">% names. Give an empty string ('') if you don't want</span> |
---|
169 | 0037 <span class="comment">% column names (DEF = 'Y').</span> |
---|
170 | 0038 <span class="comment">% 'ColNames' Cell array of strings for column names. If not 1xN cell array of strings</span> |
---|
171 | 0039 <span class="comment">% provided the columns are named 'A', 'B', ...</span> |
---|
172 | 0040 <span class="comment">% 'RowNumbers' Add a first column with row numbers. Note that this string - either '' or 'y'</span> |
---|
173 | 0041 <span class="comment">% column is set to 'inactive' and its not transmited</span> |
---|
174 | 0042 <span class="comment">% on the output (DEF = '').</span> |
---|
175 | 0043 <span class="comment">% 'checks' If = 'Y' it creates a vertical line of checkboxes string - either '' or 'y'</span> |
---|
176 | 0044 <span class="comment">% This affects what is send as output. Only rows that</span> |
---|
177 | 0045 <span class="comment">% have it's checkbox checked will be returned.</span> |
---|
178 | 0046 <span class="comment">% 'FigName' Name that appears in the title bar (DEF = 'Table'). string</span> |
---|
179 | 0047 <span class="comment">% 'position' Screen location to be used in the call to MOVEGUI string</span> |
---|
180 | 0048 <span class="comment">% See doc of that function for valid position</span> |
---|
181 | 0049 <span class="comment">% strings (DEF = 'east').</span> |
---|
182 | 0050 <span class="comment">% 'modal' By default the window works in MODAL mode. Give an string - either '' or 'y'</span> |
---|
183 | 0051 <span class="comment">% empty string ('') if you don't want it to be MODAL.</span> |
---|
184 | 0052 <span class="comment">% In this later case the output OUT, if requested, will</span> |
---|
185 | 0053 <span class="comment">% contain the figure handle but see more about this below.</span> |
---|
186 | 0054 <span class="comment">%</span> |
---|
187 | 0055 <span class="comment">% OUT - the output - contains different things depending whether or not the</span> |
---|
188 | 0056 <span class="comment">% figure works in MODAL mode. If yes, OUT is a MxN cell array with the</span> |
---|
189 | 0057 <span class="comment">% elements retrived from the contents of the edit boxes. Otherwise, OUT</span> |
---|
190 | 0058 <span class="comment">% will contain the figure's handle. This handle has the 'UserData' property</span> |
---|
191 | 0059 <span class="comment">% filled with a structure (called hand) which contains the handles of all</span> |
---|
192 | 0060 <span class="comment">% uicontrols. Use this option if you want to interact with the TABLEGUI</span> |
---|
193 | 0061 <span class="comment">% figure inside your own code.</span> |
---|
194 | 0062 <span class="comment">%</span> |
---|
195 | 0063 <span class="comment">% Examples:</span> |
---|
196 | 0064 <span class="comment">% - Display a 12x6 numeric matrix with two extra blank rows appended to the end</span> |
---|
197 | 0065 <span class="comment">% out = tableGUI('array',rand(12,6),'ColNames',{'1' '2' '3' '4' '5' '6'},'NumRows',14);</span> |
---|
198 | 0066 <span class="comment">%</span> |
---|
199 | 0067 <span class="comment">% - Create a cell array with the first column filled with the row number and use</span> |
---|
200 | 0068 <span class="comment">% columns with different widths. Create also check boxes.</span> |
---|
201 | 0069 <span class="comment">% zz=cell(4,5); zz(:,1) = num2cell(1:4)';</span> |
---|
202 | 0070 <span class="comment">% out = tableGUI('array',zz,'ColNames',{'N','A','B','C','D'},'ColWidth',[20 60 60 60 60],'checks','y');</span> |
---|
203 | 0071 <span class="comment">%</span> |
---|
204 | 0072 <span class="comment">% - Create a similar table as in the previous example but with the row numbers option.</span> |
---|
205 | 0073 <span class="comment">% out = tableGUI('array',cell(4,5),'RowNumbers','y','checks','y');</span> |
---|
206 | 0074 <span class="comment">%</span> |
---|
207 | 0075 <span class="comment">% - Display the Control Points of the Image Processing Toolbox example</span> |
---|
208 | 0076 <span class="comment">% "Registering an Aerial Photo to an Orthophoto"</span> |
---|
209 | 0077 <span class="comment">% load westconcordpoints % load some points that were already picked</span> |
---|
210 | 0078 <span class="comment">% gcp = [base_points input_points];</span> |
---|
211 | 0079 <span class="comment">% out = tableGUI('array',gcp,'RowNumbers','y','ColNames',{'Base Points - X','Base Points - Y',...</span> |
---|
212 | 0080 <span class="comment">% 'Input Points - X','Input Points - Y'},'ColWidth',110,'FigName','GCP Table');</span> |
---|
213 | 0081 <span class="comment">%</span> |
---|
214 | 0082 <span class="comment">% - Create an empty 12x6 empty table</span> |
---|
215 | 0083 <span class="comment">% out = tableGUI;</span> |
---|
216 | 0084 <span class="comment">%</span> |
---|
217 | 0085 <span class="comment">% Acknowledgment</span> |
---|
218 | 0086 <span class="comment">% This function uses the parse_pv_pairs of John d'Errico</span> |
---|
219 | 0087 <span class="comment">%</span> |
---|
220 | 0088 <span class="comment">% AUTHOR</span> |
---|
221 | 0089 <span class="comment">% Joaquim Luis (jluis@ualg.pt) 17-Feb-2006</span> |
---|
222 | 0090 |
---|
223 | 0091 hand.NumRows = 12; hand.NumCol = 6; |
---|
224 | 0092 hand.MAX_ROWS = 10; hand.left_marg = 10; |
---|
225 | 0093 hand.RowHeight = 20; hand.bd_size = 0; |
---|
226 | 0094 hand.checks = <span class="string">''</span>; hand.HdrButtons = <span class="string">'Y'</span>; |
---|
227 | 0095 hand.HorAlin = <span class="string">'center'</span>; hand.FigName = <span class="string">'Table'</span>; |
---|
228 | 0096 hand.array = cell(hand.NumRows,hand.NumCol); |
---|
229 | 0097 hand.modal = <span class="string">'y'</span>; hand.position = <span class="string">'east'</span>; |
---|
230 | 0098 hand.RowNumbers = <span class="string">''</span>; d_col = 0; |
---|
231 | 0099 |
---|
232 | 0100 <span class="keyword">if</span> (nargin == 0) <span class="comment">% Demo</span> |
---|
233 | 0101 hand.ColNames = {<span class="string">'A'</span> <span class="string">'B'</span> <span class="string">'C'</span> <span class="string">'D'</span> <span class="string">'E'</span> <span class="string">'F'</span>}; |
---|
234 | 0102 hand.ColWidth = [50 80 80 80 80 50]; |
---|
235 | 0103 <span class="keyword">else</span> |
---|
236 | 0104 hand.ColNames = <span class="string">''</span>; hand.ColWidth = []; |
---|
237 | 0105 hand.array = []; def_NumRows = hand.NumRows; |
---|
238 | 0106 hand = <a href="#_sub2" class="code" title="subfunction params = parse_pv_pairs(params,pv_pairs)">parse_pv_pairs</a>(hand,varargin); |
---|
239 | 0107 <span class="keyword">if</span> (~isempty(hand.array)) |
---|
240 | 0108 <span class="keyword">if</span> (numel(hand.array) == 1 && numel(hand.array{1}) ~= 1) |
---|
241 | 0109 error(<span class="string">'The "array" argument must be a MxN cell array and not a {MxN} cell'</span>) |
---|
242 | 0110 <span class="keyword">end</span> |
---|
243 | 0111 [NumRows,hand.NumCol] = size(hand.array); |
---|
244 | 0112 <span class="keyword">if</span> (~iscell(hand.array)) <span class="comment">% We need as a cell array to be more general</span> |
---|
245 | 0113 hand.array = num2cell(hand.array); |
---|
246 | 0114 <span class="keyword">end</span> |
---|
247 | 0115 <span class="keyword">if</span> (NumRows < hand.NumRows && hand.NumRows ~= def_NumRows) <span class="comment">% Extra rows requested</span> |
---|
248 | 0116 hand.array = [hand.array; cell(hand.NumRows-NumRows,hand.NumCol)]; |
---|
249 | 0117 <span class="keyword">else</span> |
---|
250 | 0118 hand.NumRows = NumRows; |
---|
251 | 0119 <span class="keyword">end</span> |
---|
252 | 0120 <span class="keyword">if</span> (hand.NumRows < hand.MAX_ROWS), hand.MAX_ROWS = hand.NumRows; <span class="keyword">end</span> |
---|
253 | 0121 |
---|
254 | 0122 <span class="keyword">else</span> <span class="comment">% 'array' not transmited</span> |
---|
255 | 0123 hand.array = cell(hand.NumRows,hand.NumCol); |
---|
256 | 0124 <span class="keyword">end</span> |
---|
257 | 0125 |
---|
258 | 0126 <span class="keyword">if</span> (isempty(hand.ColNames) && ~isempty(hand.HdrButtons)) <span class="comment">% By default columns are labeled 'A','B',...</span> |
---|
259 | 0127 hand.ColNames = cell(1,hand.NumCol); |
---|
260 | 0128 <span class="keyword">for</span> (i = 1:hand.NumCol), hand.ColNames{1,i} = char(i+64); <span class="keyword">end</span> |
---|
261 | 0129 <span class="keyword">end</span> |
---|
262 | 0130 <span class="keyword">if</span> (size(hand.array,2) > size(hand.ColNames,2)) |
---|
263 | 0131 error(<span class="string">'"ColNames" argument has less elements than the number of columns is "array"'</span>) |
---|
264 | 0132 <span class="keyword">end</span> |
---|
265 | 0133 <span class="keyword">if</span> (isempty(hand.ColWidth)) <span class="comment">% Use default value for button width</span> |
---|
266 | 0134 hand.ColWidth = repmat(60,1,hand.NumCol); |
---|
267 | 0135 <span class="keyword">elseif</span> (numel(hand.ColWidth) == 1) <span class="comment">% 'ColWidth' was a scalar</span> |
---|
268 | 0136 hand.ColWidth = repmat(hand.ColWidth,1,hand.NumCol); |
---|
269 | 0137 <span class="keyword">end</span> |
---|
270 | 0138 |
---|
271 | 0139 <span class="keyword">if</span> (~isempty(hand.RowNumbers)) <span class="comment">% Row numbering was requested</span> |
---|
272 | 0140 hand.ColWidth = [35 hand.ColWidth]; |
---|
273 | 0141 hand.NumCol = hand.NumCol + 1; |
---|
274 | 0142 hand.array = [cell(hand.NumRows,1) hand.array]; |
---|
275 | 0143 d_col = 1; |
---|
276 | 0144 <span class="keyword">end</span> |
---|
277 | 0145 <span class="keyword">end</span> |
---|
278 | 0146 |
---|
279 | 0147 arr_pos_xi = [hand.left_marg + [0 (cumsum(hand.ColWidth+hand.bd_size))]]; |
---|
280 | 0148 arr_pos_xi(end) = []; <span class="comment">% We don't want the last element</span> |
---|
281 | 0149 arr_pos_xw = hand.ColWidth; |
---|
282 | 0150 |
---|
283 | 0151 <span class="comment">% ---------------- Create the figure ----------------------------------</span> |
---|
284 | 0152 fig_height = min(hand.NumRows,hand.MAX_ROWS) * (hand.RowHeight+hand.bd_size); |
---|
285 | 0153 <span class="keyword">if</span> (~isempty(hand.HdrButtons)), fig_height = fig_height + 22; <span class="keyword">end</span> <span class="comment">% Make room for header buttons</span> |
---|
286 | 0154 <span class="keyword">if</span> (~isempty(hand.modal)), fig_height = fig_height + 30; <span class="keyword">end</span> <span class="comment">% Make room for OK,Cancel buttons</span> |
---|
287 | 0155 pos = [5 75 sum(arr_pos_xw)+hand.left_marg+(hand.NumCol-1)*hand.bd_size+15 fig_height]; <span class="comment">% The 15 is for the slider</span> |
---|
288 | 0156 <span class="keyword">if</span> (~isempty(hand.checks)), pos(3) = pos(3) + 15; <span class="keyword">end</span> <span class="comment">% Account for checkboxes size</span> |
---|
289 | 0157 hand.hFig = figure(<span class="string">'unit'</span>,<span class="string">'pixels'</span>,<span class="string">'NumberTitle'</span>,<span class="string">'off'</span>,<span class="string">'Menubar'</span>,<span class="string">'none'</span>,<span class="string">'resize'</span>,<span class="string">'on'</span>,<span class="string">'position'</span>, <span class="keyword">...</span> |
---|
290 | 0158 pos,<span class="string">'Name'</span>,hand.FigName,<span class="string">'Resize'</span>,<span class="string">'off'</span>,<span class="string">'Visible'</span>,<span class="string">'off'</span>); |
---|
291 | 0159 movegui(hand.hFig,hand.position) |
---|
292 | 0160 |
---|
293 | 0161 hand.arr_pos_y = (fig_height-hand.RowHeight-hand.bd_size - (0:hand.NumRows-1)*(hand.RowHeight+hand.bd_size))'; |
---|
294 | 0162 <span class="keyword">if</span> (~isempty(hand.HdrButtons)), hand.arr_pos_y = hand.arr_pos_y - 22; <span class="keyword">end</span> |
---|
295 | 0163 |
---|
296 | 0164 <span class="keyword">if</span> (~isempty(hand.checks)) <span class="comment">% Create the checkboxes uicontrols</span> |
---|
297 | 0165 arr_pos_xi = arr_pos_xi + 15; <span class="comment">% Make room for them</span> |
---|
298 | 0166 hand.hChecks = zeros(hand.NumRows,1); |
---|
299 | 0167 hand.Checks_pos_orig = [ones(hand.NumRows,1)*7 (hand.arr_pos_y+3) ones(hand.NumRows,1)*15 ones(hand.NumRows,1)*15]; |
---|
300 | 0168 <span class="keyword">end</span> |
---|
301 | 0169 hand.hEdits = zeros(hand.NumRows,hand.NumCol); |
---|
302 | 0170 hand.Edits_pos_orig = cell(hand.NumRows,hand.NumCol); |
---|
303 | 0171 |
---|
304 | 0172 <span class="comment">% ---------------- Create the edit uicontrols ---------------------------</span> |
---|
305 | 0173 <span class="keyword">for</span> (i = 1:hand.NumRows) |
---|
306 | 0174 <span class="keyword">if</span> (~isempty(hand.checks)) |
---|
307 | 0175 hand.hChecks(i) = uicontrol(<span class="string">'Style'</span>,<span class="string">'checkbox'</span>,<span class="string">'unit'</span>,<span class="string">'pixels'</span>,<span class="string">'position'</span>, <span class="keyword">...</span> |
---|
308 | 0176 hand.Checks_pos_orig(i,:),<span class="string">'Value'</span>,1); |
---|
309 | 0177 <span class="keyword">end</span> |
---|
310 | 0178 <span class="keyword">for</span> (j = 1:hand.NumCol) |
---|
311 | 0179 hand.Edits_pos_orig{i,j} = [arr_pos_xi(j) hand.arr_pos_y(i) arr_pos_xw(j) 20]; |
---|
312 | 0180 hand.hEdits(i,j) = uicontrol(<span class="string">'Style'</span>,<span class="string">'edit'</span>,<span class="string">'unit'</span>,<span class="string">'pixels'</span>,<span class="string">'backgroundcolor'</span>,<span class="string">'w'</span>,<span class="string">'position'</span>, <span class="keyword">...</span> |
---|
313 | 0181 [arr_pos_xi(j) hand.arr_pos_y(i) arr_pos_xw(j) 20],<span class="string">'String'</span>,hand.array{i,j},<span class="keyword">...</span> |
---|
314 | 0182 <span class="string">'HorizontalAlignment'</span>,hand.HorAlin); |
---|
315 | 0183 <span class="keyword">end</span> |
---|
316 | 0184 <span class="keyword">if</span> (~isempty(hand.RowNumbers)) |
---|
317 | 0185 set(hand.hEdits(i,1),<span class="string">'String'</span>,i,<span class="string">'Enable'</span>,<span class="string">'inactive'</span>,<span class="string">'Background'</span>,[200 200 145]/255,<span class="string">'UserData'</span>,i) |
---|
318 | 0186 <span class="keyword">else</span> |
---|
319 | 0187 set(hand.hEdits(i,1),<span class="string">'UserData'</span>,i) |
---|
320 | 0188 <span class="keyword">end</span> |
---|
321 | 0189 <span class="keyword">end</span> |
---|
322 | 0190 <span class="keyword">if</span> (~isempty(hand.HdrButtons)) <span class="comment">% Create the header pushbutton uicontrols</span> |
---|
323 | 0191 <span class="keyword">for</span> (j = 1:hand.NumCol-d_col) <span class="comment">% The d_col is to account for an eventual 'RowNumbers' option</span> |
---|
324 | 0192 uicontrol(<span class="string">'Style'</span>,<span class="string">'pushbutton'</span>,<span class="string">'unit'</span>,<span class="string">'pixels'</span>,<span class="string">'Enable'</span>,<span class="string">'inactive'</span>,<span class="string">'position'</span>, <span class="keyword">...</span> |
---|
325 | 0193 [arr_pos_xi(j+d_col) hand.arr_pos_y(1)+hand.RowHeight hand.ColWidth(j+d_col) 20],<span class="string">'String'</span>,hand.ColNames{j}) |
---|
326 | 0194 <span class="keyword">end</span> |
---|
327 | 0195 <span class="keyword">end</span> |
---|
328 | 0196 |
---|
329 | 0197 <span class="comment">% ---------------- See if we need a slider ---------------------------</span> |
---|
330 | 0198 pos_t = get(hand.hEdits(1,hand.NumCol),<span class="string">'pos'</span>); <span class="comment">% Get top right edit position</span> |
---|
331 | 0199 pos_b = get(hand.hEdits(hand.MAX_ROWS,1),<span class="string">'pos'</span>); <span class="comment">% Get last visible edit position</span> |
---|
332 | 0200 <span class="keyword">if</span> (hand.NumRows > hand.MAX_ROWS) |
---|
333 | 0201 set(hand.hEdits(hand.MAX_ROWS+1:hand.NumRows,1:hand.NumCol),<span class="string">'Visible'</span>,<span class="string">'off'</span>) <span class="comment">% Hide those who are out of view</span> |
---|
334 | 0202 <span class="keyword">if</span> (~isempty(hand.checks)) |
---|
335 | 0203 set(hand.hChecks(hand.MAX_ROWS+1:hand.NumRows),<span class="string">'Visible'</span>,<span class="string">'off'</span>) |
---|
336 | 0204 <span class="keyword">end</span> |
---|
337 | 0205 pos = [pos_t(1)+pos_t(3) pos_b(2) 15 pos_t(2)+pos_t(4)-pos_b(2)]; |
---|
338 | 0206 sld_step = 1 / (hand.NumRows-1); |
---|
339 | 0207 sld_step(2) = 5 * sld_step(1); |
---|
340 | 0208 hand.hSlid = uicontrol(<span class="string">'style'</span>,<span class="string">'slider'</span>,<span class="string">'units'</span>,<span class="string">'pixels'</span>,<span class="string">'position'</span>,pos,<span class="keyword">...</span> |
---|
341 | 0209 <span class="string">'min'</span>,1,<span class="string">'max'</span>,hand.NumRows,<span class="string">'Value'</span>,hand.NumRows,<span class="string">'SliderStep'</span>,sld_step); |
---|
342 | 0210 set(hand.hSlid,<span class="string">'callback'</span>,{@<a href="#_sub1" class="code" title="subfunction slider_Callback(obj,event,hand)">slider_Callback</a>,hand}) |
---|
343 | 0211 set(hand.hSlid,<span class="string">'UserData'</span>,hand.NumRows) <span class="comment">% Store current value</span> |
---|
344 | 0212 <span class="keyword">end</span> |
---|
345 | 0213 |
---|
346 | 0214 <span class="comment">% ---------------- See if the window is MODAL ---------------------------</span> |
---|
347 | 0215 <span class="keyword">if</span> (~isempty(hand.modal)) |
---|
348 | 0216 uicontrol(<span class="string">'Style'</span>,<span class="string">'pushbutton'</span>,<span class="string">'unit'</span>,<span class="string">'pixels'</span>,<span class="string">'String'</span>,<span class="string">'OK'</span>,<span class="string">'position'</span>,<span class="keyword">...</span> |
---|
349 | 0217 [pos_t(1)+pos_t(3)-110 5 40 20],<span class="string">'FontName'</span>,<span class="string">'Helvetica'</span>,<span class="string">'FontSize'</span>,9,<span class="keyword">...</span> |
---|
350 | 0218 <span class="string">'callback'</span>,<span class="string">'uiresume'</span>,<span class="string">'tag'</span>,<span class="string">'OK'</span>); |
---|
351 | 0219 uicontrol(<span class="string">'Style'</span>,<span class="string">'pushbutton'</span>,<span class="string">'unit'</span>,<span class="string">'pixels'</span>,<span class="string">'String'</span>,<span class="string">'Cancel'</span>,<span class="string">'position'</span>, <span class="keyword">...</span> |
---|
352 | 0220 [pos_t(1)+pos_t(3)-60 5 60 20],<span class="string">'FontName'</span>,<span class="string">'Helvetica'</span>,<span class="string">'FontSize'</span>,9,<span class="keyword">...</span> |
---|
353 | 0221 <span class="string">'callback'</span>,<span class="string">'uiresume'</span>,<span class="string">'tag'</span>,<span class="string">'cancel'</span>); |
---|
354 | 0222 uiwait(hand.hFig) <span class="comment">% It also sets the Figure's visibility 'on'</span> |
---|
355 | 0223 but = gco; |
---|
356 | 0224 <span class="keyword">if</span> strcmp(get(but,<span class="string">'tag'</span>),<span class="string">'OK'</span>) |
---|
357 | 0225 out = reshape(get(hand.hEdits,<span class="string">'String'</span>),hand.NumRows,hand.NumCol); |
---|
358 | 0226 <span class="keyword">if</span> (~isempty(hand.checks)) |
---|
359 | 0227 unchecked = (cell2mat(get(hand.hChecks,<span class="string">'Value'</span>)) == 0); |
---|
360 | 0228 out(unchecked,:) = []; <span class="comment">% Remove unchecked rows</span> |
---|
361 | 0229 <span class="keyword">end</span> |
---|
362 | 0230 <span class="keyword">if</span> (~isempty(hand.RowNumbers)) <span class="comment">% Do not output the row numbers</span> |
---|
363 | 0231 out = out(:,2:end); |
---|
364 | 0232 <span class="keyword">end</span> |
---|
365 | 0233 delete(hand.hFig) |
---|
366 | 0234 <span class="keyword">elseif</span> strcmp(get(but,<span class="string">'tag'</span>),<span class="string">'cancel'</span>) |
---|
367 | 0235 out = []; delete(hand.hFig) |
---|
368 | 0236 <span class="keyword">else</span> <span class="comment">% Figure was killed</span> |
---|
369 | 0237 out = []; |
---|
370 | 0238 <span class="keyword">end</span> |
---|
371 | 0239 <span class="keyword">else</span> |
---|
372 | 0240 set(hand.hFig,<span class="string">'Visible'</span>,<span class="string">'on'</span>,<span class="string">'UserData'</span>,hand) |
---|
373 | 0241 <span class="keyword">if</span> (nargout), out = hand.hFig; <span class="keyword">end</span> |
---|
374 | 0242 <span class="keyword">end</span> |
---|
375 | 0243 |
---|
376 | 0244 <span class="comment">% ---------------------------------------------------------------------------</span> |
---|
377 | 0245 <a name="_sub1" href="#_subfunctions" class="code">function slider_Callback(obj,event,hand)</a> |
---|
378 | 0246 |
---|
379 | 0247 val = round(get(hand.hSlid,<span class="string">'Value'</span>)); |
---|
380 | 0248 old_val = get(hand.hSlid,<span class="string">'UserData'</span>); |
---|
381 | 0249 ds = val - old_val; |
---|
382 | 0250 |
---|
383 | 0251 <span class="keyword">if</span> (ds < 0) <span class="comment">% Slider moved down</span> |
---|
384 | 0252 n = hand.NumRows - val + 1; d_col = hand.NumRows - val; |
---|
385 | 0253 <span class="keyword">if</span> (n+hand.MAX_ROWS-1 > hand.NumRows) <span class="comment">% Case we jumped into the midle zone</span> |
---|
386 | 0254 adj = (n+hand.MAX_ROWS-1 - hand.NumRows); |
---|
387 | 0255 n = n - adj; d_col = d_col - adj; |
---|
388 | 0256 <span class="keyword">end</span> |
---|
389 | 0257 <span class="keyword">for</span> (i = n:min(n+hand.MAX_ROWS-1,hand.NumRows)) <span class="comment">% Update positions</span> |
---|
390 | 0258 <span class="keyword">for</span> (j = 1:hand.NumCol) |
---|
391 | 0259 pos = hand.Edits_pos_orig{i,j}; |
---|
392 | 0260 set(hand.hEdits(i,j),<span class="string">'pos'</span>,[pos(1) hand.arr_pos_y(i-d_col) pos(3:4)],<span class="string">'Visible'</span>,<span class="string">'on'</span>) |
---|
393 | 0261 <span class="keyword">end</span> |
---|
394 | 0262 <span class="keyword">if</span> (~isempty(hand.checks)) <span class="comment">% If we have checkboxes</span> |
---|
395 | 0263 pos = hand.Checks_pos_orig(i,:); |
---|
396 | 0264 set(hand.hChecks(i),<span class="string">'pos'</span>,[pos(1) hand.arr_pos_y(i-d_col)+3 pos(3:4)],<span class="string">'Visible'</span>,<span class="string">'on'</span>) |
---|
397 | 0265 <span class="keyword">end</span> |
---|
398 | 0266 <span class="keyword">end</span> |
---|
399 | 0267 <span class="keyword">if</span> (i == get(hand.hEdits(hand.NumRows,1),<span class="string">'UserData'</span>)) <span class="comment">% Bottom reached. Jump to there</span> |
---|
400 | 0268 val = 1; set(hand.hSlid,<span class="string">'Value'</span>,val) <span class="comment">% This also avoids useless UIs repositioning</span> |
---|
401 | 0269 <span class="keyword">end</span> |
---|
402 | 0270 <span class="keyword">elseif</span> (ds > 0) <span class="comment">% Slider moved up</span> |
---|
403 | 0271 n = hand.NumRows - val + 1; k = hand.MAX_ROWS; |
---|
404 | 0272 <span class="keyword">if</span> (n < hand.MAX_ROWS) <span class="comment">% Case we jumped into the midle zone</span> |
---|
405 | 0273 adj = (hand.MAX_ROWS - n - 0); |
---|
406 | 0274 n = n + adj; |
---|
407 | 0275 <span class="keyword">end</span> |
---|
408 | 0276 <span class="keyword">for</span> (i = n:-1:max(n-hand.MAX_ROWS+1,1)) <span class="comment">% Update positions</span> |
---|
409 | 0277 <span class="keyword">for</span> (j = 1:hand.NumCol) |
---|
410 | 0278 pos = hand.Edits_pos_orig{i,j}; |
---|
411 | 0279 set(hand.hEdits(i,j),<span class="string">'pos'</span>,[pos(1) hand.arr_pos_y(k) pos(3:4)],<span class="string">'Visible'</span>,<span class="string">'on'</span>) |
---|
412 | 0280 <span class="keyword">end</span> |
---|
413 | 0281 <span class="keyword">if</span> (~isempty(hand.checks)) <span class="comment">% If we have checkboxes</span> |
---|
414 | 0282 pos = hand.Checks_pos_orig(i,:); |
---|
415 | 0283 set(hand.hChecks(i),<span class="string">'pos'</span>,[pos(1) hand.arr_pos_y(k)+3 pos(3:4)],<span class="string">'Visible'</span>,<span class="string">'on'</span>) |
---|
416 | 0284 <span class="keyword">end</span> |
---|
417 | 0285 k = k - 1; |
---|
418 | 0286 <span class="keyword">end</span> |
---|
419 | 0287 set(hand.hEdits(n+1:<span class="keyword">end</span>,1:end),<span class="string">'Visible'</span>,<span class="string">'off'</span>) |
---|
420 | 0288 <span class="keyword">if</span> (~isempty(hand.checks)), set(hand.hChecks(n+1:end),<span class="string">'Visible'</span>,<span class="string">'off'</span>); <span class="keyword">end</span> |
---|
421 | 0289 <span class="keyword">if</span> (i == get(hand.hEdits(1,1),<span class="string">'UserData'</span>)) <span class="comment">% Reached Top. Jump to there</span> |
---|
422 | 0290 set(hand.hSlid,<span class="string">'Value'</span>,hand.NumRows) <span class="comment">% This also avoids useless UIs repositioning</span> |
---|
423 | 0291 val = hand.NumRows; |
---|
424 | 0292 <span class="keyword">end</span> |
---|
425 | 0293 <span class="keyword">end</span> |
---|
426 | 0294 set(hand.hSlid,<span class="string">'UserData'</span>,val) <span class="comment">% Save old 'Value'</span> |
---|
427 | 0295 |
---|
428 | 0296 <span class="comment">% ----------------------------------------------------------------------------</span> |
---|
429 | 0297 <a name="_sub2" href="#_subfunctions" class="code">function params = parse_pv_pairs(params,pv_pairs)</a> |
---|
430 | 0298 <span class="comment">% parse_pv_pairs: parses sets of property value pairs, allows defaults</span> |
---|
431 | 0299 <span class="comment">% usage: params=parse_pv_pairs(default_params,pv_pairs)</span> |
---|
432 | 0300 <span class="comment">%</span> |
---|
433 | 0301 <span class="comment">% arguments: (input)</span> |
---|
434 | 0302 <span class="comment">% default_params - structure, with one field for every potential</span> |
---|
435 | 0303 <span class="comment">% property/value pair. Each field will contain the default</span> |
---|
436 | 0304 <span class="comment">% value for that property. If no default is supplied for a</span> |
---|
437 | 0305 <span class="comment">% given property, then that field must be empty.</span> |
---|
438 | 0306 <span class="comment">%</span> |
---|
439 | 0307 <span class="comment">% pv_array - cell array of property/value pairs.</span> |
---|
440 | 0308 <span class="comment">% Case is ignored when comparing properties to the list</span> |
---|
441 | 0309 <span class="comment">% of field names. Also, any unambiguous shortening of a</span> |
---|
442 | 0310 <span class="comment">% field/property name is allowed.</span> |
---|
443 | 0311 <span class="comment">%</span> |
---|
444 | 0312 <span class="comment">% arguments: (output)</span> |
---|
445 | 0313 <span class="comment">% params - parameter struct that reflects any updated property/value</span> |
---|
446 | 0314 <span class="comment">% pairs in the pv_array.</span> |
---|
447 | 0315 <span class="comment">%</span> |
---|
448 | 0316 <span class="comment">% Example usage:</span> |
---|
449 | 0317 <span class="comment">% First, set default values for the parameters. Assume we have four</span> |
---|
450 | 0318 <span class="comment">% parameters that we wish to use optionally in the function examplefun.</span> |
---|
451 | 0319 <span class="comment">%</span> |
---|
452 | 0320 <span class="comment">% - 'viscosity', which will have a default value of 1</span> |
---|
453 | 0321 <span class="comment">% - 'volume', which will default to 1</span> |
---|
454 | 0322 <span class="comment">% - 'pie' - which will have default value 3.141592653589793</span> |
---|
455 | 0323 <span class="comment">% - 'description' - a text field, left empty by default</span> |
---|
456 | 0324 <span class="comment">%</span> |
---|
457 | 0325 <span class="comment">% The first argument to examplefun is one which will always be supplied.</span> |
---|
458 | 0326 <span class="comment">%</span> |
---|
459 | 0327 <span class="comment">% function examplefun(dummyarg1,varargin)</span> |
---|
460 | 0328 <span class="comment">% params.Viscosity = 1;</span> |
---|
461 | 0329 <span class="comment">% params.Volume = 1;</span> |
---|
462 | 0330 <span class="comment">% params.Pie = 3.141592653589793</span> |
---|
463 | 0331 <span class="comment">%</span> |
---|
464 | 0332 <span class="comment">% params.Description = '';</span> |
---|
465 | 0333 <span class="comment">% params=parse_pv_pairs(params,varargin);</span> |
---|
466 | 0334 <span class="comment">% params</span> |
---|
467 | 0335 <span class="comment">%</span> |
---|
468 | 0336 <span class="comment">% Use examplefun, overriding the defaults for 'pie', 'viscosity'</span> |
---|
469 | 0337 <span class="comment">% and 'description'. The 'volume' parameter is left at its default.</span> |
---|
470 | 0338 <span class="comment">%</span> |
---|
471 | 0339 <span class="comment">% examplefun(rand(10),'vis',10,'pie',3,'Description','Hello world')</span> |
---|
472 | 0340 <span class="comment">%</span> |
---|
473 | 0341 <span class="comment">% params =</span> |
---|
474 | 0342 <span class="comment">% Viscosity: 10</span> |
---|
475 | 0343 <span class="comment">% Volume: 1</span> |
---|
476 | 0344 <span class="comment">% Pie: 3</span> |
---|
477 | 0345 <span class="comment">% Description: 'Hello world'</span> |
---|
478 | 0346 <span class="comment">%</span> |
---|
479 | 0347 <span class="comment">% Note that capitalization was ignored, and the property 'viscosity' was truncated</span> |
---|
480 | 0348 <span class="comment">% as supplied. Also note that the order the pairs were supplied was arbitrary.</span> |
---|
481 | 0349 |
---|
482 | 0350 n = length(pv_pairs) / 2; |
---|
483 | 0351 |
---|
484 | 0352 <span class="keyword">if</span> n ~= floor(n) |
---|
485 | 0353 error <span class="string">'Property/value pairs must come in PAIRS.'</span> |
---|
486 | 0354 <span class="keyword">end</span> |
---|
487 | 0355 <span class="keyword">if</span> (n <= 0), <span class="keyword">return</span>; <span class="keyword">end</span> <span class="comment">% just return the defaults</span> |
---|
488 | 0356 |
---|
489 | 0357 <span class="keyword">if</span> ~isstruct(params) |
---|
490 | 0358 error <span class="string">'No structure for defaults was supplied'</span> |
---|
491 | 0359 <span class="keyword">end</span> |
---|
492 | 0360 |
---|
493 | 0361 <span class="comment">% there was at least one pv pair. process any supplied</span> |
---|
494 | 0362 propnames = fieldnames(params); |
---|
495 | 0363 lpropnames = lower(propnames); |
---|
496 | 0364 <span class="keyword">for</span> i=1:n |
---|
497 | 0365 p_i = lower(pv_pairs{2*i-1}); |
---|
498 | 0366 v_i = pv_pairs{2*i}; |
---|
499 | 0367 |
---|
500 | 0368 ind = strmatch(p_i,lpropnames,<span class="string">'exact'</span>); |
---|
501 | 0369 <span class="keyword">if</span> isempty(ind) |
---|
502 | 0370 ind = find(strncmp(p_i,lpropnames,length(p_i))); |
---|
503 | 0371 <span class="keyword">if</span> isempty(ind) |
---|
504 | 0372 error([<span class="string">'No matching property found for: '</span>,pv_pairs{2*i-1}]) |
---|
505 | 0373 <span class="keyword">elseif</span> (length(ind) > 1) |
---|
506 | 0374 error([<span class="string">'Ambiguous property name: '</span>,pv_pairs{2*i-1}]) |
---|
507 | 0375 <span class="keyword">end</span> |
---|
508 | 0376 <span class="keyword">end</span> |
---|
509 | 0377 p_i = propnames{ind}; |
---|
510 | 0378 params = setfield(params,p_i,v_i); <span class="comment">% override the corresponding default in params</span> |
---|
511 | 0379 <span class="keyword">end</span></pre></div> |
---|
512 | <hr><address>Generated on Mon 21-May-2007 15:32:41 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address> |
---|
513 | </body> |
---|
514 | </html> |
---|