📄 stringitem.java
字号:
package com.ismyway.fairyui;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import com.ismyway.anyview.others.Settings;
import com.ismyway.util.Theme;
public class StringItem extends DisplayableBlock {
private String text = "";
private Image image;
private Object data = null;
//以下为私有变量,用于控制动画显示
private boolean animate = false;
private int animateX = 0; //偏移的X坐标
private int animateLen = 0; //可用于动画的步长
private boolean dec = true; //X坐标增加还是减少的标志位
private int delayStep = 0; //停留10步后再开始动画
public StringItem(String text) {
this(text, null);
}
public StringItem(String text, Image image) {
this.text = text;
this.image = image;
addCommand(new Command(text, Command.OK, 1));
}
public void paint(Graphics g, int adjustx, int adjusty) {
//System.out.println("ListElement.paint()");
int x, y;
x = getLeft() - adjustx;
y = getTop() - adjusty;
int clipWidth = getWidth();
if (null != image) {
g.setClip(x, y, 16, 16);
g.drawImage(image, x, y, LEFTTOP);
restoreClip(g);
}
x += 18;
clipWidth -= 18;
g.setClip(x, y, clipWidth, getHeight());
g.setFont(getFont());
if (isSelected()) {
Theme.drawSelectedBackground(g, x, y, clipWidth, getHeight());
g.setColor(Theme.TextLight);
g.drawString(text, x - animateX, y, ANCHOR);
} else {
g.setColor(Theme.TextColor);
g.drawString(text, x - animateX, y, ANCHOR);
}
restoreClip(g);
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public void setSelected(boolean b) {
super.setSelected(b);
if (!b) {
animateX = 0;
dec = true;
delayStep = 0;
}
}
public boolean isAnimated() {
if (isSelected() && animate && delayStep > 10) {
return true;
}
delayStep++;
return false;
}
public boolean clock() {
if (isAnimated()) {
if (dec) {
animateX++;
if (animateX > animateLen) {
dec = !dec;
}
} else {
animateX--;
if (animateX == 0) {
dec = !dec;
}
}
return true;
}
return false;
}
public void validate() {
}
public void putInSequence(int[] rect, int width) {
int height = getFont().getHeight();
if (null != image) {
int imgHeight = image.getHeight();
imgHeight = imgHeight > 16 ? 16 : imgHeight;
height = imgHeight > height ? imgHeight : height;
}
if (rect[0] != Settings.VECPADDING) {
rect[1] = rect[1] + rect[3] + Settings.HORPADDING;
rect[0] = Settings.VECPADDING;
rect[3] = 1;
rect[2] = width;
}
setInnerLeft(rect[0]);
setInnerTop(rect[1]);
setWidth(width);
setHeight(height);
animateLen = getFont().stringWidth(text) - width + 18;
animate = animateLen > 0;
rect[0] = Settings.VECPADDING;
rect[1] = getInnerTop() + getHeight() + Settings.HORPADDING;
rect[2] = width;
rect[3] = 1;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -