mimesis and compositing swing

19
Mimesis and Compositing SWING Lecture 17, Oct 27 2009

Upload: amena-johns

Post on 03-Jan-2016

39 views

Category:

Documents


1 download

DESCRIPTION

Mimesis and Compositing SWING. Lecture 17, Oct 27 2009. Administrivia. Reminders: Quiz 2 on Thurs Have your P3 groups ready by Thurs If you don’t pick them, I will. Progress or Congress?. Last time: Micro-tests MVC reprised; MV implementation DebugLog Today: - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Mimesis and Compositing SWING

Mimesis and Compositing SWING

Lecture 17, Oct 27 2009

Page 2: Mimesis and Compositing SWING

Administrivia

•Reminders:

•Quiz 2 on Thurs

•Have your P3 groups ready by Thurs

•If you don’t pick them, I will...

Page 3: Mimesis and Compositing SWING

Progress or Congress?•Last time:

•Micro-tests

•MVC reprised; MV implementation

•DebugLog

•Today:

•Words to the wise: user input validation

•Design principle: mimesis

•UIs in SWING

•The Composite design pattern

Page 4: Mimesis and Compositing SWING

http://xkcd.com/327/

Words to the wise...

Page 5: Mimesis and Compositing SWING

Design Principle o’ the Day

Principle of mimesis: Make the structure of your code mirror the structure of the thing that you are representing.

Page 6: Mimesis and Compositing SWING

Mimesis

•Real world has already solved design problem once

•A solution exists; steal it where you can

•Exploits human visualization/reasoning capabilities

•Improves self-documentation

•Sometimes worth introducing objects that exist only to name conceptual things

Page 7: Mimesis and Compositing SWING

Mimesis: examples

•Project 2:

CustomerType

EmployeeType

World

Receipt

Plant

AssemblyLine

Page 8: Mimesis and Compositing SWING

Mimesis: corollary 1

•Verbs are things too...

Event.execute()

Dispatcher.dispatch()

OrderContainerFactory.newOrderContainer()

Page 9: Mimesis and Compositing SWING

Mimesis: corollary 2

•If the thing is completely abstract (no “real world” counterpart)

•Make up a visual process for it

•Then mimic that...

Page 10: Mimesis and Compositing SWING

Mimesis: corollary 2

•If the thing is completely abstract (no “real world” counterpart)

•Make up a visual process for it

•Then mimic that...

•Example: P1 design

•Based on thinking about clerks at the census bureau

Page 11: Mimesis and Compositing SWING

Application: SWING

•SWING designed to be modular

•“glue together” components

•Massive PITA to write GUI code by hand

•Can become a real morass of spaghetti code and/or immense method bodies

•Instead, make structure of GUI code mimic structure of the display

Page 12: Mimesis and Compositing SWING

configFrame

The Viz configuration

configPanel

plantViz

plantButtons

Page 13: Mimesis and Compositing SWING

The Viz configuration

exptConfig

plantEmplViz

lineBuilderViz

assemblyLineViz

Page 14: Mimesis and Compositing SWING

Object Reference Hierarchy

Page 15: Mimesis and Compositing SWING

Code goes the same way..._configFrame.add(_buildConfig());

private Component _buildConfig() {final JPanel result=new JPanel();result.add(new PlantViz());result.add(_buildPlantButtons());return result;

}

public class PlantViz extends JPanel {public PlantViz() {super();this.add(_buildExptConfig());this.add(_buildPlantEmployeeViz());this.add(_buildLineViz());

}

Page 16: Mimesis and Compositing SWING

Another Design Pattern

•So why does this nested design work?

•Why can we get away with stuffing widgets (JPanel, JScrollPane, JButton, etc.) inside other widgets (JPanel, JScrollPane, etc.) willy-nilly?

•Composite Design Pattern

Page 17: Mimesis and Compositing SWING

Composite•Problem to solve:

•Conceptual containers (JPanel, JScrollPane)

•Conceptual “leaf” widgets (JButton, JTextArea)

•Part-whole structure

•Want the code to treat both uniformly

•Don’t want to have to distinguish between leaf and container in client code

Page 18: Mimesis and Compositing SWING

Composite in SWING

Page 19: Mimesis and Compositing SWING

General Composite Pattern