[icedtea-web] RFC: PR857: Don't set look and feel multiple times

Omair Majid omajid at redhat.com
Fri Feb 28 15:07:10 PST 2014


Hi,

The attached patch is a fix for PR857. The idea is quite simple: make
sure UIManager.setLookAndFeel() is called at most once (and ideally
exactly once) before any UI is shown.

There are a few code paths that can cause UIManager.setLookAndFell to be
invoked multiple times:

- AboutDialog (only on entry from a class other than Boot)
- SecurityDialog
- PolicyEditor (only on entry from ControlPanel)

CertificateViewer calls JNLPRuntime.initialize() which already calls
UIManager.setLookAndFeel. So I have removed the direct call from
CertificateViewer.

Also, JNLPRuntime.initialize currently calls setLookAndFeel after
displaying a JavaConsole. This is alos fixed.

Thoughts?

Thanks,
Omair

-- 
PGP Key: 66484681 (http://pgp.mit.edu/)
Fingerprint = F072 555B 0A17 3957 4E95  0056 F286 F14F 6648 4681
-------------- next part --------------
diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2014-02-28  Omair Majid  <omajid at redhat.com>
+
+	PR857
+	* netx/net/sourceforge/jnlp/about/AboutDialog.java
+	(run): Do not set look and feel.
+	* netx/net/sourceforge/jnlp/runtime/Boot.java
+	(main) <about>: Set look and feel before displaying dialog.
+	* netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java
+	(initialize): Set look and feel before any UI is created.
+	* netx/net/sourceforge/jnlp/security/SecurityDialog.java
+	(init): Do not set look and feel.
+	(setSystemLookAndFeel): Removed.
+	* netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
+	(createInstance): Do not set look and feel.
+	* netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java
+	(showCertificateViewer): Do not set look and feel.
+	(setSystemLookAndFeel): Removed.
+
+
 2014-02-28  Omair Majid  <omajid at redhat.com>
 
 	PR1676
diff --git a/netx/net/sourceforge/jnlp/about/AboutDialog.java b/netx/net/sourceforge/jnlp/about/AboutDialog.java
--- a/netx/net/sourceforge/jnlp/about/AboutDialog.java
+++ b/netx/net/sourceforge/jnlp/about/AboutDialog.java
@@ -175,11 +175,6 @@
 
     @Override
     public void run() {
-        try {
-            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
-        } catch (Exception e) {
-        }
-
         layoutWindow();
         ScreenFinder.centerWindowsToCurrentScreen(frame);
         frame.setVisible(true);
diff --git a/netx/net/sourceforge/jnlp/runtime/Boot.java b/netx/net/sourceforge/jnlp/runtime/Boot.java
--- a/netx/net/sourceforge/jnlp/runtime/Boot.java
+++ b/netx/net/sourceforge/jnlp/runtime/Boot.java
@@ -28,6 +28,8 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.swing.UIManager;
+
 import net.sourceforge.jnlp.LaunchException;
 import net.sourceforge.jnlp.Launcher;
 import net.sourceforge.jnlp.ParserSettings;
@@ -161,6 +163,11 @@
             if (null != getOption("-headless")) {
                 JNLPRuntime.exit(0);
             } else {
+                try {
+                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+                } catch (Exception e) {
+                    // if it fails, not a problem
+                }
                 OutputController.getLogger().printOutLn(R("BLaunchAbout"));
                 AboutDialog.display();
                 return;
diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java
--- a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java
+++ b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java
@@ -192,6 +192,12 @@
     public static void initialize(boolean isApplication) throws IllegalStateException {
         checkInitialized();
 
+        try {
+            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+        } catch (Exception e) {
+            OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e);
+        }
+
         if (JavaConsole.canShowOnStartup(isApplication)) {
             JavaConsole.getConsole().showConsoleLater();
         }
@@ -233,12 +239,6 @@
         policy = new JNLPPolicy();
         security = new JNLPSecurityManager(); // side effect: create JWindow
 
-        try {
-            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
-        } catch (Exception e) {
-            OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e);
-        }
-
         doMainAppContextHacks();
 
         if (securityEnabled) {
diff --git a/netx/net/sourceforge/jnlp/security/SecurityDialog.java b/netx/net/sourceforge/jnlp/security/SecurityDialog.java
--- a/netx/net/sourceforge/jnlp/security/SecurityDialog.java
+++ b/netx/net/sourceforge/jnlp/security/SecurityDialog.java
@@ -216,8 +216,6 @@
     }
 
     private void initDialog() {
-        setSystemLookAndFeel();
-
         String dialogTitle = "";
         if (dialogType == DialogType.CERT_WARNING) {
             if (accessType == AccessType.VERIFIED)
@@ -346,17 +344,6 @@
         super.dispose();
     }
 
-    /**
-     * Updates the look and feel of the window to be the system look and feel
-     */
-    protected void setSystemLookAndFeel() {
-        try {
-            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
-        } catch (Exception e) {
-            //don't worry if we can't.
-        }
-    }
-
     private final List<ActionListener> listeners = new CopyOnWriteArrayList<ActionListener>();
 
     /**
diff --git a/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java b/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
--- a/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
+++ b/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
@@ -917,11 +917,6 @@
     }
 
     public static PolicyEditor createInstance(final String filepath) {
-        try {
-            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
-        } catch (final Exception e) {
-            // not really important, so just ignore
-        }
         return new PolicyEditor(filepath);
     }
 
diff --git a/netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java b/netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java
--- a/netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java
+++ b/netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java
@@ -100,7 +100,6 @@
 
     public static void showCertificateViewer() throws Exception {
         JNLPRuntime.initialize(true);
-        setSystemLookAndFeel();
 
         CertificateViewer cv = new CertificateViewer();
         cv.setResizable(true);
@@ -109,14 +108,6 @@
         cv.dispose();
     }
 
-    private static void setSystemLookAndFeel() {
-        try {
-            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
-        } catch (Exception e) {
-            // don't worry if we can't.
-        }
-    }
-
     public static void main(String[] args) throws Exception {
         CertificateViewer.showCertificateViewer();
     }


More information about the distro-pkg-dev mailing list