From: gmungoc Date: Wed, 3 Apr 2019 13:07:37 +0000 (+0100) Subject: JAL-3081 JAL-3199 no auto-sort of annotations after manual reordering X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=a1935687c9e0bb6e861b5d607b5afd23ab544202;p=jalview.git JAL-3081 JAL-3199 no auto-sort of annotations after manual reordering --- diff --git a/src/jalview/analysis/AnnotationSorter.java b/src/jalview/analysis/AnnotationSorter.java index 2f556f1..5a7e72f 100644 --- a/src/jalview/analysis/AnnotationSorter.java +++ b/src/jalview/analysis/AnnotationSorter.java @@ -51,7 +51,12 @@ public class AnnotationSorter { // Text descriptions surface in the Preferences Sort by... options SEQUENCE_AND_LABEL("Sequence"), LABEL_AND_SEQUENCE("Label"), - NONE("No sort"); + NONE("No sort"), + + /** + * custom is set if user drags to reorder annotations + */ + CUSTOM("Customised"); private String description; @@ -86,7 +91,7 @@ public class AnnotationSorter private boolean showAutocalcAbove; // working map of sequence index in alignment - private final Map sequenceIndices = new HashMap(); + private final Map sequenceIndices = new HashMap<>(); /** * Constructor given an alignment and the location (top or bottom) of @@ -273,7 +278,8 @@ public class AnnotationSorter public void sort(AlignmentAnnotation[] alignmentAnnotations, SequenceAnnotationOrder order) { - if (alignmentAnnotations == null) + if (alignmentAnnotations == null + || order == SequenceAnnotationOrder.CUSTOM) { return; } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 0239bb4..9ee210f 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -22,6 +22,7 @@ package jalview.gui; import jalview.analysis.AlignmentSorter; import jalview.analysis.AlignmentUtils; +import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.analysis.CrossRef; import jalview.analysis.Dna; import jalview.analysis.GeneticCodeI; @@ -145,6 +146,8 @@ import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; +import javax.swing.event.MenuEvent; +import javax.swing.event.MenuListener; /** * DOCUMENT ME! @@ -362,9 +365,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, sortPairwiseMenuItem_actionPerformed(null); } - this.alignPanel.av - .setShowAutocalculatedAbove(isShowAutoCalculatedAbove()); - setMenusFromViewport(viewport); buildSortByAnnotationScoresMenu(); calculateTree.addActionListener(new ActionListener() @@ -481,6 +481,33 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } }); + /* + * ensure By Label/Sequence are not selected if annotations + * have been reordered manually to CUSTOM order + */ + annotationsMenu.addMenuListener(new MenuListener() + { + @Override + public void menuSelected(MenuEvent e) + { + SequenceAnnotationOrder sortAnnotationsBy = viewport + .getSortAnnotationsBy(); + sortAnnByLabel.setSelected( + sortAnnotationsBy == SequenceAnnotationOrder.LABEL_AND_SEQUENCE); + sortAnnBySequence.setSelected( + sortAnnotationsBy == SequenceAnnotationOrder.SEQUENCE_AND_LABEL); + } + + @Override + public void menuDeselected(MenuEvent e) + { + } + + @Override + public void menuCanceled(MenuEvent e) + { + } + }); } /** @@ -5410,14 +5437,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /** - * Store selected annotation sort order for the view and repaint. + * Sorts annotations and repaints the alignment */ @Override - protected void sortAnnotations_actionPerformed() + protected void sortAnnotations() { - this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder()); - this.alignPanel.av - .setShowAutocalculatedAbove(isShowAutoCalculatedAbove()); + alignPanel.sortAnnotations(); alignPanel.paintAlignment(false, false); } @@ -5645,6 +5670,34 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } + + @Override + protected boolean setShowAutoCalculatedAbove( + boolean showAutoCalculatedAbove) + { + if (viewport.isShowAutocalculatedAbove() != showAutoCalculatedAbove) + { + viewport.setShowAutocalculatedAbove(showAutoCalculatedAbove); + + /* + * change CUSTOM annotation ordering to NONE + * so that sorting actually does something + */ + if (viewport.getSortAnnotationsBy() == SequenceAnnotationOrder.CUSTOM) + { + viewport.setSortAnnotationsBy(SequenceAnnotationOrder.NONE); + } + return true; + } + return false; + } + + @Override + public void setAnnotationSortOrder( + SequenceAnnotationOrder annotationSortOrder) + { + viewport.setSortAnnotationsBy(annotationSortOrder); + } } class PrintThread extends Thread diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 92b9a50..502ab9d 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -804,10 +804,6 @@ public class AlignmentPanel extends GAlignmentPanel implements public void paintAlignment(boolean updateOverview, boolean updateStructures) { - final AnnotationSorter sorter = new AnnotationSorter(getAlignment(), - av.isShowAutocalculatedAbove()); - sorter.sort(getAlignment().getAlignmentAnnotation(), - av.getSortAnnotationsBy()); repaint(); if (updateStructures) @@ -825,6 +821,17 @@ public class AlignmentPanel extends GAlignmentPanel implements } /** + * Sorts annotations according to currently selected preference + */ + void sortAnnotations() + { + final AnnotationSorter sorter = new AnnotationSorter(getAlignment(), + av.isShowAutocalculatedAbove()); + sorter.sort(getAlignment().getAlignmentAnnotation(), + av.getSortAnnotationsBy()); + } + + /** * DOCUMENT ME! * * @param g diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 6da6cc3..2f62a41 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -22,6 +22,7 @@ package jalview.gui; import jalview.analysis.AlignSeq; import jalview.analysis.AlignmentUtils; +import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; @@ -599,6 +600,7 @@ public class AnnotationLabels extends JPanel ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA; ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA; + av.setSortAnnotationsBy(SequenceAnnotationOrder.CUSTOM); } resizePanel = false; diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 9f41c92..50ee6c8 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -200,14 +200,16 @@ public class GAlignFrame extends JInternalFrame protected JCheckBoxMenuItem applyAutoAnnotationSettings = new JCheckBoxMenuItem(); - private SequenceAnnotationOrder annotationSortOrder; - - private boolean showAutoCalculatedAbove = false; - private Map accelerators = new HashMap<>(); private SplitContainerI splitFrame; + protected JCheckBoxMenuItem sortAnnBySequence; + + protected JCheckBoxMenuItem sortAnnByLabel; + + protected JMenu annotationsMenu; + public GAlignFrame() { try @@ -286,7 +288,7 @@ public class GAlignFrame extends JInternalFrame JMenu editMenu = new JMenu(MessageManager.getString("action.edit")); JMenu viewMenu = new JMenu(MessageManager.getString("action.view")); - JMenu annotationsMenu = new JMenu( + annotationsMenu = new JMenu( MessageManager.getString("action.annotations")); JMenu showMenu = new JMenu(MessageManager.getString("action.show")); colourMenu.setText(MessageManager.getString("action.colour")); @@ -602,9 +604,9 @@ public class GAlignFrame extends JInternalFrame SequenceAnnotationOrder sortAnnotationsBy = SequenceAnnotationOrder .valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS, SequenceAnnotationOrder.NONE.name())); - final JCheckBoxMenuItem sortAnnBySequence = new JCheckBoxMenuItem( + sortAnnBySequence = new JCheckBoxMenuItem( MessageManager.getString("label.sort_annotations_by_sequence")); - final JCheckBoxMenuItem sortAnnByLabel = new JCheckBoxMenuItem( + sortAnnByLabel = new JCheckBoxMenuItem( MessageManager.getString("label.sort_annotations_by_label")); sortAnnBySequence.setSelected( @@ -619,7 +621,7 @@ public class GAlignFrame extends JInternalFrame setAnnotationSortOrder( newState ? SequenceAnnotationOrder.SEQUENCE_AND_LABEL : SequenceAnnotationOrder.NONE); - sortAnnotations_actionPerformed(); + sortAnnotations(); } }); sortAnnByLabel.setSelected( @@ -634,7 +636,7 @@ public class GAlignFrame extends JInternalFrame setAnnotationSortOrder( newState ? SequenceAnnotationOrder.LABEL_AND_SEQUENCE : SequenceAnnotationOrder.NONE); - sortAnnotations_actionPerformed(); + sortAnnotations(); } }); colourTextMenuItem = new JCheckBoxMenuItem( @@ -885,14 +887,15 @@ public class GAlignFrame extends JInternalFrame final boolean autoFirst = Cache .getDefault(Preferences.SHOW_AUTOCALC_ABOVE, false); showAutoFirst.setSelected(autoFirst); - setShowAutoCalculatedAbove(autoFirst); showAutoFirst.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - setShowAutoCalculatedAbove(showAutoFirst.isSelected()); - sortAnnotations_actionPerformed(); + if (setShowAutoCalculatedAbove(showAutoFirst.isSelected())) + { + sortAnnotations(); + } } }); showAutoLast.setSelected(!showAutoFirst.isSelected()); @@ -901,8 +904,10 @@ public class GAlignFrame extends JInternalFrame @Override public void actionPerformed(ActionEvent e) { - setShowAutoCalculatedAbove(!showAutoLast.isSelected()); - sortAnnotations_actionPerformed(); + if (setShowAutoCalculatedAbove(!showAutoLast.isSelected())) + { + sortAnnotations(); + } } }); @@ -2023,7 +2028,7 @@ public class GAlignFrame extends JInternalFrame * * @param sortOrder */ - protected void sortAnnotations_actionPerformed() + protected void sortAnnotations() { } @@ -2620,25 +2625,22 @@ public class GAlignFrame extends JInternalFrame } - protected boolean isShowAutoCalculatedAbove() - { - return showAutoCalculatedAbove; - } - - protected void setShowAutoCalculatedAbove(boolean showAutoCalculatedAbove) - { - this.showAutoCalculatedAbove = showAutoCalculatedAbove; - } - - protected SequenceAnnotationOrder getAnnotationSortOrder() + /** + * Sets the value of the flag for 'show autocalculated annotations above other + * annotations'. Answers true if the value changed, else false. + * + * @param showAutoCalculatedAbove + * @return + */ + protected boolean setShowAutoCalculatedAbove( + boolean showAutoCalculatedAbove) { - return annotationSortOrder; + return false; } - protected void setAnnotationSortOrder( + public void setAnnotationSortOrder( SequenceAnnotationOrder annotationSortOrder) { - this.annotationSortOrder = annotationSortOrder; } public Map getAccelerators()