Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8222759

com.sun.java.swing.plaf.gtk.GTKLookAndFeel has unnecessary casts to GTKStyleFactory

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b07
    • CPU:
      x86_64
    • OS:
      linux

      Description

      ADDITIONAL SYSTEM INFORMATION :
      JDK 1.8.0.202

      A DESCRIPTION OF THE PROBLEM :
      In com.sun.java.swing.plaf.gtk.GTKLookAndFeel there are unneccessary casts of javax.swing.plaf.synth.SynthStyleFactory to com.sun.java.swing.plaf.gtk.GTKStyleFactory, for example in the inner class FontLazyValue.

      This breaks applications, which change the style factory. For example, IntelliJ uses the following UI tweak:

                  if (!UIUtil.isUnderGTKLookAndFeel()) return;

                  final SynthStyleFactory original = SynthLookAndFeel.getStyleFactory();

                  SynthLookAndFeel.setStyleFactory(new SynthStyleFactory() {
                    @Override
                    public SynthStyle getStyle(final JComponent c, final Region id) {
                      final SynthStyle style = original.getStyle(c, id);
                      if (id == Region.POPUP_MENU) {
                        final Integer x = ReflectionUtil.getField(style.getClass(), style, int.class, "xThickness");
                        if (x != null && x == 0) {
                          ReflectionUtil.setField(style.getClass(), style, int.class, "xThickness", 1);
                          ReflectionUtil.setField(style.getClass(), style, int.class, "yThickness", 3);
                        }
                      }
                      return style;
                    }
                  });
              
                  new JPopupMenu(); // invokes updateUI() -> updateStyle()
              
                  SynthLookAndFeel.setStyleFactory(original);

      Because the only called method #getStyle is present in the base class SynthStyleFactory, the cast to GTKStyleFactory is unneccessary.

      Instead of

                  public Object createValue(UIDefaults table) {
                      GTKStyleFactory factory = (GTKStyleFactory)getStyleFactory();
                      GTKStyle style = (GTKStyle)factory.getStyle(null, region);
                      return style.getDefaultFont();
                  }


      you can simply write:

                  public Object createValue(UIDefaults table) {
                      SynthStyleFactory factory = getStyleFactory();
                      GTKStyle style = (GTKStyle)factory.getStyle(null, region);
                      return style.getDefaultFont();
                  }

      REGRESSION : Last worked in version 8u202

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      see above

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      see above

      ---------- BEGIN SOURCE ----------
      see above
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            pbansal Pankaj Bansal
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: