Revision: 590
Author: allain.lalonde
Date: Mon Jul 27 15:02:47 2009
Log: Making findbugs a little happier.
http://code.google.com/p/piccolo2d/source/detail?r=590

Modified:
   
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PSelectionEventHandler.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/handles/PBoundsHandle.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/pswing/PSwingEventHandler.java
   
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java

=======================================
---  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PSelectionEventHandler.java
         
Fri Jan 23 12:29:37 2009
+++  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PSelectionEventHandler.java
         
Mon Jul 27 15:02:47 2009
@@ -629,10 +629,8 @@
              if (node instanceof PLayer) {
                  for (Iterator i = selectableParents.iterator();  
i.hasNext();) {
                      PNode parent = (PNode) i.next();
-                    if (parent instanceof PCamera) {
-                        if (((PCamera) parent).indexOfLayer((PLayer)  
node) != -1) {
-                            return true;
-                        }
+                    if (parent instanceof PCamera && ((PCamera)  
parent).indexOfLayer((PLayer) node) != -1) {
+                        return true;
                      }
                  }
              }
=======================================
---  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PStyledTextEventHandler.java
        
Mon Jul 20 19:57:42 2009
+++  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PStyledTextEventHandler.java
        
Mon Jul 27 15:02:47 2009
@@ -150,22 +150,23 @@
          PStyledText newText = new PStyledText();

          Document doc =  
editor.getUI().getEditorKit(editor).createDefaultDocument();
-        if (doc instanceof StyledDocument) {
-            if  
(!doc.getDefaultRootElement().getAttributes().isDefined(StyleConstants.FontFamily)
-                    | 
| 
!doc.getDefaultRootElement().getAttributes().isDefined(StyleConstants.FontSize))
  
{
-
-                Font eFont = editor.getFont();
-                SimpleAttributeSet sas = new SimpleAttributeSet();
-                sas.addAttribute(StyleConstants.FontFamily,  
eFont.getFamily());
-                sas.addAttribute(StyleConstants.FontSize, new  
Integer(eFont.getSize()));
-
-                ((StyledDocument) doc).setParagraphAttributes(0,  
doc.getLength(), sas, false);
-            }
+        if (doc instanceof StyledDocument && missingFontFamilyOrSize(doc))  
{
+            Font eFont = editor.getFont();
+            SimpleAttributeSet sas = new SimpleAttributeSet();
+            sas.addAttribute(StyleConstants.FontFamily, eFont.getFamily());
+            sas.addAttribute(StyleConstants.FontSize, new  
Integer(eFont.getSize()));
+
+            ((StyledDocument) doc).setParagraphAttributes(0,  
doc.getLength(), sas, false);
          }
          newText.setDocument(doc);

          return newText;
      }
+
+    private boolean missingFontFamilyOrSize(Document doc) {
+         
return 
!doc.getDefaultRootElement().getAttributes().isDefined(StyleConstants.FontFamily)
+                | 
| 
!doc.getDefaultRootElement().getAttributes().isDefined(StyleConstants.FontSize);
+    }

      public void mousePressed(PInputEvent inputEvent) {
          PNode pickedNode = inputEvent.getPickedNode();
=======================================
---  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/handles/PBoundsHandle.java
        
Fri Jan 23 12:29:37 2009
+++  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/handles/PBoundsHandle.java
        
Mon Jul 27 15:02:47 2009
@@ -110,8 +110,9 @@
              }

              public void mouseExited(PInputEvent aEvent) {
-                PPickPath focus = aEvent.getInputManager().getMouseFocus();
                  if (cursorPushed) {
+                    PPickPath focus =  
aEvent.getInputManager().getMouseFocus();
+
                      if (focus == null || focus.getPickedNode() !=  
PBoundsHandle.this) {
                          aEvent.popCursor();
                          cursorPushed = false;
=======================================
---  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/nodes/PStyledText.java
    
Sat Jul 18 17:44:30 2009
+++  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/nodes/PStyledText.java
    
Mon Jul 27 15:02:47 2009
@@ -342,6 +342,7 @@
                          font = style.getFont(rootElement.getAttributes());
                      }
                  }
+
                  if (font != null) {
                      ((AttributedString)  
stringContents.get(i)).addAttribute(TextAttribute.FONT, font, (int)  
Math.max(0,
                              curElement.getStartOffset() - pEnd.runStart),  
(int) Math.min(pEnd.runLimit - pEnd.runStart,
=======================================
---  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEventHandler.java
    
Sat Jul 25 06:29:38 2009
+++  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEventHandler.java
    
Mon Jul 27 15:02:47 2009
@@ -103,11 +103,9 @@
                  listenNode.removeInputEventListener(this);
              }
          }
-        else if (!this.active && active) {
-            if (listenNode != null) {
-                this.active = true;
-                listenNode.addInputEventListener(this);
-            }
+        else if (!this.active && active && listenNode != null) {
+            this.active = true;
+            listenNode.addInputEventListener(this);
          }
      }

=======================================
---  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java
         
Fri Jan 23 12:29:37 2009
+++  
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java
         
Mon Jul 27 15:02:47 2009
@@ -206,46 +206,44 @@
       * @param y The new y position
       */
      public void setViewPosition(double x, double y) {
-        if (camera != null) {
-            // If a scroll is in progress - we ignore new scrolls -
-            // if we didn't, since the scrollbars depend on the camera  
location
-            // we can end up with an infinite loop
-            if (!scrollInProgress) {
-                scrollInProgress = true;
-
-                // Get the union of all the layers' bounds
-                PBounds layerBounds = new PBounds();
-                List layers = camera.getLayersReference();
-                for (Iterator i = layers.iterator(); i.hasNext();) {
-                    PLayer layer = (PLayer) i.next();
-                    layerBounds.add(layer.getFullBoundsReference());
-                }
-
-                PAffineTransform at = camera.getViewTransform();
-                at.transform(layerBounds, layerBounds);
-
-                // Union the camera bounds
-                PBounds viewBounds = camera.getBoundsReference();
-                layerBounds.add(viewBounds);
-
-                // Now find the new view position in view coordinates
-                Point2D newPoint = new Point2D.Double(layerBounds.getX() +  
x, layerBounds.getY() + y);
-
-                // Now transform the new view position into global coords
-                camera.localToView(newPoint);
-
-                // Compute the new matrix values to put the camera at the
-                // correct location
-                double newX = -(at.getScaleX() * newPoint.getX() +  
at.getShearX() * newPoint.getY());
-                double newY = -(at.getShearY() * newPoint.getX() +  
at.getScaleY() * newPoint.getY());
-
-                at.setTransform(at.getScaleX(), at.getShearY(),  
at.getShearX(), at.getScaleY(), newX, newY);
-
-                // Now actually set the camera's transform
-                camera.setViewTransform(at);
-                scrollInProgress = false;
-            }
-        }
+        // Bail out if scrollInProgress because we can end up with an  
infinite
+        // loop since the scrollbars depend on the camera location
+        if (camera == null || scrollInProgress)
+            return;
+
+        scrollInProgress = true;
+
+        // Get the union of all the layers' bounds
+        PBounds layerBounds = new PBounds();
+        List layers = camera.getLayersReference();
+        for (Iterator i = layers.iterator(); i.hasNext();) {
+            PLayer layer = (PLayer) i.next();
+            layerBounds.add(layer.getFullBoundsReference());
+        }
+
+        PAffineTransform at = camera.getViewTransform();
+        at.transform(layerBounds, layerBounds);
+
+        // Union the camera bounds
+        PBounds viewBounds = camera.getBoundsReference();
+        layerBounds.add(viewBounds);
+
+        // Now find the new view position in view coordinates
+        Point2D newPoint = new Point2D.Double(layerBounds.getX() + x,  
layerBounds.getY() + y);
+
+        // Now transform the new view position into global coords
+        camera.localToView(newPoint);
+
+        // Compute the new matrix values to put the camera at the
+        // correct location
+        double newX = -(at.getScaleX() * newPoint.getX() + at.getShearX()  
* newPoint.getY());
+        double newY = -(at.getShearY() * newPoint.getX() + at.getScaleY()  
* newPoint.getY());
+
+        at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(),  
at.getScaleY(), newX, newY);
+
+        // Now actually set the camera's transform
+        camera.setViewTransform(at);
+        scrollInProgress = false;
      }

      /**
@@ -254,9 +252,9 @@
       */
      public void propertyChange(PropertyChangeEvent pce) {
          boolean isRelevantViewEvent = (PCamera.PROPERTY_VIEW_TRANSFORM ==  
pce.getPropertyName());
-        boolean isRelevantBoundsEvent = (PNode.PROPERTY_BOUNDS ==  
pce.getPropertyName() || PNode.PROPERTY_FULL_BOUNDS == pce
-                .getPropertyName())
+        boolean isRelevantBoundsEvent = isBoundsChangedEvent(pce)
                  && (pce.getSource() == camera || pce.getSource() ==  
view.getRoot());
+
          if (isRelevantViewEvent || isRelevantBoundsEvent) {
              if (shouldRevalidateScrollPane()) {
                  scrollPane.revalidate();
@@ -266,6 +264,10 @@
              }
          }
      }
+
+    private boolean isBoundsChangedEvent(PropertyChangeEvent pce) {
+        return (PNode.PROPERTY_BOUNDS == pce.getPropertyName() ||  
PNode.PROPERTY_FULL_BOUNDS == pce.getPropertyName());
+    }

      /**
       * Should the ScrollPane be revalidated. This occurs when either the

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

Reply via email to