The idea of copy and paste is a not as clear as drag and drop, so we wanted to make it easier to drag and drop files between directories. Also we wanted to make a more representative file icon that would reflect the size.
Our project currently does everything we set out to do which includes:
There is a right click menu to add to favorites things to favorites and another to remove them
Copy and paste work correctly with drag and drop
Show directory name on tab
Make focus consistent for tree and tabs
Make folder size fit better
Make tree to show if a directory can be expanded
we were unable to find a way to display meaningful tool tips for all files.
Our program can display a file system in a way that allow the user to quickly and easily manage their files. A user can open files, browse in tabs and panes, add to favorites, drag and drop to a visual clipboard.
The interface is similar to other file browsers with the addition of fowling important features.
The ability to show the contents of the clipboard.
The ability to spilt the window into two panes that can have multiple tabs
Problem: Easily updating tabbed panel, and directory tree when the current directory is updated.
Solution: Model View Controller.
Code: First we had to add a class to represent our data, DataModel.java.
Next, each class that had to listen for updates must implement Observer. This class must also take the Data Model in its constructor so that it can access the current data. To implement Observer the class has to have the method:
public void update(Observable t, Object o){}
Inside this method you can access any data inside the Data Model.
Result: We learned how useful a model view controller can be. As a result of this problem we used the MVC to solve one more problem during this project.
Problem: Multiple drag and drops starting at the sometime thus causing an InvalidDnDOperationException. This exception sets an non-resetable state that does not allow any other drag and drops to take place
Solution: The underlying problem was multiple DragGestureListeners being registered on the same Components when a directory was reentered or a file added to the clipboard more then once. The solution was to reset the DragSource to a new instance each time the directory was changed or the clipboard was cleared.
Code: DragSource ds = new DragSource();
Result: This solved the problem, by removing the chance of having multiple DragGestureListeners registered on the same component.
Problem: When making a JTree represent a file system it will show that all directories as expandable even when there are no other directories are in them.
Solution: The solution was to make directories that have no sub directories a leafs in the tree. Then you must write a tree cell renderer that will draw leaf nodes as a image that is the same as the folder.
Code: In DirectoryChooser there is a DirNode class that extends DefaultMutableTreeNode. In this class there is a public boolean isLeaf() method. In this method we put the following code:
if(getChildCount() > 0)
return false;
return true;
The next thing is the FileCellRenderer class which extends DefaultTreeCellRenderer this sets the images to file icons that are saved in another directory.
Result: The tree then looks right but there is a performance downside. When using it on a large file system there are some slow down because the only way to tell if you are a leaf is if you have no children, and the only way to know if you have children is to get them. A way to speed things up may be to make it concurrent and use some sort of fork/join, but because would be a very long and difficult change and the limited time of this project there was not enough time to try this out.