From 10b63d5c3f5921725ad540c83f6943e1be85b3f9 Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Fri, 10 Mar 2006 08:40:39 +0000 Subject: [PATCH] some comments added --- .../gui/main/contactlist/ContactList.java | 25 +-- .../contactlist/ContactListCellRenderer.java | 2 +- .../main/contactlist/ContactListModel.java | 46 ++++-- .../main/contactlist/ContactListPanel.java | 149 ++++++++++++++---- .../contactlist/ContactRightButtonMenu.java | 6 +- 5 files changed, 176 insertions(+), 52 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactList.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactList.java index f2b1c4eb8..ff631f612 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactList.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactList.java @@ -27,6 +27,7 @@ import net.java.sip.communicator.service.contactlist.event.MetaContactGroupEvent; import net.java.sip.communicator.service.contactlist.event.MetaContactListListener; import net.java.sip.communicator.service.protocol.Contact; +import net.java.sip.communicator.service.protocol.PresenceStatus; public class ContactList extends JList implements MetaContactListListener { @@ -99,16 +100,27 @@ public void addChild(MetaContactGroup parentGroup, this.scrollRectToVisible(this.getCellBounds(index, index + 1)); } + /** + * Indicates that a MetaContact has been added to the + * MetaContactList. + */ public void metaContactAdded(MetaContactEvent evt) { this.addChild(evt.getParentGroup(), new MetaContactNode(evt.getSourceContact())); } + /** + * Indicates that a MetaContact has been removed from + * the MetaContactList. + */ public void metaContactRemoved(MetaContactEvent evt) { } + /** + * Indicates that a MetaContactGroup has been added. + */ public void metaContactGroupAdded(MetaContactGroupEvent evt) { MetaContactGroup contactGroup = evt.getSourceMetaContactGroup(); @@ -146,18 +158,13 @@ public void metaContactModified(MetaContactEvent evt) /**@todo implement metaContactModified() */ System.out.println("@todo implement metaContactModified()"); } - - - + + /** + * Indicates that a MetaContactGroup has been removed. + */ public void metaContactGroupRemoved(MetaContactGroupEvent evt) { } - - public MetaContactGroup getRoot() { - return root; - } - - } diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListCellRenderer.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListCellRenderer.java index 9d052537d..1c0261f44 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListCellRenderer.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListCellRenderer.java @@ -74,7 +74,7 @@ public Component getListCellRendererComponent( int index, boolean isSelected, boolean cellHasFocus) { - + if (value instanceof MetaContactNode) { MetaContactNode contactNode = (MetaContactNode)value; diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListModel.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListModel.java index 3b1b0c7f0..09ff99898 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListModel.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListModel.java @@ -14,24 +14,46 @@ import net.java.sip.communicator.service.contactlist.MetaContact; import net.java.sip.communicator.service.contactlist.MetaContactGroup; +/** + * The list model of the ContactList. + * + * @author Yana Stamcheva + * + */ public class ContactListModel extends DefaultListModel { + /** + * Returns the ContactNode element in the ContactList that corresponds + * to the given MetaContact. + * + * @param contact The MetaContact we are searching for. + * @return The ContactNode element corresponding to the given contact + */ public MetaContactNode getContactNodeByContact(MetaContact contact){ - + MetaContactNode resultNode = null; - - Enumeration enumeration = this.elements(); - - while (enumeration.hasMoreElements()){ - MetaContactNode node = (MetaContactNode)enumeration.nextElement(); - - if(node.getContact().equals(contact)){ - resultNode = node; - break; + + Enumeration listEnum = this.elements(); + + while (listEnum.hasMoreElements()){ + + Object element = listEnum.nextElement(); + + if(element instanceof MetaContactNode){ + + MetaContactNode node = (MetaContactNode)element; + + if(node.getContact().equals(contact)){ + resultNode = node; + break; + } } } - + return resultNode; } - + + public void contactStatusChanged(int index) { + fireContentsChanged(this, index, index); + } } diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java index 4477485b2..09f1b30c3 100755 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java @@ -14,6 +14,8 @@ import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.util.Hashtable; import java.util.Iterator; @@ -29,7 +31,9 @@ import javax.swing.tree.TreePath; import net.java.sip.communicator.impl.gui.main.MainFrame; -import net.java.sip.communicator.impl.gui.main.message.MessageWindow; +import net.java.sip.communicator.impl.gui.main.message.ChatPanel; +import net.java.sip.communicator.impl.gui.main.message.ChatWindow; +import net.java.sip.communicator.impl.gui.main.utils.Constants; import net.java.sip.communicator.service.contactlist.MetaContact; import net.java.sip.communicator.service.contactlist.MetaContactGroup; import net.java.sip.communicator.service.contactlist.MetaContactListService; @@ -37,7 +41,7 @@ /** * @author Yana Stamcheva * - * The ContactListPanel contains the contact list. + * Creates the contactlist panel. */ public class ContactListPanel extends JScrollPane implements MouseListener { @@ -49,7 +53,14 @@ public class ContactListPanel extends JScrollPane private JPanel treePanel = new JPanel(new BorderLayout()); private Hashtable contactMsgWindows = new Hashtable(); + + private ChatWindow tabbedChatWindow; + /** + * Creates the contactlist scroll panel defining the parent frame. + * + * @param parent The parent frame. + */ public ContactListPanel(MainFrame parent) { this.parent = parent; @@ -64,6 +75,7 @@ public ContactListPanel(MainFrame parent) { public void mouseClicked(MouseEvent e) { + //Expand and collapse groups on double click. if(e.getClickCount() > 1){ int selectedIndex @@ -119,6 +131,9 @@ public void mouseExited(MouseEvent e) { public void mousePressed(MouseEvent e) { + // Open message window, right button menu or contact info when + // mouse is pressed. Distinguish on which component was pressed + // the mouse and make the appropriate work. if (this.contactList.getSelectedValue() instanceof MetaContactNode){ MetaContactNode contactNode @@ -143,20 +158,24 @@ public void mousePressed(MouseEvent e) { int translatedY = e.getY() - selectedCellPoint.y; + //get the component under the mouse Component component = renderer.getComponentAt(translatedX, translatedY); + if (component instanceof JLabel) { - + if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { + //Left click on the contact label opens Chat window SwingUtilities.invokeLater(new RunMessageWindow( contactNode.getContact())); } else if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { - + + //Right click on the contact label opens Popup menu ContactRightButtonMenu popupMenu = new ContactRightButtonMenu( parent, contactNode.getContact()); @@ -169,6 +188,7 @@ public void mousePressed(MouseEvent e) { } } else if (component instanceof JButton) { + //Click on the info button opens the info popup panel SwingUtilities.invokeLater (new RunInfoWindow(selectedCellPoint, contactNode.getContact())); @@ -180,6 +200,11 @@ public void mouseReleased(MouseEvent e) { } + /** + * Runs the chat window for the specified contact. + * + * @author Yana Stamcheva + */ private class RunMessageWindow implements Runnable { private MetaContact contactItem; @@ -190,32 +215,102 @@ private RunMessageWindow(MetaContact contactItem) { public void run() { - if (contactMsgWindows.containsKey(this.contactItem)) { - - MessageWindow msgWindow = (MessageWindow) contactMsgWindows - .get(this.contactItem); - - if (msgWindow.getExtendedState() == JFrame.ICONIFIED) - msgWindow.setExtendedState(JFrame.NORMAL); - - msgWindow.setVisible(true); - } else { - - MessageWindow msgWindow = new MessageWindow(parent); - - contactMsgWindows.put(this.contactItem, msgWindow); - - msgWindow.addContactToChat(this.contactItem); - - msgWindow.setVisible(true); - - msgWindow.getWriteMessagePanel().getEditorPane().requestFocus(); - } - + if(!Constants.TABBED_CHAT_WINDOW){ + + //If in mode "open all messages in new window" + + if (contactMsgWindows.containsKey(this.contactItem)) { + + /* + * If a chat window for this contact is already opened + * show it. + */ + ChatWindow msgWindow = (ChatWindow) contactMsgWindows + .get(this.contactItem); + + if (msgWindow.getExtendedState() == JFrame.ICONIFIED) + msgWindow.setExtendedState(JFrame.NORMAL); + + if(!msgWindow.isVisible()) + msgWindow.setVisible(true); + + } else { + /* + * If there's no chat window for the contact + * create it and show it. + */ + ChatWindow msgWindow = new ChatWindow(parent); + + contactMsgWindows.put(this.contactItem, msgWindow); + + msgWindow.addChat(this.contactItem); + + msgWindow.setVisible(true); + + msgWindow.getWriteMessagePanel() + .getEditorPane().requestFocus(); + } + } + else{ + // If in mode "group messages in one chat window" + + if(tabbedChatWindow == null){ + + // If there's no open chat window + tabbedChatWindow = new ChatWindow(parent); + + tabbedChatWindow.addWindowListener(new WindowAdapter(){ + + public void windowClosing(WindowEvent e) { + tabbedChatWindow = null; + } + }); + } + + /* + * Get the hashtable containg all tabs and correspondins + * chat panels. + */ + Hashtable contactTabsTable + = tabbedChatWindow.getContactTabsTable(); + + if(contactTabsTable.get(this.contactItem.getDisplayName()) + == null){ + + // If there's no open tab for the given contact. + tabbedChatWindow.addChatTab(this.contactItem); + + if (tabbedChatWindow.getExtendedState() == JFrame.ICONIFIED) + tabbedChatWindow.setExtendedState(JFrame.NORMAL); + + if(!tabbedChatWindow.isVisible()) + tabbedChatWindow.setVisible(true); + + tabbedChatWindow.getWriteMessagePanel() + .getEditorPane().requestFocus(); + } + else{ + // If a tab fot the given contact already exists. + tabbedChatWindow.setSelectedContactTab(this.contactItem); + + if (tabbedChatWindow.getExtendedState() == JFrame.ICONIFIED) + tabbedChatWindow.setExtendedState(JFrame.NORMAL); + + tabbedChatWindow.setVisible(true); + + tabbedChatWindow.getWriteMessagePanel() + .getEditorPane().requestFocus(); + } + } } } - + /** + * Runs the info window for the specified contact at the + * appropriate position. + * + * @author Yana Stamcheva + */ private class RunInfoWindow implements Runnable { private MetaContact contactItem; diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactRightButtonMenu.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactRightButtonMenu.java index a4ed99044..16c70e8b7 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactRightButtonMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactRightButtonMenu.java @@ -22,7 +22,7 @@ import net.java.sip.communicator.impl.gui.main.customcontrols.MessageDialog; import net.java.sip.communicator.impl.gui.main.history.HistoryWindow; import net.java.sip.communicator.impl.gui.main.i18n.Messages; -import net.java.sip.communicator.impl.gui.main.message.MessageWindow; +import net.java.sip.communicator.impl.gui.main.message.ChatWindow; import net.java.sip.communicator.impl.gui.main.utils.Constants; import net.java.sip.communicator.impl.gui.main.utils.ImageLoader; import net.java.sip.communicator.service.contactlist.MetaContact; @@ -160,9 +160,9 @@ public void actionPerformed(ActionEvent e) { if (itemName.equalsIgnoreCase("sendMessage")) { - MessageWindow msgWindow = new MessageWindow(this.mainFrame); + ChatWindow msgWindow = new ChatWindow(this.mainFrame); - msgWindow.addContactToChat(this.contactItem); + msgWindow.getCurrentChatPanel().addContactToChat(this.contactItem); msgWindow.setVisible(true); }