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.Pdb;
69 * Base class with common functionality for JMol, Chimera or other structure
75 public abstract class StructureViewerBase extends GStructureViewer
76 implements Runnable, ViewSetProvider
79 * names for colour options (additional to Jalview colour schemes)
83 BySequence, ByChain, ChargeCysteine, ByViewer
87 * list of sequenceSet ids associated with the view
89 protected List<String> _aps = new ArrayList<>();
92 * list of alignment panels to use for superposition
94 protected Vector<AlignmentViewPanel> _alignwith = new Vector<>();
97 * list of alignment panels that are used for colouring structures by aligned
100 protected Vector<AlignmentViewPanel> _colourwith = new Vector<>();
102 private String viewId = null;
104 private AlignmentPanel ap;
106 protected boolean alignAddedStructures = false;
108 protected volatile boolean _started = false;
110 protected volatile boolean addingStructures = false;
112 protected Thread worker = null;
114 protected boolean allChainsSelected = false;
116 protected JMenu viewSelectionMenu;
119 * set after sequence colouring has been applied for this structure viewer.
120 * used to determine if the final sequence/structure mapping has been
123 protected volatile boolean seqColoursApplied = false;
125 private IProgressIndicator progressBar = null;
127 private Random random = new Random();
130 * Default constructor
132 public StructureViewerBase()
138 * @return true if added structures should be aligned to existing one(s)
141 public boolean isAlignAddedStructures()
143 return alignAddedStructures;
149 * if added structures should be aligned to existing one(s)
152 public void setAlignAddedStructures(boolean alignAdded)
154 alignAddedStructures = alignAdded;
160 * @return true if this Jmol instance is linked with the given alignPanel
162 public boolean isLinkedWith(AlignmentPanel ap2)
164 return _aps.contains(ap2.av.getSequenceSetId());
167 public boolean isUsedforaligment(AlignmentViewPanel ap2)
170 return (_alignwith != null) && _alignwith.contains(ap2);
174 public boolean isUsedForColourBy(AlignmentViewPanel ap2)
176 return (_colourwith != null) && _colourwith.contains(ap2);
181 * @return TRUE if the view is NOT being coloured by the alignment colours.
183 public boolean isColouredByViewer()
185 return !getBinding().isColourBySequence();
188 public String getViewId()
192 viewId = System.currentTimeMillis() + "." + this.hashCode();
197 protected void setViewId(String viewId)
199 this.viewId = viewId;
202 protected void buildActionMenu()
204 if (_alignwith == null)
206 _alignwith = new Vector<>();
208 if (_alignwith.size() == 0 && ap != null)
213 for (Component c : viewerActionMenu.getMenuComponents())
215 if (c != alignStructs)
217 viewerActionMenu.remove((JMenuItem) c);
223 public AlignmentPanel getAlignmentPanel()
228 protected void setAlignmentPanel(AlignmentPanel alp)
234 public AlignmentPanel[] getAllAlignmentPanels()
236 AlignmentPanel[] t, list = new AlignmentPanel[0];
237 for (String setid : _aps)
239 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
242 t = new AlignmentPanel[list.length + panels.length];
243 System.arraycopy(list, 0, t, 0, list.length);
244 System.arraycopy(panels, 0, t, list.length, panels.length);
253 * set the primary alignmentPanel reference and add another alignPanel to the
254 * list of ones to use for colouring and aligning
258 public void addAlignmentPanel(AlignmentPanel nap)
260 if (getAlignmentPanel() == null)
262 setAlignmentPanel(nap);
264 if (!_aps.contains(nap.av.getSequenceSetId()))
266 _aps.add(nap.av.getSequenceSetId());
271 * remove any references held to the given alignment panel
276 public void removeAlignmentPanel(AlignmentViewPanel nap)
280 _alignwith.remove(nap);
281 _colourwith.remove(nap);
282 if (getAlignmentPanel() == nap)
284 setAlignmentPanel(null);
285 for (AlignmentPanel aps : getAllAlignmentPanels())
289 setAlignmentPanel(aps);
294 } catch (Exception ex)
297 if (getAlignmentPanel() != null)
303 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
305 addAlignmentPanel(nap);
306 if (!_alignwith.contains(nap))
312 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
314 if (_alignwith.contains(nap))
316 _alignwith.remove(nap);
320 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
321 boolean enableColourBySeq)
323 useAlignmentPanelForColourbyseq(nap);
324 getBinding().setColourBySequence(enableColourBySeq);
325 seqColour.setSelected(enableColourBySeq);
326 viewerColour.setSelected(!enableColourBySeq);
329 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
331 addAlignmentPanel(nap);
332 if (!_colourwith.contains(nap))
334 _colourwith.add(nap);
338 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
340 if (_colourwith.contains(nap))
342 _colourwith.remove(nap);
346 public abstract ViewerType getViewerType();
349 * add a new structure (with associated sequences and chains) to this viewer,
350 * retrieving it if necessary first.
356 * if true, new structure(s) will be aligned using associated
360 protected void addStructure(final PDBEntry pdbentry,
361 final SequenceI[] seqs, final String[] chains,
362 final IProgressIndicator alignFrame)
364 if (pdbentry.getFile() == null)
366 if (worker != null && worker.isAlive())
368 // a retrieval is in progress, wait around and add ourselves to the
370 new Thread(new Runnable()
375 while (worker != null && worker.isAlive() && _started)
379 Thread.sleep(100 + ((int) Math.random() * 100));
381 } catch (Exception e)
385 // and call ourselves again.
386 addStructure(pdbentry, seqs, chains, alignFrame);
392 // otherwise, start adding the structure.
393 getBinding().addSequenceAndChain(new PDBEntry[] { pdbentry },
395 { seqs }, new String[][] { chains });
396 addingStructures = true;
398 worker = new Thread(this);
403 protected boolean hasPdbId(String pdbId)
405 return getBinding().hasPdbId(pdbId);
409 * Returns a list of any viewer of the instantiated type. The list is
410 * restricted to those linked to the given alignment panel if it is not null.
412 protected List<StructureViewerBase> getViewersFor(AlignmentPanel alp)
414 return Desktop.instance.getStructureViewers(alp, this.getClass());
418 public void addToExistingViewer(PDBEntry pdbentry, SequenceI[] seq,
419 String[] chains, final AlignmentViewPanel apanel, String pdbId)
422 * JAL-1742 exclude view with this structure already mapped (don't offer
423 * to align chain B to chain A of the same structure); code may defend
424 * against this possibility before we reach here
430 AlignmentPanel alignPanel = (AlignmentPanel) apanel; // Implementation error if this
432 useAlignmentPanelForSuperposition(alignPanel);
433 addStructure(pdbentry, seq, chains, alignPanel.alignFrame);
437 * Adds mappings for the given sequences to an already opened PDB structure,
438 * and updates any viewers that have the PDB file
445 public void addSequenceMappingsToStructure(SequenceI[] seq,
446 String[] chains, final AlignmentViewPanel alpanel,
449 AlignmentPanel apanel = (AlignmentPanel) alpanel;
451 // TODO : Fix multiple seq to one chain issue here.
453 * create the mappings
455 apanel.getStructureSelectionManager().setMapping(seq, chains,
456 pdbFilename, DataSourceType.FILE, getProgressIndicator());
459 * alert the FeatureRenderer to show new (PDB RESNUM) features
461 if (apanel.getSeqPanel().seqCanvas.fr != null)
463 apanel.getSeqPanel().seqCanvas.fr.featuresAdded();
464 // note - we don't do a refresh for structure here because we do it
465 // explicitly for all panels later on
466 apanel.paintAlignment(true, false);
470 * add the sequences to any other viewers (of the same type) for this pdb
473 // JBPNOTE: this looks like a binding routine, rather than a gui routine
474 for (StructureViewerBase viewer : getViewersFor(null))
476 AAStructureBindingModel bindingModel = viewer.getBinding();
477 for (int pe = 0; pe < bindingModel.getPdbCount(); pe++)
479 if (bindingModel.getPdbEntry(pe).getFile().equals(pdbFilename))
481 bindingModel.addSequence(pe, seq);
482 viewer.addAlignmentPanel(apanel);
484 * add it to the set of alignments used for colouring structure by
487 viewer.useAlignmentPanelForColourbyseq(apanel);
488 viewer.buildActionMenu();
489 apanel.getStructureSelectionManager()
490 .sequenceColoursChanged(apanel);
498 public boolean addAlreadyLoadedFile(SequenceI[] seq, String[] chains,
499 final AlignmentViewPanel apanel, String pdbId)
501 String alreadyMapped = apanel.getStructureSelectionManager()
502 .alreadyMappedToFile(pdbId);
504 if (alreadyMapped == null)
509 addSequenceMappingsToStructure(seq, chains, apanel, alreadyMapped);
513 void setChainMenuItems(List<String> chainNames)
515 chainMenu.removeAll();
516 if (chainNames == null || chainNames.isEmpty())
520 JMenuItem menuItem = new JMenuItem(
521 MessageManager.getString("label.all"));
522 menuItem.addActionListener(new ActionListener()
525 public void actionPerformed(ActionEvent evt)
527 allChainsSelected = true;
528 for (int i = 0; i < chainMenu.getItemCount(); i++)
530 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
532 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
535 showSelectedChains();
536 allChainsSelected = false;
540 chainMenu.add(menuItem);
542 for (String chain : chainNames)
544 menuItem = new JCheckBoxMenuItem(chain, true);
545 menuItem.addItemListener(new ItemListener()
548 public void itemStateChanged(ItemEvent evt)
550 if (!allChainsSelected)
552 showSelectedChains();
557 chainMenu.add(menuItem);
562 * Action on selecting one of Jalview's registered colour schemes
565 public void changeColour_actionPerformed(String colourSchemeName)
567 AlignmentI al = getAlignmentPanel().av.getAlignment();
568 ColourSchemeI cs = ColourSchemes.getInstance()
569 .getColourScheme(colourSchemeName, getAlignmentPanel().av, al,
571 getBinding().colourByJalviewColourScheme(cs);
575 * Builds the colour menu
577 protected void buildColourMenu()
579 colourMenu.removeAll();
580 AlignmentI al = getAlignmentPanel().av.getAlignment();
583 * add colour by sequence, by chain, by charge and cysteine
585 colourMenu.add(seqColour);
586 colourMenu.add(chainColour);
587 colourMenu.add(chargeColour);
588 chargeColour.setEnabled(!al.isNucleotide());
591 * add all 'simple' (per-residue) colour schemes registered to Jalview
593 ButtonGroup itemGroup = ColourMenuHelper.addMenuItems(colourMenu, this,
597 * add 'colour by viewer' (menu item text is set in subclasses)
599 viewerColour.setSelected(false);
600 viewerColour.addActionListener(new ActionListener()
603 public void actionPerformed(ActionEvent actionEvent)
605 viewerColour_actionPerformed();
608 colourMenu.add(viewerColour);
611 * add 'set background colour'
613 JMenuItem backGround = new JMenuItem();
615 .setText(MessageManager.getString("action.background_colour"));
616 backGround.addActionListener(new ActionListener()
619 public void actionPerformed(ActionEvent actionEvent)
621 background_actionPerformed();
624 colourMenu.add(backGround);
627 * add colour buttons to a group so their selection is
628 * mutually exclusive (background colour is a separate option)
630 itemGroup.add(seqColour);
631 itemGroup.add(chainColour);
632 itemGroup.add(chargeColour);
633 itemGroup.add(viewerColour);
637 * Construct menu items
639 protected void initMenus()
641 AAStructureBindingModel binding = getBinding();
643 seqColour = new JRadioButtonMenuItem();
644 seqColour.setText(MessageManager.getString("action.by_sequence"));
645 seqColour.setName(ViewerColour.BySequence.name());
646 seqColour.setSelected(binding.isColourBySequence());
647 seqColour.addActionListener(new ActionListener()
650 public void actionPerformed(ActionEvent actionEvent)
652 seqColour_actionPerformed();
656 chainColour = new JRadioButtonMenuItem();
657 chainColour.setText(MessageManager.getString("action.by_chain"));
658 chainColour.setName(ViewerColour.ByChain.name());
659 chainColour.addActionListener(new ActionListener()
662 public void actionPerformed(ActionEvent actionEvent)
664 chainColour_actionPerformed();
668 chargeColour = new JRadioButtonMenuItem();
669 chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
670 chargeColour.setName(ViewerColour.ChargeCysteine.name());
671 chargeColour.addActionListener(new ActionListener()
674 public void actionPerformed(ActionEvent actionEvent)
676 chargeColour_actionPerformed();
680 viewerColour = new JRadioButtonMenuItem();
682 .setText(MessageManager.getString("label.colour_with_viewer"));
683 viewerColour.setToolTipText(MessageManager
684 .getString("label.let_viewer_manage_structure_colours"));
685 viewerColour.setName(ViewerColour.ByViewer.name());
686 viewerColour.setSelected(!binding.isColourBySequence());
688 if (_colourwith == null)
690 _colourwith = new Vector<>();
692 if (_alignwith == null)
694 _alignwith = new Vector<>();
697 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
698 MessageManager.getString("label.colour_by"), this, _colourwith,
702 public void itemStateChanged(ItemEvent e)
704 if (!seqColour.isSelected())
710 // update the viewer display now.
711 seqColour_actionPerformed();
715 viewMenu.add(seqColourBy);
717 final ItemListener handler = new ItemListener()
720 public void itemStateChanged(ItemEvent e)
722 if (_alignwith.isEmpty())
724 alignStructs.setEnabled(false);
725 alignStructs.setToolTipText(null);
729 alignStructs.setEnabled(true);
730 alignStructs.setToolTipText(MessageManager.formatMessage(
731 "label.align_structures_using_linked_alignment_views",
736 viewSelectionMenu = new ViewSelectionMenu(
737 MessageManager.getString("label.superpose_with"), this,
738 _alignwith, handler);
739 handler.itemStateChanged(null);
740 viewerActionMenu.add(viewSelectionMenu, 0);
741 viewerActionMenu.addMenuListener(new MenuListener()
744 public void menuSelected(MenuEvent e)
746 handler.itemStateChanged(null);
750 public void menuDeselected(MenuEvent e)
755 public void menuCanceled(MenuEvent e)
760 viewerActionMenu.setText(getViewerName());
761 helpItem.setText(MessageManager.formatMessage("label.viewer_help",
768 * Sends commands to the structure viewer to superimpose structures based on
769 * currently associated alignments. May optionally return an error message for
773 protected String alignStructsWithAllAlignPanels()
775 if (getAlignmentPanel() == null)
780 if (_alignwith.size() == 0)
782 _alignwith.add(getAlignmentPanel());
788 reply = getBinding().superposeStructures(_alignwith);
789 if (reply != null && !reply.isEmpty())
791 String text = MessageManager
792 .formatMessage("error.superposition_failed", reply);
793 statusBar.setText(text);
795 } catch (Exception e)
797 StringBuffer sp = new StringBuffer();
798 for (AlignmentViewPanel alignPanel : _alignwith)
800 sp.append("'" + alignPanel.getViewName() + "' ");
802 Cache.log.info("Couldn't align structures with the " + sp.toString()
803 + "associated alignment panels.", e);
809 * Opens a colour chooser dialog, and applies the chosen colour to the
810 * background of the structure viewer
813 public void background_actionPerformed()
815 String ttl = MessageManager.getString("label.select_background_colour");
816 ColourChooserListener listener = new ColourChooserListener()
819 public void colourSelected(Color c)
821 getBinding().setBackgroundColour(c);
824 JalviewColourChooser.showColourChooser(this, ttl, null, listener);
828 public void viewerColour_actionPerformed()
830 if (viewerColour.isSelected())
832 // disable automatic sequence colouring.
833 getBinding().setColourBySequence(false);
838 public void chainColour_actionPerformed()
840 chainColour.setSelected(true);
841 getBinding().colourByChain();
845 public void chargeColour_actionPerformed()
847 chargeColour.setSelected(true);
848 getBinding().colourByCharge();
852 public void seqColour_actionPerformed()
854 AAStructureBindingModel binding = getBinding();
855 binding.setColourBySequence(seqColour.isSelected());
856 if (_colourwith == null)
858 _colourwith = new Vector<>();
860 if (binding.isColourBySequence())
862 if (!binding.isLoadingFromArchive())
864 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
866 // Make the currently displayed alignment panel the associated view
867 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
870 // Set the colour using the current view for the associated alignframe
871 for (AlignmentViewPanel alignPanel : _colourwith)
873 binding.colourBySequence(alignPanel);
875 seqColoursApplied = true;
880 public void pdbFile_actionPerformed()
882 // TODO: JAL-3048 not needed for Jalview-JS - save PDB file
883 JalviewFileChooser chooser = new JalviewFileChooser(
884 Cache.getProperty("LAST_DIRECTORY"));
886 chooser.setFileView(new JalviewFileView());
887 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
888 chooser.setToolTipText(MessageManager.getString("action.save"));
890 int value = chooser.showSaveDialog(this);
892 if (value == JalviewFileChooser.APPROVE_OPTION)
894 BufferedReader in = null;
897 // TODO: cope with multiple PDB files in view
898 in = new BufferedReader(
899 new FileReader(getBinding().getStructureFiles()[0]));
900 File outFile = chooser.getSelectedFile();
902 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
904 while ((data = in.readLine()) != null)
906 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
912 } catch (Exception ex)
914 ex.printStackTrace();
922 } catch (IOException e)
932 public void viewMapping_actionPerformed()
934 CutAndPasteTransfer cap = new CutAndPasteTransfer();
937 cap.appendText(getBinding().printMappings());
938 } catch (OutOfMemoryError e)
941 "composing sequence-structure alignments for display in text box.",
946 Desktop.addInternalFrame(cap,
947 MessageManager.getString("label.pdb_sequence_mapping"), 550,
951 protected abstract String getViewerName();
954 * Configures the title and menu items of the viewer panel.
957 public void updateTitleAndMenus()
959 AAStructureBindingModel binding = getBinding();
960 if (binding.hasFileLoadingError())
965 setChainMenuItems(binding.getChainNames());
967 this.setTitle(binding.getViewerTitle(getViewerName(), true));
970 * enable 'Superpose with' if more than one mapped structure
972 viewSelectionMenu.setEnabled(false);
973 if (getBinding().getMappedStructureCount() > 1
974 && getBinding().getSequence().length > 1)
976 viewSelectionMenu.setEnabled(true);
980 * Show action menu if it has any enabled items
982 viewerActionMenu.setVisible(false);
983 for (int i = 0; i < viewerActionMenu.getItemCount(); i++)
985 if (viewerActionMenu.getItem(i).isEnabled())
987 viewerActionMenu.setVisible(true);
992 if (!binding.isLoadingFromArchive())
994 seqColour_actionPerformed();
999 public String toString()
1005 public boolean hasMapping()
1007 if (worker != null && (addingStructures || _started))
1011 if (getBinding() == null)
1013 if (_aps == null || _aps.size() == 0)
1015 // viewer has been closed, but we did at some point run.
1020 String[] pdbids = getBinding().getStructureFiles();
1026 for (String pdbid:pdbids) {
1027 StructureMapping sm[] = getBinding().getSsm().getMapping(pdbid);
1028 if (sm!=null && sm.length>0 && sm[0]!=null) {
1032 // only return true if there is a mapping for every structure file we have loaded
1033 if (p == 0 || p != pdbids.length)
1037 // and that coloring has been applied
1038 return seqColoursApplied;
1042 public void raiseViewer()
1048 public long startProgressBar(String msg)
1050 // TODO would rather have startProgress/stopProgress as the
1051 // IProgressIndicator interface
1052 long tm = random.nextLong();
1053 if (progressBar != null)
1055 progressBar.setProgressBar(msg, tm);
1061 public void stopProgressBar(String msg, long handle)
1063 if (progressBar != null)
1065 progressBar.setProgressBar(msg, handle);
1069 protected IProgressIndicator getProgressIndicator()
1074 protected void setProgressIndicator(IProgressIndicator pi)
1079 protected void setProgressMessage(String message, long id)
1081 if (progressBar != null)
1083 progressBar.setProgressBar(message, id);
1088 public void showConsole(boolean show)
1090 // default does nothing
1094 * Show only the selected chain(s) in the viewer
1096 protected void showSelectedChains()
1098 List<String> toshow = new ArrayList<>();
1099 for (int i = 0; i < chainMenu.getItemCount(); i++)
1101 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
1103 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
1104 if (item.isSelected())
1106 toshow.add(item.getText());
1110 getBinding().showChains(toshow);
1114 * Tries to fetch a PDB file and save to a temporary local file. Returns the
1115 * saved file path if successful, or null if not.
1117 * @param processingEntry
1120 protected String fetchPdbFile(PDBEntry processingEntry)
1122 String filePath = null;
1123 Pdb pdbclient = new Pdb();
1124 AlignmentI pdbseq = null;
1125 String pdbid = processingEntry.getId();
1126 long handle = System.currentTimeMillis()
1127 + Thread.currentThread().hashCode();
1130 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
1132 String msg = MessageManager.formatMessage("status.fetching_pdb",
1135 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1136 // long hdl = startProgressBar(MessageManager.formatMessage(
1137 // "status.fetching_pdb", new Object[]
1141 pdbseq = pdbclient.getSequenceRecords(pdbid);
1142 } catch (Exception e)
1145 "Error retrieving PDB id " + pdbid + ": " + e.getMessage());
1148 msg = pdbid + " " + MessageManager.getString("label.state_completed");
1149 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1150 // stopProgressBar(msg, hdl);
1153 * If PDB data were saved and are not invalid (empty alignment), return the
1156 if (pdbseq != null && pdbseq.getHeight() > 0)
1158 // just use the file name from the first sequence's first PDBEntry
1159 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
1160 .elementAt(0).getFile()).getAbsolutePath();
1161 processingEntry.setFile(filePath);
1167 * If supported, saves the state of the structure viewer to a temporary file
1168 * and returns the file, else returns null
1172 public File saveSession()
1174 // TODO: a wait loop to ensure the file is written fully before returning?
1175 return getBinding() == null ? null : getBinding().saveSession();
1179 * Close down this instance of Jalview's Chimera viewer, giving the user the
1180 * option to close the associated Chimera window (process). They may wish to
1181 * keep it open until they have had an opportunity to save any work.
1184 * if true, close any linked Chimera process; if false, prompt first
1187 public void closeViewer(boolean forceClose)
1189 AAStructureBindingModel binding = getBinding();
1190 if (binding != null && binding.isViewerRunning())
1194 String viewerName = getViewerName();
1195 String prompt = MessageManager
1196 .formatMessage("label.confirm_close_viewer", new Object[]
1197 { binding.getViewerTitle(viewerName, false), viewerName });
1198 prompt = JvSwingUtils.wrapTooltip(true, prompt);
1199 int confirm = JvOptionPane.showConfirmDialog(this, prompt,
1200 MessageManager.getString("label.close_viewer"),
1201 JvOptionPane.YES_NO_CANCEL_OPTION);
1203 * abort closure if user hits escape or Cancel
1205 if (confirm == JvOptionPane.CANCEL_OPTION
1206 || confirm == JvOptionPane.CLOSED_OPTION)
1210 forceClose = confirm == JvOptionPane.YES_OPTION;
1213 if (binding != null)
1215 binding.closeViewer(forceClose);
1217 setAlignmentPanel(null);
1220 _colourwith.clear();
1221 // TODO: check for memory leaks where instance isn't finalised because jmb
1222 // holds a reference to the window
1228 public void showHelp_actionPerformed()
1232 String url = getBinding().getHelpURL();
1235 BrowserLauncher.openURL(url);
1237 } catch (IOException ex)
1240 .println("Show " + getViewerName() + " failed with: "