Mercurial > hg > octave-lyh
diff scripts/java/inputdlg.m @ 15748:54e8c2527a9e
style and doc fixes for newly imported Java package .m files
* java/cell2mlstr.m, java/errordlg.m, java/helpdlg.m, java/inputdlg.m,
java/javaArray.m, java/javaaddpath.m, java/javaclasspath.m,
java/javafields.m, java/javamem.m, java/javamethods.m,
java/javarmpath.m, java/listdlg.m, java/msgbox.m java/questdlg.m,
java/warndlg.m: Style and doc fixes.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 07 Dec 2012 17:21:27 -0500 |
parents | da26f72408a7 |
children | 05c781cca57e |
line wrap: on
line diff
--- a/scripts/java/inputdlg.m +++ b/scripts/java/inputdlg.m @@ -17,35 +17,39 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function file} {@var{P} =} inputdlg (@var{PROMPT} [,@var{TITLE} [,@var{ROWSCOLS}, @var{DEFAULTS}]]) +## @deftypefn {Function file} {@var{p} =} inputdlg (@var{prompt}, @var{title}, @var{rowscols}, @var{defaults}) +## Return user input from a multi-textfield dialog box in a cell array +## of strings, or an empty cell array if the dialog is closed by the +## Cancel button. ## -## Returns the user's inputs from a multi-textfield dialog box in form of a cell array of strings. -## If the dialog is closed by the Cancel button, an empty cell array is returned. -## -## @table @samp -## @item PROMPT -## The first argument @var{PROMPT} is mandatory. +## @table @var +## @item prompt +## The first argument @var{prompt} is mandatory. ## It is a cell array with strings labeling each textfield. -## @item TITLE -## The optional string @var{TITLE} can be used as the caption of the dialog. -## @item ROWSCOLS -## The size of the text fields can be defined by the argument @var{ROWSCOLS}, -## which can have three forms: -## - a scalar value which defines the number of rows used for each text field. -## - a vector which defines the individual number of rows used for each text field. -## - a matrix which defines the individual number of rows and columns used for each text field. -## @item DEFAULTS +## @item title +## The optional string @var{title} can be used as the caption of the dialog. +## @item rowscols +## The size of the text fields can be defined by the argument @var{rowscols}, +## which can have three forms: +## @enumerate +## @item a scalar value which defines the number of rows used for each +## text field. +## @item a vector which defines the individual number of rows +## used for each text field. +## @item a matrix which defines the individual number of rows and +## columns used for each text field. +## @end enumerate +## @item defaults ## It is possible to place default values into the text fields by supplying -## the a cell array of strings or number for the argument @var{DEFAULTS}. +## the a cell array of strings or number for the argument @var{defaults}. ## @end table -## +## @seealso{errordlg, helpdlg, listdlg, questdlg, warndlg} ## @end deftypefn -## @seealso{errordlg, helpdlg, listdlg, questdlg, warndlg} -function varargout = inputdlg (prompt, varargin) +function retval = inputdlg (prompt, varargin) if (iscell (prompt)) - % Silently extract only char elements + ## Silently extract only char elements prompt = prompt (find (cellfun ("ischar", prompt))); elseif (ischar (prompt)) prompt = {prompt}; @@ -54,68 +58,71 @@ endif switch length (varargin) - case 0 - title = "Input Dialog"; - lineNo = 1; - defaults = cellstr (cell( size (prompt))); - case 1 - title = varargin{1}; - lineNo = 1; - defaults = cellstr (cell (size (prompt))); - case 2 - title = varargin{1}; - lineNo = varargin{2}; - defaults = cellstr (cell (size (prompt))); - otherwise - title = varargin{1}; - lineNo = varargin{2}; - defaults = varargin{3}; - end + case 0 + title = "Input Dialog"; + lineNo = 1; + defaults = cellstr (cell( size (prompt))); + + case 1 + title = varargin{1}; + lineNo = 1; + defaults = cellstr (cell (size (prompt))); + + case 2 + title = varargin{1}; + lineNo = varargin{2}; + defaults = cellstr (cell (size (prompt))); + + otherwise + title = varargin{1}; + lineNo = varargin{2}; + defaults = varargin{3}; + endswitch if (! ischar (title)) error ("inputdlg: character string expected for title"); endif - % specification of text field sizes as in Matlab - % Matlab requires a matrix for lineNo, not a cell array... - % rc = [1,10; 2,20; 3,30]; - % c1 c2 - % r1 1 10 first text field is 1x10 - % r2 2 20 second text field is 2x20 - % r3 3 30 third text field is 3x30 - if isscalar(lineNo) - % only scalar value in lineTo, copy from lineNo and add defaults + ## specification of text field sizes as in Matlab + ## Matlab requires a matrix for lineNo, not a cell array... + ## rc = [1,10; 2,20; 3,30]; + ## c1 c2 + ## r1 1 10 first text field is 1x10 + ## r2 2 20 second text field is 2x20 + ## r3 3 30 third text field is 3x30 + if (isscalar (lineNo)) + ## only scalar value in lineTo, copy from lineNo and add defaults rowscols = zeros(size(prompt)(2),2); - % cols + ## cols rowscols(:,2) = 25; rowscols(:,1) = lineNo; - elseif isvector(lineNo) - % only one column in lineTo, copy from vector lineNo and add defaults - rowscols = zeros(size(prompt)(2),2); - % rows from colum vector lineNo, columns are set to default + elseif (isvector (lineNo)) + ## only one column in lineTo, copy from vector lineNo and add defaults + rowscols = zeros (columns (prompt), 2); + ## rows from colum vector lineNo, columns are set to default rowscols(:,2) = 25; rowscols(:,1) = lineNo(:); - elseif ismatrix(lineNo) - if (size(lineNo)(1) == size(prompt)(2)) && (size(lineNo)(2) == 2) - % (rows x columns) match, copy array lineNo + elseif (ismatrix (lineNo)) + if (rows (lineNo) == columns (prompt) && columns (lineNo) == 2) + ## (rows x columns) match, copy array lineNo rowscols = lineNo; - end + endif else - % dunno - disp('inputdlg: unknown form of lineNo argument.'); - lineNo - end + ## dunno + error ("inputdlg: unknown form of lineNo argument"); + endif - % convert numeric values in defaults cell array to strings - defs = cellfun(@num2str,defaults,'UniformOutput',false); - rc = arrayfun(@num2str,rowscols,'UniformOutput',false); + ## convert numeric values in defaults cell array to strings + defs = cellfun (@num2str, defaults, "UniformOutput", false); + rc = arrayfun (@num2str, rowscols, "UniformOutput", false); - user_inputs = java_invoke ("org.octave.JDialogBox", "inputdlg", prompt, title, rc, defs); + user_inputs = java_invoke ("org.octave.JDialogBox", "inputdlg", + prompt, title, rc, defs); - if isempty(user_inputs) - varargout{1} = {}; % empty + if (isempty (user_inputs)) + retval = {}; else - varargout{1} = cellstr (user_inputs); - end + retval = cellstr (user_inputs); + endif -end +endfunction