📄 listelement.java
字号:
package com.ismyway.fairyui;
import javax.microedition.lcdui.Graphics;
import com.ismyway.anyview.others.Settings;
import com.ismyway.util.Theme;
public class ListElement extends DisplayableBlock {
private boolean checked = false;
private String text = "";
private boolean radioType = false;
private Row container;
///以下为私有变量,用于控制动画显示
private boolean animate = false;
private int animateX = 0; //偏移的X坐标
private int animateLen = 0; //可用于动画的步长
private boolean dec = true; //X坐标增加还是减少的标志位
private int delayStep = 0; //停留10步后再开始动画
public ListElement() {
}
public ListElement(String text, boolean checked) {
this.text = text;
this.checked = checked;
}
public void paint(Graphics g, int adjustx, int adjusty) {
//System.out.println("ListElement.paint()");
int x, y;
x = getLeft() - adjustx;
y = getTop() - adjusty;
int disx = getFont().getHeight() / 2 - 5;
Theme.drawRadioElement(g, x, y + disx, radioType, isChecked());
x += 14;
int clipWidth = getWidth() - 18;
g.setClip(x, y, clipWidth, getHeight());
//System.out.println("ListElement.paint() " + x + ", " + y);
g.setFont(getFont());
if (isSelected()) {
g.setColor(Theme.TextShade);
g.fillRect(x, y, getFont().stringWidth(text), 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 boolean isChecked() {
return checked;
}
public void setChecked(boolean checked) {
this.checked = checked;
}
public void setType(boolean type) {
radioType = type;
}
public boolean isRadioType() {
return radioType;
}
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 (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 void setContainer(Row container) {
this.container = container;
}
public boolean generateEvent() {
container.addCommand(getCommand());
return container.generateEvent();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -