Author: allain.lalonde
Date: Sat Jul 18 16:58:33 2009
New Revision: 515

Modified:
     
piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java
     
piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/event/PNotificationCenterTest.java

Log:
removed printStackTrace call by making addListner return false if it was  
not able to add the listener

Modified:  
piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java
==============================================================================
---  
piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java
     
(original)
+++  
piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java
     
Sat Jul 18 16:58:33 2009
@@ -93,8 +93,12 @@
       * null then the listener will receive all notifications with an object
       * matching 'object'. If 'object' is null the listener will receive all
       * notifications with the name 'notificationName'.
+     *
+     * @return whether or not the listener has been added
+     * @throws SecurityException
       */
-    public void addListener(Object listener, String callbackMethodName,  
String notificationName, Object object) {
+    public boolean addListener(Object listener, String callbackMethodName,  
String notificationName, Object object)
+            throws SecurityException {
          processKeyQueue();

          Object name = notificationName;
@@ -104,14 +108,16 @@
              method = listener.getClass().getMethod(callbackMethodName, new  
Class[] { PNotification.class });
          }
          catch (NoSuchMethodException e) {
-            e.printStackTrace();
-            return;
+            return false;
          }

-        if (name == null)
+        if (name == null) {
              name = NULL_MARKER;
-        if (object == null)
+        }
+
+        if (object == null) {
              object = NULL_MARKER;
+        }

          Object key = new CompoundKey(name, object);
          Object value = new CompoundValue(listener, method);
@@ -125,6 +131,8 @@
          if (!list.contains(value)) {
              list.add(value);
          }
+
+        return true;
      }

      // ****************************************************************

Modified:  
piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/event/PNotificationCenterTest.java
==============================================================================
---  
piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/event/PNotificationCenterTest.java
         
(original)
+++  
piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/event/PNotificationCenterTest.java
         
Sat Jul 18 16:58:33 2009
@@ -41,7 +41,7 @@
          super(name);
      }

-    public void testToString() {
+    public void testToString() throws SecurityException,  
NoSuchMethodException {
          PNotificationCenter center = PNotificationCenter.defaultCenter();

          center.addListener(this, "changed1", "propertyChanged", this);

--~--~---------~--~----~------------~-------~--~----~
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to