1 8 package com.nightlabs.editor2d.j2dswt; 9 10 import java.awt.Graphics2D ; 11 import java.awt.geom.Rectangle2D ; 12 import java.util.Iterator ; 13 14 import org.apache.log4j.Logger; 15 import org.eclipse.swt.graphics.GC; 16 import org.eclipse.swt.widgets.Control; 17 import org.holongate.j2d.IPaintable; 18 import org.holongate.j2d.J2DUtilities; 19 20 import com.nightlabs.editor2d.DrawComponent; 21 import com.nightlabs.editor2d.DrawComponentContainer; 22 import com.nightlabs.editor2d.render.Renderer; 23 24 public class DrawComponentPaintable 25 implements IPaintable 26 { 27 public static final Logger LOGGER = Logger.getLogger(DrawComponentPaintable.class.getName()); 28 29 protected DrawComponent dc; 30 public DrawComponentPaintable(DrawComponent dc) { 31 super(); 32 this.dc = dc; 33 } 34 35 public void paint(Control control, Graphics2D g2d) { 36 paintDrawComponent(dc, g2d); 37 LOGGER.debug("paint called !"); 38 } 39 40 public void redraw(Control control, GC gc) { 41 LOGGER.debug("redraw called !"); 42 } 43 44 public Rectangle2D getBounds(Control control) 45 { 46 return J2DUtilities.toRectangle2D(control.getBounds()); 47 } 48 49 protected void paintDrawComponent(DrawComponent dc, Graphics2D g2d) 50 { 51 if (dc instanceof DrawComponentContainer) { 52 DrawComponentContainer dcContainer = (DrawComponentContainer) dc; 53 for (Iterator it = dcContainer.getDrawComponents().iterator(); it.hasNext(); ) { 54 DrawComponent drawComponent = (DrawComponent) it.next(); 55 paintDrawComponent(drawComponent, g2d); 56 } 57 } 58 else { 59 Renderer r = dc.getRenderer(); 60 if (r != null) 61 r.paint(dc, g2d); 62 } 63 } 64 } 65 | Popular Tags |