JAL-1067, JAL-1105 - refactor parser to fit Jalview's data parsing architecture
[jalview.git] / src / jalview / appletgui / AlignFrame.java
index efb0f4c..e03f2f4 100644 (file)
@@ -3718,16 +3718,18 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,  ItemLis
   /**\r
    * Load the (T-Coffee) score file from the specified url \r
    * \r
-   * @param url The absolute path from where download and read the score file\r
+   * @param source File/URL/T-COFFEE score file contents\r
    * @throws IOException \r
+   * @return true if alignment was annotated with data from source\r
    */\r
-  public void loadScoreFile( URL url ) throws IOException {\r
-         // TODO: refactor to string/standard jalview data importer\r
-         TCoffeeScoreFile file = TCoffeeScoreFile.load( new InputStreamReader( url.openStream() ) );\r
-         if( file == null ) {\r
-        // TODO: raise a dialog box here rather than bomb out.\r
-            \r
-                 throw new RuntimeException("The file provided does not match the T-Coffee scores file format");\r
+  public boolean loadScoreFile( String source ) throws IOException {\r
+\r
+    TCoffeeScoreFile file = new TCoffeeScoreFile(source, AppletFormatAdapter.checkProtocol(source));\r
+         if( !file.isValid()) {\r
+           // TODO: raise dialog for gui\r
+           System.err.println("Problems parsing T-Coffee scores: "+file.getWarningMessage());\r
+           System.err.println("Origin was:\n"+source);\r
+           return false;\r
          }\r
          \r
          /*\r
@@ -3736,17 +3738,25 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,  ItemLis
          AlignmentI aln; \r
          if( (aln=viewport.getAlignment()) != null && (aln.getHeight() != file.getHeight() || aln.getWidth() != file.getWidth()) ) {\r
            // TODO: raise a dialog box here rather than bomb out.\r
-           throw new RuntimeException("The scores matrix does not match the alignment dimensions");\r
+           System.err.println("The scores matrix does not match the alignment dimensions");\r
                  \r
          }\r
          \r
           // TODO add parameter to indicate if matching should be done\r
          if (file.annotateAlignment(alignPanel.getAlignment(), false))\r
          {\r
-                 tcoffeeColour.setEnabled(true);\r
+           alignPanel.fontChanged();\r
+           tcoffeeColour.setEnabled(true);\r
                  // switch to this color\r
                  changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));\r
+                 return true;\r
+          } else {\r
+            System.err.println("Problems resolving T-Coffee scores:");\r
+            if (file.getWarningMessage()!=null) {\r
+              System.err.println(file.getWarningMessage());\r
+            }\r
           }\r
+         return false;\r
   }\r
   \r
   \r