From: Ben Soares Date: Fri, 13 Sep 2024 10:20:54 +0000 (+0100) Subject: JAL-4461 Change JalviewFileFilter to use LinkedHashSet for extensions. Add list of... X-Git-Tag: Release_2_11_4_0~6^2~1^2~2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8ede146f4d51eca8d440e1c1a6fa081029b4cd1c;p=jalview.git JAL-4461 Change JalviewFileFilter to use LinkedHashSet for extensions. Add list of extensions to 'By extensions' tooltip. --- diff --git a/src/jalview/io/JalviewFileChooser.java b/src/jalview/io/JalviewFileChooser.java index 63c9a61..957e47c 100755 --- a/src/jalview/io/JalviewFileChooser.java +++ b/src/jalview/io/JalviewFileChooser.java @@ -34,6 +34,7 @@ import java.beans.PropertyChangeListener; import java.io.File; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.StringTokenizer; @@ -427,6 +428,8 @@ public class JalviewFileChooser extends JFileChooser setAccessory(multi); } + private static String byExtensionTooltip = null; + private static void setByExtensionTooltip(JComboBox dd) { if (dd.getItemCount() > 0 @@ -434,8 +437,28 @@ public class JalviewFileChooser extends JFileChooser { if (((JalviewFileFilter) dd.getSelectedItem()).isMultiFormat()) { - dd.setToolTipText( - MessageManager.getString("label.by_extension_tooltip")); + if (byExtensionTooltip == null) + { + StringBuilder sb = new StringBuilder( + MessageManager.getString("label.by_extension_tooltip")); + JalviewFileFilter jvf = (JalviewFileFilter) dd.getSelectedItem(); + Iterator extensions = jvf.getExtensions(); + if (extensions.hasNext()) + { + sb.append(" (."); + while (extensions.hasNext()) + { + sb.append(extensions.next()); + if (extensions.hasNext()) + { + sb.append(", ."); + } + } + sb.append(")"); + } + byExtensionTooltip = sb.toString(); + } + dd.setToolTipText(byExtensionTooltip); } else { diff --git a/src/jalview/io/JalviewFileFilter.java b/src/jalview/io/JalviewFileFilter.java index c24cbd4..47cca96 100755 --- a/src/jalview/io/JalviewFileFilter.java +++ b/src/jalview/io/JalviewFileFilter.java @@ -23,9 +23,9 @@ package jalview.io; import java.io.File; import java.util.Hashtable; import java.util.Iterator; -import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.Locale; -import java.util.Map; +import java.util.Set; import java.util.StringTokenizer; import javax.swing.filechooser.FileFilter; @@ -34,7 +34,7 @@ public class JalviewFileFilter extends FileFilter { public static Hashtable suffixHash = new Hashtable(); - private Map filters = null; + private Set filters = null; private String description = "no description"; @@ -79,7 +79,7 @@ public class JalviewFileFilter extends FileFilter public String getAcceptableExtension() { - return filters.keySet().iterator().next().toString(); + return filters.iterator().next().toString(); } // takes account of the fact that database is a directory @@ -96,7 +96,7 @@ public class JalviewFileFilter extends FileFilter return true; } - if ((extension != null) && (filters.get(extension) != null)) + if ((extension != null) && (filters.contains(extension))) { return true; } @@ -105,7 +105,7 @@ public class JalviewFileFilter extends FileFilter if (parentJFC != null && parentJFC.includeBackupFiles) { - Iterator it = filters.keySet().iterator(); + Iterator it = filters.iterator(); EXTENSION: while (it.hasNext()) { String ext = it.next(); @@ -150,10 +150,10 @@ public class JalviewFileFilter extends FileFilter { if (filters == null) { - filters = new LinkedHashMap<>(5); + filters = new LinkedHashSet(5); } - filters.put(extension.toLowerCase(Locale.ROOT), this); + filters.add(extension.toLowerCase(Locale.ROOT)); fullDescription = null; } @@ -168,7 +168,7 @@ public class JalviewFileFilter extends FileFilter : (description + " ("); // build the description from the extension list - Iterator extensions = filters.keySet().iterator(); + Iterator extensions = filters.iterator(); if (extensions != null) { @@ -222,4 +222,9 @@ public class JalviewFileFilter extends FileFilter { multiFormat = b; } + + protected Iterator getExtensions() + { + return filters.iterator(); + } }