DebugPCanvas.java

00001 package edu.stanford.hci.r3.tools.debug;
00002 
00003 import java.awt.Color;
00004 import java.awt.geom.Ellipse2D;
00005 import java.awt.geom.Line2D;
00006 import java.awt.geom.Rectangle2D;
00007 import java.util.List;
00008 
00009 import edu.stanford.hci.r3.Application;
00010 import edu.stanford.hci.r3.events.EventHandler;
00011 import edu.stanford.hci.r3.paper.Region;
00012 import edu.stanford.hci.r3.paper.Sheet;
00013 import edu.stanford.hci.r3.util.DebugUtils;
00014 import edu.umd.cs.piccolo.PCanvas;
00015 import edu.umd.cs.piccolo.PNode;
00016 import edu.umd.cs.piccolo.nodes.PPath;
00017 import edu.umd.cs.piccolo.nodes.PText;
00018 
00031 public class DebugPCanvas extends PCanvas {
00032 
00033         private Color defaultLineColor;
00034         private PNode sheetContainer;
00035         private Color defaultFillColor;
00036 
00037         public DebugPCanvas() {
00038                 sheetContainer = new PNode();
00039                 getLayer().addChild(sheetContainer);
00040                 useDefaultTheme();
00041         }
00042 
00043         public void useDefaultTheme() {
00044                 setBackground(new Color(50, 50, 50));
00045                 defaultLineColor = new Color(240, 240, 240);
00046                 defaultFillColor = new Color(140, 140, 140);
00047         }
00048 
00049         public void addVisualComponents(Application paperApp) {
00050                 sheetContainer.setPaint(defaultLineColor);
00051 
00052                 sheetContainer.setOffset(30, 40);
00053 
00054                 List<Sheet> sheets = paperApp.getSheets();
00055                 DebugUtils.println("Number of Sheets: " + sheets.size());
00056 
00057                 Sheet sheet = sheets.get(0);
00058 
00059                 double wInches = sheet.getWidth().getValueInInches();
00060                 double hInches = sheet.getHeight().getValueInInches();
00061 
00062                 double pixelsPerInch = 72;
00063 
00064                 PPath sheetRect = new PPath(new Rectangle2D.Double(0, 0, wInches * pixelsPerInch, hInches
00065                                 * pixelsPerInch));
00066 
00067                 sheetRect.setStrokePaint(defaultLineColor);
00068                 // rectangle.setPaint(defaultLineColor);
00069 
00070                 List<Region> regions = sheet.getRegions();
00071                 for (Region r : regions) {
00072                         double xLoc = r.getOriginX().getValueInInches() * pixelsPerInch;
00073                         double yLoc = r.getOriginY().getValueInInches() * pixelsPerInch;
00074 
00075                         double rWidth = r.getWidth().getValueInInches() * pixelsPerInch;
00076                         double rHeight = r.getHeight().getValueInInches() * pixelsPerInch;
00077 
00078                         PPath regionRect = new PPath(new Rectangle2D.Double(xLoc, yLoc, rWidth, rHeight));
00079                         regionRect.setStrokePaint(defaultLineColor);
00080                         regionRect.setPaint(defaultFillColor);
00081 
00082                         sheetRect.addChild(regionRect);
00083 
00084                         List<EventHandler> eventHandlers = r.getEventHandlers();
00085 
00086                         for (EventHandler eh : eventHandlers) {
00087                                 DebugUtils.println(eh.getClass().getName());
00088 
00089                                 int xOffset = 750;
00090 
00091                                 PPath connector = new PPath(new Line2D.Double(xLoc + rWidth, yLoc + 20, xOffset,
00092                                                 yLoc + 20));
00093                                 connector.setStrokePaint(defaultLineColor);
00094 
00095                                 PPath handlerCircle = new PPath(new Ellipse2D.Double(0, 0, 20, 20));
00096                                 handlerCircle.setStrokePaint(defaultLineColor);
00097                                 handlerCircle.setOffset(xOffset, yLoc + 10);
00098 
00099                                 PText label = new PText(eh.getClass().getName());
00100                                 label.setTextPaint(defaultLineColor);
00101                                 label.setOffset(25, 2);
00102 
00103                                 // or should we add to the regionRect?
00104                                 handlerCircle.addChild(label);
00105                                 sheetRect.addChild(connector);
00106                                 sheetRect.addChild(handlerCircle);
00107                         }
00108 
00109                 }
00110 
00111                 sheetContainer.addChild(sheetRect);
00112                 repaint();
00113         }
00114 }

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