org.eclipse.swt.graphics.ImageData Java Examples

The following examples show how to use org.eclipse.swt.graphics.ImageData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FXPaintUtils.java    From gef with Eclipse Public License 2.0 7 votes vote down vote up
/**
 * Creates a rectangular {@link Image} to visualize the given {@link Paint}.
 *
 * @param width
 *            The width of the resulting {@link Image}.
 * @param height
 *            The height of the resulting {@link Image}.
 * @param paint
 *            The {@link Paint} to use for filling the {@link Image}.
 * @return The resulting (filled) {@link Image}.
 */
public static ImageData getPaintImageData(int width, int height, Paint paint) {
	// use JavaFX canvas to render a rectangle with the given paint
	Canvas canvas = new Canvas(width, height);
	GraphicsContext graphicsContext = canvas.getGraphicsContext2D();
	graphicsContext.setFill(paint);
	graphicsContext.fillRect(0, 0, width, height);
	graphicsContext.setStroke(Color.BLACK);
	graphicsContext.strokeRect(0, 0, width, height);
	// handle transparent color separately (we want to differentiate it from
	// transparent fill)
	if (paint instanceof Color && ((Color) paint).getOpacity() == 0) {
		// draw a red line from bottom-left to top-right to indicate a
		// transparent fill color
		graphicsContext.setStroke(Color.RED);
		graphicsContext.strokeLine(0, height - 1, width, 1);
	}
	WritableImage snapshot = canvas.snapshot(new SnapshotParameters(), null);
	return SWTFXUtils.fromFXImage(snapshot, null);
}
 
Example #2
Source File: SWTUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts an AWT image to SWT.
 * 
 * @param image  the image (<code>null</code> not permitted).
 * 
 * @return Image data.
 */
public static ImageData convertAWTImageToSWT(Image image) {
    if (image == null) {
        throw new IllegalArgumentException("Null 'image' argument.");
    }
    int w = image.getWidth(null);
    int h = image.getHeight(null);
    if (w == -1 || h == -1) {
        return null;
    }
    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.dispose();
    return convertToSWT(bi);
}
 
Example #3
Source File: XYGraphToolbar.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void addSnapshotButton() {
	Button snapShotButton = new Button(XYGraphMediaFactory.getInstance().getImage("images/camera.png"));
	snapShotButton.setToolTip(new Label("Save Snapshot to PNG file"));
	addButton(snapShotButton);
	snapShotButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent event) {
			// Have valid name, so get image
			ImageLoader loader = new ImageLoader();
			Image image = xyGraph.getImage();
			loader.data = new ImageData[] { image.getImageData() };
			image.dispose();
			// Prompt for file name
			String path = SingleSourceHelper2.getImageSavePath();
			if (path == null || path.length() <= 0)
				return;
			// Assert *.png at end of file name
			if (!path.toLowerCase().endsWith(".png"))
				path = path + ".png";
			// Save
			loader.save(path, SWT.IMAGE_PNG);
		}
	});
}
 
Example #4
Source File: FollowThisPersonAction.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
public FollowThisPersonAction() {
  super(Messages.FollowThisPersonAction_follow_title);

  SarosPluginContext.initComponent(this);

  setImageDescriptor(
      new ImageDescriptor() {
        @Override
        public ImageData getImageData() {
          return ImageManager.ICON_USER_SAROS_FOLLOWMODE.getImageData();
        }
      });

  setToolTipText(Messages.FollowThisPersonAction_follow_tooltip);
  setId(ACTION_ID);

  sessionManager.addSessionLifecycleListener(sessionLifecycleListener);
  SelectionUtils.getSelectionService().addSelectionListener(selectionListener);

  updateEnablement();
}
 
Example #5
Source File: URLImageLabel.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
private void processLoad ( final String stringUrl ) throws Exception
{
    final ImageLoader loader = new ImageLoader ();

    final URL url = new URL ( stringUrl );

    final ImageData[] data;
    try ( InputStream is = url.openStream () )
    {
        data = loader.load ( is );
    }

    logger.debug ( "Image loaded" );

    Display.getDefault ().asyncExec ( new Runnable () {
        @Override
        public void run ()
        {
            showImage ( stringUrl, data );
        }
    } );
}
 
Example #6
Source File: JavaElementImageDescriptor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void drawCompositeImage(int width, int height) {
	ImageData bg= getImageData(fBaseImage);

	if ((fFlags & DEPRECATED) != 0) { // draw *behind* the full image
		Point size= getSize();
		ImageData data= getImageData(JavaPluginImages.DESC_OVR_DEPRECATED);
		drawImage(data, 0, size.y - data.height);
	}
	drawImage(bg, 0, 0);

	drawTopRight();
	drawBottomRight();
	drawBottomLeft();


}
 
Example #7
Source File: SDPrintDialogUI.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Draws region that was selected
 *
 * @param img
 *            The corresponding image
 * @param r
 *            The selected rectangle.
 * @param color
 *            The color to use for selection
 * @return image data reference
 */
public ImageData drawRegionSelected(Image img, Rectangle r, RGB color) {
    ImageData id = img.getImageData();
    for (int a = 0; a < r.width && r.x + a < id.width; a++) {
        for (int b = 0; b < r.height && r.y + b < id.height; b++) {
            int index = id.getPixel(r.x + a, r.y + b);
            RGB rgb = id.palette.getRGB(index);
            rgb = combine(color, rgb);
            id.setPixel(r.x + a, r.y + b, id.palette.getPixel(rgb));
        }
    }
    return id;
}
 
Example #8
Source File: ExportToImageManager.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
private void writePNGorGIF(Image image, String saveFilePath,
		String formatName) throws IOException, InterruptedException {

	try {
		ImageLoader loader = new ImageLoader();
		loader.data = new ImageData[] { image.getImageData() };
		loader.save(saveFilePath, format);

	} catch (SWTException e) {
		// Eclipse 3.2 �ł́A PNG �� Unsupported or unrecognized format �ƂȂ邽�߁A
		// �ȉ��̑�֕��@���g�p����
		// �������A���̕��@�ł͏�肭�o�͂ł��Ȃ��‹�����

		e.printStackTrace();
		BufferedImage bufferedImage = new BufferedImage(
				image.getBounds().width, image.getBounds().height,
				BufferedImage.TYPE_INT_RGB);

		drawAtBufferedImage(bufferedImage, image, 0, 0);

		ImageIO.write(bufferedImage, formatName, new File(saveFilePath));
	}
}
 
Example #9
Source File: ExportToFileAction.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void run() {
	IFigure contents = railroadView.getContents();
	if (contents != null) {
		FileDialog fileDialog = new FileDialog(this.railroadView.getSite().getShell(), SWT.SAVE);
		fileDialog.setFilterExtensions(new String[] { "*.png" });
		fileDialog.setText("Choose diagram file");
		String fileName = fileDialog.open();
		if (fileName == null) {
			return;
		}
		Dimension preferredSize = contents.getPreferredSize();
		Image image = new Image(Display.getDefault(), preferredSize.width + 2 * PADDING, preferredSize.height + 2
				* PADDING);
		GC gc = new GC(image);
		SWTGraphics graphics = new SWTGraphics(gc);
		graphics.translate(PADDING, PADDING);
		graphics.translate(contents.getBounds().getLocation().getNegated());
		contents.paint(graphics);
		ImageData imageData = image.getImageData();
		ImageLoader imageLoader = new ImageLoader();
		imageLoader.data = new ImageData[] { imageData };
		imageLoader.save(fileName, SWT.IMAGE_PNG);
	}
}
 
Example #10
Source File: VButtonImageBak.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public void handleEvent(Event e) {
	GC gc = new GC(b);
	Image image = new Image(b.getDisplay(), e.width, e.height);
	gc.copyArea(image, 0, 0);
	ImageData data = image.getImageData();
	gc.dispose();
	image.dispose();
	images.put(key, data);
	keys.put(data, key);
	if(requests.containsKey(key)) {
		for(Iterator<VButton> iter = requests.get(key).iterator(); iter.hasNext();) {
			iter.next().redraw();
			iter.remove();
		}
		requests.remove(key);
	}
	Display.getDefault().asyncExec(new Runnable() {
		public void run() {
			if(!b.isDisposed() && b == b.getDisplay().getFocusControl()) {
				b.getParent().forceFocus();
			}
			b.dispose();
		}
	});
}
 
Example #11
Source File: InsertedImageEditPart.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected IFigure createFigure() {
	InsertedImage model = (InsertedImage) this.getModel();

	byte[] data = Base64.decodeBase64((model.getBase64EncodedData()
			.getBytes()));
	ByteArrayInputStream in = new ByteArrayInputStream(data);

	this.imageData = new ImageData(in);
	this.changeImage();

	InsertedImageFigure figure = new InsertedImageFigure(this.image, model
			.isFixAspectRatio(), model.getAlpha());
	figure.setMinimumSize(new Dimension(1, 1));

	return figure;
}
 
Example #12
Source File: SimpleToolBarEx.java    From SWET with MIT License 5 votes vote down vote up
protected static Image getImage(InputStream stream) throws IOException {
	try {
		Display display = Display.getCurrent();
		ImageData data = new ImageData(stream);
		if (data.transparentPixel > 0) {
			return new Image(display, data, data.getTransparencyMask());
		}
		return new Image(display, data);
	} finally {
		stream.close();
	}
}
 
Example #13
Source File: FXPaintSelectionDialog.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Re-renders the image that visualizes the currently selected {@link Paint}
 * .
 */
protected void updateImageLabel() {
	if (optionsCombo != null && imageLabel != null && paint != null) {
		ImageData imageData = FXPaintUtils.getPaintImageData(64, optionsCombo.getItemHeight() - 1, paint);
		imageLabel.setImage(new Image(imageLabel.getDisplay(), imageData, imageData.getTransparencyMask()));
	}
}
 
Example #14
Source File: FXCanvasEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void changed(ObservableValue<? extends Cursor> observable,
		Cursor oldCursor, Cursor newCursor) {
	if (newCursor instanceof ImageCursor) {
		// custom cursor, convert image
		ImageData imageData = SWTFXUtils.fromFXImage(
				((ImageCursor) newCursor).getImage(), null);
		double hotspotX = ((ImageCursor) newCursor).getHotspotX();
		double hotspotY = ((ImageCursor) newCursor).getHotspotY();
		org.eclipse.swt.graphics.Cursor swtCursor = new org.eclipse.swt.graphics.Cursor(
				getDisplay(), imageData, (int) hotspotX,
				(int) hotspotY);
		try {
			Method currentCursorFrameAccessor = Cursor.class
					.getDeclaredMethod("getCurrentFrame",
							new Class[] {});
			currentCursorFrameAccessor.setAccessible(true);
			Object currentCursorFrame = currentCursorFrameAccessor
					.invoke(newCursor, new Object[] {});
			// there is a spelling-mistake in the internal API
			// (setPlatformCursor -> setPlatforCursor)
			Method platformCursorProvider = currentCursorFrame
					.getClass().getMethod("setPlatforCursor",
							new Class[] { Class.class, Object.class });
			platformCursorProvider.setAccessible(true);
			platformCursorProvider.invoke(currentCursorFrame,
					org.eclipse.swt.graphics.Cursor.class, swtCursor);
		} catch (Exception e) {
			System.err.println(
					"Failed to set platform cursor on the current cursor frame.");
			e.printStackTrace();
		}
	}
}
 
Example #15
Source File: ImportProjectWizardPage2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Image getImage(Object element) {
	if (element instanceof ProjectResource) {
		ProjectResource proResource = (ProjectResource) element;
		String fileName = proResource.getLabel();
		if (proResource.isProject()) {
			return projectImg;
		}else if (proResource.isFolder()) {
			return folderImg;
		}else if (fileName.endsWith(".hsxliff")) {
			return hsXLiffImg;
		}else if (fileName.endsWith(".html")) {
			return htmlImg;
		}else {
			int index = fileName.lastIndexOf(".");
			if (index != -1) {
				String extension = fileName.substring(index, fileName.length());
				if (imgMap.containsKey(extension)) {
					return imgMap.get(extension);
				}
				Program program = Program.findProgram(extension);
				if (program != null) {
					ImageData imageData = program.getImageData();
					if (imageData != null) {
						Image img = new Image(getShell().getDisplay(), imageData);
						imgMap.put(extension, img);
						return img;
					}
				}
			}
		}
	}
	return defaultImg;
}
 
Example #16
Source File: SliceRequest.java    From dawnsci with Eclipse Public License 1.0 5 votes vote down vote up
private void sendImage(IDataset            data, 
					   HttpServletRequest  request,
		               HttpServletResponse response, 
		               Format              format) throws Exception {
	
	data.squeeze();
	
	if (data.getRank()!=2 && data.getRank()!=1) {
		throw new Exception("The data used to make an image must either be 1D or 2D!"); 
	}
		
	response.setContentType("image/jpeg");
	response.setStatus(HttpServletResponse.SC_OK);

	ImageServiceBean bean = createImageServiceBean();
	bean.setImage(data);
	
	// Override histo if they set it.
	String histo = decode(request.getParameter("histo"));
	if (histo!=null) bean.decode(histo);

	IImageService service = ServiceHolder.getImageService();

	if (service == null) {
		throw new NullPointerException("Image service not set");
	}

	final ImageData    imdata = service.getImageData(bean);
	final BufferedImage image = service.getBufferedImage(imdata);
	
	ImageIO.write(image, format.getImageIOString(), response.getOutputStream());
}
 
Example #17
Source File: LibraryImageDescriptor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void drawCompositeImage( int width, int height )
{
	ImageData bg = fBaseImage.getImageData( );
	
	drawImage( bg, 0, 0 );
	Point pos = new Point( getSize( ).y, getSize( ).y );
	ImageData data = fDecoratorImage.getImageData( );
	addLeftBottomImage( data, pos );
}
 
Example #18
Source File: FXPaintLabelProvider.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Image getImage(Object element) {
	disposeImage();
	ImageData imageData = FXPaintUtils.getPaintImageData(32, 12,
			(Paint) element);
	image = new Image(Display.getCurrent(), imageData);
	return image;
}
 
Example #19
Source File: SWTGraphics2D.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws an image with the top left corner aligned to the point (x, y).
 *
 * @param image  the image.
 * @param x  the x-coordinate.
 * @param y  the y-coordinate.
 * @param observer  ignored here.
 *
 * @return <code>true</code> if the image has been drawn.
 */
public boolean drawImage(Image image, int x, int y,
        ImageObserver observer) {
    ImageData data = SWTUtils.convertAWTImageToSWT(image);
    if (data == null) {
        return false;
    }
    org.eclipse.swt.graphics.Image im = new org.eclipse.swt.graphics.Image(
            this.gc.getDevice(), data);
    this.gc.drawImage(im, x, y);
    im.dispose();
    return true;
}
 
Example #20
Source File: CallHierarchyImageDescriptor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void drawBottomLeft() {
    Point size= getSize();
    int x= 0;
    ImageData data= null;
    if ((fFlags & RECURSIVE) != 0) {
        data= getImageData(JavaPluginImages.DESC_OVR_RECURSIVE);
        drawImage(data, x, size.y - data.height);
        x+= data.width;
    }
    if ((fFlags & MAX_LEVEL) != 0) {
        data= getImageData(JavaPluginImages.DESC_OVR_MAX_LEVEL);
        drawImage(data, x, size.y - data.height);
        x+= data.width;
    }
}
 
Example #21
Source File: OverlayImageIcon.java    From jbt with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.jface.resource.CompositeImageDescriptor#drawCompositeImage(int,
 *      int) DrawCompositeImage is called to draw the composite image.
 * 
 */
protected void drawCompositeImage(int arg0, int arg1) {
	// Draw the base image
	drawImage(baseImage.getImageData(), 0, 0);
	ImageData imageData = decoration.getImageData();

	// Draw on bottom right corner
	drawImage(imageData, sizeOfImage.x - imageData.width, sizeOfImage.y - imageData.height);
}
 
Example #22
Source File: ImagesOnFileSystemRegistry.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public URL getImageURL(ImageDescriptor descriptor) {
	if (fTempDir == null)
		return null;

	URL url= fURLMap.get(descriptor);
	if (url != null)
		return url;

	File imageFile= getNewFile();
	ImageData imageData= descriptor.getImageData();
	if (imageData == null) {
		return null;
	}

	ImageLoader loader= new ImageLoader();
	loader.data= new ImageData[] { imageData };
	loader.save(imageFile.getAbsolutePath(), SWT.IMAGE_PNG);

	try {
		url= imageFile.toURI().toURL();
		fURLMap.put(descriptor, url);
		return url;
	} catch (MalformedURLException e) {
		JavaPlugin.log(e);
	}
	return null;
}
 
Example #23
Source File: URLImageLabel.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected void showImage ( final String url, final ImageData[] data )
{
    if ( isDisposed () || getDisplay ().isDisposed () )
    {
        return;
    }

    if ( data == null || data.length <= 0 )
    {
        logger.info ( "No image data" );
        return;
    }

    synchronized ( this )
    {
        if ( url.equals ( this.currentUrl ) )
        {
            if ( this.currentImage != null )
            {
                this.currentImage.dispose ();
            }
            this.currentImage = new Image ( getDisplay (), data[0] );
            this.label.setImage ( this.currentImage );
        }
        else
        {
            logger.warn ( "Image url changed - current: {}, our: {}", this.currentUrl, url );
        }
    }
}
 
Example #24
Source File: ImageRenderer.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Masks the corners of a rounded rectangle with a specified alpha value.
 * 
 * @param imageData
 * @param bounds
 * @param corner
 * @param alphaValue
 * @return The manipulated image data that is the same instance that is
 *         specified by the parameter {@link #imageData}.
 */
public ImageData maskAlphaAsRoundedrectangle(ImageData imageData,
		Dimension corner, int alphaValue) {

	byte[] alphaData = imageData.alphaData;
	int width = imageData.width;
	int height = imageData.height;
	int r = corner.width / 2;
	double r_square = r * r;
	byte[] alphaPixel = new byte[r];
	Arrays.fill(alphaPixel, (byte) alphaValue);

	// make sure that the corner radius is smaller than the image dimensions
	// and make it smaller if necessary
	r = Math.min(r, Math.min(imageData.height, imageData.width) / 2);

	for (int i = 0; i < r; i++) {
		// calculate pixel
		int p = r - (int) Math.sqrt(r_square - (double) ((i) * (i)));
		// mask corners ...
		if (p > 0) {
			System.arraycopy(alphaPixel, 0, alphaData, (r - (i + 1))
					* width, p);
			System.arraycopy(alphaPixel, 0, alphaData, (r - (i + 1))
					* width + (width - p), p);
			System.arraycopy(alphaPixel, 0, alphaData,
					((height - (r - (i)))) * width, p);
			System.arraycopy(alphaPixel, 0, alphaData,
					((height - (r - (i)))) * width + (width - p), p);
		}
	}

	return imageData;
}
 
Example #25
Source File: MissingDependenciesDecorator.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected Image getErrorDecoratedImage(Image image) {
	if(errorIcon == null){
		errorIcon =  new DecorationOverlayIcon(image,new ImageDescriptor() {
			
			@Override
			public ImageData getImageData() {
				return errorDecoratorImage.getImageData();
			}
		} , IDecoration.BOTTOM_RIGHT).createImage() ;
	}
	return errorIcon;
}
 
Example #26
Source File: NaturesLabelProvider.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected void drawTopRight(ImageDescriptor overlay)
{
	if (overlay == null)
	{
		return;
	}
	int x = getSize().x / 2;
	int y = getSize().y / 2;
	ImageData id = overlay.getImageData();
	x -= id.width / 2;
	y -= id.height / 2;
	drawImage(id, x, y);
}
 
Example #27
Source File: SankeyImageAction.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void run() {
	try {
		ImageLoader imgLoader = new ImageLoader();
		imgLoader.data = new ImageData[] { image.getImageData() };
		imgLoader.save(file.getAbsolutePath(), SWT.IMAGE_PNG);
	} catch (Exception e) {
		log.error("Failed to write image", e);
	}
}
 
Example #28
Source File: PaperClipsExample.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Executes the PaperClips example.
 * 
 * @param args
 *            the command line arguments.
 */
public static void main(String[] args) {
	GridPrint grid = new GridPrint("p, d, c:d:g, 72", new DefaultGridLook(
			5, 5));

	// Now add some items to the grid
	grid.add(new ImagePrint(new ImageData(PaperClipsExample.class
			.getResourceAsStream("logo.png")), new Point(300, 300))); // (The
	// point
	// indicates
	// DPI)
	grid.add(new TextPrint("Column 2 will shrink if space is scarce."));
	grid
			.add(new TextPrint(
					"Column 3 will shrink too, and it also grows to fill excess page width."));
	grid.add(new TextPrint(
			"Column 4 will be 1\" wide (72 points) wide no matter what."));
	grid.add(new TextPrint("This is in column 1 on the 2nd row"));
	grid.add(new TextPrint("Often is it useful for a document element "
			+ "to span several cells in a grid."), 3);
	grid.add(SWT.RIGHT, new TextPrint(
			"And sometimes you may want to override the "
					+ "default alignment", SWT.RIGHT), 4);
	grid
			.add(
					new TextPrint(
							"A handy shorthand for 'the rest of the row' is "
									+ "to use GridPrint.REMAINDER as the colSpan argument."),
					GridPrint.REMAINDER);

	// Workaround for SWT bug on GTK - force SWT to initialize so we don't
	// crash.
	Display.getDefault();

	// When the document is ready to go, pass it to the
	// PrintUtil.print(Print)
	// method.
	PaperClips.print(new PrintJob("PaperClipsExample.java", grid),
			new PrinterData());
}
 
Example #29
Source File: Activator.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 提供一个图片文件对插件的相对路径,返回该图片被伸缩变换为16*16像素的描述信息。
 * @param path
 *            the path
 * @return the icon descriptor
 */
public static ImageDescriptor getIconDescriptor(String path) {
	ImageDescriptor image = getImageDescriptor(path);
	ImageData data = image.getImageData();
	data = data.scaledTo(16, 16);
	image = ImageDescriptor.createFromImageData(data);
	return image;
}
 
Example #30
Source File: SWTGraphics2D.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws an image with the top left corner aligned to the point (x, y),
 * and scaled to the specified width and height.
 *
 * @param image  the image.
 * @param x  the x-coordinate.
 * @param y  the y-coordinate.
 * @param width  the width for the rendered image.
 * @param height  the height for the rendered image.
 * @param observer  ignored here.
 *
 * @return <code>true</code> if the image has been drawn.
 */
public boolean drawImage(Image image, int x, int y, int width, int height,
        ImageObserver observer) {
    ImageData data = SWTUtils.convertAWTImageToSWT(image);
    if (data == null) {
        return false;
    }
    org.eclipse.swt.graphics.Image im = new org.eclipse.swt.graphics.Image(
            this.gc.getDevice(), data);
    org.eclipse.swt.graphics.Rectangle bounds = im.getBounds();
    this.gc.drawImage(im, 0, 0, bounds.width, bounds.height, x, y, width,
            height);
    im.dispose();
    return true;
}