1 18 package org.apache.batik.swing.gvt; 19 20 import java.awt.Shape ; 21 import java.awt.geom.AffineTransform ; 22 import java.util.Collections ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 26 import org.apache.batik.bridge.InterruptedBridgeException; 27 import org.apache.batik.gvt.renderer.ImageRenderer; 28 import org.apache.batik.util.EventDispatcher; 29 import org.apache.batik.util.EventDispatcher.Dispatcher; 30 import org.apache.batik.util.HaltingThread; 31 32 39 public class GVTTreeRenderer extends HaltingThread { 40 41 44 protected ImageRenderer renderer; 45 46 49 protected Shape areaOfInterest; 50 51 54 protected int width; 55 56 59 protected int height; 60 61 64 protected AffineTransform user2DeviceTransform; 65 66 69 protected boolean doubleBuffering; 70 71 74 protected List listeners = Collections.synchronizedList(new LinkedList ()); 75 76 85 public GVTTreeRenderer(ImageRenderer r, AffineTransform usr2dev, 86 boolean dbuffer, 87 Shape aoi, int width, int height) { 88 renderer = r; 89 areaOfInterest = aoi; 90 user2DeviceTransform = usr2dev; 91 doubleBuffering = dbuffer; 92 this.width = width; 93 this.height = height; 94 } 95 96 99 public void run() { 100 GVTTreeRendererEvent ev = new GVTTreeRendererEvent(this, null); 101 try { 102 fireEvent(prepareDispatcher, ev); 103 104 renderer.setTransform(user2DeviceTransform); 105 renderer.setDoubleBuffered(doubleBuffering); 106 renderer.updateOffScreen(width, height); 107 renderer.clearOffScreen(); 108 109 if (isHalted()) { 110 fireEvent(cancelledDispatcher, ev); 111 return; 112 } 113 114 ev = new GVTTreeRendererEvent(this, renderer.getOffScreen()); 115 fireEvent(startedDispatcher, ev); 116 117 if (isHalted()) { 118 fireEvent(cancelledDispatcher, ev); 119 return; 120 } 121 122 renderer.repaint(areaOfInterest); 123 124 if (isHalted()) { 125 fireEvent(cancelledDispatcher, ev); 126 return; 127 } 128 129 ev = new GVTTreeRendererEvent(this, renderer.getOffScreen()); 130 fireEvent(completedDispatcher, ev); 131 } catch (NoClassDefFoundError e) { 132 } catch (InterruptedBridgeException e) { 135 fireEvent(cancelledDispatcher, ev); 138 } catch (ThreadDeath td) { 139 fireEvent(failedDispatcher, ev); 140 throw td; 141 } catch (Throwable t) { 142 t.printStackTrace(); 143 fireEvent(failedDispatcher, ev); 144 } 145 } 146 147 public void fireEvent(Dispatcher dispatcher, Object event) { 148 EventDispatcher.fireEvent(dispatcher, listeners, event, true); 149 } 150 151 154 public void addGVTTreeRendererListener(GVTTreeRendererListener l) { 155 listeners.add(l); 156 } 157 158 161 public void removeGVTTreeRendererListener(GVTTreeRendererListener l) { 162 listeners.remove(l); 163 } 164 165 static Dispatcher prepareDispatcher = new Dispatcher() { 166 public void dispatch(Object listener, 167 Object event) { 168 ((GVTTreeRendererListener)listener).gvtRenderingPrepare 169 ((GVTTreeRendererEvent)event); 170 } 171 }; 172 173 static Dispatcher startedDispatcher = new Dispatcher() { 174 public void dispatch(Object listener, 175 Object event) { 176 ((GVTTreeRendererListener)listener).gvtRenderingStarted 177 ((GVTTreeRendererEvent)event); 178 } 179 }; 180 181 static Dispatcher cancelledDispatcher = new Dispatcher() { 182 public void dispatch(Object listener, 183 Object event) { 184 ((GVTTreeRendererListener)listener).gvtRenderingCancelled 185 ((GVTTreeRendererEvent)event); 186 } 187 }; 188 189 static Dispatcher completedDispatcher = new Dispatcher() { 190 public void dispatch(Object listener, 191 Object event) { 192 ((GVTTreeRendererListener)listener).gvtRenderingCompleted 193 ((GVTTreeRendererEvent)event); 194 } 195 }; 196 197 static Dispatcher failedDispatcher = new Dispatcher() { 198 public void dispatch(Object listener, 199 Object event) { 200 ((GVTTreeRendererListener)listener).gvtRenderingFailed 201 ((GVTTreeRendererEvent)event); 202 } 203 }; 204 205 206 } 207 | Popular Tags |