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.MessageManager;
65 import jalview.ws.dbsources.Pdb;
68 * Base class with common functionality for JMol, Chimera or other structure
74 public abstract class StructureViewerBase extends GStructureViewer
75 implements Runnable, ViewSetProvider
78 * names for colour options (additional to Jalview colour schemes)
82 BySequence, ByChain, ChargeCysteine, ByViewer
86 * list of sequenceSet ids associated with the view
88 protected List<String> _aps = new ArrayList<>();
91 * list of alignment panels to use for superposition
93 protected Vector<AlignmentViewPanel> _alignwith = new Vector<>();
96 * list of alignment panels that are used for colouring structures by aligned
99 protected Vector<AlignmentViewPanel> _colourwith = new Vector<>();
101 private String viewId = null;
103 private AlignmentPanel ap;
105 protected boolean alignAddedStructures = false;
107 protected volatile boolean _started = false;
109 protected volatile boolean addingStructures = false;
111 protected Thread worker = null;
113 protected boolean allChainsSelected = false;
115 protected JMenu viewSelectionMenu;
118 * set after sequence colouring has been applied for this structure viewer.
119 * used to determine if the final sequence/structure mapping has been
122 protected volatile boolean seqColoursApplied = false;
124 private IProgressIndicator progressBar = null;
126 private Random random = new Random();
129 * Default constructor
131 public StructureViewerBase()
137 * @return true if added structures should be aligned to existing one(s)
140 public boolean isAlignAddedStructures()
142 return alignAddedStructures;
148 * if added structures should be aligned to existing one(s)
151 public void setAlignAddedStructures(boolean alignAdded)
153 alignAddedStructures = alignAdded;
159 * @return true if this Jmol instance is linked with the given alignPanel
161 public boolean isLinkedWith(AlignmentPanel ap2)
163 return _aps.contains(ap2.av.getSequenceSetId());
166 public boolean isUsedforaligment(AlignmentViewPanel ap2)
169 return (_alignwith != null) && _alignwith.contains(ap2);
173 public boolean isUsedForColourBy(AlignmentViewPanel ap2)
175 return (_colourwith != null) && _colourwith.contains(ap2);
180 * @return TRUE if the view is NOT being coloured by the alignment colours.
182 public boolean isColouredByViewer()
184 return !getBinding().isColourBySequence();
187 public String getViewId()
191 viewId = System.currentTimeMillis() + "." + this.hashCode();
196 protected void setViewId(String viewId)
198 this.viewId = viewId;
201 protected void buildActionMenu()
203 if (_alignwith == null)
205 _alignwith = new Vector<>();
207 if (_alignwith.size() == 0 && ap != null)
212 for (Component c : viewerActionMenu.getMenuComponents())
214 if (c != alignStructs)
216 viewerActionMenu.remove((JMenuItem) c);
222 public AlignmentPanel getAlignmentPanel()
227 protected void setAlignmentPanel(AlignmentPanel alp)
233 public AlignmentPanel[] getAllAlignmentPanels()
235 AlignmentPanel[] t, list = new AlignmentPanel[0];
236 for (String setid : _aps)
238 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
241 t = new AlignmentPanel[list.length + panels.length];
242 System.arraycopy(list, 0, t, 0, list.length);
243 System.arraycopy(panels, 0, t, list.length, panels.length);
252 * set the primary alignmentPanel reference and add another alignPanel to the
253 * list of ones to use for colouring and aligning
257 public void addAlignmentPanel(AlignmentPanel nap)
259 if (getAlignmentPanel() == null)
261 setAlignmentPanel(nap);
263 if (!_aps.contains(nap.av.getSequenceSetId()))
265 _aps.add(nap.av.getSequenceSetId());
270 * remove any references held to the given alignment panel
275 public void removeAlignmentPanel(AlignmentViewPanel nap)
279 _alignwith.remove(nap);
280 _colourwith.remove(nap);
281 if (getAlignmentPanel() == nap)
283 setAlignmentPanel(null);
284 for (AlignmentPanel aps : getAllAlignmentPanels())
288 setAlignmentPanel(aps);
293 } catch (Exception ex)
296 if (getAlignmentPanel() != null)
302 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
304 addAlignmentPanel(nap);
305 if (!_alignwith.contains(nap))
311 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
313 if (_alignwith.contains(nap))
315 _alignwith.remove(nap);
319 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
320 boolean enableColourBySeq)
322 useAlignmentPanelForColourbyseq(nap);
323 getBinding().setColourBySequence(enableColourBySeq);
324 seqColour.setSelected(enableColourBySeq);
325 viewerColour.setSelected(!enableColourBySeq);
328 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
330 addAlignmentPanel(nap);
331 if (!_colourwith.contains(nap))
333 _colourwith.add(nap);
337 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
339 if (_colourwith.contains(nap))
341 _colourwith.remove(nap);
345 public abstract ViewerType getViewerType();
348 * add a new structure (with associated sequences and chains) to this viewer,
349 * retrieving it if necessary first.
355 * if true, new structure(s) will be aligned using associated
359 protected void addStructure(final PDBEntry pdbentry,
360 final SequenceI[] seqs, final String[] chains,
361 final IProgressIndicator alignFrame)
363 if (pdbentry.getFile() == null)
365 if (worker != null && worker.isAlive())
367 // a retrieval is in progress, wait around and add ourselves to the
369 new Thread(new Runnable()
374 while (worker != null && worker.isAlive() && _started)
378 Thread.sleep(100 + ((int) Math.random() * 100));
380 } catch (Exception e)
384 // and call ourselves again.
385 addStructure(pdbentry, seqs, chains, alignFrame);
391 // otherwise, start adding the structure.
392 getBinding().addSequenceAndChain(new PDBEntry[] { pdbentry },
394 { seqs }, new String[][] { chains });
395 addingStructures = true;
397 worker = new Thread(this);
402 protected boolean hasPdbId(String pdbId)
404 return getBinding().hasPdbId(pdbId);
408 * Returns a list of any viewer of the instantiated type. The list is
409 * restricted to those linked to the given alignment panel if it is not null.
411 protected List<StructureViewerBase> getViewersFor(AlignmentPanel alp)
413 return Desktop.instance.getStructureViewers(alp, this.getClass());
417 public void addToExistingViewer(PDBEntry pdbentry, SequenceI[] seq,
418 String[] chains, final AlignmentViewPanel apanel, String pdbId)
421 * JAL-1742 exclude view with this structure already mapped (don't offer
422 * to align chain B to chain A of the same structure); code may defend
423 * against this possibility before we reach here
429 AlignmentPanel alignPanel = (AlignmentPanel) apanel; // Implementation error if this
431 useAlignmentPanelForSuperposition(alignPanel);
432 addStructure(pdbentry, seq, chains, alignPanel.alignFrame);
436 * Adds mappings for the given sequences to an already opened PDB structure,
437 * and updates any viewers that have the PDB file
444 public void addSequenceMappingsToStructure(SequenceI[] seq,
445 String[] chains, final AlignmentViewPanel alpanel,
448 AlignmentPanel apanel = (AlignmentPanel) alpanel;
450 // TODO : Fix multiple seq to one chain issue here.
452 * create the mappings
454 apanel.getStructureSelectionManager().setMapping(seq, chains,
455 pdbFilename, DataSourceType.FILE, getProgressIndicator());
458 * alert the FeatureRenderer to show new (PDB RESNUM) features
460 if (apanel.getSeqPanel().seqCanvas.fr != null)
462 apanel.getSeqPanel().seqCanvas.fr.featuresAdded();
463 // note - we don't do a refresh for structure here because we do it
464 // explicitly for all panels later on
465 apanel.paintAlignment(true, false);
469 * add the sequences to any other viewers (of the same type) for this pdb
472 // JBPNOTE: this looks like a binding routine, rather than a gui routine
473 for (StructureViewerBase viewer : getViewersFor(null))
475 AAStructureBindingModel bindingModel = viewer.getBinding();
476 for (int pe = 0; pe < bindingModel.getPdbCount(); pe++)
478 if (bindingModel.getPdbEntry(pe).getFile().equals(pdbFilename))
480 bindingModel.addSequence(pe, seq);
481 viewer.addAlignmentPanel(apanel);
483 * add it to the set of alignments used for colouring structure by
486 viewer.useAlignmentPanelForColourbyseq(apanel);
487 viewer.buildActionMenu();
488 apanel.getStructureSelectionManager()
489 .sequenceColoursChanged(apanel);
497 public boolean addAlreadyLoadedFile(SequenceI[] seq, String[] chains,
498 final AlignmentViewPanel apanel, String pdbId)
500 String alreadyMapped = apanel.getStructureSelectionManager()
501 .alreadyMappedToFile(pdbId);
503 if (alreadyMapped == null)
508 addSequenceMappingsToStructure(seq, chains, apanel, alreadyMapped);
512 void setChainMenuItems(List<String> chainNames)
514 chainMenu.removeAll();
515 if (chainNames == null || chainNames.isEmpty())
519 JMenuItem menuItem = new JMenuItem(
520 MessageManager.getString("label.all"));
521 menuItem.addActionListener(new ActionListener()
524 public void actionPerformed(ActionEvent evt)
526 allChainsSelected = true;
527 for (int i = 0; i < chainMenu.getItemCount(); i++)
529 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
531 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
534 showSelectedChains();
535 allChainsSelected = false;
539 chainMenu.add(menuItem);
541 for (String chain : chainNames)
543 menuItem = new JCheckBoxMenuItem(chain, true);
544 menuItem.addItemListener(new ItemListener()
547 public void itemStateChanged(ItemEvent evt)
549 if (!allChainsSelected)
551 showSelectedChains();
556 chainMenu.add(menuItem);
561 * Action on selecting one of Jalview's registered colour schemes
564 public void changeColour_actionPerformed(String colourSchemeName)
566 AlignmentI al = getAlignmentPanel().av.getAlignment();
567 ColourSchemeI cs = ColourSchemes.getInstance()
568 .getColourScheme(colourSchemeName, getAlignmentPanel().av, al,
570 getBinding().colourByJalviewColourScheme(cs);
574 * Builds the colour menu
576 protected void buildColourMenu()
578 colourMenu.removeAll();
579 AlignmentI al = getAlignmentPanel().av.getAlignment();
582 * add colour by sequence, by chain, by charge and cysteine
584 colourMenu.add(seqColour);
585 colourMenu.add(chainColour);
586 colourMenu.add(chargeColour);
587 chargeColour.setEnabled(!al.isNucleotide());
590 * add all 'simple' (per-residue) colour schemes registered to Jalview
592 ButtonGroup itemGroup = ColourMenuHelper.addMenuItems(colourMenu, this,
596 * add 'colour by viewer' (menu item text is set in subclasses)
598 viewerColour.setSelected(false);
599 viewerColour.addActionListener(new ActionListener()
602 public void actionPerformed(ActionEvent actionEvent)
604 viewerColour_actionPerformed();
607 colourMenu.add(viewerColour);
610 * add 'set background colour'
612 JMenuItem backGround = new JMenuItem();
614 .setText(MessageManager.getString("action.background_colour"));
615 backGround.addActionListener(new ActionListener()
618 public void actionPerformed(ActionEvent actionEvent)
620 background_actionPerformed();
623 colourMenu.add(backGround);
626 * add colour buttons to a group so their selection is
627 * mutually exclusive (background colour is a separate option)
629 itemGroup.add(seqColour);
630 itemGroup.add(chainColour);
631 itemGroup.add(chargeColour);
632 itemGroup.add(viewerColour);
636 * Construct menu items
638 protected void initMenus()
640 AAStructureBindingModel binding = getBinding();
642 seqColour = new JRadioButtonMenuItem();
643 seqColour.setText(MessageManager.getString("action.by_sequence"));
644 seqColour.setName(ViewerColour.BySequence.name());
645 seqColour.setSelected(binding.isColourBySequence());
646 seqColour.addActionListener(new ActionListener()
649 public void actionPerformed(ActionEvent actionEvent)
651 seqColour_actionPerformed();
655 chainColour = new JRadioButtonMenuItem();
656 chainColour.setText(MessageManager.getString("action.by_chain"));
657 chainColour.setName(ViewerColour.ByChain.name());
658 chainColour.addActionListener(new ActionListener()
661 public void actionPerformed(ActionEvent actionEvent)
663 chainColour_actionPerformed();
667 chargeColour = new JRadioButtonMenuItem();
668 chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
669 chargeColour.setName(ViewerColour.ChargeCysteine.name());
670 chargeColour.addActionListener(new ActionListener()
673 public void actionPerformed(ActionEvent actionEvent)
675 chargeColour_actionPerformed();
679 viewerColour = new JRadioButtonMenuItem();
681 .setText(MessageManager.getString("label.colour_with_viewer"));
682 viewerColour.setToolTipText(MessageManager
683 .getString("label.let_viewer_manage_structure_colours"));
684 viewerColour.setName(ViewerColour.ByViewer.name());
685 viewerColour.setSelected(!binding.isColourBySequence());
687 if (_colourwith == null)
689 _colourwith = new Vector<>();
691 if (_alignwith == null)
693 _alignwith = new Vector<>();
696 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
697 MessageManager.getString("label.colour_by"), this, _colourwith,
701 public void itemStateChanged(ItemEvent e)
703 if (!seqColour.isSelected())
709 // update the Chimera display now.
710 seqColour_actionPerformed();
714 viewMenu.add(seqColourBy);
716 final ItemListener handler = new ItemListener()
719 public void itemStateChanged(ItemEvent e)
721 if (_alignwith.isEmpty())
723 alignStructs.setEnabled(false);
724 alignStructs.setToolTipText(null);
728 alignStructs.setEnabled(true);
729 alignStructs.setToolTipText(MessageManager.formatMessage(
730 "label.align_structures_using_linked_alignment_views",
735 viewSelectionMenu = new ViewSelectionMenu(
736 MessageManager.getString("label.superpose_with"), this,
737 _alignwith, handler);
738 handler.itemStateChanged(null);
739 viewerActionMenu.add(viewSelectionMenu, 0);
740 viewerActionMenu.addMenuListener(new MenuListener()
743 public void menuSelected(MenuEvent e)
745 handler.itemStateChanged(null);
749 public void menuDeselected(MenuEvent e)
754 public void menuCanceled(MenuEvent e)
763 * Sends commands to the structure viewer to superimpose structures based on
764 * currently associated alignments. May optionally return an error message for
768 protected String alignStructsWithAllAlignPanels()
770 if (getAlignmentPanel() == null)
775 if (_alignwith.size() == 0)
777 _alignwith.add(getAlignmentPanel());
783 reply = getBinding().superposeStructures(_alignwith);
784 if (reply != null && !reply.isEmpty())
786 String text = MessageManager
787 .formatMessage("error.superposition_failed", reply);
788 statusBar.setText(text);
790 } catch (Exception e)
792 StringBuffer sp = new StringBuffer();
793 for (AlignmentViewPanel alignPanel : _alignwith)
795 sp.append("'" + alignPanel.getViewName() + "' ");
797 Cache.log.info("Couldn't align structures with the " + sp.toString()
798 + "associated alignment panels.", e);
804 * Opens a colour chooser dialog, and applies the chosen colour to the
805 * background of the structure viewer
808 public void background_actionPerformed()
810 String ttl = MessageManager.getString("label.select_background_colour");
811 ColourChooserListener listener = new ColourChooserListener()
814 public void colourSelected(Color c)
816 getBinding().setBackgroundColour(c);
819 JalviewColourChooser.showColourChooser(this, ttl, null, listener);
823 public void viewerColour_actionPerformed()
825 if (viewerColour.isSelected())
827 // disable automatic sequence colouring.
828 getBinding().setColourBySequence(false);
833 public void chainColour_actionPerformed()
835 chainColour.setSelected(true);
836 getBinding().colourByChain();
840 public void chargeColour_actionPerformed()
842 chargeColour.setSelected(true);
843 getBinding().colourByCharge();
847 public void seqColour_actionPerformed()
849 AAStructureBindingModel binding = getBinding();
850 binding.setColourBySequence(seqColour.isSelected());
851 if (_colourwith == null)
853 _colourwith = new Vector<>();
855 if (binding.isColourBySequence())
857 if (!binding.isLoadingFromArchive())
859 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
861 // Make the currently displayed alignment panel the associated view
862 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
865 // Set the colour using the current view for the associated alignframe
866 for (AlignmentViewPanel alignPanel : _colourwith)
868 binding.colourBySequence(alignPanel);
870 seqColoursApplied = true;
875 public void pdbFile_actionPerformed()
877 // TODO: JAL-3048 not needed for Jalview-JS - save PDB file
878 JalviewFileChooser chooser = new JalviewFileChooser(
879 Cache.getProperty("LAST_DIRECTORY"));
881 chooser.setFileView(new JalviewFileView());
882 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
883 chooser.setToolTipText(MessageManager.getString("action.save"));
885 int value = chooser.showSaveDialog(this);
887 if (value == JalviewFileChooser.APPROVE_OPTION)
889 BufferedReader in = null;
892 // TODO: cope with multiple PDB files in view
893 in = new BufferedReader(
894 new FileReader(getBinding().getStructureFiles()[0]));
895 File outFile = chooser.getSelectedFile();
897 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
899 while ((data = in.readLine()) != null)
901 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
907 } catch (Exception ex)
909 ex.printStackTrace();
917 } catch (IOException e)
927 public void viewMapping_actionPerformed()
929 CutAndPasteTransfer cap = new CutAndPasteTransfer();
932 cap.appendText(getBinding().printMappings());
933 } catch (OutOfMemoryError e)
936 "composing sequence-structure alignments for display in text box.",
941 Desktop.addInternalFrame(cap,
942 MessageManager.getString("label.pdb_sequence_mapping"), 550,
946 protected abstract String getViewerName();
949 * Configures the title and menu items of the viewer panel.
952 public void updateTitleAndMenus()
954 AAStructureBindingModel binding = getBinding();
955 if (binding.hasFileLoadingError())
960 setChainMenuItems(binding.getChainNames());
962 this.setTitle(binding.getViewerTitle(getViewerName(), true));
965 * enable 'Superpose with' if more than one mapped structure
967 viewSelectionMenu.setEnabled(false);
968 if (getBinding().getStructureFiles().length > 1
969 && getBinding().getSequence().length > 1)
971 viewSelectionMenu.setEnabled(true);
975 * Show action menu if it has any enabled items
977 viewerActionMenu.setVisible(false);
978 for (int i = 0; i < viewerActionMenu.getItemCount(); i++)
980 if (viewerActionMenu.getItem(i).isEnabled())
982 viewerActionMenu.setVisible(true);
987 if (!binding.isLoadingFromArchive())
989 seqColour_actionPerformed();
994 public String toString()
1000 public boolean hasMapping()
1002 if (worker != null && (addingStructures || _started))
1006 if (getBinding() == null)
1008 if (_aps == null || _aps.size() == 0)
1010 // viewer has been closed, but we did at some point run.
1015 String[] pdbids = getBinding().getStructureFiles();
1021 for (String pdbid:pdbids) {
1022 StructureMapping sm[] = getBinding().getSsm().getMapping(pdbid);
1023 if (sm!=null && sm.length>0 && sm[0]!=null) {
1027 // only return true if there is a mapping for every structure file we have loaded
1028 if (p == 0 || p != pdbids.length)
1032 // and that coloring has been applied
1033 return seqColoursApplied;
1037 public void raiseViewer()
1043 public long startProgressBar(String msg)
1045 // TODO would rather have startProgress/stopProgress as the
1046 // IProgressIndicator interface
1047 long tm = random.nextLong();
1048 if (progressBar != null)
1050 progressBar.setProgressBar(msg, tm);
1056 public void stopProgressBar(String msg, long handle)
1058 if (progressBar != null)
1060 progressBar.setProgressBar(msg, handle);
1064 protected IProgressIndicator getProgressIndicator()
1069 protected void setProgressIndicator(IProgressIndicator pi)
1074 protected void setProgressMessage(String message, long id)
1076 if (progressBar != null)
1078 progressBar.setProgressBar(message, id);
1083 public void showConsole(boolean show)
1085 // default does nothing
1089 * Show only the selected chain(s) in the viewer
1091 protected void showSelectedChains()
1093 List<String> toshow = new ArrayList<>();
1094 for (int i = 0; i < chainMenu.getItemCount(); i++)
1096 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
1098 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
1099 if (item.isSelected())
1101 toshow.add(item.getText());
1105 getBinding().showChains(toshow);
1109 * Tries to fetch a PDB file and save to a temporary local file. Returns the
1110 * saved file path if successful, or null if not.
1112 * @param processingEntry
1115 protected String fetchPdbFile(PDBEntry processingEntry)
1117 String filePath = null;
1118 Pdb pdbclient = new Pdb();
1119 AlignmentI pdbseq = null;
1120 String pdbid = processingEntry.getId();
1121 long handle = System.currentTimeMillis()
1122 + Thread.currentThread().hashCode();
1125 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
1127 String msg = MessageManager.formatMessage("status.fetching_pdb",
1130 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1131 // long hdl = startProgressBar(MessageManager.formatMessage(
1132 // "status.fetching_pdb", new Object[]
1136 pdbseq = pdbclient.getSequenceRecords(pdbid);
1137 } catch (Exception e)
1140 "Error retrieving PDB id " + pdbid + ": " + e.getMessage());
1143 msg = pdbid + " " + MessageManager.getString("label.state_completed");
1144 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1145 // stopProgressBar(msg, hdl);
1148 * If PDB data were saved and are not invalid (empty alignment), return the
1151 if (pdbseq != null && pdbseq.getHeight() > 0)
1153 // just use the file name from the first sequence's first PDBEntry
1154 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
1155 .elementAt(0).getFile()).getAbsolutePath();
1156 processingEntry.setFile(filePath);
1162 * If supported, saves the state of the structure viewer to a temporary file
1163 * and returns the file, else returns null
1167 public File saveSession()
1169 // TODO: a wait loop to ensure the file is written fully before returning?
1170 return getBinding() == null ? null : getBinding().saveSession();
1174 * Close down this instance of Jalview's Chimera viewer, giving the user the
1175 * option to close the associated Chimera window (process). They may wish to
1176 * keep it open until they have had an opportunity to save any work.
1179 * if true, close any linked Chimera process; if false, prompt first
1182 public void closeViewer(boolean forceClose)
1184 AAStructureBindingModel binding = getBinding();
1185 if (binding != null && binding.isViewerRunning())
1189 String viewerName = getViewerName();
1190 String prompt = MessageManager
1191 .formatMessage("label.confirm_close_viewer", new Object[]
1192 { binding.getViewerTitle(viewerName, false), viewerName });
1193 prompt = JvSwingUtils.wrapTooltip(true, prompt);
1194 int confirm = JvOptionPane.showConfirmDialog(this, prompt,
1195 MessageManager.getString("label.close_viewer"),
1196 JvOptionPane.YES_NO_CANCEL_OPTION);
1198 * abort closure if user hits escape or Cancel
1200 if (confirm == JvOptionPane.CANCEL_OPTION
1201 || confirm == JvOptionPane.CLOSED_OPTION)
1205 forceClose = confirm == JvOptionPane.YES_OPTION;
1207 binding.closeViewer(forceClose);
1209 setAlignmentPanel(null);
1212 _colourwith.clear();
1213 // TODO: check for memory leaks where instance isn't finalised because jmb
1214 // holds a reference to the window