edu.cmu.sun.folds
Class Layout

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

public class Layout
extends java.lang.Object

A Layout is a model representation of the contents of a Window. That is, It represents the folded scrolling portion of the window. Simply put, it contains a set of LayoutComponents, in order, that make up the layout. This class also provides some methods for helping with the animations process. For example, the Segment and Consolidate functions are called during the animation process to ensure that the layout is formed correctly for the next step.


Field Summary
(package private)  java.util.List<LayoutComponent> components
          The underlying components that make up the Layout.
 
Constructor Summary
Layout()
          Create a new Layout, initially empty.
Layout(Layout otherLayout)
          Create a layout that is a copy of another layout.
 
Method Summary
 void addComponent(LayoutComponent newComp)
          Adds a component to the end of this layout, and sets the parent of the provided component to this Layout.
 void clearMatches()
          Clears all of the matches from the children LayoutComponents
 void consolidate()
          Cleans up the Layout.
 java.util.LinkedList<LayoutComponent> getComponentList()
          Returns the ListCompoennts that make up this Layout.
 java.util.List<LayoutComponent> getComponentsTypedAsList()
           
 LayoutComponent getFirstComponent()
          Returns the first component of this list.
 float getHeight()
           
 LayoutComponent getLastComponent()
          Returns the last component of this list.
 LayoutComponent getNextSibling(LayoutComponent component)
          Gets the next component in the Layout
 LayoutComponent getPreviousSibling(LayoutComponent component)
          Gets the previous component in the Layout
 void segment(Layout acrossLayout)
          Segment the layout across another layout.
private  boolean segmentAcorss(Layout acrossLayout)
          Implementation of the Segment Algorithm.
private  void segmentComponent(LayoutComponent localComp, int rangeIndex)
          Segments a particular LIST component that belongs to this Layout.
 java.lang.String toString()
          Simply for debugging.
 void updateToNextRanges()
          Updates all of the child LayoutComponents to their next ranges.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

components

java.util.List<LayoutComponent> components
The underlying components that make up the Layout. This is sorted in order from the top-most component to the bottom-most.

Constructor Detail

Layout

public Layout()
Create a new Layout, initially empty.


Layout

public Layout(Layout otherLayout)
Create a layout that is a copy of another layout. All components will be copied (not referenced )from the provided Layout.

Parameters:
otherLayout - the layout to copy from.
Method Detail

getHeight

public float getHeight()
Returns:
The sum of the height of all LayoutComponents in this Layout

getComponentList

public java.util.LinkedList<LayoutComponent> getComponentList()
Returns the ListCompoennts that make up this Layout. The function returns not the underlying list that this object uses, but a copy of the list for protection.


getFirstComponent

public LayoutComponent getFirstComponent()
Returns the first component of this list. Throws a an OutOfBounds exception if list is empty.


getLastComponent

public LayoutComponent getLastComponent()
Returns the last component of this list. Throws a an OutOfBounds exception if list is empty.


addComponent

public void addComponent(LayoutComponent newComp)
Adds a component to the end of this layout, and sets the parent of the provided component to this Layout.

Parameters:
newComp -

getComponentsTypedAsList

public java.util.List<LayoutComponent> getComponentsTypedAsList()
Returns:
A list of all components, in order, that have a type of LIST

consolidate

public void consolidate()
Cleans up the Layout. It removes any components with a current range size of zero. Also, it finds consecutive components typed as LIST and merges them into a single component.


segment

public void segment(Layout acrossLayout)
Segment the layout across another layout. During the animation process, it is important to avoid 2-1 and 1-2 mappings between the current layout and the next layout. We detect these mapping by seeing which components overlap. If two LayoutComponents represnet the same elements, then we count them as connected. If one component is connected to two components in another Layout, then that component needs to be segmented to produce two 1-1 matchings rather than a single 1-2 mapping. This function segments this Layout acorss another. the call should be done bi-directionally. So, both layouts are segmented acorss each other. This function modifies THIS object, by segmenting where necessary.

Parameters:
acrossLayout - layout to segment across.
See Also:
LayoutTransitioner

segmentAcorss

private boolean segmentAcorss(Layout acrossLayout)
Implementation of the Segment Algorithm. Returns True immediately if the function performs a segment. Since a segment modifies the layout, we simpley start again from the top if a segment action oaccours. (probably not the most efecient thing.

Parameters:
acrossLayout - layout to segment across.
Returns:
True if segment occoured

segmentComponent

private void segmentComponent(LayoutComponent localComp,
                              int rangeIndex)
Segments a particular LIST component that belongs to this Layout. This breaks the compoennt into two parts at the specified index.

Parameters:
localComp - component in this Layout to segment
rangeIndex - inded at which to segment the component.

updateToNextRanges

public void updateToNextRanges()
Updates all of the child LayoutComponents to their next ranges.

See Also:
LayoutComponent

clearMatches

public void clearMatches()
Clears all of the matches from the children LayoutComponents

See Also:
LayoutComponent

toString

public java.lang.String toString()
Simply for debugging.

Overrides:
toString in class java.lang.Object

getPreviousSibling

public LayoutComponent getPreviousSibling(LayoutComponent component)
Gets the previous component in the Layout

Parameters:
component - returns a component previous to this one.
Returns:
the previous component in the Layout, or null if none found.

getNextSibling

public LayoutComponent getNextSibling(LayoutComponent component)
Gets the next component in the Layout

Parameters:
component - returns a component after to this one.
Returns:
the next component in the Layout, or null if none found.