You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jt...@apache.org on 2017/09/08 21:06:27 UTC
[19/28] incubator-netbeans-html4j git commit: #269456: window.open in
JavaFX presenter shows new popup window
#269456: window.open in JavaFX presenter shows new popup window
Project: http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/commit/9c338617
Tree: http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/tree/9c338617
Diff: http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/diff/9c338617
Branch: refs/heads/master
Commit: 9c3386172b4dd058207c7d77ade1b29bf886d24a
Parents: 327e6bd
Author: Jaroslav Tulach <jt...@netbeans.org>
Authored: Fri Feb 3 18:30:30 2017 +0100
Committer: Jaroslav Tulach <ja...@apidesign.org>
Committed: Fri Sep 8 17:13:55 2017 +0200
----------------------------------------------------------------------
.../java/org/netbeans/html/boot/fx/FXBrwsr.java | 60 ++++++---
.../org/netbeans/html/boot/fx/PopupTest.java | 127 +++++++++++++++++++
.../org/netbeans/html/boot/fx/second.html | 55 ++++++++
src/main/javadoc/overview.html | 3 +
4 files changed, 226 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/9c338617/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXBrwsr.java
----------------------------------------------------------------------
diff --git a/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXBrwsr.java b/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXBrwsr.java
index 71c8547..e1a8df5 100644
--- a/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXBrwsr.java
+++ b/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXBrwsr.java
@@ -66,12 +66,15 @@ import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
+import javafx.scene.web.PopupFeatures;
import javafx.scene.web.PromptData;
+import javafx.scene.web.WebEngine;
import javafx.scene.web.WebEvent;
import javafx.scene.web.WebView;
import javafx.stage.Modality;
import javafx.stage.Screen;
import javafx.stage.Stage;
+import javafx.stage.StageStyle;
import javafx.stage.Window;
import javafx.stage.WindowEvent;
import javafx.util.Callback;
@@ -278,25 +281,7 @@ public class FXBrwsr extends Application {
}
});
- class Title implements ChangeListener<String> {
-
- private String title;
-
- public Title() {
- super();
- }
-
- @Override
- public void changed(ObservableValue<? extends String> ov, String t, String t1) {
- title = view.getEngine().getTitle();
- if (title != null) {
- stage.setTitle(title);
- }
- }
- }
- final Title x = new Title();
- view.getEngine().titleProperty().addListener(x);
- x.changed(null, null, null);
+ Title.observeView(view, stage);
return view;
}
@@ -393,6 +378,18 @@ public class FXBrwsr extends Application {
return res[0] ? line.getText() : null;
}
});
+ view.getEngine().setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>() {
+ @Override
+ public WebEngine call(PopupFeatures param) {
+ final Stage stage = new Stage(StageStyle.UTILITY);
+ stage.initOwner(owner);
+ final WebView popUpView = new WebView();
+ stage.setScene(new Scene(popUpView));
+ Title.observeView(popUpView, stage);
+ stage.show();
+ return popUpView.getEngine();
+ }
+ });
}
static void waitFinished() {
@@ -423,5 +420,30 @@ public class FXBrwsr extends Application {
}
}
}
+ 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);
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/9c338617/boot-fx/src/test/java/org/netbeans/html/boot/fx/PopupTest.java
----------------------------------------------------------------------
diff --git a/boot-fx/src/test/java/org/netbeans/html/boot/fx/PopupTest.java b/boot-fx/src/test/java/org/netbeans/html/boot/fx/PopupTest.java
new file mode 100644
index 0000000..a2963bb
--- /dev/null
+++ b/boot-fx/src/test/java/org/netbeans/html/boot/fx/PopupTest.java
@@ -0,0 +1,127 @@
+/**
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * The Original Software is NetBeans. The Initial Developer of the Original
+ * Software is Oracle. Portions Copyright 2013-2016 Oracle. All Rights Reserved.
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ */
+package org.netbeans.html.boot.fx;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import javafx.stage.Stage;
+import net.java.html.BrwsrCtx;
+import net.java.html.boot.BrowserBuilder;
+import net.java.html.js.JavaScriptBody;
+import org.netbeans.html.boot.spi.Fn;
+import static org.testng.Assert.*;
+import org.testng.annotations.Test;
+
+/**
+ *
+ * @author Jaroslav Tulach
+ */
+public class PopupTest {
+ public PopupTest() {
+ }
+
+ @JavaScriptBody(args = { "page" }, body =
+ "return window.open(page, 'secondary', 'width=300,height=150');"
+ )
+ private static native Object openSecondaryWindow(String page);
+
+ @Test public void checkReload() throws Throwable {
+ final Throwable[] arr = { null };
+
+ class WhenInitialized implements Runnable {
+ CountDownLatch cdl = new CountDownLatch(1);
+ AbstractFXPresenter p;
+ BrwsrCtx ctx;
+
+ @Override
+ public void run() {
+ try {
+ p = (AbstractFXPresenter) Fn.activePresenter();
+ assertNotNull(p, "Presenter is defined");
+ ctx = BrwsrCtx.findDefault(WhenInitialized.class);
+ } catch (Throwable ex) {
+ arr[0] = ex;
+ } finally {
+ cdl.countDown();
+ }
+ }
+ }
+ WhenInitialized when = new WhenInitialized();
+
+ final BrowserBuilder bb = BrowserBuilder.newBrowser().loadClass(PopupTest.class).
+ loadPage("empty.html").
+ loadFinished(when);
+
+ class ShowBrowser implements Runnable {
+ @Override
+ public void run() {
+ bb.showAndWait();
+ }
+ }
+
+ Executors.newSingleThreadExecutor().submit(new ShowBrowser());
+ when.cdl.await();
+ if (arr[0] != null) throw arr[0];
+
+ Stage s = FXBrwsr.findStage();
+ assertEquals(s.getTitle(), "FX Presenter Harness");
+
+ final Object[] window = new Object[1];
+ final CountDownLatch openWindow = new CountDownLatch(1);
+ when.ctx.execute(new Runnable() {
+ @Override
+ public void run() {
+ TitleTest.changeTitle("First window");
+ window[0] = openSecondaryWindow("second.html");
+ openWindow.countDown();
+ }
+ });
+
+ openWindow.await(5, TimeUnit.SECONDS);
+
+ assertNotNull(window[0], "Second window opened");
+
+ assertEquals(s.getTitle(), "First window", "The title is kept");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/9c338617/boot-fx/src/test/resources/org/netbeans/html/boot/fx/second.html
----------------------------------------------------------------------
diff --git a/boot-fx/src/test/resources/org/netbeans/html/boot/fx/second.html b/boot-fx/src/test/resources/org/netbeans/html/boot/fx/second.html
new file mode 100644
index 0000000..a450f29
--- /dev/null
+++ b/boot-fx/src/test/resources/org/netbeans/html/boot/fx/second.html
@@ -0,0 +1,55 @@
+<!--
+
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+
+ Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
+
+ Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ Other names may be trademarks of their respective owners.
+
+ The contents of this file are subject to the terms of either the GNU
+ General Public License Version 2 only ("GPL") or the Common
+ Development and Distribution License("CDDL") (collectively, the
+ "License"). You may not use this file except in compliance with the
+ License. You can obtain a copy of the License at
+ http://www.netbeans.org/cddl-gplv2.html
+ or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ specific language governing permissions and limitations under the
+ License. When distributing the software, include this License Header
+ Notice in each file and include the License file at
+ nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
+ particular file as subject to the "Classpath" exception as provided
+ by Oracle in the GPL Version 2 section of the License file that
+ accompanied this code. If applicable, add the following below the
+ License Header, with the fields enclosed by brackets [] replaced by
+ your own identifying information:
+ "Portions Copyrighted [year] [name of copyright owner]"
+
+ Contributor(s):
+
+ The Original Software is NetBeans. The Initial Developer of the Original
+ Software is Oracle. Portions Copyright 2013-2016 Oracle. All Rights Reserved.
+
+ If you wish your version of this file to be governed by only the CDDL
+ or only the GPL Version 2, indicate your decision by adding
+ "[Contributor] elects to include this software in this distribution
+ under the [CDDL or GPL Version 2] license." If you do not indicate a
+ single choice of license, a recipient has the option to distribute
+ your version of this file under either the CDDL, the GPL Version 2 or
+ to extend the choice of license to its licensees as provided above.
+ However, if you add GPL Version 2 code and therefore, elected the GPL
+ Version 2 license, then the option applies only if the new code is
+ made subject to such option by the copyright holder.
+
+-->
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Second Window</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <meta name="viewport" content="width=device-width">
+ </head>
+ <body>
+ <div>Second Window</div>
+ </body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/9c338617/src/main/javadoc/overview.html
----------------------------------------------------------------------
diff --git a/src/main/javadoc/overview.html b/src/main/javadoc/overview.html
index b144db3..cd0cfde 100644
--- a/src/main/javadoc/overview.html
+++ b/src/main/javadoc/overview.html
@@ -85,6 +85,9 @@
<a target="_blank" href="https://netbeans.org/bugzilla/show_bug.cgi?id=269549"/>
Workaround</a> for garbage collector behavior of modern JavaFX WebView
implementations (JDK8 u112 and newer).
+ JavaFX Presenter can
+ <a target="_blank" href="https://netbeans.org/bugzilla/show_bug.cgi?id=269456"/>
+ show popup</a> window.
Development has switched to
<a target="_blank" href="https://github.com/jtulach/html-java-api/"/>
Git repository</a> thanks to