Layout Policies and Constraints in User Interface Design, Study notes of Software Development

The layout policies in swing, including top-down and bottom-up layout approaches. It also discusses the boxes and glue layout model, springs and struts model, and constraints. The boxes and glue layout model is based on the tex document processing system and is used for tiled composition without overlap. The springs and struts model specifies a fixed offset or area to take up slack. Constraints are a more general approach for establishing and maintaining relationships between things, with the system automatically maintaining relationships under change.

Typology: Study notes

Pre 2010

Uploaded on 08/05/2009

koofers-user-gac
koofers-user-gac 🇺🇸

10 documents

1 / 81

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Damage Management & Layout
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51

Partial preview of the text

Download Layout Policies and Constraints in User Interface Design and more Study notes Software Development in PDF only on Docsity!

Damage Management & Layout

Damage management

 Need to keep track of parts of the screen that need update

 (^) interactor has changed appearance, moved, appeared, disappeared, etc.  (^) done by “declaring damage”  (^) each object responsible for telling system when part of its appearance needs update

Damage Management

 (^) Can optimize somewhat  (^) Multiple rectangles of damage  (^) Knowing about opaque objects  (^) But typically not worth the effort

Damage Management in Swing

JComponent RepaintManager repaint() addDirtyRegion() paintImmediately() paintComponent() paintBorder() paintChildren() Event Dispatch Queue

Layout

 (^) Deciding size and placement of every object  (^) easiest version: static layout  (^) objects don’t move or change size  (^) easy but very limiting  (^) hard to do dynamic content  (^) only good enough for simplest cases

Dynamic layout

 (^) Change layout on the fly to reflect the current situation  (^) Need to do layout before redraw  (^) Can’t be done e.g., in paintComponent()  (^) Why?

Layout in Swing

 (^) invalidate() method  (^) Called on a container to indicate that its children need to be laid out  (^) Called on a component to indicate that something about it has changed that may change the overall layout (change in size, for example)  (^) validate() method  (^) Starts the process that makes an invalid layout valid--recomputes sizes and positions to get correct layout

“Issues” with Swing validation

 (^) invalidate() is often called automatically  (^) e.g., in response to changes to components’ state  (^) ... but not always  (^) e.g., if a JButton’s font or label changes, no automatic call to invalidate()  (^) Mark the button as changed by calling invalidate() on it  (^) Tell the container to redo layout by calling validate() on it  (^) In older versions of Swing you had to do this by hand  (^) Newer versions (post 1.2) add a shortcut: revalidate()  (^) Invalidates the component you call it on  (^) Begins the process of validating the layout, starting from the appropriate parent container  (^) Validation also uses the RepaintManager

Layout with containers

 (^) Containers (parent components) can control size/position of children  (^) example: rows & columns  (^) Two basic strategies  (^) Top-down (AKA outside-in)  (^) Bottom-up (AKA inside-out)

Top-down or outside-in layout

 (^) Parent determines layout of children  (^) Typically used for position , but sometimes size  (^) Example?

Bottom-up or inside-out layout

 (^) Children determine layout of parent  (^) Typically just size  (^) Example?

Bottom-up or inside-out layout

 (^) Children determine layout of parent  (^) Typically just size  (^) Shrink-wrap container  (^) parent just big enough to hold all children  (^) e.g., pack() method on JWindow and JFrame  (^) Resizes container to just big enough to accommodate contents’ preferredSizes

Neither one is sufficient

 (^) Need both  (^) May even need both in same object  (^) horizontal vs. vertical  (^) size vs. position (these interact!)  (^) Need more general strategies

Layout Policies in Swing

 (^) Swing layout policies are (generally) customizable  (^) Some containers come with a “built-in” layout policy  (^) JSplitPane, JScrollPane, JTabbedPane  (^) Others support “pluggable” policies through LayoutManagers  (^) LayoutManagers installed in Containers via setLayout()  (^) Two interfaces (from AWT): LayoutManager and LayoutManager  (^) Determines position and size of each component within a container  (^) Looks at components inside container:  (^) Uses getMinimumSize(), getPreferredSize(), getMaximumSize()  (^) ... but is free to ignore these  (^) Example LayoutManagers:  (^) FlowLayout, BorderLayout, GridLayout, BoxLayout, ...