KickJava   Java API By Example, From Geeks To Geeks.

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


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.apache.log4j.Logger;
35 import org.eclipse.swt.graphics.GC;
36 import org.eclipse.swt.widgets.Control;
37 import org.holongate.j2d.IPaintable;
38 import org.holongate.j2d.J2DUtilities;
39
40 import org.nightlabs.editor2d.DrawComponent;
41 import org.nightlabs.editor2d.DrawComponentContainer;
42 import org.nightlabs.editor2d.render.Renderer;
43
44 public class DrawComponentPaintable
45 implements IPaintable
46 {
47     public static final Logger LOGGER = Logger.getLogger(DrawComponentPaintable.class.getName());
48     
49     protected DrawComponent dc;
50     public DrawComponentPaintable(DrawComponent dc) {
51         super();
52         this.dc = dc;
53     }
54
55     public void paint(Control control, Graphics2D JavaDoc g2d) {
56         paintDrawComponent(dc, g2d);
57         LOGGER.debug("paint called !");
58     }
59
60     public void redraw(Control control, GC gc) {
61 // LOGGER.debug("redraw called !");
62
}
63
64     public Rectangle2D JavaDoc getBounds(Control control)
65     {
66         return J2DUtilities.toRectangle2D(control.getBounds());
67     }
68
69     protected void paintDrawComponent(DrawComponent dc, Graphics2D JavaDoc g2d)
70     {
71         if (dc instanceof DrawComponentContainer) {
72             DrawComponentContainer dcContainer = (DrawComponentContainer) dc;
73             for (Iterator JavaDoc it = dcContainer.getDrawComponents().iterator(); it.hasNext(); ) {
74                 DrawComponent drawComponent = (DrawComponent) it.next();
75                 paintDrawComponent(drawComponent, g2d);
76             }
77         }
78         else {
79             Renderer r = dc.getRenderer();
80             if (r != null)
81                 r.paint(dc, g2d);
82         }
83     }
84 }
85
Popular Tags