danw11
asked on
Remote File Drag And Drop To Local PC
Hello:
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(fileNameDesi gnator);
dragGestureEvent.startDrag (
DragSource.DefaultCopyDrop ,
transferable,
this);
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);
outData.write(data.getByte s());
outData.close();
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.
Thanks,
Dan
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(fileNameDesi
dragGestureEvent.startDrag
DragSource.DefaultCopyDrop
transferable,
this);
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
DataOutputStream outData = new DataOutputStream(outfile);
outData.write(data.getByte
outData.close();
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.
Thanks,
Dan
return ("c:\temp.dat");
should be
return ("c:\\temp.dat");
or better
return ("c:/temp.dat");
should be
return ("c:\\temp.dat");
or better
return ("c:/temp.dat");
Ignore my first comment !
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks CEHJ. That's all that was missing. Once the getTransferData returned the correct type. Things worked as expected. There is some logic as part of the API that KNOWS how to create a file in the dragged-to-file directory on the Local PC.
Thanks,
Dan
Thanks,
Dan
8-)
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?
You can find out
System.out.println(getTran