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

CanvasLFImpl

public class CanvasLFImpl extends DisplayableLFImpl implements CanvasLF
Look and feel implementation of Canvas based on platform widget.

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)
LF implementation of Canvas.

param
canvas the Canvas associated with this CanvasLFImpl

        super(canvas);
    
        this.canvas = canvas;
    
Methods Summary
voidaddEmbeddedVideo(java.lang.Object video)
Add embedded video player. This is 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;
        }
    
voidcreateNativeResource()
Create and show native resource for this Canvas.

        nativeId = createNativeResource0(canvas.title,
                    canvas.ticker == null ? null : canvas.ticker.getString());
    
private native intcreateNativeResource0(java.lang.String title, java.lang.String tickerText)
Create and show native resource for this Canvas.

param
title title of the canvas
param
tickerText text for the ticker
return
native resource ID

public voidlRepaint(int x, int y, int width, int height, java.lang.Object target)
Notifies look & 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, target);
    
public voidlRepaint()
Notifies that repaint of the entire Canvas look&feel is needed. Repaints the viewport area. SYNC NOTE: The caller of this method handles synchronization.

        lRequestPaintContents();
    
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();
                    // For MMAPI VideoControl in a Canvas 
                    if (mmHelper != null) {
                        for (Enumeration e = embeddedVideos.elements();
                                                  e.hasMoreElements();) {
                            mmHelper.hideVideo(e.nextElement());
                        }
                    }
                 } catch (Throwable t) {
                     Display.handleThrowable(t);
                 }
             }
         }
     
public voiduCallHide()
Notify this Canvas that it is being hidden on the given Display.

        
        int oldState = state;

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

        // Notify canvas subclass after hiding the native resource
        synchronized (Display.calloutLock) {
            if (oldState == SHOWN) {
                try {
                    canvas.hideNotify();
        		    /* For MMAPI VideoControl in a Canvas */
                    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

        super.uCallPaint(g, target);

        // We prevent the Canvas from drawing outside of the
        // allowable viewport.
        // We also need to preserve the original translation.
//        g.preserveMIDPRuntimeGC(x, y, WIDTH, 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();

        try {
            synchronized (Display.calloutLock) {
                canvas.paint(g);
            }
        } catch (Throwable t) {
            Display.handleThrowable(t);
        }

        // 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);
            }
	}
//        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 that it is being shown on the given Display.


        // Create native resource with title and ticker
        super.uCallShow();

        // Notify the canvas subclass before showing native resource
        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: Unlike most other LF methods, 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);
        }