Mercurial > octave
annotate scripts/java/usejava.m @ 33632:fed0dc6fd44c default tip
remove unused variable from libgui/module.mk
* libgui/module.mk: remove empty variable OCTAVE_GUI_EDITOR_MOC
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Mon, 27 May 2024 19:42:05 +0200 |
parents | 2e484f9f1f18 |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31706
diff
changeset
|
3 ## Copyright (C) 2012-2024 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## or <https://octave.org/copyright/>. |
13826
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
7 ## |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
8 ## This file is part of Octave. |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23405
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
13826
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23405
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22497
diff
changeset
|
13 ## (at your option) any later version. |
13826
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
14 ## |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
15 ## Octave is distributed in the hope that it will be useful, but |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22497
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22497
diff
changeset
|
18 ## GNU General Public License for more details. |
13826
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
19 ## |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
20 ## You should have received a copy of the GNU General Public License |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23405
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
13826
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
25 |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
26 ## -*- texinfo -*- |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
27 ## @deftypefn {} {@var{tf} =} usejava (@var{feature}) |
14353
937035390ec0
usejava.m: Update to use try/catch architecture
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
28 ## Return true if the Java element @var{feature} is available. |
13826
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
29 ## |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
30 ## Possible features are: |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
31 ## |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
32 ## @table @asis |
25003
2365c2661b3c
doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
33 ## @item @nospell{@qcode{"awt"}} |
13826
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
34 ## Abstract Window Toolkit for GUIs. |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
35 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16768
diff
changeset
|
36 ## @item @qcode{"desktop"} |
13826
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
37 ## Interactive desktop is running. |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
38 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16768
diff
changeset
|
39 ## @item @qcode{"jvm"} |
13826
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
40 ## Java Virtual Machine. |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
41 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16768
diff
changeset
|
42 ## @item @qcode{"swing"} |
13826
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
43 ## Swing components for lightweight GUIs. |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
44 ## @end table |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
45 ## |
14353
937035390ec0
usejava.m: Update to use try/catch architecture
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
46 ## @code{usejava} determines if specific Java features are available in an |
15805
420b5603cbbf
build: Move usejava.m from scripts/miscellaneous to scripts/java directory.
Rik <rik@octave.org>
parents:
14353
diff
changeset
|
47 ## Octave session. This function is provided for scripts which may alter |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16768
diff
changeset
|
48 ## their behavior based on the availability of Java. The feature |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16768
diff
changeset
|
49 ## @qcode{"desktop"} always returns @code{false} as Octave has no Java-based |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16768
diff
changeset
|
50 ## desktop. Other features may be available if Octave was compiled with the |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16768
diff
changeset
|
51 ## Java Interface and Java is installed. |
18721
700714c099a2
Add new function javachk for Matlab compatibility.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
52 ## @seealso{javachk} |
13826
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
53 ## @end deftypefn |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
54 |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
55 function tf = usejava (feature) |
13826
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
56 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
57 if (nargin < 1 || ! ischar (feature)) |
13826
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
58 print_usage (); |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
59 endif |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
60 |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
61 tf = false; |
13826
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
62 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
63 switch (feature) |
15805
420b5603cbbf
build: Move usejava.m from scripts/miscellaneous to scripts/java directory.
Rik <rik@octave.org>
parents:
14353
diff
changeset
|
64 ## For each feature, try methods() on a Java class of a feature |
14353
937035390ec0
usejava.m: Update to use try/catch architecture
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
65 case "awt" |
937035390ec0
usejava.m: Update to use try/catch architecture
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
66 try |
15805
420b5603cbbf
build: Move usejava.m from scripts/miscellaneous to scripts/java directory.
Rik <rik@octave.org>
parents:
14353
diff
changeset
|
67 dum = methods ("java.awt.Frame"); |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
68 tf = ! javaMethod ("isHeadless", "java.awt.GraphicsEnvironment"); |
14353
937035390ec0
usejava.m: Update to use try/catch architecture
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
69 end_try_catch |
937035390ec0
usejava.m: Update to use try/catch architecture
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
70 case "desktop" |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
71 ## Octave has no Java based GUI/desktop, leave tf = false |
14353
937035390ec0
usejava.m: Update to use try/catch architecture
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
72 case "jvm" |
937035390ec0
usejava.m: Update to use try/catch architecture
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
73 try |
15805
420b5603cbbf
build: Move usejava.m from scripts/miscellaneous to scripts/java directory.
Rik <rik@octave.org>
parents:
14353
diff
changeset
|
74 dum = methods ("java.lang.Runtime"); |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
75 tf = true; |
14353
937035390ec0
usejava.m: Update to use try/catch architecture
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
76 end_try_catch |
937035390ec0
usejava.m: Update to use try/catch architecture
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
77 case "swing" |
937035390ec0
usejava.m: Update to use try/catch architecture
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
78 try |
15805
420b5603cbbf
build: Move usejava.m from scripts/miscellaneous to scripts/java directory.
Rik <rik@octave.org>
parents:
14353
diff
changeset
|
79 dum = methods ("javax.swing.Popup"); |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
80 tf = ! javaMethod ("isHeadless", "java.awt.GraphicsEnvironment"); |
14353
937035390ec0
usejava.m: Update to use try/catch architecture
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
81 end_try_catch |
937035390ec0
usejava.m: Update to use try/catch architecture
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
82 otherwise |
22760
c4d80b9d2898
maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
83 error ("usejava: unrecognized FEATURE '%s'", feature); |
14353
937035390ec0
usejava.m: Update to use try/catch architecture
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
84 endswitch |
13826
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
85 |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
86 endfunction |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
87 |
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
88 |
14353
937035390ec0
usejava.m: Update to use try/catch architecture
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
89 %!assert (usejava ("desktop"), false) |
13826
847812137666
Implement new usejava function for Matlab compatability.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
90 |
23405
32ec90068be5
use %!testif runtime tests to properly skip java tests
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
91 %!testif HAVE_JAVA; usejava ("jvm") |
15805
420b5603cbbf
build: Move usejava.m from scripts/miscellaneous to scripts/java directory.
Rik <rik@octave.org>
parents:
14353
diff
changeset
|
92 %! assert (usejava ("jvm"), true); |
420b5603cbbf
build: Move usejava.m from scripts/miscellaneous to scripts/java directory.
Rik <rik@octave.org>
parents:
14353
diff
changeset
|
93 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
94 ## Test input validation |
28886
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
27985
diff
changeset
|
95 %!error <Invalid call> usejava () |
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
27985
diff
changeset
|
96 %!error <Invalid call> usejava (1) |
22765
01aae08a0105
maint: Rename variables to match documentation in m-files.
Rik <rik@octave.org>
parents:
22760
diff
changeset
|
97 %!error <unrecognized FEATURE> usejava ("abc") |