public void updateTitleAndMenus()
{
- if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
+ if (jmb.hasFileLoadingError())
{
repaint();
return;
*/
package jalview.ext.jmol;
-import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureRenderer;
import jalview.api.SequenceRenderer;
import jalview.datamodel.AlignmentI;
Hashtable<String, String> chainFile;
- public String fileLoadingError;
-
/*
* the default or current model displayed if the model cannot be identified
* from the selection message
* @param _hiddenCols
* an array of corresponding hidden columns for each alignment
*/
+ @Override
public void superposeStructures(AlignmentI[] _alignment,
int[] _refStructure, ColumnSelection[] _hiddenCols)
{
}
/**
- * colour any structures associated with sequences in the given alignment
- * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
- * if colourBySequence is enabled.
+ * Sends a set of colour commands to the structure viewer
+ *
+ * @param colourBySequenceCommands
*/
- public void colourBySequence(AlignmentViewPanel alignmentv)
+ @Override
+ protected void colourBySequence(
+ StructureMappingcommandSet[] colourBySequenceCommands)
{
- boolean showFeatures = alignmentv.getAlignViewport()
- .isShowSequenceFeatures();
- if (!colourBySequence || !isLoadingFinished())
- {
- return;
- }
- if (getSsm() == null)
- {
- return;
- }
- String[] files = getPdbFile();
-
- SequenceRenderer sr = getSequenceRenderer(alignmentv);
-
- FeatureRenderer fr = null;
- if (showFeatures)
- {
- fr = getFeatureRenderer(alignmentv);
- }
- AlignmentI alignment = alignmentv.getAlignment();
-
- for (jalview.structure.StructureMappingcommandSet cpdbbyseq : getColourBySequenceCommands(
- files, sr, fr, alignment))
+ for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands)
{
for (String cbyseq : cpdbbyseq.commands)
{
* @param alignment
* @return
*/
+ @Override
protected StructureMappingcommandSet[] getColourBySequenceCommands(
String[] files, SequenceRenderer sr, FeatureRenderer fr,
AlignmentI alignment)
}
/**
- * returns the current featureRenderer that should be used to colour the
- * structures
- *
- * @param alignment
- *
- * @return
- */
- public abstract FeatureRenderer getFeatureRenderer(
- AlignmentViewPanel alignment);
-
- /**
* instruct the Jalview binding to update the pdbentries vector if necessary
* prior to matching the jmol view's contents to the list of structure files
* Jalview knows about.
return null;
}
- /**
- * returns the current sequenceRenderer that should be used to colour the
- * structures
- *
- * @param alignment
- *
- * @return
- */
- public abstract SequenceRenderer getSequenceRenderer(
- AlignmentViewPanel alignment);
+
// ///////////////////////////////
// JmolStatusListener
}
+ @Override
public void setJalviewColourScheme(ColourSchemeI cs)
{
colourBySequence = false;
protected org.jmol.api.JmolAppConsoleInterface console = null;
+ @Override
public void setBackgroundColour(java.awt.Color col)
{
jmolHistory(false);
*/
private boolean loadingFinished = true;
- public String fileLoadingError;
-
/*
* Map of ChimeraModel objects keyed by PDB full local file name
*/
}
/**
- * Construct a title string for the viewer window based on the data Jalview
- * knows about
- *
- * @param verbose
- * @return
- */
- public String getViewerTitle(boolean verbose)
- {
- return getViewerTitle("Chimera", verbose);
- }
-
- /**
* Tells Chimera to display only the specified chains
*
* @param toshow
releaseUIResources();
}
+ @Override
public void colourByChain()
{
colourBySequence = false;
* <li>all others - white</li>
* </ul>
*/
+ @Override
public void colourByCharge()
{
colourBySequence = false;
* @param _hiddenCols
* an array of corresponding hidden columns for each alignment
*/
+ @Override
public void superposeStructures(AlignmentI[] _alignment,
int[] _refStructure, ColumnSelection[] _hiddenCols)
{
String progressMsg);
/**
- * colour any structures associated with sequences in the given alignment
- * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
- * if colourBySequence is enabled.
+ * Sends a set of colour commands to the structure viewer
+ *
+ * @param colourBySequenceCommands
*/
- public void colourBySequence(boolean showFeatures,
- jalview.api.AlignmentViewPanel alignmentv)
+ @Override
+ protected void colourBySequence(
+ StructureMappingcommandSet[] colourBySequenceCommands)
{
- if (!colourBySequence || !loadingFinished)
- {
- return;
- }
- if (getSsm() == null)
- {
- return;
- }
- String[] files = getPdbFile();
-
- SequenceRenderer sr = getSequenceRenderer(alignmentv);
-
- FeatureRenderer fr = null;
- if (showFeatures)
- {
- fr = getFeatureRenderer(alignmentv);
- }
- AlignmentI alignment = alignmentv.getAlignment();
-
- for (jalview.structure.StructureMappingcommandSet cpdbbyseq : getColourBySequenceCommands(
- files, sr, fr, alignment))
+ for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands)
{
for (String command : cpdbbyseq.commands)
{
* @param alignment
* @return
*/
+ @Override
protected StructureMappingcommandSet[] getColourBySequenceCommands(
String[] files, SequenceRenderer sr, FeatureRenderer fr,
AlignmentI alignment)
// //////////////////////////
/**
- * returns the current featureRenderer that should be used to colour the
- * structures
- *
- * @param alignment
- *
- * @return
- */
- public abstract FeatureRenderer getFeatureRenderer(
- AlignmentViewPanel alignment);
-
- /**
* instruct the Jalview binding to update the pdbentries vector if necessary
* prior to matching the viewer's contents to the list of structure files
* Jalview knows about.
*/
public abstract void refreshPdbEntries();
- private int getModelNum(String modelFileName)
- {
- String[] mfn = getPdbFile();
- if (mfn == null)
- {
- return -1;
- }
- for (int i = 0; i < mfn.length; i++)
- {
- if (mfn[i].equalsIgnoreCase(modelFileName))
- {
- return i;
- }
- }
- return -1;
- }
-
/**
* map between index of model filename returned from getPdbFile and the first
* index of models from this file in the viewer. Note - this is not trimmed -
}
/**
- * returns the current sequenceRenderer that should be used to colour the
- * structures
- *
- * @param alignment
- *
- * @return
- */
- public abstract SequenceRenderer getSequenceRenderer(
- AlignmentViewPanel alignment);
-
- /**
* Construct and send a command to highlight zero, one or more atoms. We do
* this by sending an "rlabel" command to show the residue label at that
* position.
return loadNotifiesHandled;
}
+ @Override
public void setJalviewColourScheme(ColourSchemeI cs)
{
colourBySequence = false;
* .html
* @param col
*/
+ @Override
public void setBackgroundColour(Color col)
{
viewerCommandHistory(false);
colourMenu.add(textColour);
colourMenu.addSeparator();
- ColourMenuHelper
- .addMenuItems(colourMenu, this, viewport.getAlignment());
+ ColourMenuHelper.addMenuItems(colourMenu, this,
+ viewport.getAlignment(), false);
colourMenu.addSeparator();
colourMenu.add(conservationMenuItem);
package jalview.gui;
import jalview.bin.Cache;
-import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
-import jalview.datamodel.ColumnSelection;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
import jalview.gui.StructureViewer.ViewerType;
-import jalview.io.JalviewFileChooser;
-import jalview.io.JalviewFileView;
-import jalview.schemes.BuriedColourScheme;
-import jalview.schemes.ColourSchemeI;
-import jalview.schemes.HelixColourScheme;
-import jalview.schemes.HydrophobicColourScheme;
-import jalview.schemes.PurinePyrimidineColourScheme;
-import jalview.schemes.StrandColourScheme;
-import jalview.schemes.TaylorColourScheme;
-import jalview.schemes.TurnColourScheme;
-import jalview.schemes.UserColourScheme;
-import jalview.schemes.ZappoColourScheme;
import jalview.structures.models.AAStructureBindingModel;
+import jalview.util.BrowserLauncher;
import jalview.util.MessageManager;
import jalview.util.Platform;
import jalview.ws.dbsources.Pdb;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.io.BufferedReader;
import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JColorChooser;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
-import javax.swing.event.MenuEvent;
-import javax.swing.event.MenuListener;
public class AppJmol extends StructureViewerBase
{
RenderPanel renderPanel;
- ViewSelectionMenu seqColourBy;
-
/**
*
* @param files
{
useAlignmentPanelForSuperposition(ap);
}
+ initMenus();
if (leaveColouringToJmol || !usetoColour)
{
jmb.setColourBySequence(false);
viewerColour.setSelected(false);
}
this.setBounds(bounds);
- initMenus();
setViewId(viewid);
// jalview.gui.Desktop.addInternalFrame(this, "Loading File",
// bounds.width,bounds.height);
}
});
initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
-
}
- private void initMenus()
+ @Override
+ protected void initMenus()
{
- seqColour.setSelected(jmb.isColourBySequence());
- viewerColour.setSelected(!jmb.isColourBySequence());
- if (_colourwith == null)
- {
- _colourwith = new Vector<AlignmentPanel>();
- }
- if (_alignwith == null)
- {
- _alignwith = new Vector<AlignmentPanel>();
- }
-
- seqColourBy = new ViewSelectionMenu(
- MessageManager.getString("label.colour_by"), this, _colourwith,
- new ItemListener()
- {
-
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- if (!seqColour.isSelected())
- {
- seqColour.doClick();
- }
- else
- {
- // update the jmol display now.
- seqColour_actionPerformed(null);
- }
- }
- });
- viewMenu.add(seqColourBy);
- final ItemListener handler;
- JMenu alpanels = new ViewSelectionMenu(
- MessageManager.getString("label.superpose_with"), this,
- _alignwith, handler = new ItemListener()
- {
+ super.initMenus();
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- alignStructs.setEnabled(_alignwith.size() > 0);
- alignStructs.setToolTipText(MessageManager
- .formatMessage(
- "label.align_structures_using_linked_alignment_views",
- new String[] { new Integer(_alignwith
- .size()).toString() }));
- }
- });
- handler.itemStateChanged(null);
- viewerActionMenu.add(alpanels);
- viewerActionMenu.addMenuListener(new MenuListener()
- {
+ viewerActionMenu = new JMenu(MessageManager.getString("label.jmol"));
- @Override
- public void menuSelected(MenuEvent e)
- {
- handler.itemStateChanged(null);
- }
-
- @Override
- public void menuDeselected(MenuEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void menuCanceled(MenuEvent e)
- {
- // TODO Auto-generated method stub
-
- }
- });
+ viewerColour
+ .setText(MessageManager.getString("label.colour_with_jmol"));
+ viewerColour.setToolTipText(MessageManager
+ .getString("label.let_jmol_manage_structure_colours"));
}
IProgressIndicator progressBar = null;
openNewJmol(ap, new PDBEntry[] { pdbentry }, new SequenceI[][] { seq });
}
- /**
- * Answers true if this viewer already involves the given PDB ID
- */
- @Override
- protected boolean hasPdbId(String pdbId)
- {
- return jmb.hasPdbId(pdbId);
- }
-
private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
SequenceI[][] seqs)
{
pdbentrys, seqs, null);
addAlignmentPanel(ap);
useAlignmentPanelForColourbyseq(ap);
+
if (pdbentrys.length > 1)
{
alignAddedStructures = true;
}
@Override
- public void pdbFile_actionPerformed(ActionEvent actionEvent)
- {
- JalviewFileChooser chooser = new JalviewFileChooser(
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
-
- chooser.setFileView(new JalviewFileView());
- chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
- chooser.setToolTipText(MessageManager.getString("action.save"));
-
- int value = chooser.showSaveDialog(this);
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
- {
- BufferedReader in = null;
- try
- {
- // TODO: cope with multiple PDB files in view
- in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
- File outFile = chooser.getSelectedFile();
-
- PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
- String data;
- while ((data = in.readLine()) != null)
- {
- if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
- {
- out.println(data);
- }
- }
- out.close();
- } catch (Exception ex)
- {
- ex.printStackTrace();
- } finally
- {
- if (in != null)
- {
- try
- {
- in.close();
- } catch (IOException e)
- {
- // ignore
- }
- }
- }
- }
- }
-
- @Override
- public void viewMapping_actionPerformed(ActionEvent actionEvent)
- {
- jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
- try
- {
- cap.appendText(jmb.printMappings());
- } catch (OutOfMemoryError e)
- {
- new OOMWarning(
- "composing sequence-structure alignments for display in text box.",
- e);
- cap.dispose();
- return;
- }
- jalview.gui.Desktop.addInternalFrame(cap,
- MessageManager.getString("label.pdb_sequence_mapping"), 550,
- 600);
- }
-
- @Override
public void eps_actionPerformed(ActionEvent e)
{
makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
}
@Override
- public void viewerColour_actionPerformed(ActionEvent actionEvent)
- {
- if (viewerColour.isSelected())
- {
- // disable automatic sequence colouring.
- jmb.setColourBySequence(false);
- }
- }
-
- @Override
- public void seqColour_actionPerformed(ActionEvent actionEvent)
- {
- jmb.setColourBySequence(seqColour.isSelected());
- if (_colourwith == null)
- {
- _colourwith = new Vector<AlignmentPanel>();
- }
- if (jmb.isColourBySequence())
- {
- if (!jmb.isLoadingFromArchive())
- {
- if (_colourwith.size() == 0 && getAlignmentPanel() != null)
- {
- // Make the currently displayed alignment panel the associated view
- _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
- }
- }
- // Set the colour using the current view for the associated alignframe
- for (AlignmentPanel ap : _colourwith)
- {
- jmb.colourBySequence(ap);
- }
- }
- }
-
- @Override
- public void chainColour_actionPerformed(ActionEvent actionEvent)
- {
- chainColour.setSelected(true);
- jmb.colourByChain();
- }
-
- @Override
- public void chargeColour_actionPerformed(ActionEvent actionEvent)
- {
- chargeColour.setSelected(true);
- jmb.colourByCharge();
- }
-
- @Override
- public void zappoColour_actionPerformed(ActionEvent actionEvent)
- {
- zappoColour.setSelected(true);
- jmb.setJalviewColourScheme(new ZappoColourScheme());
- }
-
- @Override
- public void taylorColour_actionPerformed(ActionEvent actionEvent)
- {
- taylorColour.setSelected(true);
- jmb.setJalviewColourScheme(new TaylorColourScheme());
- }
-
- @Override
- public void hydroColour_actionPerformed(ActionEvent actionEvent)
- {
- hydroColour.setSelected(true);
- jmb.setJalviewColourScheme(new HydrophobicColourScheme());
- }
-
- @Override
- public void helixColour_actionPerformed(ActionEvent actionEvent)
- {
- helixColour.setSelected(true);
- jmb.setJalviewColourScheme(new HelixColourScheme());
- }
-
- @Override
- public void strandColour_actionPerformed(ActionEvent actionEvent)
- {
- strandColour.setSelected(true);
- jmb.setJalviewColourScheme(new StrandColourScheme());
- }
-
- @Override
- public void turnColour_actionPerformed(ActionEvent actionEvent)
- {
- turnColour.setSelected(true);
- jmb.setJalviewColourScheme(new TurnColourScheme());
- }
-
- @Override
- public void buriedColour_actionPerformed(ActionEvent actionEvent)
- {
- buriedColour.setSelected(true);
- jmb.setJalviewColourScheme(new BuriedColourScheme());
- }
-
- @Override
- public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
- {
- setJalviewColourScheme(new PurinePyrimidineColourScheme());
- }
-
- /**
- * Action on either selecting a user-defined colour, or 'User Defined...'
- */
- @Override
- public void userColour_actionPerformed(ActionEvent e)
- {
- if (e.getActionCommand().equals(
- MessageManager.getString("action.user_defined")))
- {
- userColour.setSelected(true);
- new UserDefinedColours(this, null);
- }
- else
- {
- UserColourScheme udc = UserDefinedColours.getUserColourSchemes().get(
- e.getActionCommand());
- jmb.setJalviewColourScheme(udc);
- }
- }
-
- @Override
- public void backGround_actionPerformed(ActionEvent actionEvent)
- {
- Color col = JColorChooser.showDialog(this,
- MessageManager.getString("label.select_background_colour"),
- null);
- if (col != null)
- {
- jmb.setBackgroundColour(col);
- }
- }
-
- @Override
public void showHelp_actionPerformed(ActionEvent actionEvent)
{
try
{
- jalview.util.BrowserLauncher
+ BrowserLauncher
.openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
} catch (Exception ex)
{
{
getSize(currentSize);
- if (jmb != null && jmb.fileLoadingError != null)
+ if (jmb != null && jmb.hasFileLoadingError())
{
g.setColor(Color.black);
g.fillRect(0, 0, currentSize.width, currentSize.height);
}
}
- public void updateTitleAndMenus()
- {
- if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
- {
- repaint();
- return;
- }
- setChainMenuItems(jmb.getChainNames());
-
- this.setTitle(jmb.getViewerTitle());
- if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
- {
- viewerActionMenu.setVisible(true);
- }
- if (!jmb.isLoadingFromArchive())
- {
- seqColour_actionPerformed(null);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
- * .ActionEvent)
- */
- @Override
- protected void alignStructs_actionPerformed(ActionEvent actionEvent)
- {
- alignStructs_withAllAlignPanels();
- }
-
- private void alignStructs_withAllAlignPanels()
- {
- if (getAlignmentPanel() == null)
- {
- return;
- }
- ;
- if (_alignwith.size() == 0)
- {
- _alignwith.add(getAlignmentPanel());
- }
- ;
- try
- {
- AlignmentI[] als = new Alignment[_alignwith.size()];
- ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
- int[] alm = new int[_alignwith.size()];
- int a = 0;
-
- for (AlignmentPanel ap : _alignwith)
- {
- als[a] = ap.av.getAlignment();
- alm[a] = -1;
- alc[a++] = ap.av.getColumnSelection();
- }
- jmb.superposeStructures(als, alm, alc);
- } catch (Exception e)
- {
- StringBuffer sp = new StringBuffer();
- for (AlignmentPanel ap : _alignwith)
- {
- sp.append("'" + ap.alignFrame.getTitle() + "' ");
- }
- Cache.log.info("Couldn't align structures with the " + sp.toString()
- + "associated alignment panels.", e);
-
- }
-
- }
-
- @Override
- public void setJalviewColourScheme(ColourSchemeI ucs)
- {
- jmb.setJalviewColourScheme(ucs);
-
- }
-
- /**
- *
- * @param alignment
- * @return first alignment panel displaying given alignment, or the default
- * alignment panel
- */
- public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
- {
- for (AlignmentPanel ap : getAllAlignmentPanels())
- {
- if (ap.av.getAlignment() == alignment)
- {
- return ap;
- }
- }
- return getAlignmentPanel();
- }
-
@Override
public AAStructureBindingModel getBinding()
{
}
@Override
- protected AAStructureBindingModel getBindingModel()
+ protected String getViewerName()
{
- return jmb;
+ return "Jmol";
}
-
}
package jalview.gui;
import jalview.bin.Cache;
-import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
-import jalview.datamodel.ColumnSelection;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
import jalview.gui.StructureViewer.ViewerType;
import jalview.io.DataSourceType;
-import jalview.io.JalviewFileChooser;
-import jalview.io.JalviewFileView;
import jalview.io.StructureFile;
-import jalview.schemes.BuriedColourScheme;
-import jalview.schemes.ColourSchemeI;
-import jalview.schemes.HelixColourScheme;
-import jalview.schemes.HydrophobicColourScheme;
-import jalview.schemes.PurinePyrimidineColourScheme;
-import jalview.schemes.StrandColourScheme;
-import jalview.schemes.TaylorColourScheme;
-import jalview.schemes.TurnColourScheme;
-import jalview.schemes.UserColourScheme;
-import jalview.schemes.ZappoColourScheme;
import jalview.structures.models.AAStructureBindingModel;
+import jalview.util.BrowserLauncher;
import jalview.util.MessageManager;
import jalview.util.Platform;
import jalview.ws.dbsources.Pdb;
-import java.awt.Color;
import java.awt.event.ActionEvent;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
-import java.util.Vector;
import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JColorChooser;
import javax.swing.JInternalFrame;
-import javax.swing.JMenu;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
-import javax.swing.event.MenuEvent;
-import javax.swing.event.MenuListener;
/**
* GUI elements for handling an external chimera display
/**
* Initialise menu options.
*/
- private void initMenus()
+ @Override
+ protected void initMenus()
{
+ super.initMenus();
+
viewerActionMenu.setText(MessageManager.getString("label.chimera"));
+
viewerColour.setText(MessageManager
.getString("label.colour_with_chimera"));
viewerColour.setToolTipText(MessageManager
.getString("label.let_chimera_manage_structure_colours"));
- helpItem.setText(MessageManager.getString("label.chimera_help"));
- seqColour.setSelected(jmb.isColourBySequence());
- viewerColour.setSelected(!jmb.isColourBySequence());
- if (_colourwith == null)
- {
- _colourwith = new Vector<AlignmentPanel>();
- }
- if (_alignwith == null)
- {
- _alignwith = new Vector<AlignmentPanel>();
- }
-
- // save As not yet implemented
- savemenu.setVisible(false);
- ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
- MessageManager.getString("label.colour_by"), this, _colourwith,
- new ItemListener()
- {
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- if (!seqColour.isSelected())
- {
- seqColour.doClick();
- }
- else
- {
- // update the Chimera display now.
- seqColour_actionPerformed(null);
- }
- }
- });
- viewMenu.add(seqColourBy);
+ helpItem.setText(MessageManager.getString("label.chimera_help"));
+ savemenu.setVisible(false); // not yet implemented
viewMenu.add(fitToWindow);
-
- final ItemListener handler;
- JMenu alpanels = new ViewSelectionMenu(
- MessageManager.getString("label.superpose_with"), this,
- _alignwith, handler = new ItemListener()
- {
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- alignStructs.setEnabled(_alignwith.size() > 0);
- alignStructs.setToolTipText(MessageManager
- .formatMessage(
- "label.align_structures_using_linked_alignment_views",
- new Object[] { new Integer(_alignwith
- .size()).toString() }));
- }
- });
- handler.itemStateChanged(null);
- viewerActionMenu.add(alpanels);
- viewerActionMenu.addMenuListener(new MenuListener()
- {
-
- @Override
- public void menuSelected(MenuEvent e)
- {
- handler.itemStateChanged(null);
- }
-
- @Override
- public void menuDeselected(MenuEvent e)
- {
- // TODO Auto-generated method stub
- }
-
- @Override
- public void menuCanceled(MenuEvent e)
- {
- // TODO Auto-generated method stub
- }
- });
}
/**
}
}
- /**
- * Answers true if this viewer already involves the given PDB ID
- */
- @Override
- protected boolean hasPdbId(String pdbId)
- {
- return jmb.hasPdbId(pdbId);
- }
-
private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
SequenceI[][] seqs)
{
ap.getStructureSelectionManager(), pdbentrys, seqs, null);
addAlignmentPanel(ap);
useAlignmentPanelForColourbyseq(ap);
+
if (pdbentrys.length > 1)
{
alignAddedStructures = true;
}
-
-
/**
* Create a new viewer from saved session state data including Chimera session
* file
{
jmb.setFinishedInit(false);
jalview.gui.Desktop.addInternalFrame(this,
- jmb.getViewerTitle("Chimera", true), getBounds().width,
+ jmb.getViewerTitle(getViewerName(), true), getBounds().width,
getBounds().height);
if (!jmb.launchChimera())
{
String prompt = MessageManager.formatMessage(
"label.confirm_close_chimera",
- new Object[] { jmb.getViewerTitle("Chimera", false) });
+ new Object[] { jmb.getViewerTitle(getViewerName(),
+ false) });
prompt = JvSwingUtils.wrapTooltip(true, prompt);
int confirm = JvOptionPane.showConfirmDialog(this, prompt,
MessageManager.getString("label.close_viewer"),
try
{
int pos = filePDBpos.get(num).intValue();
- long startTime = startProgressBar("Chimera "
+ long startTime = startProgressBar(getViewerName() + " "
+ MessageManager.getString("status.opening_file_for")
+ " " + pe.getId());
jmb.openFile(pe);
}
@Override
- public void pdbFile_actionPerformed(ActionEvent actionEvent)
- {
- JalviewFileChooser chooser = new JalviewFileChooser(
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
-
- chooser.setFileView(new JalviewFileView());
- chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
- chooser.setToolTipText(MessageManager.getString("action.save"));
-
- int value = chooser.showSaveDialog(this);
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
- {
- BufferedReader in = null;
- try
- {
- // TODO: cope with multiple PDB files in view
- in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
- File outFile = chooser.getSelectedFile();
-
- PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
- String data;
- while ((data = in.readLine()) != null)
- {
- if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
- {
- out.println(data);
- }
- }
- out.close();
- } catch (Exception ex)
- {
- ex.printStackTrace();
- } finally
- {
- if (in != null)
- {
- try
- {
- in.close();
- } catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- }
- }
- }
-
- @Override
- public void viewMapping_actionPerformed(ActionEvent actionEvent)
- {
- jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
- try
- {
- cap.appendText(jmb.printMappings());
- } catch (OutOfMemoryError e)
- {
- new OOMWarning(
- "composing sequence-structure alignments for display in text box.",
- e);
- cap.dispose();
- return;
- }
- jalview.gui.Desktop.addInternalFrame(cap,
- MessageManager.getString("label.pdb_sequence_mapping"), 550,
- 600);
- }
-
- @Override
public void eps_actionPerformed(ActionEvent e)
{
throw new Error(
}
@Override
- public void viewerColour_actionPerformed(ActionEvent actionEvent)
- {
- if (viewerColour.isSelected())
- {
- // disable automatic sequence colouring.
- jmb.setColourBySequence(false);
- }
- }
-
- @Override
- public void seqColour_actionPerformed(ActionEvent actionEvent)
- {
- jmb.setColourBySequence(seqColour.isSelected());
- if (_colourwith == null)
- {
- _colourwith = new Vector<AlignmentPanel>();
- }
- if (jmb.isColourBySequence())
- {
- if (!jmb.isLoadingFromArchive())
- {
- if (_colourwith.size() == 0 && getAlignmentPanel() != null)
- {
- // Make the currently displayed alignment panel the associated view
- _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
- }
- }
- // Set the colour using the current view for the associated alignframe
- for (AlignmentPanel ap : _colourwith)
- {
- jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
- }
- }
- }
-
- @Override
- public void chainColour_actionPerformed(ActionEvent actionEvent)
- {
- chainColour.setSelected(true);
- jmb.colourByChain();
- }
-
- @Override
- public void chargeColour_actionPerformed(ActionEvent actionEvent)
- {
- chargeColour.setSelected(true);
- jmb.colourByCharge();
- }
-
- @Override
- public void zappoColour_actionPerformed(ActionEvent actionEvent)
- {
- zappoColour.setSelected(true);
- jmb.setJalviewColourScheme(new ZappoColourScheme());
- }
-
- @Override
- public void taylorColour_actionPerformed(ActionEvent actionEvent)
- {
- taylorColour.setSelected(true);
- jmb.setJalviewColourScheme(new TaylorColourScheme());
- }
-
- @Override
- public void hydroColour_actionPerformed(ActionEvent actionEvent)
- {
- hydroColour.setSelected(true);
- jmb.setJalviewColourScheme(new HydrophobicColourScheme());
- }
-
- @Override
- public void helixColour_actionPerformed(ActionEvent actionEvent)
- {
- helixColour.setSelected(true);
- jmb.setJalviewColourScheme(new HelixColourScheme());
- }
-
- @Override
- public void strandColour_actionPerformed(ActionEvent actionEvent)
- {
- strandColour.setSelected(true);
- jmb.setJalviewColourScheme(new StrandColourScheme());
- }
-
- @Override
- public void turnColour_actionPerformed(ActionEvent actionEvent)
- {
- turnColour.setSelected(true);
- jmb.setJalviewColourScheme(new TurnColourScheme());
- }
-
- @Override
- public void buriedColour_actionPerformed(ActionEvent actionEvent)
- {
- buriedColour.setSelected(true);
- jmb.setJalviewColourScheme(new BuriedColourScheme());
- }
-
- @Override
- public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
- {
- setJalviewColourScheme(new PurinePyrimidineColourScheme());
- }
-
- @Override
- public void userColour_actionPerformed(ActionEvent e)
- {
- if (e.getActionCommand().equals(
- MessageManager.getString("action.user_defined")))
- {
- new UserDefinedColours(this, null);
- }
- else
- {
- UserColourScheme udc = UserDefinedColours.getUserColourSchemes().get(
- e.getActionCommand());
- jmb.setJalviewColourScheme(udc);
- }
- }
-
- @Override
- public void backGround_actionPerformed(ActionEvent actionEvent)
- {
- Color col = JColorChooser.showDialog(this,
- MessageManager.getString("label.select_background_colour"),
- null);
- if (col != null)
- {
- jmb.setBackgroundColour(col);
- }
- }
-
- @Override
public void showHelp_actionPerformed(ActionEvent actionEvent)
{
try
{
- jalview.util.BrowserLauncher
+ BrowserLauncher
.openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
} catch (Exception ex)
{
}
}
- public void updateTitleAndMenus()
- {
- if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
- {
- repaint();
- return;
- }
- setChainMenuItems(jmb.getChainNames());
-
- this.setTitle(jmb.getViewerTitle("Chimera", true));
- if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
- {
- viewerActionMenu.setVisible(true);
- }
- if (!jmb.isLoadingFromArchive())
- {
- seqColour_actionPerformed(null);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
- * .ActionEvent)
- */
- @Override
- protected void alignStructs_actionPerformed(ActionEvent actionEvent)
- {
- alignStructs_withAllAlignPanels();
- }
-
- private void alignStructs_withAllAlignPanels()
- {
- if (getAlignmentPanel() == null)
- {
- return;
- }
-
- if (_alignwith.size() == 0)
- {
- _alignwith.add(getAlignmentPanel());
- }
-
- try
- {
- AlignmentI[] als = new Alignment[_alignwith.size()];
- ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
- int[] alm = new int[_alignwith.size()];
- int a = 0;
-
- for (AlignmentPanel ap : _alignwith)
- {
- als[a] = ap.av.getAlignment();
- alm[a] = -1;
- alc[a++] = ap.av.getColumnSelection();
- }
- jmb.superposeStructures(als, alm, alc);
- } catch (Exception e)
- {
- StringBuffer sp = new StringBuffer();
- for (AlignmentPanel ap : _alignwith)
- {
- sp.append("'" + ap.alignFrame.getTitle() + "' ");
- }
- Cache.log.info("Couldn't align structures with the " + sp.toString()
- + "associated alignment panels.", e);
- }
- }
-
- @Override
- public void setJalviewColourScheme(ColourSchemeI ucs)
- {
- jmb.setJalviewColourScheme(ucs);
-
- }
-
- /**
- *
- * @param alignment
- * @return first alignment panel displaying given alignment, or the default
- * alignment panel
- */
- public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
- {
- for (AlignmentPanel ap : getAllAlignmentPanels())
- {
- if (ap.av.getAlignment() == alignment)
- {
- return ap;
- }
- }
- return getAlignmentPanel();
- }
-
@Override
public AAStructureBindingModel getBinding()
{
}
@Override
- protected AAStructureBindingModel getBindingModel()
+ protected String getViewerName()
{
- return jmb;
+ return "Chimera";
}
}
/**
* Adds items to the colour menu, as mutually exclusive members of a button
* group. The callback handler is responsible for the action on selecting any
- * of these options. It is returned the name of the selected colour, or "None"
- * or "User Defined".
+ * of these options. The callback method receives the name of the selected
+ * colour, or "None" or "User Defined". This method returns the ButtonGroup to
+ * which items were added.
* <ul>
* <li>None</li>
* <li>Clustal</li>
* a callback to handle menu selection
* @param coll
* the data the menu is being built for
+ * @param simpleOnly
+ * if true, only simple per-residue colour schemes are included
*/
- public static void addMenuItems(final JMenu colourMenu,
- final ColourChangeListener client, AnnotatedCollectionI coll)
+ public static ButtonGroup addMenuItems(final JMenu colourMenu,
+ final ColourChangeListener client, AnnotatedCollectionI coll,
+ boolean simpleOnly)
{
/*
* ButtonGroup groups those items whose
* selection is mutually exclusive
*/
ButtonGroup colours = new ButtonGroup();
- JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem(
- MessageManager.getString("label.none"));
- noColourmenuItem.setName(ResidueColourScheme.NONE);
- noColourmenuItem.addActionListener(new ActionListener()
+
+ if (!simpleOnly)
{
- @Override
- public void actionPerformed(ActionEvent e)
+ JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem(
+ MessageManager.getString("label.none"));
+ noColourmenuItem.setName(ResidueColourScheme.NONE);
+ noColourmenuItem.addActionListener(new ActionListener()
{
- client.changeColour_actionPerformed(ResidueColourScheme.NONE);
- }
- });
- colourMenu.add(noColourmenuItem);
- colours.add(noColourmenuItem);
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ client.changeColour_actionPerformed(ResidueColourScheme.NONE);
+ }
+ });
+ colourMenu.add(noColourmenuItem);
+ colours.add(noColourmenuItem);
+ }
/*
* scan registered colour schemes (built-in or user-defined
.getColourSchemes();
for (ColourSchemeI scheme : colourSchemes)
{
+ if (simpleOnly && !scheme.isSimple())
+ {
+ continue;
+ }
+
/*
* button text is i18n'd but the name is the canonical name of
- * the colour scheme (inspected in changeColour_actionPerformed)
+ * the colour scheme (inspected in setColourSelected())
*/
final String name = scheme.getSchemeName();
String label = MessageManager.getStringOrReturn("label.colourScheme_"
colours.add(radioItem);
}
- final String label = MessageManager.getString("action.user_defined");
- JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem(label);
- userDefinedColour.addActionListener(new ActionListener()
+ /*
+ * only add the option to load/configure a user-defined colour
+ * to the AlignFrame colour menu
+ */
+ if (client instanceof AlignFrame)
{
- @Override
- public void actionPerformed(ActionEvent e)
+ final String label = MessageManager.getString("action.user_defined");
+ JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem(
+ label);
+ userDefinedColour.addActionListener(new ActionListener()
{
- client.changeColour_actionPerformed(ResidueColourScheme.USER_DEFINED);
- }
- });
- colourMenu.add(userDefinedColour);
- colours.add(userDefinedColour);
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ client.changeColour_actionPerformed(ResidueColourScheme.USER_DEFINED);
+ }
+ });
+ colourMenu.add(userDefinedColour);
+ colours.add(userDefinedColour);
+ }
+
+ return colours;
}
/**
}
if (!isLoadingFromArchive())
{
- colourBySequence(ap.av.isShowSequenceFeatures(), ap);
+ colourBySequence(ap);
}
}
protected void buildColourMenu()
{
SequenceGroup sg = getGroup();
+ if (sg == null)
+ {
+ /*
+ * popup menu with no sequence group scope
+ */
+ return;
+ }
colourMenu.removeAll();
colourMenu.add(textColour);
colourMenu.addSeparator();
- ColourMenuHelper.addMenuItems(colourMenu, this, sg);
+ ColourMenuHelper.addMenuItems(colourMenu, this, sg, false);
colourMenu.addSeparator();
colourMenu.add(conservationMenuItem);
*/
package jalview.gui;
+import jalview.bin.Cache;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
import jalview.gui.StructureViewer.ViewerType;
import jalview.gui.ViewSelectionMenu.ViewSetProvider;
import jalview.io.DataSourceType;
+import jalview.io.JalviewFileChooser;
+import jalview.io.JalviewFileView;
import jalview.jbgui.GStructureViewer;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemes;
import jalview.structures.models.AAStructureBindingModel;
import jalview.util.MessageManager;
+import java.awt.Color;
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.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
+import javax.swing.ButtonGroup;
import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JColorChooser;
+import javax.swing.JMenu;
import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
+import javax.swing.JRadioButtonMenuItem;
+import javax.swing.event.MenuEvent;
+import javax.swing.event.MenuListener;
/**
* Base class with common functionality for JMol, Chimera or other structure
public abstract class StructureViewerBase extends GStructureViewer
implements Runnable, ViewSetProvider
{
+ /*
+ * names for colour options (additional to Jalview colour schemes)
+ */
+ enum ViewerColour
+ {
+ BySequence, ByChain, ChargeCysteine, ByViewer
+ }
/**
* list of sequenceSet ids associated with the view
protected boolean allChainsSelected = false;
/**
+ * Default constructor
+ */
+ public StructureViewerBase()
+ {
+ super();
+ }
+ /**
*
* @param ap2
* @return true if this Jmol instance is linked with the given alignPanel
public abstract ViewerType getViewerType();
- protected abstract AAStructureBindingModel getBindingModel();
-
/**
* add a new structure (with associated sequences and chains) to this viewer,
* retrieving it if necessary first.
}
}
// otherwise, start adding the structure.
- getBindingModel().addSequenceAndChain(new PDBEntry[] { pdbentry },
+ getBinding().addSequenceAndChain(new PDBEntry[] { pdbentry },
new SequenceI[][] { seqs }, new String[][] { chains });
addingStructures = true;
_started = false;
return option;
}
- protected abstract boolean hasPdbId(String pdbId);
+ protected boolean hasPdbId(String pdbId)
+ {
+ return getBinding().hasPdbId(pdbId);
+ }
protected abstract List<StructureViewerBase> getViewersFor(
AlignmentPanel alp);
// JBPNOTE: this looks like a binding routine, rather than a gui routine
for (StructureViewerBase viewer : getViewersFor(null))
{
- AAStructureBindingModel bindingModel = viewer.getBindingModel();
+ AAStructureBindingModel bindingModel = viewer.getBinding();
for (int pe = 0; pe < bindingModel.getPdbCount(); pe++)
{
if (bindingModel.getPdbEntry(pe).getFile().equals(pdbFilename))
abstract void showSelectedChains();
+ /**
+ * Action on selecting one of Jalview's registered colour schemes
+ */
+ @Override
+ public void changeColour_actionPerformed(String colourSchemeName)
+ {
+ AlignmentI al = getAlignmentPanel().av.getAlignment();
+ ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(
+ colourSchemeName, al, null);
+ getBinding().setJalviewColourScheme(cs);
+ }
+
+ /**
+ * Builds the colour menu
+ */
+ protected void buildColourMenu()
+ {
+ colourMenu.removeAll();
+ AlignmentI al = getAlignmentPanel().av.getAlignment();
+
+ /*
+ * add colour by sequence, by chain, by charge and cysteine
+ */
+ colourMenu.add(seqColour);
+ colourMenu.add(chainColour);
+ colourMenu.add(chargeColour);
+ chargeColour.setEnabled(!al.isNucleotide());
+
+ /*
+ * add all 'simple' (per-residue) colour schemes registered to Jalview
+ */
+ ButtonGroup itemGroup = ColourMenuHelper.addMenuItems(colourMenu, this,
+ al, true);
+
+ /*
+ * add 'colour by viewer' (menu item text is set in subclasses)
+ */
+ viewerColour.setSelected(false);
+ viewerColour.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent)
+ {
+ viewerColour_actionPerformed(actionEvent);
+ }
+ });
+ colourMenu.add(viewerColour);
+
+ /*
+ * add 'set background colour'
+ */
+ JMenuItem backGround = new JMenuItem();
+ backGround
+ .setText(MessageManager.getString("action.background_colour"));
+ backGround.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent)
+ {
+ background_actionPerformed(actionEvent);
+ }
+ });
+ colourMenu.add(backGround);
+
+ /*
+ * add colour buttons to a group so their selection is
+ * mutually exclusive (background colour is a separate option)
+ */
+ itemGroup.add(seqColour);
+ itemGroup.add(chainColour);
+ itemGroup.add(chargeColour);
+ itemGroup.add(viewerColour);
+ }
+
+ /**
+ * Construct menu items
+ */
+ protected void initMenus()
+ {
+ AAStructureBindingModel binding = getBinding();
+
+ seqColour = new JRadioButtonMenuItem();
+ seqColour.setText(MessageManager.getString("action.by_sequence"));
+ seqColour.setName(ViewerColour.BySequence.name());
+ seqColour.setSelected(binding.isColourBySequence());
+ seqColour.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent)
+ {
+ seqColour_actionPerformed(actionEvent);
+ }
+ });
+
+ chainColour = new JRadioButtonMenuItem();
+ chainColour.setText(MessageManager.getString("action.by_chain"));
+ chainColour.setName(ViewerColour.ByChain.name());
+ chainColour.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent)
+ {
+ chainColour_actionPerformed(actionEvent);
+ }
+ });
+
+ chargeColour = new JRadioButtonMenuItem();
+ chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
+ chargeColour.setName(ViewerColour.ChargeCysteine.name());
+ chargeColour.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent)
+ {
+ chargeColour_actionPerformed(actionEvent);
+ }
+ });
+
+ viewerColour = new JRadioButtonMenuItem();
+ // text is set in overrides of this method
+ viewerColour.setName(ViewerColour.ByViewer.name());
+ viewerColour.setSelected(!binding.isColourBySequence());
+
+ if (_colourwith == null)
+ {
+ _colourwith = new Vector<AlignmentPanel>();
+ }
+ if (_alignwith == null)
+ {
+ _alignwith = new Vector<AlignmentPanel>();
+ }
+
+ ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
+ MessageManager.getString("label.colour_by"), this, _colourwith,
+ new ItemListener()
+ {
+ @Override
+ public void itemStateChanged(ItemEvent e)
+ {
+ if (!seqColour.isSelected())
+ {
+ seqColour.doClick();
+ }
+ else
+ {
+ // update the Chimera display now.
+ seqColour_actionPerformed(null);
+ }
+ }
+ });
+ viewMenu.add(seqColourBy);
+
+ final ItemListener handler = new ItemListener()
+ {
+ @Override
+ public void itemStateChanged(ItemEvent e)
+ {
+ alignStructs.setEnabled(_alignwith.size() > 0);
+ alignStructs.setToolTipText(MessageManager.formatMessage(
+ "label.align_structures_using_linked_alignment_views",
+ new String[] { String.valueOf(_alignwith.size()) }));
+ }
+ };
+ JMenu alpanels = new ViewSelectionMenu(
+ MessageManager.getString("label.superpose_with"), this,
+ _alignwith, handler);
+ handler.itemStateChanged(null);
+ viewerActionMenu.add(alpanels);
+ viewerActionMenu.addMenuListener(new MenuListener()
+ {
+ @Override
+ public void menuSelected(MenuEvent e)
+ {
+ handler.itemStateChanged(null);
+ }
+
+ @Override
+ public void menuDeselected(MenuEvent e)
+ {
+ }
+
+ @Override
+ public void menuCanceled(MenuEvent e)
+ {
+ }
+ });
+
+ buildColourMenu();
+ }
+
+ @Override
+ public void setJalviewColourScheme(ColourSchemeI cs) {
+ getBinding().setJalviewColourScheme(cs);
+ }
+ @Override
+ protected void alignStructs_actionPerformed(ActionEvent actionEvent)
+ {
+ alignStructs_withAllAlignPanels();
+ }
+ protected void alignStructs_withAllAlignPanels()
+ {
+ if (getAlignmentPanel() == null)
+ {
+ return;
+ }
+
+ if (_alignwith.size() == 0)
+ {
+ _alignwith.add(getAlignmentPanel());
+ }
+
+ try
+ {
+ AlignmentI[] als = new Alignment[_alignwith.size()];
+ ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
+ int[] alm = new int[_alignwith.size()];
+ int a = 0;
+
+ for (AlignmentPanel ap : _alignwith)
+ {
+ als[a] = ap.av.getAlignment();
+ alm[a] = -1;
+ alc[a++] = ap.av.getColumnSelection();
+ }
+ getBinding().superposeStructures(als, alm, alc);
+ } catch (Exception e)
+ {
+ StringBuffer sp = new StringBuffer();
+ for (AlignmentPanel ap : _alignwith)
+ {
+ sp.append("'" + ap.alignFrame.getTitle() + "' ");
+ }
+ Cache.log.info("Couldn't align structures with the " + sp.toString()
+ + "associated alignment panels.", e);
+ }
+ }
+ @Override
+ public void background_actionPerformed(ActionEvent actionEvent)
+ {
+ Color col = JColorChooser.showDialog(this,
+ MessageManager.getString("label.select_background_colour"),
+ null);
+ if (col != null)
+ {
+ getBinding().setBackgroundColour(col);
+ }
+ }
+ @Override
+ public void viewerColour_actionPerformed(ActionEvent actionEvent)
+ {
+ if (viewerColour.isSelected())
+ {
+ // disable automatic sequence colouring.
+ getBinding().setColourBySequence(false);
+ }
+ }
+ @Override
+ public void chainColour_actionPerformed(ActionEvent actionEvent)
+ {
+ chainColour.setSelected(true);
+ getBinding().colourByChain();
+ }
+ @Override
+ public void chargeColour_actionPerformed(ActionEvent actionEvent)
+ {
+ chargeColour.setSelected(true);
+ getBinding().colourByCharge();
+ }
+ @Override
+ public void seqColour_actionPerformed(ActionEvent actionEvent)
+ {
+ AAStructureBindingModel binding = getBinding();
+ binding.setColourBySequence(seqColour.isSelected());
+ if (_colourwith == null)
+ {
+ _colourwith = new Vector<AlignmentPanel>();
+ }
+ if (binding.isColourBySequence())
+ {
+ if (!binding.isLoadingFromArchive())
+ {
+ if (_colourwith.size() == 0 && getAlignmentPanel() != null)
+ {
+ // Make the currently displayed alignment panel the associated view
+ _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
+ }
+ }
+ // Set the colour using the current view for the associated alignframe
+ for (AlignmentPanel ap : _colourwith)
+ {
+ binding.colourBySequence(ap);
+ }
+ }
+ }
+ @Override
+ public void pdbFile_actionPerformed(ActionEvent actionEvent)
+ {
+ JalviewFileChooser chooser = new JalviewFileChooser(
+ Cache.getProperty("LAST_DIRECTORY"));
+
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
+ chooser.setToolTipText(MessageManager.getString("action.save"));
+
+ int value = chooser.showSaveDialog(this);
+
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ BufferedReader in = null;
+ try
+ {
+ // TODO: cope with multiple PDB files in view
+ in = new BufferedReader(
+ new FileReader(getBinding().getPdbFile()[0]));
+ File outFile = chooser.getSelectedFile();
+
+ PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
+ String data;
+ while ((data = in.readLine()) != null)
+ {
+ if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
+ {
+ out.println(data);
+ }
+ }
+ out.close();
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ } finally
+ {
+ if (in != null)
+ {
+ try
+ {
+ in.close();
+ } catch (IOException e)
+ {
+ // ignore
+ }
+ }
+ }
+ }
+ }
+ @Override
+ public void viewMapping_actionPerformed(ActionEvent actionEvent)
+ {
+ CutAndPasteTransfer cap = new CutAndPasteTransfer();
+ try
+ {
+ cap.appendText(getBinding().printMappings());
+ } catch (OutOfMemoryError e)
+ {
+ new OOMWarning(
+ "composing sequence-structure alignments for display in text box.",
+ e);
+ cap.dispose();
+ return;
+ }
+ Desktop.addInternalFrame(cap,
+ MessageManager.getString("label.pdb_sequence_mapping"), 550,
+ 600);
+ }
+
+ protected abstract String getViewerName();
+ public void updateTitleAndMenus()
+ {
+ AAStructureBindingModel binding = getBinding();
+ if (binding.hasFileLoadingError())
+ {
+ repaint();
+ return;
+ }
+ setChainMenuItems(binding.getChainNames());
+
+ this.setTitle(binding.getViewerTitle(getViewerName(), true));
+ if (binding.getPdbFile().length > 1 && binding.getSequence().length > 1)
+ {
+ viewerActionMenu.setVisible(true);
+ }
+ if (!binding.isLoadingFromArchive())
+ {
+ seqColour_actionPerformed(null);
+ }
+ }
}
package jalview.jbgui;
import jalview.api.structures.JalviewStructureDisplayI;
-import jalview.gui.UserDefinedColours;
-import jalview.schemes.UserColourScheme;
+import jalview.gui.ColourMenuHelper.ColourChangeListener;
import jalview.util.MessageManager;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.util.Map;
-import javax.swing.ButtonGroup;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JRadioButtonMenuItem;
public abstract class GStructureViewer extends JInternalFrame implements
- JalviewStructureDisplayI
+ JalviewStructureDisplayI, ColourChangeListener
{
// private AAStructureBindingModel bindingModel;
protected JRadioButtonMenuItem chargeColour;
- protected JRadioButtonMenuItem zappoColour;
-
- protected JRadioButtonMenuItem taylorColour;
-
- protected JRadioButtonMenuItem hydroColour;
-
- protected JRadioButtonMenuItem strandColour;
-
- protected JRadioButtonMenuItem helixColour;
-
- protected JRadioButtonMenuItem turnColour;
-
- protected JRadioButtonMenuItem buriedColour;
-
- protected JRadioButtonMenuItem nucleotideColour;
-
- protected JRadioButtonMenuItem purinePyrimidineColour;
-
- protected JRadioButtonMenuItem userColour;
-
protected JRadioButtonMenuItem viewerColour;
protected JMenuItem helpItem;
}
});
- viewerActionMenu = new JMenu(MessageManager.getString("label.jmol"));
+ viewerActionMenu = new JMenu();
viewerActionMenu.setVisible(false);
viewerActionMenu.add(alignStructs);
colourMenu = new JMenu();
- buildColourMenu();
+ colourMenu.setText(MessageManager.getString("label.colours"));
fileMenu.add(savemenu);
fileMenu.add(viewMapping);
savemenu.add(pdbFile);
statusPanel.add(statusBar, null);
}
- /**
- * Builds the colour menu
- */
- protected void buildColourMenu()
- {
- colourMenu.removeAll();
- colourMenu.setText(MessageManager.getString("label.colours"));
-
- JMenuItem backGround = new JMenuItem();
- backGround
- .setText(MessageManager.getString("action.background_colour"));
- backGround.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- backGround_actionPerformed(actionEvent);
- }
- });
- seqColour = new JRadioButtonMenuItem();
- seqColour.setSelected(false);
- seqColour.setText(MessageManager.getString("action.by_sequence"));
- seqColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- seqColour_actionPerformed(actionEvent);
- }
- });
- chainColour = new JRadioButtonMenuItem();
- chainColour.setText(MessageManager.getString("action.by_chain"));
- chainColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- chainColour_actionPerformed(actionEvent);
- }
- });
- chargeColour = new JRadioButtonMenuItem();
- chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
- chargeColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- chargeColour_actionPerformed(actionEvent);
- }
- });
- zappoColour = new JRadioButtonMenuItem();
- zappoColour.setText(MessageManager
- .getString("label.colourScheme_zappo"));
- zappoColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- zappoColour_actionPerformed(actionEvent);
- }
- });
- taylorColour = new JRadioButtonMenuItem();
- taylorColour.setText(MessageManager
- .getString("label.colourScheme_taylor"));
- taylorColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- taylorColour_actionPerformed(actionEvent);
- }
- });
- hydroColour = new JRadioButtonMenuItem();
- hydroColour.setText(MessageManager
- .getString("label.colourScheme_hydrophobic"));
- hydroColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- hydroColour_actionPerformed(actionEvent);
- }
- });
- strandColour = new JRadioButtonMenuItem();
- strandColour.setText(MessageManager
- .getString("label.colourScheme_strand_propensity"));
- strandColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- strandColour_actionPerformed(actionEvent);
- }
- });
- helixColour = new JRadioButtonMenuItem();
- helixColour.setText(MessageManager
- .getString("label.colourScheme_helix_propensity"));
- helixColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- helixColour_actionPerformed(actionEvent);
- }
- });
- turnColour = new JRadioButtonMenuItem();
- turnColour.setText(MessageManager
- .getString("label.colourScheme_turn_propensity"));
- turnColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- turnColour_actionPerformed(actionEvent);
- }
- });
- buriedColour = new JRadioButtonMenuItem();
- buriedColour.setText(MessageManager
- .getString("label.colourScheme_buried_index"));
- buriedColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- buriedColour_actionPerformed(actionEvent);
- }
- });
- nucleotideColour = new JRadioButtonMenuItem();
- nucleotideColour.setText(MessageManager
- .getString("label.colourScheme_nucleotide"));
- nucleotideColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- nucleotideColour_actionPerformed(actionEvent);
- }
- });
- purinePyrimidineColour = new JRadioButtonMenuItem();
- purinePyrimidineColour.setText(MessageManager
- .getString("label.colourScheme_purine/pyrimidine"));
- purinePyrimidineColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- purinePyrimidineColour_actionPerformed(actionEvent);
- }
- });
- userColour = new JRadioButtonMenuItem();
- userColour.setText(MessageManager.getString("action.user_defined"));
- userColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- userColour_actionPerformed(actionEvent);
- }
- });
- viewerColour = new JRadioButtonMenuItem();
- viewerColour.setSelected(false);
- viewerColour
- .setText(MessageManager.getString("label.colour_with_jmol"));
- viewerColour.setToolTipText(MessageManager
- .getString("label.let_jmol_manage_structure_colours"));
- viewerColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- viewerColour_actionPerformed(actionEvent);
- }
- });
-
- /*
- * add colour buttons to a group so their selection
- * is mutually exclusive
- */
- ButtonGroup colourButtons = new ButtonGroup();
-
- colourMenu.add(seqColour);
- colourMenu.add(chainColour);
- colourMenu.add(chargeColour);
- colourMenu.add(zappoColour);
- colourMenu.add(taylorColour);
- colourMenu.add(hydroColour);
- colourMenu.add(helixColour);
- colourMenu.add(strandColour);
- colourMenu.add(turnColour);
- colourMenu.add(buriedColour);
- colourMenu.add(purinePyrimidineColour);
-
- /*
- * add any user-defined colours that are loaded
- */
- Map<String, UserColourScheme> userColourSchemes = UserDefinedColours
- .getUserColourSchemes();
- if (userColourSchemes != null)
- {
- for (String schemeName : userColourSchemes.keySet())
- {
- final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
- schemeName);
- radioItem.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent evt)
- {
- userColour_actionPerformed(evt);
- }
- });
- colourMenu.add(radioItem);
- colourButtons.add(radioItem);
- }
- }
- colourMenu.add(userColour);
- colourMenu.add(viewerColour);
- colourMenu.add(backGround);
-
- colourButtons.add(seqColour);
- colourButtons.add(chainColour);
- colourButtons.add(chargeColour);
- colourButtons.add(zappoColour);
- colourButtons.add(taylorColour);
- colourButtons.add(hydroColour);
- colourButtons.add(helixColour);
- colourButtons.add(strandColour);
- colourButtons.add(turnColour);
- colourButtons.add(buriedColour);
- colourButtons.add(purinePyrimidineColour);
- colourButtons.add(userColour);
- colourButtons.add(viewerColour);
- }
-
protected void fitToWindow_actionPerformed()
{
}
}
- public void zappoColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void taylorColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void hydroColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void helixColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void strandColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void turnColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void buriedColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void nucleotideColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void userColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void backGround_actionPerformed(ActionEvent actionEvent)
+ public void background_actionPerformed(ActionEvent actionEvent)
{
}
{
}
-
- // {
- // return bindingModel;
- // }
-
- // public void setBindingModel(AAStructureBindingModel bindingModel)
- // {
- // this.bindingModel = bindingModel;
- // }
-
}
{
return "Annotation";
}
+
+ @Override
+ public boolean isSimple()
+ {
+ return false;
+ }
}
{
return JalviewColourScheme.Blosum62.toString();
}
+
+ @Override
+ public boolean isSimple()
+ {
+ return false;
+ }
}
{
return JalviewColourScheme.Clustal.toString();
}
+
+ @Override
+ public boolean isSimple()
+ {
+ return false;
+ }
}
* @return
*/
String getSchemeName();
+
+ /**
+ * Answers true if the colour scheme depends only on the sequence symbol, and
+ * not on other information such as alignment consensus or annotation. (Note
+ * that simple colour schemes may have a fading by percentage identity or
+ * conservation overlaid.) Simple colour schemes can be propagated to
+ * structure viewers.
+ *
+ * @return
+ */
+ boolean isSimple();
}
{
return "Covariation";
}
+
+ @Override
+ public boolean isSimple()
+ {
+ return false;
+ }
}
{
return new PIDColourScheme();
}
+
+ @Override
+ public boolean isSimple()
+ {
+ return false;
+ }
}
{
return JalviewColourScheme.RNAHelices.toString();
}
+
+ @Override
+ public boolean isSimple()
+ {
+ return false;
+ }
}
{
return false;
}
+
+ /**
+ * Default method returns true. Override this to return false in colour
+ * schemes that are not determined solely by the sequence symbol.
+ */
+ @Override
+ public boolean isSimple()
+ {
+ return true;
+ }
}
{
return JalviewColourScheme.TCoffee.toString();
}
+
+ @Override
+ public boolean isSimple()
+ {
+ return false;
+ }
}
*/
package jalview.structures.models;
+import jalview.api.AlignmentViewPanel;
+import jalview.api.FeatureRenderer;
+import jalview.api.SequenceRenderer;
import jalview.api.StructureSelectionManagerProvider;
import jalview.api.structures.JalviewStructureDisplayI;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
import jalview.io.DataSourceType;
+import jalview.schemes.ColourSchemeI;
import jalview.structure.AtomSpec;
import jalview.structure.StructureListener;
import jalview.structure.StructureMapping;
+import jalview.structure.StructureMappingcommandSet;
import jalview.structure.StructureSelectionManager;
import jalview.util.Comparison;
import jalview.util.MessageManager;
+import java.awt.Color;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
*/
protected String[] modelFileNames = null;
+ public String fileLoadingError;
+
/**
* Data bean class to simplify parameterisation in superposeStructures
*/
{
return null;
}
+
+ public abstract void setJalviewColourScheme(ColourSchemeI cs);
+
+ public abstract void superposeStructures(AlignmentI[] als, int[] alm,
+ ColumnSelection[] alc);
+
+ public abstract void setBackgroundColour(Color col);
+
+ protected abstract StructureMappingcommandSet[] getColourBySequenceCommands(
+ String[] files, SequenceRenderer sr, FeatureRenderer fr,
+ AlignmentI alignment);
+
+ /**
+ * returns the current featureRenderer that should be used to colour the
+ * structures
+ *
+ * @param alignment
+ *
+ * @return
+ */
+ public abstract FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment);
+
+ /**
+ * returns the current sequenceRenderer that should be used to colour the
+ * structures
+ *
+ * @param alignment
+ *
+ * @return
+ */
+ public abstract SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment);
+
+ protected abstract void colourBySequence(
+ StructureMappingcommandSet[] colourBySequenceCommands);
+
+ public abstract void colourByChain();
+
+ public abstract void colourByCharge();
+
+ /**
+ * colour any structures associated with sequences in the given alignment
+ * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
+ * if colourBySequence is enabled.
+ */
+ public void colourBySequence(AlignmentViewPanel alignmentv)
+ {
+ boolean showFeatures = alignmentv.getAlignViewport()
+ .isShowSequenceFeatures();
+ if (!colourBySequence || !isLoadingFinished())
+ {
+ return;
+ }
+ if (getSsm() == null)
+ {
+ return;
+ }
+ String[] files = getPdbFile();
+
+ SequenceRenderer sr = getSequenceRenderer(alignmentv);
+
+ FeatureRenderer fr = null;
+ if (showFeatures)
+ {
+ fr = getFeatureRenderer(alignmentv);
+ }
+ AlignmentI alignment = alignmentv.getAlignment();
+
+ StructureMappingcommandSet[] colourBySequenceCommands = getColourBySequenceCommands(
+ files, sr, fr, alignment);
+ colourBySequence(colourBySequenceCommands);
+ }
+
+ public boolean hasFileLoadingError()
+ {
+ return fileLoadingError != null && fileLoadingError.length() > 0;
+ }
}
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
+import jalview.api.AlignmentViewPanel;
+import jalview.api.FeatureRenderer;
+import jalview.api.SequenceRenderer;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.PDBEntry.Type;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
import jalview.gui.JvOptionPane;
import jalview.io.DataSourceType;
+import jalview.schemes.ColourSchemeI;
import jalview.structure.AtomSpec;
+import jalview.structure.StructureMappingcommandSet;
import jalview.structure.StructureSelectionManager;
import jalview.structures.models.AAStructureBindingModel.SuperposeData;
+import java.awt.Color;
import java.util.Arrays;
import java.util.List;
{
return null;
}
+
+ @Override
+ public void setJalviewColourScheme(ColourSchemeI cs)
+ {
+ }
+
+ @Override
+ public void superposeStructures(AlignmentI[] als, int[] alm,
+ ColumnSelection[] alc)
+ {
+ }
+
+ @Override
+ public void setBackgroundColour(Color col)
+ {
+ }
+
+ @Override
+ protected StructureMappingcommandSet[] getColourBySequenceCommands(
+ String[] files, SequenceRenderer sr, FeatureRenderer fr,
+ AlignmentI alignment)
+ {
+ return null;
+ }
+
+ @Override
+ public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
+ {
+ return null;
+ }
+
+ @Override
+ public SequenceRenderer getSequenceRenderer(
+ AlignmentViewPanel alignment)
+ {
+ return null;
+ }
+
+ @Override
+ protected void colourBySequence(
+ StructureMappingcommandSet[] colourBySequenceCommands)
+ {
+ }
+
+ @Override
+ public void colourByChain()
+ {
+ }
+
+ @Override
+ public void colourByCharge()
+ {
+ }
};
}
assertFalse(matched[4]); // superposable, but hidden, column
assertTrue(matched[5]);
}
+
+ public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
+ {
+ return null;
+ }
+
+ public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
+ {
+ return null;
+ }
}