public final class JXBrowserPresenter extends Object implements Executor
Fn.Presenter
. Use via BrowserBuilder
to launch whole application or use JXBrowserPresenter.create(java.lang.Class<?>)
to
instantiate presenter and its component directly. Then access
the browser event thread with JXBrowserPresenter.execute(java.lang.Runnable)
method.Constructor and Description |
---|
JXBrowserPresenter()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
static JXBrowserPresenter |
create(Class<?> type)
Creates new presenter for given UI component system.
|
static <T> JXBrowserPresenter |
create(Class<T> type,
T instance)
Creates new presenter for given component.
|
Fn |
defineFn(String code,
String... args)
Use
JavaScriptBody instead of using this method directly. |
Fn |
defineFn(String code,
String[] args,
boolean[] keepAlive)
Use
JavaScriptBody instead of using this method directly. |
void |
displayPage(URL url,
Runnable r)
Use
BrowserBuilder instead of using this method directly. |
void |
execute(Runnable command)
Entry point to the browser event loop.
|
<T> T |
getComponent(Class<T> type)
Obtains the associated component.
|
void |
loadScript(Reader reader)
Use
JavaScriptResource instead of using this method directly. |
Object |
toJava(Object js)
Internal callback from
Fn.FromJavaScript . |
Object |
toJavaScript(Object value)
Internal callback from
Fn.ToJavaScript . |
public JXBrowserPresenter()
ServiceLoader
.
Use JXBrowserPresenter.create(java.lang.Class)
for embedding browser into
your Swing or JavaFX application.public static JXBrowserPresenter create(Class<?> type)
JXBrowserPresenter.getComponent(java.lang.Class)
to obtain the element embeddable into UI of the overall application.
Use JXBrowserPresenter.execute(java.lang.Runnable)
to execute client code
inside of the browser associated with this presenter. Here is an example
of embedding the browser into Swing application:
The code to initialize the JavaFXJXBrowserPresenter
presenter =JXBrowserPresenter
.create(JComponent
.class); finalJComponent
browser = presenter.getComponent(JComponent
.class); assert browser.getParent() == null : "Component isn't in AWT hierarchy";JFrame
f = newJFrame
(); f.getContentPane().add(browser,BorderLayout
.CENTER); f.setVisible(true); // initial load of the page finalURL
pageUrl = getClass().getResource("yourPage.html"); assert pageUrl != null : "Page found"; presenter.displayPage(pageUrl, () -> { assertEventQueue
.isDispatchThread(); onPageLoadCode.runInThePresenter(); }); // access the page any time later presenter.execute(() -> { assertEventQueue
.isDispatchThread(); myCode.runInThePresenter(); });
Application
is almost
the same:
JXBrowserPresenter
presenter =JXBrowserPresenter
.create(Node
.class); finalNode
browser = presenter.getComponent(Node
.class); assert browser.getParent() == null : "Node isn't in FX hierarchy";BorderPane
borderPane = newBorderPane
(); borderPane.setTop(newLabel
("JavaFX Label")); borderPane.setCenter(browser);Scene
scene = newScene
(borderPane); stage.setTitle("JavaFX and FXBrowserView"); stage.setScene(scene); stage.show(); // initial load of the page finalURL
pageUrl = getClass().getResource("yourPage.html"); assert pageUrl != null : "Page found"; presenter.displayPage(pageUrl, () -> { assertPlatform
.isFxApplicationThread(); onPageLoadCode.runInThePresenter(); }); // access the page any time later presenter.execute(() -> { assertPlatform
.isFxApplicationThread(); myCode.runInThePresenter(); });
type
- the type of component to create - either JComponent
or Node
classJXBrowserPresenter.getComponent(java.lang.Class<T>)
method returning
instance of associated componentpublic static <T> JXBrowserPresenter create(Class<T> type, T instance)
JXBrowserPresenter
for it then.
Use JXBrowserPresenter.execute(java.lang.Runnable)
to execute client code
inside of the browser associated with this presenter. Here is an example
of embedding the BrowserView
component into Swing application:
com.teamdev.jxbrowser.chromium.swing.BrowserView bw; bw = new com.teamdev.jxbrowser.chromium.swing.BrowserView();The code to initialize the JavaFXJXBrowserPresenter
presenter =JXBrowserPresenter
.create(JComponent
.class, bw);
BrowserView
component is almost the same:
com.teamdev.jxbrowser.chromium.javafx.BrowserView bw; bw = new com.teamdev.jxbrowser.chromium.javafx.BrowserView();JXBrowserPresenter
presenter =JXBrowserPresenter
.create(Node
.class, bw);
T
- the type of the componenttype
- the type of component to create - either JComponent
or Node
classinstance
- either null
or instance of
BrowserView
or
BrowserView
JXBrowserPresenter.getComponent(java.lang.Class<T>)
method returning
instance
of provided Swing or JavaFX componentpublic <T> T getComponent(Class<T> type)
proper factory method
arguments.T
- the type of requested componenttype
- the type of requested component - either JComponent
or Node
null
if the
requested type doesn't matchpublic void execute(Runnable command)
This method may be called from any thread - in such case the method
returns immedialtely and the command is executed later on the
appropriate thread. If the caller is already on the right browser thread,
the command
is executed immediately before this method returns.
public Fn defineFn(String code, String... args)
JavaScriptBody
instead of using this method directly.
Read more in the documentation for net.java.html.js
package.defineFn
in interface Fn.Presenter
public Fn defineFn(String code, String[] args, boolean[] keepAlive)
JavaScriptBody
instead of using this method directly.
Read more in the documentation for net.java.html.js
package.defineFn
in interface Fn.KeepAlive
public void displayPage(URL url, Runnable r)
BrowserBuilder
instead of using this method directly.displayPage
in interface Fn.Presenter
public void loadScript(Reader reader) throws Exception
JavaScriptResource
instead of using this method directly.
Read more in the documentation for net.java.html.js
package.loadScript
in interface Fn.Presenter
Exception
public Object toJavaScript(Object value)
Fn.ToJavaScript
.toJavaScript
in interface Fn.ToJavaScript
public Object toJava(Object js)
Fn.FromJavaScript
.toJava
in interface Fn.FromJavaScript
Copyright © 2019. All rights reserved.