Revision: 797
Author: allain.lalonde
Date: Thu Oct 22 19:28:10 2009
Log: Fixing some FindBugs. Everything still seems to pass tests fine, so  
I'm checking in.
http://code.google.com/p/piccolo2d/source/detail?r=797

Modified:
  /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCanvas.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/activities/PActivityScheduler.java
   
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PNavigationEventHandler.java
   
/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/PStyledTextEventHandler.java
   
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/nodes/PStyledText.java
   
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java
   
/piccolo2d.java/trunk/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTTimerQueue.java

=======================================
---  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java        
 
Mon Oct 19 13:38:38 2009
+++  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java        
 
Thu Oct 22 19:28:10 2009
@@ -688,12 +688,16 @@
      /**
       * Prints the entire scene regardless of what the viewable area is.
       *
-     * @param g Graphics context onto which to paint the scene for printing
+     * @param graphics Graphics context onto which to paint the scene for  
printing
       */
-    public void printAll(final Graphics g) {
-        final Graphics2D g2 = (Graphics2D) g;
-
-        final PBounds clippingRect = new PBounds(g.getClipBounds());
+    public void printAll(final Graphics graphics) {
+        if (!(graphics instanceof Graphics2D)) {
+            throw new IllegalArgumentException("Provided graphics context  
is not a Graphics2D object");
+        }
+
+        final Graphics2D g2 = (Graphics2D) graphics;
+
+        final PBounds clippingRect = new PBounds(graphics.getClipBounds());
          clippingRect.expandNearestIntegerDimensions();

          final PBounds originalCameraBounds = getCamera().getBounds();
=======================================
--- /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PNode.java      
 
Wed Oct 21 14:05:18 2009
+++ /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PNode.java      
 
Thu Oct 22 19:28:10 2009
@@ -2940,7 +2940,7 @@
                  }
                  else {
                      scale = image.getHeight() / nodeHeight;
-                }
+                }
                  g2.scale(scale, scale);
                  break;
              case FILL_STRATEGY_EXACT_FIT:
@@ -2997,6 +2997,11 @@
          if (pageIndex != 0) {
              return NO_SUCH_PAGE;
          }
+
+        if (!(graphics instanceof Graphics2D)) {
+            throw new IllegalArgumentException("Provided graphics context  
is not a Graphics2D object");
+        }
+

          final Graphics2D g2 = (Graphics2D) graphics;
          final PBounds imageBounds = getFullBounds();
=======================================
---  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/activities/PActivityScheduler.java
   
Mon Oct 12 18:58:11 2009
+++  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/activities/PActivityScheduler.java
   
Thu Oct 22 19:28:10 2009
@@ -55,9 +55,9 @@
   */
  public class PActivityScheduler implements Serializable {
      private static final long serialVersionUID = 1L;
+    private transient Timer activityTimer = null;
      private final PRoot root;
-    private final List activities;
-    private transient Timer activityTimer;
+    private final List activities;
      private boolean activitiesChanged;
      private boolean animating;
      private final ArrayList processingActivities;
=======================================
---  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PNavigationEventHandler.java
        
Tue Oct 13 20:14:37 2009
+++  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PNavigationEventHandler.java
        
Thu Oct 22 19:28:10 2009
@@ -468,8 +468,7 @@
       * @param camera the camera to be transformed
       */
      protected void fillViewWhiteSpace(final PCamera camera) {
-        final PBounds rootBounds =  
camera.getRoot().getFullBoundsReference();
-        PBounds viewBounds = camera.getViewBounds();
+        final PBounds rootBounds =  
camera.getRoot().getFullBoundsReference();

          if (rootBounds.contains(camera.getViewBounds())) {
              return;
@@ -481,7 +480,8 @@
          // center content.
          double dx = 0;
          double dy = 0;
-        viewBounds = camera.getViewBounds();
+
+        PBounds viewBounds = camera.getViewBounds();

          if (viewBounds.getWidth() > rootBounds.getWidth()) {
              // then center along x axis.
=======================================
---  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java
    
Tue Oct 13 20:14:37 2009
+++  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java
    
Thu Oct 22 19:28:10 2009
@@ -66,7 +66,7 @@
      public static final Object NULL_MARKER = new Object();

      /** Singleton instance of the notification center. */
-    protected static PNotificationCenter DEFAULT_CENTER;
+    protected volatile static PNotificationCenter DEFAULT_CENTER;

      /** A map of listeners keyed by NotificationKey objects. */
      protected HashMap listenersMap;
=======================================
---  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PStyledTextEventHandler.java
        
Tue Oct 13 20:14:37 2009
+++  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PStyledTextEventHandler.java
        
Thu Oct 22 19:28:10 2009
@@ -360,15 +360,19 @@
           * inconsistent. Also, Swing doesn't work correctly with fractional
           * metrics.
           */
-        public void paint(final Graphics g) {
-            final Graphics2D g2 = (Graphics2D) g;
+        public void paint(final Graphics graphics) {
+            if (!(graphics instanceof Graphics2D)) {
+                throw new IllegalArgumentException("Provided graphics  
context is not a Graphics2D object");
+            }
+
+            final Graphics2D g2 = (Graphics2D) graphics;

              g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,  
RenderingHints.VALUE_ANTIALIAS_ON);
              g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,  
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
              g2.setRenderingHint(RenderingHints.KEY_RENDERING,  
RenderingHints.VALUE_RENDER_QUALITY);
              g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,  
RenderingHints.VALUE_FRACTIONALMETRICS_OFF);

-            super.paint(g);
+            super.paint(graphics);
          }
      }
  }
=======================================
---  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/nodes/PStyledText.java
    
Tue Oct 13 14:11:50 2009
+++  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/nodes/PStyledText.java
    
Thu Oct 22 19:28:10 2009
@@ -226,7 +226,6 @@
                          - paragraphRange.startIndex),  
Math.min(paragraphRange.length(), curElement.getEndOffset()
                          - paragraphRange.startIndex));

-                // These are the optional attributes
                  final Font font = extractFont(styleContext, pos,  
rootElement, attributes);
                  applyFontAttribute(paragraphRange, attributedString,  
curElement, font);
                  applyBackgroundAttribute(styleContext, paragraphRange,  
attributedString, curElement, attributes);
@@ -249,15 +248,10 @@
                              - paragraphRange.startIndex));

                      final Font font = extractFont(styleContext, pos,  
rootElement, attributes);
-                    applyFontAttribute(paragraphRange, attributedString,  
curElement, font);
-
-                    // These are the optional attributes
-
+                    applyFontAttribute(paragraphRange, attributedString,  
curElement, font);
                      applyBackgroundAttribute(styleContext, paragraphRange,  
attributedString, curElement, attributes);
-
                      applyUnderlineAttribute(paragraphRange,  
attributedString, curElement, attributes);
-
-                    applyStrikeThroughAttribute(paragraphRange,  
attributedString, curElement, attributes);
+                    applyStrikeThroughAttribute(paragraphRange,  
attributedString, curElement, attributes);

                      // And set the position to the end of the given  
