aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYana Stamcheva <yana@jitsi.org>2006-08-07 19:43:28 +0000
committerYana Stamcheva <yana@jitsi.org>2006-08-07 19:43:28 +0000
commitc44a1cac430663a7406b7a404e4d4ddb069caeef (patch)
tree1511f65d41d1ea209153ffe6ba7fe4c829d11fab /src
parentb257d2d7e824e65945598f69cd9802a1c46ea575 (diff)
downloadjitsi-c44a1cac430663a7406b7a404e4d4ddb069caeef.zip
jitsi-c44a1cac430663a7406b7a404e4d4ddb069caeef.tar.gz
jitsi-c44a1cac430663a7406b7a404e4d4ddb069caeef.tar.bz2
gui history package moved
Diffstat (limited to 'src')
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/history/HistoryWindow.java132
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/message/history/DatesPanel.java182
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/message/history/HistoryMenu.java (renamed from src/net/java/sip/communicator/impl/gui/main/history/HistoryMenu.java)7
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/message/history/HistoryWindow.java240
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/message/history/NavigationPanel.java (renamed from src/net/java/sip/communicator/impl/gui/main/history/NavigationPanel.java)2
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/message/history/SearchPanel.java (renamed from src/net/java/sip/communicator/impl/gui/main/history/SearchPanel.java)15
6 files changed, 438 insertions, 140 deletions
diff --git a/src/net/java/sip/communicator/impl/gui/main/history/HistoryWindow.java b/src/net/java/sip/communicator/impl/gui/main/history/HistoryWindow.java
deleted file mode 100644
index a3649b0..0000000
--- a/src/net/java/sip/communicator/impl/gui/main/history/HistoryWindow.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package net.java.sip.communicator.impl.gui.main.history;
-
-import java.awt.BorderLayout;
-import java.util.Vector;
-
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-
-import net.java.sip.communicator.impl.gui.i18n.Messages;
-import net.java.sip.communicator.impl.gui.utils.Constants;
-import net.java.sip.communicator.impl.gui.utils.ImageLoader;
-import net.java.sip.communicator.service.contactlist.MetaContact;
-
-/**
- * The <tt>HistoryWindow</tt> is the window, where user could view or search
- * in the message history. The <tt>HistoryWindow</tt> could contain the history
- * for one or a group of <tt>MetaContact</tt>s.
- *
- * @author Yana Stamcheva
- */
-public class HistoryWindow extends JFrame {
-
- private JScrollPane historyPane = new JScrollPane();
-
- private JPanel mainPanel = new JPanel(new BorderLayout());
-
- private NavigationPanel navigationPanel = new NavigationPanel();
-
- private SearchPanel searchPanel = new SearchPanel();
-
- private JMenuBar historyMenuBar = new JMenuBar();
-
- private HistoryMenu historyMenu;
-
- private JMenu settingsMenu = new JMenu(Messages.getString("settings"));
-
- private JPanel northPanel = new JPanel(new BorderLayout());
-
- private Vector contacts;
-
- private MetaContact contactItem;
-
- private String title = Messages.getString("history") + " - ";
-
- /**
- * Creates an instance of the <tt>HistoryWindow</tt>.
- */
- public HistoryWindow() {
- historyMenu = new HistoryMenu(this);
-
- this.setSize(Constants.HISTORY_WINDOW_WIDTH,
- Constants.HISTORY_WINDOW_HEIGHT);
-
- this.setIconImage(ImageLoader.getImage(ImageLoader.SIP_LOGO));
-
- this.init();
- }
-
- /**
- * Constructs the window, by adding all components and panels.
- */
- private void init() {
- this.historyMenuBar.add(historyMenu);
-
- this.historyMenuBar.add(settingsMenu);
-
- this.northPanel.add(historyMenuBar, BorderLayout.NORTH);
-
- this.northPanel.add(searchPanel, BorderLayout.CENTER);
-
- this.mainPanel.add(northPanel, BorderLayout.NORTH);
-
- this.mainPanel.add(historyPane, BorderLayout.CENTER);
-
- this.mainPanel.add(navigationPanel, BorderLayout.SOUTH);
-
- this.getContentPane().add(mainPanel);
- }
-
- /**
- * The <tt>HistoryWindow</tt> could contain the history for one or a
- * group of <tt>MetaContact</tt>s. This method returns the list of
- * <tt>MetaContact</tt>s for this history.
- *
- * @return returns the list of contacts for this history.
- */
- public Vector getContacts() {
- return contacts;
- }
-
- /**
- * The <tt>HistoryWindow</tt> could contain the history for one or a
- * group of <tt>MetaContact</tt>s. Sets the list of contacts for this
- * <tt>HistoryWindow</tt>.
- * @param contacts The Vector containing all <tt>MetaContact</tt>s for
- * this <tt>HistoryWindow</tt>.
- */
- public void setContacts(Vector contacts) {
- this.contacts = contacts;
-
- for (int i = 0; i < contacts.size(); i++) {
-
- MetaContact contact = (MetaContact) contacts.get(i);
-
- this.title += " " + contact.getDisplayName();
- }
- this.setTitle(title);
- }
-
- /**
- * Sets the contact, which history will be displayed in the case of a
- * <tt>HistoryWindow</tt> for only one contact.
- * @param contact The <tt>MetaContact</tt>, which history will be displayed.
- */
- public void setContact(MetaContact contact) {
- this.contactItem = contact;
-
- this.title += " " + contact.getDisplayName();
-
- this.setTitle(title);
- }
-}
diff --git a/src/net/java/sip/communicator/impl/gui/main/message/history/DatesPanel.java b/src/net/java/sip/communicator/impl/gui/main/message/history/DatesPanel.java
new file mode 100644
index 0000000..2d9d723
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/gui/main/message/history/DatesPanel.java
@@ -0,0 +1,182 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.impl.gui.main.message.history;
+
+import java.awt.BorderLayout;
+import java.awt.Font;
+import java.util.Calendar;
+import java.util.Date;
+
+import javax.swing.DefaultListModel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.ListSelectionModel;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+
+import net.java.sip.communicator.impl.gui.GuiActivator;
+import net.java.sip.communicator.impl.gui.customcontrols.ExtListCellRenderer;
+import net.java.sip.communicator.impl.gui.utils.Constants;
+import net.java.sip.communicator.service.msghistory.MessageHistoryService;
+
+/**
+ * The <tt>DatesPanel</tt> contains the list of history dates for a contact.
+ *
+ * @author Yana Stamcheva
+ */
+public class DatesPanel extends JScrollPane
+ implements ListSelectionListener {
+
+ private JList datesList = new JList();
+
+ private DefaultListModel listModel = new DefaultListModel();
+
+ private ExtListCellRenderer renderer = new ExtListCellRenderer();
+
+ private Calendar calendar = Calendar.getInstance();
+
+ private JPanel listPanel = new JPanel(new BorderLayout());
+
+ private MessageHistoryService msgHistory = GuiActivator.getMsgHistoryService();
+
+ private HistoryWindow historyWindow;
+
+ /**
+ * Creates an instance of <tt>DatesPanel</tt>.
+ *
+ * @param historyWindow the parent <tt>HistoryWindow</tt>, where
+ * this panel is contained.
+ */
+ public DatesPanel(HistoryWindow historyWindow) {
+
+ this.historyWindow = historyWindow;
+
+ this.datesList.setModel(listModel);
+
+ this.datesList.setCellRenderer(renderer);
+
+ this.datesList.setFont(Constants.FONT.deriveFont(Font.BOLD));
+
+ this.datesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+
+ this.listPanel.add(datesList, BorderLayout.NORTH);
+
+ this.getViewport().add(listPanel);
+
+ this.datesList.addListSelectionListener(this);
+ }
+
+ /**
+ * Adds the given date to the list of dates.
+ * @param date the date to add
+ */
+ public void addDate(Date date) {
+ String dateString = this.dateToString(date);
+
+ listModel.addElement(dateString);
+ }
+
+ /**
+ * Removes the given date from the list of dates
+ * @param date the date to remove
+ */
+ public void removeDate(Date date) {
+ String dateString = this.dateToString(date);
+
+ listModel.removeElement(dateString);
+ }
+
+ /**
+ * Checks whether the given date is contained in the list
+ * of history dates.
+ * @param date the date to search for
+ * @return TRUE if the given date is contained in the list
+ * of history dates, FALSE otherwise
+ */
+ public boolean containsDate(Date date) {
+ String dateString = this.dateToString(date);
+ if(listModel.contains(dateString)) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ /**
+ * Transforms the given date into a string, which contains only
+ * day, month and year.
+ * @param date the date to transform into string
+ * @return the string, obtained from the given date
+ */
+ public String dateToString(Date date) {
+ calendar.setTime(date);
+ return this.processTime(calendar.get(Calendar.DAY_OF_MONTH)) + "/"
+ + this.processTime(calendar.get(Calendar.MONTH) + 1) + "/"
+ + this.processTime(calendar.get(Calendar.YEAR));
+ }
+
+ /**
+ * Transforms the given string into date, which contains only
+ * day, month and year.
+ * @param dateString the string to transform into date
+ * @return the <tt>Date</tt>, obtained from the given string
+ */
+ public Date stringToDate(String dateString) {
+
+ int day = new Integer(dateString.substring(0, 2)).intValue();
+ int month = new Integer(dateString.substring(3, 5)).intValue() - 1;
+ int year = new Integer(dateString.substring(6)).intValue();
+
+ calendar.set(year, month, day, 0, 0, 0);
+
+ return calendar.getTime();
+ }
+
+ /**
+ * Formats a time string.
+ *
+ * @param time The time parameter could be hours, minutes or seconds.
+ * @return The formatted minutes string.
+ */
+ private String processTime(int time) {
+
+ String timeString = new Integer(time).toString();
+
+ String resultString = "";
+ if (timeString.length() < 2)
+ resultString = resultString.concat("0").concat(timeString);
+ else
+ resultString = timeString;
+
+ return resultString;
+ }
+
+ /**
+ * Implements the <tt>ListSelectionListener.valueChanged</tt>.
+ * Shows all history records for the selected date.
+ */
+ public void valueChanged(ListSelectionEvent e) {
+ int selectedIndex = this.datesList.getSelectedIndex();
+
+ String dateString = (String)this.listModel.get(selectedIndex);
+
+ Date nextDate;
+ if(selectedIndex < listModel.getSize() - 1) {
+ nextDate = stringToDate(
+ (String)this.listModel.get(selectedIndex + 1));
+ }
+ else {
+ nextDate = new Date(System.currentTimeMillis());
+ }
+
+ this.historyWindow.showHistoryByPeriod(
+ stringToDate(dateString),
+ nextDate);
+ }
+}
diff --git a/src/net/java/sip/communicator/impl/gui/main/history/HistoryMenu.java b/src/net/java/sip/communicator/impl/gui/main/message/history/HistoryMenu.java
index 0e58884..66e179c 100644
--- a/src/net/java/sip/communicator/impl/gui/main/history/HistoryMenu.java
+++ b/src/net/java/sip/communicator/impl/gui/main/message/history/HistoryMenu.java
@@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
-package net.java.sip.communicator.impl.gui.main.history;
+package net.java.sip.communicator.impl.gui.main.message.history;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -46,9 +46,12 @@ public class HistoryMenu extends JMenu implements ActionListener {
this.emptyMenuItem.addActionListener(this);
this.closeMenuItem.addActionListener(this);
-
+
this.add(emptyMenuItem);
this.add(closeMenuItem);
+
+ //disable meni items that are not yet implemented
+ this.emptyMenuItem.setEnabled(false);
}
/**
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
new file mode 100644
index 0000000..5013196
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/gui/main/message/history/HistoryWindow.java
@@ -0,0 +1,240 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package net.java.sip.communicator.impl.gui.main.message.history;
+
+import java.awt.BorderLayout;
+import java.awt.Window;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Vector;
+
+import javax.swing.BorderFactory;
+import javax.swing.JFrame;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+
+import net.java.sip.communicator.impl.gui.GuiActivator;
+import net.java.sip.communicator.impl.gui.i18n.Messages;
+import net.java.sip.communicator.impl.gui.main.MainFrame;
+import net.java.sip.communicator.impl.gui.main.message.ChatConversationContainer;
+import net.java.sip.communicator.impl.gui.main.message.ChatConversationPanel;
+import net.java.sip.communicator.impl.gui.utils.Constants;
+import net.java.sip.communicator.impl.gui.utils.ImageLoader;
+import net.java.sip.communicator.service.contactlist.MetaContact;
+import net.java.sip.communicator.service.history.QueryResultSet;
+import net.java.sip.communicator.service.history.records.HistoryRecord;
+import net.java.sip.communicator.service.msghistory.MessageHistoryService;
+import net.java.sip.communicator.service.protocol.Contact;
+import net.java.sip.communicator.service.protocol.Message;
+import net.java.sip.communicator.service.protocol.ProtocolProviderService;
+import net.java.sip.communicator.service.protocol.event.MessageDeliveredEvent;
+import net.java.sip.communicator.service.protocol.event.MessageReceivedEvent;
+
+/**
+ * The <tt>HistoryWindow</tt> is the window, where user could view or search
+ * in the message history. The <tt>HistoryWindow</tt> could contain the history
+ * for one or a group of <tt>MetaContact</tt>s.
+ *
+ * @author Yana Stamcheva
+ */
+public class HistoryWindow extends JFrame
+ implements ChatConversationContainer {
+
+ private JPanel historyPane = new JPanel(new BorderLayout());
+
+ private JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
+
+ private NavigationPanel navigationPanel = new NavigationPanel();
+
+ private SearchPanel searchPanel;
+
+ private JMenuBar historyMenuBar = new JMenuBar();
+
+ private HistoryMenu historyMenu;
+
+ private JPanel northPanel = new JPanel(new BorderLayout());
+
+ private DatesPanel datesPanel;
+
+ private Vector contacts;
+
+ private MetaContact metaContact;
+
+ private String title = Messages.getString("history") + " - ";
+
+ private MessageHistoryService msgHistory = GuiActivator.getMsgHistoryService();
+
+ private MainFrame mainFrame;
+
+ /**
+ * Creates an instance of the <tt>HistoryWindow</tt>.
+ * @param mainFrame the main application window
+ * @param metaContact the <tt>MetaContact</tt> for which to display
+ * a history
+ */
+ public HistoryWindow(MainFrame mainFrame, MetaContact metaContact) {
+
+ this.mainFrame = mainFrame;
+ this.metaContact = metaContact;
+
+ this.setTitle(metaContact.getDisplayName());
+
+ this.datesPanel = new DatesPanel(this);
+ this.historyMenu = new HistoryMenu(this);
+ this.searchPanel = new SearchPanel(this);
+
+ this.setSize(Constants.HISTORY_WINDOW_WIDTH,
+ Constants.HISTORY_WINDOW_HEIGHT);
+
+ this.setIconImage(ImageLoader.getImage(ImageLoader.SIP_LOGO));
+
+ this.initData();
+
+ this.initPanels();
+ }
+
+ /**
+ * Initializes the history with a list of all dates, for which a history
+ * with the given contact is availabled.
+ */
+ private void initData() {
+ Collection msgList = this.msgHistory.findByEndDate(
+ this.metaContact, new Date(System.currentTimeMillis()));
+
+ Iterator i = msgList.iterator();
+
+ Date date = null;
+ while (i.hasNext()) {
+ Object o = i.next();
+
+ if (o instanceof MessageDeliveredEvent) {
+ MessageDeliveredEvent evt = (MessageDeliveredEvent)o;
+
+ date = evt.getTimestamp();
+ }
+ else if (o instanceof MessageReceivedEvent) {
+ MessageReceivedEvent evt = (MessageReceivedEvent)o;
+ date = evt.getTimestamp();
+ }
+
+ if(!datesPanel.containsDate(date)) {
+ datesPanel.addDate(date);
+ }
+ }
+ }
+
+ /**
+ * Constructs the window, by adding all components and panels.
+ */
+ private void initPanels() {
+
+ this.historyMenuBar.add(historyMenu);
+
+ this.northPanel.add(historyMenuBar, BorderLayout.NORTH);
+
+ this.northPanel.add(searchPanel, BorderLayout.CENTER);
+
+ this.mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
+
+ this.mainPanel.add(northPanel, BorderLayout.NORTH);
+
+ this.mainPanel.add(historyPane, BorderLayout.CENTER);
+
+ //this.mainPanel.add(navigationPanel, BorderLayout.SOUTH);
+
+ this.mainPanel.add(datesPanel, BorderLayout.WEST);
+
+ this.getContentPane().add(mainPanel);
+ }
+
+ /**
+ * Shows a history for a given period.
+ * @param startDate the start date of the period
+ * @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);
+ }
+
+ /**
+ * Shows a history for a given keyword.
+ * @param keyword the keyword to search
+ */
+ public void showHistoryByKeyword(String keyword) {
+
+ Collection msgList = this.msgHistory.findByKeyword(
+ this.metaContact, keyword);
+
+ showHistory(msgList);
+ }
+
+ /**
+ * 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();
+
+ if(historyRecords.size() > 0) {
+
+ Iterator i = historyRecords.iterator();
+
+ ChatConversationPanel chatConvPanel
+ = new ChatConversationPanel(this);
+
+ while (i.hasNext()) {
+
+ Object o = i.next();
+
+ if(o instanceof MessageDeliveredEvent) {
+
+ MessageDeliveredEvent evt = (MessageDeliveredEvent)o;
+
+ ProtocolProviderService protocolProvider = evt
+ .getDestinationContact().getProtocolProvider();
+
+ chatConvPanel.processMessage(
+ this.mainFrame.getAccount(protocolProvider),
+ evt.getTimestamp(), Constants.OUTGOING_MESSAGE,
+ evt.getSourceMessage().getContent());
+ }
+ else if(o instanceof MessageReceivedEvent) {
+ MessageReceivedEvent evt = (MessageReceivedEvent)o;
+
+ chatConvPanel.processMessage(
+ evt.getSourceContact().getDisplayName(),
+ evt.getTimestamp(), Constants.INCOMING_MESSAGE,
+ evt.getSourceMessage().getContent());
+ }
+ }
+ this.historyPane.add(chatConvPanel, BorderLayout.CENTER);
+ }
+ this.historyPane.revalidate();
+ }
+
+ /**
+ * Implements <tt>ChatConversationContainer.setStatusMessage</tt> method.
+ */
+ public void setStatusMessage(String message) {
+ //TODO : setStatusMessage(String message)
+ }
+
+ /**
+ * Implements <tt>ChatConversationContainer.getWindow</tt> method.
+ */
+ public Window getWindow() {
+ return this;
+ }
+}
diff --git a/src/net/java/sip/communicator/impl/gui/main/history/NavigationPanel.java b/src/net/java/sip/communicator/impl/gui/main/message/history/NavigationPanel.java
index 6e8f1ad..440bd63 100644
--- a/src/net/java/sip/communicator/impl/gui/main/history/NavigationPanel.java
+++ b/src/net/java/sip/communicator/impl/gui/main/message/history/NavigationPanel.java
@@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
-package net.java.sip.communicator.impl.gui.main.history;
+package net.java.sip.communicator.impl.gui.main.message.history;
import java.awt.FlowLayout;
diff --git a/src/net/java/sip/communicator/impl/gui/main/history/SearchPanel.java b/src/net/java/sip/communicator/impl/gui/main/message/history/SearchPanel.java
index 0f1695e..55362ec 100644
--- a/src/net/java/sip/communicator/impl/gui/main/history/SearchPanel.java
+++ b/src/net/java/sip/communicator/impl/gui/main/message/history/SearchPanel.java
@@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
-package net.java.sip.communicator.impl.gui.main.history;
+package net.java.sip.communicator.impl.gui.main.message.history;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
@@ -97,14 +97,17 @@ public class SearchPanel extends JPanel implements ActionListener {
private JPanel searchButtonPanel = new JPanel(new FlowLayout(
FlowLayout.CENTER));
+ private HistoryWindow historyWindow;
+
// private JPanel extendedSearchPanel = new JPanel(new BorderLayout());
/**
* Creates an instance of the <tt>SearchPanel</tt>.
*/
- public SearchPanel() {
- super();
+ public SearchPanel(HistoryWindow historyWindow) {
+ this.historyWindow = historyWindow;
+
this.setBorder(BorderFactory.createTitledBorder(Messages
.getString("search"))); //$NON-NLS-1$
@@ -142,10 +145,12 @@ public class SearchPanel extends JPanel implements ActionListener {
this.dateCenteredPanel.add(datePanel);
- this.searchButton.setName("search");
+ this.searchButton.setName("search");
// this.extendedSearchButton.setName("extendedSearch");
// this.extendedSearchOpenedButton.setName("extendedSearchOpened");
+ this.searchButton.addActionListener(this);
+
this.searchButtonPanel.add(searchButton);
// this.extendedSearchPanel.add(extendedSearchButton,
@@ -171,7 +176,7 @@ public class SearchPanel extends JPanel implements ActionListener {
String buttonName = button.getName();
if (buttonName.equalsIgnoreCase("search")) {
- //TODO: Implement the search.
+ historyWindow.showHistoryByKeyword(searchTextField.getText());
}
/*
* else if(buttonName.equalsIgnoreCase("extendedSearch")){