fuin.org

Small Open Source Java Tools and Libraries

Optimized View and Logic (Controller) Separation with Swing


The Problem

One of the greatest challenges for those developing with the Swing framework is that few instructions from Sun are currently available that explain the most expeditious ways of developing more comprehensive projects with Swing. The JFC (Java Foundation Classes External link) Library is, fundamentally, a gigantic - very powerful and highly flexible - tool box that makes it possible to implement virtually all client developments. Unfortunately, one is also compelled to do so on a relatively low abstraction level.
 
The term Model-View-Controller (MVC External link) as it relates to Swing, for instance, refers only to the interplay between data and graphical components (UI Controls). A structure that would meet the standards of a higher level MVC model, such as the one we are familiar with from the development of client server applications, is not available.
 
Currently, new attempts are underway to establish a Swing Application Framework External link in conjunction with the JSR-296 External link, which aims to eliminate some of these weaknesses. The processing of prolonged duration function requests is accordingly going to be handled via so-called Tasks based on the familiar SwingWorker External link method.
 
One of the disadvantages of the SwingWorker pattern is the fact that the controller function is not clearly separated from the Surface, which results in the functions being scattered all across the entire UI code. This makes the creation of unit tests for the controller code more complicated or even impossible.

What would be the parameters for an alternative approach and which problems should it resolve?

  • Clear separation of View and Controller
  • Facilitated compliance with the Single Thread Rule External link
  • Utilization of existing basic Java technologies (DRY principle External link)
  • Simple utilization for the developer (KISS principle External link)
  • Blockage of the Surface while prolonged duration tasks are underway
    • Allows precise configuration of what is being blocked (entire frame or panel only)
    • User can abort the process at any time
    • Progress bars can be displayed if required
    • Automatic timeout after a predefined time period
 
Next Page: Part 1: Clear Separation of View and Controller
 

 
Page: 1 / 2 / 3 / 4 / 5 / 6 / 7