GoogleCodeArchive / piccolo2d

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

PSwing doesn't work with certain swing components (tooltips, drop-downs, scrollbars (on mouse off), etc.) #18

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create PSwing components that have a tooltip, drop-down, and scrollbar
2. Add the PSwing to a canvas where it is not at the top-left corner
3. Try to use the swing component

What is the expected output? What do you see instead?
Tooltips and drop-downs show up in the wrong location, and the scrollbar
works fine until you drag the cursor into the content region where it
mysteriously jumps.  (PComboBox is a workaround for the drop-down, but
requires a custom component)

Proposed fix:
(this is not a general purpose fix, because it relies upon the bounding
area of the PSwing component.  Therefore, if you do arbitrary transforms on
the PSwing component (for example rotation), the offset will be slightly off.

Index: extras/edu/umd/cs/piccolox/pswing/PSwing.java
===================================================================
--- extras/edu/umd/cs/piccolox/pswing/PSwing.java   (revision 12)
+++ extras/edu/umd/cs/piccolox/pswing/PSwing.java   (revision 13)
@@ -194,7 +194,7 @@
             } else {
                 updateCanvas(null);
             }
-
+            reshape();
         }
     };

@@ -213,8 +213,8 @@
                 reshape();
             }
         });
+        listenForCanvas(this);
         reshape();
-        listenForCanvas(this);
     }

     /**
@@ -232,7 +232,11 @@
      * Ensures the bounds of the underlying component are accurate, and
sets the bounds of this PNode.
      */
     void reshape() {
-        component.setBounds(0, 0, component.getPreferredSize().width,
component.getPreferredSize().height);
+        Rectangle2D swingBounds = getGlobalBounds();
+        if (canvas != null) {
+           
canvas.getCamera().getViewTransformReference().transform(swingBounds,
swingBounds);
+        }
+        component.setBounds((int) swingBounds.getX(), (int)
swingBounds.getY(), component.getPreferredSize().width,
component.getPreferredSize().height);
         setBounds(0, 0, component.getPreferredSize().width,
component.getPreferredSize().height);
     }

@@ -249,6 +253,7 @@
      * @param renderContext Contains information about current render.
      */
     public void paint(PPaintContext renderContext) {
+        reshape();
         Graphics2D g2 = renderContext.getGraphics();

         if (defaultStroke == null) { 

Original issue reported on code.google.com by steveonjava on 24 Jun 2008 at 8:09

GoogleCodeExporter commented 9 years ago

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

GoogleCodeExporter commented 9 years ago
Here are some extra fixes to the reshape function to handle multiple cameras:

Index: extras/edu/umd/cs/piccolox/pswing/PSwing.java
===================================================================
--- extras/edu/umd/cs/piccolox/pswing/PSwing.java   (revision 35)
+++ extras/edu/umd/cs/piccolox/pswing/PSwing.java   (revision 36)
@@ -235,14 +235,24 @@
         this(component);
     }

+    void reshape() {
+        reshape(null);
+    }
+
     /**
      * Ensures the bounds of the underlying component are accurate, and sets the
bounds of this PNode.
+     * @param camera
      */
-    void reshape() {
+    void reshape(PCamera camera) {
         Rectangle2D swingBounds = getGlobalBounds();
-        if (canvas != null) {
-            
canvas.getCamera().getViewTransformReference().transform(swingBounds,
swingBounds);
+        if (camera == null && canvas != null) {
+            camera = canvas.getCamera();
         }
+        if (canvas != null && !isDescendentOf(camera)) {
+            camera.globalToLocal(swingBounds);
+            camera.getViewTransformReference().transform(swingBounds, 
swingBounds);
+        }
+
         component.setBounds((int) swingBounds.getX(), (int) swingBounds.getY(),
component.getPreferredSize().width, component.getPreferredSize().height);
         setBounds(0, 0, component.getPreferredSize().width,
component.getPreferredSize().height);
     }
@@ -260,7 +270,7 @@
      * @param renderContext Contains information about current render.
      */
     public void paint(PPaintContext renderContext) {
-        reshape();
+        reshape(renderContext.getCamera());
         Graphics2D g2 = renderContext.getGraphics();

         if (defaultStroke == null) {

Original comment by steveonjava on 29 Jun 2008 at 11:27

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
Deferring to Milestone-2.0 per email from Steve.

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

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