From: Ben Soares Date: Wed, 15 Nov 2023 13:29:19 +0000 (+0000) Subject: JAL-3836 Allow .ext.gz files to be recognised in the File Chooser if .ext is a recogn... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=065fef732147eadd0453d4dbb9b8081ad4a1d301;p=jalview.git JAL-3836 Allow .ext.gz files to be recognised in the File Chooser if .ext is a recognised extension. --- diff --git a/src/jalview/io/JalviewFileFilter.java b/src/jalview/io/JalviewFileFilter.java index 5e9a242..d9d609c 100755 --- a/src/jalview/io/JalviewFileFilter.java +++ b/src/jalview/io/JalviewFileFilter.java @@ -126,22 +126,44 @@ public class JalviewFileFilter extends FileFilter return false; } - public String getExtension(File f) + public static String getExtension(File f) { - if (f != null) + if (f == null) + { + return ""; + } + String ext = getExtension(f.getName(), true, true); + return ext; + } + + public static String getExtension(String filename, boolean ignoreGz, + boolean emptyStringForNoExtension) + { + if (filename == null) { - String filename = f.getName(); - int i = filename.lastIndexOf('.'); + return emptyStringForNoExtension ? "" : null; + } + int i = filename.lastIndexOf('.'); - if ((i > 0) && (i < (filename.length() - 1))) + // i>0 as we don't consider a file ".hidden" to be an extension of "hidden" + // i<(filename.length()-1) since we don't consider a file "hi." to have an + // extension + if (i > 0 && i < (filename.length() - 1)) + { + String ext = filename.substring(i + 1).toLowerCase(Locale.ROOT); + if (ignoreGz && ext.equals("gz")) { - return filename.substring(i + 1).toLowerCase(Locale.ROOT); + // don't allow .gz all the way down! (only one in fact) + return getExtension(filename.substring(0, i), false, + emptyStringForNoExtension); + } + else + { + return ext; } - - ; } - return ""; + return emptyStringForNoExtension ? "" : null; } public void addExtension(String extension) diff --git a/src/jalview/io/JalviewFileView.java b/src/jalview/io/JalviewFileView.java index 5996781..d010013 100755 --- a/src/jalview/io/JalviewFileView.java +++ b/src/jalview/io/JalviewFileView.java @@ -20,20 +20,19 @@ */ 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.Locale; import java.util.Map; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.filechooser.FileView; +import jalview.util.MessageManager; + public class JalviewFileView extends FileView { private static Map extensions; @@ -131,16 +130,13 @@ public class JalviewFileView extends FileView */ public static String getExtension(File f) { - String ext = null; - String s = f.getName(); - int i = s.lastIndexOf('.'); - - if ((i > 0) && (i < (s.length() - 1))) + // don't set an icon for folders (that's flatlaf's job!) + if (f.isDirectory()) { - ext = s.substring(i + 1).toLowerCase(Locale.ROOT); + return null; } - - return ext; + // ignore .gz and want null for no extension + return JalviewFileFilter.getExtension(f.getName(), true, false); } /**