# HG changeset patch # User Rik # Date 1382209550 25200 # Node ID dba2e06dcdb5b92621b35c88c488eed757a8c32c # Parent 1be2993d3656e1cd30799765f2ad06cff72acc9c maint: Move scripts/ui directory into scripts/gui directory. * scripts/gui/errordlg.m, scripts/gui/helpdlg.m, scripts/gui/inputdlg.m, scripts/gui/listdlg.m, scripts/gui/msgbox.m, scripts/gui/private/message_dialog.m, scripts/gui/questdlg.m, scripts/gui/warndlg.m: Moved from scripts/ui directory. * scripts/gui/module.mk: Add scripts to build system. * scripts/Makefile.am: Remove include for ui/module.mk * scripts/ui/module.mk: Remove unused file. diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/Makefile.am --- a/scripts/Makefile.am Sat Oct 19 19:51:23 2013 +0200 +++ b/scripts/Makefile.am Sat Oct 19 12:05:50 2013 -0700 @@ -75,7 +75,6 @@ include strings/module.mk include testfun/module.mk include time/module.mk -include ui/module.mk nobase_fcnfile_DATA = $(FCN_FILES) $(GEN_FCN_FILES) $(JAR_FILES) diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/gui/errordlg.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/gui/errordlg.m Sat Oct 19 12:05:50 2013 -0700 @@ -0,0 +1,51 @@ +## Copyright (C) 2010 Martin Hepperle +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{h} =} errordlg (@var{msg}) +## @deftypefnx {Function File} {@var{h} =} errordlg (@var{msg}, @var{title}) +## Display @var{msg} using an error dialog box. +## +## The message may have multiple lines separated by newline characters +## ("\n"), or it may be a cellstr array with one element for each +## line. The optional input @var{title} (character string) can be used to +## set the dialog caption. The default title is @qcode{"Error Dialog"}. +## +## The return value is always 1. +## @seealso{helpdlg, inputdlg, listdlg, msgbox, questdlg, warndlg} +## @end deftypefn + +function retval = errordlg (msg, title = "Error Dialog") + + if (nargin < 1 || nargin > 2) + print_usage (); + endif + + retval = message_dialog ("errdlg", msg, title, "error"); + +endfunction + + +%!demo +%! disp ('- test errordlg with prompt only.'); +%! errordlg ('Oops, an expected error occured'); + +%!demo +%! disp ('- test errordlg with prompt and caption.'); +%! errordlg ('Oops another error','This is a very long and informative caption'); + diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/gui/helpdlg.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/gui/helpdlg.m Sat Oct 19 12:05:50 2013 -0700 @@ -0,0 +1,51 @@ +## Copyright (C) 2010 Martin Hepperle +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{h} =} helpdlg (@var{msg}) +## @deftypefnx {Function File} {@var{h} =} helpdlg (@var{msg}, @var{title}) +## Display @var{msg} in a help dialog box. +## +## The message may have multiple lines separated by newline characters +## ("\n"), or it may be a cellstr array with one element for each +## line. The optional input @var{title} (character string) can be used to +## set the dialog caption. The default title is @qcode{"Help Dialog"}. +## +## The return value is always 1. +## @seealso{errordlg, inputdlg, listdlg, msgbox, questdlg, warndlg} +## @end deftypefn + +function retval = helpdlg (msg, title = "Help Dialog") + + if (nargin < 1 || nargin > 2) + print_usage (); + endif + + retval = message_dialog ("helpdlg", msg, title, "help"); + +endfunction + + +%!demo +%! disp ('- test helpdlg with a help message only.'); +%! helpdlg ("Below, you should see 3 lines:\nline #1\nline #2, and\nline #3."); + +%!demo +%! disp ('- test helpdlg with help message and caption.'); +%! helpdlg ('You should see a single line.','A help dialog'); + diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/gui/inputdlg.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/gui/inputdlg.m Sat Oct 19 12:05:50 2013 -0700 @@ -0,0 +1,208 @@ +## Copyright (C) 2010 Martin Hepperle +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{cstr} =} inputdlg (@var{prompt}) +## @deftypefnx {Function File} {@var{cstr} =} inputdlg (@var{prompt}, @var{title}) +## @deftypefnx {Function File} {@var{cstr} =} inputdlg (@var{prompt}, @var{title}, @var{rowscols}) +## @deftypefnx {Function File} {@var{cstr} =} 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. +## +## Inputs: +## +## @table @var +## @item prompt +## A cell array with strings labeling each text field. This input is required. +## +## @item title +## String to use for the caption of the dialog. The default is @qcode{"Input +## Dialog"}. +## +## @item rowscols +## Specifies the size of the text fields and can take 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. In the matrix each row describes +## a single text field. The first column specifies the number of input +## rows to use and the second column specifies the text field width. +## @end enumerate +## +## @item defaults +## A list of default values to place in each text fields. It must be +## a cell array of strings with the same size as @var{prompt}. +## @end table +## @seealso{errordlg, helpdlg, listdlg, msgbox, questdlg, warndlg} +## @end deftypefn + +function cstr = inputdlg (prompt, title = "Input Dialog", varargin) + + if (nargin < 1 || nargin > 4) + print_usage (); + endif + + if (iscell (prompt)) + ## Silently extract only char elements + prompt = prompt(cellfun ("isclass", prompt, "char")); + elseif (ischar (prompt)) + prompt = {prompt}; + else + error ("inputdlg: PROMPT must be a character string or cellstr array"); + endif + + if (! ischar (title)) + error ("inputdlg: TITLE must be a character string"); + endif + + switch (numel (varargin)) + case 0 + linespec = 1; + defaults = cellstr (cell (size (prompt))); + + case 1 + linespec = varargin{1}; + defaults = cellstr (cell (size (prompt))); + + case 2 + linespec = varargin{1}; + defaults = varargin{2}; + endswitch + + ## specification of text field sizes as in Matlab + ## Matlab requires a matrix for linespec, 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 (linespec)) + ## only scalar value in lineTo, copy from linespec and add defaults + rowscols = zeros (columns (prompt), 2); + ## cols + rowscols(:,2) = 25; + rowscols(:,1) = linespec; + elseif (isvector (linespec)) + ## only one column in lineTo, copy from vector linespec and add defaults + rowscols = zeros (columns (prompt), 2); + ## rows from colum vector linespec, columns are set to default + rowscols(:,2) = 25; + rowscols(:,1) = linespec(:); + elseif (ismatrix (linespec)) + if (rows (linespec) == columns (prompt) && columns (linespec) == 2) + ## (rows x columns) match, copy array linespec + rowscols = linespec; + else + error ("inputdlg: ROWSCOLS matrix does not match size of PROMPT"); + endif + else + ## dunno + error ("inputdlg: unknown form of ROWSCOLS argument"); + endif + rowscols = ceil (rowscols); + + ## convert numeric values in defaults cell array to strings + defs = cellfun (@num2str, defaults, "UniformOutput", false); + rc = arrayfun (@num2str, rowscols, "UniformOutput", false); + + if (__octave_link_enabled__ ()) + cstr = __octave_link_input_dialog__ (prompt, title, rowscols, defs); + elseif (__have_feature__ ("JAVA")) + user_inputs = javaMethod ("inputdlg", "org.octave.JDialogBox", + prompt, title, rc, defs); + if (isempty (user_inputs)) + cstr = {}; + else + cstr = cellstr (user_inputs); + endif + else + error ("inputdlg is not available in this version of Octave"); + endif + +endfunction + + +%!demo +%! disp ('- test inputdlg with prompt and caption only.'); +%! prompt = {'Width','Height','Depth'}; +%! dims = inputdlg (prompt, 'Enter Box Dimensions'); +%! if (isempty (dims)) +%! helpdlg ('Canceled by user', 'Information'); +%! else +%! volume = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3}); +%! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... +%! str2num (dims{2}) * str2num (dims{3}) + ... +%! str2num (dims{1}) * str2num (dims{3})); +%! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', volume, surface), 'Box Dimensions'); +%! end + +%!demo +%! disp ('- test inputdlg with prescribed scalar (2 lines per text field) and defaults.'); +%! prompt = {'Width','Height','Depth'}; +%! default = {'1.1','2.2','3.3'}; +%! rc = 2; +%! dims = inputdlg (prompt, 'Enter Box Dimensions',rc,default); +%! if (isempty (dims)) +%! helpdlg ('Canceled by user', 'Information'); +%! else +%! volume = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3}); +%! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... +%! str2num (dims{2}) * str2num (dims{3}) + ... +%! str2num (dims{1}) * str2num (dims{3})); +%! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', volume, surface), 'Box Dimensions'); +%! end + +%!demo +%! disp ('- test inputdlg with prescribed vector [1,2,3] for # of lines per text field and defaults.'); +%! prompt = {'Width','Height','Depth'}; +%! default = {'1.10', '2.10', '3.10'}; +%! rc = [1,2,3]; % NOTE: must be an array +%! dims = inputdlg (prompt, 'Enter Box Dimensions',rc,default); +%! if (isempty (dims)) +%! helpdlg ('Canceled by user', 'Information'); +%! else +%! volume = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3}); +%! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... +%! str2num (dims{2}) * str2num (dims{3}) + ... +%! str2num (dims{1}) * str2num (dims{3})); +%! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', volume, surface), 'Box Dimensions'); +%! end + +%!demo +%! disp ('- test inputdlg with prescribed row by column sizes and defaults.'); +%! prompt = {'Width','Height','Depth'}; +%! default = {'1.10', '2.20', '3.30'}; +%! rc = [1,10; 2,20; 3,30]; % NOTE: must be an array +%! dims = inputdlg (prompt, 'Enter Box Dimensions',rc,default); +%! if (isempty (dims)) +%! helpdlg ('Canceled by user', 'Information'); +%! else +%! volume = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3}); +%! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... +%! str2num (dims{2}) * str2num (dims{3}) + ... +%! str2num (dims{1}) * str2num (dims{3})); +%! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', volume, surface), 'Box Dimensions'); +%! end + diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/gui/listdlg.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/gui/listdlg.m Sat Oct 19 12:05:50 2013 -0700 @@ -0,0 +1,194 @@ +## Copyright (C) 2010 Martin Hepperle +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{sel}, @var{ok}] =} listdlg (@var{key}, @var{value}, @dots{}) +## Return user inputs from a list dialog box in a vector of +## selection indices @var{sel} and a flag @var{ok} indicating how the +## user closed the dialog box. The value of @var{ok} is 1 if the user +## closed the box with the OK button, otherwise it is 0 and @var{sel} is +## empty. +## +## The indices in @var{sel} are 1-based. +## +## The arguments are specified in form of @var{key}, @var{value} pairs. +## The @qcode{"ListString"} argument pair must be specified. +## +## Valid @var{key} and @var{value} pairs are: +## +## @table @asis +## @item @qcode{"ListString"} +## a cell array of strings comprising the content of the list. +## +## @item @qcode{"SelectionMode"} +## can be either @qcode{"Single"} or @qcode{"Multiple"} (default). +## +## @item @qcode{"ListSize"} +## a vector with two elements @var{width} and @var{height} defining +## the size of the list field in pixels. Default is [160 300]. +## +## @item @qcode{"InitialValue"} +## a vector containing 1-based indices of preselected elements. Default +## is 1 (first item). +## +## @item @qcode{"Name"} +## a string to be used as the dialog caption. Default is "". +## +## @item @qcode{"PromptString"} +## a cell array of strings to be displayed above the list field. Default +## is @{@}. +## +## @item @qcode{"OKString"} +## a string used to label the OK button. Default is @qcode{"OK"}. +## +## @item @qcode{"CancelString"} +## a string used to label the Cancel button. Default is @qcode{"Cancel"}. +## @end table +## +## Example: +## +## @example +## @group +## [sel, ok] = listdlg ("ListString", @{"An item", "another", "yet another"@}, +## "SelectionMode", "Multiple"); +## if (ok == 1) +## for i = 1:numel (sel) +## disp (sel(i)); +## endfor +## endif +## @end group +## @end example +## +## @seealso{errordlg, helpdlg, inputdlg, msgbox, questdlg, warndlg} +## @end deftypefn + +function [sel, ok] = listdlg (varargin) + + if (nargin < 2) + print_usage (); + endif + + listcell = {""}; + selmode = "Multiple"; + listsize = [160, 300]; + initialvalue = 1; + name = ""; + prompt = {}; + okstring = "OK"; + cancelstring = "Cancel"; + + ## handle key, value pairs + for i = 1:2:nargin-1 + if (strcmp (varargin{i}, "ListString")) + listcell = varargin{i+1}; + elseif (strcmp (varargin{i}, "SelectionMode")) + selmode = varargin{i+1}; + elseif (strcmp (varargin{i}, "ListSize")) + listsize = varargin{i+1}; + elseif (strcmp (varargin{i}, "InitialValue")) + initialvalue = varargin{i+1}; + elseif (strcmp (varargin{i}, "Name")) + name = varargin{i+1}; + elseif (strcmp (varargin{i}, "PromptString")) + prompt = varargin{i+1}; + elseif (strcmp (varargin{i}, "OKString")) + okstring = varargin{i+1}; + elseif (strcmp (varargin{i}, "CancelString")) + cancelstring = varargin{i+1}; + endif + endfor + + ## make sure prompt strings are a cell array + if (! iscell (prompt)) + prompt = {prompt}; + endif + + ## make sure listcell strings are a cell array + if (! iscell (listcell)) + listcell = {listcell}; + endif + + ## make sure valid selection mode + if (! strcmp (selmode, "Multiple") && ! strcmp (selmode, "Single")) + error ("invalid SelectionMode"); + endif + + if (__octave_link_enabled__ ()) + [sel, ok] = __octave_link_list_dialog__ (listcell, selmode, listsize, + initialvalue, name, prompt, + okstring, cancelstring); + elseif (__have_feature__ ("JAVA")) + ## transform matrices to cell arrays of strings + ## swap width and height to correct calling format for JDialogBox + listsize = {num2str(listsize(2)), num2str(listsize(1))}; + initialvalue = arrayfun (@num2str, initialvalue, "UniformOutput", false); + if (isempty (prompt)) + prompt = {""}; + endif + + ret = javaMethod ("listdlg", "org.octave.JDialogBox", listcell, + selmode, listsize, initialvalue, name, prompt, + okstring, cancelstring); + + if (numel (ret) > 0) + sel = ret; + ok = 1; + else + sel = {}; + ok = 0; + endif + else + error ("listdlg is not available in this version of Octave"); + endif + +endfunction + + +%!demo +%! disp ('- test listdlg with selectionmode single. No caption, no prompt.'); +%! itemlist = {'An item \\alpha', 'another', 'yet another'}; +%! s = listdlg ('ListString',itemlist, 'SelectionMode','Single'); +%! imax = numel (s); +%! for i=1:1:imax +%! disp (['Selected: ',num2str (i),': ', itemlist{s (i)}]); +%! end + +%!demo +%! disp ('- test listdlg with selectionmode and preselection. Has caption and two lines prompt.'); +%! itemlist = {'An item \\alpha', 'another', 'yet another'}; +%! s = listdlg ('ListString',itemlist, ... +%! 'SelectionMode','Multiple', ... +%! 'Name','Selection Dialog', ... +%! 'InitialValue',[1,2,3,4], +%! 'PromptString',{'Select an item...', '...or multiple items'} ); +%! imax = numel (s); +%! for i=1:1:imax +%! disp (['Selected: ',num2str (i),': ', itemlist{s (i)}]); +%! end + +%!demo +%! disp ('- test listdlg with listsize.'); +%! itemlist = {"Neutron","Electron","Quark","Proton","Neutrino"}; +%! s = listdlg ("ListString",itemlist, +%! "Name","Bits and Pieces", +%! "ListSize",[200 75] ); +%! imax = numel (s); +%! for i=1:1:imax +%! disp (['Selected: ',num2str (i),': ', itemlist{s (i)}]); +%! end + diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/gui/module.mk --- a/scripts/gui/module.mk Sat Oct 19 19:51:23 2013 +0200 +++ b/scripts/gui/module.mk Sat Oct 19 12:05:50 2013 -0700 @@ -7,11 +7,18 @@ gui/private/__uigetdir_fltk__.m \ gui/private/__uigetfile_fltk__.m \ gui/private/__uiobject_split_args__.m \ - gui/private/__uiputfile_fltk__.m + gui/private/__uiputfile_fltk__.m \ + gui/private/message_dialog.m gui_FCN_FILES = \ + gui/errordlg.m \ gui/guidata.m \ gui/guihandles.m \ + gui/helpdlg.m \ + gui/inputdlg.m \ + gui/listdlg.m \ + gui/msgbox.m \ + gui/questdlg.m \ gui/uicontextmenu.m \ gui/uicontrol.m \ gui/uigetdir.m \ @@ -26,6 +33,7 @@ gui/uiwait.m \ gui/waitbar.m \ gui/waitforbuttonpress.m \ + gui/warndlg.m \ $(gui_PRIVATE_FCN_FILES) FCN_FILES += $(gui_FCN_FILES) diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/gui/msgbox.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/gui/msgbox.m Sat Oct 19 12:05:50 2013 -0700 @@ -0,0 +1,56 @@ +## Copyright (C) 2010 Martin Hepperle +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{h} =} msgbox (@var{msg}) +## @deftypefnx {Function File} {@var{h} =} msgbox (@var{msg}, @var{title}) +## @deftypefnx {Function File} {@var{h} =} msgbox (@var{msg}, @var{title}, @var{icon}) +## Display @var{msg} using a message dialog box. +## +## The message may have multiple lines separated by newline characters +## (@qcode{"\n"}), or it may be a cellstr array with one element for each +## line. The optional input @var{title} (character string) can be used to +## decorate the dialog caption. +## +## The optional argument @var{icon} selects a dialog icon. +## It can be one of @qcode{"none"} (default), @qcode{"error"}, +## @qcode{"help"}, or @qcode{"warn"}. +## +## The return value is always 1. +## @seealso{errordlg, helpdlg, inputdlg, listdlg, questdlg, warndlg} +## @end deftypefn + +function retval = msgbox (msg, title = "", varargin) + + if (nargin < 1 || nargin > 3) + print_usage (); + endif + + retval = message_dialog ("msgbox", msg, title, varargin{:}); + +endfunction + + +%!demo +%! disp('- test msgbox message only.'); +%! msgbox("Below, you should see 3 lines:\nline #1\nline #2, and\nline #3."); + +%!demo +%! disp('- test msgbox message and caption.'); +%! msgbox('You should see a single line.','A msgbox'); + diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/gui/private/message_dialog.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/gui/private/message_dialog.m Sat Oct 19 12:05:50 2013 -0700 @@ -0,0 +1,66 @@ +## Copyright (C) 2010 Martin Hepperle +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{h} =} message_dialog (@var{caller}, @var{msg}, @var{title}, @var{icon}) +## Undocumented internal function. +## @end deftypefn + +function retval = message_dialog (caller, msg, title = "", icon) + + if (! ischar (msg)) + if (iscell (msg)) + msg = sprintf ("%s\n", msg{:}); + msg(end) = ""; + else + error ("%s: MSG must be a character string or cellstr array", caller); + endif + endif + + if (! ischar (title)) + error ("%s: TITLE must be a character string", caller); + endif + + dlg = "emptydlg"; + if (nargin == 4) + switch (icon) + case "error" + dlg = "errordlg"; + case "help" + dlg = "helpdlg"; + case "warn" + dlg = "warndlg"; + case "none" + dlg = "emptydlg"; + otherwise + error ("%s: ICON is not a valid type", caller); + endswitch + else + icon = "none"; + endif + + if (__octave_link_enabled__ ()) + retval = __octave_link_message_dialog__ (icon, msg, title); + elseif (__have_feature__ ("JAVA")) + retval = javaMethod (dlg, "org.octave.JDialogBox", msg, title); + else + error ("%s is not available in this version of Octave", dlg); + endif + +endfunction + diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/gui/questdlg.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/gui/questdlg.m Sat Oct 19 12:05:50 2013 -0700 @@ -0,0 +1,176 @@ +## Copyright (C) 2010 Martin Hepperle +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{btn} =} questdlg (@var{msg}) +## @deftypefnx {Function File} {@var{btn} =} questdlg (@var{msg}, @var{title}) +## @deftypefnx {Function File} {@var{btn} =} questdlg (@var{msg}, @var{title}, @var{default}) +## @deftypefnx {Function File} {@var{btn} =} questdlg (@var{msg}, @var{title}, @var{btn1}, @var{btn2}, @var{default}) +## @deftypefnx {Function File} {@var{btn} =} questdlg (@var{msg}, @var{title}, @var{btn1}, @var{btn2}, @var{btn3}, @var{default}) +## Display @var{msg} using a question dialog box and return the caption +## of the activated button. +## +## The dialog may contain two or three buttons which will all close the dialog. +## +## The message may have multiple lines separated by newline characters +## ("\n"), or it may be a cellstr array with 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 @key{ENTER} key. +## It must match one of the strings given in @var{btn1}, @var{btn2}, or +## @var{btn3}. +## +## If only @var{msg} and @var{title} are specified, three buttons with +## the default captions @qcode{"Yes"}, @qcode{"No"}, and @qcode{"Cancel"} are +## used. +## +## If only two button captions, @var{btn1} and @var{btn2}, are specified +## the dialog will have only these two buttons. +## +## @seealso{errordlg, helpdlg, inputdlg, listdlg, warndlg} +## @end deftypefn + +function btn = questdlg (msg, title = "Question Dialog", varargin) + + if (nargin < 1 || nargin > 6) + print_usage (); + endif + + if (! ischar (msg)) + if (iscell (msg)) + msg = sprintf ("%s\n", msg{:}); + msg(end) = ""; + else + error ("questdlg: MSG must be a character string or cellstr array"); + endif + endif + + if (! ischar (title)) + error ("questdlg: TITLES must be a character string"); + endif + + options{1} = "Yes"; # button1 + options{2} = "No"; # button2 + options{3} = "Cancel"; # button3 + options{4} = "Yes"; # default + + defbtn_error_msg = "questdlg: DEFAULT must match one of the button options"; + + switch (numel (varargin)) + case 0 + ## use default default + + case 1 + ## default button string + options{4} = varargin{1}; # default + if (! any (strcmp (options{4}, options(1:3)))) + error (defbtn_error_msg); + endif + + case 3 + ## two buttons and default button string + options{1} = varargin{1}; # button1 + options{2} = ""; # not used, no middle button + options{3} = varargin{2}; # button3 + options{4} = varargin{3}; # default + if (! any (strcmp (options{4}, options([1 3])))) + error (defbtn_error_msg); + endif + + case 4 + ## three buttons and default button string + options{1} = varargin{1}; # button1 + options{2} = varargin{2}; # button2 + options{3} = varargin{3}; # button3 + options{4} = varargin{4}; # default + if (! any (strcmp (options{4}, options(1:3)))) + error (defbtn_error_msg); + endif + + otherwise + print_usage (); + + endswitch + + if (__octave_link_enabled__ ()) + btn = __octave_link_question_dialog__ (msg, title, options{1}, options{2}, + options{3}, options{4}); + elseif (__have_feature__ ("JAVA")) + btn = javaMethod ("questdlg", "org.octave.JDialogBox", msg, + title, options); + else + error ("questdlg is not available in this version of Octave"); + endif + +endfunction + + +%!demo +%! disp ('- test questdlg with two buttons'); +%! a = questdlg ('Would you like some free money?',... +%! '$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $',... +%! 'No', 'Cancel', 'Cancel'); +%! if (strcmp (a, 'No')) +%! msgbox ('Suit yourself.', 'Message Box'); +%! endif + +%!demo +%! disp ('- test questdlg with message and title only.'); +%! a = 'No'; +%! c = 0; +%! while (strcmp (a, 'No') || !c) +%! a = questdlg ('Close this Question Dialog?', 'Reductio Ad Absurdum'); +%! if (strcmp (a, 'Yes')) +%! q = 'Are you sure?'; +%! while (strcmp (a, 'Yes') && !c) +%! a = questdlg (q, 'Reductio Ad Absurdum'); +%! word = ' really'; +%! i = strfind (q, word); +%! if (isempty (i)) +%! i = strfind (q, ' sure'); +%! q = [q '!']; +%! else +%! word = [word ',']; +%! endif +%! q = [q(1:i-1) word q(i:end)]; +%! endwhile +%! endif +%! if (strcmp (a, 'Cancel')) +%! warndlg ('Answer "Yes" or "No".', 'Warning Dialog'); +%! a = 'No'; +%! c = 1; +%! endif +%! endwhile +%! msgbox ('Whew!'); + +%!demo +%! disp ('- test questdlg with five inputs'); +%! ans = questdlg ('Are you ready Steve?', 'Brian', 'No', 'Uh huh', 'Uh huh'); +%! if (! strcmp (ans, 'No')) +%! ans = questdlg ('Andy?', 'Brian', 'No', 'Yeah', 'Yeah'); +%! if (! strcmp (ans, 'No')) +%! ans = questdlg ('Mick?', 'Brian', 'No', 'Okay', 'Okay'); +%! if (! strcmp (ans, 'No')) +%! ans = msgbox ("Well all right, fellas. \n\n Let''s GO!!!!!",... +%! 'Ballroom Blitz', 'none'); +%! endif +%! endif +%! endif + diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/gui/warndlg.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/gui/warndlg.m Sat Oct 19 12:05:50 2013 -0700 @@ -0,0 +1,50 @@ +## Copyright (C) 2010 Martin Hepperle +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{h} =} warndlg (@var{msg}) +## @deftypefnx {Function File} {@var{h} =} warndlg (@var{msg}, @var{title}) +## Display @var{msg} using a warning dialog box. +## +## The message may have multiple lines separated by newline characters +## ("\n"), or it may be a cellstr array with one element for each +## line. The optional input @var{title} (character string) can be used to +## set the dialog caption. The default title is @qcode{"Warning Dialog"}. +## +## @seealso{helpdlg, inputdlg, listdlg, questdlg} +## @end deftypefn + +function retval = warndlg (msg, title = "Warning Dialog") + + if (nargin < 1 || nargin > 2) + print_usage (); + endif + + retval = message_dialog ("warndlg", msg, title, "warn"); + +endfunction + + +%!demo +%! disp ('- test warndlg with prompt only.'); +%! warndlg ('Oh, a warning occured'); + +%!demo +%! disp ('- test warndlg with prompt and caption.'); +%! warndlg ('Oh, No...','This is the last Warning'); + diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/ui/errordlg.m --- a/scripts/ui/errordlg.m Sat Oct 19 19:51:23 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -## Copyright (C) 2010 Martin Hepperle -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{h} =} errordlg (@var{msg}) -## @deftypefnx {Function File} {@var{h} =} errordlg (@var{msg}, @var{title}) -## Display @var{msg} using an error dialog box. -## -## The message may have multiple lines separated by newline characters -## ("\n"), or it may be a cellstr array with one element for each -## line. The optional input @var{title} (character string) can be used to -## set the dialog caption. The default title is @qcode{"Error Dialog"}. -## -## The return value is always 1. -## @seealso{helpdlg, inputdlg, listdlg, msgbox, questdlg, warndlg} -## @end deftypefn - -function retval = errordlg (msg, title = "Error Dialog") - - if (nargin < 1 || nargin > 2) - print_usage (); - endif - - retval = message_dialog ("errdlg", msg, title, "error"); - -endfunction - - -%!demo -%! disp ('- test errordlg with prompt only.'); -%! errordlg ('Oops, an expected error occured'); - -%!demo -%! disp ('- test errordlg with prompt and caption.'); -%! errordlg ('Oops another error','This is a very long and informative caption'); - diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/ui/helpdlg.m --- a/scripts/ui/helpdlg.m Sat Oct 19 19:51:23 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -## Copyright (C) 2010 Martin Hepperle -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{h} =} helpdlg (@var{msg}) -## @deftypefnx {Function File} {@var{h} =} helpdlg (@var{msg}, @var{title}) -## Display @var{msg} in a help dialog box. -## -## The message may have multiple lines separated by newline characters -## ("\n"), or it may be a cellstr array with one element for each -## line. The optional input @var{title} (character string) can be used to -## set the dialog caption. The default title is @qcode{"Help Dialog"}. -## -## The return value is always 1. -## @seealso{errordlg, inputdlg, listdlg, msgbox, questdlg, warndlg} -## @end deftypefn - -function retval = helpdlg (msg, title = "Help Dialog") - - if (nargin < 1 || nargin > 2) - print_usage (); - endif - - retval = message_dialog ("helpdlg", msg, title, "help"); - -endfunction - - -%!demo -%! disp ('- test helpdlg with a help message only.'); -%! helpdlg ("Below, you should see 3 lines:\nline #1\nline #2, and\nline #3."); - -%!demo -%! disp ('- test helpdlg with help message and caption.'); -%! helpdlg ('You should see a single line.','A help dialog'); - diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/ui/inputdlg.m --- a/scripts/ui/inputdlg.m Sat Oct 19 19:51:23 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,208 +0,0 @@ -## Copyright (C) 2010 Martin Hepperle -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{cstr} =} inputdlg (@var{prompt}) -## @deftypefnx {Function File} {@var{cstr} =} inputdlg (@var{prompt}, @var{title}) -## @deftypefnx {Function File} {@var{cstr} =} inputdlg (@var{prompt}, @var{title}, @var{rowscols}) -## @deftypefnx {Function File} {@var{cstr} =} 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. -## -## Inputs: -## -## @table @var -## @item prompt -## A cell array with strings labeling each text field. This input is required. -## -## @item title -## String to use for the caption of the dialog. The default is @qcode{"Input -## Dialog"}. -## -## @item rowscols -## Specifies the size of the text fields and can take 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. In the matrix each row describes -## a single text field. The first column specifies the number of input -## rows to use and the second column specifies the text field width. -## @end enumerate -## -## @item defaults -## A list of default values to place in each text fields. It must be -## a cell array of strings with the same size as @var{prompt}. -## @end table -## @seealso{errordlg, helpdlg, listdlg, msgbox, questdlg, warndlg} -## @end deftypefn - -function cstr = inputdlg (prompt, title = "Input Dialog", varargin) - - if (nargin < 1 || nargin > 4) - print_usage (); - endif - - if (iscell (prompt)) - ## Silently extract only char elements - prompt = prompt(cellfun ("isclass", prompt, "char")); - elseif (ischar (prompt)) - prompt = {prompt}; - else - error ("inputdlg: PROMPT must be a character string or cellstr array"); - endif - - if (! ischar (title)) - error ("inputdlg: TITLE must be a character string"); - endif - - switch (numel (varargin)) - case 0 - linespec = 1; - defaults = cellstr (cell (size (prompt))); - - case 1 - linespec = varargin{1}; - defaults = cellstr (cell (size (prompt))); - - case 2 - linespec = varargin{1}; - defaults = varargin{2}; - endswitch - - ## specification of text field sizes as in Matlab - ## Matlab requires a matrix for linespec, 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 (linespec)) - ## only scalar value in lineTo, copy from linespec and add defaults - rowscols = zeros (columns (prompt), 2); - ## cols - rowscols(:,2) = 25; - rowscols(:,1) = linespec; - elseif (isvector (linespec)) - ## only one column in lineTo, copy from vector linespec and add defaults - rowscols = zeros (columns (prompt), 2); - ## rows from colum vector linespec, columns are set to default - rowscols(:,2) = 25; - rowscols(:,1) = linespec(:); - elseif (ismatrix (linespec)) - if (rows (linespec) == columns (prompt) && columns (linespec) == 2) - ## (rows x columns) match, copy array linespec - rowscols = linespec; - else - error ("inputdlg: ROWSCOLS matrix does not match size of PROMPT"); - endif - else - ## dunno - error ("inputdlg: unknown form of ROWSCOLS argument"); - endif - rowscols = ceil (rowscols); - - ## convert numeric values in defaults cell array to strings - defs = cellfun (@num2str, defaults, "UniformOutput", false); - rc = arrayfun (@num2str, rowscols, "UniformOutput", false); - - if (__octave_link_enabled__ ()) - cstr = __octave_link_input_dialog__ (prompt, title, rowscols, defs); - elseif (__have_feature__ ("JAVA")) - user_inputs = javaMethod ("inputdlg", "org.octave.JDialogBox", - prompt, title, rc, defs); - if (isempty (user_inputs)) - cstr = {}; - else - cstr = cellstr (user_inputs); - endif - else - error ("inputdlg is not available in this version of Octave"); - endif - -endfunction - - -%!demo -%! disp ('- test inputdlg with prompt and caption only.'); -%! prompt = {'Width','Height','Depth'}; -%! dims = inputdlg (prompt, 'Enter Box Dimensions'); -%! if (isempty (dims)) -%! helpdlg ('Canceled by user', 'Information'); -%! else -%! volume = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3}); -%! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... -%! str2num (dims{2}) * str2num (dims{3}) + ... -%! str2num (dims{1}) * str2num (dims{3})); -%! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', volume, surface), 'Box Dimensions'); -%! end - -%!demo -%! disp ('- test inputdlg with prescribed scalar (2 lines per text field) and defaults.'); -%! prompt = {'Width','Height','Depth'}; -%! default = {'1.1','2.2','3.3'}; -%! rc = 2; -%! dims = inputdlg (prompt, 'Enter Box Dimensions',rc,default); -%! if (isempty (dims)) -%! helpdlg ('Canceled by user', 'Information'); -%! else -%! volume = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3}); -%! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... -%! str2num (dims{2}) * str2num (dims{3}) + ... -%! str2num (dims{1}) * str2num (dims{3})); -%! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', volume, surface), 'Box Dimensions'); -%! end - -%!demo -%! disp ('- test inputdlg with prescribed vector [1,2,3] for # of lines per text field and defaults.'); -%! prompt = {'Width','Height','Depth'}; -%! default = {'1.10', '2.10', '3.10'}; -%! rc = [1,2,3]; % NOTE: must be an array -%! dims = inputdlg (prompt, 'Enter Box Dimensions',rc,default); -%! if (isempty (dims)) -%! helpdlg ('Canceled by user', 'Information'); -%! else -%! volume = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3}); -%! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... -%! str2num (dims{2}) * str2num (dims{3}) + ... -%! str2num (dims{1}) * str2num (dims{3})); -%! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', volume, surface), 'Box Dimensions'); -%! end - -%!demo -%! disp ('- test inputdlg with prescribed row by column sizes and defaults.'); -%! prompt = {'Width','Height','Depth'}; -%! default = {'1.10', '2.20', '3.30'}; -%! rc = [1,10; 2,20; 3,30]; % NOTE: must be an array -%! dims = inputdlg (prompt, 'Enter Box Dimensions',rc,default); -%! if (isempty (dims)) -%! helpdlg ('Canceled by user', 'Information'); -%! else -%! volume = str2num (dims{1}) * str2num (dims{2}) * str2num (dims{3}); -%! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... -%! str2num (dims{2}) * str2num (dims{3}) + ... -%! str2num (dims{1}) * str2num (dims{3})); -%! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', volume, surface), 'Box Dimensions'); -%! end - diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/ui/listdlg.m --- a/scripts/ui/listdlg.m Sat Oct 19 19:51:23 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,194 +0,0 @@ -## Copyright (C) 2010 Martin Hepperle -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {[@var{sel}, @var{ok}] =} listdlg (@var{key}, @var{value}, @dots{}) -## Return user inputs from a list dialog box in a vector of -## selection indices @var{sel} and a flag @var{ok} indicating how the -## user closed the dialog box. The value of @var{ok} is 1 if the user -## closed the box with the OK button, otherwise it is 0 and @var{sel} is -## empty. -## -## The indices in @var{sel} are 1-based. -## -## The arguments are specified in form of @var{key}, @var{value} pairs. -## The @qcode{"ListString"} argument pair must be specified. -## -## Valid @var{key} and @var{value} pairs are: -## -## @table @asis -## @item @qcode{"ListString"} -## a cell array of strings comprising the content of the list. -## -## @item @qcode{"SelectionMode"} -## can be either @qcode{"Single"} or @qcode{"Multiple"} (default). -## -## @item @qcode{"ListSize"} -## a vector with two elements @var{width} and @var{height} defining -## the size of the list field in pixels. Default is [160 300]. -## -## @item @qcode{"InitialValue"} -## a vector containing 1-based indices of preselected elements. Default -## is 1 (first item). -## -## @item @qcode{"Name"} -## a string to be used as the dialog caption. Default is "". -## -## @item @qcode{"PromptString"} -## a cell array of strings to be displayed above the list field. Default -## is @{@}. -## -## @item @qcode{"OKString"} -## a string used to label the OK button. Default is @qcode{"OK"}. -## -## @item @qcode{"CancelString"} -## a string used to label the Cancel button. Default is @qcode{"Cancel"}. -## @end table -## -## Example: -## -## @example -## @group -## [sel, ok] = listdlg ("ListString", @{"An item", "another", "yet another"@}, -## "SelectionMode", "Multiple"); -## if (ok == 1) -## for i = 1:numel (sel) -## disp (sel(i)); -## endfor -## endif -## @end group -## @end example -## -## @seealso{errordlg, helpdlg, inputdlg, msgbox, questdlg, warndlg} -## @end deftypefn - -function [sel, ok] = listdlg (varargin) - - if (nargin < 2) - print_usage (); - endif - - listcell = {""}; - selmode = "Multiple"; - listsize = [160, 300]; - initialvalue = 1; - name = ""; - prompt = {}; - okstring = "OK"; - cancelstring = "Cancel"; - - ## handle key, value pairs - for i = 1:2:nargin-1 - if (strcmp (varargin{i}, "ListString")) - listcell = varargin{i+1}; - elseif (strcmp (varargin{i}, "SelectionMode")) - selmode = varargin{i+1}; - elseif (strcmp (varargin{i}, "ListSize")) - listsize = varargin{i+1}; - elseif (strcmp (varargin{i}, "InitialValue")) - initialvalue = varargin{i+1}; - elseif (strcmp (varargin{i}, "Name")) - name = varargin{i+1}; - elseif (strcmp (varargin{i}, "PromptString")) - prompt = varargin{i+1}; - elseif (strcmp (varargin{i}, "OKString")) - okstring = varargin{i+1}; - elseif (strcmp (varargin{i}, "CancelString")) - cancelstring = varargin{i+1}; - endif - endfor - - ## make sure prompt strings are a cell array - if (! iscell (prompt)) - prompt = {prompt}; - endif - - ## make sure listcell strings are a cell array - if (! iscell (listcell)) - listcell = {listcell}; - endif - - ## make sure valid selection mode - if (! strcmp (selmode, "Multiple") && ! strcmp (selmode, "Single")) - error ("invalid SelectionMode"); - endif - - if (__octave_link_enabled__ ()) - [sel, ok] = __octave_link_list_dialog__ (listcell, selmode, listsize, - initialvalue, name, prompt, - okstring, cancelstring); - elseif (__have_feature__ ("JAVA")) - ## transform matrices to cell arrays of strings - ## swap width and height to correct calling format for JDialogBox - listsize = {num2str(listsize(2)), num2str(listsize(1))}; - initialvalue = arrayfun (@num2str, initialvalue, "UniformOutput", false); - if (isempty (prompt)) - prompt = {""}; - endif - - ret = javaMethod ("listdlg", "org.octave.JDialogBox", listcell, - selmode, listsize, initialvalue, name, prompt, - okstring, cancelstring); - - if (numel (ret) > 0) - sel = ret; - ok = 1; - else - sel = {}; - ok = 0; - endif - else - error ("listdlg is not available in this version of Octave"); - endif - -endfunction - - -%!demo -%! disp ('- test listdlg with selectionmode single. No caption, no prompt.'); -%! itemlist = {'An item \\alpha', 'another', 'yet another'}; -%! s = listdlg ('ListString',itemlist, 'SelectionMode','Single'); -%! imax = numel (s); -%! for i=1:1:imax -%! disp (['Selected: ',num2str (i),': ', itemlist{s (i)}]); -%! end - -%!demo -%! disp ('- test listdlg with selectionmode and preselection. Has caption and two lines prompt.'); -%! itemlist = {'An item \\alpha', 'another', 'yet another'}; -%! s = listdlg ('ListString',itemlist, ... -%! 'SelectionMode','Multiple', ... -%! 'Name','Selection Dialog', ... -%! 'InitialValue',[1,2,3,4], -%! 'PromptString',{'Select an item...', '...or multiple items'} ); -%! imax = numel (s); -%! for i=1:1:imax -%! disp (['Selected: ',num2str (i),': ', itemlist{s (i)}]); -%! end - -%!demo -%! disp ('- test listdlg with listsize.'); -%! itemlist = {"Neutron","Electron","Quark","Proton","Neutrino"}; -%! s = listdlg ("ListString",itemlist, -%! "Name","Bits and Pieces", -%! "ListSize",[200 75] ); -%! imax = numel (s); -%! for i=1:1:imax -%! disp (['Selected: ',num2str (i),': ', itemlist{s (i)}]); -%! end - diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/ui/module.mk --- a/scripts/ui/module.mk Sat Oct 19 19:51:23 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -FCN_FILE_DIRS += ui - -ui_PRIVATE_FCN_FILES = \ - ui/private/message_dialog.m - -ui_FCN_FILES = \ - ui/errordlg.m \ - ui/helpdlg.m \ - ui/inputdlg.m \ - ui/listdlg.m \ - ui/msgbox.m \ - ui/questdlg.m \ - ui/warndlg.m \ - $(ui_PRIVATE_FCN_FILES) - -FCN_FILES += $(ui_FCN_FILES) - -PKG_ADD_FILES += ui/PKG_ADD - -DIRSTAMP_FILES += ui/$(octave_dirstamp) diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/ui/msgbox.m --- a/scripts/ui/msgbox.m Sat Oct 19 19:51:23 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -## Copyright (C) 2010 Martin Hepperle -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{h} =} msgbox (@var{msg}) -## @deftypefnx {Function File} {@var{h} =} msgbox (@var{msg}, @var{title}) -## @deftypefnx {Function File} {@var{h} =} msgbox (@var{msg}, @var{title}, @var{icon}) -## Display @var{msg} using a message dialog box. -## -## The message may have multiple lines separated by newline characters -## (@qcode{"\n"}), or it may be a cellstr array with one element for each -## line. The optional input @var{title} (character string) can be used to -## decorate the dialog caption. -## -## The optional argument @var{icon} selects a dialog icon. -## It can be one of @qcode{"none"} (default), @qcode{"error"}, -## @qcode{"help"}, or @qcode{"warn"}. -## -## The return value is always 1. -## @seealso{errordlg, helpdlg, inputdlg, listdlg, questdlg, warndlg} -## @end deftypefn - -function retval = msgbox (msg, title = "", varargin) - - if (nargin < 1 || nargin > 3) - print_usage (); - endif - - retval = message_dialog ("msgbox", msg, title, varargin{:}); - -endfunction - - -%!demo -%! disp('- test msgbox message only.'); -%! msgbox("Below, you should see 3 lines:\nline #1\nline #2, and\nline #3."); - -%!demo -%! disp('- test msgbox message and caption.'); -%! msgbox('You should see a single line.','A msgbox'); - diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/ui/private/message_dialog.m --- a/scripts/ui/private/message_dialog.m Sat Oct 19 19:51:23 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -## Copyright (C) 2010 Martin Hepperle -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{h} =} message_dialog (@var{caller}, @var{msg}, @var{title}, @var{icon}) -## Undocumented internal function. -## @end deftypefn - -function retval = message_dialog (caller, msg, title = "", icon) - - if (! ischar (msg)) - if (iscell (msg)) - msg = sprintf ("%s\n", msg{:}); - msg(end) = ""; - else - error ("%s: MSG must be a character string or cellstr array", caller); - endif - endif - - if (! ischar (title)) - error ("%s: TITLE must be a character string", caller); - endif - - dlg = "emptydlg"; - if (nargin == 4) - switch (icon) - case "error" - dlg = "errordlg"; - case "help" - dlg = "helpdlg"; - case "warn" - dlg = "warndlg"; - case "none" - dlg = "emptydlg"; - otherwise - error ("%s: ICON is not a valid type", caller); - endswitch - else - icon = "none"; - endif - - if (__octave_link_enabled__ ()) - retval = __octave_link_message_dialog__ (icon, msg, title); - elseif (__have_feature__ ("JAVA")) - retval = javaMethod (dlg, "org.octave.JDialogBox", msg, title); - else - error ("%s is not available in this version of Octave", dlg); - endif - -endfunction - diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/ui/questdlg.m --- a/scripts/ui/questdlg.m Sat Oct 19 19:51:23 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,176 +0,0 @@ -## Copyright (C) 2010 Martin Hepperle -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{btn} =} questdlg (@var{msg}) -## @deftypefnx {Function File} {@var{btn} =} questdlg (@var{msg}, @var{title}) -## @deftypefnx {Function File} {@var{btn} =} questdlg (@var{msg}, @var{title}, @var{default}) -## @deftypefnx {Function File} {@var{btn} =} questdlg (@var{msg}, @var{title}, @var{btn1}, @var{btn2}, @var{default}) -## @deftypefnx {Function File} {@var{btn} =} questdlg (@var{msg}, @var{title}, @var{btn1}, @var{btn2}, @var{btn3}, @var{default}) -## Display @var{msg} using a question dialog box and return the caption -## of the activated button. -## -## The dialog may contain two or three buttons which will all close the dialog. -## -## The message may have multiple lines separated by newline characters -## ("\n"), or it may be a cellstr array with 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 @key{ENTER} key. -## It must match one of the strings given in @var{btn1}, @var{btn2}, or -## @var{btn3}. -## -## If only @var{msg} and @var{title} are specified, three buttons with -## the default captions @qcode{"Yes"}, @qcode{"No"}, and @qcode{"Cancel"} are -## used. -## -## If only two button captions, @var{btn1} and @var{btn2}, are specified -## the dialog will have only these two buttons. -## -## @seealso{errordlg, helpdlg, inputdlg, listdlg, warndlg} -## @end deftypefn - -function btn = questdlg (msg, title = "Question Dialog", varargin) - - if (nargin < 1 || nargin > 6) - print_usage (); - endif - - if (! ischar (msg)) - if (iscell (msg)) - msg = sprintf ("%s\n", msg{:}); - msg(end) = ""; - else - error ("questdlg: MSG must be a character string or cellstr array"); - endif - endif - - if (! ischar (title)) - error ("questdlg: TITLES must be a character string"); - endif - - options{1} = "Yes"; # button1 - options{2} = "No"; # button2 - options{3} = "Cancel"; # button3 - options{4} = "Yes"; # default - - defbtn_error_msg = "questdlg: DEFAULT must match one of the button options"; - - switch (numel (varargin)) - case 0 - ## use default default - - case 1 - ## default button string - options{4} = varargin{1}; # default - if (! any (strcmp (options{4}, options(1:3)))) - error (defbtn_error_msg); - endif - - case 3 - ## two buttons and default button string - options{1} = varargin{1}; # button1 - options{2} = ""; # not used, no middle button - options{3} = varargin{2}; # button3 - options{4} = varargin{3}; # default - if (! any (strcmp (options{4}, options([1 3])))) - error (defbtn_error_msg); - endif - - case 4 - ## three buttons and default button string - options{1} = varargin{1}; # button1 - options{2} = varargin{2}; # button2 - options{3} = varargin{3}; # button3 - options{4} = varargin{4}; # default - if (! any (strcmp (options{4}, options(1:3)))) - error (defbtn_error_msg); - endif - - otherwise - print_usage (); - - endswitch - - if (__octave_link_enabled__ ()) - btn = __octave_link_question_dialog__ (msg, title, options{1}, options{2}, - options{3}, options{4}); - elseif (__have_feature__ ("JAVA")) - btn = javaMethod ("questdlg", "org.octave.JDialogBox", msg, - title, options); - else - error ("questdlg is not available in this version of Octave"); - endif - -endfunction - - -%!demo -%! disp ('- test questdlg with two buttons'); -%! a = questdlg ('Would you like some free money?',... -%! '$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $',... -%! 'No', 'Cancel', 'Cancel'); -%! if (strcmp (a, 'No')) -%! msgbox ('Suit yourself.', 'Message Box'); -%! endif - -%!demo -%! disp ('- test questdlg with message and title only.'); -%! a = 'No'; -%! c = 0; -%! while (strcmp (a, 'No') || !c) -%! a = questdlg ('Close this Question Dialog?', 'Reductio Ad Absurdum'); -%! if (strcmp (a, 'Yes')) -%! q = 'Are you sure?'; -%! while (strcmp (a, 'Yes') && !c) -%! a = questdlg (q, 'Reductio Ad Absurdum'); -%! word = ' really'; -%! i = strfind (q, word); -%! if (isempty (i)) -%! i = strfind (q, ' sure'); -%! q = [q '!']; -%! else -%! word = [word ',']; -%! endif -%! q = [q(1:i-1) word q(i:end)]; -%! endwhile -%! endif -%! if (strcmp (a, 'Cancel')) -%! warndlg ('Answer "Yes" or "No".', 'Warning Dialog'); -%! a = 'No'; -%! c = 1; -%! endif -%! endwhile -%! msgbox ('Whew!'); - -%!demo -%! disp ('- test questdlg with five inputs'); -%! ans = questdlg ('Are you ready Steve?', 'Brian', 'No', 'Uh huh', 'Uh huh'); -%! if (! strcmp (ans, 'No')) -%! ans = questdlg ('Andy?', 'Brian', 'No', 'Yeah', 'Yeah'); -%! if (! strcmp (ans, 'No')) -%! ans = questdlg ('Mick?', 'Brian', 'No', 'Okay', 'Okay'); -%! if (! strcmp (ans, 'No')) -%! ans = msgbox ("Well all right, fellas. \n\n Let''s GO!!!!!",... -%! 'Ballroom Blitz', 'none'); -%! endif -%! endif -%! endif - diff -r 1be2993d3656 -r dba2e06dcdb5 scripts/ui/warndlg.m --- a/scripts/ui/warndlg.m Sat Oct 19 19:51:23 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -## Copyright (C) 2010 Martin Hepperle -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## . - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{h} =} warndlg (@var{msg}) -## @deftypefnx {Function File} {@var{h} =} warndlg (@var{msg}, @var{title}) -## Display @var{msg} using a warning dialog box. -## -## The message may have multiple lines separated by newline characters -## ("\n"), or it may be a cellstr array with one element for each -## line. The optional input @var{title} (character string) can be used to -## set the dialog caption. The default title is @qcode{"Warning Dialog"}. -## -## @seealso{helpdlg, inputdlg, listdlg, questdlg} -## @end deftypefn - -function retval = warndlg (msg, title = "Warning Dialog") - - if (nargin < 1 || nargin > 2) - print_usage (); - endif - - retval = message_dialog ("warndlg", msg, title, "warn"); - -endfunction - - -%!demo -%! disp ('- test warndlg with prompt only.'); -%! warndlg ('Oh, a warning occured'); - -%!demo -%! disp ('- test warndlg with prompt and caption.'); -%! warndlg ('Oh, No...','This is the last Warning'); -