How to handle Windows shell icons in JFace LabelProviders? - java

I would like to display files and folders in a TreeViewer with the associated Windows shell icons. I use the SHGetFileInfo function to get the icons, and then I convert them to org.eclipse.swt.graphics.Image.
It works great, but when I display a large number of files I get an error: "org.eclipse.swt.SWTError: No more handles". SWT is right, I created too many images. Because I must return them from org.eclipse.jface.viewers.LabelProvider.getImage(Object).
How should I handle this situation?
(I can't "cache" the images, because the icons can be dynamic, and even different for every folder.)

You do need to work out a way to identify the different unique images you get from SHGetFileInfo and only create one Image for each. You must also keep track of the images you create because you must also dispose of them.
You may be able to use org.eclipse.jface.resource.ImageRegistry to help manage the images. This requires a string key to identify each image. It looks like SHGetFileInfo gives you an index number that could be used as a unique key.

Related

Adding text to an animated image in java

My goal is it, to make an API-endpoint, where people can provide a String, that will then be added to a randomly selected gif, which will then be returned.
The text will be provided through a link (query param).
Someone recommended me to look at Convert each animated GIF frame to a separate BufferedImage but I'm not completely sure, if the provided solutions would work, for what I want to achieve.
I already did some endpoints, where I create images depending on certain values, which are returned as bytes[] in a getOutputStream().write(), but those are (obviously) only png-images.
Other things to note are, that I store the gifs, which should be edited, locally on the server and that I use sparkjava, to listen for get actions on the endpoints.
Is the recommended answer in the above question a good solution, or is there a better one?

How to add a non-printable image in xsl / apache-fop

I'm trying to generate an xsl to be printed in a pre-printed sheet which works fine.
Now i want to give the user a better previsualization (in the pdf screen version) adding a background image which emulates the "pre-printed" stuf on the sheet to give the user a "context" of what is he printing.
The question is: Is there any way I can set a background image in xsl (using apache fop) visible only in pdf but not in the printed version of it?
Thank you all for reading or givin any advice.
Although as the comments state, you can't have content in the PDF that does not come out in a physical printed copy, here is one possible work around for you. Depending on how your users are ultimately going to be using FOP for PDF rendering and how your a driving the work flow, it's possible to pass a parameter into an xslt file before the transofrmation phase is run, so potentially, you could do a dual rendering of the same PDF, one that is presented to the user where the background image is enabled, and one that gets printed, you could just set a variable similar to how they do in this Example, and call it something like $isPreview, and just use a simple if or choose statement to check for 'Y' or 'N'.
Since you are sending to a printer, you may even want to take advantage of FOP's ability to generate to Postscript rather than PDF, I've used this feature quite extensively for print documents using FOP while also producing a PDF copy for electronic delivery via email or hosted services, and I've yet to find any discrepancy between the PDF rendering and what is printed after sending a rendered postscript file, so it should work well for you as well.
As I said, this is not truly a solution to your problem as you've presented it, but as a work around, it could get you the desired results if your clever about how you implement it.
I don;t think the statement that it is not possible is true, I am just not sure how to create such a PDF with FOP. Certainly you can add an image field. One would use a button field and place the image in the button. Then you would set the properties of that button to not print (printable false).
PDF support images in fields: https://answers.acrobatusers.com/adding-image-field-form-q41825.aspx
RenderX supports PDF Form fields but I do not see where they support an image inside the button, only text: http://www.renderx.com/reference.html#PDF%20Forms. But they do support setting a field to "printable".

If an image is tampered with some additional content, how to remove that additional content from the image in Java?

I want to know if there is any solution for the following scenario:
I have an application which uploads the files, after scanning and transcoding them, onto a server. Suppose, an image file is being uploaded which has been tampered with some additional contents over it. Now, as the uploaded file is illegitimate, I want to remove the additional tampered contents and upload just the original part of this image file. Is it possible to do so in Java?
Thanks.
It's not possible to detect in the general case, but there are some heuristic methods available to determine whether an image has been edited. Try using the tools at http://imageedited.com/ to get an idea of what's possible.
Removing the edit is a much more difficult problem, which is probably impossible with current methods.
I'm just speculating here, and I don't know how well it would work in practice, but you could do it if you limit to specific sources of tampering. E.g., suppose you want to remove the logo added to an image by memegenerator.net.
You know in advance what the text looks like and where it is. Create a transparent png template that matches the text. Then sum the differences between the image and template pixel colors, multiplying each by the alpha of the template pixel. Since for this particular logo, it's basically white (although it seems to have a thin black shadow) you would get false positives for a picture with a white part there, so you'd also need to verify that the surrounding pixels are (within a tolerance) not white. It's not clever but it could work for certain sites.
For anything more flexible (e.g., logos on images which have subsequently been resized) you're in to the territory of OCR and TinEye-like image matching, which are more advanced than I could advise you on.
To correctly detect all kinds of "tampering" and filter "illegitimate" from "legitimate" in general, you'd need an artificial intelligence that could understand the meaning and context of what it's seeing. The short answer is: you can't. That's what humans are for.
If this is for a website, probably the best thing you can do is a report button that lets users of your site report images that don't fit with your site's rules.

JAVA How to get SWT or JFace internal images

Does anybody know where are and how can I obtain internal images which are used by SWT/JFace, like WARNING, ERROR or INFORMATION icons and others...? Where are they situated and how to get them into my code ?
Some parts of JFace uses images from JFaceResources rather than SWT. You find these as
Image i = JFaceResources.getImage(...);
Unfortunately, everybody can install new images into the resource manager, so there are no way to predict the names of images. Some general images are installed in JFaceResources.initializeDefaultImages().
(If you have images, font or colors you use multiple times across your application, then look into JFaceResources.)
Also - if you are using Eclipse RCP - you can find a number of images using
Image i = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages...);
You can find additional constants in org.eclipse.ui.ide.IDE.SharedImages and org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages (for IDEs).
You can use the getSystemImage() method of Display to get those images.
For example:
Display d = Display.getCurrent();
Image img = d.getSystemImage(SWT.ICON_WARNING);
Hope that helps

Disabling table structure

I have a comprehensive web application with the use of lots of nested tables.
This app works fine for desktop version / view.
I am in the process of getting it setup for mobile view. Which is nearly done, BUT:
I am using JSP and java to, for example, retrieve search results. All of these are displayed in one row at a time.
I am not able to make this row fit onto a mobile screen, so what I am looking for is a JavaScript function to disable the table structer, and just show the columns underneath each other e.g. - comparable with opera mini MOBILE VIEW, which with the click of a button makes contect fit to any screen size. My web app works fine, except of some tables, such as search results. I do not want to change the JSP, not create new pages - that would be too much work !
All I want is to include a certain JavaScript file if the connected user comes via handheld device (which works) and disable the tables, or make it fit properly to the screen !!
I hope someone is able to come up with a solution, I have tried everything with CSS, and few JavaScript bits (which I am not so familiar with)
I have two seperate CSS files, depending on the medium u conenct with, it chooses the right one.
BUT HOW TO GET RID OF THE TABLE OVERFLOW / that the data will be displayed fine, without having to scroll left and right on a small device, which as u know is very annoying ;) !?!?!?
Best regards
ALEX
Try using an alternative stylesheet:
tr{display:block;}
td{display:inline-block;}
...this should allow cells to float inside their parent row.
Example: http://jsfiddle.net/doktormolle/nu62m/

Categories

Resources