KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > gvt > RasterImageNode


1 /*
2
3    Copyright 2000-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.gvt;
19
20 import java.awt.Graphics2D JavaDoc;
21 import java.awt.Shape JavaDoc;
22 import java.awt.geom.Rectangle2D JavaDoc;
23
24 import org.apache.batik.ext.awt.image.GraphicsUtil;
25 import org.apache.batik.ext.awt.image.renderable.Filter;
26
27 /**
28  * A graphics node that represents a raster image.
29  *
30  * @author <a HREF="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
31  * @author <a HREF="mailto:Thomas.DeWeese@Kodak.com">Thomas DeWeese</a>
32  * @version $Id: RasterImageNode.java,v 1.18 2005/03/27 08:58:34 cam Exp $
33  */

34 public class RasterImageNode extends AbstractGraphicsNode {
35
36     /**
37      * The renderable image that represents this image node.
38      */

39     protected Filter image;
40
41     /**
42      * Constructs a new empty <tt>RasterImageNode</tt>.
43      */

44     public RasterImageNode() {}
45
46     //
47
// Properties methods
48
//
49

50     /**
51      * Sets the raster image of this raster image node.
52      *
53      * @param newImage the new raster image of this raster image node
54      */

55     public void setImage(Filter newImage) {
56         fireGraphicsNodeChangeStarted();
57         invalidateGeometryCache();
58         this.image = newImage;
59         fireGraphicsNodeChangeCompleted();
60     }
61
62     /**
63      * Returns the raster image of this raster image node.
64      *
65      * @return the raster image of this raster image node
66      */

67     public Filter getImage() {
68         return image;
69     }
70
71     /**
72      * Returns the bounds of this raster image node.
73      *
74      * @return the bounds of this raster image node
75      */

76     public Rectangle2D JavaDoc getImageBounds() {
77         if (image == null)
78             return null;
79         return (Rectangle2D JavaDoc) image.getBounds2D().clone();
80     }
81
82     /**
83      * Returns the RenderableImage for this node. The returned
84      * RenderableImage this node before any of the filter operations
85      * have been applied.
86      */

87     public Filter getGraphicsNodeRable() {
88         return image;
89     }
90
91     //
92
// Drawing methods
93
//
94

95     /**
96      * Paints this node without applying Filter, Mask, Composite and clip.
97      *
98      * @param g2d the Graphics2D to use
99      */

100     public void primitivePaint(Graphics2D JavaDoc g2d) {
101         if (image == null) return;
102
103         GraphicsUtil.drawImage(g2d, image);
104     }
105
106     //
107
// Geometric methods
108
//
109

110     /**
111      * Returns the bounds of the area covered by this node's primitive paint.
112      */

113     public Rectangle2D JavaDoc getPrimitiveBounds() {
114         if (image == null)
115             return null;
116         return image.getBounds2D();
117     }
118
119     /**
120      * Returns the bounds of the area covered by this node, without taking any
121      * of its rendering attribute into account. That is, exclusive of any clipping,
122      * masking, filtering or stroking, for example.
123      */

124     public Rectangle2D JavaDoc getGeometryBounds() {
125         if (image == null)
126             return null;
127         return image.getBounds2D();
128     }
129
130     /**
131      * Returns the bounds of the sensitive area covered by this node,
132      * This includes the stroked area but does not include the effects
133      * of clipping, masking or filtering.
134      */

135     public Rectangle2D JavaDoc getSensitiveBounds() {
136         if (image == null)
137             return null;
138         return image.getBounds2D();
139     }
140
141     /**
142      * Returns the outline of this node.
143      */

144     public Shape JavaDoc getOutline() {
145         if (image == null)
146             return null;
147         return image.getBounds2D();
148     }
149 }
150
Popular Tags