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:29 UTC

[21/28] incubator-netbeans-html4j git commit: Using codesnippet Javadoc doclet to take the Periodicaly example from real source code

Using codesnippet Javadoc doclet to take the Periodicaly example from real source code


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/23ddadf3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/tree/23ddadf3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/diff/23ddadf3

Branch: refs/heads/master
Commit: 23ddadf364791550ca6319d4b9104556aaaebb8f
Parents: 9c33861
Author: Jaroslav Tulach <jt...@netbeans.org>
Authored: Fri Feb 3 21:13:06 2017 +0100
Committer: Jaroslav Tulach <ja...@apidesign.org>
Committed: Fri Sep 8 17:13:55 2017 +0200

----------------------------------------------------------------------
 .../org/netbeans/html/boot/fx/Periodicaly.java  | 103 +++++++++++++++++++
 .../netbeans/html/boot/fx/PeriodicalyTest.java  |  64 ++++++++++++
 .../src/main/java/net/java/html/BrwsrCtx.java   |  32 +-----
 pom.xml                                         |   7 ++
 4 files changed, 175 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/23ddadf3/boot-fx/src/test/java/org/netbeans/html/boot/fx/Periodicaly.java
----------------------------------------------------------------------
diff --git a/boot-fx/src/test/java/org/netbeans/html/boot/fx/Periodicaly.java b/boot-fx/src/test/java/org/netbeans/html/boot/fx/Periodicaly.java
new file mode 100644
index 0000000..8174192
--- /dev/null
+++ b/boot-fx/src/test/java/org/netbeans/html/boot/fx/Periodicaly.java
@@ -0,0 +1,103 @@
+/**
+ * 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.Timer;
+import java.util.TimerTask;
+import net.java.html.BrwsrCtx;
+import net.java.html.js.JavaScriptBody;
+
+// BEGIN: org.netbeans.html.boot.fx.Periodicaly
+public final class Periodicaly extends TimerTask {
+    private final BrwsrCtx ctx;
+    private int counter;
+
+    private Periodicaly(BrwsrCtx ctx) {
+        // remember the browser context and use it later
+        this.ctx = ctx;
+        this.counter = 0;
+    }
+
+    @Override
+    public void run() {
+        // arrives on wrong thread, needs to be re-scheduled
+        ctx.execute(new Runnable() {
+            @Override
+            public void run() {
+                codeThatNeedsToBeRunInABrowserEnvironment();
+            }
+        });
+    }
+
+    // called when your page is ready
+    public static void onPageLoad(String... args) throws Exception {
+        // the context at the time of page initialization
+        BrwsrCtx initialCtx = BrwsrCtx.findDefault(Periodicaly.class);
+        // the task that is associated with context
+        Periodicaly task = new Periodicaly(initialCtx);
+        // creates a timer
+        Timer t = new Timer("Move the box");
+        // run the task every 100ms
+        t.scheduleAtFixedRate(task, 0, 100);
+    }
+
+    @JavaScriptBody(args = { "a", "b" }, body = "return a + b")
+    private static native int plus(int a, int b);
+
+    void codeThatNeedsToBeRunInABrowserEnvironment() {
+        // invokes JavaScript function in the browser environment
+        counter = plus(counter, 1);
+// FINISH: org.netbeans.html.boot.fx.Periodicaly
+
+        synchronized (Periodicaly.class) {
+            globalCounter = counter;
+            Periodicaly.class.notifyAll();
+        }
+    }
+    static int globalCounter;
+    static synchronized void assertTen() throws InterruptedException {
+        while (globalCounter < 10) {
+            Periodicaly.class.wait();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/23ddadf3/boot-fx/src/test/java/org/netbeans/html/boot/fx/PeriodicalyTest.java
----------------------------------------------------------------------
diff --git a/boot-fx/src/test/java/org/netbeans/html/boot/fx/PeriodicalyTest.java b/boot-fx/src/test/java/org/netbeans/html/boot/fx/PeriodicalyTest.java
new file mode 100644
index 0000000..f3a3d21
--- /dev/null
+++ b/boot-fx/src/test/java/org/netbeans/html/boot/fx/PeriodicalyTest.java
@@ -0,0 +1,64 @@
+/**
+ * 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.Executors;
+import net.java.html.boot.BrowserBuilder;
+import org.testng.annotations.Test;
+
+public final class PeriodicalyTest {
+    @Test
+    public void runPeriodically() throws Exception {
+        final BrowserBuilder bb = BrowserBuilder.newBrowser(new FXPresenter())
+                .loadPage("empty.html")
+                .loadClass(Periodicaly.class)
+                .invoke("onPageLoad");
+        Executors.newSingleThreadExecutor().execute(new Runnable() {
+            @Override
+            public void run() {
+                bb.showAndWait();
+            }
+        });
+        Periodicaly.assertTen();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/23ddadf3/context/src/main/java/net/java/html/BrwsrCtx.java
----------------------------------------------------------------------
diff --git a/context/src/main/java/net/java/html/BrwsrCtx.java b/context/src/main/java/net/java/html/BrwsrCtx.java
index 59a4a21..72ac800 100644
--- a/context/src/main/java/net/java/html/BrwsrCtx.java
+++ b/context/src/main/java/net/java/html/BrwsrCtx.java
@@ -132,37 +132,7 @@ public final class BrwsrCtx implements Executor {
      * <p>
      * <b>Example Using a Timer</b>
      * </p>
-<pre>
-<b>public final class</b> Periodicaly <b>extends</b> {@link java.util.TimerTask} {
-    <b>private final</b> {@link BrwsrCtx} ctx;
-
-    <b>private</b> Periodicaly(BrwsrCtx ctx) {
-        // remember the browser context and use it later
-        this.ctx = ctx;
-    }
-    
-    <b>public void</b> run() {
-        // arrives on wrong thread, needs to be re-scheduled
-        ctx.{@link #execute(java.lang.Runnable) execute}(new Runnable() {
-            <b>public void</b> run() {
-                // code that needs to run in a browser environment
-            }
-        });
-    }
-
-    // called when your page is ready
-    <b>public static void</b> onPageLoad(String... args) <b>throws</b> Exception {
-        // the context at the time of page initialization
-        BrwsrCtx initialCtx = BrwsrCtx.findDefault(Periodicaly.<b>class</b>);
-        // the task that is associated with context 
-        Periodicaly task = new Periodicaly(initialCtx);
-        // creates a timer
-        {@link java.util.Timer} t = new {@link java.util.Timer}("Move the box");
-        // run the task every 100ms
-        t.{@link java.util.Timer#scheduleAtFixedRate(java.util.TimerTask, long, long) scheduleAtFixedRate}(task, 0, 100);
-    }
-}
-</pre>    
+     * {@codesnippet org.netbeans.html.boot.fx.Periodicaly}
      * 
      * @param exec the code to execute
      * @since 0.7.6

http://git-wip-us.apache.org/repos/asf/incubator-netbeans-html4j/blob/23ddadf3/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index a19bfcb..d881df6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -199,6 +199,13 @@ org.netbeans.html.boot.impl:org.netbeans.html.boot.fx:org.netbeans.html.context.
                     <link>http://bits.netbeans.org/8.0/javadoc/org-openide-util-lookup/</link>
                     <link>http://docs.oracle.com/javase/8/javafx/api/</link>
                 </links>              
+                <doclet>org.apidesign.javadoc.codesnippet.Doclet</doclet>
+                <docletArtifact>
+                    <groupId>org.apidesign.javadoc</groupId>
+                    <artifactId>codesnippet-doclet</artifactId>
+                    <version>0.11</version>
+                </docletArtifact>
+                <additionalparam>-snippetpath "${basedir}"</additionalparam>
               </configuration>
             </plugin>
             <plugin>