edu.cmu.sun.folds
Class LayoutCreator

java.lang.Object
  extended by edu.cmu.sun.folds.LayoutCreator

public class LayoutCreator
extends java.lang.Object

Creates new Layouts from a set of constraints. When a folded scroll window needs to be shown, it must decide where to place the folds. This class takes a height constraint, and creates a layout that shows as many items as possible. The layout represents where the folds and lists will be positioned. This class helps with Fulid Negotiation between other lists. For more information on this concept, see:
A Negotiation Architecture for Fluid Documents
Bay-Wei Chang, Jock D. Mackinlay, Polle T. Zellweger, Takeo Igarashi
Xeroc PARC

Author:
Braden Kowitz
See Also:
Layout, LayoutComponent

Field Summary
(package private)  ListModel listModel
          The underlying List model (From the WindowModel) that this object will create Layouts for.
static int MAX_ITEMS_IN_LIST
          the maximum number of items that any Layout may have.
(package private)  float maxHeight
          The maximum height of the final Layout that this object will create.
static int MIN_ITEMS_IN_LIST
          The minimum number of items that any layout may have.
(package private)  WindowModel winModel
          The window model that this object will do layout for.
 
Constructor Summary
LayoutCreator(WindowModel winModel)
          Create a new LayoutCreator for the WindowModel
 
Method Summary
private  Layout calculateLayout(int numPrimaryItems)
          Returns a valid layout for the model if the primary view is showing the item with the primary index and has the provided number of items in it.
private  Layout calculateLayout(int minPrimaryItems, int maxPrimaryItems)
          This function will try to find the layout that has the most number of items in it's primary list, without exceeding the maxSize restriction.
 Layout generateLayout()
          Create a new layout for the window's ListModel that has a height no greater than the maxHeigt set for this LayoutCreator.
 float getMinHeight()
          The Minimum possible height that the window's ListModel could be displayed in.
 float getPerferedHeight()
          The prefered height of the window's ListModel.
private  IndexRange primaryRange(int numItems)
          Returns an index range to match the window's model.
 void setMaxHeight(float maxHeight)
          Set the maximum height allowed in generated layouts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_ITEMS_IN_LIST

public static final int MAX_ITEMS_IN_LIST
the maximum number of items that any Layout may have.

See Also:
Constant Field Values

MIN_ITEMS_IN_LIST

public static final int MIN_ITEMS_IN_LIST
The minimum number of items that any layout may have.

See Also:
Constant Field Values

winModel

WindowModel winModel
The window model that this object will do layout for. This is important becasue the Window Model stores the "Index of interest"


listModel

ListModel listModel
The underlying List model (From the WindowModel) that this object will create Layouts for.


maxHeight

float maxHeight
The maximum height of the final Layout that this object will create.

Constructor Detail

LayoutCreator

public LayoutCreator(WindowModel winModel)
Create a new LayoutCreator for the WindowModel

Parameters:
winModel - the underlying WindowModel (and thus ListModel) for all Layouts
Method Detail

getMinHeight

public float getMinHeight()
The Minimum possible height that the window's ListModel could be displayed in.

Returns:
height in meters

getPerferedHeight

public float getPerferedHeight()
The prefered height of the window's ListModel. A perfered layout is one where all list items are visible on the screen.

Returns:
height in meters

setMaxHeight

public void setMaxHeight(float maxHeight)
Set the maximum height allowed in generated layouts.

Parameters:
maxHeight - maximum height in meters

generateLayout

public Layout generateLayout()
Create a new layout for the window's ListModel that has a height no greater than the maxHeigt set for this LayoutCreator. NOTE: This function breaks down when a layout cannot be made when the MaxHeight is set to less than the MinHeight returned by this function.

Returns:
A new layout for the window's ListModel.

calculateLayout

private Layout calculateLayout(int minPrimaryItems,
                               int maxPrimaryItems)
This function will try to find the layout that has the most number of items in it's primary list, without exceeding the maxSize restriction. It does this by doing a binary search on the number of items. It keeps looking until it finds a layout with the max possible that is under the maxHeight restriction.


calculateLayout

private Layout calculateLayout(int numPrimaryItems)
Returns a valid layout for the model if the primary view is showing the item with the primary index and has the provided number of items in it. The layout this method provides may be greater than the maximum height allowable for the layout manager. To create the largest size possible, call generateLayout()


primaryRange

private IndexRange primaryRange(int numItems)
Returns an index range to match the window's model. The index range will be as large as numItems (unless the model is smaller). It will be aligned to TOP so, if possible, the top of the range will be the primaryIndex.