We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Drag and Drop File Export
Page Index Toggle Pages: 1
Drag and Drop File Export (Read 1792 times)
Drag and Drop File Export
Apr 7th, 2008, 6:04am
 
So now, using the SDrop library, I can drop and drop files onto my processing sketch to import them.  But what about drag and drop from the processing sketch onto the desktop or into another application?

I'd like to have a list or table of filenames inside my processing sketch, and I want to be able to drag one or a number of those out of the sketch into another app or folder.

Any ideas?
Re: Drag and Drop File Export
Reply #1 - Apr 7th, 2008, 8:59am
 
at this stage, sDrop works only in one direction. you can drag things into your processing sketch but not out of the sketch yet. generally this is possible and will be future work. regarding the table, you would be the one to keep track of what you drag into your sketch, meaning your programming skills are required here.
to parse files or folders from a drop event, you can get started with the DropFilesAndFolders example that comes with the zip. hope this helps,
best,
andreas

Re: Drag and Drop File Export
Reply #2 - Apr 19th, 2008, 4:02am
 
Hey Andreas,

I'm using your controlP5 library and updating a scroll list with an array of strings.  I can call a function that removes the scroll list and creates a new line with a new list.  When I call that function from inside a drop event using SDrop, I through a java.lang.reflect exception.  

Any ideas about that?
Re: Drag and Drop File Export
Reply #3 - Apr 20th, 2008, 12:59pm
 
not sure. can you post the source code, if not too long. otherwise send a private message and i take a look at it.
Re: Drag and Drop File Export
Reply #4 - Apr 22nd, 2008, 9:19pm
 
Hi, I have another question about sDrop. Seems that it is not working correctly on Linux, at least on Ubuntu 7.10. When I drop a file into the applet, the isFile property gives false. This doesn't happen either on Windows and OSX. Any ideas about this?
Re: Drag and Drop File Export
Reply #5 - Apr 23rd, 2008, 7:04am
 
hi andres, i dont have a linux box handy so i prepared the following code. from a DropEvent you can extract awt's DropTargetDropEvent that contains all the info about the elements dropped into a frame.
find below the code i use in sDrop as well as an additional code block to extract the filelist from a drop event which i hope works for linux (see comments in the code). if so could you let me know, then i will make changes accordingly.
best,
andi


Code:

import sojamo.drop.*;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.DataFlavor;


SDrop drop;
boolean DEBUG;

void setup() {
size(400,400);
frameRate(30);
drop = new SDrop(this);
DEBUG = false;
}


void draw() {}


void dropEvent(DropEvent theDropEvent) {

DropTargetDropEvent event = theDropEvent.dropTargetDropEvent();
Transferable transferable = event.getTransferable();
DataFlavor[] flavors = transferable.getTransferDataFlavors();

for (int i = 0; i < flavors.length; i++) {
DataFlavor d = flavors[i];
if(DEBUG) {
System.out.println("\t\tMIME " + d.getMimeType());
System.out.println("\t\tfilelist ? " + d.isFlavorJavaFileListType());
}

// does the following block work with linux?
if(d.isFlavorJavaFileListType()==true) {
try {
println(transferable.getTransferData(d));
java.util.List fileList = (java.util.List) transferable.getTransferData(d);
Iterator iterator = fileList.iterator();
while (iterator.hasNext()) {
File f = (File) iterator.next();
println("we got a file, even on linux? "+f);
}
} catch(Exception e) {
}
}



// the following block is used by sDrop.
// as reported, it has problems with linux but works
// fine with windows and mac.
try {
if (d.equals(DataFlavor.javaFileListFlavor)) {
java.util.List fileList = (java.util.List) transferable.getTransferData(d);
Iterator iterator = fileList.iterator();
while (iterator.hasNext()) {
File f = (File) iterator.next();
println("we got a file. "+f);
}
}
}
catch (Exception e) {
System.out.println("Error: " + e + "\n");
}
}

}

Re: Drag and Drop File Export
Reply #6 - Apr 23rd, 2008, 9:41am
 
Cool, thanks andi. I'll look at the code and let you know how it goes.
Re: Drag and Drop File Export
Reply #7 - Apr 24th, 2008, 12:52am
 
Tested this:

Code:


void dropEvent(DropEvent theDropEvent)
{
println("Drop event");

DropTargetDropEvent event = theDropEvent.dropTargetDropEvent();
println(event);

Transferable transferable = event.getTransferable();
println(transferable);

DataFlavor[] flavors = transferable.getTransferDataFlavors();
println(flavors);
}


and println(event); gives null.

However, I was able to make it work when I realized that theDropEvent.toString() actually returns something, which is the name of the file preceded by "file://", so for instance if the file I'm dragging and dropping is "/usr/bin/bash", then theDropEvent.toString() returns "file:///usr/bin/bash". If the item I'm dragging is a directory, the prefix is still "file://".

What I'm using is ubuntu 7.10 and processing 0135.
Re: Drag and Drop File Export
Reply #8 - Apr 25th, 2008, 6:01am
 
thanks andres. hm, null is funny since the DropTargetDropEvent is coming straight from the dnd event. anyway, will take a look into that and update accordingly. can i send you a version when implemented for testing?
Re: Drag and Drop File Export
Reply #9 - Apr 25th, 2008, 4:06pm
 
Sure, no problem.
Re: Drag and Drop File Export
Reply #10 - Feb 5th, 2009, 12:20pm
 
Hi, this is probably a dum question so forgive me... I am new to processing. How can i access the file content of a dropped file? I've been working through the example to read directories but am not able to open files. Any hints highly appreciated.
thanks Christian
Page Index Toggle Pages: 1