FileDocCategorySizeDatePackage
CanvasLFImpl.javaAPI DocphoneME MR2 API (J2ME)12457Wed May 02 18:00:20 BST 2007javax.microedition.lcdui

CanvasLFImpl

public class CanvasLFImpl extends DisplayableLFImpl implements CanvasLF
This is the look amps; feel implementation for Canvas.

Fields Summary
Canvas
canvas
Canvas being stored in this object.
private Vector
embeddedVideos
A vector of embedded video players.
private static MMHelperImpl
mmHelper
The MMHelperImpl instance.
Constructors Summary
CanvasLFImpl(Canvas canvas)
Constructor.

param
canvas - the canvas being stored in this object.

        super(canvas);
        this.canvas = canvas;
    
Methods Summary
voidaddEmbeddedVideo(java.lang.Object video)
Add embedded video player. These are called by MMHelperImpl, whenever a video player joins this canvas.

param
video The player joining this canvas.

         embeddedVideos.addElement(video);
     
private booleanallowKey(int keyCode)
Test to see if the given keyCode should be sent to the application

param
keyCode the key code to pass to the application
return
true if the key should be allowed

        if (!canvas.suppressKeyEvents) {
            return true;
        }

        switch (KeyConverter.getGameAction(keyCode)) {
            case -1:
                // Invalid keycode, don't
                // block this key.
                return true;
            case Canvas.UP:
            case Canvas.DOWN:
            case Canvas.LEFT:
            case Canvas.RIGHT:
            case Canvas.FIRE:
            case Canvas.GAME_A:
            case Canvas.GAME_B:
            case Canvas.GAME_C:
            case Canvas.GAME_D :
                // don't generate key events for
                // the defined game keys
                return false;
            default:
                return true;
        }
    
voidlCallShow()
Prepare this CanvasLF to show. Override the version in DisplayableLFImpl to perform layout.

        int oldState = state;
        super.lCallShow();
        if (oldState != FROZEN) {
            layout();
        }
    
public voidlRepaint(int x, int y, int width, int height, java.lang.Object target)
Notifies look &s; feel object that repaint of a (x, y, width, height) area is needed. SYNC NOTE: The caller of this method handles synchronization.

param
x The x coordinate of the region to repaint
param
y The y coordinate of the region to repaint
param
width The width of the region to repaint
param
height The height of the region to repaint
param
target an optional paint target to receive the paint request when it returns via callPaint()

        lRequestPaint(x, y, width, height);
    
public voidlRepaint()
Notifies that repaint of the entire Canvas look &s; feel is needed and should repaint the viewport area. SYNC NOTE: The caller of this method handles synchronization.

        lRequestPaint();
    
voidremoveEmbeddedVideo(java.lang.Object video)
Remove embedded video player. This is called by MMHelperImpl, whenever a video player leaves this canvas.

param
video The player leaving this canvas.

         embeddedVideos.removeElement(video);
     
public voiduCallFreeze()
Notify this Canvas that it is being frozen on the given Display.

        
        int oldState = state;

        // Delete native resources including title and ticker
        super.uCallFreeze();

        // Notify canvas subclass after hiding the native resource
        synchronized (Display.calloutLock) {
            if (oldState == SHOWN) {
                try {
                    canvas.hideNotify();
                } catch (Throwable t) {
                    Display.handleThrowable(t);
                }
            }
        }
    
public voiduCallHide()
Notify this Canvas it is being hidden on the given Display


        int oldState = state;

        super.uCallHide();

        // SYNC NOTE: Call into app code. So do it outside LUICDLock
        synchronized (Display.calloutLock) {
            if (oldState == SHOWN) { 
                try {
                    canvas.hideNotify();
                    if (mmHelper != null) {
                        for (Enumeration e = embeddedVideos.elements(); 
                                                  e.hasMoreElements();) {
                            mmHelper.hideVideo(e.nextElement());
                        }
                    }
                } catch (Throwable t) {
                    Display.handleThrowable(t);
                }
            }
        }
    
voiduCallKeyPressed(int keyCode)
Handle a key press

param
keyCode The key that was pressed

        if (allowKey(keyCode)) {
            synchronized (Display.calloutLock) {
                try {
                    canvas.keyPressed(keyCode);
                } catch (Throwable t) {
                    Display.handleThrowable(t);
                }
            }
        }
    
