Revision: 1160
Author:   atdixon
Date:     Sat Jan  7 11:28:56 2012
Log: Issue 235 - PSwingEventHandler now uses Point2D.Double in call to cameraToLocal to avoid under/overflow
http://code.google.com/p/piccolo2d/source/detail?r=1160

Added:
/piccolo2d.java/branches/release-1.3.1/examples/src/main/java/edu/umd/cs/piccolo/examples/PSwingScaleExample.java
Modified:
/piccolo2d.java/branches/release-1.3.1/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEventHandler.java

=======================================
--- /dev/null
+++ /piccolo2d.java/branches/release-1.3.1/examples/src/main/java/edu/umd/cs/piccolo/examples/PSwingScaleExample.java Sat Jan 7 11:28:56 2012
@@ -0,0 +1,61 @@
+package edu.umd.cs.piccolo.examples;
+
+import edu.umd.cs.piccolo.PCamera;
+import edu.umd.cs.piccolo.PLayer;
+import edu.umd.cs.piccolo.PNode;
+import edu.umd.cs.piccolo.util.PBounds;
+import edu.umd.cs.piccolox.PFrame;
+import edu.umd.cs.piccolox.pswing.PSwing;
+import edu.umd.cs.piccolox.pswing.PSwingCanvas;
+
+import javax.swing.JButton;
+import javax.swing.JOptionPane;
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+/**
+ * Demonstrate that PSwing nodes properly receive events even when they are parented by nodes + * with extreme scales. This is an effective regression test that previously failed before fix
+ * applied to {@link edu.umd.cs.piccolox.pswing.PSwingEventHandler}.
+ */
+public class PSwingScaleExample extends PFrame {
+
+    public static void main(String[] args) {
+        new PSwingScaleExample();
+    }
+
+    public PSwingScaleExample() {
+ super(PSwingScaleExample.class.getSimpleName(), false, new PSwingCanvas());
+    }
+
+    public void initialize() {
+        final PSwingCanvas canvas = (PSwingCanvas) getCanvas();
+        final PLayer layer = canvas.getLayer();
+        final PCamera camera = canvas.getCamera();
+
+        PNode parent = new PNode();
+        parent.setPaint(Color.orange);
+        parent.setBounds(0, 0, 200, 200);
+
+        JButton button = new JButton("Drink Me");
+        button.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+ JOptionPane.showMessageDialog(PSwingScaleExample.this, "Thank You");
+            }
+        });
+        final PSwing ps = new PSwing(button);
+        centerFullBoundsIn(ps, parent.getGlobalFullBounds());
+        parent.addChild(ps);
+        parent.scale(0.001);
+
+        layer.addChild(parent);
+
+ camera.animateViewToCenterBounds(ps.getGlobalFullBounds(), true, 0);
+    }
+
+ private static void centerFullBoundsIn(PNode centerMe, PBounds bounds) { + centerMe.centerFullBoundsOnPoint(bounds.getCenterX(), bounds.getCenterY());
+    }
+
+}
=======================================
--- /piccolo2d.java/branches/release-1.3.1/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEventHandler.java Tue Mar 15 15:28:41 2011 +++ /piccolo2d.java/branches/release-1.3.1/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEventHandler.java Sat Jan 7 11:28:56 2012
@@ -208,9 +208,12 @@
             final PSwing swing = (PSwing) currentNode;
             final PNode grabNode = pickedNode;

-            point = new Point(mEvent.getX(), mEvent.getY());
- cameraToLocal(pSwingMouseEvent.getPath().getTopCamera(), point, grabNode);
-            prevPoint = (Point) point.clone();
+ // use a floating point object to perform cameraToLocal to survive the transform math + final Point2D.Double p2d = new Point2D.Double(mEvent.getX(), mEvent.getY()); + cameraToLocal(pSwingMouseEvent.getPath().getTopCamera(), p2d, grabNode);
+
+            point = new Point((int) p2d.getX(), (int) p2d.getY());
+            prevPoint = (Point2D) p2d.clone();

             // This is only partially fixed to find the deepest
             // component at pt. It needs to do something like

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

Reply via email to