From 2afbc744f6769674e1af81918206526d90a93b12 Mon Sep 17 00:00:00 2001 From: hansonr Date: Mon, 2 Jul 2018 17:55:00 +0100 Subject: [PATCH] JAL-3026 Java+JavaScript fix for GD#95 View...Features Settings... not disabled when there are no features. Involves an anonymous subclassing of JMenu for viewMenu that checks that there are features just before opening. GAlignFrame, with a call into AlignFrame for checking the viewport. --- src/jalview/gui/AlignFrame.java | 21 +++++++++++++++++++++ src/jalview/jbgui/GAlignFrame.java | 23 +++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index aa0a1fe..ee2875a 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -333,6 +333,27 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Desktop.getDesktop().propertyChange(evt); } + + /** + * BH 2018 + * + * @return true if we have any features + */ + @Override + protected boolean haveAlignmentFeatures() { + AlignmentI alignment = getViewport().getAlignment(); + + for (int i = 0; i < alignment.getHeight(); i++) + { + SequenceI seq = alignment.getSequenceAt(i); + for (String group : seq.getFeatures().getFeatureGroups(true)) + { + if (group != null)return true; + } + } + return false; + } + /** * initalise the alignframe from the underlying viewport data and the * configurations diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index a64030b..9fdc47c 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -196,6 +196,8 @@ public class GAlignFrame extends JInternalFrame protected JCheckBoxMenuItem normaliseSequenceLogo = new JCheckBoxMenuItem(); protected JCheckBoxMenuItem applyAutoAnnotationSettings = new JCheckBoxMenuItem(); + + protected JMenuItem openFeatureSettings; private SequenceAnnotationOrder annotationSortOrder; @@ -282,7 +284,17 @@ public class GAlignFrame extends JInternalFrame addMenuActionAndAccelerator(keyStroke, closeMenuItem, al); JMenu editMenu = new JMenu(MessageManager.getString("action.edit")); - JMenu viewMenu = new JMenu(MessageManager.getString("action.view")); + JMenu viewMenu = new JMenu(MessageManager.getString("action.view")) { + + public void setPopupMenuVisible(boolean b) { + if (b) { + System.out.println("openFeatureSettings " + haveAlignmentFeatures()); + openFeatureSettings.setEnabled(haveAlignmentFeatures()); + } + super.setPopupMenuVisible(b); + } + + }; JMenu annotationsMenu = new JMenu( MessageManager.getString("action.annotations")); JMenu showMenu = new JMenu(MessageManager.getString("action.show")); @@ -1279,8 +1291,9 @@ public class GAlignFrame extends JInternalFrame } }); - JMenuItem openFeatureSettings = new JMenuItem( + openFeatureSettings = new JMenuItem( MessageManager.getString("action.feature_settings")); + openFeatureSettings.setEnabled(false); openFeatureSettings.addActionListener(new ActionListener() { @Override @@ -1874,6 +1887,12 @@ public class GAlignFrame extends JInternalFrame // selectMenu.add(listenToViewSelections); } + protected boolean haveAlignmentFeatures() + { + // because gAlignFrame is not an abstract class -- see AlignFrame + return false; + } + protected void loadVcf_actionPerformed() { } -- 1.7.10.2