From 048a384fa19ac37fbe2b63bbba139d5fa17107c5 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 27 Jun 2016 14:03:09 +0100 Subject: [PATCH] JAL-2133 refactored duplicated code to AlignmentViewport --- src/jalview/appletgui/APopupMenu.java | 33 ++++---------------------- src/jalview/gui/PopupMenu.java | 23 +----------------- src/jalview/viewmodel/AlignmentViewport.java | 33 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 51 deletions(-) diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java index 748954a..948c8e5 100644 --- a/src/jalview/appletgui/APopupMenu.java +++ b/src/jalview/appletgui/APopupMenu.java @@ -537,6 +537,7 @@ public class APopupMenu extends java.awt.PopupMenu implements MenuItem item = new MenuItem(label); item.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(ActionEvent e) { ap.alignFrame.showURL(url, target); @@ -545,6 +546,7 @@ public class APopupMenu extends java.awt.PopupMenu implements linkMenu.add(item); } + @Override public void itemStateChanged(ItemEvent evt) { if (evt.getSource() == abovePIDColour) @@ -569,6 +571,7 @@ public class APopupMenu extends java.awt.PopupMenu implements } } + @Override public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); @@ -1299,35 +1302,7 @@ public class APopupMenu extends java.awt.PopupMenu implements void hideSequences(boolean representGroup) { - SequenceGroup sg = ap.av.getSelectionGroup(); - if (sg == null || sg.getSize() < 1) - { - ap.av.hideSequence(new SequenceI[] { seq }); - return; - } - - ap.av.setSelectionGroup(null); - - if (representGroup) - { - ap.av.hideRepSequences(seq, sg); - - return; - } - - int gsize = sg.getSize(); - SequenceI[] hseqs; - - hseqs = new SequenceI[gsize]; - - int index = 0; - for (int i = 0; i < gsize; i++) - { - hseqs[index++] = sg.getSequenceAt(i); - } - - ap.av.hideSequence(hseqs); - ap.av.sendSelection(); + ap.av.hideSequences(seq, representGroup); } /** diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index e64d43f..497f3ba 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -2270,28 +2270,7 @@ public class PopupMenu extends JPopupMenu void hideSequences(boolean representGroup) { - SequenceGroup sg = ap.av.getSelectionGroup(); - if (sg == null || sg.getSize() < 1) - { - ap.av.hideSequence(new SequenceI[] { sequence }); - return; - } - - ap.av.setSelectionGroup(null); - - if (representGroup) - { - ap.av.hideRepSequences(sequence, sg); - - return; - } - - int gsize = sg.getSize(); - SequenceI[] hseqs = sg.getSequences().toArray(new SequenceI[gsize]); - - ap.av.hideSequence(hseqs); - // refresh(); TODO: ? needed ? - ap.av.sendSelection(); + ap.av.hideSequences(sequence, representGroup); } public void copy_actionPerformed() diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 91ee3c1..eab4aa5 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -1413,6 +1413,39 @@ public abstract class AlignmentViewport implements AlignViewportI, } /** + * Hides the specified sequence, or the sequences it represents + * + * @param sequence + * the sequence to hide, or keep as representative + * @param representGroup + * if true, hide the current selection group except for the + * representative sequence + */ + public void hideSequences(SequenceI sequence, boolean representGroup) + { + if (selectionGroup == null || selectionGroup.getSize() < 1) + { + hideSequence(new SequenceI[] { sequence }); + return; + } + + if (representGroup) + { + hideRepSequences(sequence, selectionGroup); + setSelectionGroup(null); + return; + } + + int gsize = selectionGroup.getSize(); + SequenceI[] hseqs = selectionGroup.getSequences().toArray( + new SequenceI[gsize]); + + hideSequence(hseqs); + setSelectionGroup(null); + sendSelection(); + } + + /** * Set visibility for any annotations for the given sequence. * * @param sequenceI -- 1.7.10.2