I don't think anybody understands what you're asking -- I don't. In particular, I have no idea what the "location" of a file is, if it's not the same as the complete path? If you mean the x,y location of a icon for a file on the screen, not even the OS itself will know this, in general. It's an incidental detail -- and it's not even unique, as most "file managers" will allow you to see a single file more than once at a time.
I can tell you that in general, the way DnD is supposed to work is that data is transferred from the "drag source" to the "drop target", and it's up to the "drop target" to do something with it; there's really no mechanism for more information to be exchanged, although if you're writing the code for both, then it's generally possible to work something out.
Why not tell us what your problem, exactly, and maybe we can help you figure out how to solve it, rather than telling us your solution and asking us to tell you how to code it.
Currently my application REQUIRES ABSOLUTE PATH OF A FILE for any kind of processing. In my application files are stored in custom format and I have API's to convert from/to files.
I'm trying to implement DnD in 2 cases:
Case 1> Between 2 components within my Java App -> works alright [I'm using Drag & Drop Listeners]... here no files are involved... I just play around with my objects... there's no overhead
2> Between a component in my Java App & Desktop on Native OS (works partially on XP & still not possible on Linux ] DnD b/w Linux & Swing
When I drop files from Windows into my App; I process it as DataFlavor.javaFileListFlavor and then do the actual processing where in I get the ABSOLUTE FILE PATH from List of files dropped into my component
Similarly before DNDing to the OS I need to convert my custom format into a java.util.List of files. Now these files do not exist as such right? So I create a list of new files(reflecting my format) in tempDir and use ABSOLUTE PATHS of these files to fill data from my app. On DnD the appropriate behavior happens
But this process of actually filling in data is complete Overhead when I DND between 2 components inside my app.
I'm willing to create files everytime a drag operation is started. But if I could get the drop Location (absolute file path) after DnD to OS. I can fill in data into the files using my API's.
I will explain my story better in a better way if someone is willing to listen
TIA [ August 16, 2005: Message edited by: Ravi Sathish ]
2> Between a component in my Java App & Desktop on Native OS (works partially on XP & still not possible on Linux ]
I asked about this recently in the AWT/Swing forum but got no response so I am guessing DnD between Windows and a Java app is not possible.
Joined: Feb 26, 2002
Atleast it works partially for me on Windows XP (havent got it working yet on Linux). My problem being bit peculiar hence I able to complete implementation. Let me know what you are trying viz. DND between Swing & Desktop
Joined: Apr 21, 2005
Well my requirements were to find the name and path of a file dragged from the desktop or another folder into my Swing app. But it has already been mentioned that such additional information as file paths is not available to a drag target. However, *any* code that got this even half working would be very much appreciated.
Joined: Feb 26, 2002
I dunno if I understand your requirements correctly. But this is what I do when dragging a file from desktop to Swing component:
Do you still want this thread moved to the I/O forum? I kinda think that the title of the thread may stop some people who otherwise might have helpful information from reading it. [ August 19, 2005: Message edited by: Marilyn de Queiroz ]
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
author and iconoclast
So your question is: your client wants to know where the data is being sent, so it can consider this when creating the DnD data? You're asking about an optimization, because when DnD'ing inside the app, you can exchange data more cheaply, is that right?
You can do this by using a special flavor for intra-app DnD. The DropTarget can ask for this special flavor first, and the generic file list second; if you see the special flavor being asked for then you know the drop target is your own app.
Joined: Feb 26, 2002
Ernest Friedman-Hill wrote: So your question is: your client wants to know where the data is being sent, so it can consider this when creating the DnD data? You're asking about an optimization, because when DnD'ing inside the app, you can exchange data more cheaply, is that right?
Not really... The problem for me my components should be capable of accepting Dataflavors.javaFileListFlavor along with custom flavor b'coz a user can drop a file from desktop into my application as the code snippet I have posted describes.
Recently I found this web-blog which has some pointers which has lots of pointers to my problem. I'll keep u guys posted about my progress...redsolo's web blog [ August 21, 2005: Message edited by: Ravi Sathish ]