diff --git a/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java b/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java index 3c37aef..e6b26f5 100644 --- a/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java +++ b/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java @@ -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); } } diff --git a/core/src/main/java/edu/umd/cs/piccolo/PRoot.java b/core/src/main/java/edu/umd/cs/piccolo/PRoot.java index 61fa330..2e58583 100644 --- a/core/src/main/java/edu/umd/cs/piccolo/PRoot.java +++ b/core/src/main/java/edu/umd/cs/piccolo/PRoot.java @@ -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; @@ -163,6 +166,55 @@ } /** + * 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. + *
+ * 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 * process you can do that here. You will seldom do this unless you are * making additions to the piccolo framework. diff --git a/core/src/test/java/edu/umd/cs/piccolo/PCanvasTest.java b/core/src/test/java/edu/umd/cs/piccolo/PCanvasTest.java index c21d109..3c3ea43 100644 --- a/core/src/test/java/edu/umd/cs/piccolo/PCanvasTest.java +++ b/core/src/test/java/edu/umd/cs/piccolo/PCanvasTest.java @@ -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()); }