Understand MVC and Swing Models

Only available on StudyMode
  • Topic: User interface, Java, Business logic
  • Pages : 27 (2893 words )
  • Download(s) : 386
  • Published : September 21, 2011
Open Document
Text Preview
Swing Data Binding
Karsten Lentzsch www.JGoodies.com

Presentation Goals
Understand MVC and Swing models. Learn how to bind domain objects to Swing UI components.

:: JGOODIES :: Java User Interface Design

Speaker Qualifications
      Karsten builds elegant Swing apps works with Objects since 1990 helps others with UI and architectures provides libraries that complement Swing provides examples for Swing architectures writes about Java desktop issues

:: JGOODIES :: Java User Interface Design

Agenda
      Introduction MVC and Swing How to bind single values? How to bind lists A 3-tier Swing architecture How binding works in projects

:: JGOODIES :: Java User Interface Design

Swing Building Blocks
Application 1 Panels Utils Application 2 Help Printing Applications Helper Code/Libs Application Frame Basic Libraries Foundation

Components, Application Management, etc. Appearance Layout Binding Validation

JRE / Swing

:: JGOODIES :: Java User Interface Design

Swing Building Blocks
Application 1 Panels Utils Application 2 Help Printing Applications Helper Code/Libs Application Frame Basic Libraries Foundation

Components, Application Management, etc. Appearance Layout Binding Validation

JRE / Swing

:: JGOODIES :: Java User Interface Design

Questions
       Where do I find MVC in Swing? How to structure a Swing application? What is part of the model? How do I choose models? How to build a view? What does a controller do? Do I need controllers? :: JGOODIES :: Java User Interface Design

I - Basics
MVC and Swing

:: JGOODIES :: Java User Interface Design

Before MVC
Painting Code State Operations (Control Behavior)
State

How to live without MVC?

:: JGOODIES :: Java User Interface Design

Before MVC: 2 Layers
Painting Code State Operations
State

Client

Server
:: JGOODIES :: Java User Interface Design

Separate Domain from Views
 Domain logic contains no GUI code  Presentation handles all UI issues  Advantages: – Each part is easier to understand – Each part is easier to change

:: JGOODIES :: Java User Interface Design

Domain and Presentation
Painting Code
Presentation Layer

State Modifications

State

Domain Layer

:: JGOODIES :: Java User Interface Design

Loose Coupling
 The domain shall not reference the GUI  Presentation refers to domain and can modify it  Advantages: – Reduces complexity – Allows to build multiple presentations of a single domain object :: JGOODIES :: Java User Interface Design

Loose Coupling
Painting Code

State Modifications

reports changes
State

refers to/modifies

:: JGOODIES :: Java User Interface Design

Separate View and Controller
If you separate the painting code (View) from the state modifications (Controller), it's easier to:  combine views and controllers  reuse views and controllers

:: JGOODIES :: Java User Interface Design

MVC
refers to View Controller

reports

changes

Model

:: JGOODIES :: Java User Interface Design

MVC
refers to View Controller

reports

changes

Model

:: JGOODIES :: Java User Interface Design

UI State vs. Data State
We can categorize models into:  domain related  GUI related GUI state can make up its own layer.

:: JGOODIES :: Java User Interface Design

MVC plus Model Layer
View Controller Presentation Layer

GUI Model

(GUI) Model Layer

Domain Model

Domain Layer
:: JGOODIES :: Java User Interface Design

Candidates for a Model Layer
 TreeModel: converts a domain object tree into a form useable for JTree  Models that do not belong to the domain: GUI state, e. g. mouse pressed, mouse over ● Password in a login dialog ● Search values ●

:: JGOODIES :: Java User Interface Design

Conbining MVC Triads
A typical MVC UI combines MVC triads.  Defines models as a graph of domain objects  Composes larger views from small views  Composes controllers from...
tracking img