6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
authorrupashka
Mon, 11 Aug 2008 16:39:17 +0400
changeset 1296 b42a874137fc
parent 1295 3cf2264a5743
child 1297 59aad2292413
6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build. Summary: Fixed calculation of preferred size in SynthButtonUI Reviewed-by: loneid, peterz
jdk/src/share/classes/javax/swing/plaf/synth/SynthButtonUI.java
jdk/test/javax/swing/JButton/6604281/bug6604281.java
--- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthButtonUI.java	Fri Aug 08 20:49:26 2008 +0400
+++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthButtonUI.java	Mon Aug 11 16:39:17 2008 +0400
@@ -262,7 +262,7 @@
      * Returns the default icon. This should NOT callback
      * to the JComponent.
      *
-     * @param b AbstractButton the iocn is associated with
+     * @param b AbstractButton the icon is associated with
      * @return default icon
      */
 
@@ -445,9 +445,7 @@
      * Returns the Icon used in calculating the pref/min/max size.
      */
     protected Icon getSizingIcon(AbstractButton b) {
-        // NOTE: this is slightly different than BasicButtonUI, where it
-        // would just use getIcon, but this should be ok.
-        Icon icon = (b.isEnabled()) ? b.getIcon() : b.getDisabledIcon();
+        Icon icon = getEnabledIcon(b, b.getIcon());
         if (icon == null) {
             icon = getDefaultIcon(b);
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JButton/6604281/bug6604281.java	Mon Aug 11 16:39:17 2008 +0400
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2008 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 6604281
+   @summary NimbusL&F :Regression in Focus traversal in JFileChooser in pit build
+   @author Pavel Porvatov
+   @run main bug6604281
+*/
+
+import javax.swing.*;
+import javax.swing.plaf.IconUIResource;
+import javax.swing.plaf.synth.SynthLookAndFeel;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.lang.reflect.InvocationTargetException;
+
+public class bug6604281 {
+    public static void main(String[] args) throws InvocationTargetException, InterruptedException {
+        SwingUtilities.invokeAndWait(new Runnable() {
+            public void run() {
+                SynthLookAndFeel laf = new SynthLookAndFeel();
+                try {
+                    UIManager.setLookAndFeel(laf);
+                } catch (Exception e) {
+                    fail(e.getMessage());
+                }
+
+                // Prepare image
+                BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);
+
+                Graphics2D graphics = (Graphics2D) image.getGraphics();
+
+                graphics.setColor(Color.BLUE);
+                graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
+                graphics.setColor(Color.RED);
+                graphics.drawLine(0, 0, image.getWidth(), image.getHeight());
+
+                // Use IconUIResource as an icon, because with ImageIcon bug is not reproduced
+                JButton button1 = new JButton(new IconUIResource(new ImageIcon(image)));
+
+                JButton button2 = new JButton(new IconUIResource(new ImageIcon(image)));
+
+                button2.setEnabled(false);
+
+                if (button1.getPreferredSize().getHeight() != button2.getPreferredSize().getHeight()) {
+                    fail("Two similar buttons have different size");
+                }
+            }
+        });
+    }
+
+    private static void fail(String s) {
+        throw new RuntimeException("Test failed: " + s);
+    }
+}