Author: jm
Date: 2012-08-14 12:38:20 -0700 (Tue, 14 Aug 2012)
New Revision: 30189

Modified:
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/CytoscapeDesktop.java
Log:
Fixes #1358: Look-and-feel is now set prior to the construction of Swing 
widgets.  Some widgets don't like having their look-and-feel changed after 
construction.

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
       2012-08-14 19:12:31 UTC (rev 30188)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
       2012-08-14 19:38:20 UTC (rev 30189)
@@ -48,6 +48,9 @@
 
 import java.util.Properties;
 
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+
 import org.cytoscape.application.CyApplicationConfiguration;
 import org.cytoscape.application.CyApplicationManager;
 import org.cytoscape.application.CyShutdown;
@@ -130,6 +133,8 @@
 import org.cytoscape.work.swing.undo.SwingUndoSupport;
 import org.cytoscape.command.AvailableCommands;
 import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  *
@@ -146,6 +151,7 @@
 
        @Override
        public void start(BundleContext bc) throws Exception {
+               setLookAndFeel();
                
                RenderingEngineManager renderingEngineManagerServiceRef = 
getService(bc, RenderingEngineManager.class);
                CyShutdown cytoscapeShutdownServiceRef = getService(bc, 
CyShutdown.class);
@@ -462,6 +468,31 @@
                
        }
 
+       private void setLookAndFeel() {
+               Logger logger = LoggerFactory.getLogger(getClass());
+               String lookAndFeel;
+               // update look and feel
+               if (System.getProperty("os.name").startsWith("Mac OS X") ||
+                   System.getProperty("os.name").startsWith("Windows"))
+                       lookAndFeel = UIManager.getSystemLookAndFeelClassName();
+               else {
+                       // Use Nimbus on Unix systems
+                       lookAndFeel = 
"com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel";
+               }
+               try {
+                       logger.debug("setting look and feel to: " + 
lookAndFeel);
+                       UIManager.setLookAndFeel(lookAndFeel);
+               } catch (ClassNotFoundException e) {
+                       logger.error("Unexpected error", e);
+               } catch (InstantiationException e) {
+                       logger.error("Unexpected error", e);
+               } catch (IllegalAccessException e) {
+                       logger.error("Unexpected error", e);
+               } catch (UnsupportedLookAndFeelException e) {
+                       logger.error("Unexpected error", e);
+               }
+       }
+
        private boolean isMac() {
                return System.getProperty("os.name").startsWith("Mac OS X");
        }

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/CytoscapeDesktop.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/CytoscapeDesktop.java
     2012-08-14 19:12:31 UTC (rev 30188)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/CytoscapeDesktop.java
     2012-08-14 19:38:20 UTC (rev 30189)
@@ -48,6 +48,7 @@
 import javax.swing.JToolBar;
 import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
 import javax.swing.WindowConstants;
 
 import org.cytoscape.application.CyShutdown;
@@ -158,22 +159,6 @@
 
                setJMenuBar(cyMenus.getJMenuBar());
 
-               // update look and feel
-               try {
-                       String laf = null;
-                       if (System.getProperty("os.name").startsWith("Mac OS 
X") ||
-                           System.getProperty("os.name").startsWith("Windows"))
-                               laf = UIManager.getSystemLookAndFeelClassName();
-                       else {
-                               // Use Nimbus on Unix systems
-                               laf = 
"com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel";
-                       }
-
-                       logger.debug("setting look and feel to: " + laf);
-                       UIManager.setLookAndFeel(laf);
-                       SwingUtilities.updateComponentTreeUI(this);
-               } catch (Exception e) { /* not really a problem if this fails 
*/ }
-               
                if(System.getProperty("os.name").startsWith("Mac OS X")) {
                        // Enable full screen mode for 10.7+
                        FullScreenUtilities.setWindowCanFullScreen(this, true);

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to