2003/02/06 19:07:15
[org.ibex.core.git] / src / org / xwt / Template.java
index 859c39e..324fea1 100644 (file)
@@ -139,10 +139,12 @@ public class Template {
 
     // Methods to apply templates ////////////////////////////////////////////////////////
 
-    private Template() { } 
-    private Template(InputStream is, String nodeName) throws XML.SAXException, IOException {
+    private Template(String nodeName) {
         this.nodeName = nodeName;
         cache.put(nodeName, this);
+    }
+    private Template(InputStream is, String nodeName) throws XML.SAXException, IOException {
+        this(nodeName);
         new TemplateHelper().parseit(is, this);
     }
 
@@ -271,11 +273,8 @@ public class Template {
     }
 
     /** adds a theme mapping, retemplatizing as needed */
-    public static void retheme(String from, String to) {
-        if (Log.on) Log.log(Template.class, "retheming from " + from + " to " + to);
+    public static void retheme(Function callback) {
         XWF.flushXWFs();
-        Resources.mapFrom.addElement(from);
-        Resources.mapTo.addElement(to);
 
         // clear changed marker and relink
         Template[] t = new Template[cache.size()];
@@ -291,6 +290,17 @@ public class Template {
             Box b = ((Surface)Surface.allSurfaces.elementAt(i)).root;
             if (b != null) reapply(b);
         }
+
+        if (callback != null)
+            try {
+                callback.call(Context.enter(), null, null, new Object[] { new Double(1.0), new Double(1.0) });
+            } catch (EcmaError ex) {
+                if (Log.on) Log.log(Template.class, "WARNING: uncaught interpreter exception: " + ex.getMessage());
+                if (Log.on) Log.log(Template.class, "         thrown from within progress callback at " + ex.getSourceName() + ":" + ex.getLineNumber());
+            } catch (JavaScriptException ex) {
+                if (Log.on) Log.log(Template.class, "WARNING: uncaught ecmascript exception: " + ex.getMessage());
+                if (Log.on) Log.log(Template.class, "         thrown from within progress callback at " + ex.sourceFile + ":" + ex.line);
+            }
     }
 
     /** template reapplication procedure */
@@ -303,8 +313,7 @@ public class Template {
             if (t != b.template) retemplatize = true;
             b.template = t;
         }
-        if (b.template != null && b.template.changed)
-            retemplatize = true;
+        if (b.template != null && b.template.changed) retemplatize = true;
 
         if (retemplatize) {
 
@@ -359,7 +368,7 @@ public class Template {
     private void link(boolean force) {
 
         if (staticscript != null) try { 
-            Scriptable s = Static.createStatic(nodeName);
+            Scriptable s = Static.createStatic(nodeName, false);
             if (staticscript != null) {
                 Script temp = staticscript;
                 ((InterpretedScript)temp).setParentScope(s);     // so we know how to handle Static.get("xwt")
@@ -526,8 +535,7 @@ public class Template {
                 nodeStack.addElement(t);
 
                 // instantiate a new node, and set its nodeName/importlist/preapply
-                Template t2 = new Template();
-                t2.nodeName = t.nodeName + "." + t.childvect.size();
+                Template t2 = new Template(t.nodeName + "." + t.childvect.size());
                 t2.importlist = t.importlist;
                 t2.startLine = line;
                 if (!name.equals("box")) t2.preapply = new String[] { name };