source: MML/trunk/applications/doc_html/applications/common/tablegui.html @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 40.5 KB
Line 
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 &copy; 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> &gt;  <a href="#">applications</a> &gt; <a href="index.html">common</a> &gt; tablegui.m</div>
16
17<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
18<td align="right"><a href="index.html">Index for applications/common&nbsp;<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 &gt; 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       &quot;Registering an Aerial Photo to an Orthophoto&quot;
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>
121This function calls:
122<ul style="list-style-image:url(../../matlabicon.gif)">
123</ul>
124This 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>
1340002 <span class="comment">%   TABLEGUI - Spreadsheet like display and edition of a generic 2D array. By generic it is</span>
1350003 <span class="comment">%   mean that the array can be a numeric MxN matrix or a MxN cell array (with mixed</span>
1360004 <span class="comment">%   number and text strings). This function imitates the table cells with edit boxes</span>
1370005 <span class="comment">%   which may become slow if the number of elements required is large. However, it</span>
1380006 <span class="comment">%   works fast for small matrices. If the default number of rows is exceeded a vertical</span>
1390007 <span class="comment">%   slider is created. The slider works by changing the position of the table elements,</span>
1400008 <span class="comment">%   which again may become slow if the default number of visible rows is large. Otherwise</span>
1410009 <span class="comment">%   it works pretty fast.</span>
1420010 <span class="comment">%</span>
1430011 <span class="comment">%   USAGE:</span>
1440012 <span class="comment">%       OUT = TABLEGUI(varargin)</span>
1450013 <span class="comment">%</span>
1460014 <span class="comment">%   Inputs are in property/value pairs. All properties are strings but the values are</span>
1470015 <span class="comment">%   of different types depending on the case.</span>
1480016 <span class="comment">%</span>
1490017 <span class="comment">%   PROPERTY                        VALUE                                       TYPE</span>
1500018 <span class="comment">%</span>
1510019 <span class="comment">%   'array'         It can be either an numeric matrix or a MxN                 numeric or cell array</span>
1520020 <span class="comment">%                   cell array.</span>
1530021 <span class="comment">%   'NumRows'       Total number of rows to create. Use this when the           integer</span>
1540022 <span class="comment">%                   'array' option is not used, or when you want to</span>
1550023 <span class="comment">%                   create extra empty rows.</span>
1560024 <span class="comment">%   'NumCol'        Total number of columns to create. Use this when            integer</span>
1570025 <span class="comment">%                   the 'array' option is not used, but ignored if it was.</span>
1580026 <span class="comment">%   'MAX_ROWS'      Number of visible rows. If NumRows &gt; MAX_ROWS               integer</span>
1590027 <span class="comment">%                   a vertical slider is created (DEF = 10)</span>
1600028 <span class="comment">%   'RowHeight'     editboxes height in pixels (DEF = 20)                       integer</span>
1610029 <span class="comment">%   'ColWidth'      editboxes width in pixels (DEF = 60)                        scalar or row vector</span>
1620030 <span class="comment">%                   If a vector is transmited, it must contains NumCol</span>
1630031 <span class="comment">%                   elements which set individual column widths.</span>
1640032 <span class="comment">%   'bd_size'       space between editboxes width in pixels (DEF = 0)           integer</span>
1650033 <span class="comment">%   'HorAlin'       editboxes 'HorizontalAlignment' property. It can            string</span>
1660034 <span class="comment">%                   be either 'left', 'center' or 'right' (DEF = 'center')</span>
1670035 <span class="comment">%   'HdrButtons'    create a first row of buttons to hold column                string - either '' or 'y'</span>
1680036 <span class="comment">%                   names. Give an empty string ('') if you don't want</span>
1690037 <span class="comment">%                   column names (DEF = 'Y').</span>
1700038 <span class="comment">%   'ColNames'      Cell array of strings for column names. If not              1xN cell array of strings</span>
1710039 <span class="comment">%                   provided the columns are named 'A', 'B', ...</span>
1720040 <span class="comment">%   'RowNumbers'    Add a first column with row numbers. Note that this         string - either '' or 'y'</span>
1730041 <span class="comment">%                   column is set to 'inactive' and its not transmited</span>
1740042 <span class="comment">%                   on the output (DEF = '').</span>
1750043 <span class="comment">%   'checks'        If = 'Y' it creates a vertical line of checkboxes           string - either '' or 'y'</span>
1760044 <span class="comment">%                   This affects what is send as output. Only rows that</span>
1770045 <span class="comment">%                   have it's checkbox checked will be returned.</span>
1780046 <span class="comment">%   'FigName'       Name that appears in the title bar (DEF = 'Table').         string</span>
1790047 <span class="comment">%   'position'      Screen location to be used in the call to MOVEGUI           string</span>
1800048 <span class="comment">%                   See doc of that function for valid position</span>
1810049 <span class="comment">%                   strings (DEF = 'east').</span>
1820050 <span class="comment">%   'modal'         By default the window works in MODAL mode. Give an          string - either '' or 'y'</span>
1830051 <span class="comment">%                   empty string ('') if you don't want it to be MODAL.</span>
1840052 <span class="comment">%                   In this later case the output OUT, if requested, will</span>
1850053 <span class="comment">%                   contain the figure handle but see more about this below.</span>
1860054 <span class="comment">%</span>
1870055 <span class="comment">%   OUT - the output - contains different things depending whether or not the</span>
1880056 <span class="comment">%       figure works in MODAL mode. If yes, OUT is a MxN cell array with the</span>
1890057 <span class="comment">%       elements retrived from the contents of the edit boxes. Otherwise, OUT</span>
1900058 <span class="comment">%       will contain the figure's handle. This handle has the 'UserData' property</span>
1910059 <span class="comment">%       filled with a structure (called hand) which contains the handles of all</span>
1920060 <span class="comment">%       uicontrols. Use this option if you want to interact with the TABLEGUI</span>
1930061 <span class="comment">%       figure inside your own code.</span>
1940062 <span class="comment">%</span>
1950063 <span class="comment">%   Examples:</span>
1960064 <span class="comment">%     - Display a 12x6 numeric matrix with two extra blank rows appended to the end</span>
1970065 <span class="comment">%       out = tableGUI('array',rand(12,6),'ColNames',{'1' '2' '3' '4' '5' '6'},'NumRows',14);</span>
1980066 <span class="comment">%</span>
1990067 <span class="comment">%     - Create a cell array with the first column filled with the row number and use</span>
2000068 <span class="comment">%       columns with different widths. Create also check boxes.</span>
2010069 <span class="comment">%       zz=cell(4,5);   zz(:,1) = num2cell(1:4)';</span>
2020070 <span class="comment">%       out = tableGUI('array',zz,'ColNames',{'N','A','B','C','D'},'ColWidth',[20 60 60 60 60],'checks','y');</span>
2030071 <span class="comment">%</span>
2040072 <span class="comment">%     - Create a similar table as in the previous example but with the row numbers option.</span>
2050073 <span class="comment">%       out = tableGUI('array',cell(4,5),'RowNumbers','y','checks','y');</span>
2060074 <span class="comment">%</span>
2070075 <span class="comment">%     - Display the Control Points of the Image Processing Toolbox example</span>
2080076 <span class="comment">%       &quot;Registering an Aerial Photo to an Orthophoto&quot;</span>
2090077 <span class="comment">%       load westconcordpoints  % load some points that were already picked</span>
2100078 <span class="comment">%       gcp = [base_points input_points];</span>
2110079 <span class="comment">%       out = tableGUI('array',gcp,'RowNumbers','y','ColNames',{'Base Points - X','Base Points - Y',...</span>
2120080 <span class="comment">%               'Input Points - X','Input Points - Y'},'ColWidth',110,'FigName','GCP Table');</span>
2130081 <span class="comment">%</span>
2140082 <span class="comment">%     - Create an empty 12x6 empty table</span>
2150083 <span class="comment">%       out = tableGUI;</span>
2160084 <span class="comment">%</span>
2170085 <span class="comment">%   Acknowledgment</span>
2180086 <span class="comment">%       This function uses the parse_pv_pairs of John d'Errico</span>
2190087 <span class="comment">%</span>
2200088 <span class="comment">%   AUTHOR</span>
2210089 <span class="comment">%       Joaquim Luis (jluis@ualg.pt)   17-Feb-2006</span>
2220090
2230091 hand.NumRows = 12;          hand.NumCol = 6;
2240092 hand.MAX_ROWS = 10;         hand.left_marg = 10;
2250093 hand.RowHeight = 20;        hand.bd_size = 0;
2260094 hand.checks = <span class="string">''</span>;           hand.HdrButtons = <span class="string">'Y'</span>;
2270095 hand.HorAlin = <span class="string">'center'</span>;    hand.FigName = <span class="string">'Table'</span>;
2280096 hand.array = cell(hand.NumRows,hand.NumCol);
2290097 hand.modal = <span class="string">'y'</span>;           hand.position = <span class="string">'east'</span>;
2300098 hand.RowNumbers = <span class="string">''</span>;       d_col = 0;
2310099
2320100 <span class="keyword">if</span> (nargin == 0)        <span class="comment">% Demo</span>
2330101     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>};
2340102     hand.ColWidth = [50 80 80 80 80 50];
2350103 <span class="keyword">else</span>
2360104     hand.ColNames = <span class="string">''</span>;        hand.ColWidth = [];
2370105     hand.array = [];        def_NumRows = hand.NumRows;
2380106     hand = <a href="#_sub2" class="code" title="subfunction params = parse_pv_pairs(params,pv_pairs)">parse_pv_pairs</a>(hand,varargin);
2390107     <span class="keyword">if</span> (~isempty(hand.array))
2400108         <span class="keyword">if</span> (numel(hand.array) == 1 &amp;&amp; numel(hand.array{1}) ~= 1)
2410109             error(<span class="string">'The &quot;array&quot; argument must be a MxN cell array and not a {MxN} cell'</span>)
2420110         <span class="keyword">end</span>
2430111         [NumRows,hand.NumCol] = size(hand.array);
2440112         <span class="keyword">if</span> (~iscell(hand.array))    <span class="comment">% We need as a cell array to be more general</span>
2450113             hand.array = num2cell(hand.array);
2460114         <span class="keyword">end</span>
2470115         <span class="keyword">if</span> (NumRows &lt; hand.NumRows &amp;&amp; hand.NumRows ~= def_NumRows)     <span class="comment">% Extra rows requested</span>
2480116             hand.array = [hand.array; cell(hand.NumRows-NumRows,hand.NumCol)];
2490117         <span class="keyword">else</span>
2500118             hand.NumRows = NumRows;
2510119         <span class="keyword">end</span>
2520120         <span class="keyword">if</span> (hand.NumRows &lt; hand.MAX_ROWS),    hand.MAX_ROWS = hand.NumRows;     <span class="keyword">end</span>
2530121         
2540122     <span class="keyword">else</span>                <span class="comment">% 'array' not transmited</span>
2550123         hand.array = cell(hand.NumRows,hand.NumCol);
2560124     <span class="keyword">end</span>
2570125     
2580126     <span class="keyword">if</span> (isempty(hand.ColNames) &amp;&amp; ~isempty(hand.HdrButtons))      <span class="comment">% By default columns are labeled 'A','B',...</span>
2590127         hand.ColNames = cell(1,hand.NumCol);
2600128         <span class="keyword">for</span> (i = 1:hand.NumCol),     hand.ColNames{1,i} = char(i+64);  <span class="keyword">end</span>
2610129     <span class="keyword">end</span>
2620130     <span class="keyword">if</span> (size(hand.array,2) &gt; size(hand.ColNames,2))
2630131         error(<span class="string">'&quot;ColNames&quot; argument has less elements than the number of columns is &quot;array&quot;'</span>)
2640132     <span class="keyword">end</span>
2650133     <span class="keyword">if</span> (isempty(hand.ColWidth))                    <span class="comment">% Use default value for button width</span>
2660134         hand.ColWidth = repmat(60,1,hand.NumCol);
2670135     <span class="keyword">elseif</span> (numel(hand.ColWidth) == 1)             <span class="comment">% 'ColWidth' was a scalar</span>
2680136         hand.ColWidth = repmat(hand.ColWidth,1,hand.NumCol);
2690137     <span class="keyword">end</span>
2700138     
2710139     <span class="keyword">if</span> (~isempty(hand.RowNumbers))                 <span class="comment">% Row numbering was requested</span>
2720140         hand.ColWidth = [35 hand.ColWidth];
2730141         hand.NumCol = hand.NumCol + 1;
2740142         hand.array = [cell(hand.NumRows,1) hand.array];
2750143         d_col = 1;
2760144     <span class="keyword">end</span>
2770145 <span class="keyword">end</span>
2780146
2790147 arr_pos_xi = [hand.left_marg + [0 (cumsum(hand.ColWidth+hand.bd_size))]];
2800148 arr_pos_xi(end) = [];      <span class="comment">% We don't want the last element</span>
2810149 arr_pos_xw = hand.ColWidth;
2820150
2830151 <span class="comment">% ---------------- Create the figure ----------------------------------</span>
2840152 fig_height = min(hand.NumRows,hand.MAX_ROWS) * (hand.RowHeight+hand.bd_size);
2850153 <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>
2860154 <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>
2870155 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>
2880156 <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>
2890157 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>
2900158     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>);
2910159 movegui(hand.hFig,hand.position)
2920160
2930161 hand.arr_pos_y = (fig_height-hand.RowHeight-hand.bd_size - (0:hand.NumRows-1)*(hand.RowHeight+hand.bd_size))';
2940162 <span class="keyword">if</span> (~isempty(hand.HdrButtons)),     hand.arr_pos_y = hand.arr_pos_y - 22;   <span class="keyword">end</span>
2950163
2960164 <span class="keyword">if</span> (~isempty(hand.checks))              <span class="comment">% Create the checkboxes uicontrols</span>
2970165     arr_pos_xi = arr_pos_xi + 15;       <span class="comment">% Make room for them</span>
2980166     hand.hChecks = zeros(hand.NumRows,1);
2990167     hand.Checks_pos_orig = [ones(hand.NumRows,1)*7 (hand.arr_pos_y+3) ones(hand.NumRows,1)*15 ones(hand.NumRows,1)*15];
3000168 <span class="keyword">end</span>
3010169 hand.hEdits = zeros(hand.NumRows,hand.NumCol);
3020170 hand.Edits_pos_orig = cell(hand.NumRows,hand.NumCol);
3030171
3040172 <span class="comment">% ---------------- Create the edit uicontrols ---------------------------</span>
3050173 <span class="keyword">for</span> (i = 1:hand.NumRows)
3060174     <span class="keyword">if</span> (~isempty(hand.checks))
3070175         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>
3080176             hand.Checks_pos_orig(i,:),<span class="string">'Value'</span>,1);
3090177     <span class="keyword">end</span>
3100178     <span class="keyword">for</span> (j = 1:hand.NumCol)
3110179         hand.Edits_pos_orig{i,j} = [arr_pos_xi(j) hand.arr_pos_y(i) arr_pos_xw(j) 20];
3120180         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>
3130181             [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>
3140182             <span class="string">'HorizontalAlignment'</span>,hand.HorAlin);
3150183     <span class="keyword">end</span>
3160184     <span class="keyword">if</span> (~isempty(hand.RowNumbers))
3170185         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)
3180186     <span class="keyword">else</span>
3190187         set(hand.hEdits(i,1),<span class="string">'UserData'</span>,i)
3200188     <span class="keyword">end</span>
3210189 <span class="keyword">end</span>
3220190 <span class="keyword">if</span> (~isempty(hand.HdrButtons))         <span class="comment">% Create the header pushbutton uicontrols</span>
3230191     <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>
3240192         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>
3250193             [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})
3260194     <span class="keyword">end</span>
3270195 <span class="keyword">end</span>
3280196
3290197 <span class="comment">% ---------------- See if we need a slider ---------------------------</span>
3300198 pos_t = get(hand.hEdits(1,hand.NumCol),<span class="string">'pos'</span>);       <span class="comment">% Get top right edit position</span>
3310199 pos_b = get(hand.hEdits(hand.MAX_ROWS,1),<span class="string">'pos'</span>);    <span class="comment">% Get last visible edit position</span>
3320200 <span class="keyword">if</span> (hand.NumRows &gt; hand.MAX_ROWS)
3330201     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>
3340202     <span class="keyword">if</span> (~isempty(hand.checks))
3350203         set(hand.hChecks(hand.MAX_ROWS+1:hand.NumRows),<span class="string">'Visible'</span>,<span class="string">'off'</span>)
3360204     <span class="keyword">end</span>
3370205     pos = [pos_t(1)+pos_t(3) pos_b(2) 15 pos_t(2)+pos_t(4)-pos_b(2)];
3380206     sld_step = 1 / (hand.NumRows-1);
3390207     sld_step(2) = 5 * sld_step(1);
3400208     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>
3410209         <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);
3420210     set(hand.hSlid,<span class="string">'callback'</span>,{@<a href="#_sub1" class="code" title="subfunction slider_Callback(obj,event,hand)">slider_Callback</a>,hand})
3430211     set(hand.hSlid,<span class="string">'UserData'</span>,hand.NumRows)    <span class="comment">% Store current value</span>
3440212 <span class="keyword">end</span>
3450213
3460214 <span class="comment">% ---------------- See if the window is MODAL ---------------------------</span>
3470215 <span class="keyword">if</span> (~isempty(hand.modal))
3480216     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>
3490217         [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>
3500218         <span class="string">'callback'</span>,<span class="string">'uiresume'</span>,<span class="string">'tag'</span>,<span class="string">'OK'</span>);
3510219     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>
3520220         [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>
3530221         <span class="string">'callback'</span>,<span class="string">'uiresume'</span>,<span class="string">'tag'</span>,<span class="string">'cancel'</span>);
3540222     uiwait(hand.hFig)       <span class="comment">% It also sets the Figure's visibility 'on'</span>
3550223     but = gco;
3560224     <span class="keyword">if</span> strcmp(get(but,<span class="string">'tag'</span>),<span class="string">'OK'</span>)
3570225         out = reshape(get(hand.hEdits,<span class="string">'String'</span>),hand.NumRows,hand.NumCol);
3580226         <span class="keyword">if</span> (~isempty(hand.checks))
3590227             unchecked = (cell2mat(get(hand.hChecks,<span class="string">'Value'</span>)) == 0);
3600228             out(unchecked,:) = [];      <span class="comment">% Remove unchecked rows</span>
3610229         <span class="keyword">end</span>
3620230         <span class="keyword">if</span> (~isempty(hand.RowNumbers)) <span class="comment">% Do not output the row numbers</span>
3630231             out = out(:,2:end);
3640232         <span class="keyword">end</span>
3650233         delete(hand.hFig)
3660234     <span class="keyword">elseif</span> strcmp(get(but,<span class="string">'tag'</span>),<span class="string">'cancel'</span>)
3670235         out = [];   delete(hand.hFig)
3680236     <span class="keyword">else</span>        <span class="comment">% Figure was killed</span>
3690237         out = [];
3700238     <span class="keyword">end</span>
3710239 <span class="keyword">else</span>
3720240     set(hand.hFig,<span class="string">'Visible'</span>,<span class="string">'on'</span>,<span class="string">'UserData'</span>,hand)
3730241     <span class="keyword">if</span> (nargout),   out = hand.hFig;    <span class="keyword">end</span>
3740242 <span class="keyword">end</span>
3750243
3760244 <span class="comment">% ---------------------------------------------------------------------------</span>
3770245 <a name="_sub1" href="#_subfunctions" class="code">function slider_Callback(obj,event,hand)</a>
3780246
3790247 val = round(get(hand.hSlid,<span class="string">'Value'</span>));
3800248 old_val = get(hand.hSlid,<span class="string">'UserData'</span>);
3810249 ds = val - old_val;
3820250
3830251 <span class="keyword">if</span> (ds &lt; 0)                                         <span class="comment">% Slider moved down</span>
3840252     n = hand.NumRows - val + 1;    d_col = hand.NumRows - val;
3850253     <span class="keyword">if</span> (n+hand.MAX_ROWS-1 &gt; hand.NumRows)             <span class="comment">% Case we jumped into the midle zone</span>
3860254         adj = (n+hand.MAX_ROWS-1 - hand.NumRows);
3870255         n = n - adj;    d_col = d_col - adj;
3880256     <span class="keyword">end</span>
3890257     <span class="keyword">for</span> (i = n:min(n+hand.MAX_ROWS-1,hand.NumRows))   <span class="comment">% Update positions</span>
3900258         <span class="keyword">for</span> (j = 1:hand.NumCol)
3910259             pos = hand.Edits_pos_orig{i,j};
3920260             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>)
3930261         <span class="keyword">end</span>
3940262         <span class="keyword">if</span> (~isempty(hand.checks))                  <span class="comment">% If we have checkboxes</span>
3950263             pos = hand.Checks_pos_orig(i,:);
3960264             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>)           
3970265         <span class="keyword">end</span>
3980266     <span class="keyword">end</span>
3990267     <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>
4000268         val = 1;    set(hand.hSlid,<span class="string">'Value'</span>,val)         <span class="comment">% This also avoids useless UIs repositioning</span>
4010269     <span class="keyword">end</span>
4020270 <span class="keyword">elseif</span> (ds &gt; 0)                                     <span class="comment">% Slider moved up</span>
4030271     n = hand.NumRows - val + 1;    k = hand.MAX_ROWS;
4040272     <span class="keyword">if</span> (n &lt; hand.MAX_ROWS)                          <span class="comment">% Case we jumped into the midle zone</span>
4050273         adj = (hand.MAX_ROWS - n - 0);
4060274         n = n + adj;
4070275     <span class="keyword">end</span>
4080276     <span class="keyword">for</span> (i = n:-1:max(n-hand.MAX_ROWS+1,1))         <span class="comment">% Update positions</span>
4090277         <span class="keyword">for</span> (j = 1:hand.NumCol)
4100278             pos = hand.Edits_pos_orig{i,j};
4110279             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>)       
4120280         <span class="keyword">end</span>
4130281         <span class="keyword">if</span> (~isempty(hand.checks))                  <span class="comment">% If we have checkboxes</span>
4140282             pos = hand.Checks_pos_orig(i,:);
4150283             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>)           
4160284         <span class="keyword">end</span>
4170285         k = k - 1;
4180286     <span class="keyword">end</span>
4190287     set(hand.hEdits(n+1:<span class="keyword">end</span>,1:end),<span class="string">'Visible'</span>,<span class="string">'off'</span>)
4200288     <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>
4210289     <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>
4220290         set(hand.hSlid,<span class="string">'Value'</span>,hand.NumRows)          <span class="comment">% This also avoids useless UIs repositioning</span>
4230291         val = hand.NumRows;
4240292     <span class="keyword">end</span>
4250293 <span class="keyword">end</span>
4260294 set(hand.hSlid,<span class="string">'UserData'</span>,val)                      <span class="comment">% Save old 'Value'</span>
4270295
4280296 <span class="comment">% ----------------------------------------------------------------------------</span>
4290297 <a name="_sub2" href="#_subfunctions" class="code">function params = parse_pv_pairs(params,pv_pairs)</a>
4300298 <span class="comment">% parse_pv_pairs: parses sets of property value pairs, allows defaults</span>
4310299 <span class="comment">% usage: params=parse_pv_pairs(default_params,pv_pairs)</span>
4320300 <span class="comment">%</span>
4330301 <span class="comment">% arguments: (input)</span>
4340302 <span class="comment">%  default_params - structure, with one field for every potential</span>
4350303 <span class="comment">%             property/value pair. Each field will contain the default</span>
4360304 <span class="comment">%             value for that property. If no default is supplied for a</span>
4370305 <span class="comment">%             given property, then that field must be empty.</span>
4380306 <span class="comment">%</span>
4390307 <span class="comment">%  pv_array - cell array of property/value pairs.</span>
4400308 <span class="comment">%             Case is ignored when comparing properties to the list</span>
4410309 <span class="comment">%             of field names. Also, any unambiguous shortening of a</span>
4420310 <span class="comment">%             field/property name is allowed.</span>
4430311 <span class="comment">%</span>
4440312 <span class="comment">% arguments: (output)</span>
4450313 <span class="comment">%  params   - parameter struct that reflects any updated property/value</span>
4460314 <span class="comment">%             pairs in the pv_array.</span>
4470315 <span class="comment">%</span>
4480316 <span class="comment">% Example usage:</span>
4490317 <span class="comment">% First, set default values for the parameters. Assume we have four</span>
4500318 <span class="comment">% parameters that we wish to use optionally in the function examplefun.</span>
4510319 <span class="comment">%</span>
4520320 <span class="comment">%  - 'viscosity', which will have a default value of 1</span>
4530321 <span class="comment">%  - 'volume', which will default to 1</span>
4540322 <span class="comment">%  - 'pie' - which will have default value 3.141592653589793</span>
4550323 <span class="comment">%  - 'description' - a text field, left empty by default</span>
4560324 <span class="comment">%</span>
4570325 <span class="comment">% The first argument to examplefun is one which will always be supplied.</span>
4580326 <span class="comment">%</span>
4590327 <span class="comment">%   function examplefun(dummyarg1,varargin)</span>
4600328 <span class="comment">%   params.Viscosity = 1;</span>
4610329 <span class="comment">%   params.Volume = 1;</span>
4620330 <span class="comment">%   params.Pie = 3.141592653589793</span>
4630331 <span class="comment">%</span>
4640332 <span class="comment">%   params.Description = '';</span>
4650333 <span class="comment">%   params=parse_pv_pairs(params,varargin);</span>
4660334 <span class="comment">%   params</span>
4670335 <span class="comment">%</span>
4680336 <span class="comment">% Use examplefun, overriding the defaults for 'pie', 'viscosity'</span>
4690337 <span class="comment">% and 'description'. The 'volume' parameter is left at its default.</span>
4700338 <span class="comment">%</span>
4710339 <span class="comment">%   examplefun(rand(10),'vis',10,'pie',3,'Description','Hello world')</span>
4720340 <span class="comment">%</span>
4730341 <span class="comment">% params =</span>
4740342 <span class="comment">%     Viscosity: 10</span>
4750343 <span class="comment">%        Volume: 1</span>
4760344 <span class="comment">%           Pie: 3</span>
4770345 <span class="comment">%   Description: 'Hello world'</span>
4780346 <span class="comment">%</span>
4790347 <span class="comment">% Note that capitalization was ignored, and the property 'viscosity' was truncated</span>
4800348 <span class="comment">% as supplied. Also note that the order the pairs were supplied was arbitrary.</span>
4810349
4820350 n = length(pv_pairs) / 2;
4830351
4840352 <span class="keyword">if</span> n ~= floor(n)
4850353     error <span class="string">'Property/value pairs must come in PAIRS.'</span>
4860354 <span class="keyword">end</span>
4870355 <span class="keyword">if</span> (n &lt;= 0),    <span class="keyword">return</span>;     <span class="keyword">end</span>     <span class="comment">% just return the defaults</span>
4880356
4890357 <span class="keyword">if</span> ~isstruct(params)
4900358     error <span class="string">'No structure for defaults was supplied'</span>
4910359 <span class="keyword">end</span>
4920360
4930361 <span class="comment">% there was at least one pv pair. process any supplied</span>
4940362 propnames = fieldnames(params);
4950363 lpropnames = lower(propnames);
4960364 <span class="keyword">for</span> i=1:n
4970365     p_i = lower(pv_pairs{2*i-1});
4980366     v_i = pv_pairs{2*i};
4990367     
5000368     ind = strmatch(p_i,lpropnames,<span class="string">'exact'</span>);
5010369     <span class="keyword">if</span> isempty(ind)
5020370         ind = find(strncmp(p_i,lpropnames,length(p_i)));
5030371         <span class="keyword">if</span> isempty(ind)
5040372             error([<span class="string">'No matching property found for: '</span>,pv_pairs{2*i-1}])
5050373         <span class="keyword">elseif</span> (length(ind) &gt; 1)
5060374             error([<span class="string">'Ambiguous property name: '</span>,pv_pairs{2*i-1}])
5070375         <span class="keyword">end</span>
5080376     <span class="keyword">end</span>
5090377     p_i = propnames{ind};
5100378     params = setfield(params,p_i,v_i);      <span class="comment">% override the corresponding default in params</span>
5110379 <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> &copy; 2003</address>
513</body>
514</html>
Note: See TracBrowser for help on using the repository browser.