Created
October 10, 2010 12:23
-
-
Save masanobuimai/619202 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
// g100pon #36 ファイルをドラッグ&ドロップできるウィンドウ | |
// | |
import groovy.swing.SwingBuilder | |
import java.awt.dnd.DropTarget | |
import java.awt.dnd.DropTargetAdapter | |
import javax.swing.DefaultListModel | |
import static java.awt.datatransfer.DataFlavor.javaFileListFlavor | |
import static java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE | |
import static javax.swing.WindowConstants.EXIT_ON_CLOSE | |
def myList | |
SwingBuilder.build { | |
frame(title: "DnD", pack: true, visible: true, | |
defaultCloseOperation: EXIT_ON_CLOSE) { | |
scrollPane { | |
myList = list(model: new DefaultListModel(), | |
dropTarget: new DropTarget(myList, ACTION_COPY_OR_MOVE, [ | |
drop: {e -> | |
e.acceptDrop(ACTION_COPY_OR_MOVE) | |
myList.model.removeAllElements() | |
try { | |
if (e.isDataFlavorSupported(javaFileListFlavor)) { | |
def trans = e.transferable | |
trans.getTransferData(javaFileListFlavor).each { | |
// ドロップしたファイルを受取る | |
myList.model.addElement(it) | |
} | |
} | |
} catch (ex) { e.dropComplete(false) } | |
}, | |
dragEnter: {e -> | |
e.acceptDrag(ACTION_COPY_OR_MOVE) | |
}] as DropTargetAdapter, true)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment