Revision: 586
Author: allain.lalonde
Date: Mon Jul 27 13:14:54 2009
Log: Killing some FindBugs involving serialization.
http://code.google.com/p/piccolo2d/source/detail?r=586

Modified:
  /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCamera.java
  /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java
  /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PLayer.java
  /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PNode.java
  /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PRoot.java
   
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/nodes/PImage.java
   
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/nodes/PPath.java
   
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/nodes/PText.java
   
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/util/PAffineTransform.java
   
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/util/PAffineTransformException.java
   
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/util/PBounds.java
   
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/util/PDimension.java
   
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/util/PStack.java
   
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/MockPInputEventListener.java
   
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PCameraTest.java
  /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PLayerTest.java
  /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java
  /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PRootTest.java

=======================================
---  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCamera.java        
 
Mon Jul 27 11:23:33 2009
+++  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCamera.java        
 
Mon Jul 27 13:14:54 2009
@@ -68,6 +68,12 @@
   */
  public class PCamera extends PNode {

+    /**
+     * Allows for future serialization code to understand versioned binary
+     * formats.
+     */
+    private static final long serialVersionUID = 1L;
+
      /**
       * The property name that identifies a change in the set of this  
camera's
       * layers (see {...@link #getLayer getLayer}, {...@link #getLayerCount
@@ -158,16 +164,17 @@
              repaintFrom(TEMP_REPAINT_RECT, repaintedLayer);
          }
      }
-
+
      /**
       * @deprecated since a more specific repaintFromLayer method is  
available
       *
-     * Repaint from one of the cameras layers. The repaint region needs to  
be
-     * transformed from view to local in this case. Unlike most repaint  
methods
-     * in piccolo this one must not modify the viewBounds parameter.
+     *             Repaint from one of the cameras layers. The repaint  
region
+     *             needs to be transformed from view to local in this case.
+     *             Unlike most repaint methods in piccolo this one must not
+     *             modify the viewBounds parameter.
       */
-    public void repaintFromLayer(PBounds viewBounds, PNode repaintedLayer)  
{
-        this.repaintFromLayer(viewBounds, (PLayer)repaintedLayer);
+    public void repaintFromLayer(PBounds viewBounds, PNode repaintedLayer)  
{
+        this.repaintFromLayer(viewBounds, (PLayer) repaintedLayer);
      }

      // ****************************************************************
@@ -640,6 +647,9 @@
                  layerBounds.setRect(layerBounds.getCenterX(),  
layerBounds.getCenterY(), 0, 0);
                  constraintDelta =  
viewBounds.deltaRequiredToContain(layerBounds);
                  break;
+            default:
+
+                throw new RuntimeException("Invalid View Constraint");
          }

          viewTransform.translate(-constraintDelta.width,  
-constraintDelta.height);
@@ -685,8 +695,8 @@
       * camera's view coordinate system. The given point is modified by this
       * method.
       */
-    public Point2D localToView(Point2D localPoint) {
-        return viewTransform.inverseTransform(localPoint, localPoint);
+    public Point2D localToView(Point2D localPoint) {
+        return viewTransform.inverseTransform(localPoint, localPoint);
      }

      /**
@@ -694,8 +704,8 @@
       * camera's view coordinate system. The given dimension is modified by  
this
       * method.
       */
-    public Dimension2D localToView(Dimension2D localDimension) {
-        return viewTransform.inverseTransform(localDimension,  
localDimension);
+    public Dimension2D localToView(Dimension2D localDimension) {
+        return viewTransform.inverseTransform(localDimension,  
localDimension);
      }

      /**
=======================================
---  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java        
 
Fri Jul 24 07:37:07 2009
+++  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java        
 
Mon Jul 27 13:14:54 2009
@@ -70,7 +70,12 @@
   * @author Jesse Grosjean
   */
  public class PCanvas extends JComponent implements PComponent {
-
+    /**
+     * Allows for future serialization code to understand versioned binary
+     * formats.
+     */
+    private static final long serialVersionUID = 1L;
+
      /**
       * @deprecated this is a typo and clients should change their code to
       *             reflect the correct spelling
@@ -90,10 +95,10 @@
      private PZoomEventHandler zoomEventHandler;
      private boolean paintingImmediately;
      private boolean animatingOnLastPaint;
-    private MouseListener mouseListener;
-    private KeyEventPostProcessor keyEventPostProcessor;
-    private MouseWheelListener mouseWheelListener;
-    private MouseMotionListener mouseMotionListener;
+    private transient MouseListener mouseListener;
+    private transient KeyEventPostProcessor keyEventPostProcessor;
+    private transient MouseWheelListener mouseWheelListener;
+    private transient MouseMotionListener mouseMotionListener;

      /**
       * Construct a canvas with the basic scene graph consisting of a root,
=======================================
--- /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PLayer.java     
 
Fri Jul 17 07:05:15 2009
+++ /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PLayer.java     
 
Mon Jul 27 13:14:54 2009
@@ -54,7 +54,12 @@
   * @author Jesse Grosjean
   */
  public class PLayer extends PNode {
-
+    /**
+     * Allows for future serialization code to understand versioned binary
+     * formats.
+     */
+    private static final long serialVersionUID = 1L;
+
      /**
       * The property name that identifies a change in the set of this  
layer's
       * cameras (see {...@link #getCamera getCamera}, {...@link #getCameraCount
=======================================
--- /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PNode.java      
 
Sat Jul 25 06:39:02 2009
+++ /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PNode.java      
 
Mon Jul 27 13:14:54 2009
@@ -98,6 +98,11 @@
   * @author Jesse Grosjean
   */
  public class PNode implements Cloneable, Serializable, Printable {
+    /**
+     * Allows for future serialization code to understand versioned binary
+     * formats.
+     */
+    private static final long serialVersionUID = 1L;

      /**
       * The property name that identifies a change in this node's client
@@ -536,7 +541,7 @@
              };

              PColorActivity ca = new PColorActivity(duration,  
PUtil.DEFAULT_ACTIVITY_STEP_RATE, t, destColor);
-            addActivity(ca);
+            addActivity(ca);
              return ca;
          }
      }
@@ -761,7 +766,7 @@
          }
          catch (ClassNotFoundException e) {
              return null;
-        }
+        }
      }

      // ****************************************************************
@@ -856,8 +861,8 @@
      public Point2D parentToLocal(Point2D parentPoint) {
          if (transform == null)
              return parentPoint;
-
-        return transform.inverseTransform(parentPoint, parentPoint);
+
+        return transform.inverseTransform(parentPoint, parentPoint);
      }

      /**
@@ -1022,14 +1027,15 @@
       * @return The inverse of the concatenation of transforms from the  
root down
       *         to this node.
       */
-    public PAffineTransform getGlobalToLocalTransform(PAffineTransform  
dest) {
+    public PAffineTransform getGlobalToLocalTransform(PAffineTransform  
dest) {
          dest = getLocalToGlobalTransform(dest);
          try {
              dest.setTransform(dest.createInverse());
-        } catch (NoninvertibleTransformException e) {
+        }
+        catch (NoninvertibleTransformException e) {
              throw new PAffineTransformException(e, dest);
          }
-        return dest;
+        return dest;
      }

      // ****************************************************************
@@ -1245,8 +1251,9 @@

      /**
       * Notify this node that you will begin to repeatedly call  
<code>setBounds
-     * </code>. When you are done call <code>endResizeBounds</code> to let  
the
-     * node know that you are done.
+     * </code>. When you
+     * are done call <code>endResizeBounds</code> to let the node know  
that you
+     * are done.
       */
      public void startResizeBounds() {
      }
@@ -2130,8 +2137,9 @@
          Point2D pt1, pt2;

          if (parent == null) {
-               return null;
-        } else {
+            return null;
+        }
+        else {
              // First compute translation amount in global coordinates
              Rectangle2D srcBounds = getGlobalFullBounds();
              srcx = lerp(srcPt.getX(), srcBounds.getX(), srcBounds.getX() +  
srcBounds.getWidth());
@@ -2153,32 +2161,34 @@
              return animateToTransform(at, millis);
          }
      }
-
+
      /**
       * @deprecated in favor of animateToRelativePosition
       *
-     * It will calculate the necessary transform in order to make this node
-     * appear at a particular position relative to the specified bounding  
box.
-     * The source point specifies a point in the unit square (0, 0) - (1,  
1)
-     * that represents an anchor point on the corresponding node to this
-     * transform. The destination point specifies an anchor point on the
-     * reference node. The position method then computes the transform that
-     * results in transforming this node so that the source anchor point
-     * coincides with the reference anchor point. This can be useful for  
layout
-     * algorithms as it is straightforward to position one object relative  
to
-     * another.
-     * <p>
-     * For example, If you have two nodes, A and B, and you call
+     *             It will calculate the necessary transform in order to  
make
+     *             this node appear at a particular position relative to  
the
+     *             specified bounding box. The source point specifies a  
point in
+     *             the unit square (0, 0) - (1, 1) that represents an  
anchor
+     *             point on the corresponding node to this transform. The
+     *             destination point specifies an anchor point on the  
reference
+     *             node. The position method then computes the transform  
that
+     *             results in transforming this node so that the source  
anchor
+     *             point coincides with the reference anchor point. This  
can be
+     *             useful for layout algorithms as it is straightforward to
+     *             position one object relative to another.
+     *             <p>
+     *             For example, If you have two nodes, A and B, and you  
call
       *
-     * <PRE>
+     *             <PRE>
       * Point2D srcPt = new Point2D.Double(1.0, 0.0);
       * Point2D destPt = new Point2D.Double(0.0, 0.0);
       * A.position(srcPt, destPt, B.getGlobalBounds(), 750, null);
       * </PRE>
       *
-     * The result is that A will move so that its upper-right corner is at  
the
-     * same place as the upper-left corner of B, and the transition will be
-     * smoothly animated over a period of 750 milliseconds.
+     *             The result is that A will move so that its upper-right  
corner
+     *             is at the same place as the upper-left corner of B, and  
the
+     *             transition will be smoothly animated over a period of  
750
+     *             milliseconds.
       *
       * @param srcPt The anchor point on this transform's node (normalized  
to a
       *            unit square)
@@ -2233,10 +2243,11 @@
          if (transform == null) {
              return new PAffineTransform();
          }
-
+
          try {
              return new PAffineTransform(transform.createInverse());
-        } catch (NoninvertibleTransformException e) {
+        }
+        catch (NoninvertibleTransformException e) {
              throw new PAffineTransformException(e, transform);
          }
      }
@@ -2568,16 +2579,16 @@
       * @param height pixel height of the resulting image
       * @return a new image representing this node and its descendents
       */
-    public Image toImage(int width, int height, Paint backGroundPaint) {
+    public Image toImage(int width, int height, Paint backGroundPaint) {
          BufferedImage result;
-
+
          if (GraphicsEnvironment.isHeadless()) {
              result = new BufferedImage(width, height,  
BufferedImage.TYPE_INT_ARGB);
-        }
+        }
          else {
              GraphicsConfiguration graphicsConfiguration =  
GraphicsEnvironment.getLocalGraphicsEnvironment()
-            .getDefaultScreenDevice().getDefaultConfiguration();
-            result =  graphicsConfiguration.createCompatibleImage(width,  
height, Transparency.TRANSLUCENT);
+                    .getDefaultScreenDevice().getDefaultConfiguration();
+            result = graphicsConfiguration.createCompatibleImage(width,  
height, Transparency.TRANSLUCENT);
          }

          return toImage(result, backGroundPaint);
@@ -2777,7 +2788,7 @@
              boolean thisPickable = getPickable() &&  
pickPath.acceptsNode(this);

              if (thisPickable && pick(pickPath)) {
-                return true;
+                return true;
              }

              if (getChildrenPickable()) {
@@ -2790,7 +2801,7 @@
              }

              if (thisPickable && pickAfterChildren(pickPath)) {
-                return true;
+                return true;
              }

              pickPath.popTransform(transform);
@@ -3267,15 +3278,15 @@
      protected final String paramString() {
          return "this Method (paramString) is deprecated and will go away  
in the next release.";
      }
-
+
      public PInputEventListener[] getInputEventListeners() {
          if (listenerList == null || listenerList.getListenerCount() == 0)
              return new PInputEventListener[] {};
-
+
          EventListener[] listeners =  
listenerList.getListeners(PInputEventListener.class);
-
+
          PInputEventListener[] result = new  
PInputEventListener[listeners.length];
-        for (int i=0; i<listeners.length; i++) {
+        for (int i = 0; i < listeners.length; i++) {
              result[i] = (PInputEventListener) listeners[i];
          }
          return result;
=======================================
--- /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PRoot.java      
 
Thu Jul 23 18:04:01 2009
+++ /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PRoot.java      
 
Mon Jul 27 13:14:54 2009
@@ -52,6 +52,12 @@
   */
  public class PRoot extends PNode {

+    /**
+     * Allows for future serialization code to understand versioned binary
+     * formats.
+     */
+    private static final long serialVersionUID = 1L;
+
      /**
       * The property name that identifies a change in the set of this root's
       * input sources (see {...@link InputSource InputSource}). In any property
=======================================
---  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/nodes/PImage.java   
 
Sat Jul 25 06:39:02 2009
+++  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/nodes/PImage.java   
 
Mon Jul 27 13:14:54 2009
@@ -57,6 +57,12 @@
   */
  public class PImage extends PNode {

+    /**
+     * Allows for future serialization code to understand versioned binary
+     * formats.
+     */
+    private static final long serialVersionUID = 1L;
+
      /**
       * The property name that identifies a change of this node's image (see
       * {...@link #getImage getImage}). Both old and new value will be set  
correctly
=======================================
---  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/nodes/PPath.java    
 
Sat Jul 25 06:39:02 2009
+++  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/nodes/PPath.java    
 
Mon Jul 27 13:14:54 2009
@@ -70,6 +70,12 @@
   */
  public class PPath extends PNode {

+    /**
+     * Allows for future serialization code to understand versioned binary
+     * formats.
+     */
+    private static final long serialVersionUID = 1L;
+
      /**
       * The property name that identifies a change of this node's stroke  
paint
       * (see {...@link #getStrokePaint getStrokePaint}). Both old and new  
value will
=======================================
---  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/nodes/PText.java    
 
Sat Jul 25 06:39:02 2009
+++  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/nodes/PText.java    
 
Mon Jul 27 13:14:54 2009
@@ -52,6 +52,12 @@
   */
  public class PText extends PNode {

+    /**
+     * Allows for future serialization code to understand versioned binary
+     * formats.
+     */
+    private static final long serialVersionUID = 1L;
+
        /**
         * The property name that identifies a change of this node's text (see
         * {...@link #getText getText}). Both old and new value will be set in 
any
=======================================
---  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/util/PAffineTransform.java
   
Sat Jul 18 17:58:21 2009
+++  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/util/PAffineTransform.java
   
Mon Jul 27 13:14:54 2009
@@ -43,7 +43,12 @@
   * @author Jesse Grosjean
   */
  public class PAffineTransform extends AffineTransform {
-
+    /**
+     * Allows for future serialization code to understand versioned binary
+     * formats.
+     */
+    private static final long serialVersionUID = 1L;
+
      private static double[] PTS1 = new double[8];
      private static double[] PTS2 = new double[8];

=======================================
---  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/util/PAffineTransformException.java
  
Fri Jul 17 08:58:34 2009
+++  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/util/PAffineTransformException.java
  
Mon Jul 27 13:14:54 2009
@@ -1,7 +1,12 @@
  package edu.umd.cs.piccolo.util;

  public class PAffineTransformException extends RuntimeException {
-
+    /**
+     * Allows for future serialization code to understand versioned binary
+     * formats.
+     */
+    private static final long serialVersionUID = 1L;
+
      private final PAffineTransform errantTransform;

      public PAffineTransformException(PAffineTransform errantTransform) {
=======================================
---  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/util/PBounds.java   
 
Fri Jul 17 07:05:15 2009
+++  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/util/PBounds.java   
 
Mon Jul 27 13:14:54 2009
@@ -51,7 +51,12 @@
   * @author Jesse Grosjean
   */
  public class PBounds extends Rectangle2D.Double implements Serializable {
-
+    /**
+     * Allows for future serialization code to understand versioned binary
+     * formats.
+     */
+    private static final long serialVersionUID = 1L;
+
      private boolean isEmpty = true;

      public PBounds() {
=======================================
---  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/util/PDimension.java
         
Fri Jul 17 07:05:15 2009
+++  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/util/PDimension.java
         
Mon Jul 27 13:14:54 2009
@@ -41,7 +41,12 @@
   * @author Jesse Grosjean
   */
  public class PDimension extends Dimension2D implements Serializable {
-
+    /**
+     * Allows for future serialization code to understand versioned binary
+     * formats.
+     */
+    private static final long serialVersionUID = 1L;
+
      public double width;
      public double height;

=======================================
---  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/util/PStack.java    
 
Fri Jan 23 12:25:52 2009
+++  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/util/PStack.java    
 
Mon Jul 27 13:14:54 2009
@@ -39,7 +39,12 @@
   * @author Jesse Grosjean
   */
  public class PStack extends ArrayList {
-
+    /**
+     * Allows for future serialization code to understand versioned binary
+     * formats.
+     */
+    private static final long serialVersionUID = 1L;
+
      public PStack() {
      }

=======================================
---  
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/MockPInputEventListener.java
         
Mon Jul 13 09:01:00 2009
+++  
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/MockPInputEventListener.java
         
Mon Jul 27 13:14:54 2009
@@ -7,7 +7,7 @@
  import edu.umd.cs.piccolo.event.PInputEventListener;

  public class MockPInputEventListener implements PInputEventListener {
-       class Notification {
+       static class Notification {
                public PInputEvent event;
                public int type;

=======================================
---  
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PCameraTest.java    
 
Tue Jul 21 07:46:08 2009
+++  
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PCameraTest.java    
 
Mon Jul 27 13:14:54 2009
@@ -348,7 +348,7 @@
          assertEquals(PCamera.VIEW_CONSTRAINT_ALL,  
camera.getViewConstraint());
      }

-    class MockPComponent implements PComponent {
+    static class MockPComponent implements PComponent {

          public void paintImmediately() {
          }
=======================================
---  
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PLayerTest.java     
 
Tue Jul 21 07:46:08 2009
+++  
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PLayerTest.java     
 
Mon Jul 27 13:14:54 2009
@@ -8,118 +8,121 @@
  import edu.umd.cs.piccolo.util.PBounds;

  public class PLayerTest extends TestCase {
-       private PLayer layer;
-
-       public void setUp() {
-               layer = new PLayer();
-       }
-
-       public void testLayerHasEmptyCamerasCollectionByDefault() {
-               Collection cameras = layer.getCamerasReference();
-               assertNotNull(cameras);
-               assertTrue(cameras.isEmpty());
-               assertEquals(0, layer.getCameraCount());
-       }
-
-       public void  
testGetCameraByIndexThrowsIndexOutOfBoundsExceptionWhenOutOfBounds() {
-               PCamera camera = new PCamera();
-               layer.addCamera(camera);
-               try {
-                       layer.getCamera(-1);
-                       fail("Exception should have been thrown");
-               } catch (IndexOutOfBoundsException e) {
-                       // expected;
-               }
-
-               try {
-                       layer.getCamera(1);
-                       fail("Exception should have been thrown");
-               } catch (IndexOutOfBoundsException e) {
-                       // expected;
-               }
-       }
-
-       public void testGetCameraReturnsCameraAtCorrectIndex() {
-               PCamera camera1 = new PCamera();
-               PCamera camera2 = new PCamera();
-               PCamera camera3 = new PCamera();
-
-               layer.addCamera(camera1);
-               layer.addCamera(camera2);
-               layer.addCamera(camera3);
-
-               assertEquals(camera1, layer.getCamera(0));
-               assertEquals(camera2, layer.getCamera(1));
-               assertEquals(camera3, layer.getCamera(2));
-       }
-
-       public void testAddCameraCorrectlyHandlesIndex() {
-               PCamera camera1 = new PCamera();
-               PCamera camera2 = new PCamera();
-               PCamera camera3 = new PCamera();
-
-               layer.addCamera(0, camera1);
-               layer.addCamera(0, camera2);
-               layer.addCamera(1, camera3);
-
-               assertEquals(camera2, layer.getCamera(0));
-               assertEquals(camera3, layer.getCamera(1));
-               assertEquals(camera1, layer.getCamera(2));
-       }
-
-       public void testRemovingCameraByReferenceWorksWhenCameraIsFound() {
-               PCamera camera = new PCamera();
-               layer.addCamera(camera);
-               layer.removeCamera(camera);
-               assertEquals(0, layer.getCameraCount());
-       }
-
-       public void testRemovingCameraByIndexWorksWhenIndexIsValid() {
-               PCamera camera = new PCamera();
-               layer.addCamera(camera);
-               layer.removeCamera(0);
-               assertEquals(0, layer.getCameraCount());
-       }
-
-       public void testRemovingCameraNotAttachedToCameraShouldDoNothing() {
-               PCamera strangerCamera = new PCamera();
-               layer.removeCamera(strangerCamera);
-               assertEquals(0, layer.getCameraCount());
-       }
-
-       public void testRepaintFromNotifiesCameras() {
-               MockPCamera camera = new MockPCamera();
-               layer.addCamera(camera);
-
-               PBounds bounds = new PBounds(0, 0, 100, 100);
-               layer.repaintFrom(bounds, layer);
-
-               assertEquals(1, camera.notifications.size());
-
-               MockPCamera.Notification notification =  
(MockPCamera.Notification)camera.notifications.get(0);
-               assertEquals(layer, notification.layer);
-               assertEquals(bounds, notification.bounds);
-       }
-
-       class MockPCamera extends PCamera {
-               class Notification {
-                   String type;
-                       PBounds bounds;
-                       //this should really be PLayer
-                       PNode layer;
-
-                       Notification(String type, PBounds bounds, PNode layer) {
-                               this.bounds = bounds;
-                               this.layer = layer;
-                               this.type = type;
-                       }
-               }
-
-               List notifications = new ArrayList();
-
-               public void repaintFromLayer(PBounds bounds, PLayer layer) {
-                       notifications.add(new Notification("repaintFromLayer", 
bounds, layer));
-                       super.repaintFromLayer(bounds, layer);
-               }
-       }
-}
+    private PLayer layer;
+
+    public void setUp() {
+        layer = new PLayer();
+    }
+
+    public void testLayerHasEmptyCamerasCollectionByDefault() {
+        Collection cameras = layer.getCamerasReference();
+        assertNotNull(cameras);
+        assertTrue(cameras.isEmpty());
+        assertEquals(0, layer.getCameraCount());
+    }
+
+    public void  
testGetCameraByIndexThrowsIndexOutOfBoundsExceptionWhenOutOfBounds() {
+        PCamera camera = new PCamera();
+        layer.addCamera(camera);
+        try {
+            layer.getCamera(-1);
+            fail("Exception should have been thrown");
+        }
+        catch (IndexOutOfBoundsException e) {
+            // expected;
+        }
+
+        try {
+            layer.getCamera(1);
+            fail("Exception should have been thrown");
+        }
+        catch (IndexOutOfBoundsException e) {
+            // expected;
+        }
+    }
+
+    public void testGetCameraReturnsCameraAtCorrectIndex() {
+        PCamera camera1 = new PCamera();
+        PCamera camera2 = new PCamera();
+        PCamera camera3 = new PCamera();
+
+        layer.addCamera(camera1);
+        layer.addCamera(camera2);
+        layer.addCamera(camera3);
+
+        assertEquals(camera1, layer.getCamera(0));
+        assertEquals(camera2, layer.getCamera(1));
+        assertEquals(camera3, layer.getCamera(2));
+    }
+
+    public void testAddCameraCorrectlyHandlesIndex() {
+        PCamera camera1 = new PCamera();
+        PCamera camera2 = new PCamera();
+        PCamera camera3 = new PCamera();
+
+        layer.addCamera(0, camera1);
+        layer.addCamera(0, camera2);
+        layer.addCamera(1, camera3);
+
+        assertEquals(camera2, layer.getCamera(0));
+        assertEquals(camera3, layer.getCamera(1));
+        assertEquals(camera1, layer.getCamera(2));
+    }
+
+    public void testRemovingCameraByReferenceWorksWhenCameraIsFound() {
+        PCamera camera = new PCamera();
+        layer.addCamera(camera);
+        layer.removeCamera(camera);
+        assertEquals(0, layer.getCameraCount());
+    }
+
+    public void testRemovingCameraByIndexWorksWhenIndexIsValid() {
+        PCamera camera = new PCamera();
+        layer.addCamera(camera);
+        layer.removeCamera(0);
+        assertEquals(0, layer.getCameraCount());
+    }
+
+    public void testRemovingCameraNotAttachedToCameraShouldDoNothing() {
+        PCamera strangerCamera = new PCamera();
+        layer.removeCamera(strangerCamera);
+        assertEquals(0, layer.getCameraCount());
+    }
+
+    public void testRepaintFromNotifiesCameras() {
+        MockPCamera camera = new MockPCamera();
+        layer.addCamera(camera);
+
+        PBounds bounds = new PBounds(0, 0, 100, 100);
+        layer.repaintFrom(bounds, layer);
+
+        assertEquals(1, camera.notifications.size());
+
+        MockPCamera.Notification notification = (MockPCamera.Notification)  
camera.notifications.get(0);
+        assertEquals(layer, notification.layer);
+        assertEquals(bounds, notification.bounds);
+    }
+
+    static class MockPCamera extends PCamera {
+        List notifications = new ArrayList();
+
+        public void repaintFromLayer(PBounds bounds, PLayer layer) {
+            notifications.add(new Notification("repaintFromLayer", bounds,  
layer));
+            super.repaintFromLayer(bounds, layer);
+        }
+
+        class Notification {
+            String type;
+            PBounds bounds;
+            // this should really be PLayer
+            PNode layer;
+
+            Notification(String type, PBounds bounds, PNode layer) {
+                this.bounds = bounds;
+                this.layer = layer;
+                this.type = type;
+            }
+        }
+
+    }
+}
=======================================
---  
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java      
 
Sat Jul 25 17:43:19 2009
+++  
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java      
 
Mon Jul 27 13:14:54 2009
@@ -42,7 +42,6 @@
  import java.util.Enumeration;
  import java.util.Iterator;
  import java.util.ListIterator;
-import java.util.regex.Pattern;

  import javax.swing.text.MutableAttributeSet;

=======================================
---  
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PRootTest.java      
 
Tue Jul 14 11:58:27 2009
+++  
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PRootTest.java      
 
Mon Jul 27 13:14:54 2009
@@ -114,7 +114,7 @@
          assertTrue(activity.isActivityFished());
      }

-    private final class MockInputSource implements PRoot.InputSource {
+    private static final class MockInputSource implements  
PRoot.InputSource {
          private int processInputCalls;

          public int getProcessInputCalls() {
@@ -126,7 +126,7 @@
          }
      }

-    private final class MockPActivity extends PActivity {
+    private static final class MockPActivity extends PActivity {
          private boolean activityStarted;
          private boolean activityFinished;


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

Reply via email to