1 27 28 package org.nightlabs.editor2d.j2dswt; 29 30 import java.awt.Graphics2D ; 31 import java.awt.geom.Rectangle2D ; 32 import java.util.Iterator ; 33 34 import org.apache.log4j.Logger; 35 import org.eclipse.swt.graphics.GC; 36 import org.eclipse.swt.widgets.Control; 37 import org.holongate.j2d.IPaintable; 38 import org.holongate.j2d.J2DUtilities; 39 40 import org.nightlabs.editor2d.DrawComponent; 41 import org.nightlabs.editor2d.DrawComponentContainer; 42 import org.nightlabs.editor2d.render.Renderer; 43 44 public class DrawComponentPaintable 45 implements IPaintable 46 { 47 public static final Logger LOGGER = Logger.getLogger(DrawComponentPaintable.class.getName()); 48 49 protected DrawComponent dc; 50 public DrawComponentPaintable(DrawComponent dc) { 51 super(); 52 this.dc = dc; 53 } 54 55 public void paint(Control control, Graphics2D g2d) { 56 paintDrawComponent(dc, g2d); 57 LOGGER.debug("paint called !"); 58 } 59 60 public void redraw(Control control, GC gc) { 61 } 63 64 public Rectangle2D getBounds(Control control) 65 { 66 return J2DUtilities.toRectangle2D(control.getBounds()); 67 } 68 69 protected void paintDrawComponent(DrawComponent dc, Graphics2D g2d) 70 { 71 if (dc instanceof DrawComponentContainer) { 72 DrawComponentContainer dcContainer = (DrawComponentContainer) dc; 73 for (Iterator it = dcContainer.getDrawComponents().iterator(); it.hasNext(); ) { 74 DrawComponent drawComponent = (DrawComponent) it.next(); 75 paintDrawComponent(drawComponent, g2d); 76 } 77 } 78 else { 79 Renderer r = dc.getRenderer(); 80 if (r != null) 81 r.paint(dc, g2d); 82 } 83 } 84 } 85 | Popular Tags |