Skip to content

Commit

Permalink
Merging with master
Browse files Browse the repository at this point in the history
  • Loading branch information
jtulach committed Dec 18, 2020
2 parents 27af175 + f61392c commit c0583d1
Show file tree
Hide file tree
Showing 54 changed files with 591 additions and 321 deletions.
3 changes: 2 additions & 1 deletion Jenkinsfile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
* under the License.
*/

asfStandardBuild xvfb:true,cmdline:"clean install javadoc:aggregate site:jar"
asfStandardBuild jdk:"jdk_11_latest",xvfb:true,cmdline:"clean install"
asfStandardBuild jdk:"jdk_11_latest",xvfb:true,cmdline:"javadoc:aggregate site:jar"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
In need of cross platform, client side interaction between Java and JavaScript?

[![Travis](https://travis-ci.org/apache/netbeans-html4j.svg?branch=master)](https://travis-ci.org/apache/netbeans-html4j)
[![Linux](https://builds.apache.org/buildStatus/icon?job=netbeans-html4j-linux)](https://builds.apache.org/job/netbeans-html4j-linux/)
[![Windows](https://builds.apache.org/buildStatus/icon?job=netbeans-html4j-windows)](https://builds.apache.org/job/netbeans-html4j-windows)
[![Linux](https://ci-builds.apache.org/job/Netbeans/job/netbeans-html4j-linux/badge/icon)](https://ci-builds.apache.org/job/Netbeans/job/netbeans-html4j-linux/)
[![Windows](https://ci-builds.apache.org/job/Netbeans/job/netbeans-html4j-windows/badge/icon)](https://ci-builds.apache.org/job/Netbeans/job/netbeans-html4j-windows/)

The HTML/Java library provides [basic building blocks](https://bits.netbeans.org/html+java/dev/net/java/html/js/package-summary.html)
as well as advanced [high level concepts](https://bits.netbeans.org/html+java/dev/net/java/html/json/Model.html)
Expand Down Expand Up @@ -77,7 +77,7 @@ $ mvn clean install
```

and create a pull request, which may then be merged into the
official [Apache repository](https://gitbox.apache.org/repos/asf?p=netbeans-html4j.git).
official [Apache repository](https://gitbox.apache.org/repos/asf/netbeans-html4j.git).

### Full History

Expand Down
3 changes: 3 additions & 0 deletions boot-agent-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<artifactId>boot-agent-test</artifactId>
<packaging>jar</packaging>
<name>Dynamic Boot Test</name>
<properties>
<skipTests>${skipJavaFXTests}</skipTests>
</properties>
<build>
<plugins>
<plugin>
Expand Down
26 changes: 24 additions & 2 deletions boot-fx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<publicPackages>net.java.html.boot.fx</publicPackages>
<skipTests>${skipJavaFXTests}</skipTests>
</properties>
<build>
<plugins>
Expand Down Expand Up @@ -90,7 +91,28 @@
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<artifactId>webswing-app-toolkit</artifactId>
<groupId>org.webswing</groupId>
<version>20.1.8</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>jdk.jsobject.modpatch</groupId>
<artifactId>jdk.jsobject.modpatch</artifactId>
</exclusion>
<exclusion>
<groupId>java.desktop.modpatch</groupId>
<artifactId>java.desktop.modpatch</artifactId>
</exclusion>
<exclusion>
<groupId>org.webswing</groupId>
<artifactId>webswing-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<description>A presentation provider to show JavaFX WebView
when a Java/HTML based application is about to boot.</description>
<description>A presentation provider to show JavaFX WebView
when a Java/HTML based application is about to boot.
</description>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ JSObject createPOJOWrapper(int hash, int id) {
throw new IllegalStateException(ex);
}
}
return (JSObject) newPOJOImpl.call("fxBrwsrId", hash, id);
return (JSObject) newPOJOImpl.call("fxBrwsrId", new Object[] { hash, id });
}

final Object undefined() {
Expand All @@ -244,13 +244,13 @@ final Object undefined() {
}

private int getArrayLength(Object val) throws JSException {
int length = ((Number) arraySizeFn().call("array", val, null)).intValue();
int length = ((Number) arraySizeFn().call("array", new Object[] { val, null })).intValue();
return length;
}

private Object[] toArray(int length, Object val) throws JSException {
Object[] arr = new Object[length];
arraySizeFn().call("array", val, arr);
arraySizeFn().call("array", new Object[] { val, arr });
checkArray(arr);
return arr;
}
Expand Down Expand Up @@ -565,7 +565,7 @@ Object realValue(JSObject obj) {
synchronized (this) {
this.hash = -1;
this.id = -1;
obj.call("fxBrwsrId", this);
obj.call("fxBrwsrId", new Object[] { this });
assert this.hash != -1;
assert this.id != -1;
resultHash = this.hash;
Expand Down
34 changes: 5 additions & 29 deletions boot-fx/src/main/java/org/netbeans/html/boot/fx/FXBrwsr.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ private WebView newView(final URL url, final AbstractFXPresenter onLoad) {
}

attachHandlers(view, newStage);
final FXConsole fxConsole = new FXConsole(view, newStage);
bp.setCenter(view);
final Worker<Void> w = view.getEngine().getLoadWorker();
w.stateProperty().addListener(new ChangeListener<Worker.State>() {
Expand All @@ -238,7 +239,7 @@ private WebView newView(final URL url, final AbstractFXPresenter onLoad) {
public void changed(ObservableValue<? extends Worker.State> ov, Worker.State t, Worker.State newState) {
if (newState.equals(Worker.State.SUCCEEDED)) {
if (checkValid()) {
FXConsole.register(view.getEngine());
fxConsole.register(view.getEngine());
onLoad.onPageLoad();
}
}
Expand All @@ -257,7 +258,7 @@ private boolean checkValid() {
}

});
Title.observeView(view, stage);
fxConsole.observeWebViewTitle();
return view;
}

Expand Down Expand Up @@ -361,7 +362,8 @@ public WebEngine call(PopupFeatures param) {
stage.initOwner(owner);
final WebView popUpView = new WebView();
stage.setScene(new Scene(popUpView));
Title.observeView(popUpView, stage);
FXConsole fxConsole = new FXConsole(popUpView, stage);
fxConsole.observeWebViewTitle();
stage.show();
return popUpView.getEngine();
}
Expand Down Expand Up @@ -396,30 +398,4 @@ public void handle(ActionEvent t) {
}
}
}
private static class Title implements ChangeListener<String> {
private String title;
private final WebView view;
private final Stage stage;

private Title(WebView view, Stage stage) {
super();
this.view = view;
this.stage = stage;
}

public static void observeView(WebView view, Stage stage) {
Title t = new Title(view, stage);
view.getEngine().titleProperty().addListener(t);
t.changed(null, null, null);
}

@Override
public void changed(ObservableValue<? extends String> ov, String t, String t1) {
title = view.getEngine().getTitle();
if (title != null) {
stage.setTitle(title);
}
}
}

}
57 changes: 43 additions & 14 deletions boot-fx/src/main/java/org/netbeans/html/boot/fx/FXConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
*/
package org.netbeans.html.boot.fx;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import netscape.javascript.JSObject;

/** This is an implementation package - just
Expand All @@ -31,29 +37,52 @@
*
* @author Jaroslav Tulach
*/
public final class FXConsole {
public final class FXConsole implements ChangeListener<String> {
static final Logger LOG = Logger.getLogger(FXConsole.class.getName());

private FXConsole() {
private String title;
final WebView view;
final Stage stage;

private static final List<FXConsole> all = new ArrayList<FXConsole>();

FXConsole(WebView view, Stage stage) {
all.add(this);
this.view = view;
this.stage = stage;
}

static void register(WebEngine eng) {
void register(WebEngine eng) {
JSObject fn = (JSObject) eng.executeScript(""
+ "(function(attr, l, c) {"
+ " window.console[attr] = function(msg) { c.log(l, msg); };"
+ "(function(attr, l, FXConsole) {\n"
+ " window.console[attr] = function(msg) {\n"
+ " FXConsole.log(l, msg);\n"
+ " };"
+ "})"
);
FXConsole c = new FXConsole();
c.registerImpl(fn, "log", Level.INFO);
c.registerImpl(fn, "info", Level.INFO);
c.registerImpl(fn, "warn", Level.WARNING);
c.registerImpl(fn, "error", Level.SEVERE);
registerImpl(fn, "log", Level.INFO);
registerImpl(fn, "info", Level.INFO);
registerImpl(fn, "warn", Level.WARNING);
registerImpl(fn, "error", Level.SEVERE);
}

private void registerImpl(JSObject eng, String attr, Level l) {
eng.call("call", null, attr, l, this);
eng.call("call", new Object[] { null, attr, l, this });
}

void observeWebViewTitle() {
view.getEngine().titleProperty().addListener(this);
this.changed(null, null, null);
}

@Override
public void changed(ObservableValue<? extends String> ov, String t, String t1) {
title = view.getEngine().getTitle();
if (title != null) {
stage.setTitle(title);
}
}


// called from JavaScript
public void log(Level l, String msg) {
LOG.log(l, msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,27 @@ public final class FXGCPresenter extends AbstractFXPresenter {
}
}

private final WebView[] lastWebView;
public FXGCPresenter() {
this(null);
}

FXGCPresenter(WebView[] lastWebView) {
this.lastWebView = lastWebView;
}

@Override
void waitFinished() {
FXBrwsr.waitFinished();
}

@Override
WebView findView(final URL resource) {
return FXBrwsr.findWebView(resource, this);
WebView view = FXBrwsr.findWebView(resource, this);
if (lastWebView != null) {
lastWebView[0] = view;
}
return view;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import net.java.html.BrwsrCtx;
import net.java.html.boot.BrowserBuilder;
Expand Down Expand Up @@ -65,7 +66,8 @@ public void run() {
}
WhenInitialized when = new WhenInitialized();

final BrowserBuilder bb = BrowserBuilder.newBrowser().loadClass(PopupTest.class).
final WebView[] lastWebView = { null };
final BrowserBuilder bb = BrowserBuilder.newBrowser(new FXGCPresenter(lastWebView)).loadClass(PopupTest.class).
loadPage("empty.html").
loadFinished(when);

Expand All @@ -80,7 +82,8 @@ public void run() {
when.cdl.await();
if (arr[0] != null) throw arr[0];

Stage s = FXBrwsr.findStage();
assertNotNull(lastWebView[0], "A WebView created");
Stage s = (Stage) lastWebView[0].getScene().getWindow();
assertEquals(s.getTitle(), "FX Presenter Harness");

final Object[] window = new Object[1];
Expand Down
Loading

0 comments on commit c0583d1

Please sign in to comment.