CS349 A03: Custom Widgets

Due: 26-Feb-2012 10:00pm

Updates

Feb 16:

Modified the Assessment section to come closer to the goal of mark breakdowns that are no larger than 20% per section. Under Submission, added an optional opt-out file. Added a section indicating that clarifications are to happen via Piazza. Changes are bordered in red.

Feb 13:

A reference to a tutorial was posted on Piazza that essentially does the TreeView and DirView. I'm not happy about it; I think your educational goals would have been better served by figuring this out based less-specific examples so that you had some material left to reason out on your own. Nevertheless, you are free to use this tutorial.

You are strongly encouraged to first study the code and then to rewrite it on your own from scratch as the best approach to learning.

The outline of the marking scheme has been changed to place less weight on the parts covered by the tutorial and more on the TimeView. Given the increased emphasis on TimeView, you are strongly encouraged to test your design ideas (before implementation) with someone not familiar with the course to get their feedback.

Introduction

The standard file explorer in most operating systems shows a tree-like directory (folder) structure. Each directory is a container for files and other directories. Unfortunately, many users do a poor job of sorting their files into directories. Whether a lack of motivation, a lack of knowledge, or some other factor results in poor file organization, the fact remains that, for many users, it happens.

One dimension that is usually poorly supported in default file explorers on many operating systems is time. It is surprising that time has been so poorly explored because so many of the pieces of information we generate are related by temporal proximity. Consider, for example, web pages browsed while creating a lecture. Consider the APIs one looks at when completing an assignment. The temporal proximity of these various data indicates a relationship that can be explored in only limited ways in default file explorers.

Your task for this assignment is to create a custom file viewer for the files on a user's disk. The default file explorer with a tree-view on the left and a file view for the current directory on the right should be augmented with a tabbed container on the right, maintaining the tree view on the left. The tabbed container will have one tab for a customary file view and another tab with a custom widget for a timeline view.

Learning Goals

Requirements

The following figure is a basic example layout for your file browser. (Click to enlarge.)

Figure 1aFigure 1b

The interface is composed of three custom widgets:

All three widgets will be self-contained, extending either JComponent or JPanel. They will all make use of a BrowserModel, much like JTable makes use of TableModel. Programmers familiar with the Swing library should feel at home using your custom widgets. For example, names for adding and removing listeners should feel familiar; interfaces should be defined for listeners; listener methods should make use of an event object; etc. You may want to consult the slides from the Abstract Models lecture.

Selecting a file or directory in one of the views should cause the other views select the same file or directory.

TimeView

The basic requirements for the TimeView widget you create:

Pay special attention to the data region. In this region, you have a chance for some creativity. How will data be displayed? How can users interact with the data items? How does that interaction affect the timeline below the data area? These two areas of the widget are obviously linked. You might implement them as separate (internal) views that both interact with and listen to the file system model.

Restrictions

In light of the results of A02, the following restrictions apply:

Clarifications

Clarifications of expectations are expected to take place in public via Piazza.

Tips

  1. Make three packages, model, view, and app.
  2. The model is a combination of the actual file system and the currently selected file. On the other hand, you will almost certainly want to use JTree and JTable widgets in your user interface and thus need a TreeModel and a TableModel.

    There are several ways to fit this together. I recommend one of:

    Of the two, I'd recommend the second approach.

  3. Root the file system at the user's home directory. You can get that with
    this.root = new File(System.getProperty("user.home"));
  4. Remember that the model classes should not reference the views in any way except via listeners. Suggestions:
  5. Classes you may find useful: File, PropertyChange{Listener, Event}, ArrayList, Collections, Date, List, LinkedList, TableModel, TreePath, TreeModel, SimpleDateFormat, TableModel{Listener, Event}, TreeModel{Listener, Event}, TreeSelection{Listener, Event}, DefaultTreeCellRenderer, ListSelection{Listener, Event}, JPanel, JComponent, JTabbedPane, JSplitPane, JScrollPane.
  6. When you fire a PropertyChange event you need to give the old value and the new value. For the benefit of TreeView, it's cool to give an array of File objects that make the path to the selected file/directory. When making this list, consider using the getParentFile() method in File. But you can't compare File objects directly to tell when you get to the root. Compare paths (strings) instead.
  7. The views will need to register some listeners to change the model. For example, the TreeView should have a TreeSelectionListener registered that tells the model when a new file/directory has been selected.
  8. Tables and trees can have one or many things selected. For this application you should set each to just allow a single selection.
  9. To get selections from a JTable, you need to use it's getSelectionModel() method to get the (surprise!) SelectionModel. It can (and will) fire valueChanged many times in what seems (to us) to be a single selection. Read up on getValueIsAdjusting in the event and only pass the event on to the BrowserModel if getValueIsAdjusting is false and the first index is non-negative.
  10. Refer to the sample code from class for ideas on how to implement the TimeView.

Assessment

Submission will be assessed roughly as follows:

5%
Program compiles and runs1
20%
"Classic browser" capabilities: treeview; list of contents of the selected directory in a tab; keeping the views synchronized
10%
Effective layout; resizing; etc.
65%
Temporal view
25%
Interactive controls are designed and implemented well
25%
Display of the files selected by the interactive controls is designed and implemented well.
10%
Filtering by file type; include/exclude subdirectories
5%
Documentation

By "effectiveness" we mean:

Submission

Submit the following:

Submission will be via your personal svn repository.

1I shouldn't have to say this, but... Only programs that satisfy a reasonable number of the other requirements are eligible for these marks.