mirror of https://github.com/sipwise/jitsi.git
parent
65f31038bd
commit
2d81282722
@ -0,0 +1,295 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.swingnotification;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import javax.swing.*;
|
||||
|
||||
import javax.swing.Timer;
|
||||
import net.java.sip.communicator.service.systray.*;
|
||||
import net.java.sip.communicator.service.systray.event.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
import net.java.sip.communicator.util.swing.*;
|
||||
|
||||
/**
|
||||
* An implementation of <tt>PopupMessageHandler</tt> using swing.
|
||||
* @author Symphorien Wanko
|
||||
*/
|
||||
public class PopupMessageHandlerSwingImpl implements PopupMessageHandler
|
||||
{
|
||||
|
||||
/** logger for the <tt>PopupMessageHandlerSwingImpl</tt> class */
|
||||
private final Logger logger =
|
||||
Logger.getLogger(PopupMessageHandlerSwingImpl.class);
|
||||
|
||||
/** The list of all added popup listeners */
|
||||
private final List<SystrayPopupMessageListener> popupMessageListeners =
|
||||
new Vector<SystrayPopupMessageListener>();
|
||||
|
||||
/** An icon representing the contact from which the notification comes */
|
||||
private ImageIcon defaultIcon =
|
||||
SwingNotificationActivator.getResources().getImage(
|
||||
"service.gui.DEFAULT_USER_PHOTO");;
|
||||
|
||||
/**
|
||||
* Adds a listerner to receive popup events
|
||||
* @param listener the listener to add
|
||||
*/
|
||||
public void addPopupMessageListener(SystrayPopupMessageListener listener)
|
||||
{
|
||||
synchronized (popupMessageListeners)
|
||||
{
|
||||
if (!popupMessageListeners.contains(listener))
|
||||
popupMessageListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a listerner previously added with <tt>addPopupMessageListener</tt>
|
||||
* @param listener the listener to remove
|
||||
*/
|
||||
public void removePopupMessageListener(SystrayPopupMessageListener listener)
|
||||
{
|
||||
synchronized (popupMessageListeners)
|
||||
{
|
||||
popupMessageListeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements <tt>PopupMessageHandler#showPopupMessage()</tt>
|
||||
*
|
||||
* @param popupMessage the message we will show
|
||||
*/
|
||||
public void showPopupMessage(PopupMessage popupMessage)
|
||||
{
|
||||
final GraphicsConfiguration graphicsConf =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment().
|
||||
getDefaultScreenDevice().
|
||||
getDefaultConfiguration();
|
||||
|
||||
final JWindow notificationWindow = new JWindow(graphicsConf);
|
||||
notificationWindow.setPreferredSize(new Dimension(225, 125));
|
||||
|
||||
final Timer popupTimer = new Timer(10000, new ActionListener()
|
||||
{
|
||||
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
if (notificationWindow.isVisible())
|
||||
new Thread(new PopupDiscarder(notificationWindow)).start();
|
||||
}
|
||||
});
|
||||
|
||||
popupTimer.setRepeats(false);
|
||||
|
||||
notificationWindow.addMouseListener(new MouseAdapter()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e)
|
||||
{
|
||||
popupTimer.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e)
|
||||
{
|
||||
popupTimer.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e)
|
||||
{
|
||||
firePopupMessageClicked(new SystrayPopupMessageEvent(e));
|
||||
notificationWindow.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
if (popupMessage.getComponent() != null)
|
||||
notificationWindow.add(popupMessage.getComponent());
|
||||
else
|
||||
notificationWindow.add(createPopup(
|
||||
popupMessage.getMessageTitle(),
|
||||
popupMessage.getMessage(),
|
||||
popupMessage.getIcon()));
|
||||
notificationWindow.setAlwaysOnTop(true);
|
||||
notificationWindow.pack();
|
||||
|
||||
new Thread(new PopupLauncher(notificationWindow, graphicsConf)).start();
|
||||
popupTimer.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* builds the popup component with given informations.
|
||||
*
|
||||
* @param title message title
|
||||
* @param message message content
|
||||
* @param icon message icon
|
||||
* @return
|
||||
*/
|
||||
private JComponent createPopup(String title, String message,
|
||||
ImageIcon icon)
|
||||
{
|
||||
String msg;
|
||||
|
||||
if (message.length() > 70)
|
||||
msg = "<html><b>" + message.substring(0, 77) + "...";
|
||||
else
|
||||
msg = "<html><b>" + message;
|
||||
|
||||
JLabel msgContent = new JLabel(msg);
|
||||
|
||||
if (title.length() > 40)
|
||||
title = title.substring(0, 28) + "...";
|
||||
JLabel msgFrom = new JLabel(title);
|
||||
msgFrom.setForeground(Color.DARK_GRAY);
|
||||
|
||||
JLabel msgIcon = (icon == null) ?
|
||||
new JLabel(defaultIcon) :
|
||||
new JLabel(icon);
|
||||
msgIcon.setOpaque(false);
|
||||
msgIcon.setPreferredSize(new Dimension(45, 45));
|
||||
|
||||
JPanel notificationContent = new JPanel(new BorderLayout(5, 1));
|
||||
notificationContent.setBorder(
|
||||
BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
notificationContent.setOpaque(false);
|
||||
|
||||
notificationContent.add(msgFrom, BorderLayout.NORTH);
|
||||
notificationContent.add(msgContent, BorderLayout.CENTER);
|
||||
notificationContent.add(msgIcon, BorderLayout.WEST);
|
||||
|
||||
return new PopupNotificationPanel(notificationContent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies all interested listeners that a <tt>SystrayPopupMessageEvent</tt>
|
||||
* occured.
|
||||
*
|
||||
* @param SystrayPopupMessageEvent the evt to send to listener.
|
||||
*/
|
||||
private void firePopupMessageClicked(SystrayPopupMessageEvent evt)
|
||||
{
|
||||
logger.trace("Will dispatch the following popup event: " + evt);
|
||||
|
||||
List<SystrayPopupMessageListener> listeners;
|
||||
synchronized (popupMessageListeners)
|
||||
{
|
||||
listeners =
|
||||
new ArrayList<SystrayPopupMessageListener>(
|
||||
popupMessageListeners);
|
||||
}
|
||||
|
||||
for (SystrayPopupMessageListener listener : listeners)
|
||||
listener.popupMessageClicked(evt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements <tt>toString</tt> from <tt>PopupMessageHandler</tt>
|
||||
* @return a description of this handler
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return SwingNotificationActivator.getResources()
|
||||
.getI18NString("impl.swingnotification.POPUP_MESSAGE_HANDLER");
|
||||
}
|
||||
|
||||
/**
|
||||
* provide animation to hide a popup. The animation could be described
|
||||
* as an "inverse" of the one made by <tt>PopupLauncher</tt>.
|
||||
*/
|
||||
class PopupDiscarder implements Runnable
|
||||
{
|
||||
|
||||
private JWindow notificationWindow;
|
||||
|
||||
PopupDiscarder(JWindow notificationWindow)
|
||||
{
|
||||
this.notificationWindow = notificationWindow;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
int height = notificationWindow.getY();
|
||||
int x = notificationWindow.getX();
|
||||
do
|
||||
{
|
||||
notificationWindow.setLocation(
|
||||
x,
|
||||
notificationWindow.getY() + 2);
|
||||
try
|
||||
{
|
||||
Thread.sleep(10);
|
||||
height -= 2;
|
||||
} catch (InterruptedException ex)
|
||||
{
|
||||
logger.warn("exception while discarding" +
|
||||
" popup notification window :", ex);
|
||||
}
|
||||
} while (height > 0);
|
||||
notificationWindow.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* provide animation to show a popup. The popup comes from the bottom of
|
||||
* screen and will stay in the bottom right corner.
|
||||
*/
|
||||
class PopupLauncher implements Runnable
|
||||
{
|
||||
|
||||
private final JWindow notificationWindow;
|
||||
|
||||
private final int x;
|
||||
|
||||
private final int y;
|
||||
|
||||
PopupLauncher(JWindow notificationWindow,
|
||||
GraphicsConfiguration graphicsConf)
|
||||
{
|
||||
this.notificationWindow = notificationWindow;
|
||||
|
||||
final Rectangle rec = graphicsConf.getBounds();
|
||||
|
||||
final Insets ins =
|
||||
Toolkit.getDefaultToolkit().getScreenInsets(graphicsConf);
|
||||
|
||||
x = rec.width + rec.x -
|
||||
ins.right - notificationWindow.getWidth() - 1;
|
||||
|
||||
y = rec.height + rec.y -
|
||||
ins.bottom - notificationWindow.getHeight() - 1;
|
||||
|
||||
notificationWindow.setLocation(x, rec.height);
|
||||
notificationWindow.setVisible(true);
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
int height = y - notificationWindow.getY();
|
||||
do
|
||||
{
|
||||
notificationWindow.setLocation(
|
||||
x,
|
||||
notificationWindow.getY() - 2);
|
||||
try
|
||||
{
|
||||
Thread.sleep(10);
|
||||
height += 2;
|
||||
} catch (InterruptedException ex)
|
||||
{
|
||||
logger.warn("exception while showing" +
|
||||
" popup notification window :", ex);
|
||||
}
|
||||
} while (height < 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.swingnotification;
|
||||
|
||||
import org.osgi.framework.*;
|
||||
|
||||
import net.java.sip.communicator.service.configuration.*;
|
||||
import net.java.sip.communicator.service.resources.*;
|
||||
import net.java.sip.communicator.service.systray.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
/**
|
||||
* Activator for the swing notification service.
|
||||
* @author Symphorien Wanko
|
||||
*/
|
||||
public class SwingNotificationActivator implements BundleActivator
|
||||
{
|
||||
/**
|
||||
* The bundle context in which we started
|
||||
*/
|
||||
public static BundleContext bundleContext;
|
||||
|
||||
/**
|
||||
* A reference to the configuration service.
|
||||
*/
|
||||
private static ConfigurationService configService;
|
||||
|
||||
/**
|
||||
* Logger for this class.
|
||||
*/
|
||||
private static final Logger logger =
|
||||
Logger.getLogger(SwingNotificationActivator.class);
|
||||
|
||||
/**
|
||||
* A reference to the resource management service.
|
||||
*/
|
||||
private static ResourceManagementService resourcesService;
|
||||
|
||||
/**
|
||||
* start the swing notification service and set the swing popup handler as
|
||||
* the default if there is no default popup handler.
|
||||
* @param bc
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
public void start(BundleContext bc) throws Exception
|
||||
{
|
||||
logger.info("Swing Notification ...[ STARTING ]");
|
||||
|
||||
bundleContext = bc;
|
||||
|
||||
PopupMessageHandler handler = null;
|
||||
handler = new PopupMessageHandlerSwingImpl();
|
||||
|
||||
getConfigurationService();
|
||||
|
||||
String defaultHandler =
|
||||
(String) configService.getProperty("systray.POPUP_HANDLER");
|
||||
if (defaultHandler == null)
|
||||
{
|
||||
configService.setProperty(
|
||||
"systray.POPUP_HANDLER", handler.getClass().getName());
|
||||
}
|
||||
bc.registerService(
|
||||
PopupMessageHandler.class.getName()
|
||||
, handler
|
||||
, null);
|
||||
|
||||
logger.info("Swing Notification ...[REGISTERED]");
|
||||
}
|
||||
|
||||
public void stop(BundleContext arg0) throws Exception
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>ConfigurationService</tt> obtained from the bundle
|
||||
* context.
|
||||
* @return the <tt>ConfigurationService</tt> obtained from the bundle
|
||||
* context
|
||||
*/
|
||||
public static ConfigurationService getConfigurationService()
|
||||
{
|
||||
if(configService == null) {
|
||||
ServiceReference configReference = bundleContext
|
||||
.getServiceReference(ConfigurationService.class.getName());
|
||||
|
||||
configService = (ConfigurationService) bundleContext
|
||||
.getService(configReference);
|
||||
}
|
||||
|
||||
return configService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>ResourceManagementService</tt> obtained from the bundle
|
||||
* context.
|
||||
* @return the <tt>ResourceManagementService</tt> obtained from the bundle
|
||||
* context
|
||||
*/
|
||||
public static ResourceManagementService getResources()
|
||||
{
|
||||
if (resourcesService == null)
|
||||
resourcesService =
|
||||
ResourceManagementServiceUtils.getService(bundleContext);
|
||||
return resourcesService;
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
Bundle-Activator: net.java.sip.communicator.impl.swingnotification.SwingNotificationActivator
|
||||
Bundle-Name: Swing Notification Service Provider
|
||||
Bundle-Description: A bundle that implements swing notification.
|
||||
Bundle-Vendor: sip-communicator.org
|
||||
Bundle-Version: 0.0.1
|
||||
System-Bundle: yes
|
||||
Import-Package: org.osgi.framework,
|
||||
net.java.sip.communicator.service.configuration,
|
||||
net.java.sip.communicator.service.resources,
|
||||
net.java.sip.communicator.service.systray,
|
||||
net.java.sip.communicator.service.systray.event,
|
||||
net.java.sip.communicator.util,
|
||||
net.java.sip.communicator.util.swing,
|
||||
javax.swing
|
||||
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.systray;
|
||||
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import net.java.sip.communicator.impl.systray.jdic.*;
|
||||
import net.java.sip.communicator.service.systray.*;
|
||||
import net.java.sip.communicator.service.systray.event.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
/**
|
||||
* An implementation of the <tt>PopupMsystrayessageHandler</tt> using the tray icon.
|
||||
*/
|
||||
public class PopupMessageHandlerTrayIconImpl implements PopupMessageHandler
|
||||
{
|
||||
/**
|
||||
* The logger for this class.
|
||||
*/
|
||||
private static Logger logger =
|
||||
Logger.getLogger(PopupMessageHandlerTrayIconImpl.class);
|
||||
|
||||
/** The list of all added systray popup listeners */
|
||||
private final List<SystrayPopupMessageListener> PopupMessageListener =
|
||||
new Vector<SystrayPopupMessageListener>();
|
||||
|
||||
/** the tray icon we will use to popup messages */
|
||||
private TrayIcon trayIcon;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new <tt>PopupMessageHandlerTrayIconImpl</tt> which will uses
|
||||
* the provided <tt>TrayIcon</tt> to show message.
|
||||
* @param icon the icon we will use to show popup message.
|
||||
*/
|
||||
public PopupMessageHandlerTrayIconImpl(TrayIcon icon)
|
||||
{
|
||||
trayIcon = icon;
|
||||
icon.addBalloonActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
firePopupMessageClicked(new SystrayPopupMessageEvent(e));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of <tt>PopupMessageHandler.addPopupMessageListener</tt>
|
||||
* @param listener the listener to add
|
||||
*/
|
||||
public void addPopupMessageListener(SystrayPopupMessageListener listener)
|
||||
{
|
||||
synchronized (PopupMessageListener)
|
||||
{
|
||||
if (!PopupMessageListener.contains(listener))
|
||||
PopupMessageListener.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of <tt>PopupMessageHandler.removePopupMessageListener</tt>
|
||||
* @param listener the listener to remove
|
||||
*/
|
||||
public void removePopupMessageListener(SystrayPopupMessageListener listener)
|
||||
{
|
||||
synchronized (PopupMessageListener)
|
||||
{
|
||||
PopupMessageListener.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements <tt>PopupMessageHandler#showPopupMessage()</tt>
|
||||
*
|
||||
* @param popupMessage the message we will show
|
||||
*/
|
||||
public void showPopupMessage(PopupMessage popupMessage)
|
||||
{
|
||||
// remove eventual html code before showing the popup message
|
||||
String messageContent = popupMessage.getMessage()
|
||||
.replaceAll("</?\\w++[^>]*+>", "");
|
||||
String messageTitle = popupMessage.getMessageTitle()
|
||||
.replaceAll("</?\\w++[^>]*+>", "");
|
||||
|
||||
if(messageContent.length() > 40)
|
||||
messageContent = messageContent.substring(0, 40).concat("...");
|
||||
trayIcon.displayMessage(
|
||||
messageTitle,
|
||||
messageContent,
|
||||
TrayIcon.NONE_MESSAGE_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies all interested listeners that a <tt>SystrayPopupMessageEvent</tt>
|
||||
* has occured.
|
||||
*
|
||||
* @param SystrayPopupMessageEvent the evt to send to listener.
|
||||
*/
|
||||
private void firePopupMessageClicked(SystrayPopupMessageEvent evt)
|
||||
{
|
||||
logger.trace("Will dispatch the following systray popup event: " + evt);
|
||||
|
||||
List<SystrayPopupMessageListener> listeners;
|
||||
synchronized (PopupMessageListener)
|
||||
{
|
||||
listeners =
|
||||
new ArrayList<SystrayPopupMessageListener>(
|
||||
PopupMessageListener);
|
||||
}
|
||||
|
||||
for (SystrayPopupMessageListener listener : listeners)
|
||||
listener.popupMessageClicked(evt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements <tt>toString</tt> from <tt>PopupMessageHandler</tt>
|
||||
* @return a description of this handler
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return SystrayActivator.getResources()
|
||||
.getI18NString("impl.systray.POPUP_MESSAGE_HANDLER");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,192 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.service.systray;
|
||||
|
||||
import javax.swing.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* The <tt>PopupMessage</tt> class encloses informations to show in a popup.
|
||||
* While a message title and a message body are mandatory informations,
|
||||
* a popup message could provides more stuffs like a component or an image which
|
||||
* may be used by a <tt>PopupMessageHandler</tt> capable to handle it.
|
||||
*
|
||||
* @author Symphorien Wanko
|
||||
*/
|
||||
public class PopupMessage
|
||||
{
|
||||
|
||||
/** message to show in the popup */
|
||||
private String message;
|
||||
|
||||
/** title of the message */
|
||||
private String messageTitle;
|
||||
|
||||
/** An icon representing the contact from which the notification comes */
|
||||
private ImageIcon imageIcon;
|
||||
|
||||
/** A ready to show <tt>JComponet</tt> for this <tt>PopupMessage</tt> */
|
||||
private JComponent component;
|
||||
|
||||
/** type of the message */
|
||||
private int messageType;
|
||||
|
||||
/** the contact which is the cause of this popup message */
|
||||
private Contact contact;
|
||||
|
||||
/**
|
||||
* Creates a <tt>PopupMessage</tt> with the given title and message inside
|
||||
*
|
||||
* @param messageTitle title of the message
|
||||
* @param message message to show in the systray
|
||||
*/
|
||||
public PopupMessage(String messageTitle, String message)
|
||||
{
|
||||
this.messageTitle = messageTitle;
|
||||
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.
|
||||
*
|
||||
* @param title the title, which will be shown
|
||||
* @param content 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)
|
||||
{
|
||||
this(title, content);
|
||||
this.messageType = messageType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <tt>PopupMessage</tt> with the given title, message and
|
||||
* icon.
|
||||
*
|
||||
* @param messageTitle 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)
|
||||
{
|
||||
this(title, message);
|
||||
this.imageIcon = imageIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 component the component to put in the <tt>PopupMessage</tt>
|
||||
* @param title of the message
|
||||
* @param message message to use in place of the component
|
||||
*/
|
||||
public PopupMessage(JComponent component, String title, String message)
|
||||
{
|
||||
this(title, message);
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the message
|
||||
*/
|
||||
public String getMessage()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message the message to set
|
||||
*/
|
||||
public void setMessage(String message)
|
||||
{
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the messageTitle
|
||||
*/
|
||||
public String getMessageTitle()
|
||||
{
|
||||
return messageTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param messageTitle the messageTitle to set
|
||||
*/
|
||||
public void setMessageTitle(String messageTitle)
|
||||
{
|
||||
this.messageTitle = messageTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the component
|
||||
*/
|
||||
public JComponent getComponent()
|
||||
{
|
||||
return component;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param component the component to set
|
||||
*/
|
||||
public void setComponent(JComponent component)
|
||||
{
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the imageIcon
|
||||
*/
|
||||
public ImageIcon getIcon()
|
||||
{
|
||||
return imageIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param imageIcon the imageIcon to set
|
||||
*/
|
||||
public void setIcon(ImageIcon imageIcon)
|
||||
{
|
||||
this.imageIcon = imageIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the messageType
|
||||
*/
|
||||
public int getMessageType()
|
||||
{
|
||||
return messageType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param messageType the messageType to set
|
||||
*/
|
||||
public void setMessageType(int messageType)
|
||||
{
|
||||
this.messageType = messageType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the contact
|
||||
*/
|
||||
public Contact getContact()
|
||||
{
|
||||
return contact;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contact the contact to set
|
||||
*/
|
||||
public void setContact(Contact contact)
|
||||
{
|
||||
this.contact = contact;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.service.systray;
|
||||
|
||||
import net.java.sip.communicator.service.systray.event.*;
|
||||
|
||||
/**
|
||||
* The <tt>PopupMessageHandler</tt> role is to give differents methods to
|
||||
* display <tt>PopupMessage</tt> and listen for events (user click)
|
||||
* coming from that popup.
|
||||
*
|
||||
* @author Symphorien Wanko
|
||||
*/
|
||||
public interface PopupMessageHandler
|
||||
{
|
||||
|
||||
/**
|
||||
* Register a listener to be informed of systray popup events.
|
||||
*
|
||||
* @param listener the listened which will be informed of systray popup
|
||||
* events
|
||||
*/
|
||||
public void addPopupMessageListener(SystrayPopupMessageListener listener);
|
||||
|
||||
/**
|
||||
* Removes a listener previously added with <tt>addPopupMessageListener</tt>.
|
||||
*
|
||||
* @param listener the listener to remove
|
||||
*/
|
||||
public void removePopupMessageListener(SystrayPopupMessageListener listener);
|
||||
|
||||
/**
|
||||
* Shows the given <tt>PopupMessage</tt>. Any given <tt>PopupMessage</tt>
|
||||
* will provides a minimum of two values : a message title and
|
||||
* a message body. thoose two values are respectively available via
|
||||
* <tt>PopupMessage#getMessageTitle()</tt> and
|
||||
* <tt>PopupMessage#getMessage()</tt>
|
||||
*
|
||||
* @param popupMessage the message to show
|
||||
*/
|
||||
public void showPopupMessage(PopupMessage popupMessage);
|
||||
|
||||
/**
|
||||
* Returns a readable description of this popup handler. It is expected
|
||||
* to be a localized string.
|
||||
*
|
||||
* @returns a string describing this popup handler
|
||||
*/
|
||||
@Override
|
||||
public String toString();
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
|
||||
package net.java.sip.communicator.util.swing;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
/**
|
||||
* A custom panel to handle systray popup notification
|
||||
*
|
||||
* @author Symphorien Wanko
|
||||
*/
|
||||
public class PopupNotificationPanel extends SIPCommFrame.MainContentPane
|
||||
{
|
||||
/** logger for this class */
|
||||
private final Logger logger = Logger.getLogger(SIPCommFrame.class);
|
||||
|
||||
/**
|
||||
* Creates a new <tt>PopupNotificationPanel</tt> with a customized panel title
|
||||
*/
|
||||
private PopupNotificationPanel()
|
||||
{
|
||||
JLabel notifTitle = new JLabel(
|
||||
UtilActivator.getResources().getSettingsString(
|
||||
"service.gui.APPLICATION_NAME"),
|
||||
UtilActivator.getResources().getImage(
|
||||
"service.gui.SIP_COMMUNICATOR_LOGO"),
|
||||
SwingConstants.LEFT);
|
||||
|
||||
final JLabel notifClose = new JLabel(
|
||||
UtilActivator.getResources()
|
||||
.getImage("service.gui.lookandfeel.CLOSE_TAB_ICON"));
|
||||
notifClose.setToolTipText(UtilActivator.getResources()
|
||||
.getI18NString("service.gui.CLOSE"));
|
||||
|
||||
notifClose.addMouseListener(new MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e)
|
||||
{
|
||||
try
|
||||
{
|
||||
// TODO : that is pretty ugly. It will be nice if
|
||||
// it is possible to reach the top window in a better way
|
||||
JWindow jw = (JWindow) notifClose
|
||||
.getParent().getParent().getParent()
|
||||
.getParent().getParent().getParent();
|
||||
jw.dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// should never happens : if the user clicks on the close
|
||||
// icon, it means that the popup window were visible
|
||||
logger.warn("error while getting the popup window :"
|
||||
, ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
BorderLayout borderLayout = new BorderLayout();
|
||||
borderLayout.setVgap(5);
|
||||
|
||||
JPanel notificationWindowTitle = new JPanel(borderLayout);
|
||||
notificationWindowTitle
|
||||
.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
notificationWindowTitle.setOpaque(false);
|
||||
|
||||
notificationWindowTitle.add(notifTitle, BorderLayout.WEST);
|
||||
notificationWindowTitle.add(notifClose, BorderLayout.EAST);
|
||||
|
||||
JSeparator jSep = new JSeparator();
|
||||
|
||||
notificationWindowTitle.add(jSep, BorderLayout.SOUTH);
|
||||
add(notificationWindowTitle, BorderLayout.NORTH);
|
||||
setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new notifcation panel with <tt>notificationContent</tt> as
|
||||
* the component to put in that panel
|
||||
*
|
||||
* @param notificationContent content to add in the new created
|
||||
* <tt>PopupNotificationPanel</tt>
|
||||
*/
|
||||
public PopupNotificationPanel(JPanel notificationContent)
|
||||
{
|
||||
this();
|
||||
add(notificationContent, BorderLayout.CENTER);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.slick.popupmessagehandler;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
import org.osgi.framework.*;
|
||||
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Symphorien Wanko
|
||||
*/
|
||||
public class PopupMessageHandlerSLick extends TestSuite implements BundleActivator
|
||||
{
|
||||
/** Logger for this class */
|
||||
private static Logger logger =
|
||||
Logger.getLogger(PopupMessageHandlerSLick.class);
|
||||
|
||||
/** our bundle context */
|
||||
protected static BundleContext bundleContext = null;
|
||||
|
||||
/** implements BundleActivator.start() */
|
||||
public void start(BundleContext bc) throws Exception
|
||||
{
|
||||
logger.info("starting popup message test ");
|
||||
|
||||
bundleContext = bc;
|
||||
|
||||
setName("PopupMessageHandlerSLick");
|
||||
|
||||
Hashtable properties = new Hashtable();
|
||||
|
||||
properties.put("service.pid", getName());
|
||||
|
||||
addTest(TestPopupMessageHandler.suite());
|
||||
|
||||
bundleContext.registerService(getClass().getName(), this, properties);
|
||||
}
|
||||
|
||||
/** implements BundleActivator.stop() */
|
||||
public void stop(BundleContext bc) throws Exception
|
||||
{}
|
||||
|
||||
}
|
||||
@ -0,0 +1,164 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.slick.popupmessagehandler;
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
import org.osgi.framework.*;
|
||||
|
||||
import net.java.sip.communicator.service.notification.*;
|
||||
import net.java.sip.communicator.service.systray.*;
|
||||
import net.java.sip.communicator.service.systray.event.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Test suite for the popup message handler interface.
|
||||
* @author Symphorien Wanko
|
||||
*/
|
||||
public class TestPopupMessageHandler
|
||||
extends TestCase
|
||||
{
|
||||
/** Logger for this class */
|
||||
private static final Logger logger
|
||||
= Logger.getLogger(TestPopupMessageHandler.class);
|
||||
|
||||
/**
|
||||
* the <tt>SystrayService</tt> reference we will get from bundle
|
||||
* context to register ours handlers
|
||||
*/
|
||||
private static SystrayService systrayService = null;
|
||||
|
||||
/**
|
||||
* reference to services we will retrive from bundle context
|
||||
*/
|
||||
private static ServiceReference serviceReference = null;
|
||||
|
||||
/**
|
||||
* the <tt>NotificationService</tt> reference we will get from bundle
|
||||
* context to send notifications to our handlers
|
||||
*/
|
||||
private static NotificationService notificationService = null;
|
||||
|
||||
/**
|
||||
* a trivial message we will send via the nofification service.
|
||||
*/
|
||||
private String messageStart = "Lorem ipsum dolor sit amet.";
|
||||
|
||||
/**
|
||||
* the first handler we will use.
|
||||
*/
|
||||
private PopupMessageHandler handler1 = new MockPopupMessageHandler();
|
||||
|
||||
/**
|
||||
* the second handler we will use.
|
||||
*/
|
||||
private PopupMessageHandler handler2 = new MockPopupMessageHandler();
|
||||
|
||||
/**
|
||||
* A reference to the bundle context in which we are runing.
|
||||
*/
|
||||
private BundleContext bc = PopupMessageHandlerSLick.bundleContext;
|
||||
|
||||
/**
|
||||
* Create an instance to launch tests.
|
||||
* @param name name of the test case
|
||||
*/
|
||||
public TestPopupMessageHandler(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the test suite
|
||||
* @return the <tt>TestSuite</tt> created
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
TestSuite suite = new TestSuite();
|
||||
|
||||
suite.addTest(
|
||||
new TestPopupMessageHandler("testHandlerModification"));
|
||||
|
||||
suite.addTest(
|
||||
new TestPopupMessageHandler("testNotificationHandling"));
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
||||
/**
|
||||
* here we will test (get/set)ActivePopupMesssageHandler()
|
||||
*/
|
||||
public void testHandlerModification()
|
||||
{
|
||||
serviceReference = bc.getServiceReference(
|
||||
SystrayService.class.getName());
|
||||
|
||||
systrayService = (SystrayService) bc.getService(serviceReference);
|
||||
|
||||
systrayService.setActivePopupMessageHandler(handler1);
|
||||
|
||||
// do we have our handler as expected ?
|
||||
assertEquals(handler1, systrayService.getActivePopupMessageHandler());
|
||||
|
||||
// was handler1 the previous handler as returned by the set method ?
|
||||
assertEquals(
|
||||
handler1,
|
||||
systrayService.setActivePopupMessageHandler(handler2));
|
||||
|
||||
// and now handler2 is our curretn hander
|
||||
assertEquals(handler2, systrayService.getActivePopupMessageHandler());
|
||||
}
|
||||
|
||||
/**
|
||||
* we will fire a notification then see if it was handled by the right handler
|
||||
* which received the right message.
|
||||
*/
|
||||
public void testNotificationHandling()
|
||||
{
|
||||
serviceReference = bc.getServiceReference(
|
||||
NotificationService.class.getName());
|
||||
|
||||
notificationService = (NotificationService) bc.getService(serviceReference);
|
||||
|
||||
notificationService.fireNotification(
|
||||
NotificationService.ACTION_POPUP_MESSAGE,
|
||||
messageStart,
|
||||
messageStart);
|
||||
}
|
||||
|
||||
/** A trivial handler implementing <tt>PopupMessageHandler</tt> */
|
||||
private class MockPopupMessageHandler implements PopupMessageHandler
|
||||
{
|
||||
|
||||
/**
|
||||
* implements <tt>PopupMessageHandler.addPopupMessageListener()</tt>
|
||||
*/
|
||||
public void addPopupMessageListener(SystrayPopupMessageListener listener)
|
||||
{}
|
||||
|
||||
/**
|
||||
* implements <tt>PopupMessageHandler.removePopupMessageListener()</tt>
|
||||
*/
|
||||
public void removePopupMessageListener(SystrayPopupMessageListener listener)
|
||||
{}
|
||||
|
||||
/**
|
||||
* implements <tt>PopupMessageHandler#showPopupMessage()</tt>
|
||||
*/
|
||||
public void showPopupMessage(PopupMessage popupMsg)
|
||||
{
|
||||
// is it the expected message and title ?
|
||||
assertEquals(messageStart, popupMsg.getMessage());
|
||||
assertEquals(messageStart, popupMsg.getMessageTitle());
|
||||
|
||||
// is it the expected handler which is handling it ?
|
||||
assertEquals(handler2, this);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
Bundle-Activator: net.java.sip.communicator.slick.popupmessagehandler.PopupMessageHandlerSLick
|
||||
Bundle-Name: PopupMessageHandler Test
|
||||
Bundle-Description: PopupMessageHandler Test
|
||||
Bundle-Vendor: sip-communicator.org
|
||||
Bundle-Version: 0.0.1
|
||||
System-Bundle: yes
|
||||
Import-Package: junit.framework,
|
||||
org.osgi.framework,
|
||||
net.java.sip.communicator.service.notification,
|
||||
net.java.sip.communicator.service.systray,
|
||||
net.java.sip.communicator.service.systray.event,
|
||||
net.java.sip.communicator.util,
|
||||
Export-Package: net.java.sip.communicator.slick.popupmessagehandler,
|
||||
Loading…
Reference in new issue