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

TickerLayer

public class TickerLayer extends CLayer

Fields Summary
protected String
text
protected int
textLoc
protected int
textLen
protected Timer
tickerTimer
A Timer which will handle firing repaints of the TickerPainter
protected TickerPainter
tickerPainter
A TimerTask which will repaint the Ticker on a repeated basis
Constructors Summary
public TickerLayer()

        super(TickerSkin.IMAGE_BG, TickerSkin.COLOR_BG);
    
Methods Summary
public java.lang.StringgetText()

        return text;
    
protected voidinitialize()

        super.initialize();

        setAnchor();
        tickerTimer = new Timer();
    
protected voidpaintBody(Graphics g)

        synchronized (this) {
            if (text == null) {
                return;
            }
            g.setFont(TickerSkin.FONT);
            if (TickerSkin.COLOR_FG_SHD != TickerSkin.COLOR_FG) {
                int x = textLoc;
                int y = TickerSkin.TEXT_ANCHOR_Y;
                switch (TickerSkin.TEXT_SHD_ALIGN) {
                    case(Graphics.TOP | Graphics.LEFT):
                        x -= 1;
                        y -= 1;
                        break;
                    case(Graphics.TOP | Graphics.RIGHT):
                        x += 1;
                        y -= 1;
                        break;
                    case(Graphics.BOTTOM | Graphics.LEFT):
                        x -= 1;
                        y += 1;
                        break;
                    case(Graphics.BOTTOM | Graphics.RIGHT):
                    default:
                        x += 1;
                        y += 1;
                        break;
                }
                g.setColor(TickerSkin.COLOR_FG_SHD);
                g.drawString(text, x, y, Graphics.TOP | TickerSkin.DIRECTION);
            }
            g.setColor(TickerSkin.COLOR_FG);
            g.drawString(text, textLoc, TickerSkin.TEXT_ANCHOR_Y,
                    Graphics.TOP | TickerSkin.DIRECTION);

            if (tickerPainter == null) {
                startTicker();
            }
        }
    
public voidsetAnchor()

        bounds[X] = 0;
        bounds[W] = ScreenSkin.WIDTH;
        bounds[H] = TickerSkin.HEIGHT;
        switch (TickerSkin.ALIGN) {
            case(Graphics.TOP):
                bounds[Y] = 0;
                break;
            case(Graphics.BOTTOM):
            default:
                bounds[Y] = ScreenSkin.HEIGHT - SoftButtonSkin.HEIGHT -
                        bounds[H];
        }
    
public booleansetText(java.lang.String text)
Set the ticker of this ticker layer.

param
text the text to be displayed on the ticker
return
* @return true if visability of layer was changed

        boolean oldVisable = super.visible;
        synchronized (this) {
            this.text = text;
            super.visible = (text != null && text.trim().length() > 0);
            textLoc = bounds[X] + bounds[W];
            textLen = (text == null) ? 0 : TickerSkin.FONT.stringWidth(text);
            setDirty();
        }
        return (oldVisable != super.visible);
    
public voidstartTicker()

        if (!visible) {
            return;
        }

        stopTicker();
        tickerPainter = new TickerPainter();
        tickerTimer.schedule(tickerPainter, 0, TickerSkin.RATE);
    
public voidstopTicker()
Stop the ticking of the ticker.

        if (tickerPainter == null) {
            return;
        }
        tickerPainter.cancel();
        tickerPainter = null;
    
public voidtoggleAlert(boolean alertUp)

        if (alertUp && TickerSkin.IMAGE_AU_BG != null) {
            super.setBackground(TickerSkin.IMAGE_AU_BG, 0);
        } else if (!alertUp) {
            super.setBackground(TickerSkin.IMAGE_BG, TickerSkin.COLOR_BG);
        }
    
public voidupdate(CLayer[] layers)
Update bounds of layer

param
layers - current layer can be dependant on this parameter

        super.update(layers);
        setAnchor();