|
|
|
|
Re: Disposing Images / keeping Images just for a time or user session [message #124030 is a reply to message #124017] |
Mon, 09 March 2009 15:29 |
Eclipse User |
|
|
|
Originally posted by: benjamin.wolff.web.de
Hi,
mybe you should consider to use the Browser Widgets to Display the images..?! That's how i do it.
you could set the Browser Widget's URL to the servicehandler...
HTH,
Ben
p-lex schrieb:
> @ Rüdiger
> thx a lot for your suggestion to use a ServiceHandler to deliver images.
> This is a great solution for my needs.
>
> Instead of writing an c-widget to display the images coming from the
> ServiceHandler is there a way to create images using just an url to the
> image file?
> I dont know how the widgets wich display images get the URL to the image
> but I think it is done by ResourceFactory#getImagePath(Image). But this
> way the path to the image has to be already registered through one of
> the findImage methods.
>
> So what do you think about that? What are the problems? And is the
> RAP-Image-API on the way to change soon?
>
> best regards,
>
> p-lex
>
|
|
|
|
Re: Disposing Images / keeping Images just for a time or user session [message #124131 is a reply to message #124118] |
Tue, 10 March 2009 08:44 |
Stefan Messages: 316 Registered: July 2009 |
Senior Member |
|
|
Hi,
I would also not prefer using the Browser widget. You can use
Graphics.getImage(String, Inputstream) to register your images and to
return an Image instance that you can simply set to a Label, Button, or
whatever. Additionally, your ServiceHandler should keep a reference to
the Image (e.g. a Stream) and return it on demand.
To make this work, you'll have to pass a absolute URL to
Graphics.getImage() as path, e.g.
http://localhost:9080?custom_service_handler=ImageProvider&a mp;imageId=0x12345
Unfortunately, you'll need to patch the RAP method
org.eclipse.ui.internal.servlet.ResourceManagerFactory.Resou rceManagerWrapper.register(String,
InputStream)
to prevent registering your URL-resource image, which is not necessary.
The implementation of this method should be replaced with sth. like that:
public void register( final String name, final InputStream is ) {
// RAP HACK
if (!name.startsWith("http:")) {
resourceManager.register( name, is );
registerAtHttpService( name );
} }
In your ServiceHandler you can implement any kind of strategy to
"forget" images. Another side effect: Calls to ServiceHandlers carry
session information so you can check, if the request comes from a valid
session or not. In contrast, statically registered images are visible
outside session scope.
Hope that helps,
Stefan.
p-lex schrieb:
> thx a lot for your reply :)
>
> Yes this is the solution that I've tried first. But the problem using
> the browser widget is that I dont get the focus events for the images.
>
> The images should be displayed in a gallery. In this gallery the user
> should can "select" the images. If he klicks on an Image inside a
> browser widget I dont get it.
>
> The browser widget could be a nice solution if it could be used in some
> kind of background mode so that I could have a gui layer over the
> browsers content to handle focus events.
>
> If you take a look e.g. at bug 245635
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=245635 there are already
> requests to have more possibility to use images.
>
> RAP use image objekts just as identifier for image paths and keeps the
> width and height of the image.
>
> So why images cant be just created using an url to an image and the
> scalled size of the image?
>
> The providing of images in RAP is dont solved very well. It is not
> really tranparent that happens if you create images.
>
> I just want the best solution I can get without writing my own widgets :)
>
> p-lex
>
|
|
|
|
|
Re: Disposing Images / keeping Images just for a time or user session [message #128904 is a reply to message #128878] |
Mon, 20 April 2009 13:52 |
p-lex Messages: 18 Registered: July 2009 |
Junior Member |
|
|
For delivering Images I use an IServiceHandler (you should know about
IServiceHandler that they can be only registered programmatically - the
way through the servicehandler.xml doesnt work) you can register the
serviceHandler in a start-method of your plugin activator class e. g.:
if (imageServiceHandler == null) {
imageServiceHandler = new ImageServiceHandler();
RWT.getServiceManager().registerServiceHandler(ImageServiceH andler.REQUEST_PARAMETER_ID,
imageServiceHandler);
}
see
http://www.eclipse.org/newsportal/article.php?id=5711&gr oup=eclipse.technology.rap#5711
In the service-method of the service handler you can just write the data
of an image in a stream, like that:
byte[] data = loadImage(id, width, height);
OutputStream out = RWT.getResponse().getOutputStream();
out.write(data, 0, data.length);
out.flush();
out.close();
For display the images I started with the suggestion of Stefan Roeck see
http://www.eclipse.org/newsportal/article.php?id=5772&gr oup=eclipse.technology.rap#5772
For this I created a path-fragment to patch the rap way of creating images.
I patched the ResourceFactory class. I Just added the following methods:
public static synchronized Image createExternalImage(final String path,
int width, int height) {
//IResourceManager manager = ResourceManager.getInstance();
Image image = createImageInstance(width, height);
images.put(image.toString() + path, image);
//manager.register(path, (InputStream) null);
return image;
}
public static synchronized boolean disposeImage(Image image)
{
return disposeImage(image.toString()+getImagePath(image));
}
and changed the getImagePath method:
public static synchronized String getImagePath( final Image image ) {
String result = null;
Iterator it = images.entrySet().iterator();
boolean next = true;
while( next && it.hasNext() ) {
Map.Entry entry = ( Map.Entry )it.next();
if( entry.getValue().equals( image ) ) {
result = ( String )entry.getKey();
String imageHash = image.toString();
if(result.startsWith(imageHash))
{
result = result.substring(imageHash.length());
}
next = false;
}
}
return result;
}
This change is needed becouse I use a little hack that allows me to create
more than one image using the same path. (The hashcode of the image is
used as a extension of the path that is used as identifier for the image
objects)
Now you can create images through the createExternalImage Method and use
them like any other image.
Hope that helps :)
if not just ask ;)
|
|
|
|
Powered by
FUDForum. Page generated in 0.04476 seconds