voiduCallKeyReleased(int keyCode)
Handle a key release

param
keyCode The key that was released

        if (allowKey(keyCode)) {
            synchronized (Display.calloutLock) {
                try {
                    canvas.keyReleased(keyCode);
                } catch (Throwable t) {
                    Display.handleThrowable(t);
                }
            }
        }
    
voiduCallKeyRepeated(int keyCode)
Handle a repeated key press

param
keyCode The key that was pressed

        if (allowKey(keyCode)) {
            synchronized (Display.calloutLock) {
                try {
                    canvas.keyRepeated(keyCode);
                } catch (Throwable t) {
                    Display.handleThrowable(t);
                }
            }
        }
    
public voiduCallPaint(Graphics g, java.lang.Object target)
Paint this Canvas

param
g the Graphics to paint to
param
target the target Object of this repaint


        synchronized (Display.LCDUILock) {
            // SYNC NOTE: We assert the super function will not call into
            // app code. So we can call it inside sync block.
            super.lCallPaint(g, target);

            // Optimize to not call paint at all
            // when clipping is out of bound (relative to viewport)
            if (g.getClipY() + g.getClipHeight() <= 0) {
                return;
            }
        }

        // We prevent the Canvas from drawing outside of the
        // allowable viewport - such as over the command labels
        // or over the theme area.
        // We also need to preserve the original translation.
        g.preserveMIDPRuntimeGC(0, 0, viewport[WIDTH], viewport[HEIGHT]);

        // Reset the graphics context according to
        // the spec. requirement. This is a must
        // before we call canvas's paint(g) since
        // the title or ticker drawing routines may
        // change the GC before.
        g.resetGC();

        synchronized (Display.calloutLock) {
            try {
                canvas.paint(g);
                // If there are any video players in this canvas,
                // let the helper class invoke video rendering
                // Update frames of any video players displayed on this Canvas
                if (mmHelper != null) {
                    for (Enumeration e = embeddedVideos.elements(); 
                                                  e.hasMoreElements();) {
                        mmHelper.paintVideo(e.nextElement(), g);
                    }
                }
            } catch (Throwable t) {
                Display.handleThrowable(t);
            }
        }

        g.restoreMIDPRuntimeGC();
    
voiduCallPointerDragged(int x, int y)
Handle a pointer drag event

param
x The x coordinate of the drag
param
y The y coordinate of the drag

        synchronized (Display.calloutLock) {
            try {
                canvas.pointerDragged(x, y);
            } catch (Throwable t) {
                Display.handleThrowable(t);
            }
        }
    
voiduCallPointerPressed(int x, int y)
Handle a pointer press event

param
x The x coordinate of the press
param
y The y coordinate of the press

        synchronized (Display.calloutLock) {
            try {
                canvas.pointerPressed(x, y);
            } catch (Throwable t) {
                Display.handleThrowable(t);
            }
        }
    
voiduCallPointerReleased(int x, int y)
Handle a pointer release event

param
x The x coordinate of the release
param
y The y coordinate of the release

        synchronized (Display.calloutLock) {
            try {
                canvas.pointerReleased(x, y);
            } catch (Throwable t) {
                Display.handleThrowable(t);
            }
        }
    
public voiduCallShow()
Notify this Canvas it is being shown on the given Display


        // Check full screen mode and call lCallShow below
        super.uCallShow();

        // SYNC NOTE: Call into app code. So do it outside LUICDLock
        synchronized (Display.calloutLock) {
            try {
                canvas.showNotify();
                /* For MMAPI VideoControl in a Canvas */
                if (mmHelper != null) {
                    for (Enumeration e = embeddedVideos.elements(); 
                                              e.hasMoreElements();) {
                        mmHelper.showVideo(e.nextElement());
                    }
                }
            } catch (Throwable t) {
                Display.handleThrowable(t);
            }
        }
    
public voiduServiceRepaints()
Request serviceRepaints from current Display. SYNC NOTE: No locking is held when this function is called because Display.serviceRepaints() needs to handle its own locking.

        // Avoid locking by making a copy of currentDisplay
        // -- an atomic operation -- before testing and using it.
        Display d = currentDisplay;

        if (d != null) {
            d.serviceRepaints(this);
        }