Thanks Andreas .. We have a JAVA component in the form of a table from which we drag and drop the file and drop it into our own file system. We have a type code
A> Component JXTree. We set the following property to support Drag And Drop.
Component.setDropMode(DropMode.INSERT); Component.setDragEnabled(true); DragSource ds = DragSource.getDefaultDragSource(); DragGestureRecognizer dgr = ds.createDefaultDragGestureRecognizer( Component, DnDConstants.ACTION_MOVE, new FileDragGestureListener());
B> We wrote a class that implements List Gesture Drag Gesture.
Public class FileDragGestureListener extends DragSourceAdapter implements DragGestureListener {
public void dragGestureRecognized (DragGestureEvent dge) {
We get selected row from table. Download the selected File to Native file System TEMP directory. FileSystemView fsv = FileSystemView.getFileSystemView(); Icon icn = fsv.getSystemIcon(File); Toolkit tk = Toolkit.getDefaultToolkit(); Dimension dim = tk.getBestCursorSize(icn.getIconWidth(), icn.getIconHeight()); BufferedImage buff = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB); if (DragSource.isDragImageSupported()) { evt.startDrag(DragSource.DefaultCopyDrop, buff, new Point(0, 0), new TextFileTransferable(File), this); } else { cursor = tk.createCustomCursor(buff, new Point(0, 0), "sString"); evt.startDrag(cursor, null, new Point(0, 0), new TextFileTransferable(File), this); } }
the TextFileTransferable class implements Transferable {
File temp; public TextFileTransferable(File temp) throws IOException { this.temp = temp; } public Object getTransferData(DataFlavor flavor) { List list = new ArrayList(); list.add(temp); return list; } public DataFlavor[] getTransferDataFlavors() { DataFlavor[] df = new DataFlavor[1]; df[0] = DataFlavor.javaFileListFlavor; return df; } public boolean isDataFlavorSupported(DataFlavor flavor) { if (flavor == DataFlavor.javaFileListFlavor) { return true; } return false; }
}
Thus, we can upload the file to% TEMP%, then we will not be able to move this file to the place where it was deleted.
Please suggest where I am mistaken, or what is the best approach to implement this Drag And Drop.
thanks