X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FStructureViewerBase.java;h=25d999844248950414cf956d1a4bad9e8edf30a1;hb=6e0685c38078ddcf959db75d001f8c92b114c8ae;hp=840dbae06e19ca91634e08897cf89a11f78fb218;hpb=d156987a513b1da92fd6fbf7678b4a8e7ffc8d08;p=jalview.git diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index 840dbae..25d9998 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -22,9 +22,7 @@ package jalview.gui; import jalview.api.AlignmentViewPanel; import jalview.bin.Cache; -import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; -import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.gui.StructureViewer.ViewerType; @@ -38,6 +36,7 @@ import jalview.schemes.ColourSchemes; import jalview.structure.StructureMapping; import jalview.structures.models.AAStructureBindingModel; import jalview.util.MessageManager; +import jalview.ws.dbsources.Pdb; import java.awt.Color; import java.awt.Component; @@ -53,6 +52,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; +import java.util.Random; import java.util.Vector; import javax.swing.ButtonGroup; @@ -90,13 +90,13 @@ public abstract class StructureViewerBase extends GStructureViewer /** * list of alignment panels to use for superposition */ - protected Vector _alignwith = new Vector<>(); + protected Vector _alignwith = new Vector<>(); /** * list of alignment panels that are used for colouring structures by aligned * sequences */ - protected Vector _colourwith = new Vector<>(); + protected Vector _colourwith = new Vector<>(); private String viewId = null; @@ -121,6 +121,10 @@ public abstract class StructureViewerBase extends GStructureViewer */ protected volatile boolean seqColoursApplied = false; + private IProgressIndicator progressBar = null; + + private Random random = new Random(); + /** * Default constructor */ @@ -159,13 +163,14 @@ public abstract class StructureViewerBase extends GStructureViewer return _aps.contains(ap2.av.getSequenceSetId()); } - public boolean isUsedforaligment(AlignmentPanel ap2) + public boolean isUsedforaligment(AlignmentViewPanel ap2) { return (_alignwith != null) && _alignwith.contains(ap2); } - public boolean isUsedforcolourby(AlignmentPanel ap2) + @Override + public boolean isUsedForColourBy(AlignmentViewPanel ap2) { return (_colourwith != null) && _colourwith.contains(ap2); } @@ -215,6 +220,7 @@ public abstract class StructureViewerBase extends GStructureViewer } } + @Override public AlignmentPanel getAlignmentPanel() { return ap; @@ -267,7 +273,8 @@ public abstract class StructureViewerBase extends GStructureViewer * * @param nap */ - public void removeAlignmentPanel(AlignmentPanel nap) + @Override + public void removeAlignmentPanel(AlignmentViewPanel nap) { try { @@ -339,8 +346,6 @@ public abstract class StructureViewerBase extends GStructureViewer public abstract ViewerType getViewerType(); - protected abstract IProgressIndicator getIProgressIndicator(); - /** * add a new structure (with associated sequences and chains) to this viewer, * retrieving it if necessary first. @@ -449,7 +454,7 @@ public abstract class StructureViewerBase extends GStructureViewer * create the mappings */ apanel.getStructureSelectionManager().setMapping(seq, chains, - pdbFilename, DataSourceType.FILE, getIProgressIndicator()); + pdbFilename, DataSourceType.FILE, getProgressIndicator()); /* * alert the FeatureRenderer to show new (PDB RESNUM) features @@ -554,8 +559,6 @@ public abstract class StructureViewerBase extends GStructureViewer } } - abstract void showSelectedChains(); - /** * Action on selecting one of Jalview's registered colour schemes */ @@ -564,8 +567,9 @@ public abstract class StructureViewerBase extends GStructureViewer { AlignmentI al = getAlignmentPanel().av.getAlignment(); ColourSchemeI cs = ColourSchemes.getInstance() - .getColourScheme(colourSchemeName, al, null); - getBinding().setJalviewColourScheme(cs); + .getColourScheme(colourSchemeName, getAlignmentPanel().av, al, + null); + getBinding().colourByJalviewColourScheme(cs); } /** @@ -599,7 +603,7 @@ public abstract class StructureViewerBase extends GStructureViewer @Override public void actionPerformed(ActionEvent actionEvent) { - viewerColour_actionPerformed(actionEvent); + viewerColour_actionPerformed(); } }); colourMenu.add(viewerColour); @@ -615,7 +619,7 @@ public abstract class StructureViewerBase extends GStructureViewer @Override public void actionPerformed(ActionEvent actionEvent) { - background_actionPerformed(actionEvent); + background_actionPerformed(); } }); colourMenu.add(backGround); @@ -646,7 +650,7 @@ public abstract class StructureViewerBase extends GStructureViewer @Override public void actionPerformed(ActionEvent actionEvent) { - seqColour_actionPerformed(actionEvent); + seqColour_actionPerformed(); } }); @@ -658,7 +662,7 @@ public abstract class StructureViewerBase extends GStructureViewer @Override public void actionPerformed(ActionEvent actionEvent) { - chainColour_actionPerformed(actionEvent); + chainColour_actionPerformed(); } }); @@ -670,7 +674,7 @@ public abstract class StructureViewerBase extends GStructureViewer @Override public void actionPerformed(ActionEvent actionEvent) { - chargeColour_actionPerformed(actionEvent); + chargeColour_actionPerformed(); } }); @@ -702,7 +706,7 @@ public abstract class StructureViewerBase extends GStructureViewer else { // update the Chimera display now. - seqColour_actionPerformed(null); + seqColour_actionPerformed(); } } }); @@ -746,24 +750,13 @@ public abstract class StructureViewerBase extends GStructureViewer buildColourMenu(); } - @Override - public void setJalviewColourScheme(ColourSchemeI cs) - { - getBinding().setJalviewColourScheme(cs); - } - /** * Sends commands to the structure viewer to superimpose structures based on * currently associated alignments. May optionally return an error message for * the operation. */ @Override - protected String alignStructs_actionPerformed(ActionEvent actionEvent) - { - return alignStructs_withAllAlignPanels(); - } - - protected String alignStructs_withAllAlignPanels() + protected String alignStructsWithAllAlignPanels() { if (getAlignmentPanel() == null) { @@ -778,19 +771,8 @@ public abstract class StructureViewerBase extends GStructureViewer String reply = null; try { - AlignmentI[] als = new Alignment[_alignwith.size()]; - HiddenColumns[] alc = new HiddenColumns[_alignwith.size()]; - int[] alm = new int[_alignwith.size()]; - int a = 0; - - for (AlignmentPanel alignPanel : _alignwith) - { - als[a] = alignPanel.av.getAlignment(); - alm[a] = -1; - alc[a++] = alignPanel.av.getAlignment().getHiddenColumns(); - } - reply = getBinding().superposeStructures(als, alm, alc); - if (reply != null) + reply = getBinding().superposeStructures(_alignwith); + if (reply != null && !reply.isEmpty()) { String text = MessageManager .formatMessage("error.superposition_failed", reply); @@ -799,9 +781,9 @@ public abstract class StructureViewerBase extends GStructureViewer } catch (Exception e) { StringBuffer sp = new StringBuffer(); - for (AlignmentPanel alignPanel : _alignwith) + for (AlignmentViewPanel alignPanel : _alignwith) { - sp.append("'" + alignPanel.alignFrame.getTitle() + "' "); + sp.append("'" + alignPanel.getViewName() + "' "); } Cache.log.info("Couldn't align structures with the " + sp.toString() + "associated alignment panels.", e); @@ -810,7 +792,7 @@ public abstract class StructureViewerBase extends GStructureViewer } @Override - public void background_actionPerformed(ActionEvent actionEvent) + public void background_actionPerformed() { Color col = JColorChooser.showDialog(this, MessageManager.getString("label.select_background_colour"), @@ -822,7 +804,7 @@ public abstract class StructureViewerBase extends GStructureViewer } @Override - public void viewerColour_actionPerformed(ActionEvent actionEvent) + public void viewerColour_actionPerformed() { if (viewerColour.isSelected()) { @@ -832,21 +814,21 @@ public abstract class StructureViewerBase extends GStructureViewer } @Override - public void chainColour_actionPerformed(ActionEvent actionEvent) + public void chainColour_actionPerformed() { chainColour.setSelected(true); getBinding().colourByChain(); } @Override - public void chargeColour_actionPerformed(ActionEvent actionEvent) + public void chargeColour_actionPerformed() { chargeColour.setSelected(true); getBinding().colourByCharge(); } @Override - public void seqColour_actionPerformed(ActionEvent actionEvent) + public void seqColour_actionPerformed() { AAStructureBindingModel binding = getBinding(); binding.setColourBySequence(seqColour.isSelected()); @@ -865,7 +847,7 @@ public abstract class StructureViewerBase extends GStructureViewer } } // Set the colour using the current view for the associated alignframe - for (AlignmentPanel alignPanel : _colourwith) + for (AlignmentViewPanel alignPanel : _colourwith) { binding.colourBySequence(alignPanel); } @@ -874,7 +856,7 @@ public abstract class StructureViewerBase extends GStructureViewer } @Override - public void pdbFile_actionPerformed(ActionEvent actionEvent) + public void pdbFile_actionPerformed() { JalviewFileChooser chooser = new JalviewFileChooser( Cache.getProperty("LAST_DIRECTORY")); @@ -925,7 +907,7 @@ public abstract class StructureViewerBase extends GStructureViewer } @Override - public void viewMapping_actionPerformed(ActionEvent actionEvent) + public void viewMapping_actionPerformed() { CutAndPasteTransfer cap = new CutAndPasteTransfer(); try @@ -987,7 +969,7 @@ public abstract class StructureViewerBase extends GStructureViewer if (!binding.isLoadingFromArchive()) { - seqColour_actionPerformed(null); + seqColour_actionPerformed(); } } @@ -1034,4 +1016,129 @@ public abstract class StructureViewerBase extends GStructureViewer return seqColoursApplied; } + @Override + public void raiseViewer() + { + toFront(); + } + + @Override + public long startProgressBar(String msg) + { + // TODO would rather have startProgress/stopProgress as the + // IProgressIndicator interface + long tm = random.nextLong(); + if (progressBar != null) + { + progressBar.setProgressBar(msg, tm); + } + return tm; + } + + @Override + public void stopProgressBar(String msg, long handle) + { + if (progressBar != null) + { + progressBar.setProgressBar(msg, handle); + } + } + + protected IProgressIndicator getProgressIndicator() + { + return progressBar; + } + + protected void setProgressIndicator(IProgressIndicator pi) + { + progressBar = pi; + } + + protected void setProgressMessage(String message, long id) + { + if (progressBar != null) + { + progressBar.setProgressBar(message, id); + } + } + + @Override + public void showConsole(boolean show) + { + // default does nothing + } + + /** + * Show only the selected chain(s) in the viewer + */ + protected void showSelectedChains() + { + List 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. + * + * @param processingEntry + * @return + */ + protected String fetchPdbFile(PDBEntry processingEntry) + { + String filePath = null; + Pdb pdbclient = new Pdb(); + AlignmentI pdbseq = null; + String pdbid = processingEntry.getId(); + long handle = System.currentTimeMillis() + + Thread.currentThread().hashCode(); + + /* + * Write 'fetching PDB' progress on AlignFrame as we are not yet visible + */ + String msg = MessageManager.formatMessage("status.fetching_pdb", + new Object[] + { pdbid }); + getAlignmentPanel().alignFrame.setProgressBar(msg, handle); + // long hdl = startProgressBar(MessageManager.formatMessage( + // "status.fetching_pdb", new Object[] + // { pdbid })); + try + { + pdbseq = pdbclient.getSequenceRecords(pdbid); + } catch (Exception e) + { + System.err.println( + "Error retrieving PDB id " + pdbid + ": " + e.getMessage()); + } finally + { + msg = pdbid + " " + MessageManager.getString("label.state_completed"); + getAlignmentPanel().alignFrame.setProgressBar(msg, handle); + // stopProgressBar(msg, hdl); + } + /* + * If PDB data were saved and are not invalid (empty alignment), return the + * file path. + */ + if (pdbseq != null && pdbseq.getHeight() > 0) + { + // just use the file name from the first sequence's first PDBEntry + filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries() + .elementAt(0).getFile()).getAbsolutePath(); + processingEntry.setFile(filePath); + } + return filePath; + } + }