|
Direct Java (Swing or AWT) Rendering in Lobo
Lobo 0.98+ [download]
can directly render Java/Swing source files. Lobo treats Java
as a first-class citizen, in much the same manner it treats HTML. This means that:
- The deploy-test cycle of client-side Java code in Lobo is quicker and more convenient. There is no need to pre-compile and package Java code or use HTML pages.
- The source code of a Java class is available for browser users to examine.
- Java code in Lobo has access to various capabilities of the browser and
can be more web oriented.
- Lobo can load Java source code generated by server-side technology such as JSP, PHP, RoR and others.
- Java code loaded by Lobo is potentially indexable by search engines.
Requirements
Direct Java rendering in Lobo requires
JRE 1.6+, even
though the browser itself only requires JRE 1.5+.
Security Restrictions
JavaFX/Java code loaded by Lobo from a remote location
is run with security
restrictions equivalent to those of an unsigned applet.
Note, however, that Lobo provides capabilities that are
not currently available to applets, such as
managed stores.
MIME Type
The MIME type of a Java source document is expected to be text/x-java-source,
but other MIME types like application/octet-stream and text/plain
will work provided the URL ends in .java.
Java APIs Available in Lobo
A Java class loaded by Lobo should be assumed to only have access to the following APIs:
- Java Platform SE 6 API.
- Lobo Extensions and Clientlets API (lobo-pub.jar).
- Classes from locations specified in the
classpath or sourcepath directives (explained below).
Directives
Java/JavaFX "pages" in Lobo use standard Java/JavaFX syntax. You can,
nevertheless, add a special comment that contains
compilation and rendering directives for Lobo. The comment starts with /*!
and ends with */. The content of the comment should be in
property-file syntax, except an asterisk is allowed at the beginning of
every line. Directives (properties) understood by Lobo, all optional, include:
- title: The title of the "page". This should be the
window title when the page is rendered, and it's
also used in history lists and so on.
- description: A description of the "page". This is saved along
with Lobo bookmarks and is potentially indexable
by search engines.
- sourcepath: A list of comma-separated URLs required to locate other source files during compilation.
- classpath: A list of comma-separated URLs, typically JAR file locations,
required by the "page" at run-time.
- sourcelist: If
sourcepath contains URLs ending
in slash (directories instead of JAR files) this property should contain a
list of comma-separated file paths required during the build of
the main compilation unit. A file path consists of the package name, with its dots
replaced by forward slashes, followed by a forward slash and the file name,
e.g. com/acme/package/File.java or com/acme/package/File.fx.
- classlist: If
classpath contains URLs ending
in slash (directories instead of JAR files) this property should contain a
list of comma-separated file paths required during the build of the main
compilation unit. A file path consists of the package name, with its dots
replaced by forward slashes, followed by a forward slash and the file name,
e.g. com/acme/package/File.class.
- use-preferred-size: If
true, the component
is rendered using its preferred size, if possible, and centered in the page.
Otherwise, the component's size is the same as the page's.
Clientlet Context Access
A request-response thread in Lobo has access to the current
ClientletContext
instance, obtained by calling ClientletAccess.getCurrentClientletContext().
This can be used by scripts to perform various browser tasks, such as navigating
away from the page, opening alert windows, making requests through Lobo, creating
browser frames, or accessing
managed stores.
What is Rendered
Obviously, only certain classes can be rendered: Those that
can be assigned to java.awt.Component (including
javax.swing.JComponent and java.awt.Window)
plus any JavaFX classes
assignable to Stage, Scene or Node.
Programmatic use of Lobo
We have a Browser API (GPL) that will
load Java/JavaFX code, much like it loads HTML, provided the
pertinent browser extensions are available at run-time. This means
a Swing application can embed Lobo and load remote JavaFX/Java code via
the Lobo API.
Examples
The following examples are not intended to be Java examples.
These are examples of some basic things you can do with Java in Lobo.
- Visit a page when a button is pressed.
This is a very simple example whereby navigation is
redirected to a URL entered in a text field when the user
presses a button.
NavigateTo.java
- Using a third-party library.
This example makes use of JFreeChart
to display a simple three-dimensional pie chart. The first time
this program is loaded, you will note library JAR files are loaded
from the website where the page resides. On subsequent page loads,
JAR files should be retrieved from the Lobo cache.
ChartDemo.java
This is how ChartDemo.java renders in Lobo:
Feedback
If you have successfully tried Java or JavaFX code in Lobo, feel free to
post your source code URLs at the
Open Discussion Forum.
If something doesn't work quite right in Lobo's support
of Java/JavaFX, please use the
Help Forum
to tell us.
See Also
External Links
Support The Project
|