package de.lmu.ifi.dbs.elki.visualization.batikutil;

import org.apache.batik.swing.JSVGCanvas;
import org.w3c.dom.Document;
import org.w3c.dom.svg.SVGDocument;

import de.lmu.ifi.dbs.elki.visualization.svg.SVGPlot;

/**
 * An JSVGCanvas that allows easier synchronization of Updates for SVGPlot objects.
 * 
 * @author Erich Schubert
 *
 */
public class JSVGSynchronizedCanvas extends JSVGCanvas {
  /**
   * Serial version number. 
   */
  private static final long serialVersionUID = 1L;
  
  /**
   * Synchronizer to use when synchronizing SVG plots
   */
  final private JSVGUpdateSynchronizer synchronizer;
  
  /**
   * Current SVG plot.
   */
  private SVGPlot plot = null;

  /**
   * Constructor
   */
  public JSVGSynchronizedCanvas() {
    super();
    this.synchronizer = new JSVGUpdateSynchronizer(this);
  }

  /**
   * Use {@link #setPlot} instead if you need synchronization!
   * 
   * @deprecated Document cannot be synchronized - use {@link #setPlot} and a {@link SVGPlot} object!
   */
  @Override
  @Deprecated
  public synchronized void setDocument(Document doc) {
    SVGPlot oldplot = this.plot;
    this.plot = null;
    super.setDocument(doc);
    
    if (oldplot != null) {
      oldplot.setUpdateSynchronizer(null);
    }
  }
  
  /**
   * Use {@link #setPlot} instead if you need synchronization!
   * 
   * @deprecated Document cannot be synchronized - use {@link #setPlot} and a {@link SVGPlot} object!
   */
  @Override
  @Deprecated
  public synchronized void setSVGDocument(SVGDocument doc) {
    SVGPlot oldplot = this.plot;
    this.plot = null;
    super.setSVGDocument(doc);
    
    if (oldplot != null) {
      oldplot.setUpdateSynchronizer(null);
    }
  }

  /**
   * Choose a new plot to display.
   * 
   * @param plot New plot to display. May be null!
   */
  public synchronized void setPlot(SVGPlot plot) {
    SVGPlot oldplot = this.plot;
    this.plot = plot;
    if (this.plot != null) {
      super.setDocument(this.plot.getDocument());
    } else {
      super.setDocument(null);
    }
    
    if (oldplot != null) {
      oldplot.setUpdateSynchronizer(null);
    }
    if (plot != null) {
      plot.setUpdateSynchronizer(this.synchronizer);
    }
  }
}

@@ -2201,10 +2201,175 @@
   %7D%0A  %7D%0A
+ %0A  /**%0A   * Get the currently displayed SVG plot.%0A   * %0A   * @return current SVG plot. May be %7B@code null%7D!%0A   */%0A  public SVGPlot getPlot() %7B%0A    return plot;%0A  %7D%0A
 %7D%0A

Add getter for SVG plot.