KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2000-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.gvt;
19
20 import java.awt.Graphics2D JavaDoc;
21 import java.awt.Paint JavaDoc;
22 import java.awt.geom.AffineTransform JavaDoc;
23 import java.awt.geom.NoninvertibleTransformException JavaDoc;
24
25 /**
26  * The graphics node container with a background color.
27  *
28  * @author <a HREF="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
29  * @version $Id: CanvasGraphicsNode.java,v 1.10 2004/08/18 07:14:25 vhardy Exp $
30  */

31 public class CanvasGraphicsNode extends CompositeGraphicsNode {
32
33     /**
34      * This is the position transform for this graphics node.
35      * This is needed because getCTM returns the transform
36      * to the viewport coordinate system which is after viewing but
37      * before positioning.
38      */

39     protected AffineTransform JavaDoc positionTransform;
40     /**
41      * This is the viewing transform for this graphics node.
42      * This is needed because getCTM returns the transform
43      * to the viewport coordinate system which is after viewing but
44      * before positioning.
45      */

46     protected AffineTransform JavaDoc viewingTransform;
47
48     /**
49      * The background of this canvas graphics node.
50      */

51     protected Paint JavaDoc backgroundPaint;
52
53     /**
54      * Constructs a new empty <tt>CanvasGraphicsNode</tt>.
55      */

56     public CanvasGraphicsNode() {}
57
58     //
59
// Properties methods
60
//
61

62     /**
63      * Sets the background paint of this canvas graphics node.
64      *
65      * @param newBackgroundPaint the new background paint
66      */

67     public void setBackgroundPaint(Paint JavaDoc newBackgroundPaint) {
68         this.backgroundPaint = newBackgroundPaint;
69     }
70
71     /**
72      * Returns the background paint of this canvas graphics node.
73      */

74     public Paint JavaDoc getBackgroundPaint() {
75         return backgroundPaint;
76     }
77
78     public void setPositionTransform(AffineTransform JavaDoc at) {
79         fireGraphicsNodeChangeStarted();
80         invalidateGeometryCache();
81         this.positionTransform = at;
82         if (positionTransform != null) {
83             transform = new AffineTransform JavaDoc(positionTransform);
84             if (viewingTransform != null)
85                 transform.concatenate(viewingTransform);
86         } else if (viewingTransform != null)
87             transform = new AffineTransform JavaDoc(viewingTransform);
88         else
89             transform = new AffineTransform JavaDoc();
90         
91         if (transform.getDeterminant() != 0){
92             try{
93                 inverseTransform = transform.createInverse();
94             }catch(NoninvertibleTransformException JavaDoc e){
95                 // Should never happen.
96
throw new Error JavaDoc();
97             }
98         }
99         else{
100             // The transform is not invertible. Use the same
101
// transform.
102
inverseTransform = transform;
103         }
104         fireGraphicsNodeChangeCompleted();
105     }
106
107     public AffineTransform JavaDoc getPositionTransform() {
108         return positionTransform;
109     }
110
111     public void setViewingTransform(AffineTransform JavaDoc at) {
112         fireGraphicsNodeChangeStarted();
113         invalidateGeometryCache();
114         this.viewingTransform = at;
115         if (positionTransform != null) {
116             transform = new AffineTransform JavaDoc(positionTransform);
117             if (viewingTransform != null)
118                 transform.concatenate(viewingTransform);
119         } else if (viewingTransform != null)
120             transform = new AffineTransform JavaDoc(viewingTransform);
121         else
122             transform = new AffineTransform JavaDoc();
123
124         if(transform.getDeterminant() != 0){
125             try{
126                 inverseTransform = transform.createInverse();
127             }catch(NoninvertibleTransformException JavaDoc e){
128                 // Should never happen.
129
throw new Error JavaDoc();
130             }
131         }
132         else{
133             // The transform is not invertible. Use the same
134
// transform.
135
inverseTransform = transform;
136         }
137         fireGraphicsNodeChangeCompleted();
138     }
139
140     public AffineTransform JavaDoc getViewingTransform() {
141         return viewingTransform;
142     }
143
144     //
145
// Drawing methods
146
//
147

148     /**
149      * Paints this node without applying Filter, Mask, Composite, and clip.
150      *
151      * @param g2d the Graphics2D to use
152      */

153     public void primitivePaint(Graphics2D JavaDoc g2d) {
154         if (backgroundPaint != null) {
155             g2d.setPaint(backgroundPaint);
156             g2d.fill(g2d.getClip()); // Fast paint for huge background area
157
}
158         super.primitivePaint(g2d);
159     }
160 }
161
Popular Tags