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

TitleLayer

public class TitleLayer extends com.sun.midp.chameleon.CLayer
A basic "title" layer. This layer holds a screens title information.

Fields Summary
protected String
title
The text to draw as the title
protected int
titlex
This is the anchor position for the title
protected int
titley
protected int
titlew
protected int
titleh
Constructors Summary
public TitleLayer()
Construct a new TitleLayer. This will construct a new layer using the background image and color settings as defined in the TitleSkin.

        super(TitleSkin.IMAGE_BG, TitleSkin.COLOR_BG);
    
Methods Summary
public java.lang.StringgetTitle()
Get the title of this layer.

return
the title of this layer, or null if this TitleLayer has no title set.

        return title;
    
protected voidinitialize()
The TitleLayer overrides the initialize method in order to locate the title layer in the window at the position and dimensions defined in the TitleSkin.

        super.initialize();

       setAnchor();
    
protected voidpaintBody(Graphics g)
Draw the body of this layer. This method uses settings in the TitleSkin to render the title at the correct location using specified font and color values.

param
g the Graphics to draw to

        String title = this.title;
        if (title == null) {
            return;
        }

        if (titlex == 0) {
            // anchor isn't set yet
            titlew = TitleSkin.FONT.stringWidth(title);
            if (titlew > (ScreenSkin.WIDTH - (2 * TitleSkin.MARGIN))) {
                titlew = ScreenSkin.WIDTH - (2 * TitleSkin.MARGIN);
            }            
            
            switch (TitleSkin.TEXT_ALIGN_X) {
                case Graphics.HCENTER:
                    titlex = (ScreenSkin.WIDTH - titlew) / 2;
                    break;
                case Graphics.RIGHT:
                    titlex = 
                        (ScreenSkin.WIDTH - TitleSkin.MARGIN - titlew);
                    break;
                case Graphics.LEFT:
                default:
                    titlex = TitleSkin.MARGIN;
                    break;
            }
            
            // We center the title vertically in the
            // space provided
            titleh = TitleSkin.FONT.getHeight();
            if (titleh < TitleSkin.HEIGHT) {
                titley = (TitleSkin.HEIGHT - titleh) / 2;
            } else {
                titley = 0;
            }
        }

        g.translate(titlex, titley);
        Text.drawTruncStringShadowed(g, title, TitleSkin.FONT, TitleSkin.COLOR_FG,
                TitleSkin.COLOR_FG_SHD, TitleSkin.TEXT_SHD_ALIGN,
                titlew);
        g.translate(-titlex, -titley);
    
public voidsetAnchor()
Sets the anchor constraints for rendering operation.

        bounds[X] = 0;
        bounds[Y] = 0;
        bounds[W] = ScreenSkin.WIDTH;
        bounds[H] = TitleSkin.HEIGHT;
        titlex = 0;
    
public booleansetTitle(java.lang.String title)
Set the title of this title layer.

param
title the text to draw as the title
return
true if visability of layer was changed

        boolean oldVisible = this.visible;
        this.title = title;

        setDirty();
        this.visible = (title != null);

        // force a re-calc of the text anchor location
        titlex = 0;
        return (oldVisible != this.visible);
    
public voidupdate(com.sun.midp.chameleon.CLayer[] layers)
Update bounds of layer

param
layers - current layer can be dependant on this parameter

        super.update(layers);
        setAnchor();