📄 waitingalert.java
字号:
/*
* Created on 04.mai.2006
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package no.auc.one.portableplayer.userinterface;
import java.io.IOException;
import javax.microedition.lcdui.*;
import no.auc.one.portableplayer.utils.CancelAction;
import org.apache.log4j.Logger;
public class WaitingAlert extends Alert implements Runnable, CommandListener {
private final Logger LOG = Logger.getLogger("MUA");
Displayable prevDisp;
Display disp;
Gauge progress;
Command stop;
CancelAction action;
Thread owner;
boolean stoppable = true;
public WaitingAlert(
String title,
Display d,
CancelAction cancelAction,
Thread ownerThread) {
this(title, d, cancelAction, ownerThread, true);
}
public WaitingAlert(
String title,
Display d,
CancelAction cancelAction,
Thread ownerThread,
boolean stoppable)
{
super(title);
try {
disp = d;
action = cancelAction;
owner = ownerThread;
this.stoppable = stoppable;
progress = new Gauge(
null,
false,
Gauge.INDEFINITE,
Gauge.CONTINUOUS_RUNNING);
if (stoppable) {
stop = new Command("Stop", Command.STOP, 1);
addCommand(stop);
setCommandListener(this);
}
setString("Please wait...");
setTimeout(Alert.FOREVER); // XXX Or something more 'sophisticated'?
setType(AlertType.INFO);
setIndicator(progress);
setImage(Image.createImage("/aml_noalpha.png"));
} catch (IOException ioe) {
LOG.debug("Probably error loading aml_noalpha.png for MenuUpdateAlert");
LOG.debug(ioe);
}
}
public void start() {
System.out.println("Starting a new thread for this WA");
Thread t = new Thread(this);
t.start();
System.out.println("Thread should now be running....");
}
public void run() {
System.out.println("Running thread. Switching current display to: " + toString());
if (disp.getCurrent() != this) {
prevDisp = disp.getCurrent();
disp.setCurrent(this);
}
}
public void commandAction(Command c, Displayable d) {
if (c == stop) {
try {
setString("Stop was pressed. Cancel disco");
LOG.debug("Stop was pressed. Cancel disco");
action.cancel();
owner.interrupt();
} catch (IllegalStateException ise) {
setString(getString() + "\nIllegalStateException while stopping discovery.");
LOG.fatal("IllegalStateException while stopping discovery");
LOG.fatal(ise);
} catch (IOException ioe) {
setString(getString() + "\nIOException while stopping disco");
LOG.fatal("IOException while stopping the discovery");
LOG.fatal(ioe);
// TODO What to do next?
// 1) Change text of this alert to something like
// 'could not stop disco'
// 2) Do the removeCommand anyways...
} finally {
setString(getString() + "\nCleaning up...");
removeCommand(stop);
setCommandListener(null);
addCommand(Alert.DISMISS_COMMAND);
setTimeout(1);
setString(getString() + "\nWhat happends now?!?!?");
setString(getString() + "\nPrevDisp = " + prevDisp);
if (isShown()) {
disp.setCurrent(prevDisp);
}
}
} else {
LOG.debug("Unknown command pressed");
setString(getString() + "\r\nUnknown command pressed");
}
}
public Displayable getPrevDisplayable() {
return prevDisp;
}
public String toString() {
return getTitle() + "@" + hashCode();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -