diff options
author | Yana Stamcheva <yana@jitsi.org> | 2006-09-28 16:06:07 +0000 |
---|---|---|
committer | Yana Stamcheva <yana@jitsi.org> | 2006-09-28 16:06:07 +0000 |
commit | 6f30c1b1611294c902b7b8085c76606b52ec5a80 (patch) | |
tree | 99c52f5582003ebe1249a3e43afbf720276742d5 /src/net/java/sip/communicator | |
parent | ec618b6e352d041928d9334d80bd3ae0a1ccb450 (diff) | |
download | jitsi-6f30c1b1611294c902b7b8085c76606b52ec5a80.zip jitsi-6f30c1b1611294c902b7b8085c76606b52ec5a80.tar.gz jitsi-6f30c1b1611294c902b7b8085c76606b52ec5a80.tar.bz2 |
move contact ongoing work
Diffstat (limited to 'src/net/java/sip/communicator')
5 files changed, 650 insertions, 245 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 3f7fd53..213afb4 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 @@ -10,12 +10,20 @@ package net.java.sip.communicator.impl.gui.main.contactlist; import java.util.*; import java.awt.*; +import java.awt.event.*; + import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; +import com.sun.media.*; + +import net.java.sip.communicator.impl.gui.main.*; +import net.java.sip.communicator.impl.gui.main.contactlist.ContactListPanel.*; import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.contactlist.event.*; +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.util.*; /** * The <tt>ContactList</tt> is a JList that represents the contact list. A @@ -26,25 +34,35 @@ import net.java.sip.communicator.service.contactlist.event.*; * @author Yana Stamcheva */ public class ContactList extends JList - implements MetaContactListListener { + implements MetaContactListListener, + MouseListener { + + private Logger logger = Logger.getLogger(ContactList.class.getName()); private MetaContactListService contactList; private ContactListModel listModel; private MetaContact currentlySelectedContact; + + private Vector contactListListeners = new Vector(); + private Vector excContactListListeners = new Vector(); + + private MainFrame mainFrame; /** * Creates an instance of the <tt>ContactList</tt>. * * @param contactList The related meta contactlist. */ - public ContactList(MetaContactListService contactList) { + public ContactList(MainFrame mainFrame) { - this.contactList = contactList; + this.mainFrame = mainFrame; + + this.contactList = mainFrame.getContactList(); this.listModel = new ContactListModel(contactList); - + this.setModel(listModel); this.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); @@ -58,6 +76,8 @@ public class ContactList extends JList this.contactList.addMetaContactListListener(this); + this.addMouseListener(this); + this.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (getSelectedValue() instanceof MetaContact) { @@ -284,4 +304,356 @@ public class ContactList extends JList } return null; } + + /** + * Adds a listener for <tt>ContactListEvent</tt>s. + * + * @param listener the listener to add + */ + public void addContactListListener(ContactListListener listener) + { + synchronized (contactListListeners) + { + if(!contactListListeners.contains(listener)) + this.contactListListeners.add(listener); + } + } + + /** + * Removes a listener previously added with <tt>addContactListListener</tt>. + * + * @param listener the listener to remove + */ + public void removeContactListListener(ContactListListener listener) + { + synchronized (contactListListeners) + { + this.contactListListeners.remove(listener); + } + } + + /** + * Adds a listener for <tt>ContactListEvent</tt>s. + * + * @param listener the listener to add + */ + public void addExcContactListListener(ContactListListener listener) + { + synchronized (excContactListListeners) + { + if(!excContactListListeners.contains(listener)) + this.excContactListListeners.add(listener); + } + } + + /** + * Removes a listener previously added with <tt>addContactListListener</tt>. + * + * @param listener the listener to remove + */ + public void removeExcContactListListener(ContactListListener listener) + { + synchronized (excContactListListeners) + { + this.excContactListListeners.remove(listener); + } + } + + /** + * Creates the corresponding ContactListEvent and notifies all + * <tt>ContactListListener</tt>s that a contact is selected. + * + * @param sourceContact the contact that this event is about. + * @param eventID the id indicating the exact type of the event to fire. + */ + public void fireContactListEvent(MetaContact sourceContact, + int eventID) + { + ContactListEvent evt + = new ContactListEvent(sourceContact, eventID); + + if(excContactListListeners.size() > 0) { + synchronized (excContactListListeners) + { + Iterator listeners = new Vector( this.excContactListListeners) + .iterator(); + + while (listeners.hasNext()) + { + ContactListListener listener + = (ContactListListener) listeners.next(); + switch (evt.getEventID()) + { + case ContactListEvent.CONTACT_SELECTED: + listener.contactSelected(evt); + break; + case ContactListEvent.PROTOCOL_CONTACT_SELECTED: + listener.protocolContactSelected(evt); + break; + default: + logger.error("Unknown event type " + + evt.getEventID()); + } + } + } + } + else + { + synchronized (contactListListeners) + { + Iterator listeners = this.contactListListeners + .iterator(); + + while (listeners.hasNext()) + { + ContactListListener listener + = (ContactListListener) listeners.next(); + switch (evt.getEventID()) + { + case ContactListEvent.CONTACT_SELECTED: + listener.contactSelected(evt); + break; + case ContactListEvent.PROTOCOL_CONTACT_SELECTED: + listener.protocolContactSelected(evt); + break; + default: + logger.error("Unknown event type " + + evt.getEventID()); + } + } + } + } + } + + /** + * Creates the corresponding ContactListEvent and notifies all + * <tt>ContactListListener</tt>s that a contact is selected. + * + * @param sourceContact the contact that this event is about + * @param protocolContact the protocol contact the this event is about + * @param eventID the id indicating the exact type of the event to fire. + */ + public void fireContactListEvent(MetaContact sourceContact, + Contact protocolContact, + int eventID) + { + ContactListEvent evt + = new ContactListEvent(sourceContact, protocolContact, eventID); + + synchronized (contactListListeners) + { + Iterator listeners = this.contactListListeners + .iterator(); + + while (listeners.hasNext()) + { + ContactListListener listener + = (ContactListListener) listeners.next(); + switch (evt.getEventID()) + { + case ContactListEvent.CONTACT_SELECTED: + listener.contactSelected(evt); + break; + case ContactListEvent.PROTOCOL_CONTACT_SELECTED: + listener.protocolContactSelected(evt); + break; + default: + logger.error("Unknown event type " + evt.getEventID()); + } + } + } + } + + /** + * Closes or opens a group on a double click. + */ + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() > 1) { + + int selectedIndex = this.locationToIndex(e.getPoint()); + + ContactListModel listModel = (ContactListModel) this.getModel(); + + Object element = listModel.getElementAt(selectedIndex); + + if (element instanceof MetaContactGroup) { + + MetaContactGroup group = (MetaContactGroup) element; + + if (listModel.isGroupClosed(group)) { + listModel.openGroup(group); + } else { + listModel.closeGroup(group); + } + } + } + } + + public void mouseEntered(MouseEvent e) + {} + + public void mouseExited(MouseEvent e) + {} + + /** + * Manages a mouse press over the contact list. + * + * When the left mouse button is pressed on a contact cell different things + * may happen depending on the contained component under the mouse. If the + * mouse is pressed on the "contact name" the chat window is opened, + * configured to use the default protocol contact for the selected + * MetaContact. If the mouse is pressed on one of the protocol icons, the + * chat window is opened, configured to use the protocol contact + * corresponding to the given icon. + * + * When the right mouse button is pressed on a contact cell, the cell is + * selected and the <tt>ContactRightButtonMenu</tt> is opened. + * + * When the right mouse button is pressed on a group cell, the cell is + * selected and the <tt>GroupRightButtonMenu</tt> is opened. + * + * When the middle mouse button is pressed on a cell, the cell is selected. + */ + public void mousePressed(MouseEvent e) { + // Select the contact under the right button click. + if ((e.getModifiers() & InputEvent.BUTTON2_MASK) != 0 + || (e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 + || (e.isControlDown() && !e.isMetaDown())) { + this.setSelectedIndex(locationToIndex(e.getPoint())); + } + + int selectedIndex = this.getSelectedIndex(); + Object selectedValue = this.getSelectedValue(); + + ContactListCellRenderer renderer + = (ContactListCellRenderer) + this.getCellRenderer().getListCellRendererComponent( + this, selectedValue, selectedIndex, true, + true); + + Point selectedCellPoint = this.indexToLocation(selectedIndex); + + int translatedX = e.getX() - selectedCellPoint.x; + + int translatedY = e.getY() - selectedCellPoint.y; + + if(selectedValue instanceof MetaContactGroup) { + MetaContactGroup group = (MetaContactGroup) selectedValue; + + if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 + || (e.isControlDown() && !e.isMetaDown())) { + + GroupRightButtonMenu popupMenu + = new GroupRightButtonMenu(mainFrame, group); + + SwingUtilities.convertPointToScreen(selectedCellPoint, + renderer); + + popupMenu.setInvoker(this); + + popupMenu.setLocation(selectedCellPoint.x, + selectedCellPoint.y + renderer.getHeight()); + + popupMenu.setVisible(true); + } + } + + // 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 (selectedValue instanceof MetaContact) { + MetaContact contact = (MetaContact) selectedValue; + + //get the component under the mouse + Component component = renderer.getComponentAt(translatedX, + translatedY); + if (component instanceof JLabel) { + //Right click and Ctrl+LeftClick on the contact label opens + //Popup menu + if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 + || (e.isControlDown() && !e.isMetaDown())) { + + ContactRightButtonMenu popupMenu + = new ContactRightButtonMenu(mainFrame, contact); + + SwingUtilities.convertPointToScreen(selectedCellPoint, + renderer); + + popupMenu.setInvoker(this); + + popupMenu.setLocation(selectedCellPoint.x, + selectedCellPoint.y + renderer.getHeight()); + + popupMenu.setVisible(true); + } + //Left click on the contact label opens Chat window + else if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) { + fireContactListEvent(contact, + ContactListEvent.CONTACT_SELECTED); + } + } + else if (component instanceof JButton) { + //Click on the info button opens the info popup panel + SwingUtilities.invokeLater(new RunInfoWindow(selectedCellPoint, + contact)); + } + else if (component instanceof JPanel) { + if(component.getName() != null + && component.getName().equals("buttonsPanel")){ + JPanel panel = (JPanel) component; + + int internalX = translatedX + - (renderer.getWidth() - panel.getWidth() - 2); + int internalY = translatedY + - (renderer.getHeight() - panel.getHeight()); + + Component c = panel.getComponentAt(4, 4); + + if (c instanceof ContactProtocolButton) { + fireContactListEvent(contact, + ((ContactProtocolButton) c).getProtocolContact(), + ContactListEvent.PROTOCOL_CONTACT_SELECTED); + } + } + } + } + } + + public void mouseReleased(MouseEvent e) + {} + + /** + * Runs the info window for the specified contact at the + * appropriate position. + * + * @author Yana Stamcheva + */ + private class RunInfoWindow implements Runnable { + + private MetaContact contactItem; + + private Point p; + + private RunInfoWindow(Point p, MetaContact contactItem) { + + this.p = p; + this.contactItem = contactItem; + } + + public void run() { + + ContactInfoPanel contactInfoPanel = new ContactInfoPanel(mainFrame, + contactItem); + + SwingUtilities.convertPointToScreen(p, ContactList.this); + + // TODO: to calculate popup window posititon properly. + contactInfoPanel.setPopupLocation(p.x - 140, p.y - 15); + + contactInfoPanel.setVisible(true); + + contactInfoPanel.requestFocusInWindow(); + } + } + } diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListEvent.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListEvent.java new file mode 100644 index 0000000..516d626 --- /dev/null +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListEvent.java @@ -0,0 +1,92 @@ +/* + * 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.contactlist; + +import java.util.*; + +import net.java.sip.communicator.service.contactlist.*; +import net.java.sip.communicator.service.protocol.*; + +public class ContactListEvent + extends EventObject{ + + private int eventID = -1; + + /** + * Indicates that the ContactListEvent instance was triggered by + * selecting a contact in the contact list. + */ + public static final int CONTACT_SELECTED = 1; + + /** + * Indicates that the ContactListEvent instance was triggered by + * selecting a protocol contact in the contact list. + */ + public static final int PROTOCOL_CONTACT_SELECTED = 2; + + private MetaContact sourceContact; + + private Contact sourceProtoContact; + + /** + * Creates a new ContactListEvent according to the specified parameters. + * @param source the MetaContact which was selected + * @param eventID one of the XXX_SELECTED static fields indicating the + * nature of the event. + */ + public ContactListEvent(MetaContact source, int eventID) + { + super(source); + this.eventID = eventID; + this.sourceContact = source; + } + + /** + * Creates a new ContactListEvent according to the specified parameters. + * @param source the MetaContact which was selected + * @param protocolContact the protocol specifique contact which was selected + * @param eventID one of the XXX_SELECTED static fields indicating the + * nature of the event. + */ + public ContactListEvent(MetaContact source, + Contact protocolContact, int eventID) + { + super(source); + this.eventID = eventID; + this.sourceContact = source; + this.sourceProtoContact = protocolContact; + } + + /** + * Returns an event id specifying whether the type of this event + * (CONTACT_SELECTED or PROTOCOL_CONTACT_SELECTED) + * @return one of the XXX_SELECTED int fields of this class. + */ + public int getEventID() + { + return eventID; + } + + /** + * Returns the MetaContact for which this event occured. + * @return the MetaContact for which this event occured + */ + public MetaContact getSourceContact() + { + return sourceContact; + } + + /** + * Returns the protocol contact for which this event occured. + * @return the protocol contact for which this event occured + */ + public Contact getSourceProtoContact() + { + return sourceProtoContact; + } + +} diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListListener.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListListener.java new file mode 100644 index 0000000..542a945 --- /dev/null +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListListener.java @@ -0,0 +1,18 @@ +/* + * 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.contactlist; + +import java.util.*; + +public interface ContactListListener extends EventListener +{ + + public void contactSelected(ContactListEvent evt); + + public void protocolContactSelected(ContactListEvent evt); + +} 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 2e36015..11ecee7 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 @@ -31,9 +31,9 @@ import net.java.sip.communicator.service.protocol.event.*; * @author Yana Stamcheva */ public class ContactListPanel extends JScrollPane - implements MouseListener, - MessageListener, - TypingNotificationsListener { + implements MessageListener, + TypingNotificationsListener, + ContactListListener { private MainFrame mainFrame; @@ -72,9 +72,9 @@ public class ContactListPanel extends JScrollPane */ public void initList(MetaContactListService contactListService) { - this.contactList = new ContactList(contactListService); - - this.contactList.addMouseListener(this); + this.contactList = new ContactList(mainFrame); + + this.contactList.addContactListListener(this); this.treePanel.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { @@ -116,165 +116,24 @@ public class ContactListPanel extends JScrollPane } /** - * Closes or opens a group on a double click. + * Implements the ContactListListener.contactSelected method. */ - public void mouseClicked(MouseEvent e) { - if (e.getClickCount() > 1) { - - int selectedIndex = this.contactList.locationToIndex(e.getPoint()); - - ContactListModel listModel = (ContactListModel) this.contactList - .getModel(); - - Object element = listModel.getElementAt(selectedIndex); - - if (element instanceof MetaContactGroup) { - - MetaContactGroup group = (MetaContactGroup) element; - - if (listModel.isGroupClosed(group)) { - listModel.openGroup(group); - } else { - listModel.closeGroup(group); - } - } - } - } - - public void mouseEntered(MouseEvent e) { - } - - public void mouseExited(MouseEvent e) { + public void contactSelected(ContactListEvent evt) + { + SwingUtilities.invokeLater( + new RunMessageWindow(evt.getSourceContact())); } - + /** - * Manages a mouse press over the contact list. - * - * When the left mouse button is pressed on a contact cell different things - * may happen depending on the contained component under the mouse. If the - * mouse is pressed on the "contact name" the chat window is opened, - * configured to use the default protocol contact for the selected - * MetaContact. If the mouse is pressed on one of the protocol icons, the - * chat window is opened, configured to use the protocol contact - * corresponding to the given icon. - * - * When the right mouse button is pressed on a contact cell, the cell is - * selected and the <tt>ContactRightButtonMenu</tt> is opened. - * - * When the right mouse button is pressed on a group cell, the cell is - * selected and the <tt>GroupRightButtonMenu</tt> is opened. - * - * When the middle mouse button is pressed on a cell, the cell is selected. + * Implements the ContactListListener.protocolContactSelected method. */ - public void mousePressed(MouseEvent e) { - // Select the contact under the right button click. - if ((e.getModifiers() & InputEvent.BUTTON2_MASK) != 0 - || (e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 - || (e.isControlDown() && !e.isMetaDown())) { - this.contactList.setSelectedIndex(contactList.locationToIndex(e - .getPoint())); - } - - int selectedIndex = this.contactList.getSelectedIndex(); - Object selectedValue = this.contactList.getSelectedValue(); - - ContactListCellRenderer renderer - = (ContactListCellRenderer) this.contactList - .getCellRenderer().getListCellRendererComponent( - this.contactList, selectedValue, selectedIndex, true, - true); - - Point selectedCellPoint = this.contactList - .indexToLocation(selectedIndex); - - int translatedX = e.getX() - selectedCellPoint.x; - - int translatedY = e.getY() - selectedCellPoint.y; - - if(selectedValue instanceof MetaContactGroup) { - MetaContactGroup group = (MetaContactGroup) selectedValue; - - if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 - || (e.isControlDown() && !e.isMetaDown())) { - - GroupRightButtonMenu popupMenu - = new GroupRightButtonMenu(mainFrame, group); - - SwingUtilities.convertPointToScreen(selectedCellPoint, - renderer); - - popupMenu.setInvoker(this.contactList); - - popupMenu.setLocation(selectedCellPoint.x, - selectedCellPoint.y + renderer.getHeight()); - - popupMenu.setVisible(true); - } - } - - // 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 (selectedValue instanceof MetaContact) { - MetaContact contact = (MetaContact) selectedValue; - - //get the component under the mouse - Component component = renderer.getComponentAt(translatedX, - translatedY); - if (component instanceof JLabel) { - //Right click and Ctrl+LeftClick on the contact label opens - //Popup menu - if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 - || (e.isControlDown() && !e.isMetaDown())) { - - ContactRightButtonMenu popupMenu - = new ContactRightButtonMenu(mainFrame, contact); - - SwingUtilities.convertPointToScreen(selectedCellPoint, - renderer); - - popupMenu.setInvoker(this.contactList); - - popupMenu.setLocation(selectedCellPoint.x, - selectedCellPoint.y + renderer.getHeight()); - - popupMenu.setVisible(true); - } - //Left click on the contact label opens Chat window - else if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) { - SwingUtilities.invokeLater(new RunMessageWindow(contact)); - } - } - else if (component instanceof JButton) { - //Click on the info button opens the info popup panel - SwingUtilities.invokeLater(new RunInfoWindow(selectedCellPoint, - contact)); - } - else if (component instanceof JPanel) { - if(component.getName() != null - && component.getName().equals("buttonsPanel")){ - JPanel panel = (JPanel) component; - - int internalX = translatedX - - (renderer.getWidth() - panel.getWidth() - 2); - int internalY = translatedY - - (renderer.getHeight() - panel.getHeight()); - - Component c = panel.getComponentAt(4, 4); - - if (c instanceof ContactProtocolButton) { - - SwingUtilities.invokeLater(new RunMessageWindow(contact, - ((ContactProtocolButton) c).getProtocolContact())); - } - } - } - } + public void protocolContactSelected(ContactListEvent evt) + { + SwingUtilities.invokeLater( + new RunMessageWindow(evt.getSourceContact(), + evt.getSourceProtoContact())); } - - public void mouseReleased(MouseEvent e) { - } - + /** * Runs the chat window for the specified contact. We examine different * cases here, depending on the chat window mode. @@ -406,41 +265,7 @@ public class ContactListPanel extends JScrollPane } } } - - /** - * Runs the info window for the specified contact at the - * appropriate position. - * - * @author Yana Stamcheva - */ - private class RunInfoWindow implements Runnable { - - private MetaContact contactItem; - - private Point p; - - private RunInfoWindow(Point p, MetaContact contactItem) { - - this.p = p; - this.contactItem = contactItem; - } - - public void run() { - - ContactInfoPanel contactInfoPanel = new ContactInfoPanel(mainFrame, - contactItem); - - SwingUtilities.convertPointToScreen(p, contactList); - - // TODO: to calculate popup window posititon properly. - contactInfoPanel.setPopupLocation(p.x - 140, p.y - 15); - - contactInfoPanel.setVisible(true); - - contactInfoPanel.requestFocusInWindow(); - } - } - + /** * When a message is received determines whether to open a new chat * window or chat window tab, or to indicate that a message is received @@ -845,5 +670,5 @@ public class ContactListPanel extends JScrollPane return false; } } - } + } } 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 9ba918d..98ee69f 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 @@ -29,11 +29,17 @@ import net.java.sip.communicator.service.protocol.*; * * @author Yana Stamcheva */ -public class ContactRightButtonMenu extends JPopupMenu implements - ActionListener { +public class ContactRightButtonMenu + extends JPopupMenu + implements ActionListener, + ContactListListener +{ private JMenu moveToMenu = new JMenu(Messages.getString("moveToGroup")); + private JMenu moveSubcontactMenu + = new JMenu(Messages.getString("moveSubcontact")); + private JMenu addSubcontactMenu = new JMenu(Messages .getString("addSubcontact")); @@ -69,6 +75,12 @@ public class ContactRightButtonMenu extends JPopupMenu implements private String removeContactPrefix = "removeContact:"; private String addSubcontactPrefix = "addSubcontact:"; + + private String moveSubcontactPrefix = "moveSubcontact:"; + + private Contact contactToMove; + + private boolean moveAllContacts = false; /** * Creates an instance of ContactRightButtonMenu. @@ -161,26 +173,37 @@ public class ContactRightButtonMenu extends JPopupMenu implements if (contactItem.getContactCount() > 1) { JMenuItem allItem = new JMenuItem(Messages.getString("allContacts")); - + JMenuItem allItem1 = new JMenuItem(Messages.getString("allContacts")); + allItem.addActionListener(this); - - allItem.setName("allContacts"); + allItem1.addActionListener(this); + + allItem.setName(removeContactPrefix + "allContacts"); + allItem1.setName(moveSubcontactPrefix + "allContacts"); + this.removeContactMenu.add(allItem); - + this.moveSubcontactMenu.add(allItem1); this.removeContactMenu.addSeparator(); + this.moveSubcontactMenu.addSeparator(); } while (contacts.hasNext()) { Contact contact = (Contact)contacts.next(); JMenuItem contactItem = new JMenuItem(contact.getDisplayName()); + JMenuItem contactItem1 = new JMenuItem(contact.getDisplayName()); contactItem.setName(removeContactPrefix + contact.getAddress() + contact.getProtocolProvider().getProtocolName()); + contactItem1.setName(moveSubcontactPrefix + contact.getAddress() + + contact.getProtocolProvider().getProtocolName()); + contactItem.addActionListener(this); - + contactItem1.addActionListener(this); + this.removeContactMenu.add(contactItem); + this.moveSubcontactMenu.add(contactItem1); } this.add(sendMessageItem); @@ -189,6 +212,7 @@ public class ContactRightButtonMenu extends JPopupMenu implements this.addSeparator(); this.add(moveToMenu); + this.add(moveSubcontactMenu); this.addSeparator(); @@ -324,7 +348,7 @@ public class ContactRightButtonMenu extends JPopupMenu implements mainFrame.getContactList().moveMetaContact(contactItem, group); } } - else if (itemName.startsWith("removeContact")) { + else if (itemName.startsWith(removeContactPrefix)) { Contact contact = getContactFromMetaContact( itemName.substring(removeContactPrefix.length())); @@ -332,7 +356,7 @@ public class ContactRightButtonMenu extends JPopupMenu implements if(contact != null) { if(Constants.REMOVE_CONTACT_ASK) { String message = "<HTML>Are you sure you want to remove <B>" - + this.contactItem.getDisplayName() + + contact.getDisplayName() + "</B><BR>from your contact list?</html>"; MessageDialog dialog = new MessageDialog(this.mainFrame, @@ -353,44 +377,43 @@ public class ContactRightButtonMenu extends JPopupMenu implements new RemoveContactThread(contact).start(); } } - } - else if (itemName.equals("allContacts")) { - if(Constants.REMOVE_CONTACT_ASK) { - String message = "<HTML>Are you sure you want to remove <B>" - + this.contactItem.getDisplayName() - + "</B><BR>from your contact list?</html>"; - - MessageDialog dialog = new MessageDialog(this.mainFrame, - message, Messages.getString("remove")); - - int returnCode = dialog.showDialog(); - - if (returnCode == MessageDialog.OK_RETURN_CODE) { - new Thread() { - public void run() { - mainFrame.getContactList() - .removeMetaContact(contactItem); - } - }.start(); + else { + if(Constants.REMOVE_CONTACT_ASK) { + String message = "<HTML>Are you sure you want to remove <B>" + + Messages.getString("allContacts") + + "</B><BR>from your contact list?</html>"; + + MessageDialog dialog = new MessageDialog(this.mainFrame, + message, Messages.getString("remove")); + + int returnCode = dialog.showDialog(); + + if (returnCode == MessageDialog.OK_RETURN_CODE) { + new RemoveAllContactsThread().start(); + } + else if (returnCode == MessageDialog.OK_DONT_ASK_CODE) { + new RemoveAllContactsThread().start(); + + Constants.REMOVE_CONTACT_ASK = false; + } } - else if (returnCode == MessageDialog.OK_DONT_ASK_CODE) { - new Thread() { - public void run() { - mainFrame.getContactList() - .removeMetaContact(contactItem); - } - }.start(); - - Constants.REMOVE_CONTACT_ASK = false; + else { + new RemoveAllContactsThread().start(); } } + } + else if(itemName.startsWith(moveSubcontactPrefix)) { + Contact contact = getContactFromMetaContact( + itemName.substring(moveSubcontactPrefix.length())); + + mainFrame.getContactListPanel() + .getContactList().addExcContactListListener(this); + + if(contact != null) { + this.contactToMove = contact; + } else { - new Thread() { - public void run() { - mainFrame.getContactList() - .removeMetaContact(contactItem); - } - }.start(); + this.moveAllContacts = true; } } } @@ -403,7 +426,8 @@ public class ContactRightButtonMenu extends JPopupMenu implements * @return the <tt>Contact</tt> corresponding to the given address * identifier. */ - private Contact getContactFromMetaContact(String itemID) { + private Contact getContactFromMetaContact(String itemID) + { Iterator i = contactItem.getContacts(); while(i.hasNext()) { @@ -422,7 +446,8 @@ public class ContactRightButtonMenu extends JPopupMenu implements /** * Removes a contact from a meta contact in a separate thread. */ - private class RemoveContactThread extends Thread { + private class RemoveContactThread extends Thread + { private Contact contact; public RemoveContactThread(Contact contact) { this.contact = contact; @@ -431,4 +456,77 @@ public class ContactRightButtonMenu extends JPopupMenu implements mainFrame.getContactList().removeContact(contact); } } + + /** + * Removes a contact from a meta contact in a separate thread. + */ + private class RemoveAllContactsThread extends Thread + { + public void run() { + mainFrame.getContactList().removeMetaContact(contactItem); + } + } + + public void contactSelected(ContactListEvent evt) + { + mainFrame.getContactListPanel() + .getContactList().removeExcContactListListener(this); + + if(moveAllContacts) { + new MoveAllSubcontactsThread(evt.getSourceContact()).start(); + } + else if(contactToMove != null) { + new MoveSubcontactThread(evt.getSourceContact()).start(); + } + } + + public void protocolContactSelected(ContactListEvent evt) + { + mainFrame.getContactListPanel() + .getContactList().removeExcContactListListener(this); + + if(moveAllContacts) { + new MoveAllSubcontactsThread(evt.getSourceContact()).start(); + } + else if(contactToMove != null) { + new MoveSubcontactThread(evt.getSourceContact()).start(); + } + } + + private class MoveSubcontactThread extends Thread + { + private MetaContact metaContact; + + public MoveSubcontactThread(MetaContact metaContact) + { + this.metaContact = metaContact; + } + + public void run() + { + mainFrame.getContactList() + .moveContact(contactToMove, metaContact); + } + } + + private class MoveAllSubcontactsThread extends Thread + { + private MetaContact metaContact; + + public MoveAllSubcontactsThread(MetaContact metaContact) + { + this.metaContact = metaContact; + } + + public void run() + { + Iterator i = contactItem.getContacts(); + + while(i.hasNext()) { + Contact contact = (Contact) i.next(); + mainFrame.getContactList() + .moveContact(contact, metaContact); + } + } + } } |