class Bitmap extends Figure [message #19200] |
Mon, 09 September 2002 19:11 |
Eclipse User |
|
|
|
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);
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.02489 seconds