KickJava   Java API By Example, From Geeks To Geeks.

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


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.geom.Point2D JavaDoc;
22 import java.awt.geom.Rectangle2D JavaDoc;
23
24 /**
25  * A graphics node that represents an image described as a graphics node.
26  *
27  * @author <a HREF="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
28  * @version $Id: ImageNode.java,v 1.19 2005/02/12 01:48:24 deweese Exp $
29  */

30 public class ImageNode extends CompositeGraphicsNode {
31
32     protected boolean hitCheckChildren = false;
33     
34     /**
35      * Constructs a new empty <tt>ImageNode</tt>.
36      */

37     public ImageNode() {}
38
39     public void setVisible(boolean isVisible) {
40         fireGraphicsNodeChangeStarted();
41         this.isVisible = isVisible;
42         invalidateGeometryCache();
43         fireGraphicsNodeChangeCompleted();
44     }
45
46     public Rectangle2D JavaDoc getPrimitiveBounds() {
47         if (!isVisible) return null;
48         return super.getPrimitiveBounds();
49     }
50     /**
51      * If hitCheckChildren is true then nodeHitAt will return
52      * child nodes of this image. Otherwise it will only
53      * return this node (if the point is in the image).
54      */

55     public void setHitCheckChildren(boolean hitCheckChildren) {
56         this.hitCheckChildren = hitCheckChildren;
57     }
58
59     public boolean getHitCheckChildren() {
60         return hitCheckChildren;
61     }
62
63     /**
64      * Paints this node.
65      *
66      * @param g2d the Graphics2D to use
67      */

68     public void paint(Graphics2D JavaDoc g2d) {
69         if (isVisible) {
70             super.paint(g2d);
71         }
72     }
73
74     /**
75      * Returns true if the specified Point2D is inside the boundary of this
76      * node, false otherwise.
77      *
78      * @param p the specified Point2D in the user space
79      */

80     public boolean contains(Point2D JavaDoc p) {
81         switch(pointerEventType) {
82         case VISIBLE_PAINTED:
83         case VISIBLE_FILL:
84         case VISIBLE_STROKE:
85         case VISIBLE:
86             return isVisible && super.contains(p);
87         case PAINTED:
88         case FILL:
89         case STROKE:
90         case ALL:
91             return super.contains(p);
92         case NONE:
93             return false;
94         default:
95             return false;
96         }
97     }
98
99     /**
100      * Returns the GraphicsNode containing point p if this node or one of its
101      * children is sensitive to mouse events at p.
102      *
103      * @param p the specified Point2D in the user space
104      */

105     public GraphicsNode nodeHitAt(Point2D JavaDoc p) {
106         if (hitCheckChildren) return super.nodeHitAt(p);
107
108         return (contains(p) ? this : null);
109     }
110
111     //
112
// Properties methods
113
//
114

115     /**
116      * Sets the graphics node that represents the image.
117      *
118      * @param newImage the new graphics node that represents the image
119      */

120     public void setImage(GraphicsNode newImage) {
121         fireGraphicsNodeChangeStarted();
122         invalidateGeometryCache();
123         if (count == 0) ensureCapacity(1);
124         children[0] = newImage;
125         ((AbstractGraphicsNode)newImage).setParent(this);
126         ((AbstractGraphicsNode)newImage).setRoot(getRoot());
127         count=1;
128         fireGraphicsNodeChangeCompleted();
129     }
130
131     /**
132      * Returns the graphics node that represents the image.
133      */

134     public GraphicsNode getImage() {
135         if (count > 0) {
136             return children[0];
137         } else {
138             return null;
139         }
140     }
141 }
142
Popular Tags