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 2009/11/03 16:03:29 UTC

svn commit: r832446 - in /incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk: effects/TranslationDecorator.java skin/terra/TerraSheetSkin.java

Author: gbrown
Date: Tue Nov  3 15:03:29 2009
New Revision: 832446

URL: http://svn.apache.org/viewvc?rev=832446&view=rev
Log:
Update sheet transition to work with resizable sheets.

Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/TranslationDecorator.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/TranslationDecorator.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/TranslationDecorator.java?rev=832446&r1=832445&r2=832446&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/TranslationDecorator.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/effects/TranslationDecorator.java Tue Nov  3 15:03:29 2009
@@ -89,7 +89,10 @@
     @Override
     public Graphics2D prepare(Component component, Graphics2D graphics) {
         if (clip) {
-            graphics.clipRect(0, 0, component.getWidth(), component.getHeight());
+            Bounds decoratedBounds = component.getDecoratedBounds();
+            graphics.clipRect(decoratedBounds.x - component.getX(),
+                decoratedBounds.y - component.getY(),
+                decoratedBounds.width, decoratedBounds.height);
         }
 
         graphics.translate(x, y);

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java?rev=832446&r1=832445&r2=832446&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java Tue Nov  3 15:03:29 2009
@@ -55,6 +55,8 @@
  */
 public class TerraSheetSkin extends WindowSkin implements SheetStateListener {
     public class OpenTransition extends Transition {
+        private int dy = 0;
+
         public OpenTransition(boolean reversed) {
             super(TRANSITION_DURATION, TRANSITION_RATE, false, reversed);
         }
@@ -62,10 +64,9 @@
         @Override
         public void start(TransitionListener transitionListener) {
             Sheet sheet = (Sheet)getComponent();
-            Component content = sheet.getContent();
-            if (content != null) {
-                content.getDecorators().add(translationDecorator);
-            }
+            sheet.getDecorators().add(translationDecorator);
+
+            dy = 0;
 
             super.start(transitionListener);
         }
@@ -73,17 +74,35 @@
         @Override
         public void stop() {
             Sheet sheet = (Sheet)getComponent();
-            Component content = sheet.getContent();
-            if (content != null) {
-                content.getDecorators().remove(translationDecorator);
-            }
+            sheet.getDecorators().remove(translationDecorator);
 
             super.stop();
         }
 
         @Override
         public void update() {
-            invalidateComponent();
+            Sheet sheet = (Sheet)getComponent();
+
+            float scale;
+            if (isReversed()) {
+                scale = easing.easeIn(getElapsedTime(), 1, -1, getDuration());
+            } else {
+                scale = easing.easeOut(getElapsedTime(), 1, -1, getDuration());
+            }
+
+            Display display = sheet.getDisplay();
+            if (display != null) {
+                Bounds decoratedBounds = sheet.getDecoratedBounds();
+                display.repaint(decoratedBounds.x, decoratedBounds.y,
+                    decoratedBounds.width, decoratedBounds.height + dy);
+
+                Dimensions size = sheet.getPreferredSize();
+                dy = -(int)(size.height * scale);
+                translationDecorator.setY(dy);
+
+                display.repaint(decoratedBounds.x, decoratedBounds.y,
+                    decoratedBounds.width, decoratedBounds.height + dy);
+            }
         }
     }
 
@@ -130,7 +149,7 @@
 
     private OpenTransition openTransition = null;
     private Quadratic easing = new Quadratic();
-    private TranslationDecorator translationDecorator = new TranslationDecorator();
+    private TranslationDecorator translationDecorator = new TranslationDecorator(true);
 
     private ComponentListener ownerListener = new ComponentListener.Adapter() {
         @Override
@@ -269,7 +288,6 @@
         }
 
         preferredHeight += (padding.top + padding.bottom + 2);
-        preferredHeight = getEasedPreferredHeight(preferredHeight);
 
         return preferredHeight;
     }
@@ -290,31 +308,12 @@
 
         preferredWidth += (padding.left + padding.right + 2);
         preferredHeight += (padding.top + padding.bottom + 2);
-        preferredHeight = getEasedPreferredHeight(preferredHeight);
 
         Dimensions preferredSize = new Dimensions(preferredWidth, preferredHeight);
 
         return preferredSize;
     }
 
-    public int getEasedPreferredHeight(int preferredHeight) {
-        if (openTransition != null
-            && openTransition.isRunning()) {
-            float scale;
-            if (openTransition.isReversed()) {
-                scale = easing.easeIn(openTransition.getElapsedTime(), 0, 1,
-                    openTransition.getDuration());
-            } else {
-                scale = easing.easeOut(openTransition.getElapsedTime(), 0, 1,
-                    openTransition.getDuration());
-            }
-
-            preferredHeight = (int)(scale * preferredHeight);
-        }
-
-        return preferredHeight;
-    }
-
     @Override
     public void layout() {
         int width = getWidth();
@@ -329,21 +328,12 @@
         resizeHandle.setVisible(resizable);
 
         Component content = sheet.getContent();
-
         if (content != null) {
             content.setLocation(padding.left + 1, padding.top + 1);
 
-            if (openTransition != null
-                && openTransition.isRunning()) {
-                content.setSize(Math.max(width - (padding.left + padding.right + 2), 0),
-                    content.getPreferredHeight());
-                translationDecorator.setY(height - (padding.bottom + padding.top + 2
-                    + content.getHeight()));
-            } else {
-                int contentWidth = Math.max(width - (padding.left + padding.right + 2), 0);
-                int contentHeight = Math.max(height - (padding.top + padding.bottom + 2), 0);
-                content.setSize(contentWidth, contentHeight);
-            }
+            int contentWidth = Math.max(width - (padding.left + padding.right + 2), 0);
+            int contentHeight = Math.max(height - (padding.top + padding.bottom + 2), 0);
+            content.setSize(contentWidth, contentHeight);
         }
     }
 
@@ -570,6 +560,8 @@
 
         dropShadowDecorator.setShadowOpacity(DropShadowDecorator.DEFAULT_SHADOW_OPACITY);
 
+        alignToOwner();
+
         Window owner = window.getOwner();
         owner.getComponentListeners().add(ownerListener);