JFileUpload when running under Unix (Linux Fedora) does not seem to like file names with spaces in them when dropped on to the applet. Note the same file works fine when running under windows. I fixed this problem by modifying the processDrop method so that URLDecoder is used (I've added a bunch more logging as well):
Code: Select all
if (path.length()>0){
File f = new File(path);
if (!f.exists()) {
try {// on unix files with spaces fail, unless this called
path = URLDecoder.decode(path, "UTF-8");
f = new File(path);
} catch (Exception ex){
log.info(ex.getMessage());
return;
}
}
if ( f.exists()){
if ( f.length() > 0){
if ( f.canRead()){
filenames.add(f.getAbsolutePath());
}else{
log.info("File with no read access <" + path +">");
}
}else{
log.info("Zero length file <" + path +">");
}
} else{
log.info("File does not exist <" + path +">");
}
}
Note also as a suggestion, you could create a drop support class that does actual work of processing a drop, and then classes that require it can simply call its methods, consider:
Code: Select all
public class ProgressPanelWithDrop extends ProgressPanel implements DropTargetListener{
private DropSupport drop;
public ProgressPanelWithDrop(Conf cnf){
super(cnf);
drop = new DropSupport();
// drop onto entire progress panel
new DropTarget(this, DnDConstants.ACTION_COPY, this, true);
}
@Override
public void setController(final TransferController controller){
super.setController(controller);
drop.setController(controller);
}
public void dragEnter(DropTargetDragEvent dtde) {
drop.dragEnter(dtde);
}
public void dragExit(DropTargetEvent dte) {
drop.dragExit(dte);
}
public void dragOver(DropTargetDragEvent dtde) {
drop.dragOver(dtde);
}
public void drop(DropTargetDropEvent dtde) {
drop.drop(dtde);
}
public void dropActionChanged(DropTargetDragEvent dtde) {
drop.dropActionChanged(dtde);
}
}