KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > figures > ImageFigure


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.figures;
29
30 import java.awt.geom.AffineTransform JavaDoc;
31 import java.awt.image.BufferedImage JavaDoc;
32
33 import org.apache.log4j.Logger;
34 import org.eclipse.draw2d.Figure;
35 import org.eclipse.draw2d.Graphics;
36 import org.eclipse.draw2d.J2DGraphics;
37 import org.eclipse.draw2d.geometry.Rectangle;
38
39 public class ImageFigure
40 extends Figure
41 {
42   public static final Logger LOGGER = Logger.getLogger(ImageFigure.class);
43   
44   public ImageFigure(BufferedImage JavaDoc image)
45   {
46     super();
47     this.bufferedImage = image;
48   }
49   
50   protected AffineTransform JavaDoc at = new AffineTransform JavaDoc();
51   
52   protected BufferedImage JavaDoc bufferedImage;
53   public BufferedImage JavaDoc getBufferedImage() {
54     return bufferedImage;
55   }
56   public void setBufferedImage(BufferedImage JavaDoc image) {
57     this.bufferedImage = image;
58     bounds = null;
59   }
60     
61   protected J2DGraphics j2d;
62   protected void paintFigure(Graphics graphics)
63   {
64     if (graphics instanceof J2DGraphics)
65     {
66       j2d = (J2DGraphics) graphics;
67       if (bufferedImage != null) {
68 // j2d.drawImage(bufferedImage, getBounds().x, getBounds().y, bufferedImage.getWidth(), bufferedImage.getHeight(), null);
69
// j2d.drawImage(bufferedImage, getImageBounds().x, getImageBounds().y, bufferedImage.getWidth(), bufferedImage.getHeight(), null);
70
// j2d.drawImage(bufferedImage, at, null);
71
}
72       else {
73         // TODO: add noImage Image as default
74
j2d.drawString("NoImage", getBounds().getCenter());
75       }
76     }
77   }
78   
79   // TODO: Maybe rename rectangle bounds, because it overrides Figure.bounds
80
protected Rectangle bounds;
81   public Rectangle getBounds()
82   {
83     if (bounds == null)
84     {
85       if (bufferedImage != null)
86         bounds = new Rectangle(super.getBounds().x, super.getBounds().y, bufferedImage.getWidth(), bufferedImage.getHeight());
87       else
88         return super.getBounds();
89     }
90     return bounds;
91   }
92   
93   public void setBounds(Rectangle rect)
94   {
95     super.setBounds(rect);
96     bounds = null;
97   }
98     
99 // public void transform(AffineTransform at)
100
// {
101
// AffineTransformOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
102
// bufferedImage = op.filter(bufferedImage, null);
103
// }
104
//
105
// public void performScale(double factor)
106
// {
107
// AffineTransform transform = new AffineTransform();
108
// transform.scale(factor, factor);
109
// transform(transform);
110
// }
111
//
112
// public void performTranslate(int dx, int dy)
113
// {
114
// AffineTransform transform = new AffineTransform();
115
// transform.translate(dx, dy);
116
// transform(transform);
117
// }
118
}
119
Popular Tags