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.eclipse.swt.graphics.GC; 15 import org.eclipse.swt.widgets.Control; 16 import org.holongate.j2d.IPaintable; 17 import org.holongate.j2d.J2DUtilities; 18 19 import com.nightlabs.editor2d.DrawComponent; 20 import com.nightlabs.editor2d.DrawComponentContainer; 21 import com.nightlabs.editor2d.MultiLayerDrawComponent; 22 import com.nightlabs.editor2d.render.Renderer; 23 24 public class MLDCPaintable implements IPaintable 25 { 26 protected MultiLayerDrawComponent mldc; 27 public MLDCPaintable(MultiLayerDrawComponent mldc) 28 { 29 this.mldc = mldc; 30 } 31 32 public void paint(Control control, Graphics2D g2d) 45 { 46 for (Iterator itLayers = mldc.getDrawComponents().iterator(); itLayers.hasNext(); ) { 47 DrawComponent dc = (DrawComponent) itLayers.next(); 48 paintDrawComponent(dc, g2d); 49 } 50 } 51 52 protected void paintDrawComponent(DrawComponent dc, Graphics2D g2d) 53 { 54 if (dc instanceof DrawComponentContainer) { 55 DrawComponentContainer dcContainer = (DrawComponentContainer) dc; 56 for (Iterator it = dcContainer.getDrawComponents().iterator(); it.hasNext(); ) { 57 DrawComponent drawComponent = (DrawComponent) it.next(); 58 paintDrawComponent(drawComponent, g2d); 59 } 60 } 61 else { 62 Renderer r = dc.getRenderer(); 63 if (r != null) 64 r.paint(dc, g2d); 65 } 66 } 67 68 public void redraw(Control control, GC gc) 69 { 70 } 72 73 public Rectangle2D getBounds(Control control) 74 { 75 return J2DUtilities.toRectangle2D(control.getBounds()); 76 } 77 } 78 | Popular Tags |