From 5a1324c30a40231bea443ff15c196ced9d6d51df Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 9 Mar 2020 13:06:05 +0000 Subject: [PATCH] JAL-3549 JAL-3305 no Sort By Score / Density if no features visible --- resources/lang/Messages.properties | 4 +- resources/lang/Messages_es.properties | 3 +- src/jalview/controller/AlignViewController.java | 28 +++-- src/jalview/gui/FeatureSettings.java | 128 +++++++++++++---------- 4 files changed, 98 insertions(+), 65 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index c5589cf..a4b24ed 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1407,8 +1407,8 @@ label.create_image_of = Create {0} image of {1} label.click_to_edit = Click to edit, right-click for menu label.by_annotation_tooltip = Annotation Colour is configured from the main Colour menu label.show_linked_features = Show {0} features -label.show_linked_feature_settings = Open {0} settings label.on_top = on top label.include_linked_features = Include {0} features label.include_linked_tooltip = Include visible {0} features
converted to local sequence coordinates -label.features_not_shown = {0} feature(s) not shown \ No newline at end of file +label.features_not_shown = {0} feature(s) not shown +label.no_features_to_sort_by = No features to sort by diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index 42f145b..4e0fb1f 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1405,4 +1405,5 @@ label.show_linked_features = Caracter label.on_top = encima label.include_linked_features = Incluir características de {0} label.include_linked_tooltip = Incluir características de {0}
convertidas a coordenadas de secuencia local -label.features_not_shown = {0} característica(s) no mostradas \ No newline at end of file +label.features_not_shown = {0} característica(s) no mostradas +label.no_features_to_sort_by = No hay características para ordenar diff --git a/src/jalview/controller/AlignViewController.java b/src/jalview/controller/AlignViewController.java index f45afa5..8087210 100644 --- a/src/jalview/controller/AlignViewController.java +++ b/src/jalview/controller/AlignViewController.java @@ -310,16 +310,31 @@ public class AlignViewController implements AlignViewControllerI @Override public void sortAlignmentByFeatureDensity(List typ) { - sortBy(typ, "Sort by Density", AlignmentSorter.FEATURE_DENSITY); + String methodText = MessageManager.getString("label.sort_by_density"); + sortByFeatures(typ, methodText, AlignmentSorter.FEATURE_DENSITY); } - protected void sortBy(List typ, String methodText, + /** + * Sorts the alignment (or current selection) by either average score or + * density of the specified feature types, and adds to the command history. If + * {@code types} is null, all visible feature types are used for the sort. If + * no feature types apply, does nothing. + * + * @param types + * @param methodText + * @param method + */ + protected void sortByFeatures(List types, String methodText, final String method) { FeatureRenderer fr = alignPanel.getFeatureRenderer(); - if (typ == null && fr != null) + if (types == null && fr != null) + { + types = fr.getDisplayedFeatureTypes(); + } + if (types.isEmpty()) { - typ = fr.getDisplayedFeatureTypes(); + return; // nothing to do } List gps = null; if (fr != null) @@ -341,7 +356,7 @@ public class AlignViewController implements AlignViewControllerI stop = al.getWidth(); } SequenceI[] oldOrder = al.getSequencesArray(); - AlignmentSorter.sortByFeature(typ, gps, start, stop, al, method); + AlignmentSorter.sortByFeature(types, gps, start, stop, al, method); avcg.addHistoryItem(new OrderCommand(methodText, oldOrder, viewport.getAlignment())); alignPanel.paintAlignment(true, false); @@ -351,7 +366,8 @@ public class AlignViewController implements AlignViewControllerI @Override public void sortAlignmentByFeatureScore(List typ) { - sortBy(typ, "Sort by Feature Score", AlignmentSorter.FEATURE_SCORE); + String methodText = MessageManager.getString("label.sort_by_score"); + sortByFeatures(typ, methodText, AlignmentSorter.FEATURE_SCORE); } @Override diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 3efc63e..b87e4bf 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -82,7 +82,6 @@ import java.util.Map; import java.util.Set; import javax.help.HelpSetException; -import javax.swing.AbstractButton; import javax.swing.AbstractCellEditor; import javax.swing.BorderFactory; import javax.swing.Icon; @@ -165,6 +164,10 @@ public class FeatureSettings extends JPanel JSlider transparency = new JSlider(); + private JCheckBox showComplementOnTop; + + private JCheckBox showComplement; + /* * when true, constructor is still executing - so ignore UI events */ @@ -180,6 +183,12 @@ public class FeatureSettings extends JPanel private boolean handlingUpdate = false; /* + * a change listener to ensure the dialog is updated if + * FeatureRenderer discovers new features + */ + private PropertyChangeListener change; + + /* * holds {featureCount, totalExtent} for each feature type */ Map typeWidth = null; @@ -448,12 +457,10 @@ public class FeatureSettings extends JPanel inConstruction = false; } - PropertyChangeListener change; - - private JCheckBox showComplementOnTop; - - private AbstractButton showComplement; - + /** + * Sets the state of buttons to show complement features from viewport + * settings + */ private void updateComplementButtons() { showComplement.setSelected(af.getViewport().isShowComplementFeatures()); @@ -484,32 +491,23 @@ public class FeatureSettings extends JPanel JMenuItem scr = new JMenuItem( MessageManager.getString("label.sort_by_score")); men.add(scr); - final FeatureSettings me = this; scr.addActionListener(new ActionListener() { - @Override public void actionPerformed(ActionEvent e) { - me.af.avc - .sortAlignmentByFeatureScore(Arrays.asList(new String[] - { type })); + sortByScore(Arrays.asList(new String[] { type })); } - }); JMenuItem dens = new JMenuItem( MessageManager.getString("label.sort_by_density")); dens.addActionListener(new ActionListener() { - @Override public void actionPerformed(ActionEvent e) { - me.af.avc - .sortAlignmentByFeatureDensity(Arrays.asList(new String[] - { type })); + sortByDensity(Arrays.asList(new String[] { type })); } - }); men.add(dens); @@ -566,6 +564,47 @@ public class FeatureSettings extends JPanel men.show(table, x, y); } + /** + * Sort the sequences in the alignment by the number of features for the given + * feature types (or all features if null) + * + * @param featureTypes + */ + protected void sortByDensity(List featureTypes) + { + af.avc.sortAlignmentByFeatureDensity(featureTypes); + } + + /** + * Sort the sequences in the alignment by average score for the given feature + * types (or all features if null) + * + * @param featureTypes + */ + protected void sortByScore(List featureTypes) + { + af.avc.sortAlignmentByFeatureScore(featureTypes); + } + + /** + * Returns true if at least one feature type is visible. Else shows a warning + * dialog and returns false. + * + * @param title + * @return + */ + private boolean canSortBy(String title) + { + if (fr.getDisplayedFeatureTypes().isEmpty()) + { + JvOptionPane.showMessageDialog(this, + MessageManager.getString("label.no_features_to_sort_by"), + title, JvOptionPane.OK_OPTION); + return false; + } + return true; + } + @Override synchronized public void discoverAllFeatureData() { @@ -1267,26 +1306,32 @@ public class FeatureSettings extends JPanel } }); - JButton sortByScore = new JButton( - MessageManager.getString("label.seq_sort_by_score")); + final String byScoreLabel = MessageManager.getString("label.seq_sort_by_score"); + JButton sortByScore = new JButton(byScoreLabel); sortByScore.setFont(JvSwingUtils.getLabelFont()); sortByScore.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - af.avc.sortAlignmentByFeatureScore(null); + if (canSortBy(byScoreLabel)) + { + sortByScore(null); + } } }); - JButton sortByDens = new JButton( - MessageManager.getString("label.sequence_sort_by_density")); + final String byDensityLabel = MessageManager.getString("label.sequence_sort_by_density"); + JButton sortByDens = new JButton(byDensityLabel); sortByDens.setFont(JvSwingUtils.getLabelFont()); sortByDens.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - af.avc.sortAlignmentByFeatureDensity(null); + if (canSortBy(byDensityLabel)) + { + sortByDensity(null); + } } }); @@ -1425,38 +1470,9 @@ public class FeatureSettings extends JPanel refreshDisplay(); } }); - // JButton viewComplementSettings = new JButton(MessageManager - // .formatMessage("label.show_linked_feature_settings", - // nucleotide - // ? MessageManager.getString("label.protein") - // .toLowerCase() - // : "CDS")); - // viewComplementSettings.addActionListener(new ActionListener() - // { - // - // @Override - // public void actionPerformed(ActionEvent e) - // { - // AlignViewControllerGuiI complAf = af.getSplitViewContainer() - // .getComplementAlignFrame(af); - // FeatureSettings complFeatureSettings = (FeatureSettings) complAf - // .getFeatureSettingsUI(); - // if (complFeatureSettings != null) - // { - // complFeatureSettings.frame.setVisible(true); - // try - // { - // complFeatureSettings.frame.setSelected(true); - // return; - // } catch (Exception q) - // { - // } - // } - // { - // complAf.showFeatureSettingsUI(); - // } - // } - // }); + + updateComplementButtons(); + JPanel lowerPanel = new JPanel(new GridLayout(1, 2)); bigPanel.add(lowerPanel, BorderLayout.SOUTH); -- 1.7.10.2