-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better Drag and Drop support for DLFS Browser
- Loading branch information
Showing
5 changed files
with
131 additions
and
81 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
74 changes: 74 additions & 0 deletions
74
convex-gui/src/main/java/convex/gui/dlfs/DnDTransferHandler.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package convex.gui.dlfs; | ||
|
||
import java.awt.datatransfer.DataFlavor; | ||
import java.awt.datatransfer.Transferable; | ||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import javax.swing.JComponent; | ||
import javax.swing.JTree; | ||
import javax.swing.TransferHandler; | ||
import javax.swing.tree.TreePath; | ||
|
||
@SuppressWarnings("serial") | ||
public abstract class DnDTransferHandler extends TransferHandler { | ||
|
||
/** | ||
* | ||
*/ | ||
private final DLFSPanel dlfsPanel; | ||
|
||
public DnDTransferHandler(DLFSPanel dlfsPanel) { | ||
this.dlfsPanel = dlfsPanel; | ||
|
||
} | ||
@Override | ||
public boolean canImport(TransferSupport support) { | ||
if (!support.isDrop()) { | ||
return false; | ||
} | ||
return support.isDataFlavorSupported(DataFlavor.javaFileListFlavor); | ||
} | ||
|
||
@Override | ||
public int getSourceActions(JComponent c) { | ||
//PropertyDescriptor prop = getPropertyDescriptor(c); | ||
return COPY; | ||
|
||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public boolean importData(TransferSupport support) { | ||
if (!canImport(support)) return false; | ||
|
||
Transferable tf =support.getTransferable(); | ||
List<File> files; | ||
Path targetDir=getTargetPath(); | ||
|
||
DropLocation dropLocation = support.getDropLocation(); | ||
if (dropLocation instanceof JTree.DropLocation) { | ||
JTree.DropLocation dl =(JTree.DropLocation)dropLocation; | ||
TreePath treePath = dl.getPath(); | ||
if (treePath!=null) { | ||
DirectoryTree.Node parent =(DirectoryTree.Node)treePath.getLastPathComponent(); | ||
System.out.println("Parent: "+parent); | ||
targetDir=parent.getFilePath(); | ||
} | ||
} | ||
System.out.println("Dropping to: "+targetDir); | ||
|
||
try { | ||
files=(List<File>)(tf.getTransferData(DataFlavor.javaFileListFlavor)); | ||
if ((files==null)||(files.isEmpty())) return false; | ||
BrowserUtils.copyFiles(this.dlfsPanel, files, targetDir); | ||
this.dlfsPanel.setSelectedPath(this.dlfsPanel.getSelectedPath()); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
protected abstract Path getTargetPath(); | ||
} |
This file contains 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