diff --git a/src/java/org/jivesoftware/spark/ui/ContactGroup.java b/src/java/org/jivesoftware/spark/ui/ContactGroup.java index c6bb4941..1b7c6183 100644 --- a/src/java/org/jivesoftware/spark/ui/ContactGroup.java +++ b/src/java/org/jivesoftware/spark/ui/ContactGroup.java @@ -751,10 +751,21 @@ public class ContactGroup extends CollapsiblePane implements MouseListener { return size; } + /** + * Sets the name of group. + * + * @param groupName the contact group name. + */ public void setGroupName(String groupName) { this.groupName = groupName; } + /** + * Returns the "pretty" title of the ContactGroup. + * + * @param title the title. + * @return the new title. + */ public String getGroupTitle(String title) { int lastIndex = title.lastIndexOf("::"); if (lastIndex != -1) { @@ -764,23 +775,42 @@ public class ContactGroup extends CollapsiblePane implements MouseListener { return title; } + /** + * Returns true if the group is nested. + * + * @param groupName the name of the group. + * @return true if the group is nested. + */ public boolean isSubGroup(String groupName) { return groupName.indexOf("::") != -1; } + /** + * Returns true if this group is nested. + * + * @return true if nested. + */ public boolean isSubGroup() { return isSubGroup(getGroupName()); } + /** + * Returns the underlying container for the JList. + * + * @return the underlying container of the JList. + */ public JPanel getListPanel() { return listPanel; } + /** + * Adds an internal popup listesner. + */ private void addPopupWindow() { final Timer timer = new Timer(500, new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { canShowPopup = true; - motionListener.mouseMoved(mouseEvent); + } }); @@ -792,6 +822,7 @@ public class ContactGroup extends CollapsiblePane implements MouseListener { public void mouseExited(MouseEvent mouseEvent) { timer.stop(); canShowPopup = false; + ContactInfoWindow.getInstance().checkWindow(); } }); @@ -819,6 +850,11 @@ public class ContactGroup extends CollapsiblePane implements MouseListener { } } + /** + * Displays the ContactInfoWindow. + * + * @param e the mouseEvent that triggered this event. + */ private void displayWindow(MouseEvent e) { ContactInfoWindow.getInstance().display(this, e); } diff --git a/src/java/org/jivesoftware/spark/ui/ContactInfoWindow.java b/src/java/org/jivesoftware/spark/ui/ContactInfoWindow.java index 5cf3b88e..12e8c250 100644 --- a/src/java/org/jivesoftware/spark/ui/ContactInfoWindow.java +++ b/src/java/org/jivesoftware/spark/ui/ContactInfoWindow.java @@ -24,6 +24,13 @@ import org.jivesoftware.spark.util.log.Log; import org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport; import org.jivesoftware.sparkimpl.plugin.gateways.transports.TransportUtils; +import javax.swing.BorderFactory; +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JWindow; +import javax.swing.UIManager; + import java.awt.Color; import java.awt.Component; import java.awt.Dimension; @@ -37,24 +44,17 @@ import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.Point; import java.awt.Toolkit; -import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import java.net.MalformedURLException; import java.net.URL; -import javax.swing.BorderFactory; -import javax.swing.ImageIcon; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JWindow; -import javax.swing.UIManager; - /** * Represents the UI for the "ToolTip" functionallity in the ContactList. * * @author Derek DeMoro */ -public class ContactInfoWindow extends JPanel { +public class ContactInfoWindow extends JPanel implements MouseListener { private final JLabel nicknameLabel = new JLabel(); private final JMultilineLabel statusLabel = new JMultilineLabel(); private final JLabel fullJIDLabel = new JLabel(); @@ -156,35 +156,7 @@ public class ContactInfoWindow extends JPanel { setBorder(BorderFactory.createLineBorder(Color.gray, 1)); - window.addMouseListener(new MouseAdapter() { - public void mouseEntered(MouseEvent e) { - inWindow = true; - } - - public void mouseExited(MouseEvent e) { - Point point = e.getPoint(); - - Dimension dim = window.getSize(); - - int x = (int)point.getX(); - int y = (int)point.getY(); - - boolean close = false; - - if (x < 0 || x >= dim.getWidth()) { - close = true; - } - - if (y < 0 || y >= dim.getHeight()) { - close = true; - } - - if (close) { - inWindow = false; - checkWindow(); - } - } - }); + window.addMouseListener(this); window.getContentPane().add(this); @@ -234,6 +206,9 @@ public class ContactInfoWindow extends JPanel { window.setVisible(false); contactItem = null; } + else { + System.out.println("In window"); + } } }; @@ -341,7 +316,7 @@ public class ContactInfoWindow extends JPanel { Log.error(e); } - toolbar.removeAll(); + clearToolbar(); } public ContactItem getContactItem() { @@ -349,14 +324,12 @@ public class ContactInfoWindow extends JPanel { } public void addChatRoomButton(ChatRoomButton button) { - toolbar.add(button); - window.invalidate(); - window.validate(); - window.repaint(); + addToolbarComponent(button); } public void addToolbarComponent(Component comp) { toolbar.add(comp); + comp.addMouseListener(this); window.invalidate(); window.validate(); window.repaint(); @@ -378,4 +351,53 @@ public class ContactInfoWindow extends JPanel { size.height = 125; return size; } + + public void mouseEntered(MouseEvent e) { + inWindow = true; + } + + public void mouseExited(MouseEvent e) { + Point point = e.getPoint(); + + Dimension dim = window.getSize(); + + int x = (int)point.getX(); + int y = (int)point.getY(); + + boolean close = false; + + if (x < 0 || x >= dim.getWidth()) { + close = true; + } + + if (y < 0 || y >= dim.getHeight()) { + close = true; + } + + if (close) { + inWindow = false; + checkWindow(); + } + + System.out.println("Mouse Exited"); + } + + + public void mouseClicked(MouseEvent mouseEvent) { + } + + public void mousePressed(MouseEvent mouseEvent) { + } + + public void mouseReleased(MouseEvent mouseEvent) { + } + + private void clearToolbar() { + for (int i = 0; i < toolbar.getComponentCount(); i++) { + Component comp = toolbar.getComponent(i); + comp.removeMouseListener(this); + } + + toolbar.removeAll(); + } }