Give popups a minimum height and don't cut off text due to rounding

cusax-fix
Ingo Bauersachs 15 years ago
parent 8f9fa9fd3f
commit e635bf9956

@ -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)
{

@ -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 <tt>PopupMessageHandler#showPopupMessage()</tt>
*
@ -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
* <tt>message</tt> in HTML &lt;pre&gt; 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("<pre>" + message + "</pre>");
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;
}
/**

@ -47,12 +47,14 @@ public class PopupNotificationPanel
/**
* Creates a new <tt>PopupNotificationPanel</tt> 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 <tt>notificationContent</tt> as
* the component to put in that panel
*
*
* @param titleString The title of the popup
* @param notificationContent content to add in the new created
* <tt>PopupNotificationPanel</tt>
* @param tag an object to distinguish this <tt>PopupNotificationPanel</tt>
*/
public PopupNotificationPanel(JPanel notificationContent, Object tag)
public PopupNotificationPanel(String titleString,
JPanel notificationContent, Object tag)
{
this();
this(titleString);
add(notificationContent, BorderLayout.CENTER);
this.tag = tag;
}

Loading…
Cancel
Save