You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/06/15 22:09:05 UTC
svn commit: r784959 - in /incubator/pivot/trunk:
demos/src/org/apache/pivot/demos/scripting/ wtk/src/org/apache/pivot/wtk/
wtk/src/org/apache/pivot/wtkx/ wtk/test/org/apache/pivot/wtk/test/
Author: gbrown
Date: Mon Jun 15 20:09:05 2009
New Revision: 784959
URL: http://svn.apache.org/viewvc?rev=784959&view=rev
Log:
Add support for put() and remove() in WTKXSerializer; pass startup properties to WTKXSerializer in ScriptApplication; simplify internal handling of startup properties in BrowserApplicationContext.
Added:
incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.wtkx
Modified:
incubator/pivot/trunk/demos/src/org/apache/pivot/demos/scripting/scripting_demo.wtkx
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java
Modified: incubator/pivot/trunk/demos/src/org/apache/pivot/demos/scripting/scripting_demo.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/src/org/apache/pivot/demos/scripting/scripting_demo.wtkx?rev=784959&r1=784958&r2=784959&view=diff
==============================================================================
--- incubator/pivot/trunk/demos/src/org/apache/pivot/demos/scripting/scripting_demo.wtkx (original)
+++ incubator/pivot/trunk/demos/src/org/apache/pivot/demos/scripting/scripting_demo.wtkx Mon Jun 15 20:09:05 2009
@@ -47,7 +47,7 @@
<buttonPressListeners>
<wtkx:script language="javascript">
<![CDATA[
- importPackage(Packages.pivot.wtk);
+ importPackage(org.apache.pivot.wtk);
function buttonPressed(button) {
Alert.alert("Hello from JavaScript!", button.getWindow());
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java?rev=784959&r1=784958&r2=784959&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java Mon Jun 15 20:09:05 2009
@@ -26,6 +26,7 @@
import org.apache.pivot.collections.ArrayList;
import org.apache.pivot.collections.HashMap;
+import org.apache.pivot.collections.immutable.ImmutableMap;
import netscape.javascript.JSObject;
@@ -154,7 +155,8 @@
if (application != null) {
try {
- application.startup(applicationContext.getDisplay(), properties);
+ application.startup(applicationContext.getDisplay(),
+ new ImmutableMap<String, String>(properties));
} catch (Exception exception) {
Alert.alert(MessageType.ERROR, exception.getMessage(),
applicationContext.getDisplay());
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java?rev=784959&r1=784958&r2=784959&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java Mon Jun 15 20:09:05 2009
@@ -19,7 +19,6 @@
import org.apache.pivot.collections.Map;
import org.apache.pivot.wtkx.WTKXSerializer;
-
/**
* Script application loader.
*
@@ -28,12 +27,9 @@
public class ScriptApplication implements Application {
private Window window = null;
- private static final String SRC_ARGUMENT = "src";
- private static final String TITLE_ARGUMENT = "title";
-
- public static void main(String[] args) {
- DesktopApplicationContext.main(ScriptApplication.class, args);
- }
+ public static final String SRC_ARGUMENT = "src";
+ public static final String TITLE_ARGUMENT = "title";
+ public static final String WINDOW_PROPERTY = "window";
public void startup(Display display, Map<String, String> properties)
throws Exception {
@@ -46,13 +42,20 @@
WTKXSerializer wtkxSerializer = new WTKXSerializer();
for (String property : properties) {
- wtkxSerializer.put(property, properties.get(property));
+ if (!property.equals(SRC_ARGUMENT)
+ && !property.equals(TITLE_ARGUMENT)) {
+ wtkxSerializer.put(property, properties.get(property));
+ }
}
- Component content = (Component)wtkxSerializer.readObject(src);
- window = new Window(content);
+ window = new Window();
window.setTitle(title);
window.setMaximized(true);
+ wtkxSerializer.put(WINDOW_PROPERTY, window);
+
+ Component content = (Component)wtkxSerializer.readObject(src);
+ window.setContent(content);
+
window.open(display);
}
@@ -66,4 +69,8 @@
public void suspend() {
}
+
+ public static void main(String[] args) {
+ DesktopApplicationContext.main(ScriptApplication.class, args);
+ }
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java?rev=784959&r1=784958&r2=784959&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java Mon Jun 15 20:09:05 2009
@@ -199,6 +199,7 @@
private Object root = null;
private HashMap<String, Object> namedObjects = new HashMap<String, Object>();
private HashMap<String, WTKXSerializer> includeSerializers = new HashMap<String, WTKXSerializer>();
+ private boolean clearNamespacesOnRead = true;
private ScriptEngineManager scriptEngineManager = null;
@@ -307,8 +308,10 @@
Object object = null;
// Clear any previous named objects and include serializers
- namedObjects.clear();
- includeSerializers.clear();
+ if (clearNamespacesOnRead) {
+ namedObjects.clear();
+ includeSerializers.clear();
+ }
// Parse the XML stream
Element element = null;
@@ -687,7 +690,7 @@
scriptEngine = scriptEngineManager.getEngineByExtension(extension);
if (scriptEngine == null) {
- throw new SerializationException("Unable to find scripting engine for "
+ throw new SerializationException("Unable to find scripting engine for"
+ " extension " + extension + ".");
}
@@ -721,7 +724,7 @@
scriptEngine = scriptEngineManager.getEngineByName(language);
if (scriptEngine == null) {
- throw new SerializationException("Unable to find scripting engine for "
+ throw new SerializationException("Unable to find scripting engine for"
+ " language " + language + ".");
}
@@ -820,6 +823,9 @@
// Set the root object
root = object;
+ // Reset the clear namespaces flag
+ clearNamespacesOnRead = true;
+
return object;
}
@@ -916,6 +922,13 @@
throw new IllegalArgumentException("id is null.");
}
+ if (clearNamespacesOnRead) {
+ includeSerializers.clear();
+ namedObjects.clear();
+ }
+
+ clearNamespacesOnRead = false;
+
includeSerializers.remove(id);
return namedObjects.put(id, value);
}
@@ -925,6 +938,13 @@
throw new IllegalArgumentException("id is null.");
}
+ if (clearNamespacesOnRead) {
+ includeSerializers.clear();
+ namedObjects.clear();
+ }
+
+ clearNamespacesOnRead = false;
+
includeSerializers.remove(id);
return namedObjects.remove(id);
}
Added: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.wtkx?rev=784959&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.wtkx (added)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/script_application_test.wtkx Mon Jun 15 20:09:05 2009
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License,
+Version 2.0 (the "License"); you may not use this file except in
+compliance with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<FlowPane orientation="vertical"
+ xmlns:wtkx="http://pivot.apache.org/wtkx"
+ xmlns="org.apache.pivot.wtk">
+ <Label wtkx:id="fooLabel"/>
+ <Label wtkx:id="barLabel"/>
+
+ <wtkx:script language="javascript">
+ fooLabel.setText(foo);
+ barLabel.setText(bar);
+ </wtkx:script>
+</FlowPane>