KickJava   Java API By Example, From Geeks To Geeks.

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


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
21 import java.awt.Rectangle JavaDoc;
22 import java.awt.image.Raster JavaDoc;
23 import java.awt.image.WritableRaster JavaDoc;
24 /**
25  * This is a special case of an Affine that only contains integer
26  * translations, this allows it to do it's work by simply changing
27  * the coordinate system of the tiles.
28  *
29  * @author <a HREF="mailto:Thomas.DeWeeese@Kodak.com">Thomas DeWeese</a>
30  * @version $Id: TranslateRed.java,v 1.5 2004/08/18 07:14:09 vhardy Exp $ */

31 public class TranslateRed extends AbstractRed {
32     
33     protected int deltaX;
34     protected int deltaY;
35
36     /**
37      * Construct an instance of TranslateRed
38      * @param xloc The new x coordinate of cr.getMinX().
39      * @param yloc The new y coordinate of cr.getMinY().
40      */

41     public TranslateRed(CachableRed cr, int xloc, int yloc) {
42         super(cr, new Rectangle JavaDoc(xloc, yloc,
43                                 cr.getWidth(), cr.getHeight()),
44               cr.getColorModel(), cr.getSampleModel(),
45               cr.getTileGridXOffset()+xloc-cr.getMinX(),
46               cr.getTileGridYOffset()+yloc-cr.getMinY(),
47               null);
48         deltaX = xloc-cr.getMinX();
49         deltaY = yloc-cr.getMinY();
50     }
51     
52     /**
53      * The delata translation in x (absolute loc is available from getMinX())
54      */

55     public int getDeltaX() { return deltaX; }
56
57     /**
58      * The delata translation in y (absolute loc is available from getMinY())
59      */

60     public int getDeltaY() { return deltaY; }
61
62     /**
63      * fetch the source image for this node.
64      */

65     public CachableRed getSource() {
66         return (CachableRed)getSources().get(0);
67     }
68
69     public Object JavaDoc getProperty(String JavaDoc name) {
70         return getSource().getProperty(name);
71     }
72
73     public String JavaDoc [] getPropertyNames() {
74         return getSource().getPropertyNames();
75     }
76
77     public Raster JavaDoc getTile(int tileX, int tileY) {
78         Raster JavaDoc r = getSource().getTile(tileX, tileY);
79         
80         return r.createTranslatedChild(r.getMinX()+deltaX,
81                                        r.getMinY()+deltaY);
82     }
83
84     public Raster JavaDoc getData() {
85         Raster JavaDoc r = getSource().getData();
86         return r.createTranslatedChild(r.getMinX()+deltaX,
87                                        r.getMinY()+deltaY);
88     }
89
90     public Raster JavaDoc getData(Rectangle JavaDoc rect) {
91         Rectangle JavaDoc r = (Rectangle JavaDoc)rect.clone();
92         r.translate(-deltaX, -deltaY);
93         Raster JavaDoc ret = getSource().getData(r);
94         return ret.createTranslatedChild(ret.getMinX()+deltaX,
95                                          ret.getMinY()+deltaY);
96     }
97
98     public WritableRaster JavaDoc copyData(WritableRaster JavaDoc wr) {
99         WritableRaster JavaDoc wr2 = wr.createWritableTranslatedChild
100             (wr.getMinX()-deltaX, wr.getMinY()-deltaY);
101
102         getSource().copyData(wr2);
103
104         return wr;
105     }
106 }
107
Popular Tags