I have a hard time dragging and dropping files from a remote location to windows explorer. I use a swing ui that displays the contents of the server. Now I have implemented a TransferHandler and a Transferable to bring the files to windows explorer.
The problem here is: Windows explorer, or almost any drag operation, calls the method Transferable.getTransferData over and over again, not just when the mouse button is released over the drag target. This is problematic for me because getTransferData fetches the files from the server (which takes quite some time).
IMHO I need some sort of lazy file but I am unsure how the drag handling on windows is implemented. I want to fetch the files only if the mouse button is released over a valid drop target for the files in the native system.
Does anybody know how this can be achieved?
Related
I'm using JNativeHook to detect drags and clicks outside a JFrame in my program and it's running perfectly. The thing is I need a way (either using JNativeHook or anything else) to check if a folder is opened in my explorer (Finder for Mac) so that I can move a file to this opened folder. JNativeHook doesn't seem to have the option of detecting on what program or window was the click made.
I expect the output of the code I'm looking for to return the path of open folders in my system explorer so that I can move files to this path.
You will not be able to detect if explorer is opened to a particular folder. There are API's to detect things like the window under the cursor and get information like the title, however, if explorer is not displaying the path in the title, it will be very hard to detect without traversing the application components and finding the address bar of the window. See WindowFromPoint and GetWindowTextA for a staring point. It should work fine under JNA and can be combined with the coordinates returned from JNativeHook.
I'm using the DirectoryDialog component in my application to let the user select a folder.
Now I want to have the possibility to prevent the user from choosing a specific folder. Is there a handler or listener or something like that?
This can't be done.
DirectoryDialog is just a thin wrapper around the native open directory dialog (for example on macOS it uses NSOpenPanel). The native dialog is very different on the various platforms supported by SWT making it not practical to allow this.
You could craft your own directory dialog using a TreeViewer and the native file APIs.
I realise that there are other questions on this topic, all of which I have attempted to implement the answers of and failed. I would like to end up with a full blown answer, ideally with a demonstration, on how to, in Windows and only Windows set the desktop background instantly without having the user log in and out or lock and log back in. The approach that involves using the runtime console to push the registry entries about and then rundll32 user32.dll call UpdatePerUserSystemPreferences has yet to work for me. The desired behaviour is achieved when the user right clicks an image file in explorer and selects 'Set as desktop background'. I'd like to do that programatically even if it devolves to the level of opening a hidden explorer window and right-clicking a file in it as long as the user sees nothing of it. The application in question updates the user's desktop background image with useful system information. The image to be used will be generated and regenerated every five seconds.
Can I change my Windows desktop wallpaper programmatically in Java/Groovy?
So the correct way is with JNA if you are not familiar with JNA or if you haven't used JNA the link above is for you. Otherwise you are right about using natives but you never stated how you are using them so I am just taking shots in the dark here.
On OSX my Java application has a dock menu (using Apples extension to Java com.apple.eawt.Application.getApplication().setDockMenu) , allowing tasks to be started by right clicking on the dock icon, also files can be dropped onto the dock icon (Using Apples com.apple.eawt.OpenFilesHandler) and my application starts processing the dropped files.
I'm trying to replicate this functionality if sensible on Windows, if this behaviour on Windows is weird I don't want to do it. I cannot find a way to add tasks to to the popup menu for the application icon on the taskbar (my application is has an .exe wrapper provided by winrun4j), is that possible ?
But I have used java.awt.SystemTray to add a right click menu to that, and it works but I'm unclear in Windows when one would use the taskbar icon and when the SystemTray. What I cannot do is have the SystemTray respond to files being dropped onto it, and according to this Oracle Java issue it will never happen http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7119272. What I'm unclear about is if the Windows System tray is never meant to respond to things being dropped on it, or if this is just missing functionality in the Java implementation.
And is there way to drag files onto the taskbar icon instead, or is this whole notion of dragging files onto minimized icons purely an OSX thing and not relevent to Windows ?
To answer my own question files cannot be dropped directly onto pinned taskbar icon or the toolbar icon, but if you drag files onto the taskbar icon it should cause the main window to be displayed and then the files can be dropped onto the window instead, and this behaviour happens automtically with no coding required on my part.
I found this SO link to get the currently opened applications in task bar.
In addition I need to get the applications running in system tray using Java.
Also suggest me if there is some other good ways to find the opened apps in task bar.
How to find in which application the mouse click and key stroke has been ocuured?
I also want to track the mouse click by viewing which application is opened by the particular mouse click.
I want this application to run both in Linux and windows environment. I need to do all the above in one of my application using Java.