KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * Project author: Daniel Mazurek <Daniel.Mazurek [at] nightlabs [dot] org> *
5  * *
6  * This library is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin St, Fifth Floor, *
20  * Boston, MA 02110-1301 USA *
21  * *
22  * Or get it online : *
23  * http://www.gnu.org/copyleft/lesser.html *
24  * *
25  * *
26  ******************************************************************************/

27
28 package org.nightlabs.editor2d.j2dswt;
29
30 import java.awt.Graphics2D JavaDoc;
31 import java.awt.geom.Rectangle2D JavaDoc;
32 import java.util.Iterator JavaDoc;
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)
53
// {
54
// for (Iterator itLayers = mldc.getDrawComponents().iterator(); itLayers.hasNext(); ) {
55
// Layer l = (Layer) itLayers.next();
56
// for (Iterator it = l.getDrawComponents().iterator(); it.hasNext(); ) {
57
// DrawComponent dc = (DrawComponent) it.next();
58
// Renderer r = dc.getRenderer();
59
// if (r != null)
60
// r.paint(dc, g2d);
61
// }
62
// }
63
// }
64
public void paint(Control control, Graphics2D JavaDoc g2d)
65     {
66         for (Iterator JavaDoc 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 JavaDoc g2d)
73     {
74         if (dc instanceof DrawComponentContainer) {
75             DrawComponentContainer dcContainer = (DrawComponentContainer) dc;
76             for (Iterator JavaDoc 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 JavaDoc getBounds(Control control)
94     {
95         return J2DUtilities.toRectangle2D(control.getBounds());
96     }
97 }
98
Popular Tags