From: Jim Procter Date: Mon, 18 Oct 2021 12:18:59 +0000 (+0100) Subject: JAL-3904 override buildActionMenu to add in additional menu actions after rebuild X-Git-Tag: Release_2_11_2_1~75^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8f08ed712138cea8987594a62b6053a0bfdba327;p=jalview.git JAL-3904 override buildActionMenu to add in additional menu actions after rebuild --- diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index e3c65da..364a3b4 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -73,7 +73,10 @@ public class ChimeraViewFrame extends StructureViewerBase private int myHeight = 150; - /** + private JMenuItem writeFeatures=null; + + private JMenu fetchAttributes=null; +/** * Initialise menu options. */ @Override @@ -84,7 +87,7 @@ public class ChimeraViewFrame extends StructureViewerBase savemenu.setVisible(false); // not yet implemented viewMenu.add(fitToWindow); - JMenuItem writeFeatures = new JMenuItem( + writeFeatures = new JMenuItem( MessageManager.getString("label.create_viewer_attributes")); writeFeatures.setToolTipText(MessageManager .getString("label.create_viewer_attributes_tip")); @@ -98,7 +101,7 @@ public class ChimeraViewFrame extends StructureViewerBase }); viewerActionMenu.add(writeFeatures); - final JMenu fetchAttributes = new JMenu( + fetchAttributes = new JMenu( MessageManager.getString("label.fetch_chimera_attributes")); fetchAttributes.setToolTipText( MessageManager.getString("label.fetch_chimera_attributes_tip")); @@ -113,7 +116,15 @@ public class ChimeraViewFrame extends StructureViewerBase }); viewerActionMenu.add(fetchAttributes); } - + @Override + protected void buildActionMenu() + { + super.buildActionMenu(); + // add these back in after menu is refreshed + viewerActionMenu.add(writeFeatures); + viewerActionMenu.add(fetchAttributes); + + }; /** * Query the structure viewer for its residue attribute names and add them as * items off the attributes menu diff --git a/src/jalview/gui/PymolViewer.java b/src/jalview/gui/PymolViewer.java index c5a4c9a..8dd2fc0 100644 --- a/src/jalview/gui/PymolViewer.java +++ b/src/jalview/gui/PymolViewer.java @@ -348,7 +348,7 @@ public class PymolViewer extends StructureViewerBase { return "PyMOL"; } - + JMenuItem writeFeatures = null; @Override protected void initMenus() { @@ -357,7 +357,7 @@ public class PymolViewer extends StructureViewerBase savemenu.setVisible(false); // not yet implemented viewMenu.add(fitToWindow); - JMenuItem writeFeatures = new JMenuItem( + writeFeatures = new JMenuItem( MessageManager.getString("label.create_viewer_attributes")); writeFeatures.setToolTipText(MessageManager .getString("label.create_viewer_attributes_tip")); @@ -371,6 +371,13 @@ public class PymolViewer extends StructureViewerBase }); viewerActionMenu.add(writeFeatures); } + + @Override + protected void buildActionMenu() + { + super.buildActionMenu(); + viewerActionMenu.add(writeFeatures); + } protected void sendFeaturesToPymol() { diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index f5d350c..4f746cb 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -221,6 +221,10 @@ public abstract class StructureViewerBase extends GStructureViewer _alignwith.add(ap); } ; + // TODO: refactor to allow concrete classes to register buttons for adding + // here + // currently have to override to add buttons back in after they are cleared + // in this loop for (Component c : viewerActionMenu.getMenuComponents()) { if (c != alignStructs) @@ -1279,6 +1283,8 @@ public abstract class StructureViewerBase extends GStructureViewer @Override public boolean hasViewerActionsMenu() { - return viewerActionMenu!=null && viewerActionMenu.isEnabled() && viewerActionMenu.getItemCount()>0 && viewerActionMenu.isVisible(); + return viewerActionMenu != null && viewerActionMenu.isEnabled() + && viewerActionMenu.getItemCount() > 0 + && viewerActionMenu.isVisible(); } }