public final class Browser extends Object implements Fn.Presenter, Fn.KeepAlive, Flushable, Executor, Closeable
Fn.Presenter
. It starts local server and
launches browser that connects to it. Use Browser.Config
to
configure the actual browser to be started.
To use this presenter specify following dependency:
<dependency> <groupId>org.netbeans.html.browser</groupId> <artifactId>browser</artifactId> <version>1.x</version> </dependency>
Modifier and Type | Class and Description |
---|---|
static class |
Browser.Config
Parameters to configure
Browser . |
Constructor and Description |
---|
Browser()
Default constructor.
|
Browser(Browser.Config config)
Browser configured by provided config.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
Fn |
defineFn(String string,
String... strings)
Creates new function with given parameter names and provided body.
|
Fn |
defineFn(String string,
String[] strings,
boolean[] blns)
Creates new function with given parameter names and provided body.
|
void |
displayPage(URL page,
Runnable onPageLoad)
Opens the browser, loads provided page and when the
page is ready, it calls back to the provider runnable.
|
void |
execute(Runnable r) |
void |
flush() |
void |
loadScript(Reader reader)
Loads a script into the browser JavaScript interpreter and
executes it.
|
public Browser() throws Exception
com.dukescript.presenters.browser
property.
It can have following values:
Desktop.browse(java.net.URI)
to
launch a browsercom.dukescript.presenters.browserPort
property that
can specify a fixed port to open the server at
xdg-open
(default LINUX command to launch a browser from a shell script).Exception
public Browser(Browser.Config config)
config
- the configurationpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public Fn defineFn(String string, String... strings)
Fn.Presenter
defineFn
in interface Fn.Presenter
string
- the body of the function. Can refer to variables named
as names
strings
- names of parameters of the function - these will be
available when the code
body executespublic void loadScript(Reader reader) throws Exception
Fn.Presenter
loadScript
in interface Fn.Presenter
reader
- the script to executeException
- if something goes wrong, throw an exceptionpublic Fn defineFn(String string, String[] strings, boolean[] blns)
Fn.KeepAlive
defineFn
in interface Fn.KeepAlive
string
- the body of the function. Can refer to variables named
as names
strings
- names of parameters of the function - these will be
available when the code
body executesblns
- array of booleans describing for each parameter
whether it should be kept alive or not. Length of the array
must be the same as length of names
array. The
array may be null
to signal that all parameters
should be kept alive.public void flush() throws IOException
flush
in interface Flushable
IOException
public final void displayPage(URL page, Runnable onPageLoad)
Fn.Presenter
displayPage
in interface Fn.Presenter
page
- the URL for the page to displayonPageLoad
- callback when the page is readyCopyright © 2021 The Apache Software Foundation. All rights reserved.