1 26 27 package org.nightlabs.editor2d.viewer; 28 29 import java.awt.Graphics2D ; 30 import java.awt.geom.Rectangle2D ; 31 import java.util.Iterator ; 32 33 import org.apache.log4j.Logger; 34 import org.eclipse.swt.graphics.GC; 35 import org.eclipse.swt.widgets.Control; 36 37 import org.nightlabs.base.util.GeomUtil; 38 import org.nightlabs.editor2d.DrawComponent; 39 import org.nightlabs.editor2d.DrawComponentContainer; 40 import org.nightlabs.editor2d.Layer; 41 import org.nightlabs.editor2d.render.Renderer; 42 import org.nightlabs.editor2d.viewer.j2dswt.SWTGraphics2D; 43 44 public class DrawComponentPaintable 45 { 47 public static final Logger LOGGER = Logger.getLogger(DrawComponentPaintable.class.getName()); 48 49 protected DrawComponent dc; 50 public DrawComponentPaintable(DrawComponent dc) 51 { 52 super(); 53 this.dc = dc; 54 } 55 56 62 public void paint(Control control, Graphics2D g2d) 63 { 64 LOGGER.debug("paint called!"); 65 long startTime = System.currentTimeMillis(); 66 paintDrawComponent(dc, g2d); 67 long endTime = System.currentTimeMillis() - startTime; 68 LOGGER.debug("paint took = "+endTime+" ms!"); 69 } 70 71 75 public void redraw(Control control, GC gc) 76 { 77 LOGGER.debug("redraw called!"); 78 long startTime = System.currentTimeMillis(); 79 paintDrawComponent(dc, new SWTGraphics2D(gc)); 80 long endTime = System.currentTimeMillis() - startTime; 81 LOGGER.debug("redraw took = "+endTime+" ms!"); 82 } 83 84 88 public Rectangle2D getBounds(Control control) 89 { 90 return GeomUtil.toRectangle2D(control.getBounds()); 91 } 92 93 106 public static void paintDrawComponent(DrawComponent dc, Graphics2D g2d) 107 { 108 if (dc instanceof DrawComponentContainer) 109 { 110 if (dc instanceof Layer) 111 { 112 Layer l = (Layer) dc; 113 if (!l.isVisible()) 114 return; 115 } 116 DrawComponentContainer dcContainer = (DrawComponentContainer) dc; 117 for (Iterator it = dcContainer.getDrawComponents().iterator(); it.hasNext(); ) { 118 DrawComponent drawComponent = (DrawComponent) it.next(); 119 paintDrawComponent(drawComponent, g2d); 120 } 121 } 122 else { 123 Renderer r = dc.getRenderer(); 124 if (r != null) 125 r.paint(dc, g2d); 126 } 127 } 128 } 129 130 | Popular Tags |