GoogleCodeArchive / piccolo2d

Automatically exported from code.google.com/p/piccolo2d
0 stars 0 forks source link

Keyboard focus doesn't work for multiple cameras #24

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create 2 canvases that refer to different cameras, but the same root
2. Get the input manager and set the keyboard focus for the first canvas/camera
3. Get the input manager and set the keyboard focus for the second
canvas/camera

What is the expected output? What do you see instead?
Since the input manager is bound to the root, you only have one input
manager shared between the two sets of canvases and cameras.  Therefore,
when you change the focus in the second canvas/camera, the focus of the
first is lost.

The change below moves the input manager from the root to the camera node.
 For backwards compatibility, the PRoot.getDefaultInputManager can go down
the tree and select the first input manager it finds.

Here is the diff:
Index: src/edu/umd/cs/piccolo/PRoot.java
===================================================================
--- src/edu/umd/cs/piccolo/PRoot.java   (revision 23)
+++ src/edu/umd/cs/piccolo/PRoot.java   (revision 24)
@@ -36,9 +36,7 @@

 import javax.swing.*;
 import java.awt.event.ActionListener;
-import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.List;

 /**
  * <b>PRoot</b> serves as the top node in Piccolo's runtime structure.
@@ -57,17 +55,14 @@
      * change event the new value will be a reference to the list of this
root's
      * input sources, but old value will always be null.
      */
-    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 processActivities;
     protected transient boolean processInputsScheduled;

     private transient int interacting;
     private PInputManager defaultInputManager;
-    private transient List inputSources;
     private transient long globalTime;
     private PActivityScheduler activityScheduler;

@@ -86,7 +81,6 @@
      */
     public PRoot() {
         super();
-        inputSources = new ArrayList();
         globalTime = System.currentTimeMillis();
         activityScheduler = new PActivityScheduler(this);
     }
@@ -98,7 +92,7 @@
     /**
      * Add an activity to the activity scheduler associated with this root.
      * Activities are given a chance to run during each call to the roots
-     * <code>processInputs</code> method. When the activity has finished
+     * <code>processActivities</code> method. When the activity has finished
      * running it will automatically get removed.
      */
     public boolean addActivity(PActivity activity) {
@@ -131,7 +125,7 @@
         };

         while (activityScheduler.getActivitiesReference().size() > 0) {
-            processInputs();
+            processActivities();
             Iterator i = getAllNodes(cameraWithCanvas, null).iterator();
             while (i.hasNext()) {
                 PCamera each = (PCamera) i.next();
@@ -152,19 +146,6 @@
     }

     /**
-     * Get the default input manager to be used when processing input
-     * events. PCanvas's use this method when they forward new swing input
-     * events to the PInputManager.
-     */
-    public PInputManager getDefaultInputManager() {
-        if (defaultInputManager == null) {
-            defaultInputManager = new PInputManager();
-            addInputSource(defaultInputManager);
-        }
-        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.
      *
@@ -205,26 +186,6 @@
     }

     /**
-     * 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.
-     */
-    public void addInputSource(InputSource inputSource) {
-        inputSources.add(inputSource);
-        firePropertyChange(PROPERTY_CODE_INPUT_SOURCES,
PROPERTY_INPUT_SOURCES, null, inputSources);
-    }
-
-    /**
-     * Advanced. If you want to remove the default input source from the roots
-     * UI process you can do that here. You will seldom do this unless you
-     * are making additions to the piccolo framework.
-     */
-    public void removeInputSource(InputSource inputSource) {
-        inputSources.remove(inputSource);
-        firePropertyChange(PROPERTY_CODE_INPUT_SOURCES,
PROPERTY_INPUT_SOURCES, null, inputSources);
-    }
-
-    /**
      * Returns a new timer. This method allows subclasses, such as PSWTRoot to
      * create custom timers that will be used transparently by the Piccolo
      * framework.
@@ -239,7 +200,7 @@

     /**
      * Get the global Piccolo time. This is set to
System.currentTimeMillis() at
-     * the beginning of the roots <code>processInputs</code> method.
Activities
+     * the beginning of the roots <code>processActivities</code> method.
Activities
      * should usually use this global time instead of System.
      * currentTimeMillis() so that multiple activities will be synchronized.
      */
@@ -252,23 +213,17 @@
      * are processed. Activities are given a chance to run, and the bounds
caches
      * and any paint damage is validated.
      */
-    public void processInputs() {
-        PDebug.startProcessingInput();
-        processingInputs = true;
+    public void processActivities() {
+        PDebug.startProcessingActivities();
+        processActivities = true;

         globalTime = System.currentTimeMillis();
-        int count = inputSources == null ? 0 : inputSources.size();
-        for (int i = 0; i < count; i++) {
-            InputSource each = (InputSource) inputSources.get(i);
-            each.processInput();
-        }
-
         activityScheduler.processActivities(globalTime);
         validateFullBounds();
         validateFullPaint();

-        processingInputs = false;
-        PDebug.endProcessingInput();
+        processActivities = false;
+        PDebug.endProcessingActivities();
     }

     public void setFullBoundsInvalid(boolean fullLayoutInvalid) {
@@ -304,13 +259,13 @@

         PDebug.scheduleProcessInputs();

-        if (!processInputsScheduled && !processingInputs &&
+        if (!processInputsScheduled && !processActivities &&
                 (getFullBoundsInvalid() || getChildBoundsInvalid() ||
getPaintInvalid() || getChildPaintInvalid())) {

             processInputsScheduled = true;
             SwingUtilities.invokeLater(new Runnable() {
                 public void run() {
-                    processInputs();
+                    processActivities();
                     PRoot.this.processInputsScheduled = false;
                 }
             });
Index: src/edu/umd/cs/piccolo/activities/PActivityScheduler.java
===================================================================
--- src/edu/umd/cs/piccolo/activities/PActivityScheduler.java   (revision 23)
+++ src/edu/umd/cs/piccolo/activities/PActivityScheduler.java   (revision 24)
@@ -163,7 +163,7 @@
        if (activityTimer == null) {
            activityTimer = root.createTimer(PUtil.ACTIVITY_SCHEDULER_FRAME_DELAY,
new ActionListener() {
                public void actionPerformed(ActionEvent e) {
-                   root.processInputs();
+                    root.processActivities();
                }
            });
        }
Index: src/edu/umd/cs/piccolo/PCamera.java
===================================================================
--- src/edu/umd/cs/piccolo/PCamera.java (revision 23)
+++ src/edu/umd/cs/piccolo/PCamera.java (revision 24)
@@ -96,6 +83,7 @@
     public static final int VIEW_CONSTRAINT_CENTER = 2;

     private transient PComponent component;
+    private PInputManager inputManager;
     private transient List layers;
     private PAffineTransform viewTransform;
     private int viewConstraint;
@@ -128,6 +116,26 @@
     }

     /**
+     * Get the input manager to be used when processing input
+     * events. PCanvas's use this method when they forward new swing input
+     * events to the PInputManager.
+     */
+    public PInputManager getInputManager() {
+        if (inputManager == null) {
+            inputManager = new PInputManager();
+        }
+        return inputManager;
+    }
+
+    /**
+     * Set the input manager to be used when processing input
+     * events.
+     */
+    public void setInputManager(PInputManager inputManager) {
+        this.inputManager = inputManager;
+    }
+
+    /**
      * Repaint this camera, and forward the repaint request to the camera's
      * canvas if it is not null.
      */
Index: src/edu/umd/cs/piccolo/PInputManager.java
===================================================================
--- src/edu/umd/cs/piccolo/PInputManager.java   (revision 23)
+++ src/edu/umd/cs/piccolo/PInputManager.java   (revision 24)
@@ -257,13 +257,14 @@
     }

     public void processEventFromCamera(InputEvent event, int type, PCamera
camera) {
-        // queue input
+        // process input
         nextInput = event;
         nextType = type;
         nextInputSource = camera;
+        processInput();

         // tell root to process queued inputs
-        camera.getRoot().processInputs();
+        camera.getRoot().processActivities();
     }

     private void dispatchEventToListener(PInputEvent event, int type,
PInputEventListener listener) {
Index: src/edu/umd/cs/piccolo/PCanvas.java
===================================================================
--- src/edu/umd/cs/piccolo/PCanvas.java (revision 23)
+++ src/edu/umd/cs/piccolo/PCanvas.java (revision 24)
@@ -215,7 +215,7 @@

     /**
      * Return true if any activities that respond with true to the method
-     * isAnimating were run in the last PRoot.processInputs() loop. This
+     * isAnimating were run in the last PRoot.processActivities() loop. This
      * values is used by this canvas to determine the render quality
      * to use for the next paint.
      */
@@ -518,7 +518,7 @@
     }

     protected void sendInputEventToInputManager(InputEvent e, int type) {
-        getRoot().getDefaultInputManager().processEventFromCamera(e, type,
getCamera());
+        getCamera().getInputManager().processEventFromCamera(e, type,
getCamera());
     }

     public void setBounds(int x, int y, final int w, final int h) {
Index: src/edu/umd/cs/piccolo/util/PDebug.java
===================================================================
--- src/edu/umd/cs/piccolo/util/PDebug.java (revision 23)
+++ src/edu/umd/cs/piccolo/util/PDebug.java (revision 24)
@@ -29,17 +29,15 @@
  */
 package edu.umd.cs.piccolo.util;

-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
+import javax.swing.*;
+import java.awt.*;

-import javax.swing.SwingUtilities;
-
 /**
  * <b>PDebug</b> is used to set framework wide debugging flags.
- * <P>
- * @version 1.0
+ * <p/>
+ *
  * @author Jesse Grosjean
+ * @version 1.0
  */
 public class PDebug {

@@ -56,7 +54,7 @@

    private static long framesProcessed;
    private static long startProcessingOutputTime;
-   private static long startProcessingInputTime;
+    private static long startProcessingActivitiesTime;
    private static long processOutputTime;
    private static long processInputTime;
    private static boolean processingOutput;
@@ -125,12 +123,12 @@
        processingOutput = false;
    }

-   public static void startProcessingInput() {
-       startProcessingInputTime = System.currentTimeMillis();
+    public static void startProcessingActivities() {
+        startProcessingActivitiesTime = System.currentTimeMillis();
    }

-   public static void endProcessingInput() {
-       processInputTime += (System.currentTimeMillis() - startProcessingInputTime);
+    public static void endProcessingActivities() {
+        processInputTime += (System.currentTimeMillis() -
startProcessingActivitiesTime);
    }

    /**
Index: extras/edu/umd/cs/piccolox/swt/PSWTRoot.java
===================================================================
--- extras/edu/umd/cs/piccolox/swt/PSWTRoot.java    (revision 23)
+++ extras/edu/umd/cs/piccolox/swt/PSWTRoot.java    (revision 24)
@@ -41,13 +41,13 @@
            return;
        }

-       if (!processInputsScheduled && !processingInputs &&
+        if (!processInputsScheduled && !processActivities &&
            (getFullBoundsInvalid() || getChildBoundsInvalid() || getPaintInvalid()
|| getChildPaintInvalid())) {

            processInputsScheduled = true;
            composite.getDisplay().asyncExec(new Runnable() {
                public void run() {
-                   processInputs();
+                    processActivities();
                    processInputsScheduled = false;
                }
            });
Index: extras/edu/umd/cs/piccolox/swt/PSWTCanvas.java
===================================================================
--- extras/edu/umd/cs/piccolox/swt/PSWTCanvas.java  (revision 23)
+++ extras/edu/umd/cs/piccolox/swt/PSWTCanvas.java  (revision 24)
@@ -231,7 +222,7 @@

    /**
     * Return true if any activities that respond with true to the method
-    * isAnimating were run in the last PRoot.processInputs() loop. This
+     * isAnimating were run in the last PRoot.processActivities() loop. This
     * values is used by this canvas to determine the render quality
     * to use for the next paint.
     */
@@ -499,7 +476,7 @@
    }

    protected void sendInputEventToInputManager(InputEvent e, int type) {
-       getRoot().getDefaultInputManager().processEventFromCamera(e, type,
getCamera());
+        getCamera().getInputManager().processEventFromCamera(e, type,
getCamera());
    }

    public void setBounds(int x, int y, final int w, final int h) {
Index: examples/edu/umd/cs/piccolo/tutorial/SpecialEffects.java
===================================================================
--- examples/edu/umd/cs/piccolo/tutorial/SpecialEffects.java    (revision 23)
+++ examples/edu/umd/cs/piccolo/tutorial/SpecialEffects.java    (revision 24)
@@ -55,7 +56,7 @@
        PActivity a3 = aNode.animateToPositionScaleRotation(200, 100, 1, 0, 5000);

        // The animate activities will start immediately (in the next call to
-       // PRoot.processInputs) by default. Here we set their start times (in PRoot
+        // PRoot.processActivities) by default. Here we set their start
times (in PRoot
        // global time) so that they start when the previous one has finished.
        a1.setStartTime(currentTime);
        a2.startAfter(a1);
Index: examples/edu/umd/cs/piccolo/tutorial/PiccoloPresentation.java
===================================================================
--- examples/edu/umd/cs/piccolo/tutorial/PiccoloPresentation.java   (revision 23)
+++ examples/edu/umd/cs/piccolo/tutorial/PiccoloPresentation.java   (revision 24)
@@ -53,7 +53,7 @@

        getCanvas().requestFocus();
        getCanvas().addInputEventListener(eventHandler);
-   
getCanvas().getRoot().getDefaultInputManager().setKeyboardFocus(eventHandler);
+       
getCanvas().getCamera().getInputManager().setKeyboardFocus(eventHandler);
        getCanvas().removeInputEventListener(getCanvas().getZoomEventHandler());
        getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
    }
Index: examples/edu/umd/cs/piccolo/examples/SelectionExample.java
===================================================================
--- examples/edu/umd/cs/piccolo/examples/SelectionExample.java  (revision 23)
+++ examples/edu/umd/cs/piccolo/examples/SelectionExample.java  (revision 24)
@@ -40,7 +40,7 @@
        // Create a selection event handler
        PSelectionEventHandler selectionEventHandler = new
PSelectionEventHandler(getCanvas().getLayer(), getCanvas().getLayer());
        getCanvas().addInputEventListener(selectionEventHandler);
-   
getCanvas().getRoot().getDefaultInputManager().setKeyboardFocus(selectionEventHa
ndler);
+       
getCanvas().getCamera().getInputManager().setKeyboardFocus(selectionEventHandler
);

        PNotificationCenter.defaultCenter().addListener(this, 
                                                       "selectionChanged", 
Index: examples/edu/umd/cs/piccolo/examples/ActivityExample.java
===================================================================
--- examples/edu/umd/cs/piccolo/examples/ActivityExample.java   (revision 23)
+++ examples/edu/umd/cs/piccolo/examples/ActivityExample.java   (revision 24)
@@ -52,7 +53,7 @@

        // An activity will not run unless it is scheduled with the root. Once
        // it has been scheduled it will be given a chance to run during the next
-       // PRoot.processInputs() call.
+        // PRoot.processActivities() call.
        getCanvas().getRoot().addActivity(flash);

        // Use the PNode animate methods to create three activities that animate
@@ -63,7 +64,7 @@
        PActivity a3 = aNode.animateToPositionScaleRotation(200, 100, 1, 0, 5000);
        PActivity a4 = aNode.animateToTransparency(0.25f, 3000);

-       // the animate activities will start immediately (in the next call to
PRoot.processInputs)
+        // the animate activities will start immediately (in the next call
to PRoot.processActivities)
        // by default. Here we set their start times (in PRoot global time) so
that they start 
        // when the previous one has finished.
        a1.setStartTime(currentTime);

Original issue reported on code.google.com by steveonjava on 24 Jun 2008 at 9:30

GoogleCodeExporter commented 9 years ago

Original comment by steveonjava on 25 Jun 2008 at 6:35

GoogleCodeExporter commented 9 years ago

Original comment by steveonjava on 2 Jul 2008 at 12:28

GoogleCodeExporter commented 9 years ago

Original comment by steveonjava on 3 Jul 2008 at 5:05

GoogleCodeExporter commented 9 years ago
I'm not entire sure I understand this Issue. When using a regular user 
interface, there 
can only be 1 keyboard focus, why would a zoomable one be different?

If my screen is showing me 2 nodes as having the keyboard focus, I should have 
to type 
something to see which is the current one.

Please clarify.

Original comment by allain.lalonde on 20 Jul 2009 at 9:54

GoogleCodeExporter commented 9 years ago
Deferring to Milestone-2.0 per email from Steve.

Original comment by heue...@gmail.com on 27 Oct 2009 at 1:03

GoogleCodeExporter commented 9 years ago
Reverting back to New status

Original comment by heue...@gmail.com on 31 Aug 2012 at 8:19

GoogleCodeExporter commented 9 years ago

Original comment by heue...@gmail.com on 31 Aug 2012 at 8:20

GoogleCodeExporter commented 9 years ago

Original comment by heue...@gmail.com on 31 Aug 2012 at 8:22

GoogleCodeExporter commented 9 years ago

Original comment by heue...@gmail.com on 26 Nov 2013 at 11:22