1 18 package org.apache.batik.gvt; 19 20 import java.awt.Graphics2D ; 21 import java.awt.geom.Point2D ; 22 import java.awt.geom.Rectangle2D ; 23 24 30 public class ImageNode extends CompositeGraphicsNode { 31 32 protected boolean hitCheckChildren = false; 33 34 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 getPrimitiveBounds() { 47 if (!isVisible) return null; 48 return super.getPrimitiveBounds(); 49 } 50 55 public void setHitCheckChildren(boolean hitCheckChildren) { 56 this.hitCheckChildren = hitCheckChildren; 57 } 58 59 public boolean getHitCheckChildren() { 60 return hitCheckChildren; 61 } 62 63 68 public void paint(Graphics2D g2d) { 69 if (isVisible) { 70 super.paint(g2d); 71 } 72 } 73 74 80 public boolean contains(Point2D 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 105 public GraphicsNode nodeHitAt(Point2D p) { 106 if (hitCheckChildren) return super.nodeHitAt(p); 107 108 return (contains(p) ? this : null); 109 } 110 111 115 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 134 public GraphicsNode getImage() { 135 if (count > 0) { 136 return children[0]; 137 } else { 138 return null; 139 } 140 } 141 } 142 | Popular Tags |