📄 courseitem.java
字号:
package ui.unit;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CustomItem;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import clasAn.core.GUIInfo;
import ui.TextInput;
/**
*
* @version 2.0
*/
public class CourseItem extends CustomItem implements ItemCommandListener,
Runnable {
private static final Command CMD_EDIT = new Command(GUIInfo.COMMAND_EDIT, Command.ITEM, 1);
private static final int UPPER = 0;
private static final int IN = 1;
private static final int LOWER = 2;
// private static final String[8]={"第一节","第二节","第二节"}
private Display display;
private int maxSize = 4;
private Font font;
private int fontHeight;
private int width;
private String time;
private String content = "空";
private String rollingContent;
private int location = UPPER;
private int frameDelay = 1000;
boolean sleeping = true;
private Thread t = null;
private boolean isEdited = false;
// Traversal stuff
// indicating support of horizontal traversal internal to the CustomItem
boolean horz;
// indicating support for vertical traversal internal to the CustomItem.
boolean vert;
public CourseItem(String title, String time, String content, int maxSize,
Display d) {
super(title);
this.display = d;
this.time = time;
this.content = content;
this.maxSize = this.maxSize <= maxSize ? maxSize : this.maxSize;
this.rollingContent = contentAddBlank();
font = Font.getDefaultFont();
fontHeight = font.getHeight();
width = font.charWidth('我') * this.maxSize;
System.out.println(width);
setDefaultCommand(CMD_EDIT);
setItemCommandListener(this);
int interactionMode = getInteractionModes();// 获得可实现的交互模式
horz = ((interactionMode & CustomItem.TRAVERSE_HORIZONTAL) != 0);
vert = ((interactionMode & CustomItem.TRAVERSE_VERTICAL) != 0);
}
protected int getMinContentHeight() {
return fontHeight;
}
protected int getMinContentWidth() {
return font.stringWidth(this.getLabel()) + 3;
}
protected int getPrefContentHeight(int width) {
return fontHeight * 2 + 2;
}
// 获得首选宽度
protected int getPrefContentWidth(int height) {
return this.width + 3;
}
private String rollString(String s, int offset) {
String tmpsString;
tmpsString = s.substring(offset, s.length());
System.out.println(tmpsString
+ s.substring(s.length() - tmpsString.length(), s.length()));
return tmpsString + s.substring(0, offset);
}
// 画图
protected void paint(Graphics g, int w, int h) {
int dy = 0;
g.setColor(0xffffff);
g.fillRect(0, 0, width + 3, 2 * font.getHeight());
if (location != IN)
g.setColor(0x000000);
else
g.setColor(0x0000ff);
g.drawString(this.time, 2, dy, Graphics.TOP | Graphics.LEFT);
dy += font.getHeight();
g.drawString(this.rollingContent, 2, dy, Graphics.TOP | Graphics.LEFT);
g.setStrokeStyle(Graphics.DOTTED);
g.drawRect(0, 0, width + 2, dy + font.getHeight());
}
// 横贯来回移动 //动作
protected boolean traverse(int dir, int viewportWidth, int viewportHeight,
int[] visRect_inout) {
if (font.stringWidth(content) > width)
this.start();
// 可以水平和纵向移动
if (horz && vert) {
switch (dir) {
case Canvas.DOWN:
if (location == UPPER) {// 如果选择框在Table的上方
location = IN;// 位置为进入
repaint();
} else if (location == IN) {
location = LOWER;
return false;
}
break;
case Canvas.UP:
if (location == LOWER) {
location = IN;
repaint();
} else if (location == IN) {
location = UPPER;
return false;
}
break;
case Canvas.LEFT:
// System.out.println("内容左移");
if (font.stringWidth(content) > width)
this.rollingContent = this.rollString(rollingContent, 1);
repaint();
break;
case Canvas.RIGHT:
// System.out.println("内容 右移");
}
} else {// 不能水平和纵向移动
// In case of no Traversal at all: (horz|vert) == 0
}
// visRect_inout[0]=0;
// visRect_inout[1]=12;
// visRect_inout[2]=32;
// visRect_inout[3]=32;
return true;
}
public void start() {
this.sleeping = false;
t = new Thread(this);
t.start();
}
public void stop() {
sleeping = true;
}
public void run() {
// TODO Auto-generated method stub
while (!sleeping) {
try {
Thread.sleep(frameDelay);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (!sleeping)
this.rollingContent = rollString(rollingContent, 1);
repaint();
}
}
protected void traverseOut() {
this.stop();
t = null;
this.rollingContent = contentAddBlank();
repaint();
}
// 设置表格内容
public void setContent(String text) {
//如果输入的文本不为空
if (text.length() != 0) {
//如果输入的文本与原课程内容不一致
if (!text.endsWith(this.content)) {
this.setEdited(true);
this.content = text;
}
} else {
this.setEdited(false);
}
rollingContent = contentAddBlank();
repaint();
}
// 获得课程内容
public String getContent() {
return this.content;
}
private String contentAddBlank() {
return this.content + " ";
}
// 获取是否编辑过标志
public boolean isEdited() {
return this.isEdited;
}
// 设置是否编辑过标志
private void setEdited(boolean e) {
this.isEdited = e;
}
public void commandAction(Command c, Item i) {
if (c == CMD_EDIT) {
TextInput textInput = new TextInput(this.content, this, display);
display.setCurrent(textInput);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -