hillion 02/02/25 07:05:33
Modified: samples starfield.svg
sources/org/apache/batik/bridge
AbstractGraphicsNodeBridge.java
AbstractSVGGradientElementBridge.java
BridgeContext.java BridgeEventSupport.java
DocumentLoader.java RepaintManager.java
RepaintRateManager.java SVGAElementBridge.java
SVGGElementBridge.java SVGImageElementBridge.java
SVGSVGElementBridge.java SVGTextElementBridge.java
SVGUseElementBridge.java ScriptingEnvironment.java
UpdateManager.java
sources/org/apache/batik/dom AbstractDocument.java
AbstractNode.java
sources/org/apache/batik/dom/svg DefaultSVGContext.java
SVGContext.java SVGOMDocument.java
sources/org/apache/batik/script/rhino
EventTargetWrapHandler.java RhinoInterpreter.java
sources/org/apache/batik/swing/svg JSVGComponent.java
SVGLoadEventDispatcher.java
sources/org/apache/batik/util RunnableQueue.java
Added: sources/org/apache/batik/bridge NoRepaintRunnable.java
sources/org/apache/batik/script Window.java
sources/org/apache/batik/script/rhino WindowWrapper.java
Removed: sources/org/apache/batik/script JavaFunction.java
sources/org/apache/batik/script/rhino RhinoFunction.java
Log:
- Scripts are now evaluated from the update thread,
- defined a 'window' object to expose batik to the script writers.
Revision Changes Path
1.3 +22 -20 xml-batik/samples/starfield.svg
Index: starfield.svg
===================================================================
RCS file: /home/cvs/xml-batik/samples/starfield.svg,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- starfield.svg 18 Feb 2002 12:39:48 -0000 1.2
+++ starfield.svg 25 Feb 2002 15:05:31 -0000 1.3
@@ -14,7 +14,7 @@
<!-- A star field -->
<!-- -->
<!-- @author [EMAIL PROTECTED] -->
-<!-- @version $Id: starfield.svg,v 1.2 2002/02/18 12:39:48 hillion Exp $ -->
+<!-- @version $Id: starfield.svg,v 1.3 2002/02/25 15:05:31 hillion Exp $ -->
<!-- ========================================================================= -->
<svg xmlns="http://www.w3.org/2000/svg"
@@ -115,14 +115,15 @@
var showControlPanel = false
var helpText1 = "Click on the title to show the control panel"
var helpText2 = "Click on the title to hide the control panel"
-
+ var startDate;
+ var nframe;
//
// Decreases the number of stars. If numberOfStars is at his min value,
// do nothing.
//
function decreaseNumberOfStars(evt) {
- if (numberOfStars == starIncrement) {
+ if (numberOfStars == 0) {
return
}
@@ -132,7 +133,7 @@
updateText("number-label", numberOfStars)
unitCount--
- units.setAttributeNS(null, "width", ""+(unitCount * 10))
+ units.setAttributeNS(null, "width", unitCount * 10)
}
//
@@ -150,7 +151,7 @@
updateText("number-label", numberOfStars)
unitCount++
- units.setAttributeNS(null, "width", ""+(unitCount * 10))
+ units.setAttributeNS(null, "width", unitCount * 10)
}
@@ -170,6 +171,8 @@
grp.replaceChild(newelt, elt)
}
+ var itv;
+
//
// Starts the animation loops.
//
@@ -183,32 +186,31 @@
}
updateText("help", helpText1)
- setTimeout("animateStars()", 50, new Date(), 0)
-
- startDate = new Date();
+ itv = setInterval("animateStars()", 50)
+
+ startDate = new Date()
+ nframe = 0
}
//
- // The stars animation.
+ // Animates the stars.
//
- function animateStars(dt, n) {
+ function animateStars() {
for (var i = 0; i < starIncrement * 10; i++) {
stars[i].update()
}
- if (n < 10) {
- n++
+ if (nframe < 10) {
+ nframe++
} else {
var d = new Date()
- var dt = d - dt
+ var dt = d - startDate
var val = Math.round(10000 / dt)
updateText("fps1", val);
updateText("fps2", val);
- dt = d
- n = 0
+ startDate = d
+ nframe = 0
}
-
- setTimeout("animateStars()", 50, dt, n)
}
//
@@ -220,10 +222,10 @@
showControlPanel = !showControlPanel
if (showControlPanel) {
updateText("help", helpText2)
- setTimeout("controlPanelAnimation()", 50, 20, 1)
+ setTimeout(controlPanelAnimation, 50, 20, 1)
} else {
updateText("help", helpText1)
- setTimeout("controlPanelAnimation()", 50, 0, -1)
+ setTimeout(controlPanelAnimation, 50, 0, -1)
}
}
}
@@ -237,7 +239,7 @@
elt.setAttributeNS(null, "transform", "translate(0 " + ((n - 100) *
sgn) + ")");
if (n < 200) {
- setTimeout("controlPanelAnimation()", 50, n + 20, sgn)
+ setTimeout(controlPanelAnimation, 50, n + 20, sgn)
} else {
controlPanelMoving = false;
}
1.14 +3 -2
xml-batik/sources/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java
Index: AbstractGraphicsNodeBridge.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- AbstractGraphicsNodeBridge.java 15 Feb 2002 14:58:44 -0000 1.13
+++ AbstractGraphicsNodeBridge.java 25 Feb 2002 15:05:31 -0000 1.14
@@ -39,7 +39,7 @@
* </ul>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
- * @version $Id: AbstractGraphicsNodeBridge.java,v 1.13 2002/02/15 14:58:44
tkormann Exp $
+ * @version $Id: AbstractGraphicsNodeBridge.java,v 1.14 2002/02/25 15:05:31 hillion
Exp $
*/
public abstract class AbstractGraphicsNodeBridge extends AbstractSVGBridge
implements BridgeUpdateHandler, GraphicsNodeBridge, ErrorConstants {
@@ -200,7 +200,8 @@
/**
* The listener class for 'DOMAttrModified' event.
*/
- protected class DOMAttrModifiedEventListener implements EventListener {
+ protected class DOMAttrModifiedEventListener
+ implements UnwrappedEventListener {
/**
* Handles 'DOMAttrModfied' events and deleguates to the
1.5 +3 -2
xml-batik/sources/org/apache/batik/bridge/AbstractSVGGradientElementBridge.java
Index: AbstractSVGGradientElementBridge.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/AbstractSVGGradientElementBridge.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractSVGGradientElementBridge.java 15 Feb 2002 14:58:44 -0000 1.4
+++ AbstractSVGGradientElementBridge.java 25 Feb 2002 15:05:31 -0000 1.5
@@ -33,7 +33,7 @@
* Bridge class for vending gradients.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
- * @version $Id: AbstractSVGGradientElementBridge.java,v 1.4 2002/02/15 14:58:44
tkormann Exp $
+ * @version $Id: AbstractSVGGradientElementBridge.java,v 1.5 2002/02/25 15:05:31
hillion Exp $
*/
public abstract class AbstractSVGGradientElementBridge extends AbstractSVGBridge
implements PaintBridge, ErrorConstants {
@@ -199,7 +199,8 @@
/**
* The listener class for 'DOMAttrModified' event.
*/
- protected class DOMAttrModifiedEventListener implements EventListener {
+ protected class DOMAttrModifiedEventListener
+ implements UnwrappedEventListener {
/**
* Handles 'DOMAttrModfied' events and deleguates to the
1.38 +6 -2 xml-batik/sources/org/apache/batik/bridge/BridgeContext.java
Index: BridgeContext.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/BridgeContext.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- BridgeContext.java 22 Feb 2002 16:52:09 -0000 1.37
+++ BridgeContext.java 25 Feb 2002 15:05:31 -0000 1.38
@@ -22,6 +22,8 @@
import java.util.Map;
import org.apache.batik.css.HiddenChildElementSupport;
+import org.apache.batik.dom.svg.DefaultSVGContext;
+import org.apache.batik.dom.svg.SVGOMDocument;
import org.apache.batik.gvt.GraphicsNode;
import org.apache.batik.gvt.TextPainter;
import org.apache.batik.script.Interpreter;
@@ -31,6 +33,8 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.events.EventListener;
import org.w3c.dom.svg.SVGDocument;
import org.apache.batik.gvt.filter.GraphicsNodeRableFactory;
@@ -47,7 +51,7 @@
* a SVG DOM tree such as the current viewport or the user agent.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
- * @version $Id: BridgeContext.java,v 1.37 2002/02/22 16:52:09 tkormann Exp $
+ * @version $Id: BridgeContext.java,v 1.38 2002/02/25 15:05:31 hillion Exp $
*/
public class BridgeContext implements ErrorConstants {
@@ -217,7 +221,7 @@
// end debug leak
*/
- // properties
+ // properties ////////////////////////////////////
/**
* Sets the text painter that will be used by text nodes. This attributes
1.24 +4 -4
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.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- BridgeEventSupport.java 18 Feb 2002 09:11:58 -0000 1.23
+++ BridgeEventSupport.java 25 Feb 2002 15:05:31 -0000 1.24
@@ -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.23 2002/02/18 09:11:58 hillion Exp $
+ * @version $Id: BridgeEventSupport.java,v 1.24 2002/02/25 15:05:31 hillion Exp $
*/
class BridgeEventSupport implements SVGConstants {
private static final String[] EVENT_ATTRIBUTES_GRAPHICS = {
@@ -218,7 +218,7 @@
* by the bridge on the unload event.
*/
private static class SVGUnloadListener
- implements EventListener {
+ implements UnwrappedEventListener {
private class Entry {
String type;
EventListener caller;
@@ -280,7 +280,7 @@
}
private static class GVTUnloadListener
- implements EventListener {
+ implements UnwrappedEventListener {
private EventDispatcher dispatcher;
private Listener listener;
GVTUnloadListener(EventDispatcher dispatcher, Listener listener) {
@@ -417,7 +417,7 @@
}
}
- public static class ScriptCaller implements EventListener {
+ public static class ScriptCaller implements UnwrappedEventListener {
private String script = null;
private BridgeContext context;
private String language;
1.12 +5 -5 xml-batik/sources/org/apache/batik/bridge/DocumentLoader.java
Index: DocumentLoader.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/DocumentLoader.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- DocumentLoader.java 24 Oct 2001 14:52:35 -0000 1.11
+++ DocumentLoader.java 25 Feb 2002 15:05:31 -0000 1.12
@@ -30,7 +30,7 @@
* maintaining a cache.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
- * @version $Id: DocumentLoader.java,v 1.11 2001/10/24 14:52:35 tkormann Exp $
+ * @version $Id: DocumentLoader.java,v 1.12 2002/02/25 15:05:31 hillion Exp $
*/
public class DocumentLoader {
@@ -72,7 +72,8 @@
/**
* Returns a document from the specified uri.
* @param uri the uri of the document
- * @exception IOException if an I/O error occured while loading the document
+ * @exception IOException if an I/O error occured while loading
+ * the document
*/
public Document loadDocument(String uri) throws IOException {
int n = uri.indexOf('#');
@@ -82,10 +83,9 @@
DocumentState state = (DocumentState)cacheMap.get(uri);
if (state == null) {
Document document = documentFactory.createDocument(uri);
- DefaultSVGContext ctx
- = (DefaultSVGContext)((SVGOMDocument)document).getSVGContext();
+ SVGOMDocument svgDoc = (SVGOMDocument)document;
+ DefaultSVGContext ctx = (DefaultSVGContext)svgDoc.getSVGContext();
ctx.setUserStyleSheetURI(userAgent.getUserStyleSheetURI());
-
DocumentDescriptor desc = documentFactory.getDocumentDescriptor();
state = new DocumentState(uri, document, desc);
cacheMap.put(uri, state);
1.10 +22 -43 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- RepaintManager.java 22 Feb 2002 16:52:09 -0000 1.9
+++ RepaintManager.java 25 Feb 2002 15:05:31 -0000 1.10
@@ -26,7 +26,7 @@
* This class manages the rendering of a GVT tree.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: RepaintManager.java,v 1.9 2002/02/22 16:52:09 tkormann Exp $
+ * @version $Id: RepaintManager.java,v 1.10 2002/02/25 15:05:31 hillion Exp $
*/
public class RepaintManager {
@@ -46,6 +46,15 @@
protected boolean enabled;
/**
+ * The repaint runnable.
+ */
+ protected Runnable repaintRunnable = new Runnable() {
+ public void run() {
+ repaint();
+ }
+ };
+
+ /**
* Creates a new repaint manager.
*/
public RepaintManager(UpdateManager um, ImageRenderer r) {
@@ -54,52 +63,22 @@
}
/**
- * Provokes a repaint, if needed.
- * @param b If true, waits until the repaint has finished.
+ * Repaints the dirty areas, if needed.
*/
- public void repaint(boolean b) throws InterruptedException {
- 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) {
- // Calls the UpdateManager methods
- // to allow events to be fired.
- updateManager.modifiedAreas(dirtyAreas);
- updateManager.updateRendering(dirtyAreas);
- }
- ut.clear();
- }
- }
- };
- if (updateManager.getUpdateRunnableQueue().getThread() == null) {
- return;
- }
- if (b) {
- updateManager.getUpdateRunnableQueue().invokeAndWait(r);
- } else {
- updateManager.getUpdateRunnableQueue().invokeLater(r);
+ public void repaint() {
+ UpdateTracker ut = updateManager.getUpdateTracker();
+ if (ut.hasChanged()) {
+ List dirtyAreas = ut.getDirtyAreas();
+ if (dirtyAreas != null) {
+ // Calls the UpdateManager methods
+ // to allow events to be fired.
+ updateManager.modifiedAreas(dirtyAreas);
+ updateManager.updateRendering(dirtyAreas);
+ }
+ ut.clear();
}
}
- /**
- * Suspends the repaint management.
- */
- public void disable() {
- enabled = false;
- }
-
- /**
- * Suspends the repaint management.
- */
- public void enable() {
- enabled = true;
- }
-
/**
* Call this to let the Repaint Manager know that certain areas
* in the image have been modified and need to be rerendered..
1.2 +19 -4
xml-batik/sources/org/apache/batik/bridge/RepaintRateManager.java
Index: RepaintRateManager.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/RepaintRateManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RepaintRateManager.java 11 Feb 2002 13:14:29 -0000 1.1
+++ RepaintRateManager.java 25 Feb 2002 15:05:31 -0000 1.2
@@ -8,12 +8,14 @@
package org.apache.batik.bridge;
+import org.apache.batik.util.RunnableQueue;
+
/**
* 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 $
+ * @version $Id: RepaintRateManager.java,v 1.2 2002/02/25 15:05:31 hillion Exp $
*/
public class RepaintRateManager extends Thread {
@@ -44,18 +46,31 @@
* current frame-rate easily)
*/
public void run() {
- long lastFrameTime, currentTime, tm, sleepTime;
+ long lastFrameTime;
+ long currentTime;
+ long tm;
+ long sleepTime;
+
+ final RepaintManager rm = updateManager.getRepaintManager();
+ Runnable repaintRunnable = new NoRepaintRunnable() {
+ public void run() {
+ rm.repaint();
+ }
+ };
+ RunnableQueue rq = updateManager.getUpdateRunnableQueue();
+
try {
while (!Thread.currentThread().isInterrupted()) {
lastFrameTime = System.currentTimeMillis();
- updateManager.getRepaintManager().repaint(true);
+ rq.invokeAndWait(repaintRunnable);
currentTime = System.currentTimeMillis();
tm = currentTime - lastFrameTime;
sleepTime = targetFrameTime-tm;
- if (sleepTime > 0)
+ if (sleepTime > 0) {
sleep(sleepTime);
+ }
}
} catch (InterruptedException e) {
}
1.12 +7 -4 xml-batik/sources/org/apache/batik/bridge/SVGAElementBridge.java
Index: SVGAElementBridge.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGAElementBridge.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- SVGAElementBridge.java 19 Nov 2001 08:29:25 -0000 1.11
+++ SVGAElementBridge.java 25 Feb 2002 15:05:31 -0000 1.12
@@ -25,7 +25,7 @@
* Bridge class for the <a> element.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
- * @version $Id: SVGAElementBridge.java,v 1.11 2001/11/19 08:29:25 tkormann Exp $
+ * @version $Id: SVGAElementBridge.java,v 1.12 2002/02/25 15:05:31 hillion Exp $
*/
public class SVGAElementBridge extends AbstractGraphicsNodeBridge {
@@ -87,7 +87,8 @@
/**
* To handle a click on an anchor.
*/
- protected static class AnchorListener implements EventListener {
+ protected static class AnchorListener
+ implements UnwrappedEventListener {
protected UserAgent userAgent;
@@ -115,7 +116,8 @@
/**
* To handle a mouseover on an anchor and set the cursor.
*/
- protected static class CursorMouseOverListener implements EventListener {
+ protected static class CursorMouseOverListener
+ implements UnwrappedEventListener {
protected UserAgent userAgent;
@@ -146,7 +148,8 @@
/**
* To handle a mouseout on an anchor and set the cursor.
*/
- protected static class CursorMouseOutListener implements EventListener {
+ protected static class CursorMouseOutListener
+ implements UnwrappedEventListener {
protected UserAgent userAgent;
1.15 +5 -3 xml-batik/sources/org/apache/batik/bridge/SVGGElementBridge.java
Index: SVGGElementBridge.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGGElementBridge.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- SVGGElementBridge.java 15 Feb 2002 14:58:44 -0000 1.14
+++ SVGGElementBridge.java 25 Feb 2002 15:05:31 -0000 1.15
@@ -26,7 +26,7 @@
* Bridge class for the <g> element.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
- * @version $Id: SVGGElementBridge.java,v 1.14 2002/02/15 14:58:44 tkormann Exp $
+ * @version $Id: SVGGElementBridge.java,v 1.15 2002/02/25 15:05:31 hillion Exp $
*/
public class SVGGElementBridge extends AbstractGraphicsNodeBridge {
@@ -190,7 +190,8 @@
/**
* The listener class for 'DOMNodeInserted' event.
*/
- protected class DOMNodeInsertedEventListener implements EventListener {
+ protected class DOMNodeInsertedEventListener
+ implements UnwrappedEventListener {
/**
* Handles 'DOMNodeInserted' events and deleguates to the
@@ -210,7 +211,8 @@
/**
* The listener class for 'DOMNodeRemoved' event.
*/
- protected class DOMNodeRemovedEventListener implements EventListener {
+ protected class DOMNodeRemovedEventListener
+ implements UnwrappedEventListener {
/**
* Handles 'DOMNodeRemoved' events and deleguates to the
1.39 +3 -2
xml-batik/sources/org/apache/batik/bridge/SVGImageElementBridge.java
Index: SVGImageElementBridge.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGImageElementBridge.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- SVGImageElementBridge.java 19 Feb 2002 18:01:29 -0000 1.38
+++ SVGImageElementBridge.java 25 Feb 2002 15:05:31 -0000 1.39
@@ -53,7 +53,7 @@
* Bridge class for the <image> element.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
- * @version $Id: SVGImageElementBridge.java,v 1.38 2002/02/19 18:01:29 deweese Exp $
+ * @version $Id: SVGImageElementBridge.java,v 1.39 2002/02/25 15:05:31 hillion Exp $
*/
public class SVGImageElementBridge extends AbstractGraphicsNodeBridge {
@@ -355,7 +355,8 @@
* A simple DOM listener to forward events from the SVG image document to
* the original document.
*/
- protected static class ForwardEventListener implements EventListener {
+ protected static class ForwardEventListener
+ implements UnwrappedEventListener {
/**
* The root element of the SVG image.
1.24 +3 -2
xml-batik/sources/org/apache/batik/bridge/SVGSVGElementBridge.java
Index: SVGSVGElementBridge.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGSVGElementBridge.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- SVGSVGElementBridge.java 15 Feb 2002 14:58:44 -0000 1.23
+++ SVGSVGElementBridge.java 25 Feb 2002 15:05:31 -0000 1.24
@@ -33,7 +33,7 @@
* Bridge class for the <svg> element.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
- * @version $Id: SVGSVGElementBridge.java,v 1.23 2002/02/15 14:58:44 tkormann Exp $
+ * @version $Id: SVGSVGElementBridge.java,v 1.24 2002/02/25 15:05:31 hillion Exp $
*/
public class SVGSVGElementBridge extends AbstractSVGBridge
implements GraphicsNodeBridge, ErrorConstants {
@@ -259,7 +259,8 @@
/**
* The listener class for 'DOMAttrModified' event.
*/
- protected class DOMAttrModifiedEventListener implements EventListener {
+ protected class DOMAttrModifiedEventListener
+ implements UnwrappedEventListener {
/**
* Handles 'DOMAttrModfied' events and deleguates to the
1.50 +3 -2
xml-batik/sources/org/apache/batik/bridge/SVGTextElementBridge.java
Index: SVGTextElementBridge.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGTextElementBridge.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- SVGTextElementBridge.java 15 Feb 2002 14:58:45 -0000 1.49
+++ SVGTextElementBridge.java 25 Feb 2002 15:05:31 -0000 1.50
@@ -60,7 +60,7 @@
* Bridge class for the <text> element.
*
* @author <a href="[EMAIL PROTECTED]>Bill Haneman</a>
- * @version $Id: SVGTextElementBridge.java,v 1.49 2002/02/15 14:58:45 tkormann Exp $
+ * @version $Id: SVGTextElementBridge.java,v 1.50 2002/02/25 15:05:31 hillion Exp $
*/
public class SVGTextElementBridge extends AbstractSVGBridge
implements BridgeUpdateHandler, GraphicsNodeBridge, ErrorConstants {
@@ -308,7 +308,8 @@
/**
* The listener class for 'DOMAttrModified' event.
*/
- protected class DOMAttrModifiedEventListener implements EventListener {
+ protected class DOMAttrModifiedEventListener
+ implements UnwrappedEventListener {
/**
* Handles 'DOMAttrModfied' events and deleguates to the
1.21 +3 -2
xml-batik/sources/org/apache/batik/bridge/SVGUseElementBridge.java
Index: SVGUseElementBridge.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGUseElementBridge.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- SVGUseElementBridge.java 15 Feb 2002 14:58:45 -0000 1.20
+++ SVGUseElementBridge.java 25 Feb 2002 15:05:31 -0000 1.21
@@ -37,7 +37,7 @@
* Bridge class for the <use> element.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
- * @version $Id: SVGUseElementBridge.java,v 1.20 2002/02/15 14:58:45 tkormann Exp $
+ * @version $Id: SVGUseElementBridge.java,v 1.21 2002/02/25 15:05:31 hillion Exp $
*/
public class SVGUseElementBridge extends AbstractSVGBridge
implements GraphicsNodeBridge, ErrorConstants {
@@ -285,7 +285,8 @@
/**
* The listener class for 'DOMAttrModified' event.
*/
- protected class DOMAttrModifiedEventListener implements EventListener {
+ protected class DOMAttrModifiedEventListener
+ implements UnwrappedEventListener {
/**
* Handles 'DOMAttrModfied' events and deleguates to the
1.9 +256 -312
xml-batik/sources/org/apache/batik/bridge/ScriptingEnvironment.java
Index: ScriptingEnvironment.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/ScriptingEnvironment.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ScriptingEnvironment.java 22 Feb 2002 14:06:41 -0000 1.8
+++ ScriptingEnvironment.java 25 Feb 2002 15:05:31 -0000 1.9
@@ -16,12 +16,12 @@
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
import org.apache.batik.dom.svg.SVGOMDocument;
@@ -30,9 +30,7 @@
import org.apache.batik.script.Interpreter;
import org.apache.batik.script.InterpreterException;
import org.apache.batik.script.InterpreterPool;
-import org.apache.batik.script.JavaFunction;
-import org.apache.batik.util.Lock;
import org.apache.batik.util.RunnableQueue;
import org.apache.batik.util.SVGConstants;
@@ -52,7 +50,7 @@
* 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.8 2002/02/22 14:06:41 hillion Exp $
+ * @version $Id: ScriptingEnvironment.java,v 1.9 2002/02/25 15:05:31 hillion Exp $
*/
public class ScriptingEnvironment {
@@ -158,13 +156,13 @@
}
- private final static String EVENT_NAME = "evt";
- private final static String ARG_NAME = "arg__";
+ private final static String EVENT_NAME = "event";
+ private final static String ALTERNATE_EVENT_NAME = "evt";
/**
- * The scripting lock.
+ * The timer for periodic or delayed tasks.
*/
- protected Lock scriptingLock;
+ Timer timer = new Timer(true);
/**
* The update manager.
@@ -182,195 +180,81 @@
protected RunnableQueue updateRunnableQueue;
/**
- * Whether the scripts must be suspended.
- */
- protected volatile boolean suspended;
-
- /**
* The bridge context.
*/
protected BridgeContext bridgeContext;
-
+
/**
- * The suspend lock.
+ * The user-agent.
*/
- protected Object suspendLock = new Object();
-
+ protected UserAgent userAgent;
+
/**
* The document to manage.
*/
protected Document document;
/**
- * The alert function.
- */
- protected JavaFunction alertFunction;
-
- /**
- * The live scripting threads.
- */
- protected List liveThreads =
- Collections.synchronizedList(new LinkedList());
-
- /**
- * Whether this environment has been interrupted.
- */
- protected boolean interrupted;
-
- /**
* Creates a new ScriptingEnvironment.
* @param um The update manager.
*/
public ScriptingEnvironment(UpdateManager um) {
- scriptingLock = new Lock();
updateManager = um;
bridgeContext = updateManager.getBridgeContext();
- document = updateManager.getDocument();
+ userAgent = bridgeContext.getUserAgent();
+ document = updateManager.getDocument();
+ updateRunnableQueue = um.getUpdateRunnableQueue();
}
/**
- * Initializes the environment of the given interpreter.
+ * Creates a new Window object.
*/
- public void initializeEnvironment(Interpreter interp, String lang) {
- interp.bindObject("alert", getAlertFunction());
- interp.bindObject("setTimeout", getSetTimeoutFunction(lang));
+ public Window createWindow(Interpreter interp, String lang) {
+ return new Window(interp, lang);
}
/**
- * Returns the scripting lock.
+ * Creates a new Window object.
*/
- public Lock getScriptingLock() {
- return scriptingLock;
+ public Window createWindow() {
+ return new Window(null, null);
}
/**
- * Runs an event handler.
- */
- public void runEventHandler(String script, Event evt, String lang) {
- new EventHandlerThread(script, evt, lang).start();
- }
-
- /**
- * Runs a function.
- */
- public void runFunction(String function,
- Object[] args,
- String lang,
- long delay) {
- new FunctionCallThread(function, args, lang, delay).start();
- }
-
- /**
- * Interrupts the scripts.
- */
- public void interruptScripts() {
- synchronized (liveThreads) {
- interrupted = true;
- Iterator it = liveThreads.iterator();
- while (it.hasNext()) {
- scriptingLock.unlock();
- ((Thread)it.next()).interrupt();
- }
- }
- }
-
- /**
- * Suspends the scripts.
- */
- public void suspendScripts() {
- suspended = true;
- }
-
- /**
- * Resumes the scripts.
+ * Initializes the environment of the given interpreter.
*/
- public void resumeScripts() {
- synchronized (suspendLock) {
- suspended = false;
- suspendLock.notifyAll();
- }
+ public void initializeEnvironment(Interpreter interp, String lang) {
+ interp.bindObject("window", new Window(interp, lang));
}
/**
- * Begins a script evaluation section.
+ * Runs an event handler.
*/
- public void beginScript() {
- try {
- scriptingLock.lock();
- } catch (InterruptedException e) {
- throw new StopScriptException();
- }
- synchronized (suspendLock) {
- if (suspended) {
- try {
- suspendLock.wait();
- } catch (InterruptedException e) {
- throw new StopScriptException();
- }
+ public void runEventHandler(String script, Event evt, String lang) {
+ Interpreter interpreter = bridgeContext.getInterpreter(lang);
+ if (interpreter == null) {
+ if (userAgent != null) {
+ userAgent.displayError
+ (new Exception("unknow language: " + lang));
}
}
- if (repaintManager == null) {
- repaintManager = updateManager.getRepaintManager();
- if (repaintManager == null) {
- throw new StopScriptException();
- }
- updateRunnableQueue = updateManager.getUpdateRunnableQueue();
- }
- 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) {
- throw new StopScriptException();
- }
- }
- }
- repaintManager.enable();
- if (updateRunnableQueue.getThread() == null) {
- scriptingLock.unlock();
- throw new StopScriptException();
- }
- updateRunnableQueue.resumeExecution();
-
+ interpreter.bindObject(EVENT_NAME, evt);
+ interpreter.bindObject(ALTERNATE_EVENT_NAME, evt);
+
try {
- repaintManager.repaint(true);
- } catch (InterruptedException e) {
- throw new StopScriptException();
+ interpreter.evaluate(script);
+ } catch (InterpreterException ie) {
+ handleInterpreterException(ie);
}
- scriptingLock.unlock();
}
/**
- * Pauses the current script for the given amount of time.
+ * Interrupts the periodic tasks.
*/
- 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();
- }
+ public void interrupt() {
+ timer.cancel();
}
/**
@@ -432,16 +316,12 @@
interpreter.evaluate(reader);
} catch (IOException e) {
- UserAgent ua = bridgeContext.getUserAgent();
- if (ua != null) {
- ua.displayError(e);
+ if (userAgent != null) {
+ userAgent.displayError(e);
}
+ return;
} catch (InterpreterException e) {
- UserAgent ua = bridgeContext.getUserAgent();
- if (ua != null) {
- Exception ex = e.getException();
- ua.displayError((ex == null) ? e : ex);
- }
+ handleInterpreterException(e);
return;
}
}
@@ -487,18 +367,15 @@
elt.getAttributeNS(null, SVGConstants.SVG_ONLOAD_ATTRIBUTE);
EventListener l = null;
if (s.length() > 0) {
- l = new EventListener() {
+ l = new UnwrappedEventListener() {
public void handleEvent(Event evt) {
try {
interp.bindObject(EVENT_NAME, evt);
+ interp.bindObject(ALTERNATE_EVENT_NAME, evt);
interp.evaluate(new StringReader(s));
} catch (IOException io) {
} catch (InterpreterException e) {
- UserAgent ua = bridgeContext.getUserAgent();
- if (ua != null) {
- Exception ex = e.getException();
- ua.displayError((ex == null) ? e : ex);
- }
+ handleInterpreterException(e);
}
}
};
@@ -511,206 +388,273 @@
}
/**
- * Returns the 'alert' function.
+ * Handles the given exception.
*/
- protected JavaFunction getAlertFunction() {
- if (alertFunction == null) {
- alertFunction = new JavaFunction() {
- public Class[] getParameterTypes() {
- return new Class[] { String.class };
- }
- public Object call(Object[] arguments) {
- javax.swing.JOptionPane.showMessageDialog
- (null, (String)arguments[0]);
- return null;
- }
- };
+ protected void handleInterpreterException(InterpreterException ie) {
+ if (userAgent != null) {
+ Exception ex = ie.getException();
+ userAgent.displayError((ex == null) ? ie : ex);
}
- return alertFunction;
}
+ /**
+ * To wrap an event listener.
+ */
+ protected class EventListenerWrapper implements UnwrappedEventListener {
- protected final static Class[] ST_PARAMS = { String.class, Long.TYPE };
+ /**
+ * The wrapped event listener.
+ */
+ protected EventListener eventListener;
+
+ /**
+ * Creates a new EventListenerWrapper.
+ */
+ public EventListenerWrapper(EventListener el) {
+ eventListener = el;
+ }
+
+ public void handleEvent(final Event evt) {
+ eventListener.handleEvent(evt);
+ }
+ }
/**
- * Returns the 'setTimeout' function.
+ * To interpret a script.
*/
- protected JavaFunction getSetTimeoutFunction(final String lang) {
- return new JavaFunction() {
- public Class[] getParameterTypes() {
- return ST_PARAMS;
- }
- public Object call(Object[] args) {
- Object[] fargs = new Object[args.length - 2];
- for (int i = 0; i < fargs.length; i++) {
- fargs[i] = args[i + 2];
- }
- runFunction((String)args[0], fargs, lang,
- ((Long)args[1]).longValue());
- return null;
- }
- };
+ protected class EvaluateRunnable implements Runnable {
+ protected Interpreter interpreter;
+ protected String script;
+ public EvaluateRunnable(String s, Interpreter interp) {
+ interpreter = interp;
+ script = s;
+ }
+ public void run() {
+ try {
+ interpreter.evaluate(script);
+ } catch (InterpreterException ie) {
+ handleInterpreterException(ie);
+ }
+ }
}
/**
- * To run a piece of script.
+ * To interpret a script.
*/
- protected abstract class ScriptingThread extends Thread {
+ protected class EvaluateIntervalRunnable implements Runnable {
+ /**
+ * Incremented each time this runnable is added to the queue.
+ */
+ public int count;
- protected UserAgent userAgent;
protected Interpreter interpreter;
+ protected String script;
+
+ public EvaluateIntervalRunnable(String s, Interpreter interp) {
+ interpreter = interp;
+ script = s;
+ }
+ public void run() {
+ count--;
+ try {
+ interpreter.evaluate(script);
+ } catch (InterpreterException ie) {
+ handleInterpreterException(ie);
+ }
+ }
+ }
+ /**
+ * To call a Runnable.
+ */
+ protected class EvaluateRunnableRunnable implements Runnable {
/**
- * Creates a new scripting thread.
+ * Incremented each time this runnable is put in the queue.
*/
- public ScriptingThread(String lang) {
- BridgeContext bc = updateManager.getBridgeContext();
- userAgent = bc.getUserAgent();
- Document doc = updateManager.getDocument();
- interpreter = bc.getInterpreter(lang);
- if (interpreter == null) {
+ public int count;
+
+ protected Runnable runnable;
+
+ public EvaluateRunnableRunnable(Runnable r) {
+ runnable = r;
+ }
+ public void run() {
+ count--;
+ try {
+ runnable.run();
+ } catch (Exception e) {
if (userAgent != null) {
- userAgent.displayError
- (new Exception("unknow language: " + lang));
+ userAgent.displayError(e);
}
}
}
+ }
+
+ /**
+ * Represents the window object of this environment.
+ */
+ public class Window implements org.apache.batik.script.Window {
/**
- * The main method.
+ * The associated interpreter.
*/
- public void run() {
- try {
- liveThreads.add(this);
- if (interrupted) {
- return;
- }
- if (interpreter != null) {
- try {
- beginScript();
- } catch (StopScriptException e) {
- return;
- }
-
- try {
- interpreter.evaluate(getScript());
- } catch (InterpreterException ie) {
- Exception ex = ie.getException();
- if (ex instanceof StopScriptException) {
+ protected Interpreter interpreter;
+
+ /**
+ * The associated language.
+ */
+ protected String language;
+
+ /**
+ * Creates a new Window for the given language.
+ */
+ public Window(Interpreter interp, String lang) {
+ interpreter = interp;
+ language = lang;
+ }
+
+ /**
+ * Implements {@link
+ * org.apache.batik.script.Window#setInterval(String,long)}.
+ */
+ public Object setInterval(final String script, long interval) {
+ TimerTask tt = new TimerTask() {
+ EvaluateIntervalRunnable eir =
+ new EvaluateIntervalRunnable(script, interpreter);
+ public void run() {
+ if (eir.count > 1) {
return;
}
- if (userAgent != null) {
- userAgent.displayError((ex != null) ? ex : ie);
- }
+ eir.count++;
+ updateRunnableQueue.invokeLater(eir);
}
- if (!interrupted) {
- try {
- endScript();
- } catch (StopScriptException e) {
+ };
+
+ timer.schedule(tt, interval, interval);
+ return tt;
+ }
+
+ /**
+ * Implements {@link
+ * org.apache.batik.script.Window#setInterval(Runnable,long)}.
+ */
+ public Object setInterval(final Runnable r, long interval) {
+ TimerTask tt = new TimerTask() {
+ EvaluateRunnableRunnable eihr =
+ new EvaluateRunnableRunnable(r);
+ public void run() {
+ if (eihr.count > 1) {
+ return;
}
+ eihr.count++;
+ updateRunnableQueue.invokeLater(eihr);
}
- }
- } finally {
- liveThreads.remove(this);
- }
+ };
+
+ timer.schedule(tt, interval, interval);
+ return tt;
}
/**
- * Returns the script to execute.
+ * Implements {@link
+ * org.apache.batik.script.Window#clearInterval(Object)}.
*/
- protected abstract String getScript();
+ public void clearInterval(Object interval) {
+ ((TimerTask)interval).cancel();
+ }
- }
+ /**
+ * Implements {@link
+ * org.apache.batik.script.Window#setTimeout(String,long)}.
+ */
+ public Object setTimeout(final String script, long timeout) {
+ TimerTask tt = new TimerTask() {
+ public void run() {
+ updateRunnableQueue.invokeLater
+ (new EvaluateRunnable(script, interpreter));
+ }
+ };
- /**
- * To run a function.
- */
- protected class FunctionCallThread extends ScriptingThread {
- protected String function;
- protected Object[] arguments;
- protected long delay;
+ timer.schedule(tt, timeout);
+ return tt;
+ }
/**
- * Creates a new FunctionCallThread.
+ * Implements {@link
+ * org.apache.batik.script.Window#setTimeout(Runnable,long)}.
*/
- public FunctionCallThread(String fname,
- Object[] args,
- String lang,
- long delay) {
- super(lang);
- function = fname;
- arguments = args;
- this.delay = delay;
+ public Object setTimeout(final Runnable r, long timeout) {
+ TimerTask tt = new TimerTask() {
+ public void run() {
+ updateRunnableQueue.invokeLater(new Runnable() {
+ public void run() {
+ try {
+ r.run();
+ } catch (Exception e) {
+ if (userAgent != null) {
+ userAgent.displayError(e);
+ }
+ }
+ }
+ });
+ }
+ };
+
+ timer.schedule(tt, timeout);
+ return tt;
}
/**
- * The main method.
+ * Implements {@link
+ * org.apache.batik.script.Window#clearTimeout(Object)}.
*/
- public void run() {
- if (delay > 0) {
- try {
- sleep(delay);
- } catch (InterruptedException e) {
- return;
- }
- }
- super.run();
+ public void clearTimeout(Object timeout) {
+ ((TimerTask)timeout).cancel();
}
/**
- * Returns the script to execute.
+ * Displays an alert dialog box.
*/
- protected String getScript() {
- if (function.endsWith("()")) {
- function = function.substring(0, function.length() - 2);
- }
- StringBuffer sb = new StringBuffer(function);
-
- sb.append("(");
- if (arguments.length > 0) {
- String s = ARG_NAME + 0;
- sb.append(s);
- interpreter.bindObject(s, arguments[0]);
- for (int i = 1; i < arguments.length; i++) {
- s = ARG_NAME + i;
- sb.append(",");
- sb.append(s);
- interpreter.bindObject(s, arguments[i]);
- }
- }
- sb.append(")");
- return sb.toString();
+ public void alert(String message) {
+ javax.swing.JOptionPane.showMessageDialog
+ (null, "Script alert:\n" + message);
}
- }
- /**
- * To run an event handler.
- */
- protected class EventHandlerThread extends ScriptingThread {
- protected String script;
- protected Event event;
+ /**
+ * Displays a confirm dialog box.
+ */
+ public boolean confirm(String message) {
+ return javax.swing.JOptionPane.showConfirmDialog
+ (null, "Script confirm:\n" + message,
+ "Confirm",javax.swing.JOptionPane.YES_NO_OPTION) ==
+ javax.swing.JOptionPane.YES_OPTION;
+ }
/**
- * Creates a new EventHandlerThread.
+ * Displays an input dialog box.
*/
- public EventHandlerThread(String script, Event evt, String lang) {
- super(lang);
- this.script = script;
- event = evt;
+ public String prompt(String message) {
+ return javax.swing.JOptionPane.showInputDialog
+ ("Script prompt:\n" + message);
}
/**
- * Returns the script to execute.
+ * Displays an input dialog box, given the default value.
*/
- protected String getScript() {
- interpreter.bindObject(EVENT_NAME, event);
- return script;
+ public String prompt(String message, String defVal) {
+ return (String)javax.swing.JOptionPane.showInputDialog
+ (null,
+ "Script prompt:\n" + message,
+ "Prompt",
+ javax.swing.JOptionPane.PLAIN_MESSAGE,
+ null, null, defVal);
}
- }
- protected static class StopScriptException
- extends RuntimeException {
- public StopScriptException() {
+ /**
+ * Returns the associated interpreter.
+ */
+ public Interpreter getInterpreter() {
+ return interpreter;
}
}
}
1.12 +18 -30 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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- UpdateManager.java 22 Feb 2002 11:30:54 -0000 1.11
+++ UpdateManager.java 25 Feb 2002 15:05:31 -0000 1.12
@@ -44,7 +44,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.11 2002/02/22 11:30:54 hillion Exp $
+ * @version $Id: UpdateManager.java,v 1.12 2002/02/25 15:05:31 hillion Exp $
*/
public class UpdateManager implements RunnableQueue.RunHandler {
@@ -164,30 +164,19 @@
/**
* Dispatches an 'SVGLoad' event to the document.
- * NOTES:
- * - This method starts the update manager threads so one can't use
- * the update runnable queue to invoke this method.
- * - The scripting lock is taken. Is is released by a call to
- * manageUpdates().
*/
public synchronized void dispatchSVGLoadEvent()
throws InterruptedException {
- // Locking avoid execution of scripts scheduled by calls
- // to the setTimeout() function.
- // The lock is be released by a call to manageUpdates().
- scriptingEnvironment.getScriptingLock().lock();
-
scriptingEnvironment.loadScripts();
scriptingEnvironment.dispatchSVGLoadEvent();
-
- updateRunnableQueue.resumeExecution();
+
}
/**
* Finishes the UpdateManager initialization.
*/
public void manageUpdates(final ImageRenderer r) {
- updateRunnableQueue.invokeLater(new Runnable() {
+ updateRunnableQueue.preemptLater(new Runnable() {
public void run() {
synchronized (UpdateManager.this) {
startingTime = System.currentTimeMillis();
@@ -207,14 +196,13 @@
repaintRateManager =
new RepaintRateManager(UpdateManager.this);
repaintRateManager.start();
-
- scriptingEnvironment.getScriptingLock().unlock();
-
+
fireManagerStartedEvent();
started = true;
}
}
});
+ updateRunnableQueue.resumeExecution();
}
@@ -263,7 +251,7 @@
/**
* Tells whether the update manager is currently running.
*/
- public boolean isRunning() {
+ public synchronized boolean isRunning() {
return running;
}
@@ -305,18 +293,20 @@
if (started) {
dispatchSVGUnLoadEvent();
} else {
- resume();
- updateRunnableQueue.invokeLater(new Runnable() {
+ // Invoke first to cancel the pending tasks
+ updateRunnableQueue.preemptLater(new Runnable() {
public void run() {
synchronized (UpdateManager.this) {
+ running = false;
if (repaintManager != null) {
repaintRateManager.interrupt();
}
- scriptingEnvironment.interruptScripts();
+ scriptingEnvironment.interrupt();
updateRunnableQueue.getThread().interrupt();
}
}
});
+ resume();
}
}
}
@@ -331,8 +321,8 @@
throw new IllegalStateException("UpdateManager not started.");
}
- resume();
- updateRunnableQueue.invokeLater(new Runnable() {
+ // Invoke first to cancel the pending tasks
+ updateRunnableQueue.preemptLater(new Runnable() {
public void run() {
synchronized (UpdateManager.this) {
Event evt =
@@ -343,12 +333,13 @@
running = false;
repaintRateManager.interrupt();
- scriptingEnvironment.interruptScripts();
+ scriptingEnvironment.interrupt();
updateRunnableQueue.getThread().interrupt();
fireManagerStoppedEvent();
}
}
});
+ resume();
}
/**
@@ -518,6 +509,9 @@
* has returned.
*/
public void runnableInvoked(RunnableQueue rq, Runnable r) {
+ if (running && !(r instanceof NoRepaintRunnable)) {
+ repaintManager.repaint();
+ }
}
/**
@@ -527,9 +521,6 @@
if (suspendCalled) {
running = false;
suspendStartTime = System.currentTimeMillis();
- if (scriptingEnvironment != null) {
- scriptingEnvironment.suspendScripts();
- }
fireManagerSuspendedEvent();
}
}
@@ -544,9 +535,6 @@
suspendCalled = false;
suspendedTime = System.currentTimeMillis() - suspendStartTime;
fireManagerResumedEvent();
- if (scriptingEnvironment != null) {
- scriptingEnvironment.resumeScripts();
- }
}
}
}
1.1 xml-batik/sources/org/apache/batik/bridge/NoRepaintRunnable.java
Index: NoRepaintRunnable.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;
/**
* A tagging interface to prevent a repaint at the end of the
* execution of this runnable.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
* @version $Id: NoRepaintRunnable.java,v 1.1 2002/02/25 15:05:31 hillion Exp $
*/
public interface NoRepaintRunnable extends Runnable {
}
1.12 +18 -7 xml-batik/sources/org/apache/batik/dom/AbstractDocument.java
Index: AbstractDocument.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/AbstractDocument.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- AbstractDocument.java 19 Nov 2001 13:39:55 -0000 1.11
+++ AbstractDocument.java 25 Feb 2002 15:05:32 -0000 1.12
@@ -19,7 +19,9 @@
import java.util.WeakHashMap;
import org.apache.batik.dom.events.DocumentEventSupport;
+
import org.apache.batik.dom.traversal.TraversalSupport;
+
import org.apache.batik.i18n.Localizable;
import org.apache.batik.i18n.LocalizableSupport;
@@ -34,8 +36,11 @@
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+
import org.w3c.dom.events.DocumentEvent;
import org.w3c.dom.events.Event;
+import org.w3c.dom.events.EventListener;
+
import org.w3c.dom.traversal.DocumentTraversal;
import org.w3c.dom.traversal.NodeFilter;
import org.w3c.dom.traversal.NodeIterator;
@@ -45,7 +50,7 @@
* This class implements the {@link org.w3c.dom.Document} interface.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: AbstractDocument.java,v 1.11 2001/11/19 13:39:55 hillion Exp $
+ * @version $Id: AbstractDocument.java,v 1.12 2002/02/25 15:05:32 hillion Exp $
*/
public abstract class AbstractDocument
extends AbstractParentNode
@@ -250,8 +255,9 @@
break;
case PROCESSING_INSTRUCTION_NODE:
- result = createProcessingInstruction(importedNode.getNodeName(),
- importedNode.getNodeValue());
+ result = createProcessingInstruction
+ (importedNode.getNodeName(),
+ importedNode.getNodeValue());
deep = false;
break;
@@ -297,7 +303,9 @@
/**
* Returns an ElementsByTagName object from the cache, if any.
*/
- public ElementsByTagName getElementsByTagName(Node n, String ns, String ln) {
+ public ElementsByTagName getElementsByTagName(Node n,
+ String ns,
+ String ln) {
if (elementsByTagNames == null) {
return null;
}
@@ -334,7 +342,8 @@
public Event createEvent(String eventType) throws DOMException {
if (documentEventSupport == null) {
documentEventSupport =
-
((AbstractDOMImplementation)implementation).createDocumentEventSupport();
+ ((AbstractDOMImplementation)implementation).
+ createDocumentEventSupport();
}
return documentEventSupport.createEvent(eventType);
}
@@ -353,7 +362,8 @@
if (traversalSupport == null) {
traversalSupport = new TraversalSupport();
}
- return traversalSupport.createNodeIterator(this, root, whatToShow, filter,
+ return traversalSupport.createNodeIterator(this, root, whatToShow,
+ filter,
entityReferenceExpansion);
}
@@ -366,7 +376,8 @@
NodeFilter filter,
boolean entityReferenceExpansion)
throws DOMException {
- return TraversalSupport.createTreeWalker(this, root, whatToShow, filter,
+ return TraversalSupport.createTreeWalker(this, root, whatToShow,
+ filter,
entityReferenceExpansion);
}
1.9 +6 -3 xml-batik/sources/org/apache/batik/dom/AbstractNode.java
Index: AbstractNode.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/AbstractNode.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- AbstractNode.java 19 Nov 2001 13:39:56 -0000 1.8
+++ AbstractNode.java 25 Feb 2002 15:05:32 -0000 1.9
@@ -35,7 +35,7 @@
* This class implements the {@link org.w3c.dom.Node} interface.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: AbstractNode.java,v 1.8 2001/11/19 13:39:56 hillion Exp $
+ * @version $Id: AbstractNode.java,v 1.9 2002/02/25 15:05:32 hillion Exp $
*/
public abstract class AbstractNode
implements ExtendedNode,
@@ -287,7 +287,8 @@
* org.w3c.dom.Node#isSupported(String,String)}.
*/
public boolean isSupported(String feature, String version) {
- return getCurrentDocument().getImplementation().hasFeature(feature,
version);
+ return getCurrentDocument().getImplementation().hasFeature(feature,
+ version);
}
/**
@@ -381,9 +382,10 @@
public void addEventListener(String type,
EventListener listener,
boolean useCapture) {
+ AbstractDocument doc = getCurrentDocument();
if (eventSupport == null) {
eventSupport = new EventSupport();
- getCurrentDocument().setEventsEnabled(true);
+ doc.setEventsEnabled(true);
}
eventSupport.addEventListener(type, listener, useCapture);
}
@@ -397,6 +399,7 @@
EventListener listener,
boolean useCapture) {
if (eventSupport != null) {
+ AbstractDocument doc = getCurrentDocument();
eventSupport.removeEventListener(type, listener, useCapture);
}
}
1.7 +1 -2
xml-batik/sources/org/apache/batik/dom/svg/DefaultSVGContext.java
Index: DefaultSVGContext.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/dom/svg/DefaultSVGContext.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DefaultSVGContext.java 12 Sep 2001 16:57:07 -0000 1.6
+++ DefaultSVGContext.java 25 Feb 2002 15:05:32 -0000 1.7
@@ -10,12 +10,11 @@
import org.apache.batik.css.svg.DefaultSVGCSSContext;
-
/**
* This class is the placeholder for SVG application informations.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: DefaultSVGContext.java,v 1.6 2001/09/12 16:57:07 hillion Exp $
+ * @version $Id: DefaultSVGContext.java,v 1.7 2002/02/25 15:05:32 hillion Exp $
*/
public class DefaultSVGContext
extends DefaultSVGCSSContext
1.4 +1 -2 xml-batik/sources/org/apache/batik/dom/svg/SVGContext.java
Index: SVGContext.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/svg/SVGContext.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SVGContext.java 1 Feb 2001 13:45:49 -0000 1.3
+++ SVGContext.java 25 Feb 2002 15:05:32 -0000 1.4
@@ -14,7 +14,7 @@
* This interface is the placeholder for SVG application informations.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: SVGContext.java,v 1.3 2001/02/01 13:45:49 tkormann Exp $
+ * @version $Id: SVGContext.java,v 1.4 2002/02/25 15:05:32 hillion Exp $
*/
public interface SVGContext extends SVGCSSContext {
@@ -22,5 +22,4 @@
* Return the pixel to millimeters factor.
*/
float getPixelToMM();
-
}
1.43 +6 -1 xml-batik/sources/org/apache/batik/dom/svg/SVGOMDocument.java
Index: SVGOMDocument.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/svg/SVGOMDocument.java,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- SVGOMDocument.java 18 Oct 2001 17:29:06 -0000 1.42
+++ SVGOMDocument.java 25 Feb 2002 15:05:32 -0000 1.43
@@ -54,12 +54,17 @@
import org.w3c.dom.css.CSSStyleDeclaration;
import org.w3c.dom.css.DocumentCSS;
+
+import org.w3c.dom.events.EventListener;
+
import org.w3c.dom.stylesheets.LinkStyle;
import org.w3c.dom.stylesheets.StyleSheet;
import org.w3c.dom.stylesheets.StyleSheetList;
+
import org.w3c.dom.svg.SVGDocument;
import org.w3c.dom.svg.SVGLangSpace;
import org.w3c.dom.svg.SVGSVGElement;
+
import org.w3c.dom.views.AbstractView;
import org.w3c.dom.views.DocumentView;
@@ -67,7 +72,7 @@
* This class implements {@link SVGDocument}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: SVGOMDocument.java,v 1.42 2001/10/18 17:29:06 hillion Exp $
+ * @version $Id: SVGOMDocument.java,v 1.43 2002/02/25 15:05:32 hillion Exp $
*/
public class SVGOMDocument
extends AbstractDocument
1.1 xml-batik/sources/org/apache/batik/script/Window.java
Index: Window.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.script;
/**
* This interface represents the 'window' object defined in the global
* environment of a SVG document.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
* @version $Id: Window.java,v 1.1 2002/02/25 15:05:32 hillion Exp $
*/
public interface Window {
/**
* Evaluates the given string repeatedly after the given amount of
* time. This method does not stall the script: the evaluation is
* scheduled and the script continues its execution.
* @return an object representing the interval created.
*/
Object setInterval(String script, long interval);
/**
* Calls the 'run' method of the given Runnable repeatedly after
* the given amount of time. This method does not stall the
* script: the evaluation is scheduled and the script continues
* its execution.
* @return an object representing the interval created.
*/
Object setInterval(Runnable r, long interval);
/**
* Cancels an interval that was set by a call to 'setInterval'.
*/
void clearInterval(Object interval);
/**
* Evaluates the given string after the given amount of time.
* This method does not stall the script: the evaluation is
* scheduled and the script continues its execution.
* @return an object representing the timeout created.
*/
Object setTimeout(String script, long timeout);
/**
* Calls the 'run' method of the given Runnable after the given
* amount of time. This method does not stall the script: the
* evaluation is scheduled and the script continues its execution.
* @return an object representing the timeout created.
*/
Object setTimeout(Runnable r, long timeout);
/**
* Cancels an timeout that was set by a call to 'setTimeout'.
*/
void clearTimeout(Object timeout);
/**
* Displays an alert dialog box.
*/
void alert(String message);
/**
* Displays a confirm dialog box.
*/
boolean confirm(String message);
/**
* Displays an input dialog box.
* @return The input of the user, or null if the dialog was cancelled.
*/
String prompt(String message);
/**
* Displays an input dialog box, given the default value.
* @return The input of the user, or null if the dialog was cancelled.
*/
String prompt(String message, String defVal);
/**
* Returns the associated interpreter.
*/
Interpreter getInterpreter();
}
1.4 +3 -1
xml-batik/sources/org/apache/batik/script/rhino/EventTargetWrapHandler.java
Index: EventTargetWrapHandler.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/script/rhino/EventTargetWrapHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- EventTargetWrapHandler.java 24 Jan 2001 14:51:02 -0000 1.3
+++ EventTargetWrapHandler.java 25 Feb 2002 15:05:33 -0000 1.4
@@ -13,13 +13,15 @@
import org.w3c.dom.events.EventTarget;
+import org.apache.batik.script.Window;
+
/**
* This is an utility class allowing to pass an ECMAScript function
* as a parameter of the <code>addEventListener</code> method of
* <code>EventTarget</code> objects as DOM Level 2 recommendation
* required.
* @author <a href="mailto:[EMAIL PROTECTED]">Christophe Jolif</a>
- * @version $Id: EventTargetWrapHandler.java,v 1.3 2001/01/24 14:51:02 cjolif Exp $
+ * @version $Id: EventTargetWrapHandler.java,v 1.4 2002/02/25 15:05:33 hillion Exp $
*/
class EventTargetWrapHandler implements WrapHandler {
private RhinoInterpreter interpreter;
1.13 +35 -9
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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- RhinoInterpreter.java 22 Feb 2002 16:52:09 -0000 1.12
+++ RhinoInterpreter.java 25 Feb 2002 15:05:33 -0000 1.13
@@ -20,7 +20,7 @@
import org.apache.batik.script.Interpreter;
import org.apache.batik.script.InterpreterException;
-import org.apache.batik.script.JavaFunction;
+import org.apache.batik.script.Window;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
@@ -37,7 +37,7 @@
* 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.12 2002/02/22 16:52:09 tkormann Exp $
+ * @version $Id: RhinoInterpreter.java,v 1.13 2002/02/25 15:05:33 hillion Exp $
*/
public class RhinoInterpreter implements Interpreter {
private static String[] TO_BE_IMPORTED = {
@@ -91,7 +91,7 @@
p[i] = new NativeJavaPackage(TO_BE_IMPORTED[i]);
}
importer.importPackage(ctx, globalObject, p, null);
- ctx.setWrapHandler(wrapHandler = new EventTargetWrapHandler(this));
+ ctx.setWrapHandler(wrapHandler);
} finally {
Context.exit();
}
@@ -239,17 +239,28 @@
Context ctx = Context.enter();
ctx.setWrapHandler(wrapHandler);
try {
- if (object instanceof JavaFunction) {
- JavaFunction jf = (JavaFunction)object;
- globalObject.put(name, globalObject,
- new RhinoFunction(jf, globalObject));
- return;
- }
Scriptable jsObject = Context.toObject(object, globalObject);
globalObject.put(name, globalObject, jsObject);
} finally {
Context.exit();
}
+
+ if (name.equals("window") && object instanceof Window) {
+ try {
+ // Defines the 'Window' class.
+ ScriptableObject.defineClass(globalObject,
+ WindowWrapper.class);
+
+ // Wrap the given window object.
+ evaluate(new StringReader("window = new Window(window)"));
+
+ // The window becomes the global object.
+ globalObject =
+ (ScriptableObject)globalObject.get("window", globalObject);
+ } catch (Exception e) {
+ // Cannot happen.
+ }
+ }
}
/**
@@ -263,6 +274,21 @@
try {
arg = Context.toObject(arg, globalObject);
Object[] args = {arg};
+ handler.call(ctx, globalObject, globalObject, args);
+ } finally {
+ Context.exit();
+ }
+ }
+
+ /**
+ * To be used by <code>WindowWrapper</code>.
+ */
+ void callHandler(Function handler,
+ Object[] args)
+ throws JavaScriptException {
+ Context ctx = Context.enter();
+ ctx.setWrapHandler(wrapHandler);
+ try {
handler.call(ctx, globalObject, globalObject, args);
} finally {
Context.exit();
1.1
xml-batik/sources/org/apache/batik/script/rhino/WindowWrapper.java
Index: WindowWrapper.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.script.rhino;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.FunctionObject;
import org.mozilla.javascript.JavaScriptException;
import org.mozilla.javascript.NativeJavaObject;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.Undefined;
import org.mozilla.javascript.WrappedException;
import org.mozilla.javascript.Wrapper;
import org.apache.batik.script.Interpreter;
import org.apache.batik.script.InterpreterException;
import org.apache.batik.script.Window;
/**
* This class wraps a Window object to expose it to the interpreter.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
* @version $Id: WindowWrapper.java,v 1.1 2002/02/25 15:05:33 hillion Exp $
*/
public class WindowWrapper extends ScriptableObject {
/**
* The rhino interpreter.
*/
protected RhinoInterpreter interpreter;
/**
* The wrapped window.
*/
protected Window window;
/**
* Creates a new WindowWrapper.
*/
public WindowWrapper() {
}
/**
* The ecmascript constructor for the Window class.
*/
public static Object jsConstructor(Context cx, Object[] args,
Function ctorObj, boolean inNewExpr) {
WindowWrapper result = new WindowWrapper();
result.window = (Window)((Wrapper)args[0]).unwrap();
return result;
}
public String getClassName() {
return "Window";
}
public String toString() {
return "[object Window]";
}
/**
* Wraps the 'setInterval' methods of the Window interface.
*/
public static Object jsFunction_setInterval(Context cx,
Scriptable thisObj,
Object[] args,
Function funObj)
throws JavaScriptException {
int len = args.length;
WindowWrapper ww = (WindowWrapper)thisObj;
Window window = ww.window;
if (len < 2) {
throw Context.reportRuntimeError("invalid argument count");
}
long to = ((Long)NativeJavaObject.coerceType
(Long.TYPE, args[1])).longValue();
if (args[0] instanceof Function) {
Object[] fargs = new Object[len - 2];
for (int i = 2, j = 0; i < len; i++, j++) {
fargs[j] = args[i];
}
RhinoInterpreter interp =
(RhinoInterpreter)window.getInterpreter();
FunctionWrapper fw;
fw = new FunctionWrapper(interp, (Function)args[0], fargs);
return window.setInterval(fw, to);
}
String script =
(String)NativeJavaObject.coerceType(String.class, args[0]);
return window.setInterval(script, to);
}
/**
* Wraps the 'setTimeout' methods of the Window interface.
*/
public static Object jsFunction_setTimeout(Context cx,
Scriptable thisObj,
Object[] args,
Function funObj)
throws JavaScriptException {
int len = args.length;
WindowWrapper ww = (WindowWrapper)thisObj;
Window window = ww.window;
if (len < 2) {
throw Context.reportRuntimeError("invalid argument count");
}
long to = ((Long)NativeJavaObject.coerceType
(Long.TYPE, args[1])).longValue();
if (args[0] instanceof Function) {
Object[] fargs = new Object[len - 2];
for (int i = 2, j = 0; i < len; i++, j++) {
fargs[j] = args[i];
}
RhinoInterpreter interp =
(RhinoInterpreter)window.getInterpreter();
FunctionWrapper fw;
fw = new FunctionWrapper(interp, (Function)args[0], fargs);
return window.setTimeout(fw, to);
}
String script =
(String)NativeJavaObject.coerceType(String.class, args[0]);
return window.setTimeout(script, to);
}
/**
* Wraps the 'clearInterval' method of the Window interface.
*/
public static void jsFunction_clearInterval(Context cx,
Scriptable thisObj,
Object[] args,
Function funObj)
throws JavaScriptException {
int len = args.length;
WindowWrapper ww = (WindowWrapper)thisObj;
Window window = ww.window;
if (len >= 1) {
window.clearInterval(NativeJavaObject.coerceType
(Object.class, args[0]));
}
}
/**
* Wraps the 'clearTimeout' method of the Window interface.
*/
public static void jsFunction_clearTimeout(Context cx,
Scriptable thisObj,
Object[] args,
Function funObj)
throws JavaScriptException {
int len = args.length;
WindowWrapper ww = (WindowWrapper)thisObj;
Window window = ww.window;
if (len >= 1) {
window.clearTimeout(NativeJavaObject.coerceType
(Object.class, args[0]));
}
}
/**
* Wraps the 'alert' method of the Window interface.
*/
public static void jsFunction_alert(Context cx,
Scriptable thisObj,
Object[] args,
Function funObj)
throws JavaScriptException {
int len = args.length;
WindowWrapper ww = (WindowWrapper)thisObj;
Window window = ww.window;
if (len >= 1) {
String message =
(String)NativeJavaObject.coerceType(String.class, args[0]);
window.alert(message);
}
}
/**
* Wraps the 'confirm' method of the Window interface.
*/
public static boolean jsFunction_confirm(Context cx,
Scriptable thisObj,
Object[] args,
Function funObj)
throws JavaScriptException {
int len = args.length;
WindowWrapper ww = (WindowWrapper)thisObj;
Window window = ww.window;
if (len >= 1) {
String message =
(String)NativeJavaObject.coerceType(String.class, args[0]);
return window.confirm(message);
}
return false;
}
/**
* Wraps the 'prompt' method of the Window interface.
*/
public static String jsFunction_prompt(Context cx,
Scriptable thisObj,
Object[] args,
Function funObj)
throws JavaScriptException {
int len = args.length;
WindowWrapper ww = (WindowWrapper)thisObj;
Window window = ww.window;
switch (len) {
case 0:
return "";
case 1:
String message =
(String)NativeJavaObject.coerceType(String.class, args[0]);
String result = window.prompt(message);
return (result == null) ? "" : result;
default:
message =
(String)NativeJavaObject.coerceType(String.class, args[0]);
String defVal =
(String)NativeJavaObject.coerceType(String.class, args[1]);
result = window.prompt(message, defVal);
return (result == null) ? "" : result;
}
}
/**
* To wrap a function in an handler.
*/
protected static class FunctionWrapper implements Runnable {
/**
* The current interpreter.
*/
protected RhinoInterpreter interpreter;
/**
* The function wrapper.
*/
protected Function function;
/**
* The arguments.
*/
protected Object[] arguments;
/**
* Creates a function wrapper.
*/
public FunctionWrapper(RhinoInterpreter ri,
Function f,
Object[] args) {
interpreter = ri;
function = f;
arguments = args;
}
/**
* Calls the function.
*/
public void run() {
try {
interpreter.callHandler(function, arguments);
} catch (JavaScriptException e) {
throw new WrappedException(e);
}
}
}
}
1.44 +4 -1 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.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- JSVGComponent.java 22 Feb 2002 11:30:54 -0000 1.43
+++ JSVGComponent.java 25 Feb 2002 15:05:33 -0000 1.44
@@ -180,7 +180,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.43 2002/02/22 11:30:54 hillion Exp $
+ * @version $Id: JSVGComponent.java,v 1.44 2002/02/25 15:05:33 hillion Exp $
*/
public class JSVGComponent extends JGVTComponent {
@@ -347,6 +347,9 @@
* Returns the current update manager.
*/
public UpdateManager getUpdateManager() {
+ if (svgLoadEventDispatcher != null) {
+ return svgLoadEventDispatcher.getUpdateManager();
+ }
if (nextUpdateManager != null) {
return nextUpdateManager;
}
1.3 +5 -3
xml-batik/sources/org/apache/batik/swing/svg/SVGLoadEventDispatcher.java
Index: SVGLoadEventDispatcher.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/swing/svg/SVGLoadEventDispatcher.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SVGLoadEventDispatcher.java 22 Feb 2002 11:30:54 -0000 1.2
+++ SVGLoadEventDispatcher.java 25 Feb 2002 15:05:33 -0000 1.3
@@ -26,7 +26,7 @@
* This class dispatches the SVGLoadEvent event on a SVG document.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: SVGLoadEventDispatcher.java,v 1.2 2002/02/22 11:30:54 hillion Exp $
+ * @version $Id: SVGLoadEventDispatcher.java,v 1.3 2002/02/25 15:05:33 hillion Exp $
*/
public class SVGLoadEventDispatcher extends Thread {
@@ -108,12 +108,14 @@
/**
* Adds a SVGLoadEventDispatcherListener to this SVGLoadEventDispatcher.
*/
- public void addSVGLoadEventDispatcherListener(SVGLoadEventDispatcherListener l)
{
+ public void addSVGLoadEventDispatcherListener
+ (SVGLoadEventDispatcherListener l) {
listeners.add(l);
}
/**
- * Removes a SVGLoadEventDispatcherListener from this SVGLoadEventDispatcher.
+ * Removes a SVGLoadEventDispatcherListener from this
+ * SVGLoadEventDispatcher.
*/
public void removeSVGLoadEventDispatcherListener
(SVGLoadEventDispatcherListener l) {
1.10 +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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- RunnableQueue.java 18 Feb 2002 09:11:59 -0000 1.9
+++ RunnableQueue.java 25 Feb 2002 15:05:33 -0000 1.10
@@ -17,7 +17,7 @@
* invocation in a single thread.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: RunnableQueue.java,v 1.9 2002/02/18 09:11:59 hillion Exp $
+ * @version $Id: RunnableQueue.java,v 1.10 2002/02/25 15:05:33 hillion Exp $
*/
public class RunnableQueue implements Runnable {
@@ -89,7 +89,7 @@
public static RunnableQueue createRunnableQueue() {
RunnableQueue result = new RunnableQueue();
synchronized (result) {
- Thread t = new Thread(result);
+ Thread t = new Thread(result, "RunnableQueue-" + threadCount++);
t.setDaemon(true);
t.start();
while (result.getThread() == null) {
@@ -101,6 +101,7 @@
}
return result;
}
+ private static int threadCount;
/**
* Runs this queue.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]