1 18 package org.apache.batik.swing.svg; 19 20 import java.util.Iterator ; 21 import java.util.List ; 22 import java.util.LinkedList ; 23 24 import java.awt.Rectangle ; 25 import java.awt.Color ; 26 import java.awt.Graphics ; 27 28 import org.apache.batik.swing.gvt.Overlay; 29 30 38 public class SVGUpdateOverlay implements Overlay { 39 List rects = new LinkedList (); 40 int size, updateCount; 41 int []counts; 42 public SVGUpdateOverlay(int size, int numUpdates) { 43 this.size = size; 44 counts = new int[numUpdates]; 45 } 46 47 public void addRect(Rectangle r) { 48 rects.add(r); 49 if (rects.size() > size) 50 rects.remove(0); 51 updateCount++; 52 } 53 54 public void endUpdate() { 55 int i=0; 56 int total =0; 57 for (; i<counts.length-1; i++) { 58 counts[i] = counts[i+1]; 59 } 60 counts[i] = updateCount; 61 updateCount = 0; 62 63 int num = rects.size(); 64 for (i=counts.length-1; i>=0; i--) { 65 if (counts[i] > num) { 66 counts[i] = num; 67 } 68 num -= counts[i]; 69 } 70 counts[0] += num; 71 } 72 73 public void paint(Graphics g) { 74 Iterator i = rects.iterator(); 75 int count = 0; 76 int idx = 0; 77 int group = 0; 78 while ((group < counts.length-1) && 79 (idx == counts[group])) 80 group++; 81 int cmax = counts.length-1; 82 while (i.hasNext()) { 83 Rectangle r = (Rectangle )i.next(); 84 Color c; 85 c = new Color (1f, (cmax-group)/(float)cmax, 0, 86 (count+1f)/rects.size()); 87 g.setColor(c); 88 g.drawRect(r.x, r.y, r.width, r.height); 89 count++; idx++; 90 while ((group < counts.length-1) && 91 (idx == counts[group])) { 92 group++; 93 idx = 0; 94 } 95 } 96 } 97 } 98 | Popular Tags |