Revision: 553
Author: allain.lalonde
Date: Thu Jul 23 18:04:01 2009
Log: Implemented Issue 21; added a new Property Constant (since the old one  
was incorrect) and deprecated the old one
http://code.google.com/p/piccolo2d/source/detail?r=553

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/PRoot.java
   
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PCanvasTest.java

=======================================
---  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java        
 
Thu Jul 23 14:36:05 2009
+++  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java        
 
Thu Jul 23 18:04:01 2009
@@ -71,7 +71,11 @@
   */
  public class PCanvas extends JComponent implements PComponent {

+    /**
+     * @deprecated this is a typo and clients should change their code to  
reflect the correct spelling
+     */
      public static final String INTERATING_CHANGED_NOTIFICATION  
= "INTERATING_CHANGED_NOTIFICATION";
+    public static final String INTERACTING_CHANGED_NOTIFICATION  
= "INTERACTING_CHANGED_NOTIFICATION";

      public static PCanvas CURRENT_ZCANVAS = null;

@@ -244,7 +248,7 @@
       * canvas will normally render at a lower quality that is faster.
       */
      public boolean getInteracting() {
-        return interacting > 0;
+        return interacting > 0 || getRoot().getInteracting();
      }

      /**
@@ -286,7 +290,7 @@
          isInteracting = getInteracting();

          if (wasInteracting != isInteracting) {
-            firePropertyChange(INTERATING_CHANGED_NOTIFICATION,  
wasInteracting, isInteracting);
+            firePropertyChange(INTERACTING_CHANGED_NOTIFICATION,  
wasInteracting, isInteracting);
          }
      }

=======================================
--- /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PRoot.java      
 
Fri Jan 23 12:25:52 2009
+++ /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PRoot.java      
 
Thu Jul 23 18:04:01 2009
@@ -60,10 +60,13 @@
       */
      public static final String PROPERTY_INPUT_SOURCES = "inputSources";
      public static final int PROPERTY_CODE_INPUT_SOURCES = 1 << 14;
+    public static final String PROPERTY_INTERACTING_CHANGED  
= "INTERACTING_CHANGED_NOTIFICATION";
+    public static final int PROPERTY_CODE_INTERACTING_CHANGED = 1 << 13;

      protected transient boolean processingInputs;
      protected transient boolean processInputsScheduled;

+    private transient int interacting;
      private PInputManager defaultInputManager;
      private transient List inputSources;
      private transient long globalTime;
@@ -161,6 +164,55 @@
          }
          return defaultInputManager;
      }
+
+    /**
+     * Return true if this root has been marked as interacting. If so the  
root
+     * will normally render at a lower quality that is faster.
+     *
+     * @return True if this root has user interaction taking place
+     */
+    public boolean getInteracting() {
+        return interacting > 0;
+    }
+
+    /**
+     * Set if this root is interacting. If so the root will normally  
render at a
+     * lower quality that is faster. Also repaints the root if the the
+     * interaction has ended.
+     * <p/>
+     * This has similar functionality to the setInteracting method on  
Canvas,
+     * but this is the appropriate place to mark interactions that may  
occur in
+     * multiple canvases if this Root is shared.
+     *
+     * @param isInteracting True if this root has user interaction taking  
place
+     * @see PCanvas#setInteracting(boolean)
+     */
+    public void setInteracting(boolean isInteracting) {
+        boolean wasInteracting = getInteracting();
+
+        if (isInteracting) {
+            interacting++;
+        }
+        else {
+            interacting--;
+        }
+
+        isInteracting = getInteracting();
+        if (!isInteracting) {
+            // force all the child cameras to repaint
+            for (int i = 0; i < getChildrenCount(); i++) {
+                PNode child = getChild(i);
+                if (child instanceof PCamera) {
+                    child.repaint();
+                }
+            }
+
+        }
+        if (wasInteracting != isInteracting) {
+            firePropertyChange(PROPERTY_CODE_INTERACTING_CHANGED,  
PROPERTY_INTERACTING_CHANGED, Boolean
+                    .valueOf(wasInteracting),  
Boolean.valueOf(isInteracting));
+        }
+    }

      /**
       * Advanced. If you want to add additional input sources to the roots  
UI
=======================================
---  
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PCanvasTest.java    
 
Sun Jul 19 07:32:25 2009
+++  
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PCanvasTest.java    
 
Thu Jul 23 18:04:01 2009
@@ -45,7 +45,7 @@

      public void testSetInteractingFiresChangeEvent() {
          MockPropertyChangeListener mockListener = new  
MockPropertyChangeListener();
-         
canvas.addPropertyChangeListener(PCanvas.INTERATING_CHANGED_NOTIFICATION,  
mockListener);
+         
canvas.addPropertyChangeListener(PCanvas.INTERACTING_CHANGED_NOTIFICATION,  
mockListener);
          canvas.setInteracting(true);
          assertEquals(1, mockListener.getPropertyChangeCount());
      }

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

Reply via email to