diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactInfoPanel.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactInfoPanel.java index 8dd158eca..ff26df023 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactInfoPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactInfoPanel.java @@ -12,15 +12,20 @@ import java.awt.Color; import java.awt.Component; import java.awt.FlowLayout; +import java.awt.Frame; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridLayout; import java.awt.Point; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; import java.awt.event.WindowEvent; import java.awt.event.WindowFocusListener; import javax.swing.BorderFactory; import javax.swing.ImageIcon; +import javax.swing.JDialog; +import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JPopupMenu; @@ -29,7 +34,7 @@ import net.java.sip.communicator.impl.gui.main.ContactItem; import net.java.sip.communicator.impl.gui.main.customcontrols.TransparentBackground; -import net.java.sip.communicator.impl.gui.main.customcontrols.TransparentWindow; + import net.java.sip.communicator.impl.gui.main.utils.AntialiasingManager; import net.java.sip.communicator.impl.gui.main.utils.Constants; @@ -39,7 +44,7 @@ * The ContactListPanel contains the contact list. */ -public class ContactInfoPanel extends JWindow +public class ContactInfoPanel extends JDialog implements WindowFocusListener { private JPanel protocolsPanel = new JPanel(new GridLayout(0, 1)); @@ -48,10 +53,16 @@ public class ContactInfoPanel extends JWindow TransparentBackground bg; - public ContactInfoPanel(ContactItem contactItem){ + public ContactInfoPanel(Frame owner, ContactItem contactItem){ + super(owner); + this.contactItem = contactItem; + this.setUndecorated(true); + + this.setModal(true); + this.protocolsPanel.setOpaque(false); //Create the transparent background component @@ -90,15 +101,21 @@ private void init() { } this.bg.add(protocolsPanel, BorderLayout.CENTER); - } - + } - public void windowGainedFocus(WindowEvent e) { - System.out.println("focus gained"); + public JPanel getProtocolsPanel() { + return protocolsPanel; } + + public void windowGainedFocus(WindowEvent e) { + + } + public void windowLostFocus(WindowEvent e) { - System.out.println("focus lost"); + this.setVisible(false); + this.dispose(); } + } 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 f7f3c0269..e3e6cdc3c 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 @@ -45,12 +45,8 @@ import net.java.sip.communicator.impl.gui.main.utils.ImageLoader; public class ContactListCellRenderer extends JPanel - implements TreeCellRenderer, ActionListener { + implements TreeCellRenderer { - private ContactItem contactItem; - - private JTree tree; - private JLabel nameLabel = new JLabel(); private SIPCommButton extendPanelButton @@ -76,11 +72,9 @@ public ContactListCellRenderer() { this.nameLabel.setIconTextGap(2); - this.extendPanelButton.addActionListener(this); - this.add(nameLabel, BorderLayout.CENTER); - this.add(extendPanelButton, BorderLayout.EAST); + this.add(extendPanelButton, BorderLayout.WEST); } @@ -88,8 +82,6 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { - this.tree = tree; - // Find out which node we are rendering and get its text ContactNode node = (ContactNode) value; @@ -99,8 +91,6 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, ContactItem contactItem = (ContactItem) node.getUserObject(); - this.contactItem = contactItem; - this.nameLabel.setText(contactItem.getNickName()); this.nameLabel.setIcon(contactItem.getUserIcon()); @@ -111,7 +101,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, this.setPreferredSize(new Dimension(Constants.MAINFRAME_WIDTH + 20, 17)); - this.setBounds(0, 0, Constants.MAINFRAME_WIDTH + 20, 17); + this.setBounds(0, 0, Constants.MAINFRAME_WIDTH + 20, 17); } } else{ @@ -130,7 +120,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, this.setPreferredSize(new Dimension(Constants.MAINFRAME_WIDTH + 20, 20)); - this.setBounds(0, 0, Constants.MAINFRAME_WIDTH + 20, 20); + this.setBounds(0, 0, Constants.MAINFRAME_WIDTH + 20, 20); } } @@ -169,16 +159,4 @@ public void paintComponent(Graphics g) { public SIPCommButton getExtendPanelButton() { return extendPanelButton; } - - public void actionPerformed(ActionEvent e) { - - ContactInfoPanel contactInfoPanel = new ContactInfoPanel(this.contactItem); - -// TODO: To calculate accurately the position of the contact info popup. - contactInfoPanel.setLocation(800, 200); - - contactInfoPanel.setVisible(true); - - } - } 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 b060f5c66..4aeb5ed2e 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 @@ -15,6 +15,7 @@ import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.awt.event.WindowEvent; import java.util.Hashtable; import javax.swing.JButton; @@ -23,6 +24,8 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; @@ -39,47 +42,50 @@ * * The ContactListPanel contains the contact list. */ -public class ContactListPanel extends JScrollPane implements MouseListener { +public class ContactListPanel extends JScrollPane + implements MouseListener { private ContactList contactList; private MainFrame parent; private ContactListTree contactListTree; - + private JPanel treePanel = new JPanel(new BorderLayout()); - + private Hashtable contactMsgWindows = new Hashtable(); - - public ContactListPanel(MainFrame parent) { - + + public ContactListPanel(MainFrame parent) { + this.parent = parent; this.contactList = parent.getContactList(); - this.contactListTree = new ContactListTree(new ContactNode(new GroupItem("root"))); - + this.contactListTree = new ContactListTree(new ContactNode( + new GroupItem("root"))); + this.contactListTree.addMouseListener(this); - + this.initTree(); - + this.treePanel.add(contactListTree, BorderLayout.NORTH); - + this.getViewport().add(treePanel); - + this.treePanel.setBackground(Color.WHITE); } private void initTree() { - + // TODO: To be removed!!!! - ContactNode generalGroup = (ContactNode)this.contactListTree - .addChild(new GroupItem("General")); + ContactNode generalGroup = (ContactNode) this.contactListTree + .addChild(new GroupItem("General")); for (int i = 0; i < this.contactList.getAllContacts().size(); i++) { - this.contactListTree.addChild(generalGroup, (ContactItem) this.contactList - .getAllContacts().get(i), true); + this.contactListTree.addChild(generalGroup, + (ContactItem) this.contactList.getAllContacts().get(i), + true); } } @@ -99,123 +105,149 @@ public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { - + int selRow = this.contactListTree.getRowForLocation(e.getX(), e.getY()); - TreePath selPath = this.contactListTree.getPathForLocation(e.getX(), e.getY()); - + TreePath selPath = this.contactListTree.getPathForLocation(e.getX(), e + .getY()); + if (selRow != -1) { - if (e.getClickCount() == 1) { - + if (e.getClickCount() == 1) { + DefaultMutableTreeNode node = (DefaultMutableTreeNode) contactListTree - .getLastSelectedPathComponent(); - - if (node == null) return; - - if (node.isLeaf()) { - - ContactListCellRenderer renderer = - (ContactListCellRenderer) this.contactListTree.getCellRenderer() - .getTreeCellRendererComponent( this.contactListTree, - selPath.getLastPathComponent(), - false, false, - true, selRow, true); - - //Translate coordinates into cell cordinates. - - int translatedX = (int)e.getX() - (int)this.contactListTree.getPathBounds(selPath).getX(); - - int translatedY = (int)e.getY() - (int)this.contactListTree.getPathBounds(selPath).getY(); - - Component component = renderer.findComponentAt(translatedX, translatedY); - - ContactItem contactItem = (ContactItem) node.getUserObject(); - - if(component instanceof JLabel){ - - if((e.getModifiers() & InputEvent.BUTTON1_MASK) == - InputEvent.BUTTON1_MASK){ - - SwingUtilities.invokeLater(new RunMessageWindow(contactItem)); - } - else if((e.getModifiers() & InputEvent.BUTTON3_MASK) == - InputEvent.BUTTON3_MASK){ - - ContactRightButtonMenu popupMenu - = new ContactRightButtonMenu(parent, contactItem); - - popupMenu.setInvoker(this.contactListTree); - - popupMenu.setLocation(popupMenu.getPopupLocation()); - - popupMenu.setVisible(true); - } - } - else if(component instanceof JButton){ - - ContactInfoPanel contactInfoPanel = new ContactInfoPanel(contactItem); - - Point p = new Point(); - - p.x = (int)this.contactListTree.getPathBounds(selPath).getX(); - - p.y = (int)this.contactListTree.getPathBounds(selPath).getY(); - - SwingUtilities.convertPointToScreen(p, this.contactListTree); - - //TODO: to calculate popup window posititon properly. - contactInfoPanel.setLocation(p.x - 140, p.y - 15); - - contactInfoPanel.setVisible(true); + .getLastSelectedPathComponent(); + + if (node == null) + return; + + if (node.isLeaf()) { + + ContactListCellRenderer renderer = (ContactListCellRenderer) this.contactListTree + .getCellRenderer().getTreeCellRendererComponent( + this.contactListTree, + selPath.getLastPathComponent(), false, + false, true, selRow, true); + + // Translate coordinates into cell cordinates. + + int translatedX = (int) e.getX() + - (int) this.contactListTree.getPathBounds(selPath) + .getX(); + + int translatedY = (int) e.getY() + - (int) this.contactListTree.getPathBounds(selPath) + .getY(); + + Component component = renderer.findComponentAt(translatedX, + translatedY); + + ContactItem contactItem = (ContactItem) node + .getUserObject(); + + if (component instanceof JLabel) { + + if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { + + SwingUtilities.invokeLater(new RunMessageWindow( + contactItem)); - contactInfoPanel.requestFocus(); - } - } - - } - else if (e.getClickCount() == 2){ - + } else if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { + + ContactRightButtonMenu popupMenu = new ContactRightButtonMenu( + parent, contactItem); + + popupMenu.setInvoker(this.contactListTree); + + popupMenu.setLocation(popupMenu.getPopupLocation()); + + popupMenu.setVisible(true); + } + } else if (component instanceof JButton) { + + Point p = new Point(); + + p.x = (int) contactListTree.getPathBounds(selPath) + .getX(); + + p.y = (int) contactListTree.getPathBounds(selPath) + .getY(); + + SwingUtilities.invokeLater(new RunInfoWindow(p, contactItem)); + } + } + + } else if (e.getClickCount() == 2) { + } } } public void mouseReleased(MouseEvent e) { - // TODO Auto-generated method stub + } - - private class RunMessageWindow implements Runnable{ - + + private class RunMessageWindow implements Runnable { + private ContactItem contactItem; - - private RunMessageWindow(ContactItem contactItem){ + + private RunMessageWindow(ContactItem contactItem) { this.contactItem = contactItem; } - + public void run() { - - if (contactMsgWindows.containsKey(this.contactItem)){ - - MessageWindow msgWindow - = (MessageWindow)contactMsgWindows.get(this.contactItem); - - if(msgWindow.isVisible()){ - msgWindow.requestFocus(); - } - } - else{ - + + 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(); } + + } + } + + + private class RunInfoWindow implements Runnable { + + private ContactItem contactItem; + + private Point p; + + private RunInfoWindow(Point p, ContactItem contactItem) { + + this.p = p; + this.contactItem = contactItem; + } + + public void run() { + + ContactInfoPanel contactInfoPanel = new ContactInfoPanel(parent, contactItem); + + SwingUtilities.convertPointToScreen(p, contactListTree); + + // TODO: to calculate popup window posititon properly. + contactInfoPanel.setLocation(p.x - 140, p.y - 15); + contactInfoPanel.setVisible(true); + + contactInfoPanel.requestFocusInWindow(); + } } } \ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTree.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTree.java index 5cb703ca2..5925c633b 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTree.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTree.java @@ -33,7 +33,7 @@ public ContactListTree(ContactNode rootNode){ this.setRootVisible(false); - this.setEditable(true); + this.setEditable(false); this.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));