提交 32d6dd14 编写于 作者: R rupashka

6918861: SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled

Reviewed-by: malenkov
上级 74044c39
...@@ -169,15 +169,13 @@ public class BasicSliderUI extends SliderUI{ ...@@ -169,15 +169,13 @@ public class BasicSliderUI extends SliderUI{
+ c + " when it only knows about " + c + " when it only knows about "
+ slider + "."); + slider + ".");
LookAndFeel.uninstallBorder(slider);
scrollTimer.stop(); scrollTimer.stop();
scrollTimer = null; scrollTimer = null;
uninstallDefaults(slider);
uninstallListeners( slider ); uninstallListeners( slider );
uninstallKeyboardActions(slider); uninstallKeyboardActions(slider);
focusInsets = null;
insetCache = null; insetCache = null;
leftToRightCache = true; leftToRightCache = true;
focusRect = null; focusRect = null;
...@@ -210,6 +208,12 @@ public class BasicSliderUI extends SliderUI{ ...@@ -210,6 +208,12 @@ public class BasicSliderUI extends SliderUI{
if (focusInsets == null) focusInsets = new InsetsUIResource(2,2,2,2); 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) { protected TrackListener createTrackListener(JSlider slider) {
return new TrackListener(); return new TrackListener();
} }
......
...@@ -109,7 +109,7 @@ public class SynthSliderUI extends BasicSliderUI ...@@ -109,7 +109,7 @@ public class SynthSliderUI extends BasicSliderUI
* Uninstalls default setting. This method is called when a * Uninstalls default setting. This method is called when a
* {@code LookAndFeel} is uninstalled. * {@code LookAndFeel} is uninstalled.
*/ */
protected void uninstallDefaults() { protected void uninstallDefaults(JSlider slider) {
SynthContext context = getContext(slider, ENABLED); SynthContext context = getContext(slider, ENABLED);
style.uninstallDefaults(context); style.uninstallDefaults(context);
context.dispose(); context.dispose();
......
/*
* 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;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册