From 10e8af18560e71d0b2245ae52ffeb0ae4fcc3ca8 Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Wed, 9 Aug 2006 14:42:21 +0000 Subject: [PATCH] history scroll --- .../impl/gui/i18n/messages.properties | 1 + .../main/message/ChatConversationPanel.java | 29 ++++--- .../main/message/history/HistoryWindow.java | 75 +++++++++++++------ 3 files changed, 72 insertions(+), 33 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/i18n/messages.properties b/src/net/java/sip/communicator/impl/gui/i18n/messages.properties index ab942c4b1..749c085e5 100644 --- a/src/net/java/sip/communicator/impl/gui/i18n/messages.properties +++ b/src/net/java/sip/communicator/impl/gui/i18n/messages.properties @@ -70,6 +70,7 @@ launchOnStartUp=Launch on start up limitReachedForIp=You have too many existing registrations from the local IP address and the ? server doesn't allow to open any more of them. login=Login loginWindowTitle=Login ? +me=me modify=Modify moveToGroup=Move to group msgDeliveryFailure=Message delivery failure diff --git a/src/net/java/sip/communicator/impl/gui/main/message/ChatConversationPanel.java b/src/net/java/sip/communicator/impl/gui/main/message/ChatConversationPanel.java index 624b30478..d3f900b58 100755 --- a/src/net/java/sip/communicator/impl/gui/main/message/ChatConversationPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/message/ChatConversationPanel.java @@ -214,31 +214,36 @@ public void processMessage(String contactName, Date date, this.lastIncomingMsgTimestamp = new Date(); chatString = "

"; endHeaderTag = "

"; + + chatString += contactName + " at " + + processTime(calendar.get(Calendar.HOUR_OF_DAY)) + ":" + + processTime(calendar.get(Calendar.MINUTE)) + ":" + + processTime(calendar.get(Calendar.SECOND)) + endHeaderTag + + "
" + + processSmilies(processNewLines(processLinks(message))) + + "</PLAINTEXT></DIV>"; } else if (messageType.equals(Constants.OUTGOING_MESSAGE)){ chatString = "<h3>"; endHeaderTag = "</h3>"; + + chatString += Messages.getString("me") + " at " + + processTime(calendar.get(Calendar.HOUR_OF_DAY)) + ":" + + processTime(calendar.get(Calendar.MINUTE)) + ":" + + processTime(calendar.get(Calendar.SECOND)) + endHeaderTag + + "<DIV><PLAINTEXT>" + + processSmilies(processNewLines(processLinks(message))) + + "</PLAINTEXT></DIV>"; } else if (messageType.equals(Constants.SYSTEM_MESSAGE)) { chatString = "<h4>"; endHeaderTag = "</h4>"; - } - - if (messageType.equals(Constants.SYSTEM_MESSAGE)) { + chatString += processTime(calendar.get(Calendar.HOUR_OF_DAY)) + ":" + processTime(calendar.get(Calendar.MINUTE)) + ":" + processTime(calendar.get(Calendar.SECOND)) + " " + contactName + " " + message + endHeaderTag; } - else { - chatString += contactName + " at " - + processTime(calendar.get(Calendar.HOUR_OF_DAY)) + ":" - + processTime(calendar.get(Calendar.MINUTE)) + ":" - + processTime(calendar.get(Calendar.SECOND)) + endHeaderTag - + "<DIV><PLAINTEXT>" - + processSmilies(processNewLines(processLinks(message))) - + "</PLAINTEXT></DIV>"; - } Element root = this.document.getDefaultRootElement(); diff --git a/src/net/java/sip/communicator/impl/gui/main/message/history/HistoryWindow.java b/src/net/java/sip/communicator/impl/gui/main/message/history/HistoryWindow.java index 901800dea..7df9632f3 100644 --- a/src/net/java/sip/communicator/impl/gui/main/message/history/HistoryWindow.java +++ b/src/net/java/sip/communicator/impl/gui/main/message/history/HistoryWindow.java @@ -8,20 +8,29 @@ package net.java.sip.communicator.impl.gui.main.message.history; import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Toolkit; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.IOException; import java.util.Collection; import java.util.Date; +import java.util.Hashtable; import java.util.Iterator; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; +import javax.swing.JLabel; import javax.swing.JMenuBar; import javax.swing.JPanel; +import javax.swing.ScrollPaneConstants; +import javax.swing.text.BadLocationException; +import javax.swing.text.Element; +import javax.swing.text.html.HTMLDocument; import net.java.sip.communicator.impl.gui.GuiActivator; import net.java.sip.communicator.impl.gui.i18n.Messages; @@ -46,7 +55,7 @@ public class HistoryWindow extends JFrame implements ChatConversationContainer, ActionListener { - private JPanel historyPane = new JPanel(new BorderLayout()); + private JPanel historyPanel = new JPanel(new BorderLayout()); private JPanel mainPanel = new JPanel(new BorderLayout(10, 10)); @@ -74,6 +83,8 @@ public class HistoryWindow extends JFrame private static String PERIOD_SEARCH = "PeriodSearch"; + private Hashtable dateHistoryTable = new Hashtable(); + private String lastExecutedSearch; private Date searchStartDate; @@ -168,7 +179,7 @@ private void initPanels() { this.mainPanel.add(northPanel, BorderLayout.NORTH); - this.mainPanel.add(historyPane, BorderLayout.CENTER); + this.mainPanel.add(historyPanel, BorderLayout.CENTER); this.mainPanel.add(refreshPanel, BorderLayout.SOUTH); @@ -183,16 +194,38 @@ private void initPanels() { * @param endDate the end date of the period */ public void showHistoryByPeriod(Date startDate, Date endDate) { - Collection msgList = this.msgHistory.findByPeriod( - this.metaContact, startDate, endDate); - - showHistory(msgList); - - this.lastExecutedSearch = PERIOD_SEARCH; - this.searchStartDate = startDate; + if(searchStartDate == null || !searchStartDate.equals(startDate)) { + + ChatConversationPanel convPanel = null; + + this.historyPanel.removeAll(); + + if(dateHistoryTable.containsKey(startDate)) { + convPanel = (ChatConversationPanel)dateHistoryTable.get(startDate); + + this.historyPanel.add(convPanel); + } + else { + Collection msgList = this.msgHistory.findByPeriod( + this.metaContact, startDate, endDate); + + convPanel = new ChatConversationPanel(this); + + this.historyPanel.add(convPanel); + + this.createHistory(convPanel, msgList); + this.dateHistoryTable.put(startDate, convPanel); + } + this.historyPanel.revalidate(); + this.historyPanel.repaint(); + + this.lastExecutedSearch = PERIOD_SEARCH; + + this.searchStartDate = startDate; + } } - + /** * Shows a history for a given keyword. * @param keyword the keyword to search @@ -202,7 +235,13 @@ public void showHistoryByKeyword(String keyword) { Collection msgList = this.msgHistory.findByKeyword( this.metaContact, keyword); - showHistory(msgList); + this.historyPanel.removeAll(); + + ChatConversationPanel convPanel = new ChatConversationPanel(this); + createHistory(convPanel,msgList); + + this.historyPanel.add(convPanel, BorderLayout.CENTER); + this.historyPanel.revalidate(); this.lastExecutedSearch = KEYWORD_SEARCH; this.searchKeyword = keyword; @@ -212,16 +251,12 @@ public void showHistoryByKeyword(String keyword) { * Shows the history given by the collection into a ChatConversationPanel. * @param historyRecords a collection of history records */ - private void showHistory(Collection historyRecords) { - this.historyPane.removeAll(); - + private void createHistory(ChatConversationPanel chatConvPanel, Collection historyRecords) { + if(historyRecords.size() > 0) { Iterator i = historyRecords.iterator(); - - ChatConversationPanel chatConvPanel - = new ChatConversationPanel(this); - + while (i.hasNext()) { Object o = i.next(); @@ -246,10 +281,8 @@ else if(o instanceof MessageReceivedEvent) { evt.getTimestamp(), Constants.INCOMING_MESSAGE, evt.getSourceMessage().getContent()); } - } - this.historyPane.add(chatConvPanel, BorderLayout.CENTER); + } } - this.historyPane.revalidate(); } /**