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

BodyLayer

public class BodyLayer extends CLayer implements ScrollListener
Basic layer containing the application area of the display. This layer contains the current Displayable contents, such as a Form or Canvas.

Fields Summary
protected ScrollIndLayer
scrollInd
The scroll indicator layer to notify of scroll settings in case not all content can fit on the menu.
ChamDisplayTunnel
tunnel
Constructors Summary
public BodyLayer(ChamDisplayTunnel tunnel)
Create a new BodyLayer.

param
tunnel BodyLayer needs a "tunnel" class to cross the package protection boundary and access methods inside the javax.microedition.lcdui package

        this((Image)null, -1, tunnel);
    
public BodyLayer(Image[] bgImage, int bgColor, ChamDisplayTunnel tunnel)
Create a new BodyLayer with the given background image or color. If the image is null, the color will be used.

param
bgImage a background image array to use to render the background of this layer
param
bgColor a solid background fill color to use if the image background is null
param
tunnel BodyLayer needs a "tunnel" class to cross the package protection boundary and access methods inside the javax.microedition.lcdui package

        super(bgImage, bgColor);
        this.tunnel = tunnel;
        this.visible = false;

        setScrollInd(ScrollIndLayer.getInstance(ScrollIndSkin.MODE));
    
public BodyLayer(Image bgImage, int bgColor, ChamDisplayTunnel tunnel)
Create a new BodyLayer with the given background image or color. If the image is null, the color will be used.

param
bgImage a single background image to use to render the background of this layer
param
bgColor a solid background fill color to use if the image background is null
param
tunnel BodyLayer needs a "tunnel" class to cross the package protection boundary and access methods inside the javax.microedition.lcdui package

        super(bgImage, bgColor);
        this.tunnel = tunnel;
        this.visible = false;
        setScrollInd(ScrollIndLayer.getInstance(ScrollIndSkin.MODE));
    
Methods Summary
public voidaddDirtyRegion()
Add this layer's entire area to be marked for repaint. Any pending dirty regions will be cleared and the entire layer will be painted on the next repaint. TODO: need to be removed as soon as removeLayer algorithm takes into account layers interaction

        super.addDirtyRegion();
        if (scrollInd != null) {
            scrollInd.addDirtyRegion();
        }
    
public voidaddNotify()
Called by CWindow to notify the layer that is has been added to the active stack.

        if (scrollInd != null && owner != null) {
            if (owner.addLayer(scrollInd)) {
                updateScrollIndicator();    
            }    
        }
    
protected voidpaintBody(Graphics g)
Paint the contents of this layer. This method is overridden from the parent class to use the package tunnel to call back into the javax.microedition.lcdui package and cause the current Displayable to paint its contents into the body of this layer.

param
g the Graphics to paint to

        if (tunnel != null) {
            tunnel.callPaint(g);
        }
    
public voidremoveNotify(CWindow owner)
Called by CWindow to notify the layer that is has been removed from the active stack.

param
owner an instance of CWindow this layer has been removed from

        if (scrollInd != null && owner != null) {
            if (owner.removeLayer(scrollInd) && scrollInd.isVisible()) {
                bounds[W] += scrollInd.bounds[W];
            }
        }
     
public voidscrollContent(int scrollType, int thumbPosition)
Scrolling the contents according to the scrolling parameters.

param
scrollType can be SCROLL_LINEUP, SCROLL_LINEDOWN, SCROLL_PAGEUP, SCROLL_PAGEDOWN or SCROLL_THUMBTRACK
param
thumbPosition only valid when scrollType is SCROLL_THUMBTRACK

        tunnel.callScrollContent(scrollType, thumbPosition);
    
public voidsetDirty()
Mark this layer as being dirty. By default, this would also mark the containing window (if there is one) as being dirty as well. However, this parent class behavior is overridden in BodyLayer so as to not mark the containing window and therefor not require a full Chameleon repaint when only the application area needs updating.

        setDirtyButNotNotifyOwner();
    
public voidsetScrollInd(ScrollIndLayer newScrollInd)

        if (scrollInd != newScrollInd ||
            scrollInd != null && scrollInd.scrollable != this ||
            scrollInd != null && scrollInd.listener != this) {
            if (scrollInd != null) {
                boolean vis = scrollInd.isVisible();
                scrollInd.setScrollable(null);
                scrollInd.setListener(null);

                if (owner != null) {
                    if (owner.removeLayer(scrollInd) && vis) {
                        bounds[W] += scrollInd.bounds[W];
                        addDirtyRegion();
                    }
                }
            }
             
            scrollInd = newScrollInd;
            if (scrollInd != null) {
                scrollInd.setScrollable(this);
                scrollInd.setListener(this);

                if (owner != null) {
                    owner.addLayer(scrollInd);
                }
            }
        }
        updateScrollIndicator();        
    
public booleansetVerticalScroll(int scrollPosition, int scrollProportion)
Set the current vertical scroll position and proportion.

param
scrollPosition vertical scroll position.
param
scrollProportion vertical scroll proportion.
return
true if set vertical scroll occures

        if (scrollInd != null)  {
            boolean wasVisible = scrollInd.isVisible();
            scrollInd.setVerticalScroll(scrollPosition, scrollProportion);
            boolean scrollVisible = scrollInd.isVisible();

            if (wasVisible != scrollVisible) {
                if (scrollVisible) {
                    scrollInd.setBounds();
                }
                int w = scrollInd.bounds[W];
                bounds[W] += scrollVisible? -w: +w;
                addDirtyRegion();
                return true;
            }
        }
        return false;
    
public voidsetVisible(boolean visible)
Toggle the visibility state of this layer within its containing window.

param
visible If true, this layer will be painted as part of its containing window, as well as receive events if it supports input.

        boolean oldVis = this.visible;
        super.setVisible(visible);
        if (oldVis != visible) {
            if (scrollInd != null && !visible) {
                scrollInd.setVisible(visible);
            } else {
                updateScrollIndicator();
            }
        }
    
public voidupdate(CLayer[] layers)
Update bounds of layer

param
layers - current layer can be dependant on this parameter

        super.update(layers);

        bounds[W] = ScreenSkin.WIDTH;
        bounds[H] = ScreenSkin.HEIGHT;

        if (layers[MIDPWindow.PTI_LAYER] != null && layers[MIDPWindow.PTI_LAYER].isVisible()) {
            bounds[H] -= layers[MIDPWindow.PTI_LAYER].bounds[H];
        }
        if (layers[MIDPWindow.TITLE_LAYER].isVisible()) {
            bounds[Y] = layers[MIDPWindow.TITLE_LAYER].bounds[H];
            bounds[H] -= layers[MIDPWindow.TITLE_LAYER].bounds[H];
        } else {
            bounds[Y] = 0;
        }
        if (layers[MIDPWindow.TICKER_LAYER].isVisible()) {
            bounds[H] -= layers[MIDPWindow.TICKER_LAYER].bounds[H];
        }
        if (layers[MIDPWindow.BTN_LAYER].isVisible()) {
            bounds[H] -= layers[MIDPWindow.BTN_LAYER].bounds[H];
        }

        if (scrollInd != null) {
            scrollInd.update(layers);
            if (scrollInd.isVisible()) {
                bounds[W] -= scrollInd.bounds[W];
            }
        }
    
public voidupdateScrollIndicator()
Updates the scroll indicator.

        tunnel.updateScrollIndicator();