From 80b489dfea8ab16d81a958b9c8a033ff844bee97 Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Wed, 22 Aug 2007 15:57:36 +0000 Subject: [PATCH] notification service enhancements --- .../CommandNotificationHandler.java | 29 ++++ .../LogMessageNotificationHandler.java | 50 +++++++ .../NotificationActionHandler.java | 18 +++ .../NotificationChangeListener.java | 50 +++++-- .../notification/NotificationService.java | 130 +++++++++++++++--- .../PopupMessageNotificationHandler.java | 36 +++++ .../SoundNotificationHandler.java | 47 +++++++ .../event/NotificationActionAddedEvent.java | 57 -------- .../event/NotificationActionTypeEvent.java | 127 +++++++++++++++++ .../event/NotificationEventTypeEvent.java | 80 +++++++++++ 10 files changed, 542 insertions(+), 82 deletions(-) create mode 100644 src/net/java/sip/communicator/service/notification/CommandNotificationHandler.java create mode 100644 src/net/java/sip/communicator/service/notification/LogMessageNotificationHandler.java create mode 100644 src/net/java/sip/communicator/service/notification/NotificationActionHandler.java create mode 100644 src/net/java/sip/communicator/service/notification/PopupMessageNotificationHandler.java create mode 100644 src/net/java/sip/communicator/service/notification/SoundNotificationHandler.java delete mode 100644 src/net/java/sip/communicator/service/notification/event/NotificationActionAddedEvent.java create mode 100644 src/net/java/sip/communicator/service/notification/event/NotificationActionTypeEvent.java create mode 100644 src/net/java/sip/communicator/service/notification/event/NotificationEventTypeEvent.java diff --git a/src/net/java/sip/communicator/service/notification/CommandNotificationHandler.java b/src/net/java/sip/communicator/service/notification/CommandNotificationHandler.java new file mode 100644 index 000000000..feecab624 --- /dev/null +++ b/src/net/java/sip/communicator/service/notification/CommandNotificationHandler.java @@ -0,0 +1,29 @@ +/* + * 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.notification; + +/** + * The CommandNotificationHandler interface is meant to be implemented + * by the notification bundle in order to provide handling of command actions. + * + * @author Yana Stamcheva + */ +public interface CommandNotificationHandler + extends NotificationActionHandler +{ + /** + * Executes the program pointed by the descriptor. + */ + public void execute(); + + /** + * Returns the descriptor pointing to the command to be executed. + * + * @return the descriptor pointing to the command to be executed. + */ + public String getDescriptor(); +} diff --git a/src/net/java/sip/communicator/service/notification/LogMessageNotificationHandler.java b/src/net/java/sip/communicator/service/notification/LogMessageNotificationHandler.java new file mode 100644 index 000000000..41025ee72 --- /dev/null +++ b/src/net/java/sip/communicator/service/notification/LogMessageNotificationHandler.java @@ -0,0 +1,50 @@ +/* + * 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.notification; + +/** + * The LogMessageNotificationHandler interface is meant to be + * implemented by the notification bundle in order to provide handling of + * log actions. + * + * @author Yana Stamcheva + */ +public interface LogMessageNotificationHandler + extends NotificationActionHandler +{ + /** + * Indicates that this log is of type trace. If this logType is set + * the messages would be logged as trace logs. + */ + public static final String TRACE_LOG_TYPE = "TraceLog"; + + /** + * Indicates that this log is of type info. If this logType is set + * the messages would be logged as info logs. + */ + public static final String INFO_LOG_TYPE = "InfoLog"; + + /** + * Indicates that this log is of type error. If this logType is set + * the messages would be logged as error logs. + */ + public static final String ERROR_LOG_TYPE = "ErrorLog"; + + /** + * Returns the type of the log. One of the XXX_LOG_TYPE-s declared in this + * interface. + * @return the type of the log. One of the XXX_LOG_TYPE-s declared in this + * interface. + */ + public String getLogType(); + + /** + * Logs the given message. + * @param message the message to log + */ + public void logMessage(String message); +} diff --git a/src/net/java/sip/communicator/service/notification/NotificationActionHandler.java b/src/net/java/sip/communicator/service/notification/NotificationActionHandler.java new file mode 100644 index 000000000..6ff99213d --- /dev/null +++ b/src/net/java/sip/communicator/service/notification/NotificationActionHandler.java @@ -0,0 +1,18 @@ +/* + * 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.notification; + +/** + * The NotificationActionHandler is the parent interface of all specific + * notification handlers used for handling different action types. This + * interface is used in the NotificationService in all methods dealing with + * action handlers. + * + * @author Yana Stamcheva + */ +public interface NotificationActionHandler +{} diff --git a/src/net/java/sip/communicator/service/notification/NotificationChangeListener.java b/src/net/java/sip/communicator/service/notification/NotificationChangeListener.java index 0443e39ae..a61fcd7b1 100644 --- a/src/net/java/sip/communicator/service/notification/NotificationChangeListener.java +++ b/src/net/java/sip/communicator/service/notification/NotificationChangeListener.java @@ -8,25 +8,59 @@ import java.util.*; +import net.java.sip.communicator.service.notification.event.*; + /** - * + * The NotificationChangeListener is notified any time an action + * type or an event type is added, removed or changed. + * * @author Emil Ivov + * @author Yana Stamcheva */ public interface NotificationChangeListener extends EventListener { /** * This method gets called when a new notification action has been defined - * for one of the event types defined for a particular event type. + * for a particular event type. + * + * @param event the NotificationActionTypeEvent, which is + * dispatched when a new action has been added. */ - public void actionAdded(); - - public void actionRemoved(); + public void actionAdded(NotificationActionTypeEvent event); - public void actionChanged(); + /** + * This method gets called when a notification action for a particular event + * type has been removed. + * + * @param event the NotificationActionTypeEvent, which is + * dispatched when an action has been removed. + */ + public void actionRemoved(NotificationActionTypeEvent event); + + /** + * This method gets called when a notification action for a particular event + * type has been changed (for example the corresponding descriptor has + * changed). + * + * @param event the NotificationActionTypeEvent, which is + * dispatched when an action has been changed. + */ + public void actionChanged(NotificationActionTypeEvent event); - public void eventTypeAdded(); + /** + * This method gets called when a new event type has been added. + * + * @param event the NotificationEventTypeEvent, which is dispatched + * when a new event type has been added + */ + public void eventTypeAdded(NotificationEventTypeEvent event); + /** + * This method gets called when an event type has been removed. + * + * @param event the NotificationEventTypeEvent, which is dispatched + * when an event type has been removed. + */ public void eventTypeRemoved(); - } diff --git a/src/net/java/sip/communicator/service/notification/NotificationService.java b/src/net/java/sip/communicator/service/notification/NotificationService.java index 7c4486ccc..52354bdd8 100644 --- a/src/net/java/sip/communicator/service/notification/NotificationService.java +++ b/src/net/java/sip/communicator/service/notification/NotificationService.java @@ -1,4 +1,4 @@ -/*r +/* * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. * * Distributable under LGPL license. @@ -48,16 +48,107 @@ public interface NotificationService public static final String ACTION_COMMAND = "CommandAction"; /** - * Registers the specified actionDescriptor as a notification that - * should be used every time an event with the specified eventType - * has occurred. + * Creates a SoundNotificationHandler, by specifying the + * path pointing to the sound file and the loop interval if the sound should + * be played in loop. If the sound should be played just once the loop + * interval should be set to -1. The SoundNotificationHandler is + * the one that would take care of playing the sound, when a notification + * is fired. + * + * @param soundFileDescriptor the path pointing to the sound file + * @param loopInterval the interval of milliseconds to repeat the sound in + * loop + * @return the SoundNotificationHandler is the one, that would take + * care of playing the given sound, when a notification is fired + */ + public SoundNotificationHandler createSoundNotificationHandler( + String soundFileDescriptor, + int loopInterval); + + /** + * Creates a PopupMessageNotificationHandler, by specifying the + * default message to show, when no message is provided to the + * fireNotification method. The + * PopupMessageNotificationHandler is the one that would take care + * of showing a popup message (through the systray service for example), + * when a notification is fired. + * + * @param defaultMessage the message to show if not message is provided to + * the fireNotification method + * @return the PopupMessageNotificationHandler is the one, that + * would take care of showing a popup message (through the systray service + * for example), when a notification is fired. + */ + public PopupMessageNotificationHandler createPopupMessageNotificationHandler( + String defaultMessage); + + /** + * Creates a LogMessageNotificationHandler, by specifying the + * type of the log (error, trace, info, etc.). The + * LogMessageNotificationHandler is the one that would take care + * of logging a message (through the application log system), when a + * notification is fired. + * + * @param logType the type of the log (error, trace, etc.). One of the types + * defined in the LogMessageNotificationHandler interface + * @return the LogMessageNotificationHandler is the one, that would + * take care of logging a message (through the application log system), when + * a notification is fired. + */ + public LogMessageNotificationHandler createLogMessageNotificationHandler( + String logType); + + /** + * Creates a CommandNotificationHandler, by specifying the path to + * the command file to execute, when a notification is fired. The + * CommandNotificationHandler is the one that would take care + * of executing the given program, when a notification is fired. + * + * @param commandFileDescriptor the path to the file containing the program + * to execute + * @return the CommandNotificationHandler is the one, that would + * take care of executing a program, when a notification is fired. + */ + public CommandNotificationHandler createCommandNotificationHandler( + String commandFileDescriptor); + + /** + * Registers a notification for the given eventType by specifying + * the type of the action to be performed when a notification is fired for + * this event and the corresponding handler that should be used to + * handle the action. Unlike the other registerNotificationForEvent + * method, this one allows the user to specify its own + * NotificationHandler, which would be used to handle notifications + * for the specified actionType. + * + * @param eventType the name of the event (as defined by the plug-in that's + * registering it) that we are setting an action for. + * @param actionType the type of the action that is to be executed when the + * specified event occurs (could be one of the ACTION_XXX fields). + * @param handler the NotificationActionHandler, which would be + * used to perform the notification action. + * @throws IllegalArgumentException if the specified handler do not + * correspond to the given actionType. + */ + public void registerNotificationForEvent( String eventType, + String actionType, + NotificationActionHandler handler) + throws IllegalArgumentException; + + /** + * Registers a notification for the given eventType by specifying + * the type of the action to be performed when a notification is fired for + * this event, the actionDescriptor for sound and command actions + * and the defaultMessage for popup and log actions. Actions + * registered by this method would be handled by some default + * NotificationHandlers, declared by the implementation. *

* The method allows registering more than one actionType for a specific * event. Setting twice the same actionType for the same * eventType however would cause the first setting to be * overridden. * - * @param eventType the name of the event (as defined by the plugin that's + * @param eventType the name of the event (as defined by the plug-in that's * registering it) that we are setting an action for. * @param actionType the type of the action that is to be executed when the * specified event occurs (could be one of the ACTION_XXX fields). @@ -67,10 +158,10 @@ public interface NotificationService * @param defaultMessage the default message to use if no specific message * has been provided when firing the notification. */ - public void registerEventNotification(String eventType, - String actionType, - String actionDescriptor, - String defaultMessage); + public void registerNotificationForEvent( String eventType, + String actionType, + String actionDescriptor, + String defaultMessage); /** * Removes the given eventType from the list of event notifications. @@ -128,8 +219,8 @@ public void removeEventNotificationAction( String eventType, public Map getEventNotifications(String eventType); /** - * Returns the descriptor of the action of type actionType that - * should be executed when an event of eventType has occurred. + * Returns the NotificationActionHandler corresponding to the given + * event and action types. *

* This method returns null if the given eventType or * actionType are not contained in the list of registered types. @@ -137,11 +228,12 @@ public void removeEventNotificationAction( String eventType, * @param eventType the type of the event that we'd like to retrieve. * @param actionType the type of the action that we'd like to retrieve a * descriptor for. - * @return a String containing a descriptor of the action to be executed - * when an event of the specified type has occurred. + * @return the NotificationActionHandler corresponding to the given + * event and action types */ - public String getEventNotificationActionDescriptor(String eventType, - String actionType); + public NotificationActionHandler getEventNotificationActionHandler( + String eventType, + String actionType); /** * Registers a listener that would be notified of changes that have occurred @@ -171,10 +263,14 @@ public String getEventNotificationActionDescriptor(String eventType, * * @param eventType the type of the event that we'd like to fire a * notification for. + * @param messageTitle the message title to use if and where appropriate + * (e.g. with systray) * @param message the message to use if and where appropriate (e.g. with * systray or log notification.) */ - public void fireNotification(String eventType, String message); + public void fireNotification( String eventType, + String messageTitle, + String message); /** * Fires all notifications registered for the specified eventType @@ -189,7 +285,7 @@ public String getEventNotificationActionDescriptor(String eventType, * notification for. */ public void fireNotification(String eventType); - + /** * Activates or desactivates all notification actions related to the * specified eventType. This method does nothing if the given diff --git a/src/net/java/sip/communicator/service/notification/PopupMessageNotificationHandler.java b/src/net/java/sip/communicator/service/notification/PopupMessageNotificationHandler.java new file mode 100644 index 000000000..2aa519de5 --- /dev/null +++ b/src/net/java/sip/communicator/service/notification/PopupMessageNotificationHandler.java @@ -0,0 +1,36 @@ +/* + * 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.notification; + +/** + * The PopupMessageNotificationHandler interface is meant to be + * implemented by the notification bundle in order to provide handling of + * popup message actions. + * + * @author Yana Stamcheva + */ +public interface PopupMessageNotificationHandler + extends NotificationActionHandler +{ + /** + * Returns the default message to be used when no message is provided to the + * popupMessage method. + * + * @return the default message to be used when no message is provided to the + * popupMessage method. + */ + public String getDefaultMessage(); + + /** + * Pops up a message with the given message content and the given + * title. + * + * @param title the title of the popup + * @param message the message to show in the popup + */ + public void popupMessage(String title, String message); +} diff --git a/src/net/java/sip/communicator/service/notification/SoundNotificationHandler.java b/src/net/java/sip/communicator/service/notification/SoundNotificationHandler.java new file mode 100644 index 000000000..9e2758e7a --- /dev/null +++ b/src/net/java/sip/communicator/service/notification/SoundNotificationHandler.java @@ -0,0 +1,47 @@ +/* + * 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.notification; + +/** + * The SoundNotificationHandler interface is meant to be + * implemented by the notification bundle in order to provide handling of + * sound actions. + * + * @author Yana Stamcheva + */ +public interface SoundNotificationHandler + extends NotificationActionHandler +{ + /** + * Returns the loop interval. This is the interval of milliseconds to wait + * before repeating the sound, when playing a sound in loop. If this method + * returns -1 the sound should not played in loop. + * + * @return the loop interval + */ + public int getLoopInterval(); + + /** + * Returns the descriptor pointing to the sound to be played. + * + * @return the descriptor pointing to the sound to be played. + */ + public String getDescriptor(); + + /** + * Start playing the sound pointed by getDescriotor. This + * method should check the loopInterval value to distinguish whether to play + * a simple sound or to play it in loop. + */ + public void start(); + + /** + * Stops playing the sound pointing by getDescriptor. This method + * is meant to be used to stop sounds that are played in loop. + */ + public void stop(); +} \ No newline at end of file diff --git a/src/net/java/sip/communicator/service/notification/event/NotificationActionAddedEvent.java b/src/net/java/sip/communicator/service/notification/event/NotificationActionAddedEvent.java deleted file mode 100644 index a1a1c5b61..000000000 --- a/src/net/java/sip/communicator/service/notification/event/NotificationActionAddedEvent.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.notification.event; - -import java.util.*; -import net.java.sip.communicator.service.notification.*; - -/** - * Fired any time that a new action (i.e. of an action type previously not - * registered for the corresponding event type) has been added for an event - * type. - * - * @author Emil Ivov - */ -public class NotificationActionAddedEvent - extends EventObject -{ - /** - * The type of the notification action that is being added. - */ - private String actionType = null; - - /** - * The type of the event that a new action is being added for. - */ - private String eventType = null; - - /** - * The descriptor of the action (i.e. audio file uri, or a command line - * string) that will be performed when notifications are being fired for - * the corresponding event type. - */ - private String actionDescriptor = null; - - /** - * Creates an instance of this event according to the specified type. - * @param source NotificationService - * @param eventType String - * @param actionType String - * @param actionDescriptor String - */ - public NotificationActionAddedEvent(NotificationService source, - String eventType, - String actionType, - String actionDescriptor) - { - super(source); - this.eventType = eventType; - this.actionType = actionType; - this.actionDescriptor = actionDescriptor; - } - -} diff --git a/src/net/java/sip/communicator/service/notification/event/NotificationActionTypeEvent.java b/src/net/java/sip/communicator/service/notification/event/NotificationActionTypeEvent.java new file mode 100644 index 000000000..e6ca10964 --- /dev/null +++ b/src/net/java/sip/communicator/service/notification/event/NotificationActionTypeEvent.java @@ -0,0 +1,127 @@ +/* + * 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.notification.event; + +import java.util.*; +import net.java.sip.communicator.service.notification.*; + +/** + * Fired any time an action type is added, removed or changed. + * + * @author Emil Ivov + * @author Yana Stamcheva + */ +public class NotificationActionTypeEvent + extends EventObject +{ + /** + * Indicates that a new action is added to an event type. + */ + public static final String ACTION_ADDED = "ActionAdded"; + + /** + * Indicates that an action was removed for a given event type. + */ + public static final String ACTION_REMOVED = "ActionRemoved"; + + /** + * Indicates that an action for a given event type has changed. For example + * the action descriptor is changed. + */ + public static final String ACTION_CHANGED = "ActionChanged"; + + /** + * The type of the notification action that is being added. + */ + private String sourceActionType = null; + + /** + * The type of the event that a new action is being added for. + */ + private String sourceEventType = null; + + /** + * The descriptor of the action (i.e. audio file uri, or a command line + * string) that will be performed when notifications are being fired for + * the corresponding event type. + */ + private NotificationActionHandler actionHandler = null; + + /** + * The type of this event. One of the static field constants declared in + * this class. + */ + private String eventType = null; + + /** + * Creates an instance of this event according to the specified type. + * + * @param source the NotificationService that dispatched this event + * @param eventType the type of this event. One of the static fields + * declared in this class + * @param sourceEventType the event type for which this event occured + * @param sourceActionType the action type corresponding to this event + * @param actionHandler the NotificationActionHandler that handles + * the given action + */ + public NotificationActionTypeEvent( NotificationService source, + String eventType, + String sourceEventType, + String sourceActionType, + NotificationActionHandler actionHandler) + { + super(source); + + this.eventType = eventType; + this.sourceEventType = sourceEventType; + this.sourceActionType = sourceActionType; + this.actionHandler = actionHandler; + } + + /** + * Returns the action type, for which this event is about. + * + * @return the action type, for which this event is about. + */ + public String getSourceActionType() + { + return sourceActionType; + } + + /** + * Returns the event type, to which the given action belongs. + * + * @return the event type, to which the given action belongs + */ + public String getSourceEventType() + { + return sourceEventType; + } + + /** + * Returns the NotificationActionHandler that handles the action, + * for which this event is about. + * + * @return the NotificationActionHandler that handles the action, + * for which this event is about. + */ + public NotificationActionHandler getActionHandler() + { + return actionHandler; + } + + /** + * The type of this event. One of ACTION_XXX constants declared in this + * class. + * + * @return the type of this event + */ + public String getEventType() + { + return eventType; + } +} diff --git a/src/net/java/sip/communicator/service/notification/event/NotificationEventTypeEvent.java b/src/net/java/sip/communicator/service/notification/event/NotificationEventTypeEvent.java new file mode 100644 index 000000000..2183c8d20 --- /dev/null +++ b/src/net/java/sip/communicator/service/notification/event/NotificationEventTypeEvent.java @@ -0,0 +1,80 @@ +/* + * 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.notification.event; + +import java.util.*; +import net.java.sip.communicator.service.notification.*; + +/** + * Fired any time an event type is added or removed. + * + * @author Emil Ivov + * @author Yana Stamcheva + */ +public class NotificationEventTypeEvent + extends EventObject +{ + /** + * Indicates that a new event type is added. + */ + public static final String EVENT_TYPE_ADDED = "EventTypeAdded"; + + /** + * Indicates that an event type was removed. + */ + public static final String EVENT_TYPE_REMOVED = "EventTypeRemoved"; + + /** + * The type of the event that a new action is being added for. + */ + private String sourceEventType = null; + + /** + * The type of this event. One of the static field constants declared in + * this class. + */ + private String eventType = null; + + /** + * Creates an instance of this event according to the specified type. + * + * @param source the NotificationService that dispatched this event + * @param eventType the type of this event. One of the static fields + * declared in this class + * @param sourceEventType the event type for which this event occured + */ + public NotificationEventTypeEvent( NotificationService source, + String eventType, + String sourceEventType) + { + super(source); + + this.eventType = eventType; + this.sourceEventType = sourceEventType; + } + + /** + * Returns the eventType, for which this event is about. + * + * @return the eventType, for which this event is about. + */ + public String getSourceEventType() + { + return sourceEventType; + } + + /** + * The type of this event. One of EVENT_TYPE_XXX constants declared in this + * class. + * + * @return the type of this event + */ + public String getEventType() + { + return eventType; + } +}