From 60e7c072c017a2a8cec9cc39139b3fca8680d0eb Mon Sep 17 00:00:00 2001 From: kjvdheide Date: Thu, 7 Dec 2017 14:24:14 +0000 Subject: [PATCH] JAL-2872 Redundant Aptx GUI menu items hidden, sorting item added --- src/jalview/ext/archaeopteryx/AptxInit.java | 62 +++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/src/jalview/ext/archaeopteryx/AptxInit.java b/src/jalview/ext/archaeopteryx/AptxInit.java index b9a2266..dfc4387 100644 --- a/src/jalview/ext/archaeopteryx/AptxInit.java +++ b/src/jalview/ext/archaeopteryx/AptxInit.java @@ -9,6 +9,7 @@ import jalview.gui.JvOptionPane; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; +import java.awt.Component; import java.awt.Dimension; import java.io.File; import java.io.FileNotFoundException; @@ -18,6 +19,11 @@ import java.net.URL; import java.util.HashMap; import java.util.Map; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JSeparator; + import org.forester.archaeopteryx.AptxUtil; import org.forester.archaeopteryx.Archaeopteryx; import org.forester.archaeopteryx.Configuration; @@ -490,6 +496,7 @@ public final class AptxInit MainFrame aptxApp = Archaeopteryx.createApplication(aptxTree, APTX_CONFIG, treeTitle); + adaptAptxGui(aptxApp); LoadedTreeSequenceAssociation bindAptxNodes = new LoadedTreeSequenceAssociation( jalviewAlignport.getAlignment().getSequencesArray(), aptxTree); bindAptxNodes.associateLeavesToSequences(); @@ -540,13 +547,62 @@ public final class AptxInit } + /** + * Hides certain redundant Archaeopteryx GUI elements such as the menu items + * for reading in trees and adds extra items related to Jalview such as the + * tree sorting item. + * + * + * @param aptxFrame + */ + private static void adaptAptxGui(MainFrame aptxFrame) + { + JMenuBar frameBar = aptxFrame.getJMenuBar(); + + for (int i = 0; i < frameBar.getMenuCount();i++) { + JMenu menu = frameBar.getMenu(i); + + if (menu.getText().contains("File")) + { + // hide all "Read from ..." and "New" menu items and any Separators that + // come directly after them + Component previousMenuItem = null; + for (Component menuItem : menu.getMenuComponents()) { + if (previousMenuItem instanceof JMenuItem) + { + if (((JMenuItem) previousMenuItem).getText().startsWith("Read") + || ((JMenuItem) previousMenuItem).getText() + .startsWith("New")) + { + previousMenuItem.setVisible(false); + + if (menuItem instanceof JSeparator) + { + menuItem.setVisible(false); + } + } + } + previousMenuItem = menuItem; + } + } + else if (menu.getText().contains("Inference")) + { + menu.setVisible(false); + } + else if (menu.getText().contains("View")) + { + menu.addSeparator(); + menu.add(new JMenuItem("Sort alignment by tree")); + } + + } + aptxFrame.validate(); + } + public static Map getAllAptxFrames() { return activeAptx; } - private static void disableRedundantGuiMenus() - { - } } -- 1.7.10.2