You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/01/03 15:40:37 UTC

svn commit: r895398 - in /incubator/pivot/trunk: tests/src/org/apache/pivot/tests/ wtk-terra/src/org/apache/pivot/wtk/skin/terra/

Author: gbrown
Date: Sun Jan  3 14:40:36 2010
New Revision: 895398

URL: http://svn.apache.org/viewvc?rev=895398&view=rev
Log:
Fix issues PIVOT-374 and PIVOT-376.

Modified:
    incubator/pivot/trunk/tests/src/org/apache/pivot/tests/CardPaneTest.java
    incubator/pivot/trunk/tests/src/org/apache/pivot/tests/WindowTest.java
    incubator/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraDialogSkin.java
    incubator/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java

Modified: incubator/pivot/trunk/tests/src/org/apache/pivot/tests/CardPaneTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tests/src/org/apache/pivot/tests/CardPaneTest.java?rev=895398&r1=895397&r2=895398&view=diff
==============================================================================
--- incubator/pivot/trunk/tests/src/org/apache/pivot/tests/CardPaneTest.java (original)
+++ incubator/pivot/trunk/tests/src/org/apache/pivot/tests/CardPaneTest.java Sun Jan  3 14:40:36 2010
@@ -19,6 +19,7 @@
 import org.apache.pivot.collections.Map;
 import org.apache.pivot.util.Vote;
 import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.ApplicationContext;
 import org.apache.pivot.wtk.Button;
 import org.apache.pivot.wtk.ButtonGroup;
 import org.apache.pivot.wtk.ButtonGroupListener;
@@ -89,7 +90,13 @@
         });
 
         frame.open(display);
-        sheet.open(frame);
+
+        ApplicationContext.queueCallback(new Runnable() {
+            @Override
+            public void run() {
+                sheet.open(frame);
+            }
+        });
     }
 
     @Override

Modified: incubator/pivot/trunk/tests/src/org/apache/pivot/tests/WindowTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tests/src/org/apache/pivot/tests/WindowTest.java?rev=895398&r1=895397&r2=895398&view=diff
==============================================================================
--- incubator/pivot/trunk/tests/src/org/apache/pivot/tests/WindowTest.java (original)
+++ incubator/pivot/trunk/tests/src/org/apache/pivot/tests/WindowTest.java Sun Jan  3 14:40:36 2010
@@ -20,6 +20,7 @@
 
 import org.apache.pivot.collections.Map;
 import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.ApplicationContext;
 import org.apache.pivot.wtk.Component;
 import org.apache.pivot.wtk.ComponentListener;
 import org.apache.pivot.wtk.DesktopApplicationContext;
@@ -58,9 +59,14 @@
         window1.setContent(new Label("Hello Bar"));
         window1.open(display);
 
-        Sheet sheet = new Sheet();
+        final Sheet sheet = new Sheet();
         sheet.setContent(new Label("Hello Foo"));
-        sheet.open(window1);
+        ApplicationContext.queueCallback(new Runnable() {
+            @Override
+            public void run() {
+                sheet.open(window1);
+            }
+        });
 
         Frame window1a = new Frame();
         window1a.setTitle("Window 1 A");

Modified: incubator/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraDialogSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraDialogSkin.java?rev=895398&r1=895397&r2=895398&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraDialogSkin.java (original)
+++ incubator/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraDialogSkin.java Sun Jan  3 14:40:36 2010
@@ -19,12 +19,12 @@
 
 import org.apache.pivot.collections.ArrayList;
 import org.apache.pivot.util.Vote;
-import org.apache.pivot.wtk.ApplicationContext;
 import org.apache.pivot.wtk.Component;
 import org.apache.pivot.wtk.Container;
 import org.apache.pivot.wtk.ContainerMouseListener;
 import org.apache.pivot.wtk.Dialog;
 import org.apache.pivot.wtk.DialogStateListener;
+import org.apache.pivot.wtk.Dimensions;
 import org.apache.pivot.wtk.Display;
 import org.apache.pivot.wtk.Keyboard;
 import org.apache.pivot.wtk.Mouse;
@@ -34,31 +34,7 @@
  * Dialog skin.
  */
 public class TerraDialogSkin extends TerraFrameSkin implements DialogStateListener {
-    private class RepositionCallback implements Runnable {
-        private static final float GOLDEN_SECTION = 0.382f;
-
-        @Override
-        public void run() {
-            Dialog dialog = (Dialog)getComponent();
-            Container ancestor = dialog.getOwner();
-
-            if (ancestor == null) {
-                ancestor = dialog.getDisplay();
-            }
-
-            int deltaWidth = ancestor.getWidth() - getWidth();
-            int deltaHeight = ancestor.getHeight() - getHeight();
-
-            int x = Math.max(0, Math.round(ancestor.getX() + 0.5f * deltaWidth));
-            int y = Math.max(0, Math.round(ancestor.getY() + GOLDEN_SECTION * deltaHeight));
-
-            dialog.setLocation(x, y);
-
-            queuedCallback = null;
-        }
-    }
-
-    private ApplicationContext.QueuedCallback queuedCallback = null;
+    private static final float GOLDEN_SECTION = 0.382f;
 
     private ContainerMouseListener displayMouseListener = new ContainerMouseListener.Adapter() {
         @Override
@@ -183,26 +159,33 @@
 
         Display display = window.getDisplay();
         display.getContainerMouseListeners().add(displayMouseListener);
-
         display.reenterMouse();
 
         if (!window.requestFocus()) {
             Component.clearFocus();
         }
 
-        queuedCallback = ApplicationContext.queueCallback(new RepositionCallback());
+        // Center the window over its owner
+        Container ancestor = window.getOwner();
+
+        if (ancestor == null) {
+            ancestor = window.getDisplay();
+        }
+
+        Dimensions size = getPreferredSize();
+        int deltaWidth = ancestor.getWidth() - size.width;
+        int deltaHeight = ancestor.getHeight() - size.height;
+
+        int x = Math.max(0, Math.round(ancestor.getX() + 0.5f * deltaWidth));
+        int y = Math.max(0, Math.round(ancestor.getY() + GOLDEN_SECTION * deltaHeight));
+
+        window.setLocation(x, y);
     }
 
     @Override
     public void windowClosed(Window window, Display display, Window owner) {
         super.windowClosed(window, display, owner);
-
         display.getContainerMouseListeners().remove(displayMouseListener);
-
-        if (queuedCallback != null) {
-            queuedCallback.cancel();
-            queuedCallback = null;
-        }
     }
 
     @Override

Modified: incubator/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java?rev=895398&r1=895397&r2=895398&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java (original)
+++ incubator/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java Sun Jan  3 14:40:36 2010
@@ -555,7 +555,6 @@
 
         Display display = window.getDisplay();
         display.getContainerMouseListeners().add(displayMouseListener);
-
         display.reenterMouse();
 
         dropShadowDecorator.setShadowOpacity(DropShadowDecorator.DEFAULT_SHADOW_OPACITY);