hillion 02/02/11 05:14:30 Modified: samples/tests/spec/scripting xAnimOnClick.svg sources/org/apache/batik/bridge BridgeEventSupport.java RepaintManager.java UpdateManager.java sources/org/apache/batik/gvt UpdateTracker.java sources/org/apache/batik/script/rhino RhinoInterpreter.java sources/org/apache/batik/swing/svg JSVGComponent.java sources/org/apache/batik/util CSSConstants.java RunnableQueue.java SVGConstants.java Added: sources/org/apache/batik/bridge RepaintRateManager.java ScriptingEnvironment.java sources/org/apache/batik/util Lock.java Log: - Changed the threading model to allow multiple scripts to run at the same time. - ECMAScript function 'setTimeout' implemented. - xAnimOnClick updated to use 'setTimeout'. Revision Changes Path 1.2 +19 -9 xml-batik/samples/tests/spec/scripting/xAnimOnClick.svg Index: xAnimOnClick.svg =================================================================== RCS file: /home/cvs/xml-batik/samples/tests/spec/scripting/xAnimOnClick.svg,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- xAnimOnClick.svg 4 Feb 2002 20:11:34 -0000 1.1 +++ xAnimOnClick.svg 11 Feb 2002 13:14:29 -0000 1.2 @@ -15,7 +15,7 @@ <!-- 'onclick' event handler. --> <!-- --> <!-- @author [EMAIL PROTECTED] --> -<!-- @version $Id: xAnimOnClick.svg,v 1.1 2002/02/04 20:11:34 deweese Exp $ --> +<!-- @version $Id: xAnimOnClick.svg,v 1.2 2002/02/11 13:14:29 hillion Exp $ --> <!-- ====================================================================== --> <?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?> @@ -26,16 +26,26 @@ <script type="text/ecmascript"> + var r; + var doc; + var t; + var start; + var end; + var inc; + var frac; + function moveToX(evt, target, val){ - var r = evt.getTarget(); - var doc = r.getOwnerDocument(); - var t = doc.getElementById(target); - var start = parseInt(t.getAttribute('x')); - cyclopse(t, start, val, 1, 1); + r = evt.target; + doc = r.ownerDocument; + t = doc.getElementById(target); + start = parseInt(t.getAttribute('x')); + end = val; + inc = 1; + frac = 1; + cyclopse(); } - function cyclopse(t, start, end, frac, inc) { - while (1) { + function cyclopse() { t.setAttribute('x', (end-start)*frac/100+start); if (frac == 100) { inc = -1; @@ -43,7 +53,7 @@ inc = 1; } frac += inc; - } + setTimeout('cyclopse()', 50); } </script> 1.20 +38 -64 xml-batik/sources/org/apache/batik/bridge/BridgeEventSupport.java Index: BridgeEventSupport.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/BridgeEventSupport.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- BridgeEventSupport.java 7 Feb 2002 08:01:06 -0000 1.19 +++ BridgeEventSupport.java 11 Feb 2002 13:14:29 -0000 1.20 @@ -56,7 +56,7 @@ * on the GVT root to propagate GVT events to the DOM. * @author <a href="mailto:[EMAIL PROTECTED]>Christophe Jolif</a> * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: BridgeEventSupport.java,v 1.19 2002/02/07 08:01:06 hillion Exp $ + * @version $Id: BridgeEventSupport.java,v 1.20 2002/02/11 13:14:29 hillion Exp $ */ class BridgeEventSupport implements SVGConstants { private static final String[] EVENT_ATTRIBUTES_GRAPHICS = { @@ -306,13 +306,32 @@ public static void loadScripts(BridgeContext ctx, Element element) { UpdateManager um = ctx.getUpdateManager(); - RunnableQueue rq = um.getScriptingRunnableQueue(); - Document doc = um.getScriptingDocument(); + Document doc = um.getDocument(); NodeList list = element.getElementsByTagNameNS(SVG_NAMESPACE_URI, SVG_SCRIPT_TAG); final UserAgent ua = ctx.getUserAgent(); String language = null; Element selement = null; + final ScriptingEnvironment se = ctx.getUpdateManager(). + getScriptingEnvironment(); + + // add a function definition 'alert' + final Interpreter inter = + ctx.getInterpreterPool().getInterpreter(doc, "text/ecmascript"); + if (inter != null) { + try { + javax.swing.JOptionPane pane = new javax.swing.JOptionPane(); + inter.bindObject("pane", pane); + inter.evaluate("function alert(msg) { pane.showMessageDialog(null, msg); }"); + + inter.bindObject("scriptEnv", se); + inter.evaluate("function setTimeout(s, t) { scriptEnv.pauseScript(t); scriptEnv.runScript(s, 'text/ecmascript', null); }"); + } catch (Exception ex) { + // nothing to do + ex.printStackTrace(); + } + } + for (int i = 0; i < list.getLength(); i++) { language = (selement = (Element)list.item(i)). getAttribute("type"); @@ -324,22 +343,18 @@ n = n.getNextSibling()) { script.append(n.getNodeValue()); } - rq.invokeLater(new Runnable() { - public void run() { - try { - // use Reader mechanism => no caching - // (will not be revaluated + <script> content is - // generally bigger than the one in event attributes - interpret.evaluate(new StringReader(script.toString())); - } catch (IOException io) { - // will never appeared we don't use a file - } catch (InterpreterException e) { - if (ua != null) - ua.displayError(new Exception("scripting error: "+ - e.getMessage())); - } - } - }); + try { + // use Reader mechanism => no caching + // (will not be revaluated + <script> content is + // generally bigger than the one in event attributes + interpret.evaluate(new StringReader(script.toString())); + } catch (IOException io) { + // will never appeared we don't use a file + } catch (InterpreterException e) { + if (ua != null) + ua.displayError(new Exception("scripting error: "+ + e.getMessage())); + } } else { if (ua != null) { ua.displayError(new Exception("unknown language: "+language)); @@ -347,22 +362,6 @@ } } - // add a function definition 'alert' - final Interpreter interpret = - ctx.getInterpreterPool().getInterpreter(doc, language); - if (interpret != null) { - rq.invokeLater(new Runnable() { - public void run() { - try { - javax.swing.JOptionPane pane = new javax.swing.JOptionPane(); - interpret.bindObject("pane", pane); - interpret.evaluate("function alert(msg) { pane.showMessageDialog(null, msg); }"); - } catch (Exception ex) { - // nothing to do - } - } - }); - } } private static class GVTUnloadListener @@ -507,7 +506,6 @@ private static String EVENT_NAME = "evt"; private String script = null; - private UserAgent ua = null; private BridgeContext context; private String language; @@ -515,38 +513,14 @@ String str, String lang) { script = str; - context = ctx; language = lang; - ua = ctx.getUserAgent(); + context = ctx; } public void handleEvent(Event evt) { - UpdateManager um = context.getUpdateManager(); - final DocumentWrapper dw = um.getScriptingDocument(); - RunnableQueue rq = um.getScriptingRunnableQueue(); - final Interpreter interpreter = context.getInterpreterPool(). - getInterpreter(dw, language); - if (interpreter == null) { - if (ua != null) - ua.displayError(new Exception("unknow language: "+ - language)); - return; - } - final Event ev = dw.createEventWrapper(evt); - rq.invokeLater(new Runnable() { - public void run() { - interpreter.bindObject(EVENT_NAME, ev); - try { - // use the String version to enable caching mechanism - interpreter.evaluate(script); - } catch (InterpreterException e) { - Exception ex = e.getException(); - if (ua != null) { - ua.displayError((ex != null) ? ex : e); - } - } - } - }); + ScriptingEnvironment se = + context.getUpdateManager().getScriptingEnvironment(); + se.runScript(script, language, evt); } } } 1.5 +49 -33 xml-batik/sources/org/apache/batik/bridge/RepaintManager.java Index: RepaintManager.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/RepaintManager.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- RepaintManager.java 31 Jan 2002 21:57:35 -0000 1.4 +++ RepaintManager.java 11 Feb 2002 13:14:29 -0000 1.5 @@ -16,57 +16,73 @@ * This class manages the rendering of a GVT tree. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: RepaintManager.java,v 1.4 2002/01/31 21:57:35 deweese Exp $ + * @version $Id: RepaintManager.java,v 1.5 2002/02/11 13:14:29 hillion Exp $ */ -public class RepaintManager extends Thread { +public class RepaintManager { /** * The associated UpdateManager. */ protected UpdateManager updateManager; - long targetFrameTime = 50; + /** + * Whether or not the manager is active. + */ + protected boolean enabled; /** * Creates a new repaint manager. */ public RepaintManager(UpdateManager um) { updateManager = um; - setDaemon(true); } - + /** - * The main method of this thread. This needs to have a target - * frame rate, and it needs to ensure that it changes it target - * frame rate to ensure that it sleeps for at least a few 10s of - * millisecs per loop (it should also see if it can increase - * framerate because it's made the last few frames with the - * current frame-rate easily) */ - public void run() { - long lastFrameTime, currentTime, tm, sleepTime; - try { - while (!Thread.currentThread().isInterrupted()) { - lastFrameTime = System.currentTimeMillis(); - final UpdateTracker ut = updateManager.getUpdateTracker(); - if (ut.hasChanged()) { - updateManager.getUpdateRunnableQueue().invokeAndWait - (new Runnable() { - public void run() { - List dirtyAreas = ut.getDirtyAreas(); - updateManager.modifiedAreas(dirtyAreas); - updateManager.updateRendering(dirtyAreas); - ut.clear(); - } - }); + * Provokes a repaint, if needed. + * @param b If true, waits until the repaint has finished. + */ + public void repaint(boolean b) { + if (!enabled) { + return; + } + final UpdateTracker ut = updateManager.getUpdateTracker(); + Runnable r = new Runnable() { + public void run() { + if (ut.hasChanged()) { + List dirtyAreas = ut.getDirtyAreas(); + if (dirtyAreas != null) { + updateManager.modifiedAreas(dirtyAreas); + updateManager.updateRendering(dirtyAreas); + } + ut.clear(); + } } - currentTime = System.currentTimeMillis(); - tm = currentTime - lastFrameTime; - sleepTime = targetFrameTime-tm; - if (sleepTime > 0) - sleep(sleepTime); + }; + if (updateManager.getUpdateRunnableQueue().getThread() == null) { + return; + } + if (b) { + try { + updateManager.getUpdateRunnableQueue().invokeAndWait(r); + } catch (InterruptedException e) { } - } catch (InterruptedException e) { + } else { + updateManager.getUpdateRunnableQueue().invokeLater(r); } } + /** + * Suspends the repaint management. + */ + public void disable() { + enabled = false; + } + + /** + * Suspends the repaint management. + */ + public void enable() { + enabled = true; + } + } 1.5 +72 -52 xml-batik/sources/org/apache/batik/bridge/UpdateManager.java Index: UpdateManager.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/UpdateManager.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- UpdateManager.java 31 Jan 2002 21:57:35 -0000 1.4 +++ UpdateManager.java 11 Feb 2002 13:14:29 -0000 1.5 @@ -47,7 +47,7 @@ * This class provides features to manage the update of an SVG document. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: UpdateManager.java,v 1.4 2002/01/31 21:57:35 deweese Exp $ + * @version $Id: UpdateManager.java,v 1.5 2002/02/11 13:14:29 hillion Exp $ */ public class UpdateManager implements RunnableQueue.RunHandler { @@ -67,21 +67,11 @@ protected ImageRenderer renderer; /** - * The document usable from the scripting thread. - */ - protected DocumentWrapper scriptingDocument; - - /** * The update RunnableQueue. */ protected RunnableQueue updateRunnableQueue; /** - * The scripting RunnableQueue. - */ - protected RunnableQueue scriptingRunnableQueue; - - /** * The initial time. */ protected long initialTime; @@ -99,7 +89,7 @@ /** * Whether the update manager is running. */ - protected boolean running; + protected volatile boolean running; /** * The listeners. @@ -112,11 +102,21 @@ protected long startingTime; /** + * The scripting environment. + */ + protected ScriptingEnvironment scriptingEnvironment; + + /** * The repaint manager. */ protected RepaintManager repaintManager; /** + * The repaint-rate manager. + */ + protected RepaintRateManager repaintRateManager; + + /** * The update tracker. */ protected UpdateTracker updateTracker; @@ -139,15 +139,16 @@ renderer = r; updateRunnableQueue = RunnableQueue.createRunnableQueue(); - scriptingRunnableQueue = RunnableQueue.createRunnableQueue(); - updateRunnableQueue.setRunHandler(this); + /* DOMImplementationWrapper iw; iw = new DOMImplementationWrapper(updateRunnableQueue, scriptingRunnableQueue, document.getImplementation()); + scriptingDocument = new DocumentWrapper(iw, document); + */ updateTracker = new UpdateTracker(); @@ -157,21 +158,23 @@ } repaintManager = new RepaintManager(this); - repaintManager.start(); + repaintRateManager = new RepaintRateManager(this); + repaintRateManager.start(); + scriptingEnvironment = new ScriptingEnvironment(this); } /** - * Returns the update RunnableQueue. + * Returns the bridge context. */ - public RunnableQueue getUpdateRunnableQueue() { - return updateRunnableQueue; + public BridgeContext getBridgeContext() { + return bridgeContext; } /** - * Returns the scripting RunnableQueue. + * Returns the update RunnableQueue. */ - public RunnableQueue getScriptingRunnableQueue() { - return scriptingRunnableQueue; + public RunnableQueue getUpdateRunnableQueue() { + return updateRunnableQueue; } /** @@ -189,10 +192,17 @@ } /** - * Returns a Document usable from the scripting thread. + * Returns the current Document. + */ + public Document getDocument() { + return document; + } + + /** + * Returns the scripting environment. */ - public DocumentWrapper getScriptingDocument() { - return scriptingDocument; + public ScriptingEnvironment getScriptingEnvironment() { + return scriptingEnvironment; } /** @@ -217,20 +227,20 @@ * Suspends the update manager. */ public void suspend() { - scriptingRunnableQueue.suspendExecution(true); - updateRunnableQueue.suspendExecution(true); - running = false; - suspendStartTime = System.currentTimeMillis(); + if (running) { + running = false; + updateRunnableQueue.suspendExecution(false); + } } /** * Resumes the update manager. */ public void resume() { - scriptingRunnableQueue.resumeExecution(); - updateRunnableQueue.resumeExecution(); - running = true; - suspendedTime = System.currentTimeMillis() - suspendStartTime; + if (!running) { + running = true; + updateRunnableQueue.resumeExecution(); + } } /** @@ -240,7 +250,6 @@ */ public void dispatchSVGLoad() { updateRunnableQueue.resumeExecution(); - scriptingRunnableQueue.resumeExecution(); updateRunnableQueue.invokeLater(new Runnable() { public void run() { @@ -268,23 +277,18 @@ * NOTE: this method must be called outside the update thread. */ public void dispatchSVGUnLoad() { - try { - updateRunnableQueue.invokeAndWait(new Runnable() { - public void run() { - Event evt = ((DocumentEvent)document).createEvent("SVGEvents"); - evt.initEvent("SVGUnload", false, false); - ((EventTarget)(document.getDocumentElement())). - dispatchEvent(evt); - running = false; - - fireManagerStoppedEvent(); - } - }); - } catch (InterruptedException e) { - } - repaintManager.interrupt(); - scriptingRunnableQueue.getThread().interrupt(); - updateRunnableQueue.getThread().interrupt(); + resume(); + updateRunnableQueue.invokeLater(new Runnable() { + public void run() { + Event evt = ((DocumentEvent)document).createEvent("SVGEvents"); + evt.initEvent("SVGUnload", false, false); + ((EventTarget)(document.getDocumentElement())). + dispatchEvent(evt); + running = false; + + fireManagerStoppedEvent(); + } + }); } /** @@ -340,6 +344,7 @@ } renderer.repaint(areas); + fireCompletedEvent(renderer.getOffScreen(), rects); } catch (Exception e) { fireFailedEvent(); @@ -386,6 +391,8 @@ ((UpdateManagerListener)dll[i]).managerStopped(ev); } } + repaintRateManager.interrupt(); + updateRunnableQueue.getThread().interrupt(); } /** @@ -406,6 +413,7 @@ * Fires a UpdateManagerEvent to notify that the manager was resumed. */ protected void fireManagerResumedEvent() { + suspendedTime = System.currentTimeMillis() - suspendStartTime; Object[] dll = listeners.toArray(); if (dll.length > 0) { @@ -471,14 +479,26 @@ * Called when the execution of the queue has been suspended. */ public void executionSuspended(RunnableQueue rq) { - fireManagerSuspendedEvent(); + if (!running) { + suspendStartTime = System.currentTimeMillis(); + if (scriptingEnvironment != null) { + scriptingEnvironment.suspendScripts(); + } + fireManagerSuspendedEvent(); + } } /** * Called when the execution of the queue has been resumed. */ public void executionResumed(RunnableQueue rq) { - fireManagerResumedEvent(); + if (running) { + suspendedTime = System.currentTimeMillis() - suspendStartTime; + fireManagerResumedEvent(); + if (scriptingEnvironment != null) { + scriptingEnvironment.resumeScripts(); + } + } } // 1.1 xml-batik/sources/org/apache/batik/bridge/RepaintRateManager.java Index: RepaintRateManager.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.bridge; /** * This class is responsible of deciding whether or not a repaint is needed. * * @author <a href="mailto:[EMAIL PROTECTED]">Thomas DeWeese</a> * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> * @version $Id: RepaintRateManager.java,v 1.1 2002/02/11 13:14:29 hillion Exp $ */ public class RepaintRateManager extends Thread { /** * The associated UpdateManager. */ protected UpdateManager updateManager; /** * The expected time in ms between two repaints. */ protected long targetFrameTime = 50; /** * Creates a new repaint manager. */ public RepaintRateManager(UpdateManager um) { updateManager = um; setDaemon(true); } /** * The main method of this thread. This needs to have a target * frame rate, and it needs to ensure that it changes it target * frame rate to ensure that it sleeps for at least a few 10s of * millisecs per loop (it should also see if it can increase * framerate because it's made the last few frames with the * current frame-rate easily) */ public void run() { long lastFrameTime, currentTime, tm, sleepTime; try { while (!Thread.currentThread().isInterrupted()) { lastFrameTime = System.currentTimeMillis(); updateManager.getRepaintManager().repaint(true); currentTime = System.currentTimeMillis(); tm = currentTime - lastFrameTime; sleepTime = targetFrameTime-tm; if (sleepTime > 0) sleep(sleepTime); } } catch (InterruptedException e) { } } } 1.1 xml-batik/sources/org/apache/batik/bridge/ScriptingEnvironment.java Index: ScriptingEnvironment.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.bridge; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import org.apache.batik.script.Interpreter; import org.apache.batik.script.InterpreterException; import org.apache.batik.script.InterpreterPool; import org.apache.batik.util.Lock; import org.apache.batik.util.RunnableQueue; import org.w3c.dom.Document; import org.w3c.dom.events.Event; /** * This class contains the informations needed by the SVG scripting. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> * @version $Id: ScriptingEnvironment.java,v 1.1 2002/02/11 13:14:29 hillion Exp $ */ public class ScriptingEnvironment { private final static String EVENT_NAME = "evt"; /** * The scripting lock. */ protected Lock scriptingLock; /** * The update manager. */ protected UpdateManager updateManager; /** * The repaint manager. */ protected RepaintManager repaintManager; /** * The update runnable queue. */ protected RunnableQueue updateRunnableQueue; /** * The active scripting threads. */ protected List scripts = Collections.synchronizedList(new LinkedList()); /** * Whether the scripts must be suspended. */ protected volatile boolean suspended; /** * The suspend lock. */ protected Object suspendLock = new Object(); /** * Creates a new ScriptingEnvironment. * @param um The update manager. */ public ScriptingEnvironment(UpdateManager um) { scriptingLock = new Lock(); updateManager = um; repaintManager = um.getRepaintManager(); updateRunnableQueue = um.getUpdateRunnableQueue(); } /** * Runs a script. */ public void runScript(String script, String lang, Event evt) { new ScriptingThread(script, lang, evt).start(); } /** * Suspends the scripts. */ public void suspendScripts() { suspended = true; } /** * Resumes the scripts. */ public void resumeScripts() { synchronized (suspendLock) { suspended = false; suspendLock.notify(); } } /** * Begins a script evaluation section. */ public void beginScript() { try { scriptingLock.lock(); } catch (InterruptedException e) { throw new StopScriptException(); } synchronized (suspendLock) { if (suspended) { try { suspendLock.wait(); } catch (InterruptedException e) { } } } repaintManager.disable(); if (updateRunnableQueue.getThread() == null) { scriptingLock.unlock(); throw new StopScriptException(); } updateRunnableQueue.suspendExecution(true); } /** * Ends a script evaluation section. */ public void endScript() { synchronized (suspendLock) { if (suspended) { try { suspendLock.wait(); } catch (InterruptedException e) { } } } repaintManager.enable(); if (updateRunnableQueue.getThread() == null) { scriptingLock.unlock(); throw new StopScriptException(); } updateRunnableQueue.resumeExecution(); repaintManager.repaint(true); scriptingLock.unlock(); } /** * Pauses the current script for the given amount of time. */ public void pauseScript(long millis) { long t1 = System.currentTimeMillis(); endScript(); long t2 = System.currentTimeMillis(); millis -= t2 - t1; if (millis < 0) { millis = 0; } try { Thread.sleep(millis); } catch (InterruptedException e) { } finally { beginScript(); } } /** * To run a script. */ protected class ScriptingThread extends Thread { protected String script; protected Event event; protected UserAgent userAgent; protected Interpreter interpreter; public ScriptingThread(String script, String lang, Event evt) { this.script = script; event = evt; BridgeContext bc = updateManager.getBridgeContext(); userAgent = bc.getUserAgent(); Document doc = updateManager.getDocument(); interpreter = bc.getInterpreterPool().getInterpreter(doc, lang); if (interpreter == null) { if (userAgent != null) { userAgent.displayError(new Exception("unknow language: "+ lang)); } } } public void run() { if (interpreter != null) { beginScript(); scripts.add(this); if (event != null) { interpreter.bindObject(EVENT_NAME, event); } try { interpreter.evaluate(script); } catch (InterpreterException ie) { Exception ex = ie.getException(); if (ex instanceof StopScriptException) { scripts.remove(this); return; } if (userAgent != null) { userAgent.displayError((ex != null) ? ex : ie); } } scripts.remove(this); endScript(); } } } protected static class StopScriptException extends RuntimeException { public StopScriptException() { } } } 1.6 +2 -2 xml-batik/sources/org/apache/batik/gvt/UpdateTracker.java Index: UpdateTracker.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/UpdateTracker.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- UpdateTracker.java 31 Jan 2002 21:57:35 -0000 1.5 +++ UpdateTracker.java 11 Feb 2002 13:14:29 -0000 1.6 @@ -28,8 +28,8 @@ /** * This class tracks the changes on a GVT tree * - * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: UpdateTracker.java,v 1.5 2002/01/31 21:57:35 deweese Exp $ + * @author <a href="mailto:[EMAIL PROTECTED]">Thomas DeWeese</a> + * @version $Id: UpdateTracker.java,v 1.6 2002/02/11 13:14:29 hillion Exp $ */ public class UpdateTracker extends GraphicsNodeChangeAdapter { 1.10 +15 -17 xml-batik/sources/org/apache/batik/script/rhino/RhinoInterpreter.java Index: RhinoInterpreter.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/script/rhino/RhinoInterpreter.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- RhinoInterpreter.java 30 Jan 2002 17:44:20 -0000 1.9 +++ RhinoInterpreter.java 11 Feb 2002 13:14:29 -0000 1.10 @@ -30,12 +30,13 @@ import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.WrappedException; +import org.mozilla.javascript.WrapHandler; /** * A simple implementation of <code>Interpreter</code> interface to use * Rhino ECMAScript interpreter. * @author <a href="mailto:[EMAIL PROTECTED]">Christophe Jolif</a> - * @version $Id: RhinoInterpreter.java,v 1.9 2002/01/30 17:44:20 cjolif Exp $ + * @version $Id: RhinoInterpreter.java,v 1.10 2002/02/11 13:14:29 hillion Exp $ */ public class RhinoInterpreter implements Interpreter { private static String[] TO_BE_IMPORTED = { @@ -61,9 +62,10 @@ // store last 32 precompiled objects. private static final int MAX_CACHED_SCRIPTS = 32; - private Context context = null; private ScriptableObject globalObject = null; private LinkedList compiledScripts = new LinkedList(); + private WrapHandler wrapHandler = + new EventTargetWrapHandler(this); /** * Build a <code>Interpreter</code> for ECMAScript using Rhino. @@ -72,20 +74,20 @@ */ public RhinoInterpreter() { // entering a context - context = Context.enter(); + Context ctx = Context.enter(); try { // init std object with an importer // building the importer automatically initialize the // context with it since Rhino1.5R3 - ImporterTopLevel importer = new ImporterTopLevel(context); + ImporterTopLevel importer = new ImporterTopLevel(ctx); globalObject = importer; // import Java lang package & DOM Level 2 & SVG DOM packages NativeJavaPackage[] p= new NativeJavaPackage[TO_BE_IMPORTED.length]; for (int i = 0; i < TO_BE_IMPORTED.length; i++) { p[i] = new NativeJavaPackage(TO_BE_IMPORTED[i]); } - importer.importPackage(context, globalObject, p, null); - context.setWrapHandler(new EventTargetWrapHandler(this)); + importer.importPackage(ctx, globalObject, p, null); + ctx.setWrapHandler(wrapHandler = new EventTargetWrapHandler(this)); } finally { Context.exit(); } @@ -98,14 +100,6 @@ return globalObject; } - /** - * This method returns the default context in which the interpreter runs. - */ - protected Context getContext() { - return context; - } - - // org.apache.batik.script.Intepreter implementation /** @@ -117,7 +111,8 @@ public Object evaluate(Reader scriptreader) throws InterpreterException, IOException { Object rv = null; - Context ctx = Context.enter(context); + Context ctx = Context.enter(); + ctx.setWrapHandler(wrapHandler); try { rv = ctx.evaluateReader(globalObject, scriptreader, @@ -156,7 +151,8 @@ */ public Object evaluate(String scriptstr) throws InterpreterException { - Context ctx = Context.enter(context); + Context ctx = Context.enter(); + ctx.setWrapHandler(wrapHandler); Script script = null; Entry et = null; Iterator it = compiledScripts.iterator(); @@ -172,6 +168,7 @@ break; } } + if (script == null) { // this script has not been compiled yet or has been fogotten // since the compilation: @@ -244,7 +241,8 @@ void callHandler(Function handler, Object arg) throws JavaScriptException { - Context ctx = Context.enter(context); + Context ctx = Context.enter(); + ctx.setWrapHandler(wrapHandler); try { arg = Context.toObject(arg, globalObject); Object[] args = {arg}; 1.37 +1 -4 xml-batik/sources/org/apache/batik/swing/svg/JSVGComponent.java Index: JSVGComponent.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/swing/svg/JSVGComponent.java,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- JSVGComponent.java 23 Jan 2002 14:14:09 -0000 1.36 +++ JSVGComponent.java 11 Feb 2002 13:14:29 -0000 1.37 @@ -157,7 +157,7 @@ * building/rendering a document (invalid XML file, missing attributes...).</p> * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: JSVGComponent.java,v 1.36 2002/01/23 14:14:09 deweese Exp $ + * @version $Id: JSVGComponent.java,v 1.37 2002/02/11 13:14:29 hillion Exp $ */ public class JSVGComponent extends JGVTComponent { @@ -298,9 +298,6 @@ } else if (gvtTreeBuilder != null) { gvtTreeBuilder.interrupt(); } else if (updateManager != null) { - if (!updateManager.isRunning()) { - updateManager.resume(); - } updateManager.dispatchSVGUnLoad(); updateManager = null; updateManagerStopped = true; 1.19 +2 -1 xml-batik/sources/org/apache/batik/util/CSSConstants.java Index: CSSConstants.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/util/CSSConstants.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- CSSConstants.java 7 Feb 2002 13:15:54 -0000 1.18 +++ CSSConstants.java 11 Feb 2002 13:14:30 -0000 1.19 @@ -13,7 +13,7 @@ * Important: Constants must not contain uppercase characters. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: CSSConstants.java,v 1.18 2002/02/07 13:15:54 hillion Exp $ + * @version $Id: CSSConstants.java,v 1.19 2002/02/11 13:14:30 hillion Exp $ */ public interface CSSConstants { @@ -57,6 +57,7 @@ String CSS_GLYPH_ORIENTATION_HORIZONTAL_PROPERTY = "glyph-orientation-horizontal"; String CSS_GLYPH_ORIENTATION_VERTICAL_PROPERTY = "glyph-orientation-vertical"; String CSS_IMAGE_RENDERING_PROPERTY = "image-rendering"; + String CSS_KERNING_PROPERTY = "kerning"; String CSS_LETTER_SPACING_PROPERTY = "letter-spacing"; String CSS_LIGHTING_COLOR_PROPERTY = "lighting-color"; String CSS_MARKER_PROPERTY = "marker"; 1.7 +3 -2 xml-batik/sources/org/apache/batik/util/RunnableQueue.java Index: RunnableQueue.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/util/RunnableQueue.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- RunnableQueue.java 21 Dec 2001 14:40:32 -0000 1.6 +++ RunnableQueue.java 11 Feb 2002 13:14:30 -0000 1.7 @@ -16,7 +16,7 @@ * invocation in a single thread. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: RunnableQueue.java,v 1.6 2001/12/21 14:40:32 hillion Exp $ + * @version $Id: RunnableQueue.java,v 1.7 2002/02/11 13:14:30 hillion Exp $ */ public class RunnableQueue implements Runnable { @@ -116,7 +116,7 @@ Runnable rable; try { while (!Thread.currentThread().isInterrupted()) { - + // Mutex for suspention work. synchronized (stateLock) { if (state != RUNNING) { @@ -148,6 +148,7 @@ rable = l.runnable; } + rable.run(); l.unlock(); runnableInvoked(rable); 1.61 +2 -2 xml-batik/sources/org/apache/batik/util/SVGConstants.java Index: SVGConstants.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/util/SVGConstants.java,v retrieving revision 1.60 retrieving revision 1.61 diff -u -r1.60 -r1.61 --- SVGConstants.java 4 Nov 2001 17:57:06 -0000 1.60 +++ SVGConstants.java 11 Feb 2002 13:14:30 -0000 1.61 @@ -14,7 +14,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @author <a href="[EMAIL PROTECTED]">Vincent Hardy</a> * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: SVGConstants.java,v 1.60 2001/11/04 17:57:06 tkormann Exp $ + * @version $Id: SVGConstants.java,v 1.61 2002/02/11 13:14:30 hillion Exp $ */ public interface SVGConstants extends CSSConstants { @@ -205,7 +205,7 @@ String SVG_KERNEL_UNIT_LENGTH_ATTRIBUTE = "kernelUnitLength"; String SVG_KERNEL_UNIT_LENGTH_X_ATTRIBUTE = "kernelUnitLengthX"; String SVG_KERNEL_UNIT_LENGTH_Y_ATTRIBUTE = "kernelUnitLengthY"; - String SVG_KERNING_ATTRIBUTE = "kerning"; + String SVG_KERNING_ATTRIBUTE = CSS_KERNING_PROPERTY; String SVG_LANG_ATTRIBUTE = "lang"; String SVG_LENGTH_ADJUST_ATTRIBUTE = "lengthAdjust"; String SVG_LIGHT_COLOR_ATTRIBUTE = "lightColor"; 1.1 xml-batik/sources/org/apache/batik/util/Lock.java Index: Lock.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.util; /** * This class represents a binary semaphore. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> * @version $Id: Lock.java,v 1.1 2002/02/11 13:14:30 hillion Exp $ */ public class Lock { /** * Whether the lock is locked. */ protected boolean locked; /** * Takes the lock. */ public synchronized void lock() throws InterruptedException { while (locked) { wait(); } locked = true; } /** * Releases the lock. */ public synchronized void unlock() { locked = false; notify(); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]