CompoundRenderer.java

00001 package edu.stanford.hci.r3.render.regions;
00002 
00003 import java.awt.Graphics2D;
00004 import java.awt.geom.AffineTransform;
00005 import java.util.Set;
00006 
00007 import edu.stanford.hci.r3.paper.Region;
00008 import edu.stanford.hci.r3.paper.regions.CompoundRegion;
00009 import edu.stanford.hci.r3.render.RegionRenderer;
00010 import edu.stanford.hci.r3.units.coordinates.Coordinates;
00011 import edu.stanford.hci.r3.util.DebugUtils;
00012 import edu.stanford.hci.r3.util.MathUtils;
00013 import edu.stanford.hci.r3.util.graphics.GraphicsUtils;
00014 
00026 public class CompoundRenderer extends RegionRenderer {
00027 
00028         private CompoundRegion compoundRegion;
00029 
00033         public CompoundRenderer(CompoundRegion cr) {
00034                 super(cr);
00035                 compoundRegion = cr;
00036         }
00037 
00041         public void renderToG2D(Graphics2D g2d) {
00042                 g2d.setRenderingHints(GraphicsUtils.getBestRenderingHints());
00043                 final double originXPts = compoundRegion.getOriginX().getValueInPoints();
00044                 final double originYPts = compoundRegion.getOriginY().getValueInPoints();
00045 
00046                 if (RegionRenderer.DEBUG_REGIONS) {
00047                         super.renderToG2D(g2d);
00048                         g2d.drawOval(MathUtils.rint(originXPts - 3), MathUtils.rint(originYPts - 3), 7, 7);
00049                 }
00050 
00051                 final AffineTransform oldTransform = new AffineTransform(g2d.getTransform());
00052                 // offset by the origin
00053                 final AffineTransform originTransform = new AffineTransform(g2d.getTransform());
00054                 originTransform.translate(originXPts, originYPts);
00055 
00056                 System.out.println("Rendering Compound Region");
00057                 Set<Region> children = compoundRegion.getChildren();
00058                 for (Region child : children) {
00059                         g2d.setTransform(originTransform); // start from the origin
00060 
00061                         // move to the correct offset in Points
00062                         Coordinates childOffset = compoundRegion.getChildOffset(child);
00063                         final double xOffsetPts = childOffset.getX().getValueInPoints();
00064                         final double yOffsetPts = childOffset.getY().getValueInPoints();
00065                         DebugUtils.println("Rendering Child Region: [" + child.getName()
00066                                         + "] with Child Offset: " + childOffset);
00067                         final AffineTransform translated = g2d.getTransform();
00068                         translated.translate(xOffsetPts, yOffsetPts);
00069                         g2d.setTransform(translated); // move to the correct offset
00070                         System.out.println(g2d.getTransform());
00071                         final RegionRenderer renderer = child.getRenderer();
00072                         renderer.renderToG2D(g2d);
00073                 }
00074 
00075                 g2d.setTransform(oldTransform);
00076         }
00077 }

Generated on Sat Apr 14 18:21:33 2007 for R3 Paper Toolkit by  doxygen 1.4.7