diff options
author | rupashka <none@none> | 2008-04-28 17:17:45 +0400 |
---|---|---|
committer | rupashka <none@none> | 2008-04-28 17:17:45 +0400 |
commit | 150bb10ee9b13736eb4de3c7e3fd77208d8fa8d5 (patch) | |
tree | 7203341286925113ca4d6feeaea83f791622a212 | |
parent | d892b43350765e08c8eb5e7044a427459042fddb (diff) |
4252173: Inability to reuse the HorizontalSliderThumbIcon
Summary: Removed casting component to JSlider from MetalIconFactory
Reviewed-by: alexp
-rw-r--r-- | src/share/classes/javax/swing/plaf/metal/MetalIconFactory.java | 34 | ||||
-rw-r--r-- | test/javax/swing/JFileChooser/4252173/bug4252173.java | 58 |
2 files changed, 73 insertions, 19 deletions
diff --git a/src/share/classes/javax/swing/plaf/metal/MetalIconFactory.java b/src/share/classes/javax/swing/plaf/metal/MetalIconFactory.java index 61949c7cf..72c2230d1 100644 --- a/src/share/classes/javax/swing/plaf/metal/MetalIconFactory.java +++ b/src/share/classes/javax/swing/plaf/metal/MetalIconFactory.java @@ -2278,18 +2278,16 @@ private static class VerticalSliderThumbIcon implements Icon, Serializable, UIRe } public void paintIcon( Component c, Graphics g, int x, int y ) { - JSlider slider = (JSlider)c; - - boolean leftToRight = MetalUtils.isLeftToRight(slider); + boolean leftToRight = MetalUtils.isLeftToRight(c); g.translate( x, y ); // Draw the frame - if ( slider.hasFocus() ) { + if ( c.hasFocus() ) { g.setColor( MetalLookAndFeel.getPrimaryControlInfo() ); } else { - g.setColor( slider.isEnabled() ? MetalLookAndFeel.getPrimaryControlInfo() : + g.setColor( c.isEnabled() ? MetalLookAndFeel.getPrimaryControlInfo() : MetalLookAndFeel.getControlDarkShadow() ); } @@ -2309,7 +2307,7 @@ private static class VerticalSliderThumbIcon implements Icon, Serializable, UIRe } // Fill in the background - if ( slider.hasFocus() ) { + if ( c.hasFocus() ) { g.setColor( c.getForeground() ); } else { @@ -2338,8 +2336,8 @@ private static class VerticalSliderThumbIcon implements Icon, Serializable, UIRe // Draw the bumps int offset = (leftToRight) ? 2 : 8; - if ( slider.isEnabled() ) { - if ( slider.hasFocus() ) { + if ( c.isEnabled() ) { + if ( c.hasFocus() ) { primaryBumps.paintIcon( c, g, offset, 2 ); } else { @@ -2348,8 +2346,8 @@ private static class VerticalSliderThumbIcon implements Icon, Serializable, UIRe } // Draw the highlight - if ( slider.isEnabled() ) { - g.setColor( slider.hasFocus() ? MetalLookAndFeel.getPrimaryControl() + if ( c.isEnabled() ) { + g.setColor( c.hasFocus() ? MetalLookAndFeel.getPrimaryControl() : MetalLookAndFeel.getControlHighlight() ); if (leftToRight) { g.drawLine( 1, 1, 8, 1 ); @@ -2389,16 +2387,14 @@ private static class HorizontalSliderThumbIcon implements Icon, Serializable, UI } public void paintIcon( Component c, Graphics g, int x, int y ) { - JSlider slider = (JSlider)c; - g.translate( x, y ); // Draw the frame - if ( slider.hasFocus() ) { + if ( c.hasFocus() ) { g.setColor( MetalLookAndFeel.getPrimaryControlInfo() ); } else { - g.setColor( slider.isEnabled() ? MetalLookAndFeel.getPrimaryControlInfo() : + g.setColor( c.isEnabled() ? MetalLookAndFeel.getPrimaryControlInfo() : MetalLookAndFeel.getControlDarkShadow() ); } @@ -2409,7 +2405,7 @@ private static class HorizontalSliderThumbIcon implements Icon, Serializable, UI g.drawLine( 7,15 , 14,8 ); // right slant // Fill in the background - if ( slider.hasFocus() ) { + if ( c.hasFocus() ) { g.setColor( c.getForeground() ); } else { @@ -2425,8 +2421,8 @@ private static class HorizontalSliderThumbIcon implements Icon, Serializable, UI g.drawLine( 7,14 , 7,14 ); // Draw the bumps - if ( slider.isEnabled() ) { - if ( slider.hasFocus() ) { + if ( c.isEnabled() ) { + if ( c.hasFocus() ) { primaryBumps.paintIcon( c, g, 2, 2 ); } else { @@ -2435,8 +2431,8 @@ private static class HorizontalSliderThumbIcon implements Icon, Serializable, UI } // Draw the highlight - if ( slider.isEnabled() ) { - g.setColor( slider.hasFocus() ? MetalLookAndFeel.getPrimaryControl() + if ( c.isEnabled() ) { + g.setColor( c.hasFocus() ? MetalLookAndFeel.getPrimaryControl() : MetalLookAndFeel.getControlHighlight() ); g.drawLine( 1, 1, 13, 1 ); g.drawLine( 1, 1, 1, 8 ); diff --git a/test/javax/swing/JFileChooser/4252173/bug4252173.java b/test/javax/swing/JFileChooser/4252173/bug4252173.java new file mode 100644 index 000000000..ba9db8204 --- /dev/null +++ b/test/javax/swing/JFileChooser/4252173/bug4252173.java @@ -0,0 +1,58 @@ +/* + * Copyright 2007 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 4252173 + @summary Inability to reuse the HorizontalSliderThumbIcon + @author Pavel Porvatov + @run main bug4252173 +*/ + +import javax.swing.*; +import javax.swing.plaf.metal.DefaultMetalTheme; +import javax.swing.plaf.metal.MetalLookAndFeel; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.lang.reflect.InvocationTargetException; + +public class bug4252173 { + public static void main(String[] args) throws InvocationTargetException, InterruptedException { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme()); + + JComponent component = new JLabel(); + + Icon horizontalThumbIcon = UIManager.getIcon("Slider.horizontalThumbIcon"); + + Icon verticalThumbIcon = UIManager.getIcon("Slider.verticalThumbIcon"); + + Graphics g = new BufferedImage(100, 100, BufferedImage.TYPE_4BYTE_ABGR).getGraphics(); + + horizontalThumbIcon.paintIcon(component, g, 0, 0); + + verticalThumbIcon.paintIcon(component, g, 0, 0); + } + }); + } +} |