KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > editor2d > j2dswt > MLDCPaintable


1 /**
2  * <p> Project: com.nightlabs.editor2d </p>
3  * <p> Copyright: Copyright (c) 2005 </p>
4  * <p> Company: NightLabs GmbH (Germany) </p>
5  * <p> Creation Date: 15.06.2005 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

8 package com.nightlabs.editor2d.j2dswt;
9
10 import java.awt.Graphics2D JavaDoc;
11 import java.awt.geom.Rectangle2D JavaDoc;
12 import java.util.Iterator JavaDoc;
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)
33
// {
34
// for (Iterator itLayers = mldc.getDrawComponents().iterator(); itLayers.hasNext(); ) {
35
// Layer l = (Layer) itLayers.next();
36
// for (Iterator it = l.getDrawComponents().iterator(); it.hasNext(); ) {
37
// DrawComponent dc = (DrawComponent) it.next();
38
// Renderer r = dc.getRenderer();
39
// if (r != null)
40
// r.paint(dc, g2d);
41
// }
42
// }
43
// }
44
public void paint(Control control, Graphics2D JavaDoc g2d)
45     {
46         for (Iterator JavaDoc 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 JavaDoc g2d)
53     {
54         if (dc instanceof DrawComponentContainer) {
55             DrawComponentContainer dcContainer = (DrawComponentContainer) dc;
56             for (Iterator JavaDoc 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         // TODO Auto-generated method stub
71
}
72
73     public Rectangle2D JavaDoc getBounds(Control control)
74     {
75         return J2DUtilities.toRectangle2D(control.getBounds());
76     }
77 }
78
Popular Tags