public final class Browser extends java.lang.Object implements Fn.Presenter, Fn.KeepAlive, java.io.Flushable, java.util.concurrent.Executor, java.io.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(java.lang.String string,
java.lang.String... strings)
Creates new function with given parameter names and provided body.
|
Fn |
defineFn(java.lang.String string,
java.lang.String[] strings,
boolean[] blns)
Creates new function with given parameter names and provided body.
|
void |
displayPage(java.net.URL page,
java.lang.Runnable onPageLoad)
Opens the browser, loads provided page and when the
page is ready, it calls back to the provider runnable.
|
void |
execute(java.lang.Runnable r) |
void |
flush() |
void |
loadScript(java.io.Reader reader)
Loads a script into the browser JavaScript interpreter and
executes it.
|
public Browser()
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).public Browser(Browser.Config config)
config
- the configurationpublic final void execute(java.lang.Runnable r)
execute
in interface java.util.concurrent.Executor
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public Fn defineFn(java.lang.String string, java.lang.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(java.io.Reader reader) throws java.lang.Exception
Fn.Presenter
loadScript
in interface Fn.Presenter
reader
- the script to executejava.lang.Exception
- if something goes wrong, throw an exceptionpublic Fn defineFn(java.lang.String string, java.lang.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 java.io.IOException
flush
in interface java.io.Flushable
java.io.IOException
public final void displayPage(java.net.URL page, java.lang.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.