views:

31

answers:

2

I'd like write a layout manager for j2me. I already have widgets and panels (panel is a set of widgets in this context). Now I'd like to add dynimc layout management so when i call doLayout on the outer most panel, internal widgets and panels rearrange according device's width and height.

I was wondering whether there any well known patterns for layout managers.

A: 

Common approach which I know is to keep each Displayable in Stack collection, such that current panel/screen should always be on top of Stack. And when user press "back" button you just should pop previous screen/panel on top of Stack.

Example can be found here

barmaley
Yep. But that does not handle different screen sizes.
Gatis
+2  A: 

Each UI object should return a "minimum size (w,h)". Then you need an algorithm that traverse all your objects and split the available area in chunks and assign each chunk to an object. You can Tree-Partition it based on the object relevance.

fabrizioM
Yep. That's an idea. Right now my algorithm traverses the whole tree collecting min size for each widget. Then it does a second pass which resize widgets based on available room and widget's properties (alignment and expandability). I was wondering whether I could do everything in a single pass.
Gatis
I think the double pass is the best and cleanest method out there.
fabrizioM