X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FStructureViewerBase.java;h=d7d01ca7085f531fe2d487a89aed906dbe32239e;hb=ab506fbc0fa234dc7ce44e1d2af4944df734fe2c;hp=91d71309c7c57ff198eb650efd0310aed15ab70a;hpb=8f3b3ddf42faa51a857e4483a4177412f64f7600;p=jalview.git diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index 91d7130..d7d01ca 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -35,12 +35,13 @@ import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Vector; import javax.swing.JCheckBoxMenuItem; +import javax.swing.JMenu; import javax.swing.JMenuItem; -import javax.swing.JOptionPane; /** * Base class with common functionality for JMol, Chimera or other structure @@ -52,6 +53,10 @@ import javax.swing.JOptionPane; public abstract class StructureViewerBase extends GStructureViewer implements Runnable, ViewSetProvider { + /* + * prefix for attributes on structure which are derived from Jalview features + */ + public static final String NAMESPACE_PREFIX = "jv_"; /** * list of sequenceSet ids associated with the view @@ -552,4 +557,64 @@ public abstract class StructureViewerBase extends GStructureViewer abstract void showSelectedChains(); + /** + * Send a command to the structure viewer to create residue attributes for + * Jalview features + */ + abstract protected void sendFeaturesToViewer(); + + /** + * Query the structure viewer for its residue attribute names and add them as + * sub-items of the attributes menu. Names of the form "jv_*" are ignored as + * these originated from Jalview so no need to copy them back. + * + * @param attributesMenu + */ + protected void buildAttributesMenu(JMenu attributesMenu) + { + List atts = getResidueAttributeNames(); + if (atts == null) + { + return; + } + attributesMenu.removeAll(); + Collections.sort(atts); + for (final String att : atts) + { + /* + * ignore 'jv_*' attributes, as these are Jalview features that have + * been transferred to residue attributes in Chimera! + */ + if (!att.startsWith(StructureViewerBase.NAMESPACE_PREFIX)) + { + JMenuItem menuItem = new JMenuItem(att); + menuItem.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + getResidueAttributes(att); + } + }); + attributesMenu.add(menuItem); + } + } + } + + /** + * Queries the structure viewer for residues with the given attribute, and + * creates sequence features in Jalview for the corresponding mapped positions + * + * @param attName + */ + protected abstract void getResidueAttributes(String attName); + + /** + * Returns a list of residue attributes in the structure viewer, excluding any + * with prefix "jv_" + * + * @return + */ + protected abstract List getResidueAttributeNames(); + }