comparison scripts/java/usejava.m @ 15805:420b5603cbbf

build: Move usejava.m from scripts/miscellaneous to scripts/java directory. * scripts/java/module.mk: Add usejava.m to build system. * scripts/java/usejava.m: Added m-file. * scripts/miscellaneous/module.mk: Remove usejava from miscellaneous directory build. * scripts/miscellaneous/usejava.m: Removed m-file.
author Rik <rik@octave.org>
date Mon, 17 Dec 2012 10:16:08 -0800
parents scripts/miscellaneous/usejava.m@937035390ec0
children e2de3c8882be
comparison
equal deleted inserted replaced
15804:b15cfb7ed0eb 15805:420b5603cbbf
1 ## Copyright (C) 2012 Rik Wehbring
2 ## Parts Copyright (C) 2012 Philip Nienhuis <prnienhuis@users.sf.net>
3 ##
4 ## This file is part of Octave.
5 ##
6 ## Octave is free software; you can redistribute it and/or modify it
7 ## under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or (at
9 ## your option) any later version.
10 ##
11 ## Octave is distributed in the hope that it will be useful, but
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ## General Public License for more details.
15 ##
16 ## You should have received a copy of the GNU General Public License
17 ## along with Octave; see the file COPYING. If not, see
18 ## <http://www.gnu.org/licenses/>.
19
20 ## -*- texinfo -*-
21 ## @deftypefn {Function File} {} usejava (@var{feature})
22 ## Return true if the Java element @var{feature} is available.
23 ##
24 ## Possible features are:
25 ##
26 ## @table @asis
27 ## @item "awt"
28 ## Abstract Window Toolkit for GUIs.
29 ##
30 ## @item "desktop"
31 ## Interactive desktop is running.
32 ##
33 ## @item "jvm"
34 ## Java Virtual Machine.
35 ##
36 ## @item "swing"
37 ## Swing components for lightweight GUIs.
38 ## @end table
39 ##
40 ## @code{usejava} determines if specific Java features are available in an
41 ## Octave session. This function is provided for scripts which may alter
42 ## their behavior based on the availability of Java. The feature "desktop"
43 ## always returns @code{false} as Octave has no Java-based desktop. Other
44 ## features may be available if Octave was compiled with the Java Interface
45 ## and Java is installed.
46 ## @end deftypefn
47
48 function retval = usejava (feature)
49
50 if (nargin != 1 || ! ischar (feature))
51 print_usage ();
52 endif
53
54 retval = false;
55
56 switch feature
57 ## For each feature, try methods() on a Java class of a feature
58 case "awt"
59 try
60 dum = methods ("java.awt.Frame");
61 retval = true;
62 end_try_catch
63 case "desktop"
64 ## Octave has no Java based GUI/desktop, leave retval = false
65 case "jvm"
66 try
67 dum = methods ("java.lang.Runtime");
68 retval = true;
69 end_try_catch
70 case "swing"
71 try
72 dum = methods ("javax.swing.Popup");
73 retval = true;
74 end_try_catch
75 otherwise
76 error ("usejava: unrecognized feature '%s'", feature);
77 endswitch
78
79 endfunction
80
81
82 %!assert (usejava ("desktop"), false)
83
84 %!testif HAVE_JAVA
85 %! assert (usejava ("jvm"), true);
86
87 %% Test input validation
88 %!error usejava ()
89 %!error usejava (1, 2)
90 %!error usejava (1)
91 %!error <unrecognized feature> usejava ("abc")
92