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/03/14 14:46:51 UTC

svn commit: r922844 - in /pivot/trunk/wtk/src/org/apache/pivot/wtk: ScriptApplication.java skin/CardPaneSkin.java

Author: gbrown
Date: Sun Mar 14 13:46:51 2010
New Revision: 922844

URL: http://svn.apache.org/viewvc?rev=922844&view=rev
Log:
Account for width and height constraints in CardPane when sizeToSelection is true; add more helpful error message when source file cannot be found in ScriptApplication.


Modified:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CardPaneSkin.java

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java?rev=922844&r1=922843&r2=922844&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java Sun Mar 14 13:46:51 2010
@@ -50,6 +50,10 @@ public class ScriptApplication implement
         ClassLoader classLoader = ThreadUtilities.getClassLoader();
         URL location = classLoader.getResource(src);
 
+        if (location == null) {
+            throw new IllegalArgumentException("Cannot find source file \"" + src + "\".");
+        }
+
         wtkxSerializer.put("location", location);
         window = (Window)wtkxSerializer.readObject(location);
         window.open(display);

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CardPaneSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CardPaneSkin.java?rev=922844&r1=922843&r2=922844&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CardPaneSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CardPaneSkin.java Sun Mar 14 13:46:51 2010
@@ -314,12 +314,35 @@ public class CardPaneSkin extends Contai
     public int getPreferredWidth(int height) {
         int preferredWidth = 0;
 
-        if (sizeToSelection
-            || height == -1) {
-            Dimensions preferredSize = getPreferredSize();
-            preferredWidth = preferredSize.width;
+        CardPane cardPane = (CardPane)getComponent();
+
+        if (sizeToSelection) {
+            if (selectionChangeTransition == null) {
+                Component selectedCard = cardPane.getSelectedCard();
+
+                if (selectedCard != null) {
+                    preferredWidth = selectedCard.getPreferredWidth(height);
+                }
+            } else {
+                float percentComplete = selectionChangeTransition.getPercentComplete();
+
+                int previousWidth;
+                if (selectionChangeTransition.fromCard == null) {
+                    previousWidth = 0;
+                } else {
+                    previousWidth = selectionChangeTransition.fromCard.getPreferredWidth(height);
+                }
+
+                int width;
+                if (selectionChangeTransition.toCard == null) {
+                    width = 0;
+                } else {
+                    width = selectionChangeTransition.toCard.getPreferredWidth(height);
+                }
+
+                preferredWidth = previousWidth + (int)((width - previousWidth) * percentComplete);
+            }
         } else {
-            CardPane cardPane = (CardPane)getComponent();
             for (Component card : cardPane) {
                 preferredWidth = Math.max(preferredWidth, card.getPreferredWidth(height));
             }
@@ -334,12 +357,35 @@ public class CardPaneSkin extends Contai
     public int getPreferredHeight(int width) {
         int preferredHeight = 0;
 
-        if (sizeToSelection
-            || width == -1) {
-            Dimensions preferredSize = getPreferredSize();
-            preferredHeight = preferredSize.height;
+        CardPane cardPane = (CardPane)getComponent();
+
+        if (sizeToSelection) {
+            if (selectionChangeTransition == null) {
+                Component selectedCard = cardPane.getSelectedCard();
+
+                if (selectedCard != null) {
+                    preferredHeight = selectedCard.getPreferredHeight(width);
+                }
+            } else {
+                float percentComplete = selectionChangeTransition.getPercentComplete();
+
+                int previousHeight;
+                if (selectionChangeTransition.fromCard == null) {
+                    previousHeight = 0;
+                } else {
+                    previousHeight = selectionChangeTransition.fromCard.getPreferredHeight(width);
+                }
+
+                int height;
+                if (selectionChangeTransition.toCard == null) {
+                    height = 0;
+                } else {
+                    height = selectionChangeTransition.toCard.getPreferredHeight(width);
+                }
+
+                preferredHeight = previousHeight + (int)((height - previousHeight) * percentComplete);
+            }
         } else {
-            CardPane cardPane = (CardPane)getComponent();
             for (Component card : cardPane) {
                 preferredHeight = Math.max(preferredHeight, card.getPreferredHeight(width));
             }