📄 bqalert.java
字号:
/*
* Created on 2005-9-21 by pcy
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package a.a.a.midp.lcdui;
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.lcdui.*;
import a.a.a.b.Resource;
public class BQAlert extends BQScreen {
public static final long serialVersionUID=1;
private BQDisplayable nextDisplayable;
private static final Command OK =
new Command(Resource.getString("Done"), Command.OK, 0);
/**
* Default spacing between elements of this Alert
*/
private static final int CELL_SPACING = 6;
/**
* Number of pixels to scroll when using up/down keys
*/
private static final int SCROLL_AMOUNT = 40;
/**
* The default timeout of all alerts
*/
private static final int DEFAULT_TIMEOUT = 2000;
/**
* The type of this alert
*/
private BQAlertType type;
/**
* The layout object for the alert text string
*/
private String text;
/**
* The image of this alert
*/
private BQImage image;
/**
* A reference to the original, mutable Image passed to setImage(). This
* is only so getImage() can return the correct Image Object.
*/
private BQImage mutableImage;
/**
* The activity indicator for this alert
*/
private BQGauge indicator;
/**
* The timeout value of this alert
*/
private int time;
/**
* The overall height of this alert
*/
private int height;
/**
* A Timer which serves all Alert objects to schedule
* their timout tasks
*/
private static Timer timeoutTimer=new Timer();
/**
* A TimerTask which will be set to expire this Alert after
* its timeout period has elapsed.
*/
//private TimerTask timerTask;
/**
* The screen which the display will return to when this Alert
* is completed
*/
private BQDisplayable returnScreen;
/**
* The application's command listener
*/
private BQCommandListener userCommandListener;
public BQAlert(String title,
String alertText,
BQImage alertImage,
BQAlertType alertType){
super(title);
this.time = DEFAULT_TIMEOUT;
this.text = alertText;
this.type = alertType;
setImageImpl(alertImage);
}
public int getDefaultTimeout(){
return DEFAULT_TIMEOUT;
}
public int getTimeout(){
if ((height > super.getDisplayHeight()) || (getCommandCount() > 1)) {
return Alert.FOREVER;
} else {
return time;
}
}
public void setTimeout(int time){
if (time <= 0 && time != Alert.FOREVER) {
throw new IllegalArgumentException();
}
this.time = time;
}
public BQAlertType getType(){
return type;
}
public void setType(BQAlertType type){
this.type = type;
}
public String getString(){
return text;
}
public void setString(String str){
text = str;
}
public BQImage getImage(){
if (mutableImage != null) {
return mutableImage;
} else {
return image;
}
}
public void setImage(BQImage img){
setImageImpl(img);
}
public void setIndicator(BQGauge indicator){
if (indicator == null) {
if (this.indicator != null) {
this.indicator.setOwner(null);
}
} else {
if (!isConformantIndicator(indicator)) {
throw new IllegalArgumentException("Gauge in wrong state");
}
indicator.setOwner(this);
}
if (this.indicator != null) {
this.indicator.setOwner(null);
}
this.indicator = indicator;
}
public BQGauge getIndicator(){
return indicator;
}
/*
public void setCommandListener(BQCommandListener l){
userCommandListener = l;
}*/
void setImageImpl(BQImage img) {
if (img != null && img.isMutable()) {
this.image = BQImage.createImage(img); // use immutable copy of img
this.mutableImage = img;
} else {
this.image = img;
this.mutableImage = null; // Make sure to clear mutableImage
}
}
void showNotify(){
if(this.getTimeout()!=Alert.FOREVER){
timeoutTimer.schedule(new TimerTask(){
public void run(){
dismiss();
}
},time);
}
}
void hideNotify(){
}
boolean isConformantIndicator(BQGauge ind) {
return ((ind.isInteractive() == false) &&
(ind.getOwner() == null) &&
(ind.getCommandCount() == 0) &&
(ind.getItemCommandListener() == null) &&
(ind.getLabel() == null) &&
(ind.getMLayout() == Item.LAYOUT_DEFAULT) &&
(ind.lockedWidth == -1) &&
(ind.lockedHeight == -1));
}
private void dismiss(){
Display.getDisplay(null).setCurrent(nextDisplayable.shell);
}
public void setNextDisplayable(BQDisplayable d){
nextDisplayable=d;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -