harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r566638 - in /harmony/enhanced/classlib/trunk/modules/swing/src: main/java/common/javax/swing/plaf/basic/BasicSliderUI.java test/api/java.injected/javax/swing/plaf/basic/BasicSliderUITest.java
Date Thu, 16 Aug 2007 09:57:11 GMT
Author: odeakin
Date: Thu Aug 16 02:57:11 2007
New Revision: 566638

URL: http://svn.apache.org/viewvc?view=rev&rev=566638
Log:
Apply patch HARMONY-4445 ([classlib][swing] JSlider thumb can't move if JSlider.getMaximum()=Integer.MAX_VALUE)

Modified:
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicSliderUI.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/plaf/basic/BasicSliderUITest.java

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicSliderUI.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicSliderUI.java?view=diff&rev=566638&r1=566637&r2=566638
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicSliderUI.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicSliderUI.java
Thu Aug 16 02:57:11 2007
@@ -1095,21 +1095,29 @@
     }
 
     protected int xPositionForValue(final int value) {
-        int size = slider.getMaximum() - slider.getMinimum();
-        int result = drawInverted() ^ !slider.getComponentOrientation().isLeftToRight()
-                           ? trackRect.x + trackRect.width - (trackRect.width * (value -
slider.getMinimum()) / size)
-                           : trackRect.x + trackRect.width * (value - slider.getMinimum())
/ size;
+        // Changed according to JIRA 4445
+        double valueToSizeRatio = (double) value
+                / (double) (slider.getMaximum() - slider.getMinimum());
+
+        if ((drawInverted() ^ !slider.getComponentOrientation().isLeftToRight())) {
+            return (int) (trackRect.x + trackRect.width - (trackRect.width * valueToSizeRatio));
+        } else {
+            return (int) (trackRect.x + trackRect.width * valueToSizeRatio);
+        }
 
-        return result;
     }
 
     protected int yPositionForValue(final int value) {
-        int size = slider.getMaximum() - slider.getMinimum();
-        int result = drawInverted() ^ (!slider.getComponentOrientation().isLeftToRight()
&& slider.getOrientation() == JSlider.HORIZONTAL)
-                           ? trackRect.y + trackRect.height * (value - slider.getMinimum())
/ size
-                           : trackRect.y + trackRect.height - (trackRect.height * (value
- slider.getMinimum()) / size);
+        // Changed according to JIRA 4445
+        double valueToSizeRatio = (double) value
+                / (double) (slider.getMaximum() - slider.getMinimum());
 
-        return result;
+        if ((drawInverted() ^ (!slider.getComponentOrientation()
+                .isLeftToRight() && slider.getOrientation() == JSlider.HORIZONTAL)))
{
+            return (int) (trackRect.y + trackRect.height * valueToSizeRatio);
+        } else {
+            return (int) (trackRect.y + trackRect.height - (trackRect.height * valueToSizeRatio));
+        }
     }
 
     public int valueForYPosition(final int yPos) {

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/plaf/basic/BasicSliderUITest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/plaf/basic/BasicSliderUITest.java?view=diff&rev=566638&r1=566637&r2=566638
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/plaf/basic/BasicSliderUITest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/plaf/basic/BasicSliderUITest.java
Thu Aug 16 02:57:11 2007
@@ -23,6 +23,7 @@
 import javax.swing.JButton;
 import javax.swing.JLabel;
 import javax.swing.JSlider;
+import javax.swing.SwingConstants;
 import javax.swing.SwingTestCase;
 import javax.swing.UIManager;
 import javax.swing.UnsupportedLookAndFeelException;
@@ -340,5 +341,57 @@
                 3, true);
         assertTrue(m.isEnabled());
     } 
+    
+    /**
+     * Regression test for HARMONY-4445
+     */
+    public void testMinMaxValue() {
+
+        slider.setMaximum(Integer.MAX_VALUE);
+        slider.setMinimum(0);
+        slider.setBounds(0,0,100,100);
+
+        int half = Integer.MAX_VALUE / 2;
+
+        // UI slightly modified to omit unneeded actions - no functional changes
+        // according to spec
+        BasicSliderUI tested = new BasicSliderUI(slider) {
+            @Override
+            protected void installKeyboardActions(JSlider unneded) {
+                // Empty. In real BasicSliderUI this method installs Keyboard
+                // actions
+            }
+
+            @Override
+            protected void installDefaults(JSlider unneded) {
+                // Empty. In real BasicSliderUI this method installs defaults
+                // (colors and fonts)
+            }
+
+            @Override
+            protected void installListeners(JSlider unneded) {
+                // Empty. In real BasicSliderUI this method installs listeners
+            }
+        };
+
+        tested.installUI(slider);
+        assertEquals(tested.xPositionForValue(half),
+                getCenterHorisontalPosition(tested));
+
+        slider.setOrientation(SwingConstants.VERTICAL);
+        tested.installUI(slider);
+
+        assertEquals(tested.yPositionForValue(half),
+                getCenterVerticalPosition(tested));
+        
+    }
+
+    private int getCenterVerticalPosition(BasicSliderUI ui) {
+        return ui.trackRect.y + (ui.trackRect.height / 2);
+    }
+
+    private int getCenterHorisontalPosition(BasicSliderUI ui) {
+        return ui.trackRect.x + (ui.trackRect.width / 2);
+    }
     
 }



Mime
View raw message