1 18 package org.apache.batik.gvt; 19 20 import java.awt.Graphics2D ; 21 import java.awt.Paint ; 22 import java.awt.geom.AffineTransform ; 23 import java.awt.geom.NoninvertibleTransformException ; 24 25 31 public class CanvasGraphicsNode extends CompositeGraphicsNode { 32 33 39 protected AffineTransform positionTransform; 40 46 protected AffineTransform viewingTransform; 47 48 51 protected Paint backgroundPaint; 52 53 56 public CanvasGraphicsNode() {} 57 58 62 67 public void setBackgroundPaint(Paint newBackgroundPaint) { 68 this.backgroundPaint = newBackgroundPaint; 69 } 70 71 74 public Paint getBackgroundPaint() { 75 return backgroundPaint; 76 } 77 78 public void setPositionTransform(AffineTransform at) { 79 fireGraphicsNodeChangeStarted(); 80 invalidateGeometryCache(); 81 this.positionTransform = at; 82 if (positionTransform != null) { 83 transform = new AffineTransform (positionTransform); 84 if (viewingTransform != null) 85 transform.concatenate(viewingTransform); 86 } else if (viewingTransform != null) 87 transform = new AffineTransform (viewingTransform); 88 else 89 transform = new AffineTransform (); 90 91 if (transform.getDeterminant() != 0){ 92 try{ 93 inverseTransform = transform.createInverse(); 94 }catch(NoninvertibleTransformException e){ 95 throw new Error (); 97 } 98 } 99 else{ 100 inverseTransform = transform; 103 } 104 fireGraphicsNodeChangeCompleted(); 105 } 106 107 public AffineTransform getPositionTransform() { 108 return positionTransform; 109 } 110 111 public void setViewingTransform(AffineTransform at) { 112 fireGraphicsNodeChangeStarted(); 113 invalidateGeometryCache(); 114 this.viewingTransform = at; 115 if (positionTransform != null) { 116 transform = new AffineTransform (positionTransform); 117 if (viewingTransform != null) 118 transform.concatenate(viewingTransform); 119 } else if (viewingTransform != null) 120 transform = new AffineTransform (viewingTransform); 121 else 122 transform = new AffineTransform (); 123 124 if(transform.getDeterminant() != 0){ 125 try{ 126 inverseTransform = transform.createInverse(); 127 }catch(NoninvertibleTransformException e){ 128 throw new Error (); 130 } 131 } 132 else{ 133 inverseTransform = transform; 136 } 137 fireGraphicsNodeChangeCompleted(); 138 } 139 140 public AffineTransform getViewingTransform() { 141 return viewingTransform; 142 } 143 144 148 153 public void primitivePaint(Graphics2D g2d) { 154 if (backgroundPaint != null) { 155 g2d.setPaint(backgroundPaint); 156 g2d.fill(g2d.getClip()); } 158 super.primitivePaint(g2d); 159 } 160 } 161 | Popular Tags |