2D1640 GRIP 2009
Cristian Bogdan

Lab 2: GUI programming

Goal

Give the students the possibility to learn the basics of well-architected GUI programming by practicing the Model-View-Controller paradigm and by using the Java Swing framework.

Estimated time

About 40 hours.

Background material

Task

Implement according to the video prototype below a production planner where the user can plan tasks on production lines. Task planning is visible in graphic and tabular view. Task data is visible in tabular view.

Redovisning

Please email to cristi at kth dot se (subject: GRIP Lab2) by March 3rd, 23:59:

  1. Name of the (max 2) participants, personnumer
  2. Application in runnable format, preferrably as executable jar file so it can be checked rapidly
  3. Application source code as a ZIP
  4. sketch of a UML diagram showing the most important classes and their relations

Please expect feedback, especially on the interaction. You may be asked to improve (especially the interaction) by March 6th.

Detailed description

The user should be able to:

Attention should be paid to the intuitivity of the task drag-and-drop (see the suggestions in the video prototype), and on the effectiveness of entering new tasks in the table, or editing tasks in the table.

At startup, the program can show no tasks, or read the task data (and maybe some task planning data) from a file. It does not need to save the task and planning data at the end (we are interested in interaction, not persistence).

Please find a list of hints at the end.

Video prototype

For reference please use the video prototype below. It is meant to illustrate how the interaction described above could look like. Below the prototype movie you can find its approximate transcript, which you can use for your reference.

If you cannot view the prototype in your browser, try the YouTube version.

Hints

Model

The Model can be represented as a list of Task objects, each containing its customer (String), its duration, its earliest start Date and latest delivery Date.

As a task can be planned at most once, we can also represent the planning information in the Task object, or in an object it refers to. The Task planning information is some description of the production line, and the starting Date (the date when the task is planned to be executed on the line). The end date does not need to be represented as a field, as it can be determined by adding the duration to the starting Date (you can use e.g. Calendar.add), so a method is enough.

The Model must expose a task creation method. Then come the most important methods, of task planning to a line on a date (this can be also used when moving from a line to another), task editing and task deletion. When implementing these methods the model must ensure that no two tasks intersect on a line, so tasks already planned might need to move to the future (i.e. to be re-planned later) to make space for a newly planned tasks. To be able to rapidly detect whether there is potential for task intersection, it may be a good idea to keep the planned tasks sorted after their planned start date.

An important advice is to try to get this "no task intersection" functionality to work in a standalone, non-graphical program. This is a benefit of MVC, it allows us to separate the concerns of data storage and manipulation from those of data visualization and interaction.

Optionally (for easier task planning) the model could also provide the functionality of re-planning tasks earlier (as long as they do not go before their earliest start date) if "space" on the production line becomes available.

To be able to notify its views, the Model could extend Observable. The views can then implement Observer. You can use the object passed to the Observer update method to tell what happened in the model (a Task was added, edited, planned, etc). One operation (e.g. a task planning) can generate one or more updates of the views.

There should be no reference to the view classes (or to java.awt, or to javax.swing) in the model code. Models don't know how they are viewed.

View1: the task table

Can be easily implemented using JTable, and reading the underlying Model to populate the table. The task planning start, end and line columns (the rightmost 3 columns) are not editable, this can be configured in JTable.

View2: the planning chart

The planning chart could include the parking line or a separate view can be created for that.

Important parameters of the planning chart is the "visualization period", i.e. which date is represented by the leftmost margin of the chart, and which date by the righmost. The visualization period can be regarded a higher-level data model, which the planning chart can use, on top of the basic model described above.

The production lines (and the parking line) can be represented as components that are grouped in e.g. a vertical FlowLayout so they remain nicely aligned. Implementing the production line components can be done in various ways:

Another goal of the planning chart is to show and change (with a scrollbar) the visualization period. In some way the user needs to know what period is being visualized and also see some markers for days and possibly weeks.

The "current task" data model

This higher-level data structure is a piece of data that is needed by both the table view (to highlight a table line) and the planning chart view (to highlight a task rectangle). Both views can register themselves as observers also to this model (in addition to the basic Model above). In such a way, when a view changes the current task, the other view will be notified and can update the current task in its turn.

Controllers

Some of the most important controllers in the application: