public class DropEvent extends Object
ƒ/** * basic example of a drop event and its contained informations. * drag an image, a file, a folder, a link into the sketch and see * what information the console spits out. */ import drop.*; SDrop drop; void setup() { size(400, 400); frameRate(30); drop = new SDrop(this); } void draw() { background(0); } void dropEvent(DropEvent theDropEvent) { // returns a string e.g. if you drag text from a texteditor // into the sketch this can be handy. println("toString()\t"+theDropEvent.toString()); // returns true if the dropped object is an image from // the harddisk or the browser. println("isImage()\t"+theDropEvent.isImage()); // returns true if the dropped object is a file or folder. println("isFile()\t"+theDropEvent.isFile()); // if the dropped object is a file or a folder you // can access it with file() . for more information see // http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html println("file()\t"+theDropEvent.file()); // returns true if the dropped object is a bookmark, a link, or a url. println("isURL()\t"+theDropEvent.isURL()); // returns the url as string. println("url()\t"+theDropEvent.url()); // returns the DropTargetDropEvent, for further information see // http://java.sun.com/j2se/1.4.2/docs/api/java/awt/dnd/DropTargetDropEvent.html println("dropTargetDropEvent()\t"+theDropEvent.dropTargetDropEvent()); }
Modifier and Type | Method and Description |
---|---|
Component |
component()
get the component of the drop event.
|
DropTargetDropEvent |
dropTargetDropEvent()
get the DropTargetDropEvent of the drop event.
|
File |
file()
when dropping a file or a folder onto the applet you get a java File back.
|
String |
filePath()
filePath returns the absolute path of a file.
|
boolean |
isFile()
check if the drop event was of type java.io.File.
|
boolean |
isImage()
check if drop event is an image of type java.awt.Image
|
boolean |
isURL()
check if drop event is an url, e.g.
|
static Collection<File> |
listFiles(File directory,
boolean recurse) |
static Collection<File> |
listFiles(File directory,
FilenameFilter filter,
boolean recurse)
list files in a folder, recursive is optional, use true or false.
|
static Collection<File> |
listFiles(File directory,
FilenameFilter filter,
int theDepthLimit) |
static Collection<File> |
listFiles(File directory,
int theDepthLimit) |
static File[] |
listFilesAsArray(File directory,
boolean recurse) |
static File[] |
listFilesAsArray(File directory,
FilenameFilter filter,
boolean recurse)
list files in a folder, recursive is optional, use true or false.
|
static File[] |
listFilesAsArray(File directory,
FilenameFilter filter,
int theDepthLimit) |
static File[] |
listFilesAsArray(File directory,
int theDepthLimit) |
processing.core.PImage |
loadImage()
load an image from an URL or from a harddisk.
|
String |
text()
when dropping text onto the applet you can access the text with the
getText() method.
|
String |
toString() |
String |
url()
if an URL was dropped onto the applet the url() method returns the same as
String.
|
int |
x()
get the x coordinate where the object was dropped.
|
int |
y()
get the y coordinate where the object was dropped.
|
public Component component()
public int x()
public int y()
public DropTargetDropEvent dropTargetDropEvent()
public boolean isFile()
/** * DropFilesAndFolders demonstrates how to access the information of * a file or folder that has been dragged into the sketch. */ import drop.*; SDrop drop; void setup() { size(400,400); drop = new SDrop(this); } void draw() { background(0); } void dropEvent(DropEvent theDropEvent) { if(theDropEvent.isFile()) { // for further information see // http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html File myFile = theDropEvent.file(); println("\nisDirectory ? "+myFile.isDirectory()+" / isFile ? "+myFile.isFile()); if(myFile.isDirectory()) { println("listing the directory"); // list the directory, not recursive, with the File api. returns File[]. println("\n\n### listFiles #############################\n"); println(myFile.listFiles()); // list the directory recursively with listFilesAsArray. returns File[] println("\n\n### listFilesAsArray recursive #############################\n"); println(theDropEvent.listFilesAsArray(myFile,true)); // list the directory and control the depth of the search. returns File[] println("\n\n### listFilesAsArray depth #############################\n"); println(theDropEvent.listFilesAsArray(myFile,2)); } } }
public boolean isImage()
public boolean isURL()
public String text()
/** * basic demonstration of dragging text into the sketch. */ import drop.*; SDrop drop; void setup() { size(400,400); frameRate(30); drop = new SDrop(this); } void draw() { background(0); } void dropEvent(DropEvent theDropEvent) { // drag some text from e.g. a text editor into // the sketch. println(theDropEvent.text()); }
public File file()
/** * DropFilesAndFolders demonstrates how to access the information of * a file or folder that has been dragged into the sketch. */ import drop.*; SDrop drop; void setup() { size(400,400); drop = new SDrop(this); } void draw() { background(0); } void dropEvent(DropEvent theDropEvent) { if(theDropEvent.isFile()) { // for further information see // http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html File myFile = theDropEvent.file(); println("\nisDirectory ? "+myFile.isDirectory()+" / isFile ? "+myFile.isFile()); if(myFile.isDirectory()) { println("listing the directory"); // list the directory, not recursive, with the File api. returns File[]. println("\n\n### listFiles #############################\n"); println(myFile.listFiles()); // list the directory recursively with listFilesAsArray. returns File[] println("\n\n### listFilesAsArray recursive #############################\n"); println(theDropEvent.listFilesAsArray(myFile,true)); // list the directory and control the depth of the search. returns File[] println("\n\n### listFilesAsArray depth #############################\n"); println(theDropEvent.listFilesAsArray(myFile,2)); } } }
public String url()
public String filePath()
public processing.core.PImage loadImage()
/** * loading an image from the web or the harddisk with sDrop. */ import drop.*; SDrop drop; PImage m; void setup() { size(400,400); frameRate(30); drop = new SDrop(this); } void draw() { // flickering background to see the framerate interference // when loading an image. there should be none since the images // are loaded in their own thread. background(random(255)); if(m !=null) { image(m,10,10); } } void dropEvent(DropEvent theDropEvent) { println(""); println("isFile()\t"+theDropEvent.isFile()); println("isImage()\t"+theDropEvent.isImage()); println("isURL()\t"+theDropEvent.isURL()); // if the dropped object is an image, then // load the image into our PImage. if(theDropEvent.isImage()) { println("### loading image ..."); m = theDropEvent.loadImage(); } }
public static File[] listFilesAsArray(File directory, FilenameFilter filter, boolean recurse)
directory
- Filefilter
- FilenameFilterrecurse
- boolean/** * DropFilesAndFolders demonstrates how to access the information of * a file or folder that has been dragged into the sketch. */ import drop.*; SDrop drop; void setup() { size(400,400); drop = new SDrop(this); } void draw() { background(0); } void dropEvent(DropEvent theDropEvent) { if(theDropEvent.isFile()) { // for further information see // http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html File myFile = theDropEvent.file(); println("\nisDirectory ? "+myFile.isDirectory()+" / isFile ? "+myFile.isFile()); if(myFile.isDirectory()) { println("listing the directory"); // list the directory, not recursive, with the File api. returns File[]. println("\n\n### listFiles #############################\n"); println(myFile.listFiles()); // list the directory recursively with listFilesAsArray. returns File[] println("\n\n### listFilesAsArray recursive #############################\n"); println(theDropEvent.listFilesAsArray(myFile,true)); // list the directory and control the depth of the search. returns File[] println("\n\n### listFilesAsArray depth #############################\n"); println(theDropEvent.listFilesAsArray(myFile,2)); } } }
public static File[] listFilesAsArray(File directory, boolean recurse)
directory
- recurse
- public static File[] listFilesAsArray(File directory, FilenameFilter filter, int theDepthLimit)
directory
- filter
- theDepthLimit
- public static File[] listFilesAsArray(File directory, int theDepthLimit)
directory
- theDepthLimit
- public static Collection<File> listFiles(File directory, FilenameFilter filter, boolean recurse)
directory
- Filefilter
- FilenameFilterrecurse
- boolean/** * DropFilesAndFolders demonstrates how to access the information of * a file or folder that has been dragged into the sketch. */ import drop.*; SDrop drop; void setup() { size(400,400); drop = new SDrop(this); } void draw() { background(0); } void dropEvent(DropEvent theDropEvent) { if(theDropEvent.isFile()) { // for further information see // http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html File myFile = theDropEvent.file(); println("\nisDirectory ? "+myFile.isDirectory()+" / isFile ? "+myFile.isFile()); if(myFile.isDirectory()) { println("listing the directory"); // list the directory, not recursive, with the File api. returns File[]. println("\n\n### listFiles #############################\n"); println(myFile.listFiles()); // list the directory recursively with listFilesAsArray. returns File[] println("\n\n### listFilesAsArray recursive #############################\n"); println(theDropEvent.listFilesAsArray(myFile,true)); // list the directory and control the depth of the search. returns File[] println("\n\n### listFilesAsArray depth #############################\n"); println(theDropEvent.listFilesAsArray(myFile,2)); } } }
public static Collection<File> listFiles(File directory, boolean recurse)
public static Collection<File> listFiles(File directory, FilenameFilter filter, int theDepthLimit)
public static Collection<File> listFiles(File directory, int theDepthLimit)
Processing Library Drop by [Ramin Soleymani](http://diskordier.net), original sDrop by [Andreas Schlegel](http://www.sojamo.com). (c) 2015