FileDocCategorySizeDatePackage
SystemAlert.javaAPI DocphoneME MR2 API (J2ME)5669Wed May 02 18:00:24 BST 2007com.sun.midp.lcdui

SystemAlert

public class SystemAlert extends Alert implements CommandListener, Runnable
Display a preempting alert and wait for the user to acknowledge it.

Fields Summary
private Object
preemptToken
Preempt token for displaying errors.
private DisplayEventHandler
displayEventHandler
The display event handler for displaying errors.
private CommandListener
explicitListener
Explicit command lstener for this alert, null if not set.
private final Object
listenerLock
Synchronization lock for setting explicit command listener.
private boolean
shown
Flag to identify if the alert is being displayed currently.
Constructors Summary
public SystemAlert(DisplayEventHandler displayEventHandler, String title, String text, Image image, AlertType type)
Construct an SystemAlert.

param
displayEventHandler The display event handler for error display
param
title The title of the Alert
param
text The text of the Alert
param
image An Image to display on the Alert
param
type The Alert type


                                                 
      
                          
                           

        super(title, text, image, type);

        setTimeout(Alert.FOREVER);

        super.setCommandListener(this);

        this.displayEventHandler = displayEventHandler;

    
Methods Summary
public voidcommandAction(Command c, Displayable s)
Respond to a command issued on this alert.

param
c command activated by the user
param
s the Displayable the command was on.

        synchronized (listenerLock) {
            if (null != explicitListener) {
                explicitListener.commandAction(c, s);
            } else {
                dismiss();
            }
        }

    
public synchronized voiddismiss()
Dismiss the alert

        if (shown) {
            notify(); // wait up waitForUser() thread
            displayEventHandler.donePreempting(preemptToken);
            preemptToken = null;
            shown = false;
        }
    
public synchronized voidrun()
Displays this alert. Since alert displaying may be blocking, it is not allowed in the event dispatching thread. Nothing is done when the method is called from the dispatching thread, to produce a system alert from ituse runInNewThread(). Nothing is done if the alert is being displayed currently.

        shown = true;

        if (preemptToken != null) {
            return;
        }

        try {
            preemptToken =
                displayEventHandler.preemptDisplay(this, true);
        } catch (Throwable e) {
            if (Logging.REPORT_LEVEL <= Logging.WARNING) {
                Logging.report(Logging.WARNING, LogChannels.LC_CORE,
                              "Throwable while preempting Display");
            }
        }
    
public synchronized voidrunInNewThread()
Launches a new thread and displays this alert from it. Use this method to avoid blocking a thread that produces the alert. Makes nothing if the alert is being displayed currently.

        shown = true;
        new Thread(this).start();
    
public voidsetCommandListener(CommandListener cl)
Assigns explicit command listener to this alert. If an non-null explcit listener its commandAction() method is called to process a command, otherwise default dismiss() action is used.

param
cl expilict command listener, null to remove any explicit listener

        synchronized (listenerLock) {
            explicitListener = cl;
        }
    
public synchronized voidwaitForUser()
Waits for the user to acknowledge the alert.

        if (!shown) {
            return;
        }

        if (EventQueue.isDispatchThread()) {
            // Developer programming error
            throw new RuntimeException(
                "Blocking call performed in the event thread");
        }

        try {
            wait();
        } catch (Throwable t) {
            if (Logging.REPORT_LEVEL <= Logging.WARNING) {
                Logging.report(Logging.WARNING, LogChannels.LC_CORE,
                              "Throwable while SystemAlert.waitForUser");
            }
        }