Home » Eclipse Projects » Remote Application Platform (RAP) » Widget.notifyListeners() and Image scaling
|
Re: Widget.notifyListeners() and Image scaling [message #118977 is a reply to message #118951] |
Wed, 21 January 2009 11:52 |
Rüdiger Herrmann 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 |
|
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 #119120 is a reply to message #119055] |
Thu, 22 January 2009 09:37 |
|
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 #124106 is a reply to message #119120] |
Mon, 09 March 2009 19:54 |
Howard 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 |
|
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;
> }
>
|
|
| | |
Goto Forum:
Current Time: Mon Sep 23 09:29:32 GMT 2024
Powered by FUDForum. Page generated in 0.03648 seconds
|