package jp.ac.kyutech.mns.ist;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.io.File;
import java.io.IOException;
import java.util.List;

public class PathDropTargetListener implements DropTargetListener{
	PathDropActionListener parent;
	PathDropTargetListener(PathDropActionListener parentd){
		parent = parentd;
	}
	@SuppressWarnings("unchecked")
	public void drop(DropTargetDropEvent dtde) {
{
			DataFlavor[] dataFlavours = dtde.getCurrentDataFlavors();
			for(int i=0; i<dataFlavours.length; i++) {
				if(dataFlavours[i].isFlavorJavaFileListType()) {
					try {
						dtde.acceptDrop(DnDConstants.ACTION_COPY);
						List<File> fileList = (List<File>) dtde.getTransferable().getTransferData(dataFlavours[i]);
						
						for(File file: fileList) parent.dropPath(file.getAbsolutePath(), dtde);
						//Iterate the file list...
					} catch (UnsupportedFlavorException e1) {
						// handle the exception
					} catch (IOException e1) {
					// handle the exception
					}
				}
			}
		}
	}
	public void dragEnter(DropTargetDragEvent dtde) {
		dtde.acceptDrag(DnDConstants.ACTION_MOVE);
		//    System.out.println("enter");
	}
	public void dragOver(DropTargetDragEvent dtde) {
		//    System.out.println("over");
	}
	public void dropActionChanged(DropTargetDragEvent dtde) {
		//    System.out.println("action changed");
	}
	public void dragExit(DropTargetEvent dte) {
		//    System.out.println("exit");
	}
}
