KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > image > rendered > TileCacheRed


1 /*
2
3    Copyright 2001-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.ext.awt.image.rendered;
19
20 import java.awt.Rectangle JavaDoc;
21 import java.awt.image.ColorModel JavaDoc;
22 import java.awt.image.SampleModel JavaDoc;
23 import java.awt.image.WritableRaster JavaDoc;
24
25 /**
26  * This implementation of RenderedImage only serves to put the tiles
27  * generated by it's input into the TileCache.
28  *
29  * @author <a HREF="mailto:thomas.deweese@kodak.com">Thomas DeWeese</a>
30  * @version $Id: TileCacheRed.java,v 1.7 2004/08/18 07:14:08 vhardy Exp $
31  */

32 public class TileCacheRed extends AbstractTiledRed {
33
34     /**
35      * Place the results of computations of cr into the global tile cache.
36      * @param cr The operation to cache results from.
37      */

38     public TileCacheRed(CachableRed cr) {
39         super(cr, null);
40     }
41
42     /**
43      * Place the results of computations of cr into the global tile cache.
44      * @param cr The operation to cache results from.
45      */

46     public TileCacheRed(CachableRed cr, int tileWidth, int tileHeight) {
47         super();
48         ColorModel JavaDoc cm = cr.getColorModel();
49         Rectangle JavaDoc bounds = cr.getBounds();
50         if (tileWidth > bounds.width) tileWidth = bounds.width;
51         if (tileHeight > bounds.height) tileHeight = bounds.height;
52         SampleModel JavaDoc sm = cm.createCompatibleSampleModel(tileWidth, tileHeight);
53         init(cr, cr.getBounds(), cm, sm,
54              cr.getTileGridXOffset(), cr.getTileGridYOffset(),
55              null);
56     }
57
58     public void genRect(WritableRaster JavaDoc wr) {
59         // Get my source.
60
CachableRed src = (CachableRed)getSources().get(0);
61         
62         src.copyData(wr);
63     }
64
65     public void flushCache(Rectangle JavaDoc rect) {
66         int tx0 = getXTile(rect.x);
67         int ty0 = getYTile(rect.y);
68         int tx1 = getXTile(rect.x+rect.width -1);
69         int ty1 = getYTile(rect.y+rect.height-1);
70
71         if (tx0 < minTileX) tx0 = minTileX;
72         if (ty0 < minTileY) ty0 = minTileY;
73
74         if (tx1 >= minTileX+numXTiles) tx1 = minTileX+numXTiles-1;
75         if (ty1 >= minTileY+numYTiles) ty1 = minTileY+numYTiles-1;
76
77         if ((tx1 < tx0) || (ty1 < ty0))
78             return;
79
80         TileStore store = getTileStore();
81         for (int y=ty0; y<=ty1; y++)
82             for (int x=tx0; x<=tx1; x++)
83                 store.setTile(x, y, null);
84     }
85 }
86
Popular Tags