📄 chathistory.java.svn-base
字号:
if ((Options.getBoolean(Options.OPTION_SHOW_MESS_DATE)) && (!shortMsg)) { messHeader.append('('); messHeader.append(Util.getDateString(!offline, time)); messHeader.append(')'); } if (messHeader.length() != 0) messHeader.append(": "); if (messHeader.length() != 0) { textList.addBigText(messHeader.toString(), getInOutColor(red), Font.STYLE_BOLD, messTotalCounter); if (offline || Options.getBoolean(Options.OPTION_SHOW_MESS_CLRF)) textList.doCRLF(messTotalCounter); String restoredHeadText = textList.getTextByIndex(0, false, messTotalCounter); texOffset = restoredHeadText.length(); } else texOffset = 0; if (url.length() > 0) { textList.addBigText(ResourceBundle.getString("url") + ": " + url, 0x00FF00, Font.STYLE_PLAIN, messTotalCounter); } int textColor = Options.getBoolean(Options.OPTION_MESS_COLORED_TEXT) ? getInOutColor(red) : textList.getTextColor(); JimmUI.addMessageText(textList, message, textColor, messTotalCounter); boolean contains_url = false; //#sijapp cond.if target is "MIDP2" | target is "SIEMENS2" | target is "MOTOROLA"# if (Util.parseMessageForURL(message) != null) { contains_url = true; if (texOffset == 1) textList.addCommandEx(JimmUI.cmdGotoURL, VirtualList.MENU_TYPE_RIGHT); } //#sijapp cond.end# getMessData().addElement( new MessData(red, time, texOffset, contains_url, messId)); messTotalCounter++; lastMsgTime = (shortMsg) ? lastMsgTime : time; lastDirection = red; textList.setTopItem(lastSize); textList.unlock(); } public void activate() { buildMenu(); JimmUI.setColorScheme(textList, true, -1, false); textList.activate(Jimm.display); ChatHistory.currentChat = this; ChatHistory.updateCaption_Internal(this); contact.resetUnreadMessages(); contact.setStatusImage(); JimmUI.setLastScreen(this, false); JimmUI.removeScreen(contact); } public boolean isScreenActive() { System.out.println(textList.isActive()); return textList.isActive(); } public void messageIsDelivered(int messId) { MessData data; boolean ok; for (int i = messData.size()-1; i >= 0; i--) { data = (MessData)messData.elementAt(i); if (data.getMessId() == messId) { ok = textList.replaceImages(i, JimmUI.eventPlainMessageImg, JimmUI.imgMessDeliv); if (ok) textList.repaint(); break; } } }}public class ChatHistory{ static private ChatHistory _this; static private Hashtable historyTable; static private Vector historyUins = new Vector(); public ChatHistory() { _this = this; } static { historyTable = new Hashtable(); } /* Adds a message to the message display */ static protected void addMessage(ContactItem contact, Message message) { MainThread.showTime(); synchronized (_this) { String uin = contact.getStringValue(ContactItem.CONTACTITEM_UIN); if (!historyTable.containsKey(uin)) newChatForm(contact, contact.getStringValue(ContactItem.CONTACTITEM_NAME)); ChatTextList chat = (ChatTextList) historyTable.get(uin); boolean offline = message.getOffline(); boolean visible = chat.isVisible(); if (message instanceof PlainMessage) { PlainMessage plainMsg = (PlainMessage) message; if (!visible) contact.setBooleanValue(ContactItem.CONTACTITEM_B_PLMESSAGES, true); addTextToForm(uin, contact .getStringValue(ContactItem.CONTACTITEM_NAME), plainMsg.getText(), "", plainMsg.getNewDate(), true, offline, -1); //#sijapp cond.if modules_HISTORY is "true" # if (Options.getBoolean(Options.OPTION_HISTORY)) HistoryStorage.addText ( uin, plainMsg.getText(), (byte) 0, contact.getStringValue(ContactItem.CONTACTITEM_NAME), plainMsg.getNewDate() ); //#sijapp cond.end# if (!offline) { /* Show creeping line */ JimmUI.showCreepingLine(JimmUI.getCurrentScreen(), plainMsg.getText(), contact); } } else if (message instanceof UrlMessage) { UrlMessage urlMsg = (UrlMessage) message; if (!chat.isVisible()) contact.setBooleanValue(ContactItem.CONTACTITEM_B_URLMESSAGES, true); addTextToForm(uin, contact .getStringValue(ContactItem.CONTACTITEM_NAME), urlMsg.getText(), urlMsg.getUrl(), urlMsg.getNewDate(), false, offline, -1); } else if (message instanceof SystemNotice) { SystemNotice notice = (SystemNotice) message; if (!visible) contact.setBooleanValue(ContactItem.CONTACTITEM_B_SYSNOTICES, true); if (notice.getSysnotetype() == SystemNotice.SYS_NOTICE_YOUWEREADDED) { addTextToForm(uin, ResourceBundle.getString("sysnotice"), ResourceBundle.getString("youwereadded") + notice.getSndrUin(), "", notice.getNewDate(), false, offline, -1); } else if (notice.getSysnotetype() == SystemNotice.SYS_NOTICE_AUTHREQ) { contact.setBooleanValue(ContactItem.CONTACTITEM_B_AUTREQUESTS, true); addTextToForm(uin, ResourceBundle.getString("sysnotice"), notice.getSndrUin() + ResourceBundle.getString("wantsyourauth") + notice.getText(), "", notice.getNewDate(), false, offline, -1); } else if (notice.getSysnotetype() == SystemNotice.SYS_NOTICE_AUTHREPLY) { if (notice.isAUTH_granted()) { contact.setBooleanValue( ContactItem.CONTACTITEM_NO_AUTH, false); addTextToForm(uin, ResourceBundle.getString("sysnotice"), ResourceBundle.getString("grantedby") + notice.getSndrUin() + ".", "", notice .getNewDate(), false, offline, -1); } else if (notice.getText() != null) addTextToForm(uin, ResourceBundle.getString("sysnotice"), ResourceBundle.getString("denyedby") + notice.getSndrUin() + ". " + ResourceBundle.getString("reason") + ": " + notice.getText(), "", notice .getNewDate(), false, offline, -1); else addTextToForm(uin, ResourceBundle.getString("sysnotice"), ResourceBundle.getString("denyedby") + notice.getSndrUin() + ". " + ResourceBundle.getString("noreason"), "", notice.getNewDate(), false, offline, -1); } chat.buildMenu(); } chat.checkTextForURL(); chat.checkForAuthReply(); } } static protected synchronized void addMyMessage(ContactItem contact, String message, long time, String ChatName, int messId) { String uin = contact.getStringValue(ContactItem.CONTACTITEM_UIN); if (!historyTable.containsKey(uin)) newChatForm(contact, ChatName); addTextToForm(uin, ResourceBundle.getString("me"), message, "", time, false, false, messId); } // Add text to message form static synchronized private void addTextToForm(String uin, String from, String message, String url, long time, boolean red, boolean offline, int messId) { ChatTextList msgDisplay = (ChatTextList) historyTable.get(uin); msgDisplay.addTextToForm(from, message, url, time, red, offline, messId); } static private MessData getCurrentMessData(String uin) { ChatTextList list = getChatHistoryAt(uin); int messIndex = list.textList.getCurrTextIndex(); if (messIndex == -1) return null; MessData md = (MessData) list.getMessData().elementAt(messIndex); return md; } static public String getCurrentMessage(String uin) { return getChatHistoryAt(uin).textList.getCurrText(getCurrentMessData(uin).getOffset(), false); } static public void copyText(String uin, String from) { ChatTextList list = getChatHistoryAt(uin); int messIndex = list.textList.getCurrTextIndex(); if (messIndex == -1) return; MessData md = (MessData) list.getMessData().elementAt(messIndex); JimmUI.setClipBoardText(md.getIncoming(), Util.getDateString(false, md .getTime()), md.getIncoming() ? from : ResourceBundle .getString("me"), getCurrentMessage(uin)); } // Returns the chat history form at the given uin static public ChatTextList getChatHistoryAt(String uin) { if (historyTable.containsKey(uin)) return (ChatTextList) historyTable.get(uin); else return null; } final static public int DEL_TYPE_CURRENT = 1; final static public int DEL_TYPE_ALL_EXCEPT_CUR = 2; final static public int DEL_TYPE_ALL = 3; static public void chatHistoryDelete(String uin) { ContactItem cItem = ContactList.getItembyUIN(uin); historyTable.remove(uin); historyUins.removeElement(uin); cItem.setBooleanValue(ContactItem.CONTACTITEM_HAS_CHAT, false); cItem.resetUnreadMessages(); } // Delete the chat history for uin static public void chatHistoryDelete(String uin, int delType) { switch (delType) { case DEL_TYPE_CURRENT: chatHistoryDelete(uin); break; case DEL_TYPE_ALL_EXCEPT_CUR: case DEL_TYPE_ALL: Enumeration AllChats = historyTable.keys(); String key; while (AllChats.hasMoreElements()) { key = (String) AllChats.nextElement(); if ((delType == DEL_TYPE_ALL_EXCEPT_CUR) && (key.equals(uin))) continue; chatHistoryDelete(key); } break; } } // Returns if the chat history at the given number is shown static public boolean chatHistoryShown(String uin) { if (historyTable.containsKey(uin)) { ChatTextList temp = (ChatTextList) historyTable.get(uin); return temp.isVisible(); } else return false; } // Returns true if chat history exists for this uin static public boolean chatHistoryExists(String uin) { return historyTable.containsKey(uin); } // Creates a new chat form static private void newChatForm(ContactItem contact, String name) { ChatTextList chatForm = new ChatTextList(name, contact); String uin = contact.getStringValue(ContactItem.CONTACTITEM_UIN); historyTable.put(uin, chatForm); Enumeration chats = historyTable.elements(); ChatTextList chat; while (chats.hasMoreElements()) { chat = (ChatTextList)chats.nextElement(); if (chatForm != chat) updateCaption_Internal(chat); } chat = null; historyUins.addElement(uin); ContactList.getItembyUIN(uin).setBooleanValue(ContactItem.CONTACTITEM_HAS_CHAT, true);//#sijapp cond.if modules_HISTORY is "true" # fillFormHistory(contact);//#sijapp cond.end# } static public void updateChatIfExists(ContactItem contact) { String uin = contact.getStringValue(ContactItem.CONTACTITEM_UIN); ChatTextList chat = (ChatTextList) historyTable.get(uin); if (chat == null) return; chat.contact = contact; } // fill chat with last history lines //#sijapp cond.if modules_HISTORY is "true" # final static private int MAX_HIST_LAST_MESS = 5; static public void fillFormHistory(ContactItem contact) { String name = contact.getStringValue(ContactItem.CONTACTITEM_NAME); String uin = contact.getStringValue(ContactItem.CONTACTITEM_UIN); if (Options.getBoolean(Options.OPTION_SHOW_LAST_MESS)) { int recCount = HistoryStorage.getRecordCount(uin); if (recCount == 0) return; if (!chatHistoryExists(uin)) newChatForm(contact, name); ChatTextList chatForm = (ChatTextList) historyTable.get(uin); if (chatForm.textList.getSize() != 0) return; int insSize = (recCount > MAX_HIST_LAST_MESS) ? MAX_HIST_LAST_MESS : recCount; CachedRecord rec; for (int i = recCount - insSize; i < recCount; i++) { rec = HistoryStorage.getRecord(uin, i); chatForm.textList.addBigText("[" + rec.from + " " + rec.date + "]", ChatTextList.getInOutColor(rec.type == 0), Font.STYLE_PLAIN, -1); chatForm.textList.doCRLF(-1); //#sijapp cond.if modules_SMILES_STD="true" | modules_SMILES_ANI="true" # Emotions.addTextWithEmotions(chatForm.textList, rec.text, Font.STYLE_PLAIN, 0x808080, -1); //#sijapp cond.else# chatForm.textList.addBigText(rec.text, 0x808080, Font.STYLE_PLAIN, -1); //#sijapp cond.end# chatForm.textList.doCRLF(-1); } rec = null; } } //#sijapp cond.end# static public void contactRenamed(String uin, String newName) { ChatTextList temp = (ChatTextList) historyTable.get(uin); if (temp == null) return; temp.ChatName = newName; updateCaption_Internal(temp); } static protected void updateCaption_Internal(ChatTextList current) { String uin = current.contact.getStringValue(ContactItem.CONTACTITEM_UIN); ChatTextList temp = (ChatTextList) historyTable.get(uin); int size = historyTable.size(); String title = null; if (size != 1) { int index = historyUins.indexOf(uin)+1; title = temp.ChatName + " (" + index + "/" + size + ")"; } else title = temp.ChatName; temp.textList.setCaption(title); } static protected boolean selectNextChat_Internal(ChatTextList current, boolean next) { if (historyTable.size() <= 1) return false; String curUin = current.contact.getStringValue(ContactItem.CONTACTITEM_UIN); Enumeration keys = historyTable.keys(); Vector uins = new Vector(); while (keys.hasMoreElements()) uins.addElement(keys.nextElement()); int curIndex = uins.indexOf(curUin); if (next) curIndex++; else curIndex--; if (curIndex < 0) curIndex = uins.size()-1; if (curIndex >= uins.size()) curIndex = 0; JimmUI.removeScreen(current); ChatTextList newChat = (ChatTextList)historyTable.get(uins.elementAt(curIndex)); newChat.activate(); return true; } public static void rebuildMenu(ContactItem item) { ChatTextList chat = getChatHistoryAt(item.getStringValue(ContactItem.CONTACTITEM_UIN)); if (chat != null) chat.buildMenu(); } public static boolean activateIfExists(ContactItem item) { if (item == null) return false; ChatTextList chat = getChatHistoryAt(item.getStringValue(ContactItem.CONTACTITEM_UIN)); if (chat != null) chat.activate(); return (chat != null); } static ChatTextList currentChat; public static ChatTextList getCurrent() { return currentChat; } public static void messageIsDelivered(String uin, int messId) { ChatTextList msgDisplay = (ChatTextList) historyTable.get(uin); if (msgDisplay == null) return; msgDisplay.messageIsDelivered(messId); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -