changeset 2302:621e921a14cd

6918861: SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled Reviewed-by: malenkov
author rupashka
date Sat, 27 Feb 2010 15:09:16 +0300
parents 96205ed1b196
children 28741de0bb4a
files src/share/classes/javax/swing/plaf/basic/BasicSliderUI.java src/share/classes/javax/swing/plaf/synth/SynthSliderUI.java test/javax/swing/JSlider/6918861/bug6918861.java
diffstat 3 files changed, 111 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/javax/swing/plaf/basic/BasicSliderUI.java	Sat Feb 27 14:47:38 2010 +0300
+++ b/src/share/classes/javax/swing/plaf/basic/BasicSliderUI.java	Sat Feb 27 15:09:16 2010 +0300
@@ -169,15 +169,13 @@
                                                     + c + " when it only knows about "
                                                     + slider + ".");
 
-        LookAndFeel.uninstallBorder(slider);
-
         scrollTimer.stop();
         scrollTimer = null;
 
+        uninstallDefaults(slider);
         uninstallListeners( slider );
         uninstallKeyboardActions(slider);
 
-        focusInsets = null;
         insetCache = null;
         leftToRightCache = true;
         focusRect = null;
@@ -210,6 +208,12 @@
         if (focusInsets == null) focusInsets = new InsetsUIResource(2,2,2,2);
     }
 
+    protected void uninstallDefaults(JSlider slider) {
+        LookAndFeel.uninstallBorder(slider);
+
+        focusInsets = null;
+    }
+
     protected TrackListener createTrackListener(JSlider slider) {
         return new TrackListener();
     }
--- a/src/share/classes/javax/swing/plaf/synth/SynthSliderUI.java	Sat Feb 27 14:47:38 2010 +0300
+++ b/src/share/classes/javax/swing/plaf/synth/SynthSliderUI.java	Sat Feb 27 15:09:16 2010 +0300
@@ -109,7 +109,7 @@
      * Uninstalls default setting. This method is called when a
      * {@code LookAndFeel} is uninstalled.
      */
-    protected void uninstallDefaults() {
+    protected void uninstallDefaults(JSlider slider) {
         SynthContext context = getContext(slider, ENABLED);
         style.uninstallDefaults(context);
         context.dispose();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/swing/JSlider/6918861/bug6918861.java	Sat Feb 27 15:09:16 2010 +0300
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 6918861
+ * @summary SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled
+ * @author Pavel Porvatov
+ * @run main bug6918861
+ */
+
+import javax.swing.*;
+import javax.swing.plaf.synth.SynthLookAndFeel;
+import javax.swing.plaf.synth.SynthSliderUI;
+
+public class bug6918861 {
+    public static void main(String[] args) throws Exception {
+        UIManager.setLookAndFeel(new SynthLookAndFeel());
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+            public void run() {
+                JSlider slider = new JSlider();
+
+                HackedSynthSliderUI ui = new HackedSynthSliderUI(slider);
+
+                slider.setUI(ui);
+
+                if (ui.counter != 111) {
+                    throw new RuntimeException("Some installers of SynthSliderUI weren't invoked");
+                }
+
+                slider.setUI(null);
+
+                if (ui.counter != 0) {
+                    throw new RuntimeException("Some uninstallers of SynthSliderUI weren't invoked");
+                }
+            }
+        });
+    }
+
+    private static class HackedSynthSliderUI extends SynthSliderUI {
+        private int counter;
+
+        protected HackedSynthSliderUI(JSlider c) {
+            super(c);
+        }
+
+        protected void installDefaults(JSlider slider) {
+            super.installDefaults(slider);
+
+            counter += 1;
+        }
+
+        protected void uninstallDefaults(JSlider slider) {
+            super.uninstallDefaults(slider);
+
+            counter -= 1;
+        }
+
+        protected void installListeners(JSlider slider) {
+            super.installListeners(slider);
+
+            counter += 10;
+        }
+
+        protected void uninstallListeners(JSlider slider) {
+            super.uninstallListeners(slider);
+
+            counter -= 10;
+        }
+
+        protected void installKeyboardActions(JSlider slider) {
+            super.installKeyboardActions(slider);
+
+            counter += 100;
+        }
+
+        protected void uninstallKeyboardActions(JSlider slider) {
+            super.uninstallKeyboardActions(slider);
+
+            counter -= 100;
+        }
+    }
+}