Some enhancements on fancy systray tooltips, including:

- frame and rounded corners for contact photos
- reduced size of the default sip comm icon
- changed layout
- image is now passed to popup message as a separate parameter
cusax-fix
Yana Stamcheva 17 years ago
parent bc32fa3215
commit cb37e61d02

@ -1,6 +1,6 @@
# service gui
service.gui.SIP_COMMUNICATOR_LOGO=resources/images/logo/sc_logo16x16.png
service.gui.SIP_COMMUNICATOR_LOGO_39x58=resources/images/logo/sc_logo_39x58.png
service.gui.SIP_COMMUNICATOR_LOGO_45x45=resources/images/logo/sc_logo_45x45.png
service.gui.MAIN_WINDOW_BACKGROUND=
service.gui.AUTH_WINDOW_BACKGROUND=resources/images/impl/gui/common/passWindowBackground.png
service.gui.ABOUT_WINDOW_BACKGROUND=resources/images/impl/gui/common/aboutWindowBackground.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

@ -11,7 +11,6 @@
import javax.swing.*;
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.lookandfeel.*;
import net.java.sip.communicator.impl.gui.main.*;
import net.java.sip.communicator.impl.gui.utils.*;

@ -115,7 +115,11 @@ public static void fireNotification(String eventType,
if(notificationService == null)
return;
notificationService.fireNotification(eventType, messageTitle, message, null);
notificationService.fireNotification( eventType,
messageTitle,
message,
null,
null);
}
/**
@ -128,7 +132,7 @@ public static void fireNotification(String eventType,
* @param messageTitle the title of the message
* @param message the content of the message
*/
public static void fireChatNotification(Object contact,
public static void fireChatNotification(Object chatContact,
String eventType,
String messageTitle,
String message)
@ -142,16 +146,24 @@ public static void fireChatNotification(Object contact,
NotificationActionHandler popupActionHandler = null;
Chat chatPanel = null;
byte[] contactIcon = null;
if (chatContact instanceof Contact)
{
Contact contact = (Contact) chatContact;
chatPanel = GuiActivator.getUIService().getChat(contact);
if (contact instanceof Contact)
chatPanel = GuiActivator.getUIService().getChat((Contact) contact);
else if (contact instanceof ChatRoom)
contactIcon = contact.getImage();
}
else if (chatContact instanceof ChatRoom)
{
ChatRoom chatRoom = (ChatRoom) chatContact;
// For system rooms we don't want to send notification events.
if (((ChatRoom) contact).isSystem())
if (chatRoom.isSystem())
return;
chatPanel = GuiActivator.getUIService().getChat((ChatRoom) contact);
chatPanel = GuiActivator.getUIService().getChat(chatRoom);
}
if(eventType.equals(INCOMING_MESSAGE)
@ -165,8 +177,11 @@ else if (contact instanceof ChatRoom)
popupActionHandler.setEnabled(false);
}
notificationService.fireNotification(
eventType, messageTitle, message, contact);
notificationService.fireNotification( eventType,
messageTitle,
message,
contactIcon,
chatContact);
if(popupActionHandler != null)
popupActionHandler.setEnabled(true);

@ -376,20 +376,23 @@ public void removeNotificationChangeListener(
* @param title the title of the given message
* @param message the message to use if and where appropriate (e.g. with
* systray or log notification.)
* @param icon the icon to show in the notification if and where
* appropriate
* @param tag additional info to be used by the notification handler
*/
public void fireNotification(
String eventType,
String title,
String message,
byte[] icon,
Object tag)
{
EventNotification notification
= (EventNotification) notificationsTable.get(eventType);
if(notification == null || !notification.isActive())
return;
Iterator actions = notification.getActions().values().iterator();
while(actions.hasNext())
@ -406,7 +409,7 @@ public void fireNotification(
if (actionType.equals(NotificationService.ACTION_POPUP_MESSAGE))
{
((PopupMessageNotificationHandler) handler)
.popupMessage(new PopupMessage(title, message, tag));
.popupMessage(new PopupMessage(title, message, icon, tag));
}
else if (actionType.equals(NotificationService.ACTION_LOG_MESSAGE))
{
@ -436,7 +439,7 @@ else if (actionType.equals(NotificationService.ACTION_COMMAND))
*/
public void fireNotification(String eventType)
{
this.fireNotification(eventType, null, null, null);
this.fireNotification(eventType, null, null, null, null);
}
/**

@ -206,7 +206,7 @@ public ChatRoom createChatRoom(String roomName, Hashtable roomProperties)
if(room != null)
throw new OperationFailedException(
"There is already a room with"
"There is already a room with this name."
, OperationFailedException.IDENTIFICATION_CONFLICT);
MultiUserChat muc = new MultiUserChat(getXmppConnection(), roomName);

@ -25,7 +25,6 @@
*/
public class PopupMessageHandlerSwingImpl implements PopupMessageHandler
{
/** logger for the <tt>PopupMessageHandlerSwingImpl</tt> class */
private final Logger logger =
Logger.getLogger(PopupMessageHandlerSwingImpl.class);
@ -37,7 +36,7 @@ public class PopupMessageHandlerSwingImpl implements PopupMessageHandler
/** An icon representing the contact from which the notification comes */
private ImageIcon defaultIcon =
SwingNotificationActivator.getResources().getImage(
"service.gui.SIP_COMMUNICATOR_LOGO_39x58");;
"service.gui.SIP_COMMUNICATOR_LOGO_45x45");;
/**
* Adds a listerner to receive popup events
@ -125,8 +124,8 @@ public void mouseClicked(MouseEvent e)
notificationWindow.add(createPopup(
popupMessage.getMessageTitle(),
popupMessage.getMessage(),
popupMessage.getIcon(),
popupMessage.getTag()));
notificationWindow.setPreferredSize(new Dimension(225, 120));
}
notificationWindow.setAlwaysOnTop(true);
notificationWindow.pack();
@ -143,42 +142,50 @@ public void mouseClicked(MouseEvent e)
* @param icon message icon
* @return
*/
private JComponent createPopup(String title, String message,
Object tag)
private JComponent createPopup( String titleString,
String message,
byte[] imageIcon,
Object tag)
{
String ttle = title;
if (title.length() > 50)
ttle = title.substring(0, 47) + "...";
JLabel msgTitle = new JLabel("<html>" + ttle);
msgTitle.setForeground(Color.DARK_GRAY);
String msg = message;
if (message.length() > 90)
msg = message.substring(0, 87) + "...";
JLabel msgContent = new JLabel("<html><b>" + msg);
JPanel notificationBody = new JPanel(new BorderLayout());
notificationBody.setOpaque(false);
notificationBody.add(msgTitle, BorderLayout.NORTH);
notificationBody.add(msgContent, BorderLayout.CENTER);
JLabel msgIcon = new JLabel(defaultIcon);
if (tag instanceof Contact)
{
byte[] b = ((Contact) tag).getImage();
if (b != null)
msgIcon = new JLabel(new ImageIcon(b));
}
else if (tag instanceof ImageIcon)
FramedImage msgIcon = new FramedImage(defaultIcon, 45, 45);
if (imageIcon != null)
{
msgIcon = new JLabel((ImageIcon) tag);
ImageIcon contactIcon = new ImageIcon(imageIcon);
msgIcon = new FramedImage(contactIcon, 45, 45);
}
msgIcon.setPreferredSize(new Dimension(45, 45));
JPanel notificationContent = new JPanel(new BorderLayout(5, 0));
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));
JTextArea msgContent = new JTextArea(message);
msgContent.setLineWrap(true);
msgContent.setWrapStyleWord(true);
msgContent.setOpaque(false);
msgContent.setAlignmentX(JTextArea.LEFT_ALIGNMENT);
int msgContentHeight = getPopupMessageAreaHeight(msgContent, message);
msgContent.setPreferredSize(new Dimension(200, 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
= new TransparentPanel();
notificationContent.setLayout(new BorderLayout(5, 0));
notificationContent.setBorder(
BorderFactory.createEmptyBorder(0, 3, 3, 3));
notificationContent.setOpaque(false);
BorderFactory.createEmptyBorder(5, 5, 5, 5));
notificationContent.add(msgIcon, BorderLayout.WEST);
notificationContent.add(notificationBody, BorderLayout.CENTER);
@ -308,4 +315,19 @@ public void run()
} while (height < 0);
}
}
private int getPopupMessageAreaHeight(Component c, String message)
{
int stringWidth = GuiUtils.getStringWidth(c, message);
int numberOfRows = 0;
if (stringWidth/200 > 3)
numberOfRows = 3;
else
numberOfRows = stringWidth/200;
FontMetrics fontMetrics = c.getFontMetrics(c.getFont());
return fontMetrics.getHeight()*numberOfRows;
}
}

@ -333,11 +333,14 @@ public void removeNotificationChangeListener(
* (e.g. with systray)
* @param message the message to use if and where appropriate (e.g. with
* systray or log notification.)
* @param icon the icon to show in the notification if and where
* appropriate
* @param tag additional info to be used by the notification handler
*/
public void fireNotification( String eventType,
String messageTitle,
String message,
byte[] icon,
Object tag);
/**

@ -19,48 +19,60 @@
public class PopupMessage
{
/** message to show in the popup */
/**
* Message to show in the popup.
*/
private String message;
/** title of the message */
/**
* Title of the message.
*/
private String messageTitle;
/** An icon representing the contact from which the notification comes */
private ImageIcon imageIcon;
/**
* An icon representing the contact from which the notification comes.
*/
private byte[] imageIcon;
/** A ready to show <tt>JComponet</tt> for this <tt>PopupMessage</tt> */
/**
* A ready to show <tt>JComponet</tt> for this <tt>PopupMessage</tt>.
*/
private JComponent component;
/** type of the message */
/**
* The type of the message.
*/
private int messageType;
/** additional info to be used by the <tt>PopupMessageHandler</tt> */
/**
* Additional info to be used by the <tt>PopupMessageHandler</tt>.
*/
private Object tag;
/**
* Creates a <tt>PopupMessage</tt> with the given title and message inside
* Creates a <tt>PopupMessage</tt> with the given title and message inside.
*
* @param messageTitle title of the message
* @param title title of the message
* @param message message to show in the systray
*/
public PopupMessage(String messageTitle, String message)
public PopupMessage(String title, String message)
{
this.messageTitle = messageTitle;
this.messageTitle = title;
this.message = message;
}
/**
* Creates a system tray message with the given title and message content. The
* message type will affect the icon used to present the message.
* Creates a system tray message with the given title and message content.
* The message type will affect the icon used to present the message.
*
* @param title the title, which will be shown
* @param content the content of the message to display
* @param message the content of the message to display
* @param messageType the message type; one of XXX_MESSAGE_TYPE constants
* declared in <tt>SystrayService
*/
public PopupMessage(String title, String content, int messageType)
public PopupMessage(String title, String message, int messageType)
{
this(title, content);
this(title, message);
this.messageType = messageType;
}
@ -68,11 +80,11 @@ public PopupMessage(String title, String content, int messageType)
* Creates a new <tt>PopupMessage</tt> with the given title, message and
* icon.
*
* @param messageTitle title of the message
* @param title the title of the message
* @param message message to show in the systray
* @param imageIcon an incon to show in the popup message.
*/
public PopupMessage(String title, String message, ImageIcon imageIcon)
public PopupMessage(String title, String message, byte[] imageIcon)
{
this(title, message);
this.imageIcon = imageIcon;
@ -98,8 +110,8 @@ public PopupMessage(JComponent component, String title, String message)
* <tt>JComponent</tt> as its content. This constructor also takes a title
* and a message as replacements in cases the component is not usable.
*
* @param component the component to put in the <tt>PopupMessage</tt>
* @param title of the message
* @param message the message to show in this popup
* @param tag additional info to be used by the <tt>PopupMessageHandler</tt>
*/
public PopupMessage(String title, String message, Object tag)
@ -109,7 +121,26 @@ public PopupMessage(String title, String message, Object tag)
}
/**
* @return the message
* Creates a new <tt>PopupMessage</tt> with the given
* <tt>JComponent</tt> as its content. This constructor also takes a title
* and a message as replacements in cases the component is not usable.
*
* @param title the title of the message
* @param message the message to show in this popup
* @param imageIcon the image icon to show in this popup message
* @param tag additional info to be used by the <tt>PopupMessageHandler</tt>
*/
public PopupMessage(String title, String message,
byte[] imageIcon, Object tag)
{
this(title, message, imageIcon);
this.tag = tag;
}
/**
* Returns the message contained in this popup.
*
* @return the message contained in this popup
*/
public String getMessage()
{
@ -117,7 +148,9 @@ public String getMessage()
}
/**
* @param message the message to set
* Sets the message to show in the popup.
*
* @param message the message to show in the popup
*/
public void setMessage(String message)
{
@ -125,7 +158,9 @@ public void setMessage(String message)
}
/**
* @return the messageTitle
* Returns the title of this popup message.
*
* @return the title of this popup message
*/
public String getMessageTitle()
{
@ -133,7 +168,9 @@ public String getMessageTitle()
}
/**
* @param messageTitle the messageTitle to set
* Sets the title of this popup message.
*
* @param messageTitle the title to set
*/
public void setMessageTitle(String messageTitle)
{
@ -141,7 +178,9 @@ public void setMessageTitle(String messageTitle)
}
/**
* @return the component
* Returns the component contained in this popup message.
*
* @return the component contained in this popup message.
*/
public JComponent getComponent()
{
@ -149,6 +188,8 @@ public JComponent getComponent()
}
/**
* Sets the component to be showed in this popup message.
*
* @param component the component to set
*/
public void setComponent(JComponent component)
@ -157,23 +198,29 @@ public void setComponent(JComponent component)
}
/**
* @return the imageIcon
* Returns the icon of this popup message.
*
* @return the icon of this popup message
*/
public ImageIcon getIcon()
public byte[] getIcon()
{
return imageIcon;
}
/**
* @param imageIcon the imageIcon to set
* Sets the icon of this popup message.
*
* @param imageIcon the icon to set
*/
public void setIcon(ImageIcon imageIcon)
public void setIcon(byte[] imageIcon)
{
this.imageIcon = imageIcon;
}
/**
* @return the messageType
* Returns the type of this popup message.
*
* @return the type of this popup message.
*/
public int getMessageType()
{
@ -181,7 +228,9 @@ public int getMessageType()
}
/**
* @param messageType the messageType to set
* Sets the type of this popup message.
*
* @param messageType the type to set
*/
public void setMessageType(int messageType)
{
@ -189,6 +238,8 @@ public void setMessageType(int messageType)
}
/**
* Returns the object used to tag this <tt>PopupMessage</tt>.
*
* @return the object used to tag this <tt>PopupMessage</tt>
*/
public Object getTag()
@ -197,6 +248,8 @@ public Object getTag()
}
/**
* Sets the object used to tag this popup message.
*
* @param tag the object to set
*/
public void setTag(Object tag)

@ -18,8 +18,8 @@
*
* @author Yana Stamcheva
*/
public class GuiUtils {
public class GuiUtils
{
private static Calendar c1 = Calendar.getInstance();
private static Calendar c2 = Calendar.getInstance();
@ -29,21 +29,23 @@ public class GuiUtils {
* @param text The initial text.
* @return the formatted text
*/
public static String replaceSpecialRegExpChars(String text) {
public static String replaceSpecialRegExpChars(String text)
{
return text.replaceAll("([.()^&$*|])", "\\\\$1");
}
/**
* Returns the width in pixels of a text.
* @param c the component where the text is contained
* @param text the text to measure
* @return the width in pixels of a text.
*/
public static int getStringWidth(Component c, String text) {
public static int getStringWidth(Component c, String text)
{
return SwingUtilities.computeStringWidth(c
.getFontMetrics(c.getFont()), text);
}
/**
* Compares the two dates. The comparison is based only on the day, month
* and year values. Returns 0 if the two dates are equals, a value < 0 if
@ -70,17 +72,18 @@ public static int compareDates(Date date1, Date date2)
if((day1 == day2)
&& (month1 == month2)
&& (year1 == year2)) {
&& (year1 == year2))
{
return 0;
}
else if((day1 < day2)
&& (month1 <= month2)
&& (year1 <= year2)) {
&& (year1 <= year2))
{
return -1;
}
else {
else
{
return 1;
}
}
@ -94,9 +97,9 @@ else if((day1 < day2)
public static String formatDate(Date date)
{
c1.setTime(date);
return GuiUtils.processMonth(c1.get(Calendar.MONTH) + 1) + " "
+ GuiUtils.formatTime(c1.get(Calendar.DAY_OF_MONTH)) + ", "
+ GuiUtils.formatTime(c1.get(Calendar.DAY_OF_MONTH)) + ", "
+ GuiUtils.formatTime(c1.get(Calendar.YEAR));
}
@ -136,7 +139,7 @@ public static Date substractDates(Date date1, Date date2)
int min
= (int)(( difMil - days*milPerDay - hour*milPerHour ) / milPerMin);
int sec
= (int)(( difMil - days*milPerDay - hour*milPerHour - min*milPerMin )
= (int)(( difMil - days*milPerDay - hour*milPerHour - min*milPerMin)
/ milPerSec);
c1.clear();

@ -4,18 +4,16 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.customcontrols;
package net.java.sip.communicator.util.swing;
import java.awt.*;
import javax.swing.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.util.*;
/**
* A custom component, used to show contact images in a frame,
* where appropriate.
* A custom component, used to show images in a frame.
*
* @author Yana Stamcheva
*/
@ -31,12 +29,12 @@ public class FramedImage
private final int height;
/**
* Creates a ContactPhotoLabel by specifying the width and the height of the
* label. These are used to paint the frame in the correct bounds.
* Creates a FramedImage by specifying the width and the height of the
* label. These are used to paint the image frame in the correct bounds.
*
* @param imageIcon the icon to show within the frame
* @param width the width of the label.
* @param height the height of the label.
* @param width the width of the frame
* @param height the height of the frame
*/
public FramedImage(ImageIcon imageIcon, int width, int height)
{
@ -45,9 +43,10 @@ public FramedImage(ImageIcon imageIcon, int width, int height)
this.setPreferredSize(new Dimension(width, height));
this.frameImage =
ImageUtils.scaleImageWithinBounds(ImageLoader
.getImage(ImageLoader.USER_PHOTO_FRAME), width, height);
this.frameImage = ImageUtils.scaleImageWithinBounds(
UtilActivator.getResources()
.getImage("service.gui.USER_PHOTO_FRAME").getImage(),
width, height);
if (imageIcon != null)
{
@ -55,11 +54,22 @@ public FramedImage(ImageIcon imageIcon, int width, int height)
}
}
/**
* Creates a FramedImage by specifying the width and the height of the frame.
*
* @param width the width of the frame
* @param height the height of the frame
*/
public FramedImage(int width, int height)
{
this(null, width, height);
}
/**
* Sets the image to display in the frame.
*
* @param imageIcon the image to display in the frame
*/
public void setImageIcon(ImageIcon imageIcon)
{
this.image =
@ -67,8 +77,10 @@ public void setImageIcon(ImageIcon imageIcon)
height - 2);
}
/*
* Overrides {@link JComponent#paintComponent(Graphics)}.
/**
* Paints the contained image in a frame.
*
* @overrides {@link JComponent#paintComponent(Graphics)}.
*/
public void paintComponent(Graphics g)
{

@ -34,7 +34,7 @@ public class TestPopupMessageHandler
private static SystrayService systrayService = null;
/**
* reference to services we will retrive from bundle context
* reference to services we will retrieve from bundle context
*/
private static ServiceReference serviceReference = null;
@ -45,7 +45,7 @@ public class TestPopupMessageHandler
private static NotificationService notificationService = null;
/**
* a trivial message we will send via the nofification service.
* a trivial message we will send via the notification service.
*/
private String messageStart = "Lorem ipsum dolor sit amet.";
@ -123,19 +123,20 @@ public void testNotificationHandling()
serviceReference = bc.getServiceReference(
NotificationService.class.getName());
notificationService = (NotificationService) bc.getService(serviceReference);
notificationService
= (NotificationService) bc.getService(serviceReference);
notificationService.fireNotification(
NotificationService.ACTION_POPUP_MESSAGE,
messageStart,
messageStart,
null,
null);
}
/** A trivial handler implementing <tt>PopupMessageHandler</tt> */
private class MockPopupMessageHandler implements PopupMessageHandler
{
/**
* implements <tt>PopupMessageHandler.addPopupMessageListener()</tt>
*/
@ -160,6 +161,5 @@ public void showPopupMessage(PopupMessage popupMsg)
// is it the expected handler which is handling it ?
assertEquals(handler2, this);
}
}
}

Loading…
Cancel
Save