changeset 59736:75dd1b241671

8222759: com.sun.java.swing.plaf.gtk.GTKLookAndFeel has unnecessary casts to GTKStyleFactory Reviewed-by: prr, jdv
author pbansal
date Mon, 23 Dec 2019 13:04:07 +0530
parents 747c05277fd7
children 34f4782c0850
files src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java test/jdk/javax/swing/plaf/gtk/TestCustomStyleFactory.java
diffstat 2 files changed, 76 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java	Thu Dec 19 15:36:40 2019 -0800
+++ b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java	Mon Dec 23 13:04:07 2019 +0530
@@ -312,7 +312,7 @@
             "com.sun.java.swing.plaf.gtk.GTKPainter$ListTableFocusBorder",
             "getNoFocusCellBorder");
 
-        GTKStyleFactory factory = (GTKStyleFactory)getStyleFactory();
+        SynthStyleFactory factory = getStyleFactory();
         GTKStyle tableStyle = (GTKStyle)factory.getStyle(null, Region.TREE);
         Color tableBg = tableStyle.getGTKColor(SynthConstants.ENABLED,
                 GTKColorType.TEXT_BACKGROUND);
@@ -505,7 +505,7 @@
                 this.region = region;
             }
             public Object createValue(UIDefaults table) {
-                GTKStyleFactory factory = (GTKStyleFactory)getStyleFactory();
+                SynthStyleFactory factory = getStyleFactory();
                 GTKStyle style = (GTKStyle)factory.getStyle(null, region);
                 return style.getDefaultFont();
             }
@@ -1305,7 +1305,7 @@
     }
 
     protected void initSystemColorDefaults(UIDefaults table) {
-        GTKStyleFactory factory = (GTKStyleFactory)getStyleFactory();
+        SynthStyleFactory factory = getStyleFactory();
         GTKStyle windowStyle =
                 (GTKStyle)factory.getStyle(null, Region.INTERNAL_FRAME);
         table.put("window", windowStyle.getGTKColor(SynthConstants.ENABLED,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/swing/plaf/gtk/TestCustomStyleFactory.java	Mon Dec 23 13:04:07 2019 +0530
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @key headful
+ * @bug 8222759
+ * @requires (os.family == "linux")
+ * @summary Tests if a custom style factory can be used in GTKL&F after
+ *  removing unnecessary casts
+ * @run main TestCustomStyleFactory
+ */
+
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+import javax.swing.plaf.synth.Region;
+import javax.swing.plaf.synth.SynthLookAndFeel;
+import javax.swing.plaf.synth.SynthStyleFactory;
+import javax.swing.plaf.synth.SynthStyle;
+
+public class TestCustomStyleFactory {
+    private static final String GTK_LAF_CLASS = "GTKLookAndFeel";
+
+    public static void main(String args[]) throws Exception {
+        if (!System.getProperty("os.name").startsWith("Linux")) {
+            System.out.println("This test is meant for Linux platform only");
+            return;
+        }
+
+        for (UIManager.LookAndFeelInfo lookAndFeelInfo :
+                UIManager.getInstalledLookAndFeels()) {
+            if (lookAndFeelInfo.getClassName().contains(GTK_LAF_CLASS)) {
+                try {
+                    UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());
+                } catch (final UnsupportedLookAndFeelException ignored) {
+                    System.out.println("GTK L&F could not be set, so this " +
+                            "test can not be run in this scenario ");
+                    return;
+                }
+            }
+        }
+        final SynthStyleFactory original = SynthLookAndFeel.getStyleFactory();
+        SynthLookAndFeel.setStyleFactory(new SynthStyleFactory() {
+            @Override
+            public SynthStyle getStyle(JComponent c, Region id) {
+                return original.getStyle(c, id);
+            }
+        });
+        new JLabel("test");
+    }
+}