6741426: ClassCastException from ComboBoxEditableState (Nimbus LaF) in JDK 1.6.0_10 RC
Reviewed-by: rupashka
1.1 --- a/src/share/classes/javax/swing/plaf/nimbus/skin.laf Thu May 14 00:17:25 2009 -0700
1.2 +++ b/src/share/classes/javax/swing/plaf/nimbus/skin.laf Thu May 14 18:12:13 2009 +0400
1.3 @@ -4201,8 +4201,9 @@
1.4 <stateType key="Disabled"/>
1.5 <stateType key="Focused"/>
1.6 <stateType key="Editable">
1.7 - <codeSnippet><![CDATA[
1.8 - return ((JComboBox)c).isEditable();]]></codeSnippet>
1.9 + <codeSnippet><![CDATA[
1.10 + return c instanceof JComboBox && ((JComboBox)c).isEditable();
1.11 + ]]></codeSnippet>
1.12 </stateType>
1.13 </stateTypes>
1.14 <contentMargins top="0" bottom="0" left="0" right="0"/>
1.15 @@ -16160,12 +16161,14 @@
1.16 <stateType key="Disabled"/>
1.17 <stateType key="Indeterminate">
1.18 <codeSnippet><![CDATA[
1.19 - return ((JProgressBar)c).isIndeterminate();
1.20 + return c instanceof JProgressBar &&
1.21 + ((JProgressBar)c).isIndeterminate();
1.22 ]]></codeSnippet>
1.23 </stateType>
1.24 <stateType key="Finished">
1.25 <codeSnippet><![CDATA[
1.26 - return ((JProgressBar)c).getPercentComplete() == 1.0;
1.27 + return c instanceof JProgressBar &&
1.28 + ((JProgressBar)c).getPercentComplete() == 1.0;
1.29 ]]></codeSnippet>
1.30 </stateType>
1.31 </stateTypes>
1.32 @@ -25845,26 +25848,26 @@
1.33 <stateTypes>
1.34 <stateType key="North">
1.35 <codeSnippet><![CDATA[
1.36 - JToolBar toolbar = (JToolBar)c;
1.37 - return NimbusLookAndFeel.resolveToolbarConstraint(toolbar) == BorderLayout.NORTH;
1.38 + return (c instanceof JToolBar) &&
1.39 + NimbusLookAndFeel.resolveToolbarConstraint((JToolBar)c) == BorderLayout.NORTH;
1.40 ]]></codeSnippet>
1.41 </stateType>
1.42 <stateType key="East">
1.43 <codeSnippet><![CDATA[
1.44 - JToolBar toolbar = (JToolBar)c;
1.45 - return NimbusLookAndFeel.resolveToolbarConstraint(toolbar) == BorderLayout.EAST;
1.46 + return (c instanceof JToolBar) &&
1.47 + NimbusLookAndFeel.resolveToolbarConstraint((JToolBar)c) == BorderLayout.EAST;
1.48 ]]></codeSnippet>
1.49 </stateType>
1.50 <stateType key="West">
1.51 <codeSnippet><![CDATA[
1.52 - JToolBar toolbar = (JToolBar)c;
1.53 - return NimbusLookAndFeel.resolveToolbarConstraint(toolbar) == BorderLayout.WEST;
1.54 + return (c instanceof JToolBar) &&
1.55 + NimbusLookAndFeel.resolveToolbarConstraint((JToolBar)c) == BorderLayout.WEST;
1.56 ]]></codeSnippet>
1.57 </stateType>
1.58 <stateType key="South">
1.59 <codeSnippet><![CDATA[
1.60 - JToolBar toolbar = (JToolBar)c;
1.61 - return NimbusLookAndFeel.resolveToolbarConstraint(toolbar) == BorderLayout.SOUTH;
1.62 + return (c instanceof JToolBar) &&
1.63 + NimbusLookAndFeel.resolveToolbarConstraint((JToolBar)c) == BorderLayout.SOUTH;
1.64 ]]></codeSnippet>
1.65 </stateType>
1.66 </stateTypes>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/test/javax/swing/plaf/nimbus/Test6741426.java Thu May 14 18:12:13 2009 +0400
2.3 @@ -0,0 +1,55 @@
2.4 +/*
2.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2.7 + *
2.8 + * This code is free software; you can redistribute it and/or modify it
2.9 + * under the terms of the GNU General Public License version 2 only, as
2.10 + * published by the Free Software Foundation.
2.11 + *
2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2.15 + * version 2 for more details (a copy is included in the LICENSE file that
2.16 + * accompanied this code).
2.17 + *
2.18 + * You should have received a copy of the GNU General Public License version
2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2.21 + *
2.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
2.24 + * have any questions.
2.25 + */
2.26 +
2.27 +/* @test
2.28 + @bug 6741426
2.29 + @summary Tests reusing Nimbus borders across different components (JComboBox border set on a JTextField)
2.30 + @author Peter Zhelezniakov
2.31 + @run main Test6741426
2.32 +*/
2.33 +
2.34 +import com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel;
2.35 +import javax.swing.*;
2.36 +import java.awt.image.BufferedImage;
2.37 +
2.38 +
2.39 +public class Test6741426 implements Runnable {
2.40 +
2.41 + static final int WIDTH = 160;
2.42 + static final int HEIGHT = 80;
2.43 +
2.44 + @Override public void run() {
2.45 + JComboBox cb = new JComboBox();
2.46 + JTextField tf = new JTextField();
2.47 + tf.setBorder(cb.getBorder());
2.48 + BufferedImage img =
2.49 + new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
2.50 + tf.setSize(WIDTH, HEIGHT);
2.51 + tf.paint(img.getGraphics());
2.52 + }
2.53 +
2.54 + public static void main(String[] args) throws Exception {
2.55 + UIManager.setLookAndFeel(new NimbusLookAndFeel());
2.56 + SwingUtilities.invokeAndWait(new Test6741426());
2.57 + }
2.58 +}