SystemAlertpublic class SystemAlert extends Alert implements CommandListener, RunnableDisplay a preempting alert and wait for the user to acknowledge it. |
Fields Summary |
---|
private Object | preemptTokenPreempt token for displaying errors. | private DisplayEventHandler | displayEventHandlerThe display event handler for displaying errors. | private CommandListener | explicitListenerExplicit command lstener for this alert, null if not set. | private final Object | listenerLockSynchronization lock for setting explicit command listener. | private boolean | shownFlag 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 .
super(title, text, image, type);
setTimeout(Alert.FOREVER);
super.setCommandListener(this);
this.displayEventHandler = displayEventHandler;
|
Methods Summary |
---|
public void | commandAction(Command c, Displayable s)Respond to a command issued on this alert.
synchronized (listenerLock) {
if (null != explicitListener) {
explicitListener.commandAction(c, s);
} else {
dismiss();
}
}
| public synchronized void | dismiss()Dismiss the alert
if (shown) {
notify(); // wait up waitForUser() thread
displayEventHandler.donePreempting(preemptToken);
preemptToken = null;
shown = false;
}
| public synchronized void | run()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 void | runInNewThread()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 void | setCommandListener(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.
synchronized (listenerLock) {
explicitListener = cl;
}
| public synchronized void | waitForUser()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");
}
}
|
|