Skip to main content



      Home
Home » Eclipse Projects » GEF » class Bitmap extends Figure
class Bitmap extends Figure [message #19200] Mon, 09 September 2002 19:11
Eclipse UserFriend
Randy,

If you like it, here's a submission you're welcome to incorporate into
Draw2d as long as you retain the @author line and license it under the
CPL. :-)

Dave


import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;

/**
* A Figure that displays an Image
* @author Dave Orme; http://www.asc-iseries.com
*/
public class Bitmap extends Figure {

/**
* Construct a Bitmap object - default constructor
*/
public Bitmap() {
}

/**
* Method Bitmap.-- Constructs a Bitmap object with the image
* it will display.
*
* @param image the Image to display
*/
public Bitmap(Image image) {
this.image = image;
}

private Image image = null;

/**
* Returns the image.
* @return Image
*/
public Image getImage() {
return image;
}

/**
* Sets the image.
* @param image The image to set
*/
public void setImage(Image image) {
this.image = image;
repaint();
}

/**
* @see org.eclipse.draw2d.Figure#getPreferredSize()
*/
public Dimension getPreferredSize() {
if (image != null) {
Rectangle rect = image.getBounds();
return new Dimension(rect.width, rect.height);
} else {
return new Dimension(0, 0);
}
}

/**
* @see org.eclipse.draw2d.Figure#paintClientArea(Graphics)
*/
protected void paintClientArea(Graphics g) {
g.drawImage(image, getLocation().x, getLocation().y);
}

}
Previous Topic:Labels with non rectangular borders
Next Topic:Draw2d: Drawing Image in Thumbnail yelds NullPointerException
Goto Forum:
  


Current Time: Thu Apr 24 23:15:37 EDT 2025

Powered by FUDForum. Page generated in 0.02489 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top