You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by de...@apache.org on 2006/06/11 14:35:29 UTC
svn commit: r413438 - in /xmlgraphics/batik/trunk:
samples/tests/spec/scripting/ sources/org/apache/batik/bridge/
sources/org/apache/batik/dom/svg/ test-resources/org/apache/batik/test/
Author: deweese
Date: Sun Jun 11 05:35:28 2006
New Revision: 413438
URL: http://svn.apache.org/viewvc?rev=413438&view=rev
Log:
C:\Apps\cygwin\home\l449433\dev\batik\svg12-batik\svn-commit.2.tmp
Added:
xmlgraphics/batik/trunk/samples/tests/spec/scripting/forceRedraw.svg
- copied unchanged from r413436, xmlgraphics/batik/branches/svg11/samples/tests/spec/scripting/forceRedraw.svg
xmlgraphics/batik/trunk/samples/tests/spec/scripting/suspendRedraw.svg
- copied unchanged from r413436, xmlgraphics/batik/branches/svg11/samples/tests/spec/scripting/suspendRedraw.svg
Modified:
xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/SVGSVGElementBridge.java
xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/UpdateManager.java
xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMSVGElement.java
xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGSVGContext.java
xmlgraphics/batik/trunk/test-resources/org/apache/batik/test/interactiveSamples.xml
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/SVGSVGElementBridge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/SVGSVGElementBridge.java?rev=413438&r1=413437&r2=413438&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/SVGSVGElementBridge.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/SVGSVGElementBridge.java Sun Jun 11 05:35:28 2006
@@ -851,4 +851,29 @@
public void deselectAll() {
ctx.getUserAgent().deselectAll();
}
+
+ public int suspendRedraw ( int max_wait_milliseconds ) {
+ UpdateManager um = ctx.getUpdateManager();
+ if (um != null)
+ return um.addRedrawSuspension(max_wait_milliseconds);
+ return -1;
+ }
+ public boolean unsuspendRedraw ( int suspend_handle_id ) {
+ UpdateManager um = ctx.getUpdateManager();
+ if (um != null)
+ return um.releaseRedrawSuspension(suspend_handle_id);
+ return false; // no UM so couldn't have issued an id...
+ }
+ public void unsuspendRedrawAll ( ) {
+ UpdateManager um = ctx.getUpdateManager();
+ if (um != null)
+ um.releaseAllRedrawSuspension();
+ }
+
+ public void forceRedraw ( ) {
+ UpdateManager um = ctx.getUpdateManager();
+ if (um != null)
+ um.forceRepaint();
+ }
+
}
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/UpdateManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/UpdateManager.java?rev=413438&r1=413437&r2=413438&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/UpdateManager.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/UpdateManager.java Sun Jun 11 05:35:28 2006
@@ -25,6 +25,8 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
import org.apache.batik.bridge.svg12.DefaultXBLManager;
import org.apache.batik.bridge.svg12.SVG12BridgeContext;
@@ -529,9 +531,22 @@
* Repaints the dirty areas, if needed.
*/
protected void repaint() {
- if (!updateTracker.hasChanged())
+ if (!updateTracker.hasChanged()) {
+ // No changes, nothing to repaint.
+ outOfDateTime = 0;
return;
+ }
+
long ctime = System.currentTimeMillis();
+ if (ctime < allResumeTime) {
+ createRepaintTimer();
+ return;
+ }
+ if (allResumeTime > 0) {
+ // All suspendRedraw requests have expired.
+ releaseAllRedrawSuspension();
+ }
+
if (ctime-outOfDateTime < minRepaintTime) {
// We very recently did a repaint check if other
// repaint runnables are pending.
@@ -555,6 +570,169 @@
outOfDateTime = 0;
}
+ /**
+ * Users of Batik should essentially never call
+ * this directly from Java. If the Canvas is not
+ * updating when you change the SVG Document it is almost
+ * certainly because you are not making your changes
+ * in the RunnableQueue (getUpdateRunnableQueue()).
+ * You will have problems if you are not making all
+ * changes to the document in the UpdateManager's
+ * RunnableQueue.
+ *
+ * This method exists to implement the
+ * 'SVGSVGElement.forceRedraw()' method.
+ */
+ public void forceRepaint() {
+ if (!updateTracker.hasChanged()) {
+ // No changes, nothing to repaint.
+ outOfDateTime = 0;
+ return;
+ }
+
+ List dirtyAreas = updateTracker.getDirtyAreas();
+ updateTracker.clear();
+ if (dirtyAreas != null) {
+ updateRendering(dirtyAreas, false);
+ }
+ outOfDateTime = 0;
+ }
+
+ protected class SuspensionInfo {
+ /**
+ * The index of this redraw suspension
+ */
+ int index;
+ /**
+ * The system time in millisec that this suspension
+ * will expire and redraws can resume (at least for
+ * this suspension.
+ */
+ long resumeMilli;
+ public SuspensionInfo(int index, long resumeMilli) {
+ this.index = index;
+ this.resumeMilli = resumeMilli;
+ }
+ public int getIndex() { return index; }
+ public long getResumeMilli() { return resumeMilli; }
+ }
+
+ protected class RepaintTimerTask extends TimerTask {
+ UpdateManager um;
+ RepaintTimerTask(UpdateManager um) {
+ this.um = um;
+ }
+ public void run() {
+ RunnableQueue rq = um.getUpdateRunnableQueue();
+ if (rq == null) return;
+ rq.invokeLater(new Runnable() {
+ public void run() { }
+ });
+ }
+ }
+
+ List suspensionList = new ArrayList();
+ int nextSuspensionIndex = 1;
+ long allResumeTime = -1;
+ Timer repaintTriggerTimer = null;
+ TimerTask repaintTimerTask = null;
+
+ void createRepaintTimer() {
+ if (repaintTimerTask != null) return;
+ if (allResumeTime < 0) return;
+ if (repaintTriggerTimer == null)
+ repaintTriggerTimer = new Timer(true);
+
+ long delay = allResumeTime - System.currentTimeMillis();
+ if (delay < 0) delay = 0;
+ repaintTimerTask = new RepaintTimerTask(this);
+ repaintTriggerTimer.schedule(repaintTimerTask, delay);
+ // System.err.println("CTimer delay: " + delay);
+ }
+ /**
+ * Sets up a timer that will trigger a repaint
+ * when it fires.
+ * If create is true it will construct a timer even
+ * if one
+ */
+ void resetRepaintTimer() {
+ if (repaintTimerTask == null) return;
+ if (allResumeTime < 0) return;
+ if (repaintTriggerTimer == null)
+ repaintTriggerTimer = new Timer(true);
+
+ long delay = allResumeTime - System.currentTimeMillis();
+ if (delay < 0) delay = 0;
+ repaintTimerTask = new RepaintTimerTask(this);
+ repaintTriggerTimer.schedule(repaintTimerTask, delay);
+ // System.err.println("Timer delay: " + delay);
+ }
+
+ int addRedrawSuspension(int max_wait_milliseconds) {
+ long resumeTime = System.currentTimeMillis() + max_wait_milliseconds;
+ SuspensionInfo si = new SuspensionInfo(nextSuspensionIndex++,
+ resumeTime);
+ if (resumeTime > allResumeTime) {
+ allResumeTime = resumeTime;
+ // System.err.println("Added AllRes Time: " + allResumeTime);
+ resetRepaintTimer();
+ }
+ suspensionList.add(si);
+ return si.getIndex();
+ }
+
+ void releaseAllRedrawSuspension() {
+ suspensionList.clear();
+ allResumeTime = -1;
+ resetRepaintTimer();
+ }
+
+ boolean releaseRedrawSuspension(int index) {
+ if (index > nextSuspensionIndex) return false;
+ if (suspensionList.size() == 0) return true;
+
+ int lo = 0, hi=suspensionList.size()-1;
+ while (lo < hi) {
+ int mid = (lo+hi)>>1;
+ SuspensionInfo si = (SuspensionInfo)suspensionList.get(mid);
+ int idx = si.getIndex();
+ if (idx == index) { lo = hi = mid; }
+ else if (idx < index) { lo = mid+1; }
+ else { hi = mid-1; }
+ }
+
+ SuspensionInfo si = (SuspensionInfo)suspensionList.get(lo);
+ int idx = si.getIndex();
+ if (idx != index)
+ return true; // currently not in list but was at some point...
+
+ suspensionList.remove(lo);
+ if (suspensionList.size() == 0) {
+ // No more active suspensions
+ allResumeTime = -1;
+ resetRepaintTimer();
+ } else {
+ // Check if we need to find a new 'bounding' suspension.
+ long resumeTime = si.getResumeMilli();
+ if (resumeTime == allResumeTime) {
+ allResumeTime = findNewAllResumeTime();
+ // System.err.println("New AllRes Time: " + allResumeTime);
+ resetRepaintTimer();
+ }
+ }
+ return true;
+ }
+
+ long findNewAllResumeTime() {
+ long ret = -1;
+ Iterator i = suspensionList.iterator();
+ while (i.hasNext()) {
+ SuspensionInfo si = (SuspensionInfo)i.next();
+ long t = si.getResumeMilli();
+ if (t > ret) ret = t;
+ }
+ return ret;
+ }
/**
* Adds a UpdateManagerListener to this UpdateManager.
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMSVGElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMSVGElement.java?rev=413438&r1=413437&r2=413438&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMSVGElement.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMSVGElement.java Sun Jun 11 05:35:28 2006
@@ -286,17 +286,30 @@
}
public int suspendRedraw ( int max_wait_milliseconds ) {
- throw new UnsupportedOperationException("!!! Not implemented.");
+ if (max_wait_milliseconds > 60000)
+ max_wait_milliseconds = 60000;
+ else if (max_wait_milliseconds < 0) max_wait_milliseconds = 0;
+
+ SVGSVGContext ctx = (SVGSVGContext)getSVGContext();
+ return ctx.suspendRedraw(max_wait_milliseconds);
}
public void unsuspendRedraw ( int suspend_handle_id )
throws DOMException {
- throw new UnsupportedOperationException("!!! Not implemented.");
+ SVGSVGContext ctx = (SVGSVGContext)getSVGContext();
+ boolean ok = ctx.unsuspendRedraw(suspend_handle_id);
+ if (!ok) {
+ throw new DOMException(DOMException.NOT_FOUND_ERR,
+ "Bad suspend_handle_id: " +
+ suspend_handle_id);
+ }
}
public void unsuspendRedrawAll ( ) {
- throw new UnsupportedOperationException("!!! Not implemented.");
+ SVGSVGContext ctx = (SVGSVGContext)getSVGContext();
+ ctx.unsuspendRedrawAll();
}
public void forceRedraw ( ) {
- throw new UnsupportedOperationException("!!! Not implemented.");
+ SVGSVGContext ctx = (SVGSVGContext)getSVGContext();
+ ctx.forceRedraw();
}
public void pauseAnimations ( ) {
throw new UnsupportedOperationException("!!! Not implemented.");
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGSVGContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGSVGContext.java?rev=413438&r1=413437&r2=413438&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGSVGContext.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGSVGContext.java Sun Jun 11 05:35:28 2006
@@ -67,4 +67,10 @@
*/
public void deselectAll();
+
+ public int suspendRedraw ( int max_wait_milliseconds );
+ public boolean unsuspendRedraw ( int suspend_handle_id );
+ public void unsuspendRedrawAll ( );
+ public void forceRedraw ( );
+
};
Modified: xmlgraphics/batik/trunk/test-resources/org/apache/batik/test/interactiveSamples.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/test-resources/org/apache/batik/test/interactiveSamples.xml?rev=413438&r1=413437&r2=413438&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/test-resources/org/apache/batik/test/interactiveSamples.xml (original)
+++ xmlgraphics/batik/trunk/test-resources/org/apache/batik/test/interactiveSamples.xml Sun Jun 11 05:35:28 2006
@@ -40,12 +40,14 @@
<test id="samples/tests/spec/scripting/addDescOnClick.svg" />
<test id="samples/tests/spec/scripting/bug12933.svg" />
<test id="samples/tests/spec/scripting/filterPatternUpdate.svg" />
+ <test id="samples/tests/spec/scripting/forceRedraw.svg" />
<test id="samples/tests/spec/scripting/gradientsUpdate.svg" />
<test id="samples/tests/spec/scripting/imageUpdate.svg" />
<test id="samples/tests/spec/scripting/javaBinding.svg" />
<test id="samples/tests/spec/scripting/maskClipUpdate.svg" />
<!-- <test id="samples/tests/spec/scripting/removeLast.svg" /> -->
<test id="samples/tests/spec/scripting/security3.svg" />
+ <test id="samples/tests/spec/scripting/suspendRedraw.svg" />
<test id="samples/tests/spec/scripting/svg.svg" />
<test id="samples/tests/spec/scripting/svg2.svg" />
<test id="samples/tests/spec/scripting/textSelection.svg" />