From: <prn...@us...> - 2012-06-29 16:41:08
|
Revision: 10708 http://octave.svn.sourceforge.net/octave/?rev=10708&view=rev Author: prnienhuis Date: 2012-06-29 16:40:57 +0000 (Fri, 29 Jun 2012) Log Message: ----------- More input validation and (ML compatible) allowing cellstr arrays to specify multi-line messages Modified Paths: -------------- trunk/octave-forge/extra/java/inst/errordlg.m trunk/octave-forge/extra/java/inst/helpdlg.m trunk/octave-forge/extra/java/inst/inputdlg.m trunk/octave-forge/extra/java/inst/msgbox.m trunk/octave-forge/extra/java/inst/questdlg.m trunk/octave-forge/extra/java/inst/warndlg.m Modified: trunk/octave-forge/extra/java/inst/errordlg.m =================================================================== --- trunk/octave-forge/extra/java/inst/errordlg.m 2012-06-29 16:39:30 UTC (rev 10707) +++ trunk/octave-forge/extra/java/inst/errordlg.m 2012-06-29 16:40:57 UTC (rev 10708) @@ -17,21 +17,34 @@ ## @deftypefn {Function file} {@var{P} =} errordlg (@var{MESSAGE} [,@var{TITLE}]) ## ## Displays the @var{MESSAGE} using an error dialog box. -## The @var{TITLE} can be used optionally to decorate the dialog caption. +## @var{TITLE} (character string or cell string array for multi-line text) can +## be used optionally to decorate the dialog caption. ## The return value is always 1. ## ## @end deftypefn ## @seealso{helpdlg, inputdlg, listdlg, questdlg, warndlg} -function ret = errordlg(message,varargin) - +function ret = errordlg (message, varargin) + + if (! ischar (message)) + if (iscell (message)) + message = cell2mlstr (message); + else + error ("errordlg: character string or cellstr array expected for message"); + endif + endif + switch length (varargin) case 0 - title = "Error Dialog"; + title = "Error Dialog"; otherwise - title = varargin{1}; + title = varargin{1}; endswitch + if (! ischar (title)) + error ("errordlg: character string expected for title"); + endif + ret = java_invoke ("org.octave.JDialogBox", "errordlg", message, title); endfunction Modified: trunk/octave-forge/extra/java/inst/helpdlg.m =================================================================== --- trunk/octave-forge/extra/java/inst/helpdlg.m 2012-06-29 16:39:30 UTC (rev 10707) +++ trunk/octave-forge/extra/java/inst/helpdlg.m 2012-06-29 16:40:57 UTC (rev 10708) @@ -16,23 +16,42 @@ ## -*- texinfo -*- ## @deftypefn {Function file} {@var{P} =} helpdlg (@var{MESSAGE} [,@var{TITLE}]) ## -## Displays a @var{MESSAGE} in a help dialog box. -## The help message can have multiple lines, separated by a newline character '\n'. -## The @var{TITLE} can be used optionally to decorate the dialog caption. +## Displays a @var{MESSAGE} in a help dialog box. +## +## @var{message} can have multiple lines separated by newline characters +## ("\n"), or it can be a cellstr array (one element for each line). +## The optional @var{TITLE} (character string) can be used to decorate the +## dialog caption. ## The return value is always 1. ## ## @end deftypefn ## @seealso{errordlg, inputdlg, listdlg, questdlg, warndlg} -function ret = helpdlg(message,varargin) +function ret = helpdlg (message, varargin) + + if (! ischar (message)) + if (iscell (message)) + message = cell2mlstr (message); + else + error ("helpdlg: character string or cellstr array expected for message"); + endif + endif switch length (varargin) case 0 title = "Help Dialog"; otherwise - title = varargin{1}; + if (ischar (varargin {1})) + title = varargin{1}; + else + error ("helpdlg: character string expected for title"); + endif endswitch + if (! ischar (title)) + error ("helpdlg: character string expected for title"); + endif + ret = java_invoke ("org.octave.JDialogBox", "helpdlg", message, title); endfunction Modified: trunk/octave-forge/extra/java/inst/inputdlg.m =================================================================== --- trunk/octave-forge/extra/java/inst/inputdlg.m 2012-06-29 16:39:30 UTC (rev 10707) +++ trunk/octave-forge/extra/java/inst/inputdlg.m 2012-06-29 16:40:57 UTC (rev 10708) @@ -39,27 +39,39 @@ ## @end deftypefn ## @seealso{errordlg, helpdlg, listdlg, questdlg, warndlg} -function varargout = inputdlg(prompt,varargin) - +function varargout = inputdlg (prompt, varargin) + + if (iscell (prompt)) + % Silently extract only char elements + prompt = prompt (find (cellfun ("ischar", prompt))); + elseif (ischar (prompt)) + prompt = {prompt}; + else + error ("inputdlg: character string or cellstr array expected for prompt"); + endif + switch length (varargin) case 0 title = "Input Dialog"; lineNo = 1; - defaults = cellstr(cell(size(prompt))); + defaults = cellstr (cell( size (prompt))); case 1 title = varargin{1}; lineNo = 1; - defaults = cellstr(cell(size(prompt))); + defaults = cellstr (cell (size (prompt))); case 2 title = varargin{1}; lineNo = varargin{2}; - defaults = cellstr(cell(size(prompt))); + defaults = cellstr (cell (size (prompt))); otherwise title = varargin{1}; lineNo = varargin{2}; defaults = varargin{3}; end + 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... Modified: trunk/octave-forge/extra/java/inst/msgbox.m =================================================================== --- trunk/octave-forge/extra/java/inst/msgbox.m 2012-06-29 16:39:30 UTC (rev 10707) +++ trunk/octave-forge/extra/java/inst/msgbox.m 2012-06-29 16:40:57 UTC (rev 10708) @@ -17,7 +17,11 @@ ## @deftypefn {Function file} {@var{P} =} msgbox (@var{MESSAGE} [,@var{TITLE} [,@var{ICON}]]) ## ## Displays the @var{MESSAGE} using a message dialog. -## The @var{TITLE} is an optional string, which can be used to decorate the dialog caption. +## +## @var{message} can have multiple lines separated by newline characters +## ("\n"), or it can be a cellstr array (one element for each line). +## The optional @var{TITLE} (character string) can be used to decorate the +## dialog caption. ## The @var{ICON} can be used optionally to select a dialog icon. ## It can be one of @code{'error'}, @code{'help'} or @code{'warn'}. ## The return value is always 1. @@ -25,30 +29,42 @@ ## @end deftypefn ## @seealso{helpdlg, questdlg, warndlg} -function ret = msgbox(message,varargin) +function ret = msgbox (message, varargin) + + if (! ischar (message)) + if (iscell (message)) + message = cell2mlstr (message); + else + error ("msgbox: character string or cellstr array expected for message"); + endif + endif switch length (varargin) - case 0 - title = ""; - dlg = 'emptydlg'; - case 1 - title = varargin{1}; - dlg = 'emptydlg'; - otherwise - % two or more arguments - title = varargin{1}; - icon = varargin{2}; - if strcmp(icon,'error') == 1 - dlg = 'errordlg'; - elseif strcmp(icon,'help') == 1 - dlg = 'helpdlg'; - elseif strcmp(icon,'warn') == 1 - dlg = 'warndlg'; - else + case 0 + title = ""; dlg = 'emptydlg'; - end + case 1 + title = varargin{1}; + dlg = 'emptydlg'; + otherwise + % two or more arguments + title = varargin{1}; + icon = varargin{2}; + if strcmp (icon,'error') == 1 + dlg = 'errordlg'; + elseif strcmp (icon,'help') == 1 + dlg = 'helpdlg'; + elseif strcmp (icon,'warn') == 1 + dlg = 'warndlg'; + else + dlg = 'emptydlg'; + end endswitch + if (! ischar (title)) + error ("questdlg: character string expected for title"); + endif + ret = java_invoke ('org.octave.JDialogBox', dlg, message, title ); endfunction Modified: trunk/octave-forge/extra/java/inst/questdlg.m =================================================================== --- trunk/octave-forge/extra/java/inst/questdlg.m 2012-06-29 16:39:30 UTC (rev 10707) +++ trunk/octave-forge/extra/java/inst/questdlg.m 2012-06-29 16:40:57 UTC (rev 10708) @@ -23,7 +23,10 @@ ## The dialog contains two or three buttons which all close the dialog. ## It returns the caption of the activated button. ## -## The @var{TITLE} can be used optionally to decorate the dialog caption. +## @var{message} can have multiple lines separated by newline characters +## ("\n"), or it can be a cellstr array (one element for each line). +## The optional @var{TITLE} (character string) can be used to decorate the +## dialog caption. ## The string @var{DEFAULT} identifies the default button, ## which is activated by pressing the ENTER key. ## It must match one of the strings given in @var{BTN1}, @var{BTN2} or @var{BTN3}. @@ -37,9 +40,9 @@ ## @end deftypefn ## @seealso{errordlg, helpdlg, inputdlg, listdlg, warndlg} -function ret = questdlg(question,varargin) +function ret = questdlg (question, varargin) - if length(varargin) < 1 + if length (varargin) < 1 print_usage(); end @@ -48,8 +51,15 @@ options{3} = 'Cancel'; % button3 options{4} = 'Yes'; % default + if (! ischar (question)) + if (iscell (question)) + question = cell2mlstr (question); + else + error ("questdlg: character string or cellstr array expected for message"); + endif + endif - switch length(varargin) + switch length (varargin) case 1 % title was given title = varargin{1}; @@ -75,6 +85,9 @@ print_usage(); end + if (! ischar (title)) + error ("questdlg: character string expected for title"); + endif ret = java_invoke ('org.octave.JDialogBox', 'questdlg', question, title, options); Modified: trunk/octave-forge/extra/java/inst/warndlg.m =================================================================== --- trunk/octave-forge/extra/java/inst/warndlg.m 2012-06-29 16:39:30 UTC (rev 10707) +++ trunk/octave-forge/extra/java/inst/warndlg.m 2012-06-29 16:40:57 UTC (rev 10708) @@ -15,20 +15,35 @@ ## -*- texinfo -*- ## @deftypefn {Function file} {@var{P} =} warndlg (@var{MESSAGE} [,@var{TITLE}]) -## ## Displays the @var{MESSAGE} using a warning dialog box. -## The @var{TITLE} can be used optionally to decorate the dialog caption. ## +## @var{message} can have multiple lines separated by newline characters +## ("\n"), or it can be a cellstr array (one element for each line). +## The optional @var{TITLE} (character string) can be used to decorate the +## dialog caption. +## ## @end deftypefn ## @seealso{helpdlg, inputdlg, listdlg, questiondlg} -function ret = warndlg(message,varargin) +function ret = warndlg (message, varargin) + + if (! ischar (message)) + if (iscell (message)) + message = cell2mlstr (message); + else + error ("warndlg: character string or cellstr array expected for message"); + endif + endif switch length (varargin) case 0 title = 'Warning Dialog'; otherwise - title = varargin{1}; + if (ischar (varargin{1})) + title = varargin{1}; + else + error ("warndlg: character string expected for title"); + endif endswitch ret = java_invoke ('org.octave.JDialogBox', 'warndlg', message, title); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |