1 8 package com.nightlabs.editor2d.figures; 9 10 import java.awt.geom.AffineTransform ; 11 import java.awt.image.BufferedImage ; 12 13 import org.apache.log4j.Logger; 14 import org.eclipse.draw2d.Figure; 15 import org.eclipse.draw2d.Graphics; 16 import org.eclipse.draw2d.J2DGraphics; 17 import org.eclipse.draw2d.geometry.Rectangle; 18 19 public class ImageFigure 20 extends Figure 21 { 22 public static final Logger LOGGER = Logger.getLogger(ImageFigure.class); 23 24 public ImageFigure(BufferedImage image) 25 { 26 super(); 27 this.bufferedImage = image; 28 } 29 30 protected AffineTransform at = new AffineTransform (); 31 32 protected BufferedImage bufferedImage; 33 public BufferedImage getBufferedImage() { 34 return bufferedImage; 35 } 36 public void setBufferedImage(BufferedImage image) { 37 this.bufferedImage = image; 38 bounds = null; 39 } 40 41 protected J2DGraphics j2d; 42 protected void paintFigure(Graphics graphics) 43 { 44 if (graphics instanceof J2DGraphics) 45 { 46 j2d = (J2DGraphics) graphics; 47 if (bufferedImage != null) { 48 } 52 else { 53 j2d.drawString("NoImage", getBounds().getCenter()); 55 } 56 } 57 } 58 59 protected Rectangle bounds; 61 public Rectangle getBounds() 62 { 63 if (bounds == null) 64 { 65 if (bufferedImage != null) 66 bounds = new Rectangle(super.getBounds().x, super.getBounds().y, bufferedImage.getWidth(), bufferedImage.getHeight()); 67 else 68 return super.getBounds(); 69 } 70 return bounds; 71 } 72 73 public void setBounds(Rectangle rect) 74 { 75 super.setBounds(rect); 76 bounds = null; 77 } 78 79 } 99 | Popular Tags |