On 'save' menu entry check to see if fileformat is a valid output format and open...
[jalview.git] / src / jalview / gui / AlignFrame.java
index 289ffbc..72691cc 100755 (executable)
@@ -160,7 +160,12 @@ public class AlignFrame
    addKeyListener();
 
   }
-
+  /**
+   * Change the filename and format for the alignment, and
+   * enable the 'reload' button functionality.
+   * @param file valid filename
+   * @param format format of file
+   */
   public void setFileName(String file, String format)
   {
      fileName = file;
@@ -683,7 +688,7 @@ public class AlignFrame
   public void save_actionPerformed(ActionEvent e)
   {
     if(fileName==null
-       || currentFileFormat==null
+       || (currentFileFormat==null || jalview.io.AppletFormatAdapter.isValidFormat(currentFileFormat, true))
        || fileName.startsWith("http")
         )
     {
@@ -765,8 +770,18 @@ public class AlignFrame
 
     }
     else
-    {
-
+    {        
+      if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
+      {
+        // JBPNote need to have a raise_gui flag here
+        JOptionPane.showInternalMessageDialog(
+                this, "Cannot save file " + fileName + " using format "+format,
+                "Alignment output format not supported",
+                JOptionPane.WARNING_MESSAGE);
+        saveAs_actionPerformed(null);
+        return false;
+      }
+        
       String[] omitHidden = null;
 
       if (viewport.hasHiddenColumns)
@@ -783,7 +798,6 @@ public class AlignFrame
       }
       }
       FormatAdapter f = new FormatAdapter();
-
       String output = f.formatSequences(
           format,
           (Alignment) viewport.alignment, // class cast exceptions will occur in the distant future
@@ -1442,9 +1456,9 @@ public class AlignFrame
   }
 
   /**
-   * DOCUMENT ME!
+   * Paste contents of Jalview clipboard
    *
-   * @param newAlignment DOCUMENT ME!
+   * @param newAlignment true to paste to a new alignment, otherwise add to this.
    */
   void paste(boolean newAlignment)
   {
@@ -2866,7 +2880,7 @@ public class AlignFrame
   {
     SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
     AlignmentSorter.sortByPID(viewport.getAlignment(),
-                              viewport.getAlignment().getSequenceAt(0));
+                              viewport.getAlignment().getSequenceAt(0), null);
     addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
                                     viewport.alignment));
     alignPanel.paintAlignment(true);
@@ -3129,7 +3143,7 @@ public class AlignFrame
       public void actionPerformed(ActionEvent e)
       {
         SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
-        AlignmentSorter.sortByAnnotationScore(scoreLabel, viewport.getAlignment());
+        AlignmentSorter.sortByAnnotationScore(scoreLabel, viewport.getAlignment());//,viewport.getSelectionGroup());
         addHistoryItem(new OrderCommand("Sort by "+scoreLabel, oldOrder, viewport.alignment));
         alignPanel.paintAlignment(true);
       }
@@ -3974,7 +3988,7 @@ public void drop(DropTargetDropEvent evt)
   protected void extractScores_actionPerformed(ActionEvent e)
   {
     ParseProperties pp = new jalview.analysis.ParseProperties(viewport.alignment);
-    if (pp.getScoresFromDescription("col", "score column ", "\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)")>0)
+    if (pp.getScoresFromDescription("col", "score column ", "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)", true)>0)
     {
       buildSortByAnnotationScoresMenu();
     }