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.JColorChooser;
43 import javax.swing.JMenu;
44 import javax.swing.JMenuItem;
45 import javax.swing.JRadioButtonMenuItem;
46 import javax.swing.event.MenuEvent;
47 import javax.swing.event.MenuListener;
49 import jalview.api.AlignmentViewPanel;
50 import jalview.bin.Cache;
51 import jalview.datamodel.AlignmentI;
52 import jalview.datamodel.PDBEntry;
53 import jalview.datamodel.SequenceI;
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 public void background_actionPerformed()
806 Color col = JColorChooser.showDialog(this,
807 MessageManager.getString("label.select_background_colour"),
811 getBinding().setBackgroundColour(col);
816 public void viewerColour_actionPerformed()
818 if (viewerColour.isSelected())
820 // disable automatic sequence colouring.
821 getBinding().setColourBySequence(false);
826 public void chainColour_actionPerformed()
828 chainColour.setSelected(true);
829 getBinding().colourByChain();
833 public void chargeColour_actionPerformed()
835 chargeColour.setSelected(true);
836 getBinding().colourByCharge();
840 public void seqColour_actionPerformed()
842 AAStructureBindingModel binding = getBinding();
843 binding.setColourBySequence(seqColour.isSelected());
844 if (_colourwith == null)
846 _colourwith = new Vector<>();
848 if (binding.isColourBySequence())
850 if (!binding.isLoadingFromArchive())
852 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
854 // Make the currently displayed alignment panel the associated view
855 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
858 // Set the colour using the current view for the associated alignframe
859 for (AlignmentViewPanel alignPanel : _colourwith)
861 binding.colourBySequence(alignPanel);
863 seqColoursApplied = true;
868 public void pdbFile_actionPerformed()
870 JalviewFileChooser chooser = new JalviewFileChooser(
871 Cache.getProperty("LAST_DIRECTORY"));
873 chooser.setFileView(new JalviewFileView());
874 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
875 chooser.setToolTipText(MessageManager.getString("action.save"));
877 int value = chooser.showSaveDialog(this);
879 if (value == JalviewFileChooser.APPROVE_OPTION)
881 BufferedReader in = null;
884 // TODO: cope with multiple PDB files in view
885 in = new BufferedReader(
886 new FileReader(getBinding().getStructureFiles()[0]));
887 File outFile = chooser.getSelectedFile();
889 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
891 while ((data = in.readLine()) != null)
893 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
899 } catch (Exception ex)
901 ex.printStackTrace();
909 } catch (IOException e)
919 public void viewMapping_actionPerformed()
921 CutAndPasteTransfer cap = new CutAndPasteTransfer();
924 cap.appendText(getBinding().printMappings());
925 } catch (OutOfMemoryError e)
928 "composing sequence-structure alignments for display in text box.",
933 Desktop.addInternalFrame(cap,
934 MessageManager.getString("label.pdb_sequence_mapping"), 550,
938 protected abstract String getViewerName();
941 * Configures the title and menu items of the viewer panel.
944 public void updateTitleAndMenus()
946 AAStructureBindingModel binding = getBinding();
947 if (binding.hasFileLoadingError())
952 setChainMenuItems(binding.getChainNames());
954 this.setTitle(binding.getViewerTitle(getViewerName(), true));
957 * enable 'Superpose with' if more than one mapped structure
959 viewSelectionMenu.setEnabled(false);
960 if (getBinding().getStructureFiles().length > 1
961 && getBinding().getSequence().length > 1)
963 viewSelectionMenu.setEnabled(true);
967 * Show action menu if it has any enabled items
969 viewerActionMenu.setVisible(false);
970 for (int i = 0; i < viewerActionMenu.getItemCount(); i++)
972 if (viewerActionMenu.getItem(i).isEnabled())
974 viewerActionMenu.setVisible(true);
979 if (!binding.isLoadingFromArchive())
981 seqColour_actionPerformed();
986 public String toString()
992 public boolean hasMapping()
994 if (worker != null && (addingStructures || _started))
998 if (getBinding() == null)
1000 if (_aps == null || _aps.size() == 0)
1002 // viewer has been closed, but we did at some point run.
1007 String[] pdbids = getBinding().getStructureFiles();
1013 for (String pdbid:pdbids) {
1014 StructureMapping sm[] = getBinding().getSsm().getMapping(pdbid);
1015 if (sm!=null && sm.length>0 && sm[0]!=null) {
1019 // only return true if there is a mapping for every structure file we have loaded
1020 if (p == 0 || p != pdbids.length)
1024 // and that coloring has been applied
1025 return seqColoursApplied;
1029 public void raiseViewer()
1035 public long startProgressBar(String msg)
1037 // TODO would rather have startProgress/stopProgress as the
1038 // IProgressIndicator interface
1039 long tm = random.nextLong();
1040 if (progressBar != null)
1042 progressBar.setProgressBar(msg, tm);
1048 public void stopProgressBar(String msg, long handle)
1050 if (progressBar != null)
1052 progressBar.setProgressBar(msg, handle);
1056 protected IProgressIndicator getProgressIndicator()
1061 protected void setProgressIndicator(IProgressIndicator pi)
1066 protected void setProgressMessage(String message, long id)
1068 if (progressBar != null)
1070 progressBar.setProgressBar(message, id);
1075 public void showConsole(boolean show)
1077 // default does nothing
1081 * Show only the selected chain(s) in the viewer
1083 protected void showSelectedChains()
1085 List<String> toshow = new ArrayList<>();
1086 for (int i = 0; i < chainMenu.getItemCount(); i++)
1088 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
1090 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
1091 if (item.isSelected())
1093 toshow.add(item.getText());
1097 getBinding().showChains(toshow);
1101 * Tries to fetch a PDB file and save to a temporary local file. Returns the
1102 * saved file path if successful, or null if not.
1104 * @param processingEntry
1107 protected String fetchPdbFile(PDBEntry processingEntry)
1109 String filePath = null;
1110 Pdb pdbclient = new Pdb();
1111 AlignmentI pdbseq = null;
1112 String pdbid = processingEntry.getId();
1113 long handle = System.currentTimeMillis()
1114 + Thread.currentThread().hashCode();
1117 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
1119 String msg = MessageManager.formatMessage("status.fetching_pdb",
1122 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1123 // long hdl = startProgressBar(MessageManager.formatMessage(
1124 // "status.fetching_pdb", new Object[]
1128 pdbseq = pdbclient.getSequenceRecords(pdbid);
1129 } catch (Exception e)
1132 "Error retrieving PDB id " + pdbid + ": " + e.getMessage());
1135 msg = pdbid + " " + MessageManager.getString("label.state_completed");
1136 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1137 // stopProgressBar(msg, hdl);
1140 * If PDB data were saved and are not invalid (empty alignment), return the
1143 if (pdbseq != null && pdbseq.getHeight() > 0)
1145 // just use the file name from the first sequence's first PDBEntry
1146 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
1147 .elementAt(0).getFile()).getAbsolutePath();
1148 processingEntry.setFile(filePath);
1154 * If supported, saves the state of the structure viewer to a temporary file
1155 * and returns the file, else returns null
1159 public File saveSession()
1161 // TODO: a wait loop to ensure the file is written fully before returning?
1162 return getBinding() == null ? null : getBinding().saveSession();
1166 * Close down this instance of Jalview's Chimera viewer, giving the user the
1167 * option to close the associated Chimera window (process). They may wish to
1168 * keep it open until they have had an opportunity to save any work.
1171 * if true, close any linked Chimera process; if false, prompt first
1174 public void closeViewer(boolean forceClose)
1176 AAStructureBindingModel binding = getBinding();
1177 if (binding != null && binding.isViewerRunning())
1181 String viewerName = getViewerName();
1182 String prompt = MessageManager
1183 .formatMessage("label.confirm_close_viewer", new Object[]
1184 { binding.getViewerTitle(viewerName, false), viewerName });
1185 prompt = JvSwingUtils.wrapTooltip(true, prompt);
1186 int confirm = JvOptionPane.showConfirmDialog(this, prompt,
1187 MessageManager.getString("label.close_viewer"),
1188 JvOptionPane.YES_NO_CANCEL_OPTION);
1190 * abort closure if user hits escape or Cancel
1192 if (confirm == JvOptionPane.CANCEL_OPTION
1193 || confirm == JvOptionPane.CLOSED_OPTION)
1197 forceClose = confirm == JvOptionPane.YES_OPTION;
1199 binding.closeViewer(forceClose);
1201 setAlignmentPanel(null);
1204 _colourwith.clear();
1205 // TODO: check for memory leaks where instance isn't finalised because jmb
1206 // holds a reference to the window