1 27 28 package org.nightlabs.editor2d.figures; 29 30 import java.awt.geom.AffineTransform ; 31 import java.awt.image.BufferedImage ; 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 image) 45 { 46 super(); 47 this.bufferedImage = image; 48 } 49 50 protected AffineTransform at = new AffineTransform (); 51 52 protected BufferedImage bufferedImage; 53 public BufferedImage getBufferedImage() { 54 return bufferedImage; 55 } 56 public void setBufferedImage(BufferedImage 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 } 72 else { 73 j2d.drawString("NoImage", getBounds().getCenter()); 75 } 76 } 77 } 78 79 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 } 119 | Popular Tags |