1 18 package org.apache.batik.bridge; 19 20 import java.awt.Rectangle ; 21 import java.awt.Shape ; 22 import java.awt.geom.AffineTransform ; 23 import java.awt.geom.Rectangle2D ; 24 import java.awt.image.BufferedImage ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 import java.util.Iterator ; 28 import java.util.Collection ; 29 30 import org.apache.batik.gvt.renderer.ImageRenderer; 31 import org.apache.batik.ext.awt.geom.RectListManager; 32 33 40 public class RepaintManager { 41 final static int COPY_OVERHEAD = 10000; 42 final static int COPY_LINE_OVERHEAD = 10; 43 44 47 protected ImageRenderer renderer; 48 49 52 public RepaintManager(ImageRenderer r) { 53 renderer = r; 54 } 55 56 61 public Collection updateRendering(Collection areas) 62 throws InterruptedException { 63 renderer.flush(areas); 64 List rects = new ArrayList (areas.size()); 65 AffineTransform at = renderer.getTransform(); 66 67 Iterator i = areas.iterator(); 68 while (i.hasNext()) { 69 Shape s = (Shape )i.next(); 70 s = at.createTransformedShape(s); 71 Rectangle2D r2d = s.getBounds2D(); 72 int x0 = (int)Math.floor(r2d.getX()); 73 int y0 = (int)Math.floor(r2d.getY()); 74 int x1 = (int)Math.ceil(r2d.getX()+r2d.getWidth()); 75 int y1 = (int)Math.ceil(r2d.getY()+r2d.getHeight()); 76 Rectangle r = new Rectangle (x0-1, y0-1, x1-x0+3, y1-y0+3); 79 80 rects.add(r); 81 } 82 RectListManager devRLM =null; 83 try { 84 devRLM = new RectListManager(rects); 85 devRLM.mergeRects(COPY_OVERHEAD, COPY_LINE_OVERHEAD); 86 } catch(Exception e) { 87 e.printStackTrace(); 88 } 89 90 renderer.repaint(devRLM); 91 return devRLM; 92 } 93 94 104 public void setupRenderer(AffineTransform u2d, 105 boolean dbr, 106 Shape aoi, 107 int width, 108 int height) { 109 renderer.setTransform(u2d); 110 renderer.setDoubleBuffered(dbr); 111 renderer.updateOffScreen(width, height); 112 renderer.clearOffScreen(); 113 } 114 115 119 public BufferedImage getOffScreen(){ 120 return renderer.getOffScreen(); 121 } 122 } 123 | Popular Tags |