?? courseitem.java
字號:
?package ui.unit;// Download by http://www.codefans.netimport 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 + -