Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Widget.notifyListeners() and Image scaling
Widget.notifyListeners() and Image scaling [message #118951] Wed, 21 January 2009 00:25 Go to next message
Howard is currently offline HowardFriend
Messages: 29
Registered: July 2009
Junior Member
First of all, let me say what an awesome project and awesome job you guys
have done! With a couple weeks worth of work, I was able to take a decent
sized application written in SWT and deploy and display it on the web! :D
Now I'm going through the app and ironing out the incompatibilities
between RAP and SWT.

One of the things I noticed is that Widget.notifyListeners() as well as
Display.post() are both missing. This is causing me some heart-burns.
Since programmatically calling Combo.setSelect() in SWT doesn't fire an
selection event, I used to use Widget.notifyListeners() to manually fire
one. Unfortunately RAP doesn't like that. Is there a RAP work-around, or
any plans to address this by any chance?

Another difficulty I'm having is scaling image. The only two ways I know
to resize an image are ImageData.scaledTo() and GC.drawImage(). Neither is
available in RAP. Any help here?

Thanks, and keep up the great work!
Re: Widget.notifyListeners() and Image scaling [message #118977 is a reply to message #118951] Wed, 21 January 2009 11:52 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
Howard,

glad to hear that you liked RAP:) Are you aware of upcoming [1] and
past [2] webinars about single sourcing RAP and RCP? Some of the
presented techniques will probably also fit for single sourcing
standalone SWT and RWT applications.
Please also see my comments below.

Cheers,
Rüdiger

[1] https://www1.gotomeeting.com/register/733916337
[2] http://www.eclipse.org/rap/buzz.php#articles

Howard wrote:
> First of all, let me say what an awesome project and awesome job you
> guys have done! With a couple weeks worth of work, I was able to take a
> decent sized application written in SWT and deploy and display it on the
> web! :D Now I'm going through the app and ironing out the
> incompatibilities between RAP and SWT.
>
> One of the things I noticed is that Widget.notifyListeners() as well as
> Display.post() are both missing. This is causing me some heart-burns.
> Since programmatically calling Combo.setSelect() in SWT doesn't fire an
> selection event, I used to use Widget.notifyListeners() to manually fire
> one. Unfortunately RAP doesn't like that. Is there a RAP work-around, or
> any plans to address this by any chance?
Feel free to file enhancement requests. Widget#notifyListeners()
seems to be not too difficult to implement, whereas I am not sure if
that is also the case for Display.post().
To work around the missing notifyListeners() you could rely on RWT
internals like so:
event = new SelectionEvent( widget, ... );
event.processEvent();

>
> Another difficulty I'm having is scaling image. The only two ways I know
> to resize an image are ImageData.scaledTo() and GC.drawImage(). Neither
> is available in RAP. Any help here?
AFAIK the same can be achieved with AWT. Though using AWT - even in
headless mode - might require some extra software when deploying the
application on the server.

>
> Thanks, and keep up the great work!
>
Re: Widget.notifyListeners() and Image scaling [message #119016 is a reply to message #118977] Wed, 21 January 2009 15:23 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1313
Registered: July 2009
Senior Member

Hi Howard,

>> Another difficulty I'm having is scaling image. The only two ways I
>> know to resize an image are ImageData.scaledTo() and GC.drawImage().
>> Neither is available in RAP. Any help here?
> AFAIK the same can be achieved with AWT. Though using AWT - even in
> headless mode - might require some extra software when deploying the
> application on the server.

I'd like to add that SWT ImageData already exists in RAP in an internal
package. We haven't yet decided whether we can or cannot make this API
publically available, since inappropriate usage might incur severe
memory problems in RAP.

But if you like to experiment, you could try the following (without
having it tried by myself):

ImageData imageData = new ImageData( inputStream );
ImageData scaledData = imageData.scaledTo( width, height );
Image image = ResourceFacory.findImage( scaledData );

Best regards, Ralf
Re: Widget.notifyListeners() and Image scaling [message #119055 is a reply to message #119016] Wed, 21 January 2009 20:46 Go to previous messageGo to next message
Howard is currently offline HowardFriend
Messages: 29
Registered: July 2009
Junior Member
Thanks for the responses!

Rüdiger:
Yes I already know about the webinar and articles; in fact I wouldn't have
gotten this far without those great examples.

I got event.processEvent() to work, after a bit of struggle, due to my
reliance on event.data. Was data left out of the Selection(event)
constructor on purpose?

Ralf:
I got ImageData to work, and am now scaling image size, yay! How do I know
if I'm using it correctly or not? Any easy way to detect memory issues
caused by ImageData?


You guys are awesome! Thanks again.
Howard
Re: Widget.notifyListeners() and Image scaling [message #119120 is a reply to message #119055] Thu, 22 January 2009 09:37 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1313
Registered: July 2009
Senior Member

Howard wrote:
> Ralf:
> I got ImageData to work, and am now scaling image size, yay! How do I
> know if I'm using it correctly or not? Any easy way to detect memory
> issues caused by ImageData?

Great to hear that it works! Regarding memory consumption: as long as
you don't create lots of large ImageData in session scope and you ensure
that you don't keep references to the ImageData objects, so they can be
garbage collected after use, you should be safe. Just keep in mind, that
ImageData hold the entire content of an image and thus might need a lot
of memory. And, if created in session scope, the load can be multiplied
by the number of concurrent users.

Best regards, Ralf
Re: Widget.notifyListeners() and Image scaling [message #119133 is a reply to message #119055] Thu, 22 January 2009 09:45 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
Howard wrote:
> Thanks for the responses!
>
> Rüdiger:
> Yes I already know about the webinar and articles; in fact I wouldn't
> have gotten this far without those great examples.
>
> I got event.processEvent() to work, after a bit of struggle, due to my
> reliance on event.data. Was data left out of the Selection(event)
> constructor on purpose?
The data field of a SelectionEvent that is created by
user-interaction is always null (correct me if I'm wrong). The
SelectionEvent constructor is only for internal use and the
framework had no need for it in the constructor.
You can still assign the data field after creating the
SelectionEvent instance.

>
> Ralf:
> I got ImageData to work, and am now scaling image size, yay! How do I
> know if I'm using it correctly or not? Any easy way to detect memory
> issues caused by ImageData?
>
>
> You guys are awesome! Thanks again.
> Howard
>
Re: Widget.notifyListeners() and Image scaling [message #119685 is a reply to message #118977] Mon, 26 January 2009 15:24 Go to previous messageGo to next message
Setya Nugdjaja is currently offline Setya NugdjajaFriend
Messages: 567
Registered: July 2009
Senior Member
Hi,

> To work around the missing notifyListeners() you could rely on RWT
> internals like so:
> event = new SelectionEvent( widget, ... );
> event.processEvent();

How to do the same for JFace viewer's events ?


Regards,

Setya
Re: Widget.notifyListeners() and Image scaling [message #119737 is a reply to message #119685] Tue, 27 January 2009 08:44 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
Setya,

as far as I know, this is not possible in JFace. To be entirely
sure, you may ask this question on the Platform/UI newsgroup.

Cheers,
Rüdiger

Setya wrote:
> Hi,
>
>> To work around the missing notifyListeners() you could rely on RWT
>> internals like so:
>> event = new SelectionEvent( widget, ... );
>> event.processEvent();
>
> How to do the same for JFace viewer's events ?
>
>
> Regards,
>
> Setya
>
Re: Widget.notifyListeners() and Image scaling [message #124106 is a reply to message #119120] Mon, 09 March 2009 19:54 Go to previous messageGo to next message
Howard is currently offline HowardFriend
Messages: 29
Registered: July 2009
Junior Member
I just noticed that I have some issues with image resizing. I have a label
that displays images from the DB. I have a resize listener on the
composite containing the label so that when the app is resized, the image
will resize and use extra space or use less space along with the app.
Unfortunately with the way RAP image works, multiple copies of the images
in different sizes are created as I slowly expand or contract the browser.
Is there a better way to achieve my desired result?



imageComposite.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event p_event) {
int imageWidth = imageComposite.getSize().x;
int imageHeight = imageComposite.getSize().y;
Image image = getBeanImage(imageBytes, imageWidth, imageHeight);
label.setImage(image);
imageComposite.layout();
}
});

public Image createImage(byte[] imageBytes, int width, int height) {
ImageData imageData = new ImageData(new
ByteArrayInputStream(imageBytes));
if (width != 0 && height != 0) {
// If the image is smaller than scaling dimension, leave it alone
and don't stretch it.
if (imageData.width < width) {
width = imageData.width;
}
if (imageData.height < height) {
height = imageData.height;
}
imageData = imageData.scaledTo(width, height);
}
Image image = ResourceFactory.findImage(imageData);
return image;
}
Re: Widget.notifyListeners() and Image scaling [message #124171 is a reply to message #124106] Tue, 10 March 2009 11:24 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1313
Registered: July 2009
Senior Member

Hi Howard,

Howard wrote:
> I just noticed that I have some issues with image resizing. I have a
> label that displays images from the DB. I have a resize listener on the
> composite containing the label so that when the app is resized, the
> image will resize and use extra space or use less space along with the
> app. Unfortunately with the way RAP image works, multiple copies of the
> images in different sizes are created as I slowly expand or contract the
> browser. Is there a better way to achieve my desired result?

Creating new image versions on every resize seems like overkill to me.
After all, a browser is capable of scaling images as well (you could use
the browser widget to exploit this capability). On the other hand,
resizing on the server saves bandwidth - I guess the best solution
depends on your use case. Maybe a feasible approach is to limit the
possible image sizes in the layout to a few, or to add a "fit to window"
button to minimize the number of requests for resized images?

Best regards,
Ralf


> imageComposite.addListener(SWT.Resize, new Listener() {
> public void handleEvent(Event p_event) {
> int imageWidth = imageComposite.getSize().x;
> int imageHeight = imageComposite.getSize().y;
> Image image = getBeanImage(imageBytes, imageWidth, imageHeight);
> label.setImage(image);
> imageComposite.layout();
> }
> });
>
> public Image createImage(byte[] imageBytes, int width, int height) {
> ImageData imageData = new ImageData(new
> ByteArrayInputStream(imageBytes));
> if (width != 0 && height != 0) {
> // If the image is smaller than scaling dimension, leave it alone
> and don't stretch it.
> if (imageData.width < width) {
> width = imageData.width;
> }
> if (imageData.height < height) {
> height = imageData.height;
> }
> imageData = imageData.scaledTo(width, height);
> }
> Image image = ResourceFactory.findImage(imageData);
> return image;
> }
>
Re: Widget.notifyListeners() and Image scaling [message #124247 is a reply to message #124106] Tue, 10 March 2009 13:13 Go to previous messageGo to next message
p-lex is currently offline p-lexFriend
Messages: 18
Registered: July 2009
Junior Member
Howard wrote:

> I just noticed that I have some issues with image resizing. I have a label
> that displays images from the DB. I have a resize listener on the
> composite containing the label so that when the app is resized, the image
> will resize and use extra space or use less space along with the app.
> Unfortunately with the way RAP image works, multiple copies of the images
> in different sizes are created as I slowly expand or contract the browser.
> Is there a better way to achieve my desired result?

I can link you to a reply of my post:
http://www.eclipse.org/newsportal/article.php?id=5711&gr oup=eclipse.technology.rap#5711

I've got the same problem you have. I get images from a db and wanna
display them in a label and have the possibility to scale them, too. So
RAP is never "disposing" images it has created.
see:
http://www.eclipse.org/newsportal/article.php?id=5706&gr oup=eclipse.technology.rap#5706

The best way to deliver dynamic images wich are coming froma db is through
a ServiceHandler (link posted above). But there is a problem to display
the images. There are some solutions like:
- use a browser widget and set the html snippet to display the image
- write an custom widget to display this images
- Patch the RAP images handling to create images using an URL

I prefer the last solution, for this see:
http://www.eclipse.org/newsportal/article.php?id=5772&gr oup=eclipse.technology.rap#5772

please let me know about your solutions. Maybe we can find a great way to
solve our problems ^^

best regards,

p-lex
Re: Widget.notifyListeners() and Image scaling [message #124258 is a reply to message #124247] Tue, 10 March 2009 16:56 Go to previous message
Howard is currently offline HowardFriend
Messages: 29
Registered: July 2009
Junior Member
Thanks for the suggestions Ralf, I think that'll work as I'm not expecting
resizing to happen too often. It was only a worst case scenario.

p-lex, I think the latest response you got is a winner. I would be
interested to see your finished implementation if possible.
Previous Topic:TableEditor
Next Topic:FormText and ControlDecoration support
Goto Forum:
  


Current Time: Thu Mar 28 22:45:19 GMT 2024

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

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

Back to the top