LogForm.java
上传用户:kyckim
上传日期:2007-12-11
资源大小:332k
文件大小:3k
- package Hiisi;
- import javax.microedition.lcdui.Alert;
- import javax.microedition.lcdui.AlertType;
- 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.Item;
- import javax.microedition.lcdui.Spacer;
- import javax.microedition.lcdui.StringItem;
- public class LogForm extends Form implements CommandListener{
-
- private long sentByte = 0;
- private long recvdByte = 0;
-
- long getSentByte() {
- return sentByte;
- }
- long addSentByte(int b) {
- sentByte += b;
- return sentByte;
- }
- long getRecvdByte() {
- return recvdByte;
- }
- long addRecvdByte(int b) {
- recvdByte += b;
- return recvdByte;
- }
-
- // opeiton metus
- private Command[] command = new Command[2];
-
- // constructor
- LogForm() {
- super(HiisiMIDlet.hiisiMIDlet.proxyName);
-
- totalLog(0, 0);
-
- command[0] = new Command("Back", Command.EXIT, 1);
- command[1] = new Command("Clear", Command.SCREEN, 2);
- addCommand(command[0]);
- addCommand(command[1]);
- setCommandListener(this);
- }
-
- // adds HTTP log
- synchronized void log(String msg) {
- int logSize = size();
- if(logSize > 6 && !HiisiMIDlet.settingForm.isLogEnable()) {
- for(int i = logSize; i > 6; i--) delete(i - 1);
- }
- insert(2, new StringItem("", msg));
- }
-
- synchronized void totalLog(long sent, long recvd) {
- if(size() == 0) {
- append("Sent: " + sent/1024 + "KB, Recvd.: " + recvd/1024 + "KBn");
- Spacer spacer = new Spacer(5, 5);
- spacer.setLayout(Item.LAYOUT_2|Item.LAYOUT_NEWLINE_AFTER);
- append(spacer);
- } else {
- set(0, new StringItem("","Sent: " + sent/1024 + "KB, Recvd.: " + recvd/1024 + "KBn"));
- }
- }
-
- // comfirmation for delete log
- private void makeConfirmationAlert() {
- final Command[] cmd = new Command[2];
- Alert confirm = new Alert("Clear log",
- "You are about to delete your entire proxy log. Do you wish to continue?", null, AlertType.WARNING);
- confirm.setTimeout(Alert.FOREVER);
- cmd[0] = new Command("Yes", Command.OK, 1);
- cmd[1] = new Command("No", Command.CANCEL, 2);
- confirm.addCommand(cmd[0]);
- confirm.addCommand(cmd[1]);
- confirm.setCommandListener(
- new CommandListener() {
- public void commandAction(Command c, Displayable d) {
- if(c == cmd[0]) {
- deleteAll();
- totalLog(getSentByte(), getRecvdByte());
- }
- Display.getDisplay(HiisiMIDlet.hiisiMIDlet).setCurrent(HiisiMIDlet.logForm);
- }
- }
- );
- Display.getDisplay(HiisiMIDlet.hiisiMIDlet).setCurrent(confirm);
- }
-
- // actions of option menus
- public void commandAction(Command c,Displayable d) {
- // back
- if(c == command[0]) {
- Display.getDisplay(HiisiMIDlet.hiisiMIDlet).setCurrent(HiisiMIDlet.mainForm);
- }
- // clears log
- if(c == command[1]) {
- makeConfirmationAlert();
- }
- }
- }