You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2012/07/31 18:14:41 UTC

svn commit: r1367652 - in /pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot859: Pivot859.java pivot859.html pivot_859.bxml

Author: smartini
Date: Tue Jul 31 16:14:41 2012
New Revision: 1367652

URL: http://svn.apache.org/viewvc?rev=1367652&view=rev
Log:
PIVOT-859, continuing the test

Modified:
    pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot859/Pivot859.java
    pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot859/pivot859.html
    pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot859/pivot_859.bxml

Modified: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot859/Pivot859.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot859/Pivot859.java?rev=1367652&r1=1367651&r2=1367652&view=diff
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot859/Pivot859.java (original)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot859/Pivot859.java Tue Jul 31 16:14:41 2012
@@ -16,11 +16,19 @@
  */
 package org.apache.pivot.tests.issues.pivot859;
 
+import java.net.MalformedURLException;
+import java.net.URL;
+
 import org.apache.pivot.beans.BXMLSerializer;
 import org.apache.pivot.collections.Map;
 import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.Button;
+import org.apache.pivot.wtk.ButtonPressListener;
 import org.apache.pivot.wtk.DesktopApplicationContext;
 import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.PushButton;
+import org.apache.pivot.wtk.TextArea;
+import org.apache.pivot.wtk.TextInput;
 import org.apache.pivot.wtk.Window;
 
 /**
@@ -29,12 +37,20 @@ import org.apache.pivot.wtk.Window;
 public class Pivot859 extends Application.Adapter {
 
     private Window window = null;
+    private TextInput urlInput = null;
+    private PushButton goButton = null;
+    private TextArea contentArea = null;
+    @SuppressWarnings("unused") private PushButton clearButton = null;
+
+    private String appletName = null;
+
 
     public void startup(final Display display, Map<String, String> args) throws Exception {
-        System.out.println("Pivot859 startup(...)");
+        System.out.println("startup(...)");
 
         BXMLSerializer bxmlSerializer = new BXMLSerializer();
         window = (Window) bxmlSerializer.readObject(Pivot859.class, "pivot_859.bxml");
+        initializeFields(bxmlSerializer);
         window.open(display);
     }
 
@@ -47,6 +63,94 @@ public class Pivot859 extends Applicatio
         return false;
     }
 
+    /**
+     * Set the Applet name.
+     * <p>
+     * Called by JavaScript from the Browser.
+     * @param name the name
+     */
+    public void setAppletName(String name) {
+        appletName = name;
+        System.out.println("set appletName to \"" + appletName + "\"");
+    }
+
+    /**
+     * Get the Applet name.
+     * <p>
+     * Called by JavaScript from the Browser.
+     * @return the name
+     */
+    public String getAppletName() {
+        return appletName;
+    }
+
+
+    private void initializeFields(BXMLSerializer serializer) {
+        System.out.println("initializeFields: start");
+
+        urlInput = (TextInput)serializer.getNamespace().get("textInput");
+
+        goButton = (PushButton)serializer.getNamespace().get("goButton");
+        goButton.getButtonPressListeners().add(new ButtonPressListener() {
+            @Override
+            public void buttonPressed(Button button) {
+                clearContent();
+                retrieveURLContentSync();
+            }
+        });
+
+        contentArea = (TextArea)serializer.getNamespace().get("textArea");
+        clearButton = (PushButton)serializer.getNamespace().get("clearButton");
+
+        System.out.println("initializeFields: end");
+    }
+
+    private String getAppletNameForLog() {
+        return ( (getAppletName() != null) ? getAppletName() + ": " : "" );
+    }
+
+    private void clearContent() {
+        System.out.println(getAppletNameForLog() + "Clearing text area content ...");
+        // contentArea.clear();
+        contentArea.setText("");
+    }
+
+    private URL buildURL() {
+        URL url = null;
+        String urlTyped = urlInput.getText();
+
+        try {
+            url = new URL(urlTyped);
+        } catch (MalformedURLException e) {
+            e.printStackTrace();
+        }
+
+        return url;
+    }
+
+    /**
+     * Retrieve content from the given URL (in applet GUI), but in a synchronous way.
+     */
+    private void retrieveURLContentSync() {
+        URL url = buildURL();
+        if (url == null) {
+            System.out.println(getAppletNameForLog() + "Unable to retrieve content from a bad URL");
+            return ;
+        }
+
+        try {
+            System.out.println(getAppletNameForLog() + "Retrieving Content from URL \"" + url + "\"");
+// TODO: retrieve content ...
+
+            contentArea.setText("test");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+// TODO: retrieve content in the usual asynchronous way, but maybe in another method ...
+
+
     public static void main(String[] args) {
         DesktopApplicationContext.main(Pivot859.class, args);
     }

Modified: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot859/pivot859.html
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot859/pivot859.html?rev=1367652&r1=1367651&r2=1367652&view=diff
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot859/pivot859.html (original)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot859/pivot859.html Tue Jul 31 16:14:41 2012
@@ -67,6 +67,13 @@ limitations under the License.
         parameters.java_arguments = javaArguments.join(" ");
 
         deployJava.runApplet(attributes, parameters, "1.6");
+
+        // call Applet methods from JavaScript
+        var applet1 = document.getElementById("applet1");
+        // alert("applet1 = " + applet1);
+        var appletReference = applet1.getApplication();  // the reference to Pivot Applet instance
+        appletReference.setAppletName(applet1.name);  // read the name from applet tag attribute in HTML page
+        alert("applet1 has name = \"" + appletReference.getAppletName() + "\"");
     </script>
     <br/>
 </div>
@@ -108,6 +115,13 @@ limitations under the License.
         parameters.java_arguments = javaArguments.join(" ");
 
         deployJava.runApplet(attributes, parameters, "1.6");
+
+        // call Applet methods from JavaScript
+        var applet2 = document.getElementById("applet2");
+        // alert("applet2 = " + applet2);
+        var appletReference = applet2.getApplication();  // the reference to Pivot Applet instance
+        appletReference.setAppletName(applet2.name);  // read the name from applet tag attribute in HTML page
+        alert("applet2 has name = \"" + appletReference.getAppletName() + "\"");
     </script>
     <br/>
 </div>

Modified: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot859/pivot_859.bxml
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot859/pivot_859.bxml?rev=1367652&r1=1367651&r2=1367652&view=diff
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot859/pivot_859.bxml (original)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot859/pivot_859.bxml Tue Jul 31 16:14:41 2012
@@ -33,21 +33,16 @@ limitations under the License.
         <TablePane.Row height="-1">
             <Label styles="{horizontalAlignment:'right', verticalAlignment:'center'}" text="URL:"/>
             <TextInput bxml:id="textInput" text="http://pivot.apache.org/index.html" textSize="30"/>
-            <PushButton buttonData="Go">
-                <buttonPressListeners>
-                function buttonPressed(button) {
-                    var id = "";  
-                        // = org.apache.pivot.wtk.BrowserApplicationContext.eval("", Pivot859.this);  // test
-                    java.lang.System.out.println("Applet " + id + ", getting content from \"" + textInput.text + "\" ...");
-                    textArea.text = "";
-                }
-                </buttonPressListeners>
-            </PushButton>
+            <PushButton bxml:id="goButton" buttonData="Go"/>
         </TablePane.Row>
         <TablePane.Row height="-1">
             <Label styles="{horizontalAlignment:'right', verticalAlignment:'center'}" text="Content:"/>
             <Border>
-                <TextArea bxml:id="textArea" text="" preferredWidth="320" preferredHeight="200" styles="{wrapText:true}">
+                <TextArea bxml:id="textArea" preferredWidth="320" preferredHeight="200"
+                    styles="{wrapText:true}"
+                    editable="false"
+                    text=""
+                >
                    <textAreaContentListeners>
                     function textChanged(textArea) {
                         // java.lang.System.out.println("length = " + textArea.characterCount);
@@ -55,7 +50,7 @@ limitations under the License.
                     </textAreaContentListeners>
                 </TextArea>
             </Border>
-            <PushButton buttonData="Clear" preferredHeight="40" preferredWidth="50">
+            <PushButton  bxml:id="clearButton" buttonData="Clear" preferredHeight="40" preferredWidth="50">
                 <buttonPressListeners>
                 function buttonPressed(button) {
                     textArea.text = "";