diff --git a/src/net/java/sip/communicator/impl/gui/utils/NotificationManager.java b/src/net/java/sip/communicator/impl/gui/utils/NotificationManager.java index 1d2c6f19e..1e9f51b07 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/NotificationManager.java +++ b/src/net/java/sip/communicator/impl/gui/utils/NotificationManager.java @@ -10,6 +10,7 @@ import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.notification.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.util.*; public class NotificationManager { @@ -222,6 +223,11 @@ public static void fireChatNotification(Object chatContact, chatPanel = GuiActivator.getUIService().getChat(contact); contactIcon = contact.getImage(); + if(contactIcon == null) + { + contactIcon = ImageUtils.toByteArray( + ImageLoader.getImage(ImageLoader.DEFAULT_USER_PHOTO)); + } } else if (chatContact instanceof ChatRoom) { diff --git a/src/net/java/sip/communicator/impl/swingnotification/PopupMessageHandlerSwingImpl.java b/src/net/java/sip/communicator/impl/swingnotification/PopupMessageHandlerSwingImpl.java index 1615923e8..5d938309b 100644 --- a/src/net/java/sip/communicator/impl/swingnotification/PopupMessageHandlerSwingImpl.java +++ b/src/net/java/sip/communicator/impl/swingnotification/PopupMessageHandlerSwingImpl.java @@ -29,11 +29,6 @@ public class PopupMessageHandlerSwingImpl private static final Logger logger = Logger.getLogger(PopupMessageHandlerSwingImpl.class); - /** An icon representing the contact from which the notification comes */ - private ImageIcon defaultIcon = - SwingNotificationActivator.getResources().getImage( - "service.gui.SIP_COMMUNICATOR_LOGO_45x45");; - /** * Implements PopupMessageHandler#showPopupMessage() * @@ -56,12 +51,10 @@ public void actionPerformed(ActionEvent e) new Thread(new PopupDiscarder(notificationWindow)).start(); } }); - popupTimer.setRepeats(false); - notificationWindow.addMouseListener(new MouseAdapter() + MouseAdapter adapter = new MouseAdapter() { - @Override public void mouseEntered(MouseEvent e) { @@ -84,20 +77,20 @@ public void mouseClicked(MouseEvent e) new SystrayPopupMessageEvent(e, notif.getTag())); notificationWindow.dispose(); } - }); + }; - if (popupMessage.getComponent() != null) - { - notificationWindow.add(popupMessage.getComponent()); - } - else + notificationWindow.addMouseListener(adapter); + JComponent content = popupMessage.getComponent(); + if (content == null) { - notificationWindow.add(createPopup( + content = createPopup( popupMessage.getMessageTitle(), popupMessage.getMessage(), popupMessage.getIcon(), - popupMessage.getTag())); + popupMessage.getTag()); } + registerMouseListener(content, adapter); + notificationWindow.add(content); notificationWindow.setAlwaysOnTop(true); notificationWindow.pack(); @@ -105,6 +98,14 @@ public void mouseClicked(MouseEvent e) popupTimer.start(); } + private void registerMouseListener(Component content, MouseAdapter adapter) + { + content.addMouseListener(adapter); + if(content instanceof JComponent) + for(Component c : ((JComponent) content).getComponents()) + registerMouseListener(c, adapter); + } + /** * Builds the popup component with given informations. Wraps the specified * message in HTML <pre> tags to ensure that text such as @@ -121,8 +122,7 @@ private JComponent createPopup( String titleString, byte[] imageBytes, Object tag) { - JLabel msgIcon = new JLabel(defaultIcon); - + JLabel msgIcon = null; if (imageBytes != null) { ImageIcon imageIcon @@ -131,13 +131,6 @@ private JComponent createPopup( String titleString, msgIcon = new JLabel(imageIcon); } - JLabel msgTitle = new JLabel(titleString); - - int msgTitleHeight - = msgTitle.getFontMetrics(msgTitle.getFont()).getHeight(); - msgTitle.setPreferredSize(new Dimension(200, msgTitleHeight)); - msgTitle.setFont(msgTitle.getFont().deriveFont(Font.BOLD)); - String plainMessage = Html2Text.extractText("
" + message + "
"); JTextArea msgContent = new JTextArea(plainMessage); @@ -149,14 +142,13 @@ private JComponent createPopup( String titleString, int msgContentHeight = getPopupMessageAreaHeight(msgContent, plainMessage); - msgContent.setPreferredSize(new Dimension(200, msgContentHeight)); + msgContent.setPreferredSize(new Dimension(250, msgContentHeight)); TransparentPanel notificationBody = new TransparentPanel(); notificationBody.setLayout( new BoxLayout(notificationBody, BoxLayout.Y_AXIS)); notificationBody.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); - notificationBody.add(msgTitle); notificationBody.add(msgContent); TransparentPanel notificationContent @@ -165,12 +157,13 @@ private JComponent createPopup( String titleString, notificationContent.setLayout(new BorderLayout(5, 0)); notificationContent.setBorder( - BorderFactory.createEmptyBorder(5, 5, 5, 5)); + BorderFactory.createEmptyBorder(0, 5, 5, 5)); - notificationContent.add(msgIcon, BorderLayout.WEST); + if(msgIcon != null) + notificationContent.add(msgIcon, BorderLayout.WEST); notificationContent.add(notificationBody, BorderLayout.CENTER); - return new PopupNotificationPanel(notificationContent, tag); + return new PopupNotificationPanel(titleString, notificationContent, tag); } /** @@ -294,14 +287,14 @@ private int getPopupMessageAreaHeight(Component c, String message) int stringWidth = GuiUtils.getStringWidth(c, message); int numberOfRows = 0; - if (stringWidth/200 > 3) - numberOfRows = 3; + if (stringWidth/230 > 5) + numberOfRows = 5; else - numberOfRows = stringWidth/200; + numberOfRows = stringWidth/230 + 1; FontMetrics fontMetrics = c.getFontMetrics(c.getFont()); - return fontMetrics.getHeight()*numberOfRows; + return fontMetrics.getHeight()*Math.max(numberOfRows, 3)+5; } /** diff --git a/src/net/java/sip/communicator/util/swing/PopupNotificationPanel.java b/src/net/java/sip/communicator/util/swing/PopupNotificationPanel.java index 06248b5ec..80000ba39 100644 --- a/src/net/java/sip/communicator/util/swing/PopupNotificationPanel.java +++ b/src/net/java/sip/communicator/util/swing/PopupNotificationPanel.java @@ -47,12 +47,14 @@ public class PopupNotificationPanel /** * Creates a new PopupNotificationPanel with a customized panel * title. + * @param titleString The title of the popup */ - private PopupNotificationPanel() + private PopupNotificationPanel(String titleString) { notifTitle = new JLabel( UtilActivator.getResources().getSettingsString( - "service.gui.APPLICATION_NAME"), + "service.gui.APPLICATION_NAME") + + (titleString == null ? "" : ": " + titleString), SwingConstants.LEFT); notifClose = new SIPCommButton(); @@ -103,14 +105,16 @@ public void actionPerformed(ActionEvent e) /** * Creates a new notification panel with notificationContent as * the component to put in that panel - * + * + * @param titleString The title of the popup * @param notificationContent content to add in the new created * PopupNotificationPanel * @param tag an object to distinguish this PopupNotificationPanel */ - public PopupNotificationPanel(JPanel notificationContent, Object tag) + public PopupNotificationPanel(String titleString, + JPanel notificationContent, Object tag) { - this(); + this(titleString); add(notificationContent, BorderLayout.CENTER); this.tag = tag; }