Formatting
[jalview.git] / src / jalview / io / FileLoader.java
index 34e5886..86c1cf4 100755 (executable)
@@ -1,35 +1,33 @@
 /*\r
-* Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
-*\r
-* This program is free software; you can redistribute it and/or\r
-* modify it under the terms of the GNU General Public License\r
-* as published by the Free Software Foundation; either version 2\r
-* of the License, or (at your option) any later version.\r
-*\r
-* This program is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with this program; if not, write to the Free Software\r
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
-*/\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+ */\r
 \r
 package jalview.io;\r
 \r
-import jalview.gui.AlignFrame;\r
-import jalview.gui.Jalview2XML;\r
-import javax.swing.JOptionPane;\r
+import java.util.*;\r
+\r
+import javax.swing.*;\r
 \r
-import jalview.gui.*;\r
 import jalview.datamodel.*;\r
-import java.util.Vector;\r
-import java.util.StringTokenizer;\r
-import javax.swing.SwingUtilities;\r
+import jalview.gui.*;\r
 \r
-public class FileLoader implements Runnable\r
+public class FileLoader\r
+    implements Runnable\r
 {\r
   String file;\r
   String protocol;\r
@@ -37,14 +35,13 @@ public class FileLoader implements Runnable
   AlignViewport viewport;\r
   AlignFrame alignFrame;\r
 \r
-  public void LoadFile(AlignViewport viewport, String file, String protocol, String format)\r
+  public void LoadFile(AlignViewport viewport, String file, String protocol,\r
+                       String format)\r
   {\r
     this.viewport = viewport;\r
     LoadFile(file, protocol, format);\r
   }\r
 \r
-\r
-\r
   public void LoadFile(String file, String protocol, String format)\r
   {\r
     this.file = file;\r
@@ -62,9 +59,8 @@ public class FileLoader implements Runnable
     });\r
   }\r
 \r
-\r
   public AlignFrame LoadFileWaitTillLoaded(String file, String protocol,\r
-                                                  String format)\r
+                                           String format)\r
   {\r
     this.file = file;\r
     this.protocol = protocol;\r
@@ -86,8 +82,6 @@ public class FileLoader implements Runnable
     return alignFrame;\r
   }\r
 \r
-\r
-\r
   public void updateRecentlyOpened()\r
   {\r
     Vector recent = new Vector();\r
@@ -123,122 +117,130 @@ public class FileLoader implements Runnable
 \r
     jalview.bin.Cache.setProperty(type, newHistory.toString());\r
 \r
-    if(type.equals(FormatAdapter.FILE))\r
+    if (type.equals(FormatAdapter.FILE))\r
+    {\r
       jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format);\r
+    }\r
   }\r
 \r
-    public void run()\r
+  public void run()\r
+  {\r
+    try\r
     {\r
-      try{\r
-        if (Desktop.instance != null)\r
-          Desktop.instance.startLoading(file);\r
+      if (Desktop.instance != null)\r
+      {\r
+        Desktop.instance.startLoading(file);\r
+      }\r
 \r
-        Alignment al = null;\r
+      Alignment al = null;\r
 \r
-        if (format.equalsIgnoreCase("Jalview"))\r
+      if (format.equalsIgnoreCase("Jalview"))\r
+      {\r
+        alignFrame = new Jalview2XML().LoadJalviewAlign(file);\r
+      }\r
+      else\r
+      {\r
+        String error = AppletFormatAdapter.SUPPORTED_FORMATS;\r
+\r
+        if (FormatAdapter.isValidFormat(format))\r
         {\r
-          alignFrame = new Jalview2XML().LoadJalviewAlign(file);\r
+          try\r
+          {\r
+            al = new FormatAdapter().readFile(file, protocol, format);\r
+          }\r
+          catch (java.io.IOException ex)\r
+          {\r
+            error = ex.getMessage();\r
+          }\r
         }\r
-        else\r
-        {\r
-          String error = AppletFormatAdapter.SUPPORTED_FORMATS;\r
 \r
-          if (FormatAdapter.isValidFormat(format))\r
+        if ( (al != null) && (al.getHeight() > 0))\r
+        {\r
+          if (viewport != null)\r
           {\r
-            try\r
+            for (int i = 0; i < al.getHeight(); i++)\r
             {\r
-              al = new FormatAdapter().readFile(file, protocol, format);\r
+              viewport.getAlignment().addSequence(al.getSequenceAt(i));\r
             }\r
-            catch (java.io.IOException ex)\r
-            {\r
-              error = ex.getMessage();\r
-            }\r
-          }\r
+            viewport.firePropertyChange("alignment", null,\r
+                                        viewport.getAlignment().getSequences());\r
 \r
-          if ( (al != null) && (al.getHeight() > 0))\r
+          }\r
+          else\r
           {\r
-            if (viewport != null)\r
-            {\r
-              for (int i = 0; i < al.getHeight(); i++)\r
-              {\r
-                viewport.getAlignment().addSequence(al.getSequenceAt(i));\r
-              }\r
-              viewport.firePropertyChange("alignment", null,\r
-                                          viewport.getAlignment().getSequences());\r
+            alignFrame = new AlignFrame(al,\r
+                                        AlignFrame.DEFAULT_WIDTH,\r
+                                        AlignFrame.DEFAULT_HEIGHT);\r
+\r
+            alignFrame.statusBar.setText("Successfully loaded file " + file);\r
+            alignFrame.setFileName(file, format);\r
+\r
+            Desktop.addInternalFrame(alignFrame, file,\r
+                                     AlignFrame.DEFAULT_WIDTH,\r
+                                     AlignFrame.DEFAULT_HEIGHT);\r
 \r
+            try\r
+            {\r
+              alignFrame.setMaximum(jalview.bin.Cache.getDefault(\r
+                  "SHOW_FULLSCREEN", false));\r
             }\r
-            else\r
+            catch (java.beans.PropertyVetoException ex)\r
             {\r
-              alignFrame = new AlignFrame(al,\r
-                                           AlignFrame.DEFAULT_WIDTH,\r
-                                           AlignFrame.DEFAULT_HEIGHT);\r
-\r
-              alignFrame.statusBar.setText("Successfully loaded file " + file);\r
-              alignFrame.setFileName(file, format);\r
-\r
-\r
-              Desktop.addInternalFrame(alignFrame, file,\r
-                                       AlignFrame.DEFAULT_WIDTH,\r
-                                       AlignFrame.DEFAULT_HEIGHT);\r
-\r
-              try\r
-              {\r
-               alignFrame.setMaximum(jalview.bin.Cache.getDefault(\r
-                   "SHOW_FULLSCREEN", false));\r
-              }\r
-              catch (java.beans.PropertyVetoException ex)\r
-              {\r
-              }\r
             }\r
           }\r
-          else\r
+        }\r
+        else\r
+        {\r
+          if (Desktop.instance != null)\r
           {\r
-            if (Desktop.instance != null)\r
-              Desktop.instance.stopLoading();\r
+            Desktop.instance.stopLoading();\r
+          }\r
 \r
-            final String errorMessage = "Couldn't load file " + file + "\n" +\r
-                error;\r
+          final String errorMessage = "Couldn't load file " + file + "\n" +\r
+              error;\r
 \r
-            javax.swing.SwingUtilities.invokeLater(new Runnable()\r
+          javax.swing.SwingUtilities.invokeLater(new Runnable()\r
+          {\r
+            public void run()\r
             {\r
-              public void run()\r
-              {\r
-                JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
-                    errorMessage,\r
-                    "Error loading file",\r
-                    JOptionPane.WARNING_MESSAGE);\r
-              }\r
-            });\r
-          }\r
+              JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+                  errorMessage,\r
+                  "Error loading file",\r
+                  JOptionPane.WARNING_MESSAGE);\r
+            }\r
+          });\r
         }\r
+      }\r
 \r
-         updateRecentlyOpened();\r
+      updateRecentlyOpened();\r
 \r
-      }\r
-      catch (OutOfMemoryError er)\r
-      {\r
+    }\r
+    catch (OutOfMemoryError er)\r
+    {\r
 \r
-        er.printStackTrace();\r
-        alignFrame = null;\r
+      er.printStackTrace();\r
+      alignFrame = null;\r
 \r
-        javax.swing.SwingUtilities.invokeLater(new Runnable()\r
+      javax.swing.SwingUtilities.invokeLater(new Runnable()\r
+      {\r
+        public void run()\r
         {\r
-          public void run()\r
-          {\r
-            javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
-                "Out of memory loading file "+file+"!!"\r
-                +\r
-                "\nSee help files for increasing Java Virtual Machine memory."\r
-                , "Out of memory",\r
-                javax.swing.JOptionPane.WARNING_MESSAGE);\r
-          }\r
-        });\r
-      }\r
-\r
-     System.gc();\r
-     if (Desktop.instance != null)\r
-        Desktop.instance.stopLoading();\r
+          javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+              "Out of memory loading file " + file + "!!"\r
+              +\r
+              "\nSee help files for increasing Java Virtual Machine memory."\r
+              , "Out of memory",\r
+              javax.swing.JOptionPane.WARNING_MESSAGE);\r
+        }\r
+      });\r
+    }\r
 \r
+    System.gc();\r
+    if (Desktop.instance != null)\r
+    {\r
+      Desktop.instance.stopLoading();\r
     }\r
 \r
+  }\r
+\r
 }\r