Version 4 (modified by wouter, 2 years ago) ( diff )

--

MVC

Model View Controller, or MVC in short, is a software design pattern used to develop GUIs.

The details of the approach are explained well on the MVC wiki page. In short,

  • A model contains the data that the user is adjusting.
  • A view shows the data in a GUI to the user (eg, graph, text field, slider position)
  • A controller allows the user to change the data (eg dragging sliders, entering text or numbers, clicking check boxes)

A view and controller can, and often are, merged into a single component. For example a slider shows the current value, but the user can also drag the slider; or a checkbox shows the current setting (on or off) while the user can simply click on it to toggle the value.

Why a toolbox?

This toolbox is to help users develop an MVC based GUI. The tools built into Java lack some functionality: while Java provides a ListModel and a TableModel, it lacks other models such as a StringModel.

The Model

The toolbox has a hierarchy of Models. This section describes the various standard models.

Model and Submodels

At the root is the Model interface. A model basically is an object, which implicitly contains some values that can be adjusted. The interface only specifies that the object broadcasts Event objects whenever something changes in the model. A Model can contain recursively contain sub-models. For instance a Person model may contain a StringModel containing the name, and a NumberModel containing the age.

Event object

All Event objects are objects containing details of a change that happened in a model. It contains a reference to the source Model of the event, and possibly a child event if the change happened on some sub-model. There are four types of changes to a model:

  • Changed: a sub-model of the model changed
  • Added: a model (eg a list) just got extended by addition of a new submodel
  • Removed: a model (eg a list) just got shrinked by removal of a submodel
  • Selected: a model (eg in a list) just got selected
Note: See TracWiki for help on using the wiki.