JAL-3365 expand range of allowed DSSP secondary structure symbols in Stockholm files
[jalview.git] / src / jalview / io / JalviewFileView.java
index 18114f3..a9fc7ed 100755 (executable)
  */
 package jalview.io;
 
+import java.util.Locale;
+
+import jalview.util.MessageManager;
+
 import java.io.File;
 import java.net.URL;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 
 import javax.swing.Icon;
@@ -44,9 +49,8 @@ public class JalviewFileView extends FileView
       String exts = ff.getExtensions();
       for (String ext : exts.split(","))
       {
-        ext = ext.trim().toLowerCase();
-        extensions.put(ext,
-                desc + ("jar".equals(ext) ? " (old)" : ""));
+        ext = ext.trim().toLowerCase(Locale.ROOT);
+        extensions.put(ext, desc + ("jar".equals(ext) ? " (old)" : ""));
       }
     }
   }
@@ -55,7 +59,9 @@ public class JalviewFileView extends FileView
   public String getTypeDescription(File f)
   {
     String extension = getExtension(f);
+
     String type = getDescriptionForExtension(extension);
+
     if (extension != null)
     {
       if (extensions.containsKey(extension))
@@ -84,8 +90,34 @@ public class JalviewFileView extends FileView
   {
     String extension = getExtension(f);
     Icon icon = null;
+    String type = getDescriptionForExtension(extension);
+
+    if (type == null)
+    {
+      Iterator<String> it = extensions.keySet().iterator();
+      EXTENSION: while (it.hasNext())
+      {
+        String ext = it.next();
+
+        // quick negative test
+        if (!f.getName().contains(ext))
+        {
+          continue EXTENSION;
+        }
+
+        BackupFilenameParts bfp = BackupFilenameParts
+                .currentBackupFilenameParts(f.getName(), ext, true);
+        if (bfp.isBackupFile())
+        {
+          extension = ext;
+          type = getDescriptionForExtension(extension)
+                  + MessageManager.getString("label.backup");
+          break;
+        }
+      }
+    }
 
-    if (getDescriptionForExtension(extension) != null)
+    if (type != null)
     {
       icon = getImageIcon("/images/file.png");
     }
@@ -105,7 +137,7 @@ public class JalviewFileView extends FileView
 
     if ((i > 0) && (i < (s.length() - 1)))
     {
-      ext = s.substring(i + 1).toLowerCase();
+      ext = s.substring(i + 1).toLowerCase(Locale.ROOT);
     }
 
     return ext;