1 18 package org.apache.batik.swing; 19 20 import java.io.File ; 21 import java.net.MalformedURLException ; 22 23 import javax.swing.JFrame ; 24 import javax.swing.SwingUtilities ; 25 26 import org.w3c.dom.Element ; 27 28 import org.apache.batik.bridge.BridgeContext; 29 import org.apache.batik.bridge.UpdateManager; 30 import org.apache.batik.dom.svg.SVGContext; 31 import org.apache.batik.dom.svg.SVGOMElement; 32 import org.apache.batik.gvt.GraphicsNode; 33 import org.apache.batik.test.DefaultTestReport; 34 import org.apache.batik.test.MemoryLeakTest; 35 import org.apache.batik.test.TestReport; 36 37 45 public class JSVGMemoryLeakTest extends MemoryLeakTest 46 implements JSVGCanvasHandler.Delegate { 47 public JSVGMemoryLeakTest() { 48 } 49 50 public String getName() { return "JSVGMemoryLeakTest."+getId(); } 51 52 TestReport failReport = null; 53 boolean done; 54 JSVGCanvasHandler handler; 55 JFrame theFrame; 56 JSVGCanvas theCanvas; 57 58 public static String fmt(String key, Object []args) { 59 return TestMessages.formatMessage(key, args); 60 } 61 62 public JSVGCanvasHandler createHandler() { 63 return new JSVGCanvasHandler(this, this); 64 } 65 66 public TestReport doSomething() throws Exception { 67 handler = createHandler(); 68 registerObjectDesc(handler, "Handler"); 69 done = false; 70 handler.runCanvas(getId()); 71 72 SwingUtilities.invokeAndWait( new Runnable () { 73 public void run() { 74 theFrame.remove(theCanvas); 76 theCanvas.dispose(); 77 78 theFrame.dispose(); 79 theFrame=null; 80 theCanvas=null; 81 } 82 }); 83 84 try { Thread.sleep(100); } catch (InterruptedException ie) { } 85 86 SwingUtilities.invokeAndWait( new Runnable () { 87 public void run() { 88 theFrame = new JFrame ("FocusFrame"); 91 theFrame.setSize(new java.awt.Dimension (40, 50)); 93 theFrame.setVisible(true); 94 }}); 95 96 try { Thread.sleep(100); } catch (InterruptedException ie) { } 97 98 SwingUtilities.invokeAndWait( new Runnable () { 99 public void run() { 100 theFrame.setVisible(false); 101 theFrame.dispose(); 102 }}); 103 104 handler = null; 105 if (failReport != null) return failReport; 106 DefaultTestReport report = new DefaultTestReport(this); 107 report.setPassed(true); 108 return report; 109 } 110 111 public void scriptDone() { 112 synchronized (this) { 113 done = true; 114 handler.scriptDone(); 115 } 116 } 117 118 public void registerElement(Element e, String desc) { 119 registerObjectDesc(e, desc); 120 UpdateManager um = theCanvas.getUpdateManager(); 121 BridgeContext bc = um.getBridgeContext(); 122 GraphicsNode gn = bc.getGraphicsNode(e); 123 if (gn != null) 124 registerObjectDesc(gn, desc+"_GN"); 125 if (e instanceof SVGOMElement) { 126 SVGOMElement svge = (SVGOMElement)e; 127 SVGContext svgctx = svge.getSVGContext(); 128 if (svgctx != null) 129 registerObjectDesc(svgctx, desc+"_CTX"); 130 } 131 } 132 133 134 public boolean canvasInit(JSVGCanvas canvas) { 135 theCanvas = canvas; 137 theFrame = handler.getFrame(); 138 139 File f = new File (getId()); 140 try { 141 canvas.setURI(f.toURL().toString()); 142 } catch (MalformedURLException mue) { 143 } 144 registerObjectDesc(canvas, "JSVGCanvas"); 145 registerObjectDesc(handler.getFrame(), "JFrame"); 146 147 return true; 148 } 149 150 public void canvasLoaded(JSVGCanvas canvas) { 151 registerObjectDesc(canvas.getSVGDocument(), "SVGDoc"); 153 } 154 155 public void canvasRendered(JSVGCanvas canvas) { 156 registerObjectDesc(canvas.getGraphicsNode(), "GVT"); 158 registerObjectDesc(canvas.getUpdateManager(), "updateManager"); 159 } 160 161 public boolean canvasUpdated(JSVGCanvas canvas) { 162 synchronized (this) { 164 return done; 165 } 166 } 167 public void canvasDone(final JSVGCanvas canvas) { 168 } 170 171 public void failure(TestReport report) { 172 synchronized (this) { 173 done = true; 174 failReport = report; 175 } 176 } 177 } 178 | Popular Tags |