[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [albireo-dev] AwtEnvironment & customizability

Hi Gordon,

> I'm no GTK expert, and I didn't spend a lot of time on this. Here's the 
> reasoning... The primary distribution of Eclipse on Linux is GTK-based, 
> even if you are running on KDE (i.e. there is no Qt version of SWT). So 
> I concluded that the GTK look and feel would be a closer match, even 
> when running under a KDE window manager.

This is all right in principle. The only problem is that it leads to bad
results in the KDE case.

> >>> /opt/gnome/share/themes/Qt/gtk-2.0/gtkrc:5: Engine "qtengine" is unsupported, ignoring
> >> I've seen this message before, and it depends on the window manager
> >> used, but there's nothing (reasonable) we can do to detect this situation.

Well, I dug a bit and found that the System.err output is a sufficient
indicator of this situation. I turn this System.err output into an exception,
and the rest is easy.

I've renamed the constant from
   LAFChoiceNativeSystemForceGtk
to LAFChoiceNativeSystemPreferGtk,
to match what it now does.

Bruno


Index: src/org/eclipse/albireo/core/LookAndFeelHandler.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.albireo/org.eclipse.albireo.core/src/org/eclipse/albireo/core/LookAndFeelHandler.java,v
retrieving revision 1.3
diff -c -3 -r1.3 LookAndFeelHandler.java
*** src/org/eclipse/albireo/core/LookAndFeelHandler.java	25 Jan 2008 21:17:39 -0000	1.3
--- src/org/eclipse/albireo/core/LookAndFeelHandler.java	1 Feb 2008 19:14:48 -0000
***************
*** 12,17 ****
--- 12,18 ----
  package org.eclipse.albireo.core;
  
  import java.awt.EventQueue;
+ import java.io.PrintStream;
  
  import javax.swing.UIManager;
  import javax.swing.UnsupportedLookAndFeelException;
***************
*** 55,65 ****
       * This look&feel choice denotes the Swing look&feel
       * that best approximates the system look&feel, except that
       * the Gtk look&feel is used instead of the cross-platform
!      * look&feel if SWT is based on Gtk.
       * (This typically affects Linux systems with KDE desktop.)
       * It is platform dependent.
       */
!     public static final String LAFChoiceNativeSystemForceGtk = "swing.systemlaf+gtk";
  
      /**
       * This look&feel choice denotes the Swing look&feel
--- 56,66 ----
       * This look&feel choice denotes the Swing look&feel
       * that best approximates the system look&feel, except that
       * the Gtk look&feel is used instead of the cross-platform
!      * look&feel if SWT is based on Gtk and if it works fine.
       * (This typically affects Linux systems with KDE desktop.)
       * It is platform dependent.
       */
!     public static final String LAFChoiceNativeSystemPreferGtk = "swing.systemlaf+gtk";
  
      /**
       * This look&feel choice denotes the Swing look&feel
***************
*** 81,89 ****
                || javaVersion.startsWith("1.5"))) {
              lafChoice = LAFChoiceNativeSystemNoGtk;
          } else {
!             // Gordon prefers LAFChoiceNativeSystemForceGtk here.
!             // Bruno prefers LAFChoiceNativeSystem here.
!             lafChoice = LAFChoiceNativeSystemForceGtk;
          }
      }
  
--- 82,92 ----
                || javaVersion.startsWith("1.5"))) {
              lafChoice = LAFChoiceNativeSystemNoGtk;
          } else {
!             // Set the default to LAFChoiceNativeSystemPreferGtk, so that on
!             // Unix systems with a GNOME desktop and with themes supported by
!             // the Swing Gtk look&feel this Gtk look&feel is used; it resembles
!             // the system look&feel more closely than Metal or Nimbus.
!             lafChoice = LAFChoiceNativeSystemPreferGtk;
          }
      }
  
***************
*** 107,113 ****
       *               {@link #LAFChoiceSwingDefault},
       *               {@link #LAFChoiceCrossPlatform},
       *               {@link #LAFChoiceNativeSystem},
!      *               {@link #LAFChoiceNativeSystemForceGtk},
       *               {@link #LAFChoiceNativeSystemNoGtk}.
       */
      public void setLAFChoice(String choice) {
--- 110,116 ----
       *               {@link #LAFChoiceSwingDefault},
       *               {@link #LAFChoiceCrossPlatform},
       *               {@link #LAFChoiceNativeSystem},
!      *               {@link #LAFChoiceNativeSystemPreferGtk},
       *               {@link #LAFChoiceNativeSystemNoGtk}.
       */
      public void setLAFChoice(String choice) {
***************
*** 143,153 ****
              laf = UIManager.getCrossPlatformLookAndFeelClassName();
          } else if (LAFChoiceNativeSystem.equals(laf)) {
              laf = UIManager.getSystemLookAndFeelClassName();
!         } else if (LAFChoiceNativeSystemForceGtk.equals(laf)) {
              laf = UIManager.getSystemLookAndFeelClassName();
              if (Platform.isGtk()
                  && laf.equals(UIManager.getCrossPlatformLookAndFeelClassName())) {
!                 laf = GTK_LOOK_AND_FEEL_NAME;
              }
          } else if (LAFChoiceNativeSystemNoGtk.equals(laf)) {
              laf = UIManager.getSystemLookAndFeelClassName();
--- 146,165 ----
              laf = UIManager.getCrossPlatformLookAndFeelClassName();
          } else if (LAFChoiceNativeSystem.equals(laf)) {
              laf = UIManager.getSystemLookAndFeelClassName();
!         } else if (LAFChoiceNativeSystemPreferGtk.equals(laf)) {
              laf = UIManager.getSystemLookAndFeelClassName();
              if (Platform.isGtk()
                  && laf.equals(UIManager.getCrossPlatformLookAndFeelClassName())) {
!                 // Try the Gtk look&feel.
!                 try {
!                     doSetLookAndFeel(GTK_LOOK_AND_FEEL_NAME);
!                     return;
!                 } catch (ClassNotFoundException e) {
!                 } catch (InstantiationException e) {
!                 } catch (IllegalAccessException e) {
!                 } catch (UnsupportedLookAndFeelException e) {
!                 }
!                 // Second try: Use getSystemLookAndFeelClassName().
              }
          } else if (LAFChoiceNativeSystemNoGtk.equals(laf)) {
              laf = UIManager.getSystemLookAndFeelClassName();
***************
*** 155,161 ****
                  laf = UIManager.getCrossPlatformLookAndFeelClassName();
          }
  
!         UIManager.setLookAndFeel(laf);
      }
  
      // ========================================================================
--- 167,221 ----
                  laf = UIManager.getCrossPlatformLookAndFeelClassName();
          }
  
!         doSetLookAndFeel(laf);
!     }
! 
!     private static void doSetLookAndFeel(String laf)
!         throws ClassNotFoundException,
!                InstantiationException,
!                IllegalAccessException,
!                UnsupportedLookAndFeelException {
!         // Although UIManager.setLookAndFeel is specified to throw an
!         // UnsupportedLookAndFeelException when the look&feel is not supported,
!         // the com.sun.java.swing.plaf.gtk.GTKParser of JDK 1.5.0 reports
!         // failures by doing System.err.println() and instead sets an unthemed
!         // Gtk look&feel, which is very ugly.
!         // Typically this happens on Linux systems with KDE desktop. The
!         // $HOME/.gtkrc-2.0 file created by the KDE control center refers to
!         // /opt/gnome/share/themes/Qt/gtk-2.0/gtkrc, which specifies a theming
!         // engine "qtengine", which exists in C++ code but not in the
!         // com.sun.java.swing.plaf.gtk mockup. The error message in this case
!         // reads:
!         // "/opt/gnome/share/themes/Qt/gtk-2.0/gtkrc:5: Engine "qtengine" is unsupported, ignoring"
!         PrintStream origSystemErr = System.err;
!         try {
!             System.setErr(
!                 new PrintStream(origSystemErr) {
!                     public void print(String s) {
!                         throw new UnsupportedLookAndFeelRuntimeException(s);
!                     }
!                     public void println(String s) {
!                         throw new UnsupportedLookAndFeelRuntimeException(s);
!                     }
!                 });
!             UIManager.setLookAndFeel(laf);
!         } catch (UnsupportedLookAndFeelRuntimeException e) {
!             UnsupportedLookAndFeelException newExc =
!                 new UnsupportedLookAndFeelException(e.getMessage());
!             newExc.initCause(e);
!             throw newExc;
!         } finally {
!             System.setErr(origSystemErr);
!         }
!     }
! 
!     /**
!      * This exception signals an unsupported look&feel.
!      */
!     static class UnsupportedLookAndFeelRuntimeException extends RuntimeException {
!         UnsupportedLookAndFeelRuntimeException(String message) {
!             super(message);
!         }
      }
  
      // ========================================================================