diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/visualization/batikutil/JSVGSynchronizedCanvas.java')
-rw-r--r-- | src/de/lmu/ifi/dbs/elki/visualization/batikutil/JSVGSynchronizedCanvas.java | 83 |
1 files changed, 35 insertions, 48 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/visualization/batikutil/JSVGSynchronizedCanvas.java b/src/de/lmu/ifi/dbs/elki/visualization/batikutil/JSVGSynchronizedCanvas.java index 2e08a2dc..08f8f426 100644 --- a/src/de/lmu/ifi/dbs/elki/visualization/batikutil/JSVGSynchronizedCanvas.java +++ b/src/de/lmu/ifi/dbs/elki/visualization/batikutil/JSVGSynchronizedCanvas.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.visualization.batikutil; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -26,7 +26,6 @@ package de.lmu.ifi.dbs.elki.visualization.batikutil; import org.apache.batik.bridge.UpdateManager; import org.apache.batik.swing.JSVGCanvas; import org.w3c.dom.Document; -import org.w3c.dom.svg.SVGDocument; import de.lmu.ifi.dbs.elki.logging.LoggingUtil; import de.lmu.ifi.dbs.elki.visualization.svg.SVGPlot; @@ -66,16 +65,12 @@ public class JSVGSynchronizedCanvas extends JSVGCanvas { } /** - * Use {@link #setPlot} instead if you need synchronization! + * Get the currently displayed SVG plot. * - * @deprecated Document cannot be synchronized - use {@link #setPlot} and a - * {@link SVGPlot} object! + * @return current SVG plot. May be {@code null}! */ - @Override - @Deprecated - public synchronized void setDocument(Document doc) { - // Note: this will call this.setSVGDocument! - super.setDocument(doc); + public SVGPlot getPlot() { + return this.plot; } /** @@ -86,9 +81,9 @@ public class JSVGSynchronizedCanvas extends JSVGCanvas { */ @Override @Deprecated - public synchronized void setSVGDocument(SVGDocument doc) { - setPlot(null); - super.setSVGDocument(doc); + public synchronized void setDocument(Document doc) { + // Note: this will call this.setSVGDocument! + super.setDocument(doc); } /** @@ -98,18 +93,19 @@ public class JSVGSynchronizedCanvas extends JSVGCanvas { */ public void setPlot(final SVGPlot newplot) { final SVGPlot oldplot = this.plot; - this.plot = newplot; - if(newplot != null) { - newplot.synchronizeWith(this.synchronizer); - super.setSVGDocument(newplot.getDocument()); - super.setDisableInteractions(newplot.getDisableInteractions()); - } - else { + if(newplot == null) { super.setSVGDocument(null); + if(oldplot != null) { + scheduleDetach(oldplot); + } + return; } + newplot.synchronizeWith(this.synchronizer); + super.setSVGDocument(newplot.getDocument()); + super.setDisableInteractions(newplot.getDisableInteractions()); // We only know we're detached when the synchronizer has run again. - if(oldplot != null) { + if(oldplot != null && oldplot != newplot) { scheduleDetach(oldplot); } } @@ -121,44 +117,35 @@ public class JSVGSynchronizedCanvas extends JSVGCanvas { */ private void scheduleDetach(final SVGPlot oldplot) { UpdateManager um = this.getUpdateManager(); - if(um != null) { - synchronized(um) { - if(um.isRunning()) { - //LoggingUtil.warning("Scheduling detach: " + this + " " + oldplot); - um.getUpdateRunnableQueue().preemptLater(new Runnable() { - @Override - public void run() { - detachPlot(oldplot); - } - }); - return; - } + if(um == null) { + return; + } + synchronized(um) { + if(um.isRunning()) { + // LoggingUtil.warning("Scheduling detach: " + this + " " + oldplot); + um.getUpdateRunnableQueue().preemptLater(new Runnable() { + @Override + public void run() { + detachPlot(oldplot); + } + }); + return; } } detachPlot(oldplot); } /** - * Get the currently displayed SVG plot. - * - * @return current SVG plot. May be {@code null}! - */ - public SVGPlot getPlot() { - return this.plot; - } - - /** * Execute the detaching event. * * @param oldplot Plot to detach from. */ protected void detachPlot(SVGPlot oldplot) { - //LoggingUtil.warning("Detaching: " + this + " " + oldplot); - if(oldplot != plot) { - oldplot.unsynchronizeWith(JSVGSynchronizedCanvas.this.synchronizer); - } - else { - LoggingUtil.warning("Detaching from a plot I'm already attached to again?!?"); + // LoggingUtil.warning("Detaching: " + this + " " + oldplot); + if(oldplot == plot) { + LoggingUtil.warning("Detaching from a plot I'm already attached to again?!?", new Throwable()); + return; } + oldplot.unsynchronizeWith(JSVGSynchronizedCanvas.this.synchronizer); } }
\ No newline at end of file |