FileDocCategorySizeDatePackage
CLayerList.javaAPI DocphoneME MR2 API (J2ME)3971Wed May 02 18:00:20 BST 2007com.sun.midp.chameleon

CLayerList

public class CLayerList extends Object
The class represents bi-directional ordered list of UI layers with possibility to add, remove and iterate over list elements

Fields Summary
protected CLayerElement
top
protected CLayerElement
bottom
protected int
count
Constructors Summary
CLayerList()
Construct empty layers list

        top = null;
        bottom = null;
        count = 0;
    
Methods Summary
CLayerElementaddLayer(CLayer layer)
Add new layer to the top of list with no check for other occurrences of the layer in the list

param
layer CLayer instance to be added
return
list element of the newly added layer

        CLayerElement le =
            new CLayerElement(layer, top, null);
        if (top != null)
            top.upper = le;
        top = le;
        if (bottom == null)
            bottom = le;
        count ++;
        return le;
    
CLayerElementfind(CLayer layer)
Find UI layer instance in the list

param
layer the instance to search in the list for
return
list element with searched layer if success, null otherwise

        for(CLayerElement l = top; l != null; l = l.lower)
            if (l.layer == layer) return l;
        return null;
    
CLayerElementgetBottom()
Get the most bottom list element

return
return the element with top most layer

        return bottom;
    
CLayerElementgetTop()
Get the most top list element

return
return the element with top most layer

        return top;
    
booleanremoveLayer(CLayer layer)
Remove layer from the list

param
layer CLayer instance to be removed
return
true if the layer was found and removed, false otherwise

        CLayerElement le = find(layer);
        if (le != null) {
            removeLayerElement(le);
            le.layer = null;
            return true;
        } else {
            return false;
        }
    
voidremoveLayerElement(CLayerElement le)
Remove layer element from the list with no extra checks. It's caller's responsibility to apply the method on list elements only.

param
le list element to be removed

        CLayerElement upper = le.upper;
        CLayerElement lower = le.lower;

        if (upper != null) {
            upper.lower = lower;
        } else if (top == le) {
            top = lower;
        }

        if (lower != null) {
            lower.upper = upper;
        } else if (bottom == le) { 
            bottom = upper;
        }

        // Clear links to neighbour layers
        le.upper = le.lower = null;
        count --;
    
intsize()
Get number of layers in the list

return
number of list elements

        return count;