4252173: Inability to reuse the HorizontalSliderThumbIcon
authorrupashka
Mon, 28 Apr 2008 17:17:45 +0400
changeset 453 145f4ac00bfd
parent 414 05c1395dbe48
child 454 2f4f4fef8880
4252173: Inability to reuse the HorizontalSliderThumbIcon Summary: Removed casting component to JSlider from MetalIconFactory Reviewed-by: alexp
jdk/src/share/classes/javax/swing/plaf/metal/MetalIconFactory.java
jdk/test/javax/swing/JFileChooser/4252173/bug4252173.java
--- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalIconFactory.java	Wed Apr 23 18:06:34 2008 +0400
+++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalIconFactory.java	Mon Apr 28 17:17:45 2008 +0400
@@ -2278,18 +2278,16 @@
     }
 
     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 @@
         }
 
         // Fill in the background
-        if ( slider.hasFocus() ) {
+        if ( c.hasFocus() ) {
             g.setColor( c.getForeground() );
         }
         else {
@@ -2338,8 +2336,8 @@
 
         // 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 @@
         }
 
         // 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 @@
     }
 
     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 @@
         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 @@
         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 @@
         }
 
         // 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 );
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JFileChooser/4252173/bug4252173.java	Mon Apr 28 17:17:45 2008 +0400
@@ -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);
+            }
+        });
+    }
+}