JAL-3141. This adds quite a lot of code to allow an 'Include backup files' checkbox...
[jalview.git] / src / jalview / io / JalviewFileFilter.java
index 21f5b0f..8c6b802 100755 (executable)
@@ -41,6 +41,8 @@ public class JalviewFileFilter extends FileFilter
 
   private boolean useExtensionsInDescription = true;
 
+  private JalviewFileChooser parentJFC = null;
+
   public JalviewFileFilter(String extension, String description)
   {
     StringTokenizer st = new StringTokenizer(extension, ",");
@@ -81,6 +83,7 @@ public class JalviewFileFilter extends FileFilter
   @Override
   public boolean accept(File f)
   {
+
     if (f != null)
     {
       String extension = getExtension(f);
@@ -94,8 +97,25 @@ public class JalviewFileFilter extends FileFilter
       {
         return true;
       }
+
     }
 
+    if (parentJFC != null && parentJFC.includeBackupFiles)
+    {
+      Iterator<String> it = filters.keySet().iterator();
+      while (it.hasNext())
+      {
+        String ext = it.next();
+
+        BackupFilenameParts bfp = BackupFilenameParts
+                .currentBackupFilenameParts(f.getName(), ext, true);
+        if (bfp.isBackupFile())
+        {
+          return true;
+        }
+      }
+    }
+    
     return false;
   }
 
@@ -178,4 +198,10 @@ public class JalviewFileFilter extends FileFilter
   {
     return useExtensionsInDescription;
   }
+
+  protected void setParentJFC(JalviewFileChooser p)
+  {
+    this.parentJFC = p;
+  }
+
 }