001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.gvt;
020:
021: import java.awt.Graphics2D;
022: import java.awt.geom.Point2D;
023: import java.awt.geom.Rectangle2D;
024:
025: /**
026: * A graphics node that represents an image described as a graphics node.
027: *
028: * @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
029: * @version $Id: ImageNode.java 475477 2006-11-15 22:44:28Z cam $
030: */
031: public class ImageNode extends CompositeGraphicsNode {
032:
033: protected boolean hitCheckChildren = false;
034:
035: /**
036: * Constructs a new empty <tt>ImageNode</tt>.
037: */
038: public ImageNode() {
039: }
040:
041: public void setVisible(boolean isVisible) {
042: fireGraphicsNodeChangeStarted();
043: this .isVisible = isVisible;
044: invalidateGeometryCache();
045: fireGraphicsNodeChangeCompleted();
046: }
047:
048: public Rectangle2D getPrimitiveBounds() {
049: if (!isVisible)
050: return null;
051: return super .getPrimitiveBounds();
052: }
053:
054: /**
055: * If hitCheckChildren is true then nodeHitAt will return
056: * child nodes of this image. Otherwise it will only
057: * return this node (if the point is in the image).
058: */
059: public void setHitCheckChildren(boolean hitCheckChildren) {
060: this .hitCheckChildren = hitCheckChildren;
061: }
062:
063: public boolean getHitCheckChildren() {
064: return hitCheckChildren;
065: }
066:
067: /**
068: * Paints this node.
069: *
070: * @param g2d the Graphics2D to use
071: */
072: public void paint(Graphics2D g2d) {
073: if (isVisible) {
074: super .paint(g2d);
075: }
076: }
077:
078: /**
079: * Returns true if the specified Point2D is inside the boundary of this
080: * node, false otherwise.
081: *
082: * @param p the specified Point2D in the user space
083: */
084: public boolean contains(Point2D p) {
085: switch (pointerEventType) {
086: case VISIBLE_PAINTED:
087: case VISIBLE_FILL:
088: case VISIBLE_STROKE:
089: case VISIBLE:
090: return isVisible && super .contains(p);
091: case PAINTED:
092: case FILL:
093: case STROKE:
094: case ALL:
095: return super .contains(p);
096: case NONE:
097: return false;
098: default:
099: return false;
100: }
101: }
102:
103: /**
104: * Returns the GraphicsNode containing point p if this node or one of its
105: * children is sensitive to mouse events at p.
106: *
107: * @param p the specified Point2D in the user space
108: */
109: public GraphicsNode nodeHitAt(Point2D p) {
110: if (hitCheckChildren)
111: return super .nodeHitAt(p);
112:
113: return (contains(p) ? this : null);
114: }
115:
116: //
117: // Properties methods
118: //
119:
120: /**
121: * Sets the graphics node that represents the image.
122: *
123: * @param newImage the new graphics node that represents the image
124: */
125: public void setImage(GraphicsNode newImage) {
126: fireGraphicsNodeChangeStarted();
127: invalidateGeometryCache();
128: if (count == 0)
129: ensureCapacity(1);
130: children[0] = newImage;
131: ((AbstractGraphicsNode) newImage).setParent(this );
132: ((AbstractGraphicsNode) newImage).setRoot(getRoot());
133: count = 1;
134: fireGraphicsNodeChangeCompleted();
135: }
136:
137: /**
138: * Returns the graphics node that represents the image.
139: */
140: public GraphicsNode getImage() {
141: if (count > 0) {
142: return children[0];
143: } else {
144: return null;
145: }
146: }
147: }
|