public LocalDirectoryTree() {
leftSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
// leftSplitPane.setDividerLocation(200);
leftTreePanel = new JPanel();
leftTablePanel = new JPanel();
leftTreePanel.setLayout(new BorderLayout());
// Saves the drive letters in an array
File[] roots = File.listRoots();
// Creates the JTree on the left side
FileTreeNode rootTreeNode = new FileTreeNode(roots);
leftTree = new FileSystemTree(rootTreeNode, true);
private class FileTreeNode implements TreeNode {
private File file;
private File[] children;
private TreeNode parent;
private boolean isFileSystemRoot;
public FileTreeNode(File aFile, TreeNode aParent,
boolean aIsFileSystemRoot) {
this.file = aFile;
this.parent = aParent;
this.isFileSystemRoot = aIsFileSystemRoot;
this.children = this.file.listFiles(new DirectoryOnlyFilter());
if (this.children == null) {
this.children = new File[0];
}
}
// Creates the filesystem hierachy
public FileTreeNode(File[] aChildren) {
// adds the directories from the desktop folder
File[] desktop = fsv.getHomeDirectory().listFiles(
new DirectoryOnlyFilter());
int totalLength = aChildren.length + desktop.length + 1;
File[] bChildren = new File[totalLength];
for (int index1 = 0; index1 < desktop.length; index1++) {
bChildren[index1] = desktop[index1];
}
// adds the folder "My Documents"
bChildren[desktop.length] = fsv.getDefaultDirectory();
// adds all available drives from aChildren
int index3 = 0;
for (int index2 = desktop.length + 1; index2 < totalLength; index2++) {
bChildren[index2] = aChildren[index3];
index3++;
}
this.file = null;
this.parent = null;
this.children = bChildren;
}
public class FileSystemTree extends JTree implements DragGestureListener,
DragSourceListener, DropTargetListener, MouseListener {
TreePath[] selectedFolders;
// Creates the tree on the left side with the passed parameters
public FileSystemTree(TreeNode aTreeNode, boolean allowChildren) {
super(aTreeNode, allowChildren);
getSelectionModel().setSelectionMode(
TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
addMouseListener(this);
// sets this as a dnd source
DragSource dragSource = DragSource.getDefaultDragSource();
dragSource.createDefaultDragGestureRecognizer(this,
DnDConstants.ACTION_REFERENCE, this);
}