X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=3f7432708eedb04be4fbf68e4ef0b56608cd94bb;hb=039594a00b40c65c2864485c1c6ea939a49399a9;hp=f258990c3f641532c04e2be8c52f5c0deff2fefd;hpb=c81c5e6d65f3e3ffe711fe98b95a5d9d4a7656c7;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index f258990..3f74327 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -94,7 +94,6 @@ import jalview.schemes.ColourSchemes; import jalview.schemes.ResidueColourScheme; import jalview.schemes.TCoffeeColourScheme; import jalview.util.MessageManager; -import jalview.util.StringUtils; import jalview.viewmodel.AlignmentViewport; import jalview.viewmodel.ViewportRanges; import jalview.ws.DBRefFetcher; @@ -140,10 +139,9 @@ import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Deque; -import java.util.Enumeration; -import java.util.Hashtable; +import java.util.HashSet; import java.util.List; -import java.util.Scanner; +import java.util.Set; import java.util.Vector; import javax.swing.JCheckBoxMenuItem; @@ -1140,36 +1138,30 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return true; } + /** + * Opens a file browser and adds the selected file, if in Fasta, Stockholm or + * Pfam format, to the list held under preference key "HMMSEARCH_DBS" (as a + * comma-separated list) + */ @Override public void addDatabase_actionPerformed() throws IOException { - if (Cache.getProperty(Preferences.HMMSEARCH_DB_PATHS) == null) + if (Cache.getProperty(Preferences.HMMSEARCH_DBS) == null) { Cache.setProperty(Preferences.HMMSEARCH_DBS, ""); - Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, ""); } String path = openFileChooser(false); - if (new File(path).exists()) + if (path != null && new File(path).exists()) { IdentifyFile identifier = new IdentifyFile(); FileFormatI format = identifier.identify(path, DataSourceType.FILE); if (format == FileFormat.Fasta || format == FileFormat.Stockholm || format == FileFormat.Pfam) { - String currentDbs = Cache.getProperty(Preferences.HMMSEARCH_DBS); String currentDbPaths = Cache - .getProperty(Preferences.HMMSEARCH_DB_PATHS); - currentDbPaths += " " + path; - - String fileName = StringUtils.getLastToken(path, File.separator); - Scanner scanner = new Scanner(fileName).useDelimiter("."); - String name = scanner.next(); - scanner.close(); - currentDbs += " " + path; // TODO remove path from file name - scanner.close(); - - Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, currentDbPaths); + .getProperty(Preferences.HMMSEARCH_DBS); + currentDbPaths += Preferences.COMMA + path; Cache.setProperty(Preferences.HMMSEARCH_DBS, currentDbPaths); } else @@ -1178,21 +1170,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, MessageManager.getString("warn.invalid_format")); } } - else - { - JOptionPane.showMessageDialog(this, - MessageManager.getString("label.not_enough_sequences")); - } } /** - * Opens a file chooser + * Opens a file chooser, optionally restricted to selecting folders + * (directories) only. Answers the path to the selected file or folder, or + * null if none is chosen. * - * @param forFolder + * @param * @return */ protected String openFileChooser(boolean forFolder) { + // TODO duplicates GPreferences method - relocate to JalviewFileChooser? String choice = null; JFileChooser chooser = new JFileChooser(); if (forFolder) @@ -3913,35 +3903,33 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (viewport.getAlignment().getAlignmentAnnotation() - .hashCode() != _annotationScoreVectorHash) + .hashCode() == _annotationScoreVectorHash) { - sortByAnnotScore.removeAll(); - // almost certainly a quicker way to do this - but we keep it simple - Hashtable scoreSorts = new Hashtable(); - AlignmentAnnotation aann[]; - for (SequenceI sqa : viewport.getAlignment().getSequences()) + return; + } + + sortByAnnotScore.removeAll(); + Set scoreSorts = new HashSet<>(); + for (SequenceI sqa : viewport.getAlignment().getSequences()) + { + AlignmentAnnotation[] anns = sqa.getAnnotation(); + for (int i = 0; anns != null && i < anns.length; i++) { - aann = sqa.getAnnotation(); - for (int i = 0; aann != null && i < aann.length; i++) + AlignmentAnnotation aa = anns[i]; + if (aa != null && aa.hasScore() && aa.sequenceRef != null) { - if (aann[i].hasScore() && aann[i].sequenceRef != null) - { - scoreSorts.put(aann[i].label, aann[i].label); - } + scoreSorts.add(aa.label); } } - Enumeration labels = scoreSorts.keys(); - while (labels.hasMoreElements()) - { - addSortByAnnotScoreMenuItem(sortByAnnotScore, - (String) labels.nextElement()); - } - sortByAnnotScore.setVisible(scoreSorts.size() > 0); - scoreSorts.clear(); - - _annotationScoreVectorHash = viewport.getAlignment() - .getAlignmentAnnotation().hashCode(); } + for (String label : scoreSorts) + { + addSortByAnnotScoreMenuItem(sortByAnnotScore, label); + } + sortByAnnotScore.setVisible(!scoreSorts.isEmpty()); + + _annotationScoreVectorHash = viewport.getAlignment() + .getAlignmentAnnotation().hashCode(); } /**