jmdiframework and the Document-View paradigm

Note: The Java MDI application framework was designed with the ideas of the Document-View paradigm in mind. However, that does not mean that this framework forces you to adhere to a particular paradigm. If you want, you can, for example, add your GUI component to your DocumentData object, therefore violating the division between document data and document view. It's up to you to find and implement the method which fits your needs best.

Graphical overview

framework overview

Splitting Documents in data and views

Which part is responsible for what tasks? In theory, it's really obvious how to split data and view. Just look at the diagram below:

data and view

The problem with the division between data and view is that usually the view already contains the data in some way, otherwise it simply couldn't display it on the screen. An ordinary text editor is a good example for this problem. The data could be seen as a simple String object, however, the view (perhaps a JTextArea) already contains the data and makes it accessible via the getText() method. This redundancy leads to a synchronization problem, which is covered in the next section.

Interaction between data, view and actions

A major difficulty of the Document-View paradigm is keeping view and data synchronized. Therefore, we need to implement a means of bi-directional communication between data and view. There are two situations where this means of communication is used:

Instantiation sequence

When overwriting the default constructors of DocumentView, DocumentData or DocumentWindow classes, it's important to know which of the other elements have already been created. The usual creation sequence is:
  1. Document
  2. DocumentData
  3. DocumentView
  4. DocumentWindow
That means that you can assume that the DocumentData object already exists while the DocumentView's constructor is executed and you can safely access it using getDocument().getData(). It won't work the other way round: trying to get the DocumentView in the DocumentData constructor would result in a NullPointerException.