📄 eventloglistui.java
字号:
package org.placelab.midp;import java.util.Date;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.Form;import javax.microedition.lcdui.Spacer;import javax.microedition.lcdui.StringItem;import javax.microedition.rms.RecordEnumeration;import javax.microedition.rms.RecordStoreException;import org.placelab.util.StringUtil;public class EventLogListUI implements UIComponent, CommandListener { Form browseForm = null; Display display = null; UIComponent back = null; RecordEnumeration re = null; int curRec = 0; int showAtMost = 5; Command next10Command = null; Command backCommand = null; //Command uploadCommand = null; Command clearCommand = null; public EventLogListUI(Display display, UIComponent back) { this.display=display; this.back=back; } public void setContent() throws RecordStoreException { if ((re == null) || (!re.hasNextElement())) { re = null; return; } int min = curRec; int max = min + showAtMost; if (max > EventLogger.numRecords()) { max = EventLogger.numRecords(); //recordCount; } browseForm.deleteAll(); for (int i = min; i < max; i++) { if ((re != null) && re.hasNextElement()) { try { curRec++; String s = new String(re.nextRecord()); String[] sarr = StringUtil.split(s, '|'); int idx = Integer.parseInt(sarr[1]); String stat = null; try { long l = (new Date().getTime() - Long.parseLong(sarr[0]))/1000; long lo = l; long sec = l%60; l /= 60; long mn = l%60; l /= 60; stat = "-" + l + ":" + mn + ":" + sec; } catch (Exception ex) {;}//stat = ex.getClass().getName() + ex.getMessage();} if ((idx < 0) || (idx >= EventLogger.getNumEventTypes() || EventLogger.getEventType(new Integer(idx)) == null)) { stat = stat + " Unknown"; } else { stat = stat + " " + EventLogger.getEventType(new Integer(idx));//[idx]; } String msg = sarr[2]; browseForm.append(new StringItem(stat, msg + "\n")); browseForm.append(new Spacer(0, 4)); } catch (Exception ex) { ; } } else { browseForm.append(new StringItem("","End of records")); } } if(max == 0) { browseForm.append(new StringItem("","No records")); } setTitle(min, max); if ((re == null) || (!re.hasNextElement())) { re = null; browseForm.removeCommand(next10Command); } } public void setTitle(int min, int max) { String numrecs = "unknown"; numrecs = ""+ EventLogger.numRecords(); browseForm.setTitle("Event Log (" + (min + 1) + "-" + max + " of " + numrecs + ")"); } public void commandAction(Command c, Displayable s) { if (c.getLabel().startsWith("Next")) { try { setContent(); } catch (RecordStoreException e) { e.printStackTrace(); } } if (c.getLabel().startsWith("Back")) { back.showUI(this);//display.setCurrent(back); } } public void showUI(UIComponent from) { if (browseForm == null) { browseForm = new Form("Event Log"); next10Command = new Command("Next " + showAtMost, Command.SCREEN, 1); backCommand = new Command("Back", Command.BACK, 1); //uploadCommand = new Command("Upload", Command.ITEM, 1); clearCommand = new Command("Clear", Command.ITEM,1); //browseForm.addCommand(uploadCommand); } else { browseForm.deleteAll(); browseForm.removeCommand(next10Command); browseForm.removeCommand(backCommand); } curRec = 0; if (EventLogger.numRecords() > showAtMost) { browseForm.addCommand(next10Command); } if (back != null) { browseForm.addCommand(backCommand); } browseForm.setCommandListener(this); display.setCurrent(browseForm); try { re = EventLogger.getRecords(null, null, false); if(!re.hasNextElement()) { browseForm.append(new StringItem("","No records")); browseForm.setTitle("Event Log"); } else { setContent(); } } catch(RecordStoreException rse) { browseForm.append(new StringItem("Error", ""+rse)); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -