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.eclipse.swt.graphics.GC; 35 import org.eclipse.swt.widgets.Control; 36 import org.holongate.j2d.IPaintable; 37 import org.holongate.j2d.J2DUtilities; 38 39 import org.nightlabs.editor2d.DrawComponent; 40 import org.nightlabs.editor2d.DrawComponentContainer; 41 import org.nightlabs.editor2d.MultiLayerDrawComponent; 42 import org.nightlabs.editor2d.render.Renderer; 43 44 public class MLDCPaintable implements IPaintable 45 { 46 protected MultiLayerDrawComponent mldc; 47 public MLDCPaintable(MultiLayerDrawComponent mldc) 48 { 49 this.mldc = mldc; 50 } 51 52 public void paint(Control control, Graphics2D g2d) 65 { 66 for (Iterator itLayers = mldc.getDrawComponents().iterator(); itLayers.hasNext(); ) { 67 DrawComponent dc = (DrawComponent) itLayers.next(); 68 paintDrawComponent(dc, g2d); 69 } 70 } 71 72 protected void paintDrawComponent(DrawComponent dc, Graphics2D g2d) 73 { 74 if (dc instanceof DrawComponentContainer) { 75 DrawComponentContainer dcContainer = (DrawComponentContainer) dc; 76 for (Iterator it = dcContainer.getDrawComponents().iterator(); it.hasNext(); ) { 77 DrawComponent drawComponent = (DrawComponent) it.next(); 78 paintDrawComponent(drawComponent, g2d); 79 } 80 } 81 else { 82 Renderer r = dc.getRenderer(); 83 if (r != null) 84 r.paint(dc, g2d); 85 } 86 } 87 88 public void redraw(Control control, GC gc) 89 { 90 91 } 92 93 public Rectangle2D getBounds(Control control) 94 { 95 return J2DUtilities.toRectangle2D(control.getBounds()); 96 } 97 } 98 | Popular Tags |