📄 menu.java
字号:
imSendallAct = Functions.getIcon("act_sendall.png");
imPollAct = Functions.getIcon("act_poll.png");
imPrimaryAcc = Functions.getIcon("acc_primary.png");
imActiveAcc = Functions.getIcon("acc_active.png");
imInActiveAcc = Functions.getIcon("acc_inactive.png");
imBook = Functions.getIcon("addressbook.png");
imClearDB = Functions.getIcon("act_clear.png");
imDisc = Functions.getIcon("act_disc.png");
imSync = Functions.getIcon("act_sync.png");
imTaskManager = Functions.getIcon("task_manager.png");
//#ifdef MUJMAIL_SEARCH
imSearch = Functions.getIcon("search.png");
//#endif
//#ifdef MUJMAIL_SYNC
imBackup = Functions.getIcon("act_backup.png");
imRestore = Functions.getIcon("act_restore.png");
//#endif
imAbout = Functions.getIcon("help.png");
//#ifdef MUJMAIL_DEBUG_CONSOLE
imDebug = Functions.getIcon("menu_debug.png");
//#endif
addCommand(clear);
addCommand(exit);
addCommand(cmdNew);
addCommand(change);
addCommand(delete);
addCommand(setPrimary);
addCommand(retrieve);
setCommandListener(this);
init();
//#ifdef MUJMAIL_TOUCH_SCR
pointerEventTransformer = new MujMailPointerEventProducer(new MenuPointerEventListener(), getWidth(), getHeight());
//#endif
}
private void init() {
// ACTION menu
byte i = 0;
tabs[i] = new MenuTab();
tabs[i].name = Lang.get(Lang.AC_ACTIONS);
tabs[i].actionKey = KEY_NUM1; //a keyboard shortcut
tabs[i].img = imAction; //an icon
tabs[i].item = new Vector(MENU_ACT_SIZE);
tabs[i].item.setSize(MENU_ACT_SIZE);
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.TB_INBOX), null, KEY_NUM1, imInbox), MENU_ACT_INBOX);
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.AC_RETRIEVE_MAILS), null, KEY_NUM2, imRetrieveAct), MENU_ACT_RETRIEVE_MAILS);
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.AC_WRITE_MAIL), null, KEY_NUM3, imWriteAct), MENU_ACT_WRITE_MAIL);
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.AC_SENDALL), null, KEY_NUM4, imSendallAct), MENU_ACT_SENDALL);
//#ifdef MUJMAIL_SEARCH
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.AC_SEARCH_MAILS), null, KEY_NUM5, imSearch), MENU_ACT_SEARCH_MAILS);
//#endif
//tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.AC_POLLING), "(" + Lang.get(Lang.INACTIVE) + ")", KEY_NUM6, imPollAct), ... NOT POSITION DEFINED NOW);
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.AC_PUSH) + " (" + Lang.get(Lang.INACTIVE) + ")", null, KEY_NUM6, imPollAct), MENU_ACT_PUSH);
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.AC_DISCONNECT), null, KEY_NUM7, imDisc), MENU_ACT_DISCONNECT);
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.AC_SERVERS_INBOX_SYNC), null, KEY_NUM9, imSync), MENU_ACT_SERVERS_INBOX_SYNC);
++i;
// FOLDERS menu
tabs[i] = new MenuTab();
tabs[i].name = Lang.get(Lang.TB_FOLDERS);
tabs[i].actionKey = KEY_NUM3;
tabs[i].img = imFolders;
tabs[i].item = new Vector(MENU_FOLDERS_USERBOX_FIRST);
tabs[i].item.setSize(MENU_FOLDERS_SEPARATOR); // Currently we set only 5 elements
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.TB_INBOX) + " (0/0)", null, KEY_NUM1, null), MENU_FOLDERS_INBOX);
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.TB_OUTBOX) + " (0)", null, KEY_NUM2, null), MENU_FOLDERS_OUTBOX);
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.TB_SENTBOX) + " (0)", null, KEY_NUM3, null), MENU_FOLDERS_SENTBOX);
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.TB_DRAFT) + " (0)", null, KEY_NUM4, null), MENU_FOLDERS_DRAFT);
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.TB_TRASH) + " (0)", null, KEY_NUM5, null), MENU_FOLDERS_TRASH);
//Initialy no user folders are present. After loading folders from DB, refresh method is called
++i;
// SETTINGS menu
tabs[i] = new MenuTab();
tabs[i].name = Lang.get(Lang.ST_SETTINGS);
tabs[i].actionKey = KEY_NUM4;
tabs[i].img = imSettings;
tabs[i].item = new Vector(MENU_SETTINGS_SIZE);
tabs[i].item.setSize(MENU_SETTINGS_SIZE);
tabs[i].item.setElementAt(new MenuItem("Appearance", null, -1, null), MENU_SETTINGS_APPEARANCE);
tabs[i].item.setElementAt(new MenuItem("MujMail server", null, -1, null), MENU_SETTINGS_MUJMAIL_SERVER);
tabs[i].item.setElementAt(new MenuItem("Other", null, -1, null), MENU_SETTINGS_OTHER);
tabs[i].item.setElementAt(new MenuItem("Polling", null, -1, null), MENU_SETTINGS_POLLING);
tabs[i].item.setElementAt(new MenuItem("Retrieving mails", null, -1, null), MENU_SETTINGS_RETRIEVING);
tabs[i].item.setElementAt(new MenuItem("SMTP", null, -1, null), MENU_SETTINGS_SMTP);
tabs[i].item.setElementAt(new MenuItem("Storing mails", null, -1, null), MENU_SETTINGS_STORING_MAILS);
++i;
// ACCOUNTS menu
tabs[i] = new MenuTab();
tabs[i].name = Lang.get(Lang.AC_ACTIONS);
tabs[i].actionKey = KEY_NUM5;
tabs[i].img = imAccounts;
++i;
// UTILITIES menu
tabs[i] = new MenuTab();
tabs[i].name = Lang.get(Lang.UT_UTILS);
tabs[i].actionKey = KEY_NUM6;
tabs[i].img = imUtilities;
tabs[i].item = new Vector(MENU_UTILS_SIZE);
tabs[i].item.setSize(MENU_UTILS_SIZE);
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.AD_ADDRESSBOOK), null, KEY_NUM1, imBook), MENU_UTILS_ADRESSBOOK);
//#ifdef MUJMAIL_SYNC
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.AC_BACKUP_SETTINGS), null, KEY_NUM0, imBackup), MENU_UTILS_BACKUP_SETTINGS);
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.AC_RESTORE_SETTINGS), null, KEY_NUM0, imRestore), MENU_UTILS_RESTORE_SETTINGS);
//#endif
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.AC_CLEAR_DB), null, KEY_NUM8, imClearDB), MENU_UTILS_CLEAR_DB);
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.ABT_ABOUT), null, KEY_NUM2, imAbout), MENU_UTILS_ABOUT);
//#ifdef MUJMAIL_DEBUG_CONSOLE
tabs[i].item.setElementAt(new MenuItem(Lang.get(Lang.DEB_MENU), null, KEY_NUM3, imDebug), MENU_UTILS_DEB_MENU);
//#endif
tabs[i].item.setElementAt(new MenuItem("Task manager", null, KEY_NUM4, imTaskManager), MENU_UTILS_TASK_MANAGER);
tabs[i].item.setElementAt(new MenuItem("Start sample task", null, KEY_NUM5, null), MENU_UTILS_RUN_SAMPLE_TASK);
setSelectedTab((byte) 0);
}
public void refreshAll(boolean displayMenu) {
refresh(ACTION, false);
refresh(FOLDERS, false);
refresh(SETTINGS, false);
refresh(ACCOUNTS, false);
if (displayMenu) {
repaint();
mujMail.getDisplay().setCurrent(this);
}
}
public void refresh(byte tabContext, boolean displayMenu) {
String prefix = " (";
byte refreshAgain = -1;
try {
if (tabContext == ACTION) {
//if it's busy display the * signaling that numbers are just estimated
if (mujMail.getInBox().isBusy() && getSelectedTab() == ACTION) {
prefix = " *(";
refreshAgain = ACTION;
}
if (DEBUG) { System.out.println("DEBUG Menu.refresh() - inbox storage: " + mujMail.getInBox().getStorage()); }
((MenuItem) tabs[tabContext].item.elementAt(MENU_ACT_INBOX)).name = Lang.get(Lang.TB_INBOX) +
prefix + mujMail.getInBox().getUnreadMailsCount() + "/" +
mujMail.getInBox().getMessageCount() + ")";
if (DEBUG) { System.out.println("DEBUG Menu.refresh() - outBox storage: " + mujMail.outBox.storage); }
String saCounter = "";
if (mujMail.outBox.isBusy() && getSelectedTab() == ACTION) {
refreshAgain = ACTION;
saCounter = " *(" + mujMail.outBox.getMessageCount() + ")";
} else if (mujMail.outBox.getMessageCount() != 0) {
saCounter = " (" + mujMail.outBox.getMessageCount() + ")";
}
((MenuItem) tabs[tabContext].item.elementAt(MENU_ACT_SENDALL)).name = Lang.get(Lang.AC_SENDALL) + saCounter;
// Updating state of pushing
if (DEBUG) { System.out.println("DEBUG Menu.refresh() - mujMail: " + mujMail); }
if ( mujMail.getInBox().isPushActive() ) {
((MenuItem) tabs[tabContext].item.elementAt(MENU_ACT_PUSH)).name = Lang.get(Lang.AC_PUSH) + " (" + Lang.get(Lang.ACTIVE) + ")";
} else {
((MenuItem) tabs[tabContext].item.elementAt(MENU_ACT_PUSH)).name = Lang.get(Lang.AC_PUSH) + " (" + Lang.get(Lang.INACTIVE) + ")";
}
} else
if (tabContext == FOLDERS) {
// Inbox - updating state
if (mujMail.getInBox().isBusy() && getSelectedTab() == FOLDERS) {
prefix = " *(";
refreshAgain = ACTION;
}
((MenuItem) tabs[tabContext].item.elementAt(MENU_FOLDERS_INBOX)).name = Lang.get(Lang.TB_INBOX) + " " +
prefix + mujMail.getInBox().getUnreadMailsCount() + "/" +
mujMail.getInBox().getMessageCount() + ")";
// Outbox - updating state
if (mujMail.outBox.isBusy() && getSelectedTab() == FOLDERS) {
prefix = " *(";
refreshAgain = FOLDERS;
} else {
prefix = "(";
}
((MenuItem) tabs[tabContext].item.elementAt(MENU_FOLDERS_OUTBOX)).name = Lang.get(Lang.TB_OUTBOX) + " " + prefix + mujMail.outBox.getMessageCount() + ")";
// SentBox - updating state
if (mujMail.getSentBox().isBusy() && getSelectedTab() == FOLDERS) {
prefix = " *(";
refreshAgain = FOLDERS;
} else {
prefix = "(";
}
((MenuItem) tabs[tabContext].item.elementAt(MENU_FOLDERS_SENTBOX)).name = Lang.get(Lang.TB_SENTBOX) + " " + prefix + mujMail.getSentBox().getMessageCount() + ")";
// Drafts - updating state
if (mujMail.draft.isBusy() && getSelectedTab() == FOLDERS) {
prefix = " *(";
refreshAgain = FOLDERS;
} else {
prefix = "(";
}
((MenuItem) tabs[tabContext].item.elementAt(MENU_FOLDERS_DRAFT)).name = Lang.get(Lang.TB_DRAFT) + " " + prefix + mujMail.draft.getMessageCount() + ")";
// Trash - updating state
if (mujMail.getTrash().isBusy() && getSelectedTab() == FOLDERS) {
prefix = " *(";
refreshAgain = FOLDERS;
} else {
prefix = "(";
}
((MenuItem) tabs[tabContext].item.elementAt(MENU_FOLDERS_TRASH)).name = Lang.get(Lang.TB_TRASH) + " " + prefix + mujMail.getTrash().getMessageCount() + ")";
//#ifdef MUJMAIL_USR_FOLDERS
// User folders
// Note user folder use only name, no other parameters from MenuItem (picture, shortcut key or value)
Vector userMailBoxes = mujMail.getUserMailBoxes().getBoxList();
int userMailBoxesSize = userMailBoxes.size();
synchronized(this) {
/* We update size of tabs folders array /
if we repaint in time before entrie setting is done
we can fall down on null dereference --> synchronisation is needed
*/
// Prepare item array to have correct length
if (userMailBoxesSize == 0) {
// 1) Last user mailbox removed - no separator
tabs[tabContext].item.setSize(MENU_FOLDERS_SEPARATOR);
} else {
tabs[tabContext].item.setSize(MENU_FOLDERS_USERBOX_FIRST + userMailBoxesSize);
// Set separator
if (tabs[tabContext].item.elementAt(MENU_FOLDERS_SEPARATOR) == null) {
tabs[tabContext].item.setElementAt(new MenuItem(null, null, -1, null), MENU_FOLDERS_SEPARATOR);
}
((MenuItem) tabs[tabContext].item.elementAt(MENU_FOLDERS_SEPARATOR)).name = "-----------------";
}
// Check if position is not out of range (otherwise set to last position)
if ((tabContext == currTab) && (currItem >= tabs[tabContext].item.size()-1)) {
setSelectedItem((short)(tabs[tabContext].item.size()-1));
}
// Setting user folder names
for( int i = 0; i < userMailBoxesSize; i++) {
InBox userBox = (InBox)userMailBoxes.elementAt(i);
if (userBox.isBusy() && getSelectedTab() == FOLDERS) {
prefix = " *(";
refreshAgain = FOLDERS;
} else {
prefix = "(";
}
if (tabs[tabContext].item.elementAt(MENU_FOLDERS_USERBOX_FIRST + i) == null) {
tabs[tabContext].item.setElementAt(new MenuItem(null, null, -1, null), MENU_FOLDERS_USERBOX_FIRST + i);
}
((MenuItem)tabs[tabContext].item.elementAt(MENU_FOLDERS_USERBOX_FIRST + i)).name = userBox.getName() + " " + prefix + userBox.getUnreadMailsCount() + "/" + userBox.getMessageCount() + ")";
}
}
//#endif
} else
if (tabContext == ACCOUNTS) {
// Display only primary mail accounts
Hashtable /*<String, MailAccountPrimar>*/ accounts = mujMail.getMailAccounts();
tabs[tabContext].item = new Vector(accounts.size());
short i = 1;
for (Enumeration e = accounts.elements(); e.hasMoreElements();) {
MailAccount account = (MailAccount) e.nextElement();
String info = account.isActive() ? Lang.get(Lang.ACTIVE) : Lang.get(Lang.INACTIVE);
Image img = imInActiveAcc;
//an account must be active in order to be primary,
//so if it has icon imPrimary, it means its active and also primary
if (Settings.primaryEmail.equals(account.getEmail())) {
info += " | " + Lang.get(Lang.AS_PRIMARY);
img = imPrimaryAcc;
} else if (account.isActive()) //its active only
{
img = imActiveAcc;
}
tabs[tabContext].item.addElement(new MenuItem(account.getEmail(), info, i, img));
}
}
if (displayMenu) {
if (refreshTimer == null) { //this is not a refresh call
setTabContext(getSelectedTab());
}
repaint();
mujMail.getDisplay().setCurrent(this);
}
//if refresh is needed and it was not initiated yet
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -