2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.awt.Color;
24 import java.awt.Component;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.awt.event.ItemEvent;
28 import java.awt.event.ItemListener;
29 import java.io.BufferedReader;
31 import java.io.FileOutputStream;
32 import java.io.FileReader;
33 import java.io.IOException;
34 import java.io.PrintWriter;
35 import java.util.ArrayList;
36 import java.util.List;
37 import java.util.Random;
38 import java.util.Vector;
40 import javax.swing.ButtonGroup;
41 import javax.swing.JCheckBoxMenuItem;
42 import javax.swing.JMenu;
43 import javax.swing.JMenuItem;
44 import javax.swing.JRadioButtonMenuItem;
45 import javax.swing.event.MenuEvent;
46 import javax.swing.event.MenuListener;
48 import jalview.api.AlignmentViewPanel;
49 import jalview.bin.Cache;
50 import jalview.datamodel.AlignmentI;
51 import jalview.datamodel.PDBEntry;
52 import jalview.datamodel.SequenceI;
53 import jalview.gui.JalviewColourChooser.ColourChooserListener;
54 import jalview.gui.StructureViewer.ViewerType;
55 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
56 import jalview.io.DataSourceType;
57 import jalview.io.JalviewFileChooser;
58 import jalview.io.JalviewFileView;
59 import jalview.jbgui.GStructureViewer;
60 import jalview.schemes.ColourSchemeI;
61 import jalview.schemes.ColourSchemes;
62 import jalview.structure.StructureMapping;
63 import jalview.structures.models.AAStructureBindingModel;
64 import jalview.util.BrowserLauncher;
65 import jalview.util.MessageManager;
66 import jalview.ws.dbsources.EBIAlfaFold;
67 import jalview.ws.dbsources.Pdb;
70 * Base class with common functionality for JMol, Chimera or other structure
76 public abstract class StructureViewerBase extends GStructureViewer
77 implements Runnable, ViewSetProvider
80 * names for colour options (additional to Jalview colour schemes)
84 BySequence, ByChain, ChargeCysteine, ByViewer
88 * list of sequenceSet ids associated with the view
90 protected List<String> _aps = new ArrayList<>();
93 * list of alignment panels to use for superposition
95 protected Vector<AlignmentViewPanel> _alignwith = new Vector<>();
98 * list of alignment panels that are used for colouring structures by aligned
101 protected Vector<AlignmentViewPanel> _colourwith = new Vector<>();
103 private String viewId = null;
105 private AlignmentPanel ap;
107 protected boolean alignAddedStructures = false;
109 protected volatile boolean _started = false;
111 protected volatile boolean addingStructures = false;
113 protected Thread worker = null;
115 protected boolean allChainsSelected = false;
117 protected JMenu viewSelectionMenu;
120 * set after sequence colouring has been applied for this structure viewer.
121 * used to determine if the final sequence/structure mapping has been
124 protected volatile boolean seqColoursApplied = false;
126 private IProgressIndicator progressBar = null;
128 private Random random = new Random();
131 * Default constructor
133 public StructureViewerBase()
139 * @return true if added structures should be aligned to existing one(s)
142 public boolean isAlignAddedStructures()
144 return alignAddedStructures;
150 * if added structures should be aligned to existing one(s)
153 public void setAlignAddedStructures(boolean alignAdded)
155 alignAddedStructures = alignAdded;
159 * called by the binding model to indicate when adding structures is happening or has been completed
160 * @param addingStructures
162 public synchronized void setAddingStructures(boolean addingStructures)
164 this.addingStructures = addingStructures;
170 * @return true if this Jmol instance is linked with the given alignPanel
172 public boolean isLinkedWith(AlignmentPanel ap2)
174 return _aps.contains(ap2.av.getSequenceSetId());
177 public boolean isUsedforaligment(AlignmentViewPanel ap2)
180 return (_alignwith != null) && _alignwith.contains(ap2);
184 public boolean isUsedForColourBy(AlignmentViewPanel ap2)
186 return (_colourwith != null) && _colourwith.contains(ap2);
191 * @return TRUE if the view is NOT being coloured by the alignment colours.
193 public boolean isColouredByViewer()
195 return !getBinding().isColourBySequence();
198 public String getViewId()
202 viewId = System.currentTimeMillis() + "." + this.hashCode();
207 protected void setViewId(String viewId)
209 this.viewId = viewId;
212 protected void buildActionMenu()
214 if (_alignwith == null)
216 _alignwith = new Vector<>();
218 if (_alignwith.size() == 0 && ap != null)
223 for (Component c : viewerActionMenu.getMenuComponents())
225 if (c != alignStructs)
227 viewerActionMenu.remove((JMenuItem) c);
233 public AlignmentPanel getAlignmentPanel()
238 protected void setAlignmentPanel(AlignmentPanel alp)
244 public AlignmentPanel[] getAllAlignmentPanels()
246 AlignmentPanel[] t, list = new AlignmentPanel[0];
247 for (String setid : _aps)
249 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
252 t = new AlignmentPanel[list.length + panels.length];
253 System.arraycopy(list, 0, t, 0, list.length);
254 System.arraycopy(panels, 0, t, list.length, panels.length);
263 * set the primary alignmentPanel reference and add another alignPanel to the
264 * list of ones to use for colouring and aligning
268 public void addAlignmentPanel(AlignmentPanel nap)
270 if (getAlignmentPanel() == null)
272 setAlignmentPanel(nap);
274 if (!_aps.contains(nap.av.getSequenceSetId()))
276 _aps.add(nap.av.getSequenceSetId());
281 * remove any references held to the given alignment panel
286 public void removeAlignmentPanel(AlignmentViewPanel nap)
290 _alignwith.remove(nap);
291 _colourwith.remove(nap);
292 if (getAlignmentPanel() == nap)
294 setAlignmentPanel(null);
295 for (AlignmentPanel aps : getAllAlignmentPanels())
299 setAlignmentPanel(aps);
304 } catch (Exception ex)
307 if (getAlignmentPanel() != null)
313 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
315 addAlignmentPanel(nap);
316 if (!_alignwith.contains(nap))
322 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
324 if (_alignwith.contains(nap))
326 _alignwith.remove(nap);
330 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
331 boolean enableColourBySeq)
333 useAlignmentPanelForColourbyseq(nap);
334 getBinding().setColourBySequence(enableColourBySeq);
335 seqColour.setSelected(enableColourBySeq);
336 viewerColour.setSelected(!enableColourBySeq);
339 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
341 addAlignmentPanel(nap);
342 if (!_colourwith.contains(nap))
344 _colourwith.add(nap);
348 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
350 if (_colourwith.contains(nap))
352 _colourwith.remove(nap);
356 public abstract ViewerType getViewerType();
359 * add a new structure (with associated sequences and chains) to this viewer,
360 * retrieving it if necessary first.
366 * if true, new structure(s) will be aligned using associated
370 protected void addStructure(final PDBEntry pdbentry,
371 final SequenceI[] seqs, final String[] chains,
372 final IProgressIndicator alignFrame)
374 if (pdbentry.getFile() == null)
376 if (worker != null && worker.isAlive())
378 // a retrieval is in progress, wait around and add ourselves to the
380 new Thread(new Runnable()
385 while (worker != null && worker.isAlive() && _started)
389 Thread.sleep(100 + ((int) Math.random() * 100));
391 } catch (Exception e)
395 // and call ourselves again.
396 addStructure(pdbentry, seqs, chains, alignFrame);
402 // otherwise, start adding the structure.
403 getBinding().addSequenceAndChain(new PDBEntry[] { pdbentry },
405 { seqs }, new String[][] { chains });
406 addingStructures = true;
408 worker = new Thread(this);
413 protected boolean hasPdbId(String pdbId)
415 return getBinding().hasPdbId(pdbId);
419 * Returns a list of any viewer of the instantiated type. The list is
420 * restricted to those linked to the given alignment panel if it is not null.
422 protected List<StructureViewerBase> getViewersFor(AlignmentPanel alp)
424 return Desktop.instance.getStructureViewers(alp, this.getClass());
428 public void addToExistingViewer(PDBEntry pdbentry, SequenceI[] seq,
429 String[] chains, final AlignmentViewPanel apanel, String pdbId)
432 * JAL-1742 exclude view with this structure already mapped (don't offer
433 * to align chain B to chain A of the same structure); code may defend
434 * against this possibility before we reach here
440 AlignmentPanel alignPanel = (AlignmentPanel) apanel; // Implementation error if this
442 useAlignmentPanelForSuperposition(alignPanel);
443 addStructure(pdbentry, seq, chains, alignPanel.alignFrame);
447 * Adds mappings for the given sequences to an already opened PDB structure,
448 * and updates any viewers that have the PDB file
455 public void addSequenceMappingsToStructure(SequenceI[] seq,
456 String[] chains, final AlignmentViewPanel alpanel,
459 AlignmentPanel apanel = (AlignmentPanel) alpanel;
461 // TODO : Fix multiple seq to one chain issue here.
463 * create the mappings
465 apanel.getStructureSelectionManager().setMapping(seq, chains,
466 pdbFilename, DataSourceType.FILE, getProgressIndicator());
469 * alert the FeatureRenderer to show new (PDB RESNUM) features
471 if (apanel.getSeqPanel().seqCanvas.fr != null)
473 apanel.getSeqPanel().seqCanvas.fr.featuresAdded();
474 // note - we don't do a refresh for structure here because we do it
475 // explicitly for all panels later on
476 apanel.paintAlignment(true, false);
480 * add the sequences to any other viewers (of the same type) for this pdb
483 // JBPNOTE: this looks like a binding routine, rather than a gui routine
484 for (StructureViewerBase viewer : getViewersFor(null))
486 AAStructureBindingModel bindingModel = viewer.getBinding();
487 for (int pe = 0; pe < bindingModel.getPdbCount(); pe++)
489 if (bindingModel.getPdbEntry(pe).getFile().equals(pdbFilename))
491 bindingModel.addSequence(pe, seq);
492 viewer.addAlignmentPanel(apanel);
494 * add it to the set of alignments used for colouring structure by
497 viewer.useAlignmentPanelForColourbyseq(apanel);
498 viewer.buildActionMenu();
499 apanel.getStructureSelectionManager()
500 .sequenceColoursChanged(apanel);
508 public boolean addAlreadyLoadedFile(SequenceI[] seq, String[] chains,
509 final AlignmentViewPanel apanel, String pdbId)
511 String alreadyMapped = apanel.getStructureSelectionManager()
512 .alreadyMappedToFile(pdbId);
514 if (alreadyMapped == null)
519 addSequenceMappingsToStructure(seq, chains, apanel, alreadyMapped);
523 void setChainMenuItems(List<String> chainNames)
525 chainMenu.removeAll();
526 if (chainNames == null || chainNames.isEmpty())
530 JMenuItem menuItem = new JMenuItem(
531 MessageManager.getString("label.all"));
532 menuItem.addActionListener(new ActionListener()
535 public void actionPerformed(ActionEvent evt)
537 allChainsSelected = true;
538 for (int i = 0; i < chainMenu.getItemCount(); i++)
540 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
542 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
545 showSelectedChains();
546 allChainsSelected = false;
550 chainMenu.add(menuItem);
552 for (String chain : chainNames)
554 menuItem = new JCheckBoxMenuItem(chain, true);
555 menuItem.addItemListener(new ItemListener()
558 public void itemStateChanged(ItemEvent evt)
560 if (!allChainsSelected)
562 showSelectedChains();
567 chainMenu.add(menuItem);
572 * Action on selecting one of Jalview's registered colour schemes
575 public void changeColour_actionPerformed(String colourSchemeName)
577 AlignmentI al = getAlignmentPanel().av.getAlignment();
578 ColourSchemeI cs = ColourSchemes.getInstance()
579 .getColourScheme(colourSchemeName, getAlignmentPanel().av, al,
581 getBinding().colourByJalviewColourScheme(cs);
585 * Builds the colour menu
587 protected void buildColourMenu()
589 colourMenu.removeAll();
590 AlignmentI al = getAlignmentPanel().av.getAlignment();
593 * add colour by sequence, by chain, by charge and cysteine
595 colourMenu.add(seqColour);
596 colourMenu.add(chainColour);
597 colourMenu.add(chargeColour);
598 chargeColour.setEnabled(!al.isNucleotide());
601 * add all 'simple' (per-residue) colour schemes registered to Jalview
603 ButtonGroup itemGroup = ColourMenuHelper.addMenuItems(colourMenu, this,
607 * add 'colour by viewer' (menu item text is set in subclasses)
609 viewerColour.setSelected(false);
610 viewerColour.addActionListener(new ActionListener()
613 public void actionPerformed(ActionEvent actionEvent)
615 viewerColour_actionPerformed();
618 colourMenu.add(viewerColour);
621 * add 'set background colour'
623 JMenuItem backGround = new JMenuItem();
625 .setText(MessageManager.getString("action.background_colour"));
626 backGround.addActionListener(new ActionListener()
629 public void actionPerformed(ActionEvent actionEvent)
631 background_actionPerformed();
634 colourMenu.add(backGround);
637 * add colour buttons to a group so their selection is
638 * mutually exclusive (background colour is a separate option)
640 itemGroup.add(seqColour);
641 itemGroup.add(chainColour);
642 itemGroup.add(chargeColour);
643 itemGroup.add(viewerColour);
647 * Construct menu items
649 protected void initMenus()
651 AAStructureBindingModel binding = getBinding();
653 seqColour = new JRadioButtonMenuItem();
654 seqColour.setText(MessageManager.getString("action.by_sequence"));
655 seqColour.setName(ViewerColour.BySequence.name());
656 seqColour.setSelected(binding.isColourBySequence());
657 seqColour.addActionListener(new ActionListener()
660 public void actionPerformed(ActionEvent actionEvent)
662 seqColour_actionPerformed();
666 chainColour = new JRadioButtonMenuItem();
667 chainColour.setText(MessageManager.getString("action.by_chain"));
668 chainColour.setName(ViewerColour.ByChain.name());
669 chainColour.addActionListener(new ActionListener()
672 public void actionPerformed(ActionEvent actionEvent)
674 chainColour_actionPerformed();
678 chargeColour = new JRadioButtonMenuItem();
679 chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
680 chargeColour.setName(ViewerColour.ChargeCysteine.name());
681 chargeColour.addActionListener(new ActionListener()
684 public void actionPerformed(ActionEvent actionEvent)
686 chargeColour_actionPerformed();
690 viewerColour = new JRadioButtonMenuItem();
692 .setText(MessageManager.getString("label.colour_with_viewer"));
693 viewerColour.setToolTipText(MessageManager
694 .getString("label.let_viewer_manage_structure_colours"));
695 viewerColour.setName(ViewerColour.ByViewer.name());
696 viewerColour.setSelected(!binding.isColourBySequence());
698 if (_colourwith == null)
700 _colourwith = new Vector<>();
702 if (_alignwith == null)
704 _alignwith = new Vector<>();
707 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
708 MessageManager.getString("label.colour_by"), this, _colourwith,
712 public void itemStateChanged(ItemEvent e)
714 if (!seqColour.isSelected())
720 // update the viewer display now.
721 seqColour_actionPerformed();
725 viewMenu.add(seqColourBy);
727 final ItemListener handler = new ItemListener()
730 public void itemStateChanged(ItemEvent e)
732 if (_alignwith.isEmpty())
734 alignStructs.setEnabled(false);
735 alignStructs.setToolTipText(null);
739 alignStructs.setEnabled(true);
740 alignStructs.setToolTipText(MessageManager.formatMessage(
741 "label.align_structures_using_linked_alignment_views",
746 viewSelectionMenu = new ViewSelectionMenu(
747 MessageManager.getString("label.superpose_with"), this,
748 _alignwith, handler);
749 handler.itemStateChanged(null);
750 viewerActionMenu.add(viewSelectionMenu, 0);
751 viewerActionMenu.addMenuListener(new MenuListener()
754 public void menuSelected(MenuEvent e)
756 handler.itemStateChanged(null);
760 public void menuDeselected(MenuEvent e)
765 public void menuCanceled(MenuEvent e)
770 viewerActionMenu.setText(getViewerName());
771 helpItem.setText(MessageManager.formatMessage("label.viewer_help",
778 * Sends commands to the structure viewer to superimpose structures based on
779 * currently associated alignments. May optionally return an error message for
783 protected String alignStructsWithAllAlignPanels()
785 if (getAlignmentPanel() == null)
790 if (_alignwith.size() == 0)
792 _alignwith.add(getAlignmentPanel());
798 reply = getBinding().superposeStructures(_alignwith);
799 if (reply != null && !reply.isEmpty())
801 String text = MessageManager
802 .formatMessage("error.superposition_failed", reply);
803 statusBar.setText(text);
805 } catch (Exception e)
807 StringBuffer sp = new StringBuffer();
808 for (AlignmentViewPanel alignPanel : _alignwith)
810 sp.append("'" + alignPanel.getViewName() + "' ");
812 Cache.log.info("Couldn't align structures with the " + sp.toString()
813 + "associated alignment panels.", e);
819 * Opens a colour chooser dialog, and applies the chosen colour to the
820 * background of the structure viewer
823 public void background_actionPerformed()
825 String ttl = MessageManager.getString("label.select_background_colour");
826 ColourChooserListener listener = new ColourChooserListener()
829 public void colourSelected(Color c)
831 getBinding().setBackgroundColour(c);
834 JalviewColourChooser.showColourChooser(this, ttl, null, listener);
838 public void viewerColour_actionPerformed()
840 if (viewerColour.isSelected())
842 // disable automatic sequence colouring.
843 getBinding().setColourBySequence(false);
848 public void chainColour_actionPerformed()
850 chainColour.setSelected(true);
851 getBinding().colourByChain();
855 public void chargeColour_actionPerformed()
857 chargeColour.setSelected(true);
858 getBinding().colourByCharge();
862 public void seqColour_actionPerformed()
864 AAStructureBindingModel binding = getBinding();
865 binding.setColourBySequence(seqColour.isSelected());
866 if (_colourwith == null)
868 _colourwith = new Vector<>();
870 if (binding.isColourBySequence())
872 if (!binding.isLoadingFromArchive())
874 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
876 // Make the currently displayed alignment panel the associated view
877 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
880 // Set the colour using the current view for the associated alignframe
881 for (AlignmentViewPanel alignPanel : _colourwith)
883 binding.colourBySequence(alignPanel);
885 seqColoursApplied = true;
890 public void pdbFile_actionPerformed()
892 // TODO: JAL-3048 not needed for Jalview-JS - save PDB file
893 JalviewFileChooser chooser = new JalviewFileChooser(
894 Cache.getProperty("LAST_DIRECTORY"));
896 chooser.setFileView(new JalviewFileView());
897 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
898 chooser.setToolTipText(MessageManager.getString("action.save"));
900 int value = chooser.showSaveDialog(this);
902 if (value == JalviewFileChooser.APPROVE_OPTION)
904 BufferedReader in = null;
907 // TODO: cope with multiple PDB files in view
908 in = new BufferedReader(
909 new FileReader(getBinding().getStructureFiles()[0]));
910 File outFile = chooser.getSelectedFile();
912 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
914 while ((data = in.readLine()) != null)
916 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
922 } catch (Exception ex)
924 ex.printStackTrace();
932 } catch (IOException e)
942 public void viewMapping_actionPerformed()
944 CutAndPasteTransfer cap = new CutAndPasteTransfer();
947 cap.appendText(getBinding().printMappings());
948 } catch (OutOfMemoryError e)
951 "composing sequence-structure alignments for display in text box.",
956 Desktop.addInternalFrame(cap,
957 MessageManager.getString("label.pdb_sequence_mapping"), 550,
961 protected abstract String getViewerName();
964 * Configures the title and menu items of the viewer panel.
967 public void updateTitleAndMenus()
969 AAStructureBindingModel binding = getBinding();
970 if (binding.hasFileLoadingError())
975 setChainMenuItems(binding.getChainNames());
977 this.setTitle(binding.getViewerTitle(getViewerName(), true));
980 * enable 'Superpose with' if more than one mapped structure
982 viewSelectionMenu.setEnabled(false);
983 if (getBinding().getMappedStructureCount() > 1
984 && getBinding().getSequence().length > 1)
986 viewSelectionMenu.setEnabled(true);
990 * Show action menu if it has any enabled items
992 viewerActionMenu.setVisible(false);
993 for (int i = 0; i < viewerActionMenu.getItemCount(); i++)
995 if (viewerActionMenu.getItem(i).isEnabled())
997 viewerActionMenu.setVisible(true);
1002 if (!binding.isLoadingFromArchive())
1004 seqColour_actionPerformed();
1009 public String toString()
1015 public boolean hasMapping()
1017 if (worker != null && (addingStructures || _started))
1021 if (getBinding() == null)
1023 if (_aps == null || _aps.size() == 0)
1025 // viewer has been closed, but we did at some point run.
1030 String[] pdbids = getBinding().getStructureFiles();
1036 for (String pdbid:pdbids) {
1037 StructureMapping sm[] = getBinding().getSsm().getMapping(pdbid);
1038 if (sm!=null && sm.length>0 && sm[0]!=null) {
1042 // only return true if there is a mapping for every structure file we have loaded
1043 if (p == 0 || p != pdbids.length)
1047 // and that coloring has been applied
1048 return seqColoursApplied;
1052 public void raiseViewer()
1058 public long startProgressBar(String msg)
1060 // TODO would rather have startProgress/stopProgress as the
1061 // IProgressIndicator interface
1062 long tm = random.nextLong();
1063 if (progressBar != null)
1065 progressBar.setProgressBar(msg, tm);
1071 public void stopProgressBar(String msg, long handle)
1073 if (progressBar != null)
1075 progressBar.setProgressBar(msg, handle);
1079 protected IProgressIndicator getProgressIndicator()
1084 protected void setProgressIndicator(IProgressIndicator pi)
1089 public void setProgressMessage(String message, long id)
1091 if (progressBar != null)
1093 progressBar.setProgressBar(message, id);
1098 public void showConsole(boolean show)
1100 // default does nothing
1104 * Show only the selected chain(s) in the viewer
1106 protected void showSelectedChains()
1108 List<String> toshow = new ArrayList<>();
1109 for (int i = 0; i < chainMenu.getItemCount(); i++)
1111 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
1113 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
1114 if (item.isSelected())
1116 toshow.add(item.getText());
1120 getBinding().showChains(toshow);
1124 * Tries to fetch a PDB file and save to a temporary local file. Returns the
1125 * saved file path if successful, or null if not.
1127 * @param processingEntry
1130 protected String fetchPdbFile(PDBEntry processingEntry)
1132 String filePath = null;
1133 Pdb pdbclient = new Pdb();
1134 EBIAlfaFold afclient = new EBIAlfaFold();
1135 AlignmentI pdbseq = null;
1136 String pdbid = processingEntry.getId();
1137 long handle = System.currentTimeMillis()
1138 + Thread.currentThread().hashCode();
1141 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
1143 String msg = MessageManager.formatMessage("status.fetching_pdb",
1146 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1147 // long hdl = startProgressBar(MessageManager.formatMessage(
1148 // "status.fetching_pdb", new Object[]
1152 if (afclient.isValidReference(pdbid))
1154 pdbseq = afclient.getSequenceRecords(pdbid);
1156 pdbseq = pdbclient.getSequenceRecords(pdbid);
1158 } catch (Exception e)
1161 "Error retrieving PDB id " + pdbid + ": " + e.getMessage());
1164 msg = pdbid + " " + MessageManager.getString("label.state_completed");
1165 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1166 // stopProgressBar(msg, hdl);
1169 * If PDB data were saved and are not invalid (empty alignment), return the
1172 if (pdbseq != null && pdbseq.getHeight() > 0)
1174 // just use the file name from the first sequence's first PDBEntry
1175 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
1176 .elementAt(0).getFile()).getAbsolutePath();
1177 processingEntry.setFile(filePath);
1183 * If supported, saves the state of the structure viewer to a temporary file
1184 * and returns the file, else returns null
1188 public File saveSession()
1190 // TODO: a wait loop to ensure the file is written fully before returning?
1191 return getBinding() == null ? null : getBinding().saveSession();
1195 * Close down this instance of Jalview's Chimera viewer, giving the user the
1196 * option to close the associated Chimera window (process). They may wish to
1197 * keep it open until they have had an opportunity to save any work.
1200 * if true, close any linked Chimera process; if false, prompt first
1203 public void closeViewer(boolean forceClose)
1205 AAStructureBindingModel binding = getBinding();
1206 if (binding != null && binding.isViewerRunning())
1210 String viewerName = getViewerName();
1211 String prompt = MessageManager
1212 .formatMessage("label.confirm_close_viewer", new Object[]
1213 { binding.getViewerTitle(viewerName, false), viewerName });
1214 prompt = JvSwingUtils.wrapTooltip(true, prompt);
1215 int confirm = JvOptionPane.showConfirmDialog(this, prompt,
1216 MessageManager.getString("label.close_viewer"),
1217 JvOptionPane.YES_NO_CANCEL_OPTION);
1219 * abort closure if user hits escape or Cancel
1221 if (confirm == JvOptionPane.CANCEL_OPTION
1222 || confirm == JvOptionPane.CLOSED_OPTION)
1226 forceClose = confirm == JvOptionPane.YES_OPTION;
1229 if (binding != null)
1231 binding.closeViewer(forceClose);
1233 setAlignmentPanel(null);
1236 _colourwith.clear();
1237 // TODO: check for memory leaks where instance isn't finalised because jmb
1238 // holds a reference to the window
1244 public void showHelp_actionPerformed()
1248 String url = getBinding().getHelpURL();
1251 BrowserLauncher.openURL(url);
1253 } catch (IOException ex)
1256 .println("Show " + getViewerName() + " failed with: "