Created
September 9, 2010 19:55
-
-
Save swinton/572444 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package dragdroptest; | |
| import processing.core.PApplet; | |
| import java.awt.dnd.*; | |
| import java.awt.datatransfer.*; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| import java.util.regex.*; | |
| public class DragDropTest extends PApplet implements DropTargetListener { | |
| Pattern pattern = Pattern.compile("^(http://open\\.spotify\\.com\\/(:?track|album|artist|(:?user/.+?/playlist))/[a-zA-Z0-9]+)$", Pattern.MULTILINE); | |
| public void setup() { | |
| size(320, 240); | |
| DropTarget dt = new DropTarget(this, this); | |
| } | |
| public void draw() { | |
| } | |
| public static void main(String _args[]) { | |
| PApplet | |
| .main(new String[] { dragdroptest.DragDropTest.class.getName() }); | |
| } | |
| public void dragEnter(DropTargetDragEvent event) { | |
| event.acceptDrag(DnDConstants.ACTION_COPY); | |
| } | |
| public void dragExit(DropTargetEvent event) { | |
| } | |
| public void dragOver(DropTargetDragEvent event) { | |
| event.acceptDrag(DnDConstants.ACTION_COPY); | |
| } | |
| public void drop(DropTargetDropEvent event) { | |
| event.acceptDrop(DnDConstants.ACTION_COPY); | |
| Transferable transferable = event.getTransferable(); | |
| DataFlavor flavors[] = transferable.getTransferDataFlavors(); | |
| int successful = 0; | |
| List<String> found = new ArrayList<String>(); | |
| for (int i = 0; i < flavors.length; i++) { | |
| try { | |
| Object stuff = transferable.getTransferData(flavors[i]); | |
| if (stuff instanceof String) { | |
| Matcher m = pattern.matcher((String)stuff); | |
| while (m.find()) { | |
| String s = m.group(0); | |
| if (!found.contains(s)) { | |
| found.add(s); | |
| } | |
| } | |
| } | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| System.out.print("\n\n!!! Found: " + found); | |
| } | |
| public void dropActionChanged(DropTargetDragEvent event) { | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment