From: BobHanson Date: Wed, 10 Jun 2020 03:07:59 +0000 (-0500) Subject: JAL-3446 Dynamic menu - Moves calc sortby tree item creation to opening X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=909eba506e9353290500a5d2e70eb53068cbdc5f;p=jalview.git JAL-3446 Dynamic menu - Moves calc sortby tree item creation to opening of its submenu, rather than the upper-level sort menu. - suggestion only; changes setVisible to setEnabled, more along the lines of standard practice (?) - allows for a simple change from "enabled" to "visible" if desired, but still leaves the submenu creation in its most proximate location. --- diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index b69ba88..a06c6d8 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -3966,7 +3966,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ protected int _annotationScoreVectorHash; - /** + /**g * search the alignment and rebuild the sort by annotation score submenu the * last alignment annotation vector hash is stored to minimize cost of * rebuilding in subsequence calls. @@ -4013,6 +4013,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /** + * Enable (or, if desired, make visible) the By Tree + * submenu only if it has at least one element (or will have). + * + */ + @Override + protected void enableSortMenuOptions() + { + List treePanels = getTreePanels(); + sortByTreeMenu.setEnabled(!treePanels.isEmpty()); + } + + /** * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a * TreePanel with an appropriate jalview.analysis.AlignmentSorter * call. Listeners are added to remove the menu item when the treePanel is @@ -4025,24 +4037,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { sortByTreeMenu.removeAll(); - List comps = PaintRefresher.components - .get(viewport.getSequenceSetId()); - List treePanels = new ArrayList<>(); - for (Component comp : comps) - { - if (comp instanceof TreePanel) - { - treePanels.add((TreePanel) comp); - } - } - - if (treePanels.size() < 1) - { - sortByTreeMenu.setVisible(false); - return; - } - - sortByTreeMenu.setVisible(true); + List treePanels = getTreePanels(); for (final TreePanel tp : treePanels) { @@ -4063,6 +4058,21 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } + private List getTreePanels() + { + List comps = PaintRefresher.components + .get(viewport.getSequenceSetId()); + List treePanels = new ArrayList<>(); + for (Component comp : comps) + { + if (comp instanceof TreePanel) + { + treePanels.add((TreePanel) comp); + } + } + return treePanels; + } + public boolean sortBy(AlignmentOrder alorder, String undoname) { SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray(); diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 836aa33..b6c5280 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -26,7 +26,9 @@ import jalview.analysis.GeneticCodes; import jalview.api.SplitContainerI; import jalview.bin.Cache; import jalview.gui.JvSwingUtils; +import jalview.gui.PaintRefresher; import jalview.gui.Preferences; +import jalview.gui.TreePanel; import jalview.io.FileFormats; import jalview.schemes.ResidueColourScheme; import jalview.util.MessageManager; @@ -34,6 +36,7 @@ import jalview.util.Platform; import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Component; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -42,7 +45,9 @@ import java.awt.event.FocusEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.swing.BorderFactory; @@ -1173,6 +1178,24 @@ public class GAlignFrame extends JInternalFrame @Override public void menuSelected(MenuEvent e) { + enableSortMenuOptions(); + } + + @Override + public void menuDeselected(MenuEvent e) + { + } + + @Override + public void menuCanceled(MenuEvent e) + { + } + }); + sortByTreeMenu.addMenuListener(new MenuListener() + { + @Override + public void menuSelected(MenuEvent e) + { buildTreeSortMenu(); } @@ -1737,9 +1760,9 @@ public class GAlignFrame extends JInternalFrame alignFrameMenuBar.add(selectMenu); alignFrameMenuBar.add(viewMenu); alignFrameMenuBar.add(annotationsMenu); + alignFrameMenuBar.add(calculateMenu); alignFrameMenuBar.add(formatMenu); alignFrameMenuBar.add(colourMenu); - alignFrameMenuBar.add(calculateMenu); if (!Platform.isJS()) { alignFrameMenuBar.add(webService); @@ -1919,6 +1942,10 @@ public class GAlignFrame extends JInternalFrame // selectMenu.add(listenToViewSelections); } + protected void enableSortMenuOptions() + { + } + protected void loadVcf_actionPerformed() { } @@ -2717,4 +2744,6 @@ public class GAlignFrame extends JInternalFrame protected void showComplement_actionPerformed(boolean complement) { } + + }