JAL-2344 handle null format, simplify JalviewFileChooser constructor
[jalview.git] / src / jalview / gui / Preferences.java
index b57b951..0b65c1b 100755 (executable)
  */
 package jalview.gui;
 
+import static jalview.util.UrlConstants.DB_ACCESSION;
 import static jalview.util.UrlConstants.EMBLEBI_STRING;
-import static jalview.util.UrlConstants.OLD_EMBLEBI_STRING;
 import static jalview.util.UrlConstants.SEQUENCE_ID;
-import static jalview.util.UrlConstants.SEQUENCE_NAME;
 import static jalview.util.UrlConstants.SRS_STRING;
 
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
 import jalview.bin.Cache;
 import jalview.gui.Help.HelpId;
 import jalview.gui.StructureViewer.ViewerType;
+import jalview.io.FileFormatI;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
 import jalview.jbgui.GPreferences;
@@ -56,7 +56,6 @@ import javax.help.HelpSetException;
 import javax.swing.JColorChooser;
 import javax.swing.JFileChooser;
 import javax.swing.JInternalFrame;
-import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 
 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
@@ -127,10 +126,10 @@ public class Preferences extends GPreferences
         String name = st.nextToken();
         String url = st.nextToken();
         // check for '|' within a regex
-        int rxstart = url.indexOf("$" + SEQUENCE_ID + "$");
+        int rxstart = url.indexOf("$" + DB_ACCESSION + "$");
         if (rxstart == -1)
         {
-          rxstart = url.indexOf("$" + SEQUENCE_NAME + "$");
+          rxstart = url.indexOf("$" + SEQUENCE_ID + "$");
         }
         while (rxstart == -1 && url.indexOf("/=$") == -1)
         {
@@ -149,12 +148,6 @@ public class Preferences extends GPreferences
       {
         sequenceURLLinks.setElementAt(EMBLEBI_STRING, srsPos);
       }
-      // upgrade old EMBL-EBI link
-      int emblPos = sequenceURLLinks.indexOf(OLD_EMBLEBI_STRING);
-      if (emblPos > -1)
-      {
-        sequenceURLLinks.setElementAt(EMBLEBI_STRING, emblPos);
-      }
     }
 
     /**
@@ -574,6 +567,7 @@ public class Preferences extends GPreferences
     else
     {
       Cache.applicationProperties.remove("SEQUENCE_LINKS");
+      sequenceURLLinks.clear();
     }
 
     Cache.applicationProperties.setProperty("USE_PROXY",
@@ -692,12 +686,9 @@ public class Preferences extends GPreferences
   @Override
   public void startupFileTextfield_mouseClicked()
   {
-    JalviewFileChooser chooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] {
-                "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
-                "jar" }, new String[] { "Fasta", "Clustal", "PFAM", "MSF",
-                "PIR", "BLC", "Jalview" },
-            jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
+    String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
+    JalviewFileChooser chooser = JalviewFileChooser.forRead(
+            Cache.getProperty("LAST_DIRECTORY"), fileFormat);
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager
             .getString("label.select_startup_file"));
@@ -706,8 +697,12 @@ public class Preferences extends GPreferences
 
     if (value == JalviewFileChooser.APPROVE_OPTION)
     {
-      jalview.bin.Cache.applicationProperties.setProperty(
-              "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
+      FileFormatI format = chooser.getSelectedFormat();
+      if (format != null)
+      {
+        Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
+                format.toString());
+      }
       startupFileTextfield.setText(chooser.getSelectedFile()
               .getAbsolutePath());
     }
@@ -760,9 +755,9 @@ public class Preferences extends GPreferences
     boolean valid = false;
     while (!valid)
     {
-      if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
+      if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
               MessageManager.getString("label.new_sequence_url_link"),
-              JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION)
+              JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION)
       {
         if (link.checkValid())
         {
@@ -787,10 +782,10 @@ public class Preferences extends GPreferences
     int index = linkNameList.getSelectedIndex();
     if (index == -1)
     {
-      JOptionPane.showInternalMessageDialog(Desktop.desktop,
+      JvOptionPane.showInternalMessageDialog(Desktop.desktop,
               MessageManager.getString("label.no_link_selected"),
               MessageManager.getString("label.no_link_selected"),
-              JOptionPane.WARNING_MESSAGE);
+              JvOptionPane.WARNING_MESSAGE);
       return;
     }
 
@@ -801,9 +796,9 @@ public class Preferences extends GPreferences
     while (!valid)
     {
 
-      if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
+      if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
               MessageManager.getString("label.new_sequence_url_link"),
-              JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION)
+              JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION)
       {
         if (link.checkValid())
         {
@@ -827,10 +822,10 @@ public class Preferences extends GPreferences
     int index = linkNameList.getSelectedIndex();
     if (index == -1)
     {
-      JOptionPane.showInternalMessageDialog(Desktop.desktop,
+      JvOptionPane.showInternalMessageDialog(Desktop.desktop,
               MessageManager.getString("label.no_link_selected"),
               MessageManager.getString("label.no_link_selected"),
-              JOptionPane.WARNING_MESSAGE);
+              JvOptionPane.WARNING_MESSAGE);
       return;
     }
     nameLinks.removeElementAt(index);
@@ -922,10 +917,10 @@ public class Preferences extends GPreferences
       }
     } catch (NumberFormatException x)
     {
-      JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
+      JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
               .getString("warn.user_defined_width_requirements"),
               MessageManager.getString("label.invalid_id_column_width"),
-              JOptionPane.WARNING_MESSAGE);
+              JvOptionPane.WARNING_MESSAGE);
       userIdWidth.setText("");
     }
   }
@@ -948,10 +943,10 @@ public class Preferences extends GPreferences
       File f = new File(chimeraPath.getText());
       if (!f.canExecute())
       {
-        JOptionPane.showInternalMessageDialog(Desktop.desktop,
+        JvOptionPane.showInternalMessageDialog(Desktop.desktop,
                 MessageManager.getString("label.invalid_chimera_path"),
                 MessageManager.getString("label.invalid_name"),
-                JOptionPane.ERROR_MESSAGE);
+                JvOptionPane.ERROR_MESSAGE);
         return false;
       }
     }
@@ -987,13 +982,13 @@ public class Preferences extends GPreferences
     if (!found)
     {
       String[] options = { "OK", "Help" };
-      int showHelp = JOptionPane.showInternalOptionDialog(
+      int showHelp = JvOptionPane.showInternalOptionDialog(
               Desktop.desktop,
               JvSwingUtils.wrapTooltip(true,
                       MessageManager.getString("label.chimera_missing")),
-              "", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
+              "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
               null, options, options[0]);
-      if (showHelp == JOptionPane.NO_OPTION)
+      if (showHelp == JvOptionPane.NO_OPTION)
       {
         try
         {