import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.Vector;
public abstract class StructureViewerBase extends GStructureViewer
implements Runnable, ViewSetProvider
{
+ private static final String UNMAPPED = "(unmapped)";
+
/*
* names for colour options (additional to Jalview colour schemes)
*/
}
@Override
- public boolean isUsedForColourBy(AlignmentViewPanel ap2)
+ public boolean isUsedForColourBy(AlignmentViewPanel avp)
{
- return (_colourwith != null) && _colourwith.contains(ap2);
+ return (_colourwith != null) && _colourwith.contains(avp);
}
/**
{
return;
}
+
+ /*
+ * add the 'All' menu item
+ */
JMenuItem menuItem = new JMenuItem(
MessageManager.getString("label.all"));
menuItem.addActionListener(new ActionListener()
allChainsSelected = false;
}
});
-
chainMenu.add(menuItem);
+ /*
+ * add a menu item for each structure and chain
+ */
+ Collections.sort(chainNames);
for (String chain : chainNames)
{
- menuItem = new JCheckBoxMenuItem(chain, true);
+ String seqName = getSequenceNameForChain(chain);
+ if (seqName == null)
+ {
+ seqName = UNMAPPED;
+ }
+ int nameLength = seqName.length();
+ if (nameLength > 16)
+ {
+ seqName = seqName.substring(0, 8) + "..."
+ + seqName.substring(nameLength - 8, nameLength);
+ }
+ String text = chain + " " + seqName;
+ menuItem = new JCheckBoxMenuItem(text, true);
menuItem.addItemListener(new ItemListener()
{
@Override
}
/**
+ * Answers the name of the sequence mapped to the given chain (formatted as
+ * pdbId:chainId, e.g. 1A70:A). Answers null if no mapped sequence is found. If
+ * more than one sequence is matched, just answers the name of the first one
+ * found.
+ *
+ * @param chain
+ * @return
+ */
+ private String getSequenceNameForChain(String chain)
+ {
+ String[] tokens = chain.split(":");
+ String pdbId = tokens[0];
+ String chainId = tokens[1];
+ List<StructureMapping> mappings = getBinding().getSsm()
+ .getMappingForChain(pdbId, chainId);
+ return mappings.isEmpty() ? null
+ : mappings.get(0).getSequence().getName();
+ }
+
+ /**
* Action on selecting one of Jalview's registered colour schemes
*/
@Override
});
viewMenu.add(seqColourBy);
+ showAlignmentOnly = new JCheckBoxMenuItem(
+ MessageManager.getString("label.show_alignment_only"));
+ showAlignmentOnly.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ hideHiddenRegions.setEnabled(showAlignmentOnly.isSelected());
+ getBinding().setShowAlignmentOnly(showAlignmentOnly.isSelected());
+ getBinding().showStructures(getAlignmentPanel().getAlignViewport(),
+ true);
+ }
+ });
+ viewMenu.add(showAlignmentOnly);
+
+ hideHiddenRegions = new JCheckBoxMenuItem(
+ MessageManager.getString("label.hide_hidden_regions"));
+ hideHiddenRegions.setEnabled(false);
+ hideHiddenRegions.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ getBinding().setHideHiddenRegions(hideHiddenRegions.isSelected());
+ getBinding().showStructures(getAlignmentPanel().getAlignViewport(),
+ false);
+ }
+ });
+ viewMenu.add(hideHiddenRegions);
+ viewMenu.add(fitToWindow);
+
final ItemListener handler = new ItemListener()
{
@Override
}
} catch (Exception e)
{
- StringBuffer sp = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
for (AlignmentViewPanel alignPanel : _alignwith)
{
- sp.append("'" + alignPanel.getViewName() + "' ");
+ sb.append("'").append(alignPanel.getViewName()).append("' ");
}
- Cache.log.info("Couldn't align structures with the " + sp.toString()
+ Cache.log.info("Couldn't align structures with the " + sb.toString()
+ "associated alignment panels.", e);
}
return reply;
}
}
// Set the colour using the current view for the associated alignframe
- for (AlignmentViewPanel alignPanel : _colourwith)
+ for (AlignmentViewPanel avp : _colourwith)
{
- binding.colourBySequence(alignPanel);
+ binding.updateStructureColours(avp);
}
seqColoursApplied = true;
}
}
@Override
+ public abstract AAStructureBindingModel getBinding();
+
+ /**
+ * Show only the selected chain(s) in the viewer
+ */
+ protected void showSelectedChains()
+ {
+ setChainsToHide();
+
+ /*
+ * refresh display without resizing - easier to see what changed
+ */
+ getBinding().showStructures(getAlignmentPanel().getAlignViewport(),
+ false);
+ }
+
+ @Override
public long startProgressBar(String msg)
{
// TODO would rather have startProgress/stopProgress as the
}
/**
- * Show only the selected chain(s) in the viewer
- */
- protected void showSelectedChains()
- {
- List<String> toshow = new ArrayList<>();
- for (int i = 0; i < chainMenu.getItemCount(); i++)
- {
- if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
- {
- JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
- if (item.isSelected())
- {
- toshow.add(item.getText());
- }
- }
- }
- getBinding().showChains(toshow);
- }
-
- /**
* Tries to fetch a PDB file and save to a temporary local file. Returns the
* saved file path if successful, or null if not.
*