From c3b8fbc19c04c2daec702a2bffdfab5d10555143 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Thu, 10 Nov 2016 11:56:51 +0000 Subject: [PATCH] Bugfix to enable accurate chain extraction/association with models loaded in Chimera, refactored and factorised some duplicated codes with Jmol viewer implementation. --- src/jalview/appletgui/AppletJmol.java | 6 +- src/jalview/appletgui/AppletJmolBinding.java | 7 +- src/jalview/appletgui/ExtJmol.java | 7 +- src/jalview/datamodel/PDBEntry.java | 10 -- src/jalview/ext/jmol/JalviewJmolBinding.java | 16 ++- .../ext/rbvi/chimera/JalviewChimeraBinding.java | 56 ++++------ src/jalview/gui/AppJmol.java | 57 +--------- src/jalview/gui/AppJmolBinding.java | 8 +- src/jalview/gui/ChimeraViewFrame.java | 111 ++++---------------- src/jalview/gui/JalviewChimeraBindingModel.java | 10 +- src/jalview/gui/StructureViewerBase.java | 60 +++++++++++ .../structures/models/AAStructureBindingModel.java | 15 +-- .../models/AAStructureBindingModelTest.java | 9 +- 13 files changed, 155 insertions(+), 217 deletions(-) diff --git a/src/jalview/appletgui/AppletJmol.java b/src/jalview/appletgui/AppletJmol.java index b925284..133cc94 100644 --- a/src/jalview/appletgui/AppletJmol.java +++ b/src/jalview/appletgui/AppletJmol.java @@ -180,7 +180,7 @@ public class AppletJmol extends EmbmenuFrame implements this.ap = ap; jmb = new AppletJmolBinding(this, ap.getStructureSelectionManager(), new PDBEntry[] { pdbentry }, new SequenceI[][] { seq }, - new String[][] { chains }, protocol); + protocol); jmb.setColourBySequence(true); if (pdbentry.getId() == null || pdbentry.getId().length() < 1) { @@ -369,7 +369,7 @@ public class AppletJmol extends EmbmenuFrame implements jmb.loadInline(string); } - void setChainMenuItems(Vector chains) + void setChainMenuItems(List chains) { chainMenu.removeAll(); @@ -588,7 +588,7 @@ public class AppletJmol extends EmbmenuFrame implements repaint(); return; } - setChainMenuItems(jmb.chainNames); + setChainMenuItems(jmb.getChainNames()); jmb.colourBySequence(ap); setTitle(jmb.getViewerTitle()); diff --git a/src/jalview/appletgui/AppletJmolBinding.java b/src/jalview/appletgui/AppletJmolBinding.java index 6ec5b4d..3a36ed5 100644 --- a/src/jalview/appletgui/AppletJmolBinding.java +++ b/src/jalview/appletgui/AppletJmolBinding.java @@ -45,9 +45,9 @@ class AppletJmolBinding extends JalviewJmolBinding public AppletJmolBinding(AppletJmol appletJmol, StructureSelectionManager sSm, PDBEntry[] pdbentry, - SequenceI[][] seq, String[][] chains, String protocol) + SequenceI[][] seq, String protocol) { - super(sSm, pdbentry, seq, chains, protocol); + super(sSm, pdbentry, seq, protocol); appletJmolBinding = appletJmol; } @@ -113,12 +113,14 @@ class AppletJmolBinding extends JalviewJmolBinding appletJmolBinding.updateTitleAndMenus(); } + @Override public void updateColours(Object source) { AlignmentPanel ap = (AlignmentPanel) source; colourBySequence(ap); } + @Override public void showUrl(String url) { try @@ -143,6 +145,7 @@ class AppletJmolBinding extends JalviewJmolBinding // do nothing. } + @Override public void selectionChanged(BS arg0) { // TODO Auto-generated method stub diff --git a/src/jalview/appletgui/ExtJmol.java b/src/jalview/appletgui/ExtJmol.java index 929a871..5ffbaa4 100644 --- a/src/jalview/appletgui/ExtJmol.java +++ b/src/jalview/appletgui/ExtJmol.java @@ -49,11 +49,11 @@ public class ExtJmol extends JalviewJmolBinding private AlignmentPanel ap; protected ExtJmol(jalview.appletgui.AlignFrame alframe, - PDBEntry[] pdbentry, SequenceI[][] seq, String[][] chains, + PDBEntry[] pdbentry, SequenceI[][] seq, String protocol) { super(alframe.alignPanel.getStructureSelectionManager(), pdbentry, seq, - chains, protocol); + protocol); } public ExtJmol(Viewer viewer, AlignmentPanel alignPanel, @@ -64,6 +64,7 @@ public class ExtJmol extends JalviewJmolBinding notifyFileLoaded(null, null, null, null, 0); } + @Override public void updateColours(Object source) { @@ -71,6 +72,7 @@ public class ExtJmol extends JalviewJmolBinding } + @Override public void showUrl(String arg0) { showUrl(arg0, "jmol"); @@ -126,6 +128,7 @@ public class ExtJmol extends JalviewJmolBinding // ignore } + @Override public void selectionChanged(BS arg0) { System.out.println(arg0); diff --git a/src/jalview/datamodel/PDBEntry.java b/src/jalview/datamodel/PDBEntry.java index 6a6ccd0..9c3a8e7 100755 --- a/src/jalview/datamodel/PDBEntry.java +++ b/src/jalview/datamodel/PDBEntry.java @@ -121,16 +121,6 @@ public class PDBEntry { } - /** - * Constructor given file path and PDB id. - * - * @param filePath - */ - // public PDBEntry(String filePath, String pdbId) - // { - // this.file = filePath; - // this.id = pdbId; - // } public PDBEntry(String pdbId, String chain, PDBEntry.Type type, String filePath) diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index fbac400..abebcf7 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -74,7 +74,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel Vector atomsPicked = new Vector(); - public Vector chainNames; + private List chainNames; Hashtable chainFile; @@ -99,10 +99,10 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel public Viewer viewer; public JalviewJmolBinding(StructureSelectionManager ssm, - PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains, + PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String protocol) { - super(ssm, pdbentry, sequenceIs, chains, protocol); + super(ssm, pdbentry, sequenceIs, protocol); /* * viewer = JmolViewer.allocateViewer(renderPanel, new SmarterJmolAdapter(), * "jalviewJmol", ap.av.applet .getDocumentBase(), @@ -1083,7 +1083,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel fileLoadingError = null; String[] oldmodels = modelFileNames; modelFileNames = null; - chainNames = new Vector(); + chainNames = new ArrayList(); chainFile = new Hashtable(); boolean notifyLoaded = false; String[] modelfilenames = getPdbFile(); @@ -1194,7 +1194,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel String chid = new String(pdb.getId() + ":" + pdb.getChains().elementAt(i).id); chainFile.put(chid, fileName); - chainNames.addElement(chid); + chainNames.add(chid); } notifyLoaded = true; } @@ -1242,6 +1242,12 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel setLoadingFromArchive(false); } + @Override + public List getChainNames() + { + return chainNames; + } + public void notifyNewPickingModeMeasurement(int iatom, String strMeasure) { notifyAtomPicked(iatom, strMeasure, null); diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index 7ba9186..4c7334f 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -40,6 +40,7 @@ import jalview.util.MessageManager; import java.awt.Color; import java.net.BindException; import java.util.ArrayList; +import java.util.Hashtable; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -63,6 +64,9 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel private static final String ALPHACARBON = "CA"; + private List chainNames = new ArrayList(); + + private Hashtable chainFile = new Hashtable(); /* * Object through which we talk to Chimera */ @@ -191,10 +195,9 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel * @param protocol */ public JalviewChimeraBinding(StructureSelectionManager ssm, - PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains, - String protocol) + PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String protocol) { - super(ssm, pdbentry, sequenceIs, chains, protocol); + super(ssm, pdbentry, sequenceIs, protocol); viewer = new ChimeraManager( new ext.edu.ucsf.rbvi.strucviz2.StructureManager(true)); } @@ -758,18 +761,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel { return new String[0]; } - // if (modelFileNames == null) - // { - // Collection chimodels = viewer.getChimeraModels(); - // _modelFileNameMap = new int[chimodels.size()]; - // int j = 0; - // for (ChimeraModel chimodel : chimodels) - // { - // String mdlName = chimodel.getModelName(); - // } - // modelFileNames = new String[j]; - // // System.arraycopy(mset, 0, modelFileNames, 0, j); - // } return chimeraMaps.keySet().toArray( modelFileNames = new String[chimeraMaps.size()]); @@ -1067,28 +1058,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel * * @return */ - public List getChainNames() - { - List names = new ArrayList(); - String[][] allNames = getChains(); - if (allNames != null) - { - for (String[] chainsForPdb : allNames) - { - if (chainsForPdb != null) - { - for (String chain : chainsForPdb) - { - if (chain != null && !names.contains(chain)) - { - names.add(chain); - } - } - } - } - } - return names; - } /** * Send a 'focus' command to Chimera to recentre the visible display @@ -1125,4 +1094,17 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel sm.highlightStructure(this, seq, positions); } } + + + @Override + public List getChainNames() + { + return chainNames; + } + + public Hashtable getChainFile() + { + return chainFile; + } + } diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index 1c0dfe6..d7e8305 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -50,7 +50,6 @@ import java.awt.Font; import java.awt.Graphics; import java.awt.Rectangle; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.io.BufferedReader; @@ -67,7 +66,6 @@ import javax.swing.JCheckBoxMenuItem; import javax.swing.JColorChooser; import javax.swing.JInternalFrame; import javax.swing.JMenu; -import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JSplitPane; @@ -131,7 +129,7 @@ public class AppJmol extends StructureViewerBase // / TODO: check if protocol is needed to be set, and if chains are // autodiscovered. jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), - pdbentrys, seqs, null, null); + pdbentrys, seqs, null); jmb.setLoadingFromArchive(true); addAlignmentPanel(ap); @@ -301,7 +299,7 @@ public class AppJmol extends StructureViewerBase { progressBar = ap.alignFrame; jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), - pdbentrys, seqs, null, null); + pdbentrys, seqs, null); addAlignmentPanel(ap); useAlignmentPanelForColourbyseq(ap); if (pdbentrys.length > 1) @@ -394,57 +392,12 @@ public class AppJmol extends StructureViewerBase jmb.setFinishedInit(true); } - void setChainMenuItems(Vector chains) - { - chainMenu.removeAll(); - if (chains == null) - { - return; - } - JMenuItem menuItem = new JMenuItem( - MessageManager.getString("label.all")); - menuItem.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent evt) - { - allChainsSelected = true; - for (int i = 0; i < chainMenu.getItemCount(); i++) - { - if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem) - { - ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true); - } - } - centerViewer(); - allChainsSelected = false; - } - }); - - chainMenu.add(menuItem); - - for (String chain : chains) - { - menuItem = new JCheckBoxMenuItem(chain, true); - menuItem.addItemListener(new ItemListener() - { - @Override - public void itemStateChanged(ItemEvent evt) - { - if (!allChainsSelected) - { - centerViewer(); - } - } - }); - chainMenu.add(menuItem); - } - } boolean allChainsSelected = false; - void centerViewer() + @Override + void showSelectedChains() { Vector toshow = new Vector(); for (int i = 0; i < chainMenu.getItemCount(); i++) @@ -1075,7 +1028,7 @@ public class AppJmol extends StructureViewerBase repaint(); return; } - setChainMenuItems(jmb.chainNames); + setChainMenuItems(jmb.getChainNames()); this.setTitle(jmb.getViewerTitle()); if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1) diff --git a/src/jalview/gui/AppJmolBinding.java b/src/jalview/gui/AppJmolBinding.java index 1c54a5e..546890e 100644 --- a/src/jalview/gui/AppJmolBinding.java +++ b/src/jalview/gui/AppJmolBinding.java @@ -41,10 +41,9 @@ public class AppJmolBinding extends JalviewJmolBinding private FeatureRenderer fr = null; public AppJmolBinding(AppJmol appJmol, StructureSelectionManager sSm, - PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains, - String protocol) + PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String protocol) { - super(sSm, pdbentry, sequenceIs, chains, protocol); + super(sSm, pdbentry, sequenceIs, protocol); appJmolWindow = appJmol; } @@ -113,6 +112,7 @@ public class AppJmolBinding extends JalviewJmolBinding // appJmolWindow.repaint(); javax.swing.SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { appJmolWindow.updateTitleAndMenus(); @@ -121,6 +121,7 @@ public class AppJmolBinding extends JalviewJmolBinding }); } + @Override public void updateColours(Object source) { AlignmentPanel ap = (AlignmentPanel) source; @@ -144,6 +145,7 @@ public class AppJmolBinding extends JalviewJmolBinding // msWalltime); } + @Override public void showUrl(String url) { showUrl(url, "jmol"); diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index ce719d0..fe12f40 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -31,6 +31,7 @@ import jalview.gui.StructureViewer.ViewerType; import jalview.io.AppletFormatAdapter; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; +import jalview.io.StructureFile; import jalview.schemes.BuriedColourScheme; import jalview.schemes.ColourSchemeI; import jalview.schemes.HelixColourScheme; @@ -46,7 +47,6 @@ import jalview.util.Platform; import jalview.ws.dbsources.Pdb; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.io.BufferedReader; @@ -66,7 +66,6 @@ import javax.swing.JCheckBoxMenuItem; import javax.swing.JColorChooser; import javax.swing.JInternalFrame; import javax.swing.JMenu; -import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameEvent; @@ -248,10 +247,8 @@ public class ChimeraViewFrame extends StructureViewerBase { createProgressBar(); // FIXME extractChains needs pdbentries to match IDs to PDBEntry(s) on seqs - String[][] chains = extractChains(seqs); jmb = new JalviewChimeraBindingModel(this, - ap.getStructureSelectionManager(), pdbentrys, seqs, chains, - null); + ap.getStructureSelectionManager(), pdbentrys, seqs, null); addAlignmentPanel(ap); useAlignmentPanelForColourbyseq(ap); if (pdbentrys.length > 1) @@ -278,41 +275,7 @@ public class ChimeraViewFrame extends StructureViewerBase } - /** - * Retrieve chains for sequences by inspecting their PDB refs. The hope is - * that the first will be to the sequence's own chain. Really need a more - * managed way of doing this. - * - * @param seqs - * @return - */ - protected String[][] extractChains(SequenceI[][] seqs) - { - String[][] chains = new String[seqs.length][]; - for (int i = 0; i < seqs.length; i++) - { - chains[i] = new String[seqs[i].length]; - int seqno = 0; - for (SequenceI seq : seqs[i]) - { - String chain = null; - if (seq.getDatasetSequence() != null) - { - Vector pdbrefs = seq.getDatasetSequence() - .getAllPDBEntries(); - if (pdbrefs != null && pdbrefs.size() > 0) - { - // FIXME: SequenceI.PDBEntry[0] chain mapping used for - // ChimeraViewFrame. Is this even used ??? - chain = pdbrefs.get(0).getChainCode(); - } - } - chains[i][seqno++] = chain; - } - } - return chains; - } /** * Create a new viewer from saved session state data including Chimera session @@ -437,63 +400,11 @@ public class ChimeraViewFrame extends StructureViewerBase jmb.startChimeraListener(); } - /** - * If the list is not empty, add menu items for 'All' and each individual - * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed. - * - * @param chainNames - */ - void setChainMenuItems(List chainNames) - { - chainMenu.removeAll(); - if (chainNames == null || chainNames.isEmpty()) - { - return; - } - JMenuItem menuItem = new JMenuItem( - MessageManager.getString("label.all")); - menuItem.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent evt) - { - allChainsSelected = true; - for (int i = 0; i < chainMenu.getItemCount(); i++) - { - if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem) - { - ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true); - } - } - showSelectedChains(); - allChainsSelected = false; - } - }); - - chainMenu.add(menuItem); - - for (String chainName : chainNames) - { - menuItem = new JCheckBoxMenuItem(chainName, true); - menuItem.addItemListener(new ItemListener() - { - @Override - public void itemStateChanged(ItemEvent evt) - { - if (!allChainsSelected) - { - showSelectedChains(); - } - } - }); - - chainMenu.add(menuItem); - } - } /** * Show only the selected chain(s) in the viewer */ + @Override void showSelectedChains() { List toshow = new ArrayList(); @@ -569,6 +480,7 @@ public class ChimeraViewFrame extends StructureViewerBase List filePDB = new ArrayList(); List filePDBpos = new ArrayList(); PDBEntry thePdbEntry = null; + StructureFile pdb = null; try { String[] curfiles = jmb.getPdbFile(); // files currently in viewer @@ -677,8 +589,9 @@ public class ChimeraViewFrame extends StructureViewerBase stopProgressBar("", startTime); } // Explicitly map to the filename used by Chimera ; - jmb.getSsm().setMapping(jmb.getSequence()[pos], + pdb = jmb.getSsm().setMapping(jmb.getSequence()[pos], jmb.getChains()[pos], pe.getFile(), protocol); + stashFoundChains(pdb, pe.getFile()); } catch (OutOfMemoryError oomerror) { new OOMWarning( @@ -694,6 +607,7 @@ public class ChimeraViewFrame extends StructureViewerBase } } } + jmb.refreshGUI(); jmb.setFinishedInit(true); jmb.setLoadingFromArchive(false); @@ -729,6 +643,17 @@ public class ChimeraViewFrame extends StructureViewerBase * @return * @throws Exception */ + + private void stashFoundChains(StructureFile pdb, String file) + { + for (int i = 0; i < pdb.getChains().size(); i++) + { + String chid = new String(pdb.getId() + ":" + + pdb.getChains().elementAt(i).id); + jmb.getChainNames().add(chid); + jmb.getChainFile().put(chid, file); + } + } private String fetchPdbFile(PDBEntry processingEntry) throws Exception { // FIXME: this is duplicated code with Jmol frame ? diff --git a/src/jalview/gui/JalviewChimeraBindingModel.java b/src/jalview/gui/JalviewChimeraBindingModel.java index 7a54732..78ab68d 100644 --- a/src/jalview/gui/JalviewChimeraBindingModel.java +++ b/src/jalview/gui/JalviewChimeraBindingModel.java @@ -32,11 +32,12 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding private FeatureRenderer fr = null; + public JalviewChimeraBindingModel(ChimeraViewFrame chimeraViewFrame, StructureSelectionManager ssm, PDBEntry[] pdbentry, - SequenceI[][] sequenceIs, String[][] chains, String protocol) + SequenceI[][] sequenceIs, String protocol) { - super(ssm, pdbentry, sequenceIs, chains, protocol); + super(ssm, pdbentry, sequenceIs, protocol); cvf = chimeraViewFrame; } @@ -72,6 +73,7 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding { javax.swing.SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { cvf.updateTitleAndMenus(); @@ -80,6 +82,7 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding }); } + @Override public void updateColours(Object source) { AlignmentPanel ap = (AlignmentPanel) source; @@ -113,6 +116,7 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding * Send an asynchronous command to Chimera, in a new thread, optionally with * an 'in progress' message in a progress bar somewhere */ + @Override protected void sendAsynchronousCommand(final String command, final String progressMsg) { @@ -135,4 +139,6 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding thread.start(); } + + } diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index 7df42fd..4715e48 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -30,10 +30,15 @@ import jalview.structures.models.AAStructureBindingModel; import jalview.util.MessageManager; import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.util.ArrayList; import java.util.List; import java.util.Vector; +import javax.swing.JCheckBoxMenuItem; import javax.swing.JMenuItem; import javax.swing.JOptionPane; @@ -76,6 +81,8 @@ public abstract class StructureViewerBase extends GStructureViewer protected Thread worker = null; + protected boolean allChainsSelected = false; + /** * * @param ap2 @@ -152,6 +159,7 @@ public abstract class StructureViewerBase extends GStructureViewer this.ap = alp; } + @Override public AlignmentPanel[] getAllAlignmentPanels() { AlignmentPanel[] t, list = new AlignmentPanel[0]; @@ -291,6 +299,7 @@ public abstract class StructureViewerBase extends GStructureViewer // queue. new Thread(new Runnable() { + @Override public void run() { while (worker != null && worker.isAlive() && _started) @@ -492,4 +501,55 @@ public abstract class StructureViewerBase extends GStructureViewer } return finished; } + + void setChainMenuItems(List chainNames) + { + chainMenu.removeAll(); + if (chainNames == null || chainNames.isEmpty()) + { + return; + } + JMenuItem menuItem = new JMenuItem( + MessageManager.getString("label.all")); + menuItem.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent evt) + { + allChainsSelected = true; + for (int i = 0; i < chainMenu.getItemCount(); i++) + { + if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem) + { + ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true); + } + } + showSelectedChains(); + allChainsSelected = false; + } + }); + + chainMenu.add(menuItem); + + for (String chain : chainNames) + { + menuItem = new JCheckBoxMenuItem(chain, true); + menuItem.addItemListener(new ItemListener() + { + @Override + public void itemStateChanged(ItemEvent evt) + { + if (!allChainsSelected) + { + showSelectedChains(); + } + } + }); + + chainMenu.add(menuItem); + } + } + + abstract void showSelectedChains(); + } diff --git a/src/jalview/structures/models/AAStructureBindingModel.java b/src/jalview/structures/models/AAStructureBindingModel.java index b00f1bc..5dc3465 100644 --- a/src/jalview/structures/models/AAStructureBindingModel.java +++ b/src/jalview/structures/models/AAStructureBindingModel.java @@ -135,19 +135,14 @@ public abstract class AAStructureBindingModel extends * @param protocol */ public AAStructureBindingModel(StructureSelectionManager ssm, - PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains, + PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String protocol) { this.ssm = ssm; this.sequence = sequenceIs; this.nucleotide = Comparison.isNucleotide(sequenceIs); - this.chains = chains; this.pdbEntry = pdbentry; this.protocol = protocol; - if (chains == null) - { - this.chains = new String[pdbentry.length][]; - } } public StructureSelectionManager getSsm() @@ -674,4 +669,12 @@ public abstract class AAStructureBindingModel extends { this.finishedInit = fi; } + + /** + * Returns a list of chains mapped in this viewer. + * + * @return + */ + public abstract List getChainNames(); + } diff --git a/test/jalview/structures/models/AAStructureBindingModelTest.java b/test/jalview/structures/models/AAStructureBindingModelTest.java index 0d00169..66e0152 100644 --- a/test/jalview/structures/models/AAStructureBindingModelTest.java +++ b/test/jalview/structures/models/AAStructureBindingModelTest.java @@ -104,7 +104,6 @@ public class AAStructureBindingModelTest pdbFiles[0] = new PDBEntry("1YCS", "A", Type.PDB, "INLINE1YCS"); pdbFiles[1] = new PDBEntry("3A6S", "B", Type.PDB, "INLINE3A6S"); pdbFiles[2] = new PDBEntry("1OOT", "A", Type.PDB, "INLINE1OOT"); - String[][] chains = new String[3][]; SequenceI[][] seqs = new SequenceI[3][]; seqs[0] = new SequenceI[] { seq1a, seq1b }; seqs[1] = new SequenceI[] { seq2 }; @@ -118,7 +117,7 @@ public class AAStructureBindingModelTest ssm.setMapping(new SequenceI[] { seq3 }, null, PDB_3, AppletFormatAdapter.PASTE); - testee = new AAStructureBindingModel(ssm, pdbFiles, seqs, chains, null) + testee = new AAStructureBindingModel(ssm, pdbFiles, seqs, null) { @Override public String[] getPdbFile() @@ -140,6 +139,12 @@ public class AAStructureBindingModelTest public void highlightAtoms(List atoms) { } + + @Override + public List getChainNames() + { + return null; + } }; } -- 1.7.10.2