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)
*/
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<String, String> extensions;
*/
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);
}
/**