Fix weird and not reproductible exception on Scilab close 72/10772/3
Calixte DENIZET [Mon, 11 Mar 2013 10:41:55 +0000 (11:41 +0100)]
Change-Id: Ide2239be5d359ddf40e437aec68ebff1a70b6839

scilab/modules/gui/src/java/org/scilab/modules/gui/utils/WindowsConfigurationManager.java

index 3c9500a..af2b0dc 100644 (file)
@@ -90,43 +90,47 @@ public class WindowsConfigurationManager implements XConfigurationListener {
     private static boolean mustSave = true;
 
     static {
-        if (ScilabConstants.SCIHOME != null && ScilabConstants.SCIHOME.canRead() && ScilabConstants.SCIHOME.canWrite()) {
-            USER_WINDOWS_CONFIG_FILE = ScilabConstants.SCIHOME.toString() + "/windowsConfiguration.xml";
-        } else {
-            USER_WINDOWS_CONFIG_FILE = DEFAULT_WINDOWS_CONFIG_FILE;
-            mustSave = false;
-        }
+        try {
+            if (ScilabConstants.SCIHOME != null && ScilabConstants.SCIHOME.canRead() && ScilabConstants.SCIHOME.canWrite()) {
+                USER_WINDOWS_CONFIG_FILE = ScilabConstants.SCIHOME.toString() + "/windowsConfiguration.xml";
+            } else {
+                USER_WINDOWS_CONFIG_FILE = DEFAULT_WINDOWS_CONFIG_FILE;
+                mustSave = false;
+            }
 
-        new WindowsConfigurationManager();
-        Runnable runnable = new Runnable() {
-            public void run() {
-                if (mustInvalidate) {
-                    File f = new File(USER_WINDOWS_CONFIG_FILE);
-                    if (f.exists() && f.isFile()) {
-                        f.delete();
+            new WindowsConfigurationManager();
+            Runnable runnable = new Runnable() {
+                public void run() {
+                    if (mustInvalidate) {
+                        File f = new File(USER_WINDOWS_CONFIG_FILE);
+                        if (f.exists() && f.isFile()) {
+                            f.delete();
+                        }
                     }
                 }
-            }
-        };
+            };
 
-        try {
             Class scilab = ClassLoader.getSystemClassLoader().loadClass("org.scilab.modules.core.Scilab");
             Method registerFinalHook = scilab.getDeclaredMethod("registerFinalHook", Runnable.class);
             registerFinalHook.invoke(null, runnable);
+
+
+            defaultWinAttributes.put("x", new Integer(DEFAULTX));
+            defaultWinAttributes.put("y", new Integer(DEFAULTY));
+            defaultWinAttributes.put("height", new Integer(DEFAULTHEIGHT));
+            defaultWinAttributes.put("width", new Integer(DEFAULTWIDTH));
+            defaultWinAttributes.put("state", new Integer(SwingScilabWindow.NORMAL));
+            /*
+              Uncomment this code for debugging focus issues
+
+              java.awt.Toolkit.getDefaultToolkit().addAWTEventListener(new java.awt.event.AWTEventListener() {
+              public void eventDispatched(java.awt.AWTEvent e) {
+              System.out.println(e);
+              }
+              }, java.awt.AWTEvent.FOCUS_EVENT_MASK);*/
         } catch (Exception e) {
             System.err.println(e);
         }
-
-        defaultWinAttributes.put("x", new Integer(DEFAULTX));
-        defaultWinAttributes.put("y", new Integer(DEFAULTY));
-        defaultWinAttributes.put("height", new Integer(DEFAULTHEIGHT));
-        defaultWinAttributes.put("width", new Integer(DEFAULTWIDTH));
-        defaultWinAttributes.put("state", new Integer(SwingScilabWindow.NORMAL));
-        /*java.awt.Toolkit.getDefaultToolkit().addAWTEventListener(new java.awt.event.AWTEventListener() {
-          public void eventDispatched(java.awt.AWTEvent e) {
-          System.out.println(e);
-          }
-          }, java.awt.AWTEvent.FOCUS_EVENT_MASK);*/
     }
 
     private WindowsConfigurationManager() {