FileDocCategorySizeDatePackage
LcduiTestCanvas.javaAPI DocphoneME MR2 API (J2ME)5916Wed May 02 18:00:00 BST 2007com.sun.midp.util

LcduiTestCanvas

public class LcduiTestCanvas extends javax.microedition.lcdui.Canvas
A simple test canvas. Adds the ability to wait for the Canvas to become visible for the first time.

Fields Summary
static final long
TIMEOUT
boolean
painted
boolean
shown
boolean
everShown
Constructors Summary
Methods Summary
public booleanawaitPaint()
Waits until this canvas is painted for the first time. Proper operation relies on the caller to have arranged for this canvas to be shown, for example, with setCurrent(). Returns immediately if the canvas has been painted already, even if it's been hidden and shown again. Returns true if the canvas has been painted at least once. Returns false if the wait was interrupted or if it timed out. This method must not be called on the event thread. If it is, it will block paint processing and will eventually timeout.

        long deadline = System.currentTimeMillis() + TIMEOUT;

        synchronized (this) {
            try {
                while (!painted && System.currentTimeMillis() < deadline) {
                    wait(TIMEOUT);
                }
            } catch (InterruptedException ie) {
                return false;
            }
            return painted;
        }
    
public booleanawaitShow()
Waits until this canvas is shown for the first time. Proper operation relies on the caller to have arranged for this canvas to be shown, for example, with setCurrent(). Returns immediately if the canvas has been shown already, even if it has subsequently been hidden. Returns true if the canvas has ever been shown. Returns false if the wait was interrupted or if it timed out. This method must not be called on the event thread. If it is, it will block show processing and will eventually timeout.

        long deadline = System.currentTimeMillis() + TIMEOUT;

        synchronized (this) {
            try {
                while (!everShown && System.currentTimeMillis() < deadline) {
                    wait(TIMEOUT);
                }
            } catch (InterruptedException ie) {
                return false;
            }
            return everShown;
        }
    
public final voidhideNotify()
Tracks the shown state. This is made final so that subclassers can't accidentally break the protocol if they override and forget to call super(). Subclassers may override hideNotify1() if they wish to do hide processing.

        synchronized (this) {
            shown = false;
        }
        hideNotify1();
    
public voidhideNotify1()
Subclassers should override this to do hideNotify() processing.

    
public final voidpaint(javax.microedition.lcdui.Graphics g)
Notifies when painted for the first time. This is made final so that subclassers can't accidentally break this if they override and forget to call super(). Subclassers should override paint1() to do actual painting.

        synchronized (this) {
            if (!painted) {
                painted = true;
                notifyAll();
            }
        }
        paint1(g);
    
public voidpaint1(javax.microedition.lcdui.Graphics g)
Subclassers should override this to do actual painting.



                 
        
    
public synchronized booleanshowCalled()
Returns a boolean indicating whether showNotify has been called on this canvas more recently than hideNotify. This differs from the Displayable.isShown() method, which checks the internal state of the Displayable object.

        return shown;
    
public final voidshowNotify()
Tracks the shown state. If this is the first time the Canvas is being shown, sets everShown and does a monitor notify. This is made final so that subclassers can't accidentally break the protocol if they override and forget to call super(). Subclassers may override showNotify1() if they wish to do show processing.

        synchronized (this) {
            shown = true;
            if (!everShown) {
                everShown = true;
                notifyAll();
            }
        }
        showNotify1();
    
public voidshowNotify1()
Subclassers should override this to do showNotify() processing.

    
public synchronized booleanwasShown()
Returns a boolean indicating whether showNotify() has ever been called at any time since the canvas was created.

        return everShown;