comparison scripts/java/inputdlg.m @ 15625:acf0addfc610

include Octave Forge java package in core Octave * scripts/java: New directory tree. * scripts/Makefile.am: Include java/module.mk. (JAR_FILES): New variable. (nobase_fcnfile_DATA): Include $(JAR_FILES) in the list. (all-local): Depend on $(JAR_FILES). (java/PKG_ADD, java_GEN_FCN_FILES, java/$(octave_dirstamp)): New rules. * libinterp/link-deps (LIBOCTINTERP_LINK_DEP): Include $(JAVA_LIBS) in the list. * dldfcn/__java__.h, dldfcn/__java__.cc: New files. * dldfcn/module-files (__java__.cc): New file description. * doc/interpreter/java.txi: New file. * doc/interpreter/octave.texi: Include java.texi. * doc/interpreter/java-images: New directory. * doc/interpreter/Makefile.am (JAVA_IMAGES): New variable. (IMAGES): Include $(JAVA_IMAGSES) in the list. (MUNGED_TEXI_SRC): Include java.texi in the list. * configure.ac: Check for Java libraries and tools. Include Java info in the summary message. * build-aux/common.mk (JAVA_CPPFLAGS, JAVA_LIBS): New variables. * NEWS: Update. * contributors.in: Include Martin Hepperle in the list.
author John W. Eaton <jwe@octave.org>
date Fri, 23 Nov 2012 15:29:13 -0500
parents
children 9fee0b741de6
comparison
equal deleted inserted replaced
15624:550147454137 15625:acf0addfc610
1 ## Copyright (C) 2010 Martin Hepperle
2 ##
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function file} {@var{P} =} inputdlg (@var{PROMPT} [,@var{TITLE} [,@var{ROWSCOLS}, @var{DEFAULTS}]])
18 ##
19 ## Returns the user's inputs from a multi-textfield dialog box in form of a cell array of strings.
20 ## If the dialog is closed by the Cancel button, an empty cell array is returned.
21 ##
22 ## @table @samp
23 ## @item PROMPT
24 ## The first argument @var{PROMPT} is mandatory.
25 ## It is a cell array with strings labeling each textfield.
26 ## @item TITLE
27 ## The optional string @var{TITLE} can be used as the caption of the dialog.
28 ## @item ROWSCOLS
29 ## The size of the text fields can be defined by the argument @var{ROWSCOLS},
30 ## which can have three forms:
31 ## - a scalar value which defines the number of rows used for each text field.
32 ## - a vector which defines the individual number of rows used for each text field.
33 ## - a matrix which defines the individual number of rows and columns used for each text field.
34 ## @item DEFAULTS
35 ## It is possible to place default values into the text fields by supplying
36 ## the a cell array of strings or number for the argument @var{DEFAULTS}.
37 ## @end table
38 ##
39 ## @end deftypefn
40 ## @seealso{errordlg, helpdlg, listdlg, questdlg, warndlg}
41
42 function varargout = inputdlg(prompt,varargin)
43
44 switch length (varargin)
45 case 0
46 title = "Input Dialog";
47 lineNo = 1;
48 defaults = cellstr(cell(size(prompt)));
49 case 1
50 title = varargin{1};
51 lineNo = 1;
52 defaults = cellstr(cell(size(prompt)));
53 case 2
54 title = varargin{1};
55 lineNo = varargin{2};
56 defaults = cellstr(cell(size(prompt)));
57 otherwise
58 title = varargin{1};
59 lineNo = varargin{2};
60 defaults = varargin{3};
61 end
62
63
64 % specification of text field sizes as in Matlab
65 % Matlab requires a matrix for lineNo, not a cell array...
66 % rc = [1,10; 2,20; 3,30];
67 % c1 c2
68 % r1 1 10 first text field is 1x10
69 % r2 2 20 second text field is 2x20
70 % r3 3 30 third text field is 3x30
71 if isscalar(lineNo)
72 % only scalar value in lineTo, copy from lineNo and add defaults
73 rowscols = zeros(size(prompt)(2),2);
74 % cols
75 rowscols(:,2) = 25;
76 rowscols(:,1) = lineNo;
77 elseif isvector(lineNo)
78 % only one column in lineTo, copy from vector lineNo and add defaults
79 rowscols = zeros(size(prompt)(2),2);
80 % rows from colum vector lineNo, columns are set to default
81 rowscols(:,2) = 25;
82 rowscols(:,1) = lineNo(:);
83 elseif ismatrix(lineNo)
84 if (size(lineNo)(1) == size(prompt)(2)) && (size(lineNo)(2) == 2)
85 % (rows x columns) match, copy array lineNo
86 rowscols = lineNo;
87 end
88 else
89 % dunno
90 disp('inputdlg: unknown form of lineNo argument.');
91 lineNo
92 end
93
94 % convert numeric values in defaults cell array to strings
95 defs = cellfun(@num2str,defaults,'UniformOutput',false);
96 rc = arrayfun(@num2str,rowscols,'UniformOutput',false);
97
98 user_inputs = java_invoke ("org.octave.JDialogBox", "inputdlg", prompt, title, rc, defs);
99
100 if isempty(user_inputs)
101 varargout{1} = {}; % empty
102 else
103 varargout{1} = cellstr (user_inputs);
104 end
105
106 end