attribute
                      pos = curElement.getEndOffset();
@@ -333,23 +327,14 @@

      private Font extractFont(final StyleContext style, final int pos,  
final Element rootElement,
              final AttributeSet attributes) {
-        Font font;
+        Font font = null;
          if (attributes.isDefined(StyleConstants.FontSize) ||  
attributes.isDefined(StyleConstants.FontFamily)) {
              font = style.getFont(attributes);
          }
-        else {
-            font = null;
-        }

          if (font == null) {
              if (document instanceof DefaultStyledDocument) {
-                font = style.getFont(((DefaultStyledDocument)  
document).getCharacterElement(pos).getAttributes());
-                if (font == null) {
-                    font = style.getFont(((DefaultStyledDocument)  
document).getParagraphElement(pos).getAttributes());
-                    if (font == null) {
-                        font = style.getFont(rootElement.getAttributes());
-                    }
-                }
+                font =  
extractFontFromDefaultStyledDocument((DefaultStyledDocument) document,  
style, pos, rootElement);
              }
              else {
                  font = style.getFont(rootElement.getAttributes());
@@ -357,6 +342,18 @@
          }
          return font;
      }
+
+    private Font extractFontFromDefaultStyledDocument(final  
DefaultStyledDocument styledDocument,
+            final StyleContext style, final int pos, final Element  
rootElement) {
+        Font font =  
style.getFont(styledDocument.getCharacterElement(pos).getAttributes());
+        if (font == null) {
+            font =  
style.getFont(styledDocument.getParagraphElement(pos).getAttributes());
+            if (font == null) {
+                font = style.getFont(rootElement.getAttributes());
+            }
+        }
+        return font;
+    }

      private ArrayList extractParagraphRanges(final String documentString) {
          // The paragraph start and end indices
@@ -502,7 +499,7 @@
              textWidth = Math.max(textWidth, lineWidth);
          }

-        lines = (LineInfo[]) linesList.toArray(new LineInfo[0]);
+        lines = (LineInfo[]) linesList.toArray(new  
LineInfo[linesList.size()]);

          constrainDimensionsIfNeeded(textWidth, textHeight);
      }
=======================================
---  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java
         
Tue Oct 13 20:14:37 2009
+++  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java
         
Thu Oct 22 19:28:10 2009
@@ -242,7 +242,7 @@
       * @param pce property change event to examine
       */
      public void propertyChange(final PropertyChangeEvent pce) {
-        final boolean isRelevantViewEvent =  
PCamera.PROPERTY_VIEW_TRANSFORM == pce.getPropertyName();
+        final boolean isRelevantViewEvent =  
PCamera.PROPERTY_VIEW_TRANSFORM.equals(pce.getPropertyName());
          final boolean isRelevantBoundsEvent = isBoundsChangedEvent(pce)
                  && (pce.getSource() == camera || pce.getSource() ==  
view.getRoot());

@@ -257,7 +257,7 @@
      }

      private boolean isBoundsChangedEvent(final PropertyChangeEvent pce) {
-        return PNode.PROPERTY_BOUNDS == pce.getPropertyName() ||  
PNode.PROPERTY_FULL_BOUNDS == pce.getPropertyName();
+        return PNode.PROPERTY_BOUNDS.equals(pce.getPropertyName()) ||  
PNode.PROPERTY_FULL_BOUNDS.equals(pce.getPropertyName());
      }

      /**
=======================================
---  
/piccolo2d.java/trunk/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTTimerQueue.java
       
Mon Oct 19 09:11:29 2009
+++  
/piccolo2d.java/trunk/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTTimerQueue.java
       
Thu Oct 22 19:28:10 2009
@@ -99,7 +99,7 @@
       */
      synchronized void stop() {
          running = false;
-        notify();
+        notifyAll();
      }

      /**
@@ -117,7 +117,7 @@
              timer.setExpirationTime(expirationTime);

              timer.setRunning(true);
-            notify();
+            notifyAll();
          }
      }


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

Reply via email to