Merge branch 'develop' into trialMerge
[jalview.git] / src / jalview / gui / CutAndPasteTransfer.java
index ed2b9bf..ca79a83 100644 (file)
@@ -30,8 +30,11 @@ import jalview.bin.Jalview;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.SequenceI;
+import jalview.io.AlignmentFileI;
 import jalview.io.AppletFormatAdapter;
-import jalview.io.FileParse;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormatException;
+import jalview.io.FileFormatI;
 import jalview.io.FormatAdapter;
 import jalview.io.IdentifyFile;
 import jalview.io.JalviewFileChooser;
@@ -68,7 +71,7 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer
 
   AlignViewportI viewport;
 
-  FileParse source = null;
+  AlignmentFileI source = null;
 
   public CutAndPasteTransfer()
   {
@@ -213,14 +216,21 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer
       return;
     }
 
-    String format = new IdentifyFile().identify(text, "Paste");
-    if (format == null || format.equalsIgnoreCase("EMPTY DATA FILE"))
+    FileFormatI format = null;
+    try
+    {
+      format = new IdentifyFile().identify(text, DataSourceType.PASTE);
+    } catch (FileFormatException e1)
+    {
+      // leave as null
+    }
+    if (format == null)
     {
       System.err.println(MessageManager
               .getString("label.couldnt_read_data"));
       if (!Jalview.isHeadlessMode())
       {
-        javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
+        JOptionPane.showInternalMessageDialog(Desktop.desktop,
                 AppletFormatAdapter.SUPPORTED_FORMATS,
                 MessageManager.getString("label.couldnt_read_data"),
                 JOptionPane.WARNING_MESSAGE);
@@ -231,29 +241,26 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer
     // TODO: identify feature, annotation or tree file and parse appropriately.
     AlignmentI al = null;
 
-    if (FormatAdapter.isValidFormat(format))
+    try
     {
-      try
-      {
-        FormatAdapter fa = new FormatAdapter(alignpanel);
-        al = fa.readFile(getText(), "Paste", format);
-        source = fa.getAlignFile();
+      FormatAdapter fa = new FormatAdapter(alignpanel);
+      al = fa.readFile(getText(), DataSourceType.PASTE, format);
+      source = fa.getAlignFile();
 
-      } catch (java.io.IOException ex)
-      {
-        JOptionPane.showInternalMessageDialog(Desktop.desktop,
-                MessageManager.formatMessage(
-                        "label.couldnt_read_pasted_text",
-                        new String[] { ex.toString() }), MessageManager
-                        .getString("label.error_parsing_text"),
-                JOptionPane.WARNING_MESSAGE);
-      }
+    } catch (java.io.IOException ex)
+    {
+      JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
+              .formatMessage("label.couldnt_read_pasted_text", new String[]
+              { ex.toString() }), MessageManager
+              .getString("label.error_parsing_text"),
+              JOptionPane.WARNING_MESSAGE);
     }
 
     if (al != null && al.hasValidSequence())
     {
       String title = MessageManager.formatMessage(
-              "label.input_cut_paste_params", new String[] { format });
+              "label.input_cut_paste_params",
+              new String[] { format.toString() });
       FeatureSettingsModelI proxyColourScheme = source
               .getFeatureColourScheme();