Dragging and dropping an image on a composite.

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Dragging and dropping an image on a composite.

Postby Sebastien » Fri Jul 29, 2005 10:08 am

Reading the object of this post should tell you what I wish for :D ! I’m still rather unfamiliar with SWT. It took me a bit of reading before I got the company logo in my JFace Window acting as a splash. This is how my code looks like after research on the web:

final Canvas canvas = new Canvas(composite,0);
canvas.addPaintListener(new PaintListener(){
public void paintControl(PaintEvent e){
GC gc = e.gc;
gc.drawImage(logo,0,0,logo.getBounds().width,logo.getBounds().height,0,0,150,200);
}
});

Using SWT Designer, I perused through the Canvas’ properties looking for a way to stick an image into it but found nothing. Is there a simple way to drag and drop an image onto a composite (or canvas) with SWT Designer or must I alway open the source each time ?

Thank you
Sebastien
Sebastien
Sebastien
 
Posts: 16
Joined: Thu Jun 02, 2005 12:18 pm
Location: Canada

Re: Dragging and dropping an image on a composite.

Postby Eric Clayberg » Mon Aug 01, 2005 6:09 pm

Sebastien wrote:Using SWT Designer, I perused through the Canvas’ properties looking for a way to stick an image into it but found nothing. Is there a simple way to drag and drop an image onto a composite (or canvas) with SWT Designer or must I alway open the source each time ?

The Canvas widget doesn't support options like that.

Why not use a simple Label widget with an image instead?
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Dragging and dropping an image on a composite.

Postby Sebastien » Wed Aug 10, 2005 4:57 am

I tried the idea with the Label. It's simpler then with my previous code but the image doesn't resize to the label's size. Whatever the label's size, the image always keeps it's original size.

With my previous Canvas example, I couldn't drag and drop just as easily with Label an image on my Composite. But now I'm back to the starting line because I will have to programmatically resize my Image object within the Label.

If Labels or Canvas are the way to go to insert images onto Composites, then basic Image manipulation should be available within Designer. Or maybe I've haven't found them yet. Any advices?

Thanks
Sebastien
Sebastien
Sebastien
 
Posts: 16
Joined: Thu Jun 02, 2005 12:18 pm
Location: Canada

Re: Dragging and dropping an image on a composite.

Postby Eric Clayberg » Wed Aug 10, 2005 6:05 pm

Sebastien wrote:I tried the idea with the Label. It's simpler then with my previous code but the image doesn't resize to the label's size. Whatever the label's size, the image always keeps it's original size.

Yes. That is what labels do.

Sebastien wrote:If Labels or Canvas are the way to go to insert images onto Composites, then basic Image manipulation should be available within Designer.

The Canvas widget is a very generic drawing surface. It isn't a dedicated widget for displaying images. It can display images or anything else that you want to draw. What you draw is entirely up to you, and it is outside of the scope of Designer to generate that custom drawing code for you.

The Label widget will easily display images, but it does so at their native size.

If you want a widget that will display a scaled image, why not just subclass Canvas and create that resusable widget for yourself? You have already written all of the necessary drawing code. One of the additional benefits to using a custom widget is that Designer will render it in the design view, so you will be able to see the image.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest