1 18 package org.apache.batik.swing.svg; 19 20 import java.util.Collections ; 21 import java.util.LinkedList ; 22 import java.util.List ; 23 24 import org.apache.batik.bridge.BridgeContext; 25 import org.apache.batik.bridge.InterruptedBridgeException; 26 import org.apache.batik.bridge.UpdateManager; 27 import org.apache.batik.gvt.GraphicsNode; 28 import org.apache.batik.util.EventDispatcher; 29 import org.apache.batik.util.EventDispatcher.Dispatcher; 30 import org.apache.batik.util.HaltingThread; 31 32 import org.w3c.dom.svg.SVGDocument; 33 34 40 public class SVGLoadEventDispatcher extends HaltingThread { 41 42 45 protected SVGDocument svgDocument; 46 47 50 protected GraphicsNode root; 51 52 55 protected BridgeContext bridgeContext; 56 57 60 protected UpdateManager updateManager; 61 62 65 protected List listeners = Collections.synchronizedList(new LinkedList ()); 66 67 70 protected Exception exception; 71 72 75 public SVGLoadEventDispatcher(GraphicsNode gn, 76 SVGDocument doc, 77 BridgeContext bc, 78 UpdateManager um) { 79 svgDocument = doc; 80 root = gn; 81 bridgeContext = bc; 82 updateManager = um; 83 } 84 85 88 public void run() { 89 SVGLoadEventDispatcherEvent ev; 90 ev = new SVGLoadEventDispatcherEvent(this, root); 91 try { 92 fireEvent(startedDispatcher, ev); 93 94 if (isHalted()) { 95 fireEvent(cancelledDispatcher, ev); 96 return; 97 } 98 99 updateManager.dispatchSVGLoadEvent(); 100 101 if (isHalted()) { 102 fireEvent(cancelledDispatcher, ev); 103 return; 104 } 105 106 fireEvent(completedDispatcher, ev); 107 } catch (InterruptedException e) { 108 fireEvent(cancelledDispatcher, ev); 109 } catch (InterruptedBridgeException e) { 110 fireEvent(cancelledDispatcher, ev); 111 } catch (Exception e) { 112 exception = e; 113 fireEvent(failedDispatcher, ev); 114 } catch (ThreadDeath td) { 115 exception = new Exception (td.getMessage()); 116 fireEvent(failedDispatcher, ev); 117 throw td; 118 } catch (Throwable t) { 119 t.printStackTrace(); 120 exception = new Exception (t.getMessage()); 121 fireEvent(failedDispatcher, ev); 122 } 123 } 124 125 128 public UpdateManager getUpdateManager() { 129 return updateManager; 130 } 131 132 135 public Exception getException() { 136 return exception; 137 } 138 139 142 public void addSVGLoadEventDispatcherListener 143 (SVGLoadEventDispatcherListener l) { 144 listeners.add(l); 145 } 146 147 151 public void removeSVGLoadEventDispatcherListener 152 (SVGLoadEventDispatcherListener l) { 153 listeners.remove(l); 154 } 155 156 public void fireEvent(Dispatcher dispatcher, Object event) { 157 EventDispatcher.fireEvent(dispatcher, listeners, event, true); 158 } 159 160 static Dispatcher startedDispatcher = new Dispatcher() { 161 public void dispatch(Object listener, 162 Object event) { 163 ((SVGLoadEventDispatcherListener)listener). 164 svgLoadEventDispatchStarted 165 ((SVGLoadEventDispatcherEvent)event); 166 } 167 }; 168 169 static Dispatcher completedDispatcher = new Dispatcher() { 170 public void dispatch(Object listener, 171 Object event) { 172 ((SVGLoadEventDispatcherListener)listener). 173 svgLoadEventDispatchCompleted 174 ((SVGLoadEventDispatcherEvent)event); 175 } 176 }; 177 178 static Dispatcher cancelledDispatcher = new Dispatcher() { 179 public void dispatch(Object listener, 180 Object event) { 181 ((SVGLoadEventDispatcherListener)listener). 182 svgLoadEventDispatchCancelled 183 ((SVGLoadEventDispatcherEvent)event); 184 } 185 }; 186 187 static Dispatcher failedDispatcher = new Dispatcher() { 188 public void dispatch(Object listener, 189 Object event) { 190 ((SVGLoadEventDispatcherListener)listener). 191 svgLoadEventDispatchFailed 192 ((SVGLoadEventDispatcherEvent)event); 193 } 194 }; 195 } 196 | Popular Tags |