harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r496250 - in /harmony/enhanced/classlib/trunk/modules/swing/src: main/java/common/javax/swing/plaf/basic/BasicSliderUI.java test/api/java/common/javax/swing/plaf/basic/BasicSliderUITest.java
Date Mon, 15 Jan 2007 08:58:18 GMT
Author: hindessm
Date: Mon Jan 15 00:58:17 2007
New Revision: 496250

URL: http://svn.apache.org/viewvc?view=rev&rev=496250
Log:
Applying patches from "[#HARMONY-2855] [classlib][swing]
j.s.plaf.basic.BasicSliderUI.uninstallUI should throw
IllegalComponentStateException".

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/common/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=496250&r1=496249&r2=496250
==============================================================================
--- 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
Mon Jan 15 00:58:17 2007
@@ -14,18 +14,13 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
-/**
- * @author Sergey Burlak
- * @version $Revision$
- */
-
 package javax.swing.plaf.basic;
 
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.Graphics;
+import java.awt.IllegalComponentStateException;
 import java.awt.Insets;
 import java.awt.Point;
 import java.awt.Rectangle;
@@ -59,16 +54,23 @@
 import org.apache.harmony.x.swing.StringConstants;
 import org.apache.harmony.x.swing.Utilities;
 
-
+/**
+ * <b>Note:</b> <code>serialVersionUID</code> fields are added as
+ * a performance optimization only but not as a guarantee of correct
+ * deserialization.
+ */
 public class BasicSliderUI extends SliderUI {
 
     public class ActionScroller extends AbstractAction {
+        private static final long serialVersionUID = -3454576988589353120L;
+
         public ActionScroller(final JSlider slider, final int dir, final boolean block) {
         }
 
         public void actionPerformed(final ActionEvent e) {
         }
 
+        @Override
         public boolean isEnabled() {
             return true;
         }
@@ -88,7 +90,9 @@
         }
     }
 
+
     public class ComponentHandler extends ComponentAdapter {
+        @Override
         public void componentResized(final ComponentEvent e) {
             calculateGeometry();
             slider.repaint();
@@ -175,6 +179,7 @@
             });
         }
 
+        @Override
         public void mouseReleased(final MouseEvent e) {
             if (trackTimer.isRunning()) {
                 trackTimer.stop();
@@ -200,6 +205,7 @@
             slider.repaint();
         }
 
+        @Override
         public void mousePressed(final MouseEvent e) {
             if (!slider.isFocusOwner()) {
                 slider.requestFocus();
@@ -239,6 +245,7 @@
             return false;
         }
 
+        @Override
         public void mouseDragged(final MouseEvent e) {
             mousePoint = e.getPoint();
             if (inThumb && SwingUtilities.isLeftMouseButton(e)) {
@@ -272,6 +279,7 @@
             }
         }
 
+        @Override
         public void mouseMoved(final MouseEvent e) {
         }
 
@@ -378,8 +386,6 @@
     private static final int UNIT_INCREMENT = 1;
 
     public BasicSliderUI(final JSlider slider) {
-        this.slider = slider;
-
         focusRect = new Rectangle();
         contentRect = new Rectangle();
         labelRect = new Rectangle();
@@ -408,6 +414,7 @@
         return new BasicSliderUI((JSlider)c);
     }
 
+    @Override
     public void installUI(final JComponent c) {
         slider = (JSlider)c;
 
@@ -418,9 +425,12 @@
         calculateGeometry();
     }
 
+    @Override
     public void uninstallUI(final JComponent c) {
-        slider = (JSlider)c;
-
+        if (c != slider) {
+            // TODO Perform i18n after HARMONY-1320 is applied
+            throw new IllegalComponentStateException(this + " was asked to deinstall() "
+ c + " when it only knows about " + slider);
+        }
         uninstallListeners(slider);
         uninstallKeyboardActions(slider);
     }
@@ -558,6 +568,7 @@
         return new Dimension(width, DEFAULT_SLIDER_MIN_SIZE);
     }
 
+    @Override
     public Dimension getPreferredSize(final JComponent c) {
         if (slider.getOrientation() == JSlider.HORIZONTAL) {
             return getPreferredHorizontalSize();
@@ -566,6 +577,7 @@
         }
     }
 
+    @Override
     public Dimension getMinimumSize(final JComponent c) {
         if (slider.getOrientation() == JSlider.HORIZONTAL) {
             return getMinimumHorizontalSize();
@@ -574,6 +586,7 @@
         }
     }
 
+    @Override
     public Dimension getMaximumSize(final JComponent c) {
         if (slider.getOrientation() == JSlider.HORIZONTAL) {
             return new Dimension(Short.MAX_VALUE, getPreferredHorizontalSize().height);
@@ -811,6 +824,7 @@
         return result;
     }
 
+    @Override
     public void paint(final Graphics g, final JComponent c) {
         Color oldColor = g.getColor();
 
@@ -1063,6 +1077,8 @@
 
     private Action newMaxScrollAction() {
         return new AbstractAction() {
+            private static final long serialVersionUID = -3822301141065864044L;
+
             public void actionPerformed(final ActionEvent e) {
                 if (drawInverted()) {
                     slider.setValue(slider.getMinimum());
@@ -1076,6 +1092,8 @@
 
     private Action newMinScrollAction() {
         return new AbstractAction() {
+            private static final long serialVersionUID = 703565386507416752L;
+
             public void actionPerformed(final ActionEvent e) {
                 if (drawInverted()) {
                     slider.setValue(slider.getMaximum());
@@ -1089,6 +1107,8 @@
 
     private Action newNegativeBlockIncrementAction() {
         return new AbstractAction() {
+            private static final long serialVersionUID = 7818668169396841520L;
+
             public void actionPerformed(final ActionEvent e) {
                 scrollByBlock(NEGATIVE_SCROLL);
             }
@@ -1097,6 +1117,8 @@
 
     private Action newNegativeUnitIncrementAction() {
         return new AbstractAction() {
+            private static final long serialVersionUID = -4366059737366026435L;
+
             public void actionPerformed(final ActionEvent e) {
                 scrollByUnit(NEGATIVE_SCROLL);
             }
@@ -1105,6 +1127,8 @@
 
     private Action newPositiveBlockIncrementAction() {
         return new AbstractAction() {
+            private static final long serialVersionUID = -5999323396935662487L;
+
             public void actionPerformed(final ActionEvent e) {
                 scrollByBlock(POSITIVE_SCROLL);
             }
@@ -1113,6 +1137,8 @@
 
     private Action newPositiveUnitIncrementAction() {
         return new AbstractAction() {
+            private static final long serialVersionUID = 5166413389559469128L;
+
             public void actionPerformed(final ActionEvent e) {
                 scrollByUnit(POSITIVE_SCROLL);
             }

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/plaf/basic/BasicSliderUITest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/plaf/basic/BasicSliderUITest.java?view=diff&rev=496250&r1=496249&r2=496250
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/plaf/basic/BasicSliderUITest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/plaf/basic/BasicSliderUITest.java
Mon Jan 15 00:58:17 2007
@@ -20,8 +20,11 @@
  */
 package javax.swing.plaf.basic;
 
+import java.awt.IllegalComponentStateException;
 import java.awt.Point;
 import java.util.Hashtable;
+
+import javax.swing.JButton;
 import javax.swing.JLabel;
 import javax.swing.JSlider;
 import javax.swing.SwingTestCase;
@@ -223,6 +226,64 @@
         assertEquals(new Point(200, -500), sliderUI.thumbRect.getLocation());
         sliderUI.setThumbLocation(-200, 500);
         assertEquals(new Point(-200, 500), sliderUI.thumbRect.getLocation());
+    }
+
+    // Regression test for HARMONY-2855
+    public void testBasicSliderUI() throws Exception {
+        assertNull(sliderUI.slider);
+    }
+
+    /**
+     * <code>uninstallUI</code> is called with the same instance of
+     * <code>JSlider</code> to which this UI was installed.
+     */
+    // Regression test for HARMONY-2855
+    public void testUninstallUI01() {
+        sliderUI.installUI(slider);
+        sliderUI.uninstallUI(slider);
+        // No exception is expected
+    }
+
+    /**
+     * <code>uninstallUI</code> is called before <code>installUI</code>
+     * was called.
+     */
+    // Regression test for HARMONY-2855
+    public void testUninstallUI02() {
+        try {
+            sliderUI.uninstallUI(slider);
+            fail("IllegalComponentStateException is expected");
+        } catch (IllegalComponentStateException e) {
+            // expected
+        }
+    }
+
+    /**
+     * <code>uninstallUI</code> is called with another instance of
+     * <code>JSlider</code>.
+     */
+    // Regression test for HARMONY-2855
+    public void testUninstallUI03() {
+        try {
+            sliderUI.uninstallUI(new JSlider());
+            fail("IllegalComponentStateException is expected");
+        } catch (IllegalComponentStateException e) {
+            // expected
+        }
+    }
+
+    /**
+     * <code>uninstallUI</code> is called with instance of another class, i.e.
+     * not <code>JSlider</code> instance.
+     */
+    // Regression test for HARMONY-2855
+    public void testUninstallUI04() {
+        try {
+            sliderUI.uninstallUI(new JButton());
+            fail("IllegalComponentStateException is expected");
+        } catch (IllegalComponentStateException e) {
+            // expected
+        }
     }
     
     /**



Mime
View raw message