KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > swing > svg > SVGUpdateOverlay


1 /*
2
3    Copyright 2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.swing.svg;
19
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.LinkedList JavaDoc;
23
24 import java.awt.Rectangle JavaDoc;
25 import java.awt.Color JavaDoc;
26 import java.awt.Graphics JavaDoc;
27
28 import org.apache.batik.swing.gvt.Overlay;
29
30 /**
31  * One line Class Desc
32  *
33  * Complete Class Desc
34  *
35  * @author <a HREF="mailto:deweese@apache.org">deweese</a>
36  * @version $Id: SVGUpdateOverlay.java,v 1.3 2005/03/27 08:58:36 cam Exp $
37  */

38 public class SVGUpdateOverlay implements Overlay {
39     List JavaDoc rects = new LinkedList JavaDoc();
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 JavaDoc 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 JavaDoc g) {
74         Iterator JavaDoc 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 JavaDoc r = (Rectangle JavaDoc)i.next();
84             Color JavaDoc c;
85             c = new Color JavaDoc(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