I am trying to create a Remote File Drag And Drop Dialog to allow a user to drag a file from a Jlist that shows files
from a specified directory on a server. I have found some code to get to that point. My JList is a custom JList called
Droppable List that implements DropTargetListener, DragSourceListener, DragGestureListener.
In the implemented dragGestureRecognized method, I create a FileSelection object. Then, I call the startDrag method()
as shown. :
FileSelection transferable = new FileSelection(fileNameDesignator);
The FileSelection object implements the Transferrable interface. FileSelection extends ArrayList and adds the argument fileNameDesignator (a String) to the FileSelection object.
Now, during the drag operation, I see the FileSelection getTransferData() get called.
In the getTransferData() method, I retrieve the fileNameDesignator string that I sent in using the code:(String)get(0).
Now, another piece of this open source code that is part of this project knows how to take this fileNameDesignator string
and retrieve the data as a large String from the remote file.
I then use this code (after I get the fileNameDesignator string). This code creates a temporary file from the data that
I have retrieved from the server. So, now my data goes into temp.dat and this works. The problem is that the return
of the getTransferData() method is causing a Class Cast Exception. I am not sure what the Class is supposed to be that
getTransferData() is returning. What would that be?
FileOutputStream outfile = new FileOutputStream("c:\\temp.dat");
DataOutputStream outData = new DataOutputStream(outfile);
return ("c:\temp.dat"); <-- Class cast exception thrown from here. I tried returning a File object and that causes the same exception.
Anyway, the end result that I want is to create a file with the same name by dragging it to a Windows Explorer window. How does Java know what File object (including the complete path) to create. I've looked at local file drag drop examples and I can't find where this occurs.
Do you have any suggestions for me in helping me get my code to work? I know I may have some issues in several areas
here so any comments about anything would be greatly appreciated. I am a novice to the Drag and Drop interface although
I have worked with Java since 1998 in other APIs.