You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/08/25 21:59:01 UTC

svn commit: r807785 - in /incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk: SplitPaneListener.java skin/terra/TerraSplitPaneSkin.java

Author: tvolkert
Date: Tue Aug 25 19:59:00 2009
New Revision: 807785

URL: http://svn.apache.org/viewvc?rev=807785&view=rev
Log:
PIVOT-237 :: Fixed newly introduced TerraSplitPaneSkin issues

Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPaneListener.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSplitPaneSkin.java

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPaneListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPaneListener.java?rev=807785&r1=807784&r2=807785&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPaneListener.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPaneListener.java Tue Aug 25 19:59:00 2009
@@ -24,7 +24,10 @@
      * Called when a split pane's top left component has changed.
      *
      * @param splitPane
+     * The SplitPane that the event originates from.
+     *
      * @param previousTopLeft
+     * The previous component. The new component can be found inside the splitPane.
      */
     public void topLeftChanged(SplitPane splitPane, Component previousTopLeft);
 
@@ -32,7 +35,10 @@
      * Called when a split pane's bottom right component has changed.
      *
      * @param splitPane
+     * The SplitPane that the event originates from.
+     *
      * @param previousBottomRight
+     * The previous component. The new component can be found inside the splitPane.
      */
     public void bottomRightChanged(SplitPane splitPane, Component previousBottomRight);
 
@@ -40,6 +46,7 @@
      * Called when a split pane's orientation has changed.
      *
      * @param splitPane
+     * The SplitPane that the event originates from.
      */
     public void orientationChanged(SplitPane splitPane);
 
@@ -47,6 +54,7 @@
      * Called when a split pane's primary region has changed.
      *
      * @param splitPane
+     * The SplitPane that the event originates from.
      */
     public void primaryRegionChanged(SplitPane splitPane);
 
@@ -54,7 +62,10 @@
      * Called when a split pane's split location has changed.
      *
      * @param splitPane
+     * The SplitPane that the event originates from.
+     *
      * @param previousSplitRatio
+     * The previous setting of the splitRatio.
      */
     public void splitRatioChanged(SplitPane splitPane, float previousSplitRatio);
 
@@ -62,6 +73,7 @@
      * Called when a split pane's locked flag has changed.
      *
      * @param splitPane
+     * The SplitPane that the event originates from.
      */
     public void lockedChanged(SplitPane splitPane);
 }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSplitPaneSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSplitPaneSkin.java?rev=807785&r1=807784&r2=807785&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSplitPaneSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSplitPaneSkin.java Tue Aug 25 19:59:00 2009
@@ -77,7 +77,7 @@
         }
 
         public void paint(Graphics2D graphics) {
-            SplitPane splitPane = (SplitPane) TerraSplitPaneSkin.this.getComponent();
+            SplitPane splitPane = (SplitPane)TerraSplitPaneSkin.this.getComponent();
 
             Orientation orientation = splitPane.getOrientation();
 
@@ -93,7 +93,8 @@
                 imageHeight = height - 4;
             }
 
-            if (imageWidth > 0 && imageHeight > 0) {
+            if (imageWidth > 0
+                && imageHeight > 0) {
                 int translateX = (width - imageWidth) / 2;
                 int translateY = (height - imageHeight) / 2;
                 graphics.translate(translateX, translateY);
@@ -134,7 +135,7 @@
             boolean consumed = super.mouseMove(component, x, y);
 
             if (Mouse.getCapturer() == component) {
-                SplitPane splitPane = (SplitPane) TerraSplitPaneSkin.this.getComponent();
+                SplitPane splitPane = (SplitPane)TerraSplitPaneSkin.this.getComponent();
                 Orientation orientation = splitPane.getOrientation();
 
                 // Calculate the would-be new split location
@@ -142,10 +143,10 @@
                 float splitRatio;
                 if (orientation == Orientation.HORIZONTAL) {
                     splitLocation = limitSplitLocation(component.getX() + x - dragOffset);
-                    splitRatio = (float) splitLocation / splitPane.getWidth();
+                    splitRatio = (float)splitLocation / splitPane.getWidth();
                 } else {
                     splitLocation = limitSplitLocation(component.getY() + y - dragOffset);
-                    splitRatio = (float) splitLocation / splitPane.getHeight();
+                    splitRatio = (float)splitLocation / splitPane.getHeight();
                 }
 
                 if (shadow == null) {
@@ -168,9 +169,10 @@
         public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
             boolean consumed = super.mouseDown(component, button, x, y);
 
-            SplitPane splitPane = (SplitPane) TerraSplitPaneSkin.this.getComponent();
+            SplitPane splitPane = (SplitPane)TerraSplitPaneSkin.this.getComponent();
 
-            if (button == Mouse.Button.LEFT && !splitPane.isLocked()) {
+            if (button == Mouse.Button.LEFT
+                && !splitPane.isLocked()) {
                 Orientation orientation = splitPane.getOrientation();
 
                 if (useShadow) {
@@ -199,19 +201,20 @@
         public boolean mouseUp(Component component, Mouse.Button button, int x, int y) {
             boolean consumed = super.mouseUp(component, button, x, y);
 
-            if (button == Mouse.Button.LEFT && Mouse.getCapturer() == component) {
+            if (button == Mouse.Button.LEFT
+                && Mouse.getCapturer() == component) {
                 if (shadow != null) {
-                    SplitPane splitPane = (SplitPane) TerraSplitPaneSkin.this.getComponent();
+                    SplitPane splitPane = (SplitPane)TerraSplitPaneSkin.this.getComponent();
 
                     // Update the split location and remove the shadow
                     int splitLocation;
                     float splitRatio;
                     if (splitPane.getOrientation() == Orientation.HORIZONTAL) {
                         splitLocation = shadow.getX();
-                        splitRatio = (float) splitLocation / splitPane.getWidth();
+                        splitRatio = (float)splitLocation / splitPane.getWidth();
                     } else {
                         splitLocation = shadow.getY();
-                        splitRatio = (float) splitLocation / splitPane.getHeight();
+                        splitRatio = (float)splitLocation / splitPane.getHeight();
                     }
 
                     splitPane.setSplitRatio(splitRatio);
@@ -232,7 +235,6 @@
      */
     protected class SplitterShadow extends Component {
         public SplitterShadow() {
-            super();
             setSkin(new SplitterShadowSkin());
         }
     }
@@ -258,7 +260,6 @@
         }
 
         public void paint(Graphics2D graphics) {
-            graphics.setStroke(new BasicStroke());
             graphics.setPaint(new Color(0, 0, 0, 64));
             graphics.fillRect(0, 0, getWidth(), getHeight());
         }
@@ -272,7 +273,7 @@
     private boolean useShadow;
 
     public TerraSplitPaneSkin() {
-        TerraTheme theme = (TerraTheme) Theme.getTheme();
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
         splitterHandlePrimaryColor = theme.getColor(9);
         splitterHandleSecondaryColor = theme.getColor(10);
         splitterThickness = 6;
@@ -283,7 +284,7 @@
     public void install(Component component) {
         super.install(component);
 
-        SplitPane splitPane = (SplitPane) component;
+        SplitPane splitPane = (SplitPane)component;
         splitPane.getSplitPaneListeners().add(this);
 
         splitPane.add(splitter);
@@ -292,7 +293,7 @@
 
     @Override
     public void uninstall() {
-        SplitPane splitPane = (SplitPane) getComponent();
+        SplitPane splitPane = (SplitPane)getComponent();
         splitPane.getSplitPaneListeners().remove(this);
 
         splitPane.remove(splitter);
@@ -319,14 +320,14 @@
         int width = getWidth();
         int height = getHeight();
 
-        SplitPane splitPane = (SplitPane) getComponent();
+        SplitPane splitPane = (SplitPane)getComponent();
 
         float splitRatio = splitPane.getSplitRatio();
         Component topLeft = splitPane.getTopLeft();
         Component bottomRight = splitPane.getBottomRight();
 
         if (splitPane.getOrientation() == Orientation.HORIZONTAL) {
-            int splitLocation = limitSplitLocation((int) (splitRatio * width));
+            int splitLocation = limitSplitLocation((int)(splitRatio * width));
             int rightStart = splitLocation + splitterThickness;
             splitter.setLocation(splitLocation, 0);
             splitter.setSize(splitterThickness, height);
@@ -341,7 +342,7 @@
                 bottomRight.setSize(Math.max(width - rightStart, 0), height);
             }
         } else {
-            int splitLocation = limitSplitLocation((int) (splitRatio * height));
+            int splitLocation = limitSplitLocation((int)(splitRatio * height));
             int bottomStart = splitLocation + splitterThickness;
             splitter.setLocation(0, splitLocation);
             splitter.setSize(width, splitterThickness);
@@ -380,7 +381,7 @@
     }
 
     public final void setSplitterHandlePrimaryColor(int splitterHandlePrimaryColor) {
-        TerraTheme theme = (TerraTheme) Theme.getTheme();
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
         setSplitterHandlePrimaryColor(theme.getColor(splitterHandlePrimaryColor));
     }
 
@@ -406,7 +407,7 @@
     }
 
     public final void setSplitterHandleSecondaryColor(int splitterHandleSecondaryColor) {
-        TerraTheme theme = (TerraTheme) Theme.getTheme();
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
         setSplitterHandleSecondaryColor(theme.getColor(splitterHandleSecondaryColor));
     }
 
@@ -424,6 +425,10 @@
     }
 
     public void setUseShadow(boolean useShadow) {
+        if (Mouse.getCapturer() == getComponent()) {
+            throw new IllegalStateException("Cannot set useShadow while the splitter is being dragged.");
+        }
+
         this.useShadow = useShadow;
     }
 
@@ -454,7 +459,7 @@
 
     private void updateSplitterCursor() {
         Cursor cursor = Cursor.DEFAULT;
-        SplitPane splitPane = (SplitPane) getComponent();
+        SplitPane splitPane = (SplitPane)getComponent();
 
         if (!splitPane.isLocked()) {
             switch (splitPane.getOrientation()) {
@@ -490,46 +495,58 @@
     }
 
     private int limitSplitLocation(int splitLocation) {
-        SplitPane splitPane = (SplitPane) getComponent();
-        Orientation orientation = splitPane.getOrientation();
+        int width = getWidth();
+        int height = getHeight();
 
-        int lower = getMinimumTopLeftSize(splitPane);
-        int minBottomRightSize = getMinimumBottomRightSize(splitPane);
+        SplitPane splitPane = (SplitPane)getComponent();
 
-        int upper = ((orientation == Orientation.HORIZONTAL) ? splitPane.getWidth() : splitPane.getHeight())
-            - (splitterThickness + minBottomRightSize);
+        Component topLeft = splitPane.getTopLeft();
+        Component bottomRight = splitPane.getBottomRight();
 
-        if (splitLocation < lower) {
-            splitLocation = lower;
-        } else if (splitLocation > upper) {
-            splitLocation = upper;
-        }
+        int lower, upper;
 
-        return splitLocation;
-    }
+        if (splitPane.getOrientation() == Orientation.HORIZONTAL) {
+            lower = 0;
+            upper = width - splitterThickness;
 
-    private int getMinimumBottomRightSize( SplitPane splitPane ) {
-        int minBottomRightSize = 0;
-        Component bottomRightComponent = splitPane.getBottomRight();
-        if (bottomRightComponent  != null) {
-            minBottomRightSize = bottomRightComponent.getMinimumPreferredWidth();
-            if (minBottomRightSize < 0) {
-                minBottomRightSize = 0;
+            if (topLeft  != null) {
+                int leftLimit = topLeft.getMinimumPreferredWidth();
+                if (leftLimit >= 0) {
+                    lower = Math.min(leftLimit, upper);
+                }
             }
-        }
-        return minBottomRightSize;
-    }
 
-    private int getMinimumTopLeftSize( SplitPane splitPane ) {
-        int minTopLeftSize = 0;
-        Component topLeftComponent = splitPane.getBottomRight();
-        if (topLeftComponent  != null) {
-            minTopLeftSize = topLeftComponent.getMinimumPreferredWidth();
-            if (minTopLeftSize < 0) {
-                minTopLeftSize = 0;
+            if (bottomRight != null) {
+                int rightLimit = bottomRight.getMinimumPreferredWidth();
+                if (rightLimit >= 0) {
+                    upper = Math.max(upper - rightLimit, lower);
+                }
             }
+        } else {
+            lower = 0;
+            upper = height - splitterThickness;
 
+            if (topLeft  != null) {
+                int topLimit = topLeft.getMinimumPreferredHeight();
+                if (topLimit >= 0) {
+                    lower = Math.min(topLimit, upper);
+                }
+            }
+
+            if (bottomRight != null) {
+                int bottomLimit = bottomRight.getMinimumPreferredHeight();
+                if (bottomLimit >= 0) {
+                    upper = Math.max(upper - bottomLimit, lower);
+                }
+            }
         }
-        return minTopLeftSize;
+
+        if (splitLocation < lower) {
+            splitLocation = lower;
+        } else if (splitLocation > upper) {
+            splitLocation = upper;
+        }
+
+        return splitLocation;
     }
 }