annotate scripts/java/listdlg.m @ 15750:05c781cca57e

use numel instead of length in newly imported java functions
author John W. Eaton <jwe@octave.org>
date Fri, 07 Dec 2012 18:03:01 -0500
parents 54e8c2527a9e
children 0f1a143e5002
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 ## Copyright (C) 2010 Martin Hepperle
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 ##
15746
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
3 ## This file is part of Octave.
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 ##
15746
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
6 ## under the terms of the GNU General Public License as published by
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
8 ## your option) any later version.
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
9 ##
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
13 ## General Public License for more details.
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 ##
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
15746
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
17 ## <http://www.gnu.org/licenses/>.
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 ## -*- texinfo -*-
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
20 ## @deftypefn {Function file} {[@var{sel}, @var{ok}] =} listdlg (@var{key}, @var{value}, @dots{})
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
21 ## Return user inputs from a list dialog box in a vector of
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
22 ## selection indices @var{sel} and a flag @var{ok} indicating how the
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
23 ## user closed the dialog box. The value of @var{ok} is 1 if the user
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
24 ## closed the box with the OK button, otherwise it is 0 and @var{sel} is
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
25 ## empty.
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 ##
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
27 ## The indices in @var{sel} are 1 based.
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 ##
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
29 ## The arguments are specified in form of @var{key}, @var{value} pairs.
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
30 ## The @code{"ListString"} argument pair must be specified.
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 ##
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
32 ## Valid @var{key} and @var{value} pairs are:
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 ##
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
34 ## @table @code
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
35 ## @item "ListString"
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 ## a cell array of strings comprising the content of the list.
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
37 ## @item "SelectionMode"
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
38 ## can be either @code{"Single"} or @code{"Multiple"}.
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
39 ## @item "ListSize"
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
40 ## a vector with two elements @var{width} and @var{height} defining
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
41 ## the size of the list field in pixels.
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
42 ## @item "InitialValue"
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 ## a vector containing 1-based indices of preselected elements.
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
44 ## @item "Name"
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 ## a string to be used as the dialog caption.
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
46 ## @item "PromptString"
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 ## a cell array of strings to be displayed above the list field.
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
48 ## @item "OKString"
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 ## a string used to label the OK button.
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
50 ## @item "CancelString"
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
51 ## a string used to label the Cancel button.
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 ## @end table
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 ##
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 ## Example:
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 ##
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 ## @example
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
57 ## [sel, ok] = listdlg ("ListString", @{"An item", "another", "yet another"@}, "SelectionMode", "Multiple" );
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
58 ## if (ok == 1)
15750
05c781cca57e use numel instead of length in newly imported java functions
John W. Eaton <jwe@octave.org>
parents: 15748
diff changeset
59 ## imax = numel (sel);
05c781cca57e use numel instead of length in newly imported java functions
John W. Eaton <jwe@octave.org>
parents: 15748
diff changeset
60 ## for i = 1:1:imax
05c781cca57e use numel instead of length in newly imported java functions
John W. Eaton <jwe@octave.org>
parents: 15748
diff changeset
61 ## disp (sel(i));
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
62 ## end
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
63 ## end
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 ## @end example
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 ##
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
66 ## @seealso{errordlg, helpdlg, inputdlg, questdlg, warndlg}
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 ## @end deftypefn
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68
15709
9fee0b741de6 Update Java dialog scrips to latest octave-forge status
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15625
diff changeset
69 function varargout = listdlg (varargin)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 if nargin < 2
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 print_usage ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 return;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 end
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
76 listcell = {""};
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
77 selmode = "single";
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
78 listsize = [300, 160];
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
79 initialvalue = 1;
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
80 name = "";
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
81 prompt = {""};
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
82 okstring = "OK";
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
83 cancelstring = "Cancel";
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
85 ## handle key, value pairs
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
86 for i = 1:2:nargin-1
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
87 if strcmp (varargin{i}, "ListString")
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
88 listcell = varargin{i+1};
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
89 elseif strcmp (varargin{i}, "SelectionMode")
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
90 selmode = varargin{i+1};
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
91 elseif strcmp (varargin{i}, "ListSize")
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
92 listsize = varargin{i+1};
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
93 elseif strcmp (varargin{i}, "InitialValue")
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
94 initialvalue = varargin{i+1};
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
95 elseif strcmp (varargin{i}, "Name")
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
96 name = varargin{i+1};
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
97 elseif strcmp (varargin{i}, "PromptString")
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
98 prompt = varargin{i+1};
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
99 elseif strcmp (varargin{i}, "OKString")
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
100 okstring = varargin{i+1};
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
101 elseif strcmp (varargin{i}, "CancelString")
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
102 cancelstring = varargin{i+1};
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
103 endif
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
104 endfor
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
105
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
106 ## make sure prompt strings are a cell array
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
107 if (! iscell (prompt))
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
108 prompt = {prompt};
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 end
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
111 ## make sure listcell strings are a cell array
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
112 if (! iscell (listcell))
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
113 listcell = {listcell};
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
114 endif
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
115
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
116 ## transform matrices to cell arrays of strings
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
117 listsize = arrayfun (@num2str, listsize, "UniformOutput", false);
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
118 initialvalue = arrayfun (@num2str, initialvalue, "UniformOutput", false);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
120 ret = java_invoke ("org.octave.JDialogBox", "listdlg", listcell,
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
121 selmode, listsize, initialvalue, name, prompt,
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
122 okstring, cancelstring);
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
123
15750
05c781cca57e use numel instead of length in newly imported java functions
John W. Eaton <jwe@octave.org>
parents: 15748
diff changeset
124 if (numel (ret) > 0)
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
125 varargout = {ret, 1};
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 else
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
127 varargout = {{}, 0};
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
128 endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
130 endfunction