- void apply(Box b, Vec pboxes, Vec ptemplates, Function callback, int numerator, int denominator) {
-
- int original_numerator = numerator;
-
- if (pboxes == null) {
- pboxes = new Vec();
- ptemplates = new Vec();
- }
-
- if (id != null && !id.equals(""))
- for(int i=0; i<pboxes.size(); i++) {
- Box parent = (Box)pboxes.elementAt(i);
- String parentNodeName = (String)ptemplates.elementAt(i);
- parent.putPrivately("$" + id, b, parentNodeName);
- }
-
- if (script != null || (redirect != null && !"self".equals(redirect))) {
- pboxes.addElement(b);
- ptemplates.addElement(nodeName);
- }
-
- int numids = pboxes.size();
-
- link();
-
- for(int i=0; _preapply != null && i<_preapply.length; i++)
- if (_preapply[i] != null) {
- _preapply[i].apply(b, null, null, callback, numerator, denominator);
- numerator += _preapply[i].numUnits();
- }
-
- for (int i=0; children != null && i<children.length; i++) {
- b.put(Integer.MAX_VALUE, null, new Box(children[i], pboxes, ptemplates, callback, numerator, denominator));
- numerator += children[i].numUnits();
- }
-
- // whom to redirect to; doesn't take effect until after script runs
- Box redir = null;
- if (redirect != null && !"self".equals(redirect))
- redir = (Box)b.getPrivately("$" + redirect, nodeName);
-
- if (script != null) try {
- Context cx = Context.enter();
- script.exec(cx, b);
- } catch (EcmaError e) {
- if (Log.on) Log.log(this, "WARNING: uncaught interpreter exception: " + e.getMessage());
- if (Log.on) Log.log(this, " thrown while instantiating " + nodeName + " at " + e.getSourceName() + ":" + e.getLineNumber());
- } catch (JavaScriptException e) {
- if (Log.on) Log.log(this, "WARNING: uncaught ecmascript exception: " + e.getMessage());
- if (Log.on) Log.log(this, " thrown while instantiating " + nodeName + " at " + e.sourceFile + ":" + e.line);
- }
-
- for(int i=0; keys != null && i<keys.length; i++) {
- Context.enter().interpreterSourceFile = nodeName;
- Context.enter().interpreterLine = startLine;
- if (keys[i] == null) { }
- else if (keys[i].equals("border") || keys[i].equals("image") &&
- !vals[i].toString().startsWith("http://") && !vals[i].toString().startsWith("https://")) {
- String s = Resources.resolve(vals[i].toString() + ".png", importlist);
- if (s != null) b.put(keys[i], null, s.substring(0, s.length() - 4));
- else if (Log.on) Log.log(this, "unable to resolve image " + vals[i].toString() + " referenced in attributes of " + nodeName);
- }
- else b.put(keys[i], null, vals[i]);
- }
-
- if (redirect != null && !"self".equals(redirect)) b.redirect = redir;
-
- for(int i=0; _postapply != null && i<_postapply.length; i++)
- if (_postapply[i] != null) {
- _postapply[i].apply(b, null, null, callback, numerator, denominator);
- numerator += _postapply[i].numUnits();
- }
-
- pboxes.setSize(numids);
- ptemplates.setSize(numids);
-
- numerator = original_numerator + numUnits();
-
- if (callback != null)
- try {
- callback.call(Context.enter(), null, null, new Object[] { new Double(numerator), new Double(denominator) });
- } catch (EcmaError e) {
- if (Log.on) Log.log(this, "WARNING: uncaught interpreter exception: " + e.getMessage());
- if (Log.on) Log.log(this, " thrown from within progress callback at " + e.getSourceName() + ":" + e.getLineNumber());
- } catch (JavaScriptException e) {
- if (Log.on) Log.log(this, "WARNING: uncaught ecmascript exception: " + e.getMessage());
- if (Log.on) Log.log(this, " thrown from within progress callback at " + e.sourceFile + ":" + e.line);
- }
-
- if (Thread.currentThread() instanceof ThreadMessage) try {
- XWT.yield.call(Context.enter(), null, null, null);
- } catch (JavaScriptException e) {
- if (Log.on) Log.log(this, "WARNING: uncaught ecmascript exception: " + e.getMessage());
- if (Log.on) Log.log(this, " thrown from within yield at " + e.sourceFile + ":" + e.line);