public final class BrowserBuilder extends Object
public static void main(String... args) { BrowserBuilder.The above will loadnewBrowser()
.loadClass(YourMain.class)
.loadPage("index.html")
.locale
(Locale.getDefault()
).invoke("initialized", args)
.BrowserBuilder.showAndWait()
; System.exit(0); }
YourMain
class via
a special classloader, it will locate an index.html
(relative
to YourMain
class) and show it in a browser window. When the
initialization is over, a public static method initialized
in YourMain
will be called with provided string parameters.
This module provides only API for building browsers. To use it properly one also needs an implementation on the classpath of one's application. For example use:
<dependency> <groupId>org.netbeans.html</groupId> <artifactId>net.java.html.boot.fx</artifactId> <scope>runtime</scope> </dependency>
Modifier and Type | Method and Description |
---|---|
BrowserBuilder |
classloader(ClassLoader l)
Loader to use when searching for classes to initialize.
|
BrowserBuilder |
invoke(String methodName,
String... args)
Specifies callback method to notify the application that the browser is ready.
|
BrowserBuilder |
loadClass(Class<?> mainClass)
The class to load when the browser is initialized.
|
BrowserBuilder |
loadFinished(Runnable r)
Allows one to specify a runnable that should be invoked when a load
of a page is finished.
|
BrowserBuilder |
loadPage(String page)
Page to load into the browser.
|
BrowserBuilder |
locale(Locale locale)
Locale to use when searching for an initial
page to load . |
static BrowserBuilder |
newBrowser(Object... context)
Entry method to obtain a new browser builder.
|
void |
showAndWait()
Shows the browser, loads specified page in and executes the
initialization method . |
public static BrowserBuilder newBrowser(Object... context)
BrowserBuilder.loadClass(java.lang.Class)
and
BrowserBuilder.loadPage(java.lang.String)
.
Since introduction of technology identifiers
the
provided context
objects are also passed to the
context
when it is being
created
and can influence the selection
of available technologies
(like Technology
,
Transfer
or
WSTransfer
) by name.context
- any instances that should be available to the builder -
implementation dependantpublic BrowserBuilder loadClass(Class<?> mainClass)
JavaScriptBody
and co.).mainClass
- the class to load and resolve when the browser is readypublic BrowserBuilder loadFinished(Runnable r)
BrowserBuilder.loadClass(java.lang.Class)
and
BrowserBuilder.invoke(java.lang.String, java.lang.String...)
methods.r
- the code to run when the page is loadedpublic BrowserBuilder loadPage(String page)
page
represents
a URL
known to the Java system, the URL is passed to the browser.
If system property browser.rootdir
is specified, then a
file page
relative to this directory is used as the URL.
If no such file exists, the system seeks for the
resource via Class.getResource(java.lang.String)
method (relative to the specified class
).
If such resource is not found, a file relative to the location JAR
that contains the main class
is
searched for.
The search honors provided BrowserBuilder.locale
, if specified.
E.g. it will prefer index_cs.html
over index.html
if the locale is set to cs_CZ
.
page
- the location (relative, absolute, or URL) of a page to loadpublic BrowserBuilder locale(Locale locale)
page to load
.
Localization is best done by providing different versions of the
initial page with appropriate suffixes (like index_cs.html
).
Then one can call this method with value of Locale.getDefault()
to instruct the builder to use the user's current locale.locale
- the locale to use or null
if no suffix search should be performedpublic BrowserBuilder invoke(String methodName, String... args)
BrowserBuilder.loadClass(java.lang.Class)
which takes an array of String
argument. The method is called on the browser dispatch thread one
the browser finishes loading of the HTML page
.methodName
- name of a method to seek forargs
- parameters to pass to the methodpublic BrowserBuilder classloader(ClassLoader l)
Fn.Presenter
and fill
BrwsrCtx
in.
Specifying special classloader may be useful in modular systems,
like OSGi, where one needs to load classes from many otherwise independent
modules.l
- the loader to use (or null
)public void showAndWait()
initialization method
.
The method returns when the browser is closed.NullPointerException
- if some of essential parameters (like page
or
class
have not been specifiedCopyright © 2018 NetBeans. All rights reserved.