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;
161 * @return true if this Jmol instance is linked with the given alignPanel
163 public boolean isLinkedWith(AlignmentPanel ap2)
165 return _aps.contains(ap2.av.getSequenceSetId());
168 public boolean isUsedforaligment(AlignmentViewPanel ap2)
171 return (_alignwith != null) && _alignwith.contains(ap2);
175 public boolean isUsedForColourBy(AlignmentViewPanel ap2)
177 return (_colourwith != null) && _colourwith.contains(ap2);
182 * @return TRUE if the view is NOT being coloured by the alignment colours.
184 public boolean isColouredByViewer()
186 return !getBinding().isColourBySequence();
189 public String getViewId()
193 viewId = System.currentTimeMillis() + "." + this.hashCode();
198 protected void setViewId(String viewId)
200 this.viewId = viewId;
203 protected void buildActionMenu()
205 if (_alignwith == null)
207 _alignwith = new Vector<>();
209 if (_alignwith.size() == 0 && ap != null)
214 for (Component c : viewerActionMenu.getMenuComponents())
216 if (c != alignStructs)
218 viewerActionMenu.remove((JMenuItem) c);
224 public AlignmentPanel getAlignmentPanel()
229 protected void setAlignmentPanel(AlignmentPanel alp)
235 public AlignmentPanel[] getAllAlignmentPanels()
237 AlignmentPanel[] t, list = new AlignmentPanel[0];
238 for (String setid : _aps)
240 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
243 t = new AlignmentPanel[list.length + panels.length];
244 System.arraycopy(list, 0, t, 0, list.length);
245 System.arraycopy(panels, 0, t, list.length, panels.length);
254 * set the primary alignmentPanel reference and add another alignPanel to the
255 * list of ones to use for colouring and aligning
259 public void addAlignmentPanel(AlignmentPanel nap)
261 if (getAlignmentPanel() == null)
263 setAlignmentPanel(nap);
265 if (!_aps.contains(nap.av.getSequenceSetId()))
267 _aps.add(nap.av.getSequenceSetId());
272 * remove any references held to the given alignment panel
277 public void removeAlignmentPanel(AlignmentViewPanel nap)
281 _alignwith.remove(nap);
282 _colourwith.remove(nap);
283 if (getAlignmentPanel() == nap)
285 setAlignmentPanel(null);
286 for (AlignmentPanel aps : getAllAlignmentPanels())
290 setAlignmentPanel(aps);
295 } catch (Exception ex)
298 if (getAlignmentPanel() != null)
304 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
306 addAlignmentPanel(nap);
307 if (!_alignwith.contains(nap))
313 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
315 if (_alignwith.contains(nap))
317 _alignwith.remove(nap);
321 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
322 boolean enableColourBySeq)
324 useAlignmentPanelForColourbyseq(nap);
325 getBinding().setColourBySequence(enableColourBySeq);
326 seqColour.setSelected(enableColourBySeq);
327 viewerColour.setSelected(!enableColourBySeq);
330 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
332 addAlignmentPanel(nap);
333 if (!_colourwith.contains(nap))
335 _colourwith.add(nap);
339 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
341 if (_colourwith.contains(nap))
343 _colourwith.remove(nap);
347 public abstract ViewerType getViewerType();
350 * add a new structure (with associated sequences and chains) to this viewer,
351 * retrieving it if necessary first.
357 * if true, new structure(s) will be aligned using associated
361 protected void addStructure(final PDBEntry pdbentry,
362 final SequenceI[] seqs, final String[] chains,
363 final IProgressIndicator alignFrame)
365 if (pdbentry.getFile() == null)
367 if (worker != null && worker.isAlive())
369 // a retrieval is in progress, wait around and add ourselves to the
371 new Thread(new Runnable()
376 while (worker != null && worker.isAlive() && _started)
380 Thread.sleep(100 + ((int) Math.random() * 100));
382 } catch (Exception e)
386 // and call ourselves again.
387 addStructure(pdbentry, seqs, chains, alignFrame);
393 // otherwise, start adding the structure.
394 getBinding().addSequenceAndChain(new PDBEntry[] { pdbentry },
396 { seqs }, new String[][] { chains });
397 addingStructures = true;
399 worker = new Thread(this);
404 protected boolean hasPdbId(String pdbId)
406 return getBinding().hasPdbId(pdbId);
410 * Returns a list of any viewer of the instantiated type. The list is
411 * restricted to those linked to the given alignment panel if it is not null.
413 protected List<StructureViewerBase> getViewersFor(AlignmentPanel alp)
415 return Desktop.instance.getStructureViewers(alp, this.getClass());
419 public void addToExistingViewer(PDBEntry pdbentry, SequenceI[] seq,
420 String[] chains, final AlignmentViewPanel apanel, String pdbId)
423 * JAL-1742 exclude view with this structure already mapped (don't offer
424 * to align chain B to chain A of the same structure); code may defend
425 * against this possibility before we reach here
431 AlignmentPanel alignPanel = (AlignmentPanel) apanel; // Implementation error if this
433 useAlignmentPanelForSuperposition(alignPanel);
434 addStructure(pdbentry, seq, chains, alignPanel.alignFrame);
438 * Adds mappings for the given sequences to an already opened PDB structure,
439 * and updates any viewers that have the PDB file
446 public void addSequenceMappingsToStructure(SequenceI[] seq,
447 String[] chains, final AlignmentViewPanel alpanel,
450 AlignmentPanel apanel = (AlignmentPanel) alpanel;
452 // TODO : Fix multiple seq to one chain issue here.
454 * create the mappings
456 apanel.getStructureSelectionManager().setMapping(seq, chains,
457 pdbFilename, DataSourceType.FILE, getProgressIndicator());
460 * alert the FeatureRenderer to show new (PDB RESNUM) features
462 if (apanel.getSeqPanel().seqCanvas.fr != null)
464 apanel.getSeqPanel().seqCanvas.fr.featuresAdded();
465 // note - we don't do a refresh for structure here because we do it
466 // explicitly for all panels later on
467 apanel.paintAlignment(true, false);
471 * add the sequences to any other viewers (of the same type) for this pdb
474 // JBPNOTE: this looks like a binding routine, rather than a gui routine
475 for (StructureViewerBase viewer : getViewersFor(null))
477 AAStructureBindingModel bindingModel = viewer.getBinding();
478 for (int pe = 0; pe < bindingModel.getPdbCount(); pe++)
480 if (bindingModel.getPdbEntry(pe).getFile().equals(pdbFilename))
482 bindingModel.addSequence(pe, seq);
483 viewer.addAlignmentPanel(apanel);
485 * add it to the set of alignments used for colouring structure by
488 viewer.useAlignmentPanelForColourbyseq(apanel);
489 viewer.buildActionMenu();
490 apanel.getStructureSelectionManager()
491 .sequenceColoursChanged(apanel);
499 public boolean addAlreadyLoadedFile(SequenceI[] seq, String[] chains,
500 final AlignmentViewPanel apanel, String pdbId)
502 String alreadyMapped = apanel.getStructureSelectionManager()
503 .alreadyMappedToFile(pdbId);
505 if (alreadyMapped == null)
510 addSequenceMappingsToStructure(seq, chains, apanel, alreadyMapped);
514 void setChainMenuItems(List<String> chainNames)
516 chainMenu.removeAll();
517 if (chainNames == null || chainNames.isEmpty())
521 JMenuItem menuItem = new JMenuItem(
522 MessageManager.getString("label.all"));
523 menuItem.addActionListener(new ActionListener()
526 public void actionPerformed(ActionEvent evt)
528 allChainsSelected = true;
529 for (int i = 0; i < chainMenu.getItemCount(); i++)
531 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
533 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
536 showSelectedChains();
537 allChainsSelected = false;
541 chainMenu.add(menuItem);
543 for (String chain : chainNames)
545 menuItem = new JCheckBoxMenuItem(chain, true);
546 menuItem.addItemListener(new ItemListener()
549 public void itemStateChanged(ItemEvent evt)
551 if (!allChainsSelected)
553 showSelectedChains();
558 chainMenu.add(menuItem);
563 * Action on selecting one of Jalview's registered colour schemes
566 public void changeColour_actionPerformed(String colourSchemeName)
568 AlignmentI al = getAlignmentPanel().av.getAlignment();
569 ColourSchemeI cs = ColourSchemes.getInstance()
570 .getColourScheme(colourSchemeName, getAlignmentPanel().av, al,
572 getBinding().colourByJalviewColourScheme(cs);
576 * Builds the colour menu
578 protected void buildColourMenu()
580 colourMenu.removeAll();
581 AlignmentI al = getAlignmentPanel().av.getAlignment();
584 * add colour by sequence, by chain, by charge and cysteine
586 colourMenu.add(seqColour);
587 colourMenu.add(chainColour);
588 colourMenu.add(chargeColour);
589 chargeColour.setEnabled(!al.isNucleotide());
592 * add all 'simple' (per-residue) colour schemes registered to Jalview
594 ButtonGroup itemGroup = ColourMenuHelper.addMenuItems(colourMenu, this,
598 * add 'colour by viewer' (menu item text is set in subclasses)
600 viewerColour.setSelected(false);
601 viewerColour.addActionListener(new ActionListener()
604 public void actionPerformed(ActionEvent actionEvent)
606 viewerColour_actionPerformed();
609 colourMenu.add(viewerColour);
612 * add 'set background colour'
614 JMenuItem backGround = new JMenuItem();
616 .setText(MessageManager.getString("action.background_colour"));
617 backGround.addActionListener(new ActionListener()
620 public void actionPerformed(ActionEvent actionEvent)
622 background_actionPerformed();
625 colourMenu.add(backGround);
628 * add colour buttons to a group so their selection is
629 * mutually exclusive (background colour is a separate option)
631 itemGroup.add(seqColour);
632 itemGroup.add(chainColour);
633 itemGroup.add(chargeColour);
634 itemGroup.add(viewerColour);
638 * Construct menu items
640 protected void initMenus()
642 AAStructureBindingModel binding = getBinding();
644 seqColour = new JRadioButtonMenuItem();
645 seqColour.setText(MessageManager.getString("action.by_sequence"));
646 seqColour.setName(ViewerColour.BySequence.name());
647 seqColour.setSelected(binding.isColourBySequence());
648 seqColour.addActionListener(new ActionListener()
651 public void actionPerformed(ActionEvent actionEvent)
653 seqColour_actionPerformed();
657 chainColour = new JRadioButtonMenuItem();
658 chainColour.setText(MessageManager.getString("action.by_chain"));
659 chainColour.setName(ViewerColour.ByChain.name());
660 chainColour.addActionListener(new ActionListener()
663 public void actionPerformed(ActionEvent actionEvent)
665 chainColour_actionPerformed();
669 chargeColour = new JRadioButtonMenuItem();
670 chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
671 chargeColour.setName(ViewerColour.ChargeCysteine.name());
672 chargeColour.addActionListener(new ActionListener()
675 public void actionPerformed(ActionEvent actionEvent)
677 chargeColour_actionPerformed();
681 viewerColour = new JRadioButtonMenuItem();
683 .setText(MessageManager.getString("label.colour_with_viewer"));
684 viewerColour.setToolTipText(MessageManager
685 .getString("label.let_viewer_manage_structure_colours"));
686 viewerColour.setName(ViewerColour.ByViewer.name());
687 viewerColour.setSelected(!binding.isColourBySequence());
689 if (_colourwith == null)
691 _colourwith = new Vector<>();
693 if (_alignwith == null)
695 _alignwith = new Vector<>();
698 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
699 MessageManager.getString("label.colour_by"), this, _colourwith,
703 public void itemStateChanged(ItemEvent e)
705 if (!seqColour.isSelected())
711 // update the viewer display now.
712 seqColour_actionPerformed();
716 viewMenu.add(seqColourBy);
718 final ItemListener handler = new ItemListener()
721 public void itemStateChanged(ItemEvent e)
723 if (_alignwith.isEmpty())
725 alignStructs.setEnabled(false);
726 alignStructs.setToolTipText(null);
730 alignStructs.setEnabled(true);
731 alignStructs.setToolTipText(MessageManager.formatMessage(
732 "label.align_structures_using_linked_alignment_views",
737 viewSelectionMenu = new ViewSelectionMenu(
738 MessageManager.getString("label.superpose_with"), this,
739 _alignwith, handler);
740 handler.itemStateChanged(null);
741 viewerActionMenu.add(viewSelectionMenu, 0);
742 viewerActionMenu.addMenuListener(new MenuListener()
745 public void menuSelected(MenuEvent e)
747 handler.itemStateChanged(null);
751 public void menuDeselected(MenuEvent e)
756 public void menuCanceled(MenuEvent e)
761 viewerActionMenu.setText(getViewerName());
762 helpItem.setText(MessageManager.formatMessage("label.viewer_help",
769 * Sends commands to the structure viewer to superimpose structures based on
770 * currently associated alignments. May optionally return an error message for
774 protected String alignStructsWithAllAlignPanels()
776 if (getAlignmentPanel() == null)
781 if (_alignwith.size() == 0)
783 _alignwith.add(getAlignmentPanel());
789 reply = getBinding().superposeStructures(_alignwith);
790 if (reply != null && !reply.isEmpty())
792 String text = MessageManager
793 .formatMessage("error.superposition_failed", reply);
794 statusBar.setText(text);
796 } catch (Exception e)
798 StringBuffer sp = new StringBuffer();
799 for (AlignmentViewPanel alignPanel : _alignwith)
801 sp.append("'" + alignPanel.getViewName() + "' ");
803 Cache.log.info("Couldn't align structures with the " + sp.toString()
804 + "associated alignment panels.", e);
810 * Opens a colour chooser dialog, and applies the chosen colour to the
811 * background of the structure viewer
814 public void background_actionPerformed()
816 String ttl = MessageManager.getString("label.select_background_colour");
817 ColourChooserListener listener = new ColourChooserListener()
820 public void colourSelected(Color c)
822 getBinding().setBackgroundColour(c);
825 JalviewColourChooser.showColourChooser(this, ttl, null, listener);
829 public void viewerColour_actionPerformed()
831 if (viewerColour.isSelected())
833 // disable automatic sequence colouring.
834 getBinding().setColourBySequence(false);
839 public void chainColour_actionPerformed()
841 chainColour.setSelected(true);
842 getBinding().colourByChain();
846 public void chargeColour_actionPerformed()
848 chargeColour.setSelected(true);
849 getBinding().colourByCharge();
853 public void seqColour_actionPerformed()
855 AAStructureBindingModel binding = getBinding();
856 binding.setColourBySequence(seqColour.isSelected());
857 if (_colourwith == null)
859 _colourwith = new Vector<>();
861 if (binding.isColourBySequence())
863 if (!binding.isLoadingFromArchive())
865 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
867 // Make the currently displayed alignment panel the associated view
868 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
871 // Set the colour using the current view for the associated alignframe
872 for (AlignmentViewPanel alignPanel : _colourwith)
874 binding.colourBySequence(alignPanel);
876 seqColoursApplied = true;
881 public void pdbFile_actionPerformed()
883 // TODO: JAL-3048 not needed for Jalview-JS - save PDB file
884 JalviewFileChooser chooser = new JalviewFileChooser(
885 Cache.getProperty("LAST_DIRECTORY"));
887 chooser.setFileView(new JalviewFileView());
888 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
889 chooser.setToolTipText(MessageManager.getString("action.save"));
891 int value = chooser.showSaveDialog(this);
893 if (value == JalviewFileChooser.APPROVE_OPTION)
895 BufferedReader in = null;
898 // TODO: cope with multiple PDB files in view
899 in = new BufferedReader(
900 new FileReader(getBinding().getStructureFiles()[0]));
901 File outFile = chooser.getSelectedFile();
903 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
905 while ((data = in.readLine()) != null)
907 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
913 } catch (Exception ex)
915 ex.printStackTrace();
923 } catch (IOException e)
933 public void viewMapping_actionPerformed()
935 CutAndPasteTransfer cap = new CutAndPasteTransfer();
938 cap.appendText(getBinding().printMappings());
939 } catch (OutOfMemoryError e)
942 "composing sequence-structure alignments for display in text box.",
947 Desktop.addInternalFrame(cap,
948 MessageManager.getString("label.pdb_sequence_mapping"), 550,
952 protected abstract String getViewerName();
955 * Configures the title and menu items of the viewer panel.
958 public void updateTitleAndMenus()
960 AAStructureBindingModel binding = getBinding();
961 if (binding.hasFileLoadingError())
966 setChainMenuItems(binding.getChainNames());
968 this.setTitle(binding.getViewerTitle(getViewerName(), true));
971 * enable 'Superpose with' if more than one mapped structure
973 viewSelectionMenu.setEnabled(false);
974 if (getBinding().getMappedStructureCount() > 1
975 && getBinding().getSequence().length > 1)
977 viewSelectionMenu.setEnabled(true);
981 * Show action menu if it has any enabled items
983 viewerActionMenu.setVisible(false);
984 for (int i = 0; i < viewerActionMenu.getItemCount(); i++)
986 if (viewerActionMenu.getItem(i).isEnabled())
988 viewerActionMenu.setVisible(true);
993 if (!binding.isLoadingFromArchive())
995 seqColour_actionPerformed();
1000 public String toString()
1006 public boolean hasMapping()
1008 if (worker != null && (addingStructures || _started))
1012 if (getBinding() == null)
1014 if (_aps == null || _aps.size() == 0)
1016 // viewer has been closed, but we did at some point run.
1021 String[] pdbids = getBinding().getStructureFiles();
1027 for (String pdbid:pdbids) {
1028 StructureMapping sm[] = getBinding().getSsm().getMapping(pdbid);
1029 if (sm!=null && sm.length>0 && sm[0]!=null) {
1033 // only return true if there is a mapping for every structure file we have loaded
1034 if (p == 0 || p != pdbids.length)
1038 // and that coloring has been applied
1039 return seqColoursApplied;
1043 public void raiseViewer()
1049 public long startProgressBar(String msg)
1051 // TODO would rather have startProgress/stopProgress as the
1052 // IProgressIndicator interface
1053 long tm = random.nextLong();
1054 if (progressBar != null)
1056 progressBar.setProgressBar(msg, tm);
1062 public void stopProgressBar(String msg, long handle)
1064 if (progressBar != null)
1066 progressBar.setProgressBar(msg, handle);
1070 protected IProgressIndicator getProgressIndicator()
1075 protected void setProgressIndicator(IProgressIndicator pi)
1080 protected void setProgressMessage(String message, long id)
1082 if (progressBar != null)
1084 progressBar.setProgressBar(message, id);
1089 public void showConsole(boolean show)
1091 // default does nothing
1095 * Show only the selected chain(s) in the viewer
1097 protected void showSelectedChains()
1099 List<String> toshow = new ArrayList<>();
1100 for (int i = 0; i < chainMenu.getItemCount(); i++)
1102 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
1104 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
1105 if (item.isSelected())
1107 toshow.add(item.getText());
1111 getBinding().showChains(toshow);
1115 * Tries to fetch a PDB file and save to a temporary local file. Returns the
1116 * saved file path if successful, or null if not.
1118 * @param processingEntry
1121 protected String fetchPdbFile(PDBEntry processingEntry)
1123 String filePath = null;
1124 Pdb pdbclient = new Pdb();
1125 EBIAlfaFold afclient = new EBIAlfaFold();
1126 AlignmentI pdbseq = null;
1127 String pdbid = processingEntry.getId();
1128 long handle = System.currentTimeMillis()
1129 + Thread.currentThread().hashCode();
1132 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
1134 String msg = MessageManager.formatMessage("status.fetching_pdb",
1137 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1138 // long hdl = startProgressBar(MessageManager.formatMessage(
1139 // "status.fetching_pdb", new Object[]
1143 if (afclient.isValidReference(pdbid))
1145 pdbseq = afclient.getSequenceRecords(pdbid);
1147 pdbseq = pdbclient.getSequenceRecords(pdbid);
1149 } catch (Exception e)
1152 "Error retrieving PDB id " + pdbid + ": " + e.getMessage());
1155 msg = pdbid + " " + MessageManager.getString("label.state_completed");
1156 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1157 // stopProgressBar(msg, hdl);
1160 * If PDB data were saved and are not invalid (empty alignment), return the
1163 if (pdbseq != null && pdbseq.getHeight() > 0)
1165 // just use the file name from the first sequence's first PDBEntry
1166 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
1167 .elementAt(0).getFile()).getAbsolutePath();
1168 processingEntry.setFile(filePath);
1174 * If supported, saves the state of the structure viewer to a temporary file
1175 * and returns the file, else returns null
1179 public File saveSession()
1181 // TODO: a wait loop to ensure the file is written fully before returning?
1182 return getBinding() == null ? null : getBinding().saveSession();
1186 * Close down this instance of Jalview's Chimera viewer, giving the user the
1187 * option to close the associated Chimera window (process). They may wish to
1188 * keep it open until they have had an opportunity to save any work.
1191 * if true, close any linked Chimera process; if false, prompt first
1194 public void closeViewer(boolean forceClose)
1196 AAStructureBindingModel binding = getBinding();
1197 if (binding != null && binding.isViewerRunning())
1201 String viewerName = getViewerName();
1202 String prompt = MessageManager
1203 .formatMessage("label.confirm_close_viewer", new Object[]
1204 { binding.getViewerTitle(viewerName, false), viewerName });
1205 prompt = JvSwingUtils.wrapTooltip(true, prompt);
1206 int confirm = JvOptionPane.showConfirmDialog(this, prompt,
1207 MessageManager.getString("label.close_viewer"),
1208 JvOptionPane.YES_NO_CANCEL_OPTION);
1210 * abort closure if user hits escape or Cancel
1212 if (confirm == JvOptionPane.CANCEL_OPTION
1213 || confirm == JvOptionPane.CLOSED_OPTION)
1217 forceClose = confirm == JvOptionPane.YES_OPTION;
1220 if (binding != null)
1222 binding.closeViewer(forceClose);
1224 setAlignmentPanel(null);
1227 _colourwith.clear();
1228 // TODO: check for memory leaks where instance isn't finalised because jmb
1229 // holds a reference to the window
1235 public void showHelp_actionPerformed()
1239 String url = getBinding().getHelpURL();
1242 BrowserLauncher.openURL(url);
1244 } catch (IOException ex)
1247 .println("Show " + getViewerName() + " failed with: "