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.Collections;
37 import java.util.List;
38 import java.util.Random;
39 import java.util.Vector;
41 import javax.swing.ButtonGroup;
42 import javax.swing.JCheckBoxMenuItem;
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.JalviewColourChooser.ColourChooserListener;
55 import jalview.gui.StructureViewer.ViewerType;
56 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
57 import jalview.io.DataSourceType;
58 import jalview.io.JalviewFileChooser;
59 import jalview.io.JalviewFileView;
60 import jalview.jbgui.GStructureViewer;
61 import jalview.schemes.ColourSchemeI;
62 import jalview.schemes.ColourSchemes;
63 import jalview.structure.StructureMapping;
64 import jalview.structures.models.AAStructureBindingModel;
65 import jalview.util.BrowserLauncher;
66 import jalview.util.MessageManager;
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
79 private static final String UNMAPPED = "(unmapped)";
82 * names for colour options (additional to Jalview colour schemes)
86 BySequence, ByChain, ChargeCysteine, ByViewer
90 * list of sequenceSet ids associated with the view
92 protected List<String> _aps = new ArrayList<>();
95 * list of alignment panels to use for superposition
97 protected Vector<AlignmentViewPanel> _alignwith = new Vector<>();
100 * list of alignment panels that are used for colouring structures by aligned
103 protected Vector<AlignmentViewPanel> _colourwith = new Vector<>();
105 private String viewId = null;
107 private AlignmentPanel ap;
109 protected boolean alignAddedStructures = false;
111 protected volatile boolean _started = false;
113 protected volatile boolean addingStructures = false;
115 protected Thread worker = null;
117 protected boolean allChainsSelected = false;
119 protected JMenu viewSelectionMenu;
122 * set after sequence colouring has been applied for this structure viewer.
123 * used to determine if the final sequence/structure mapping has been
126 protected volatile boolean seqColoursApplied = false;
128 private IProgressIndicator progressBar = null;
130 private Random random = new Random();
133 * Default constructor
135 public StructureViewerBase()
141 * @return true if added structures should be aligned to existing one(s)
144 public boolean isAlignAddedStructures()
146 return alignAddedStructures;
152 * if added structures should be aligned to existing one(s)
155 public void setAlignAddedStructures(boolean alignAdded)
157 alignAddedStructures = alignAdded;
163 * @return true if this Jmol instance is linked with the given alignPanel
165 public boolean isLinkedWith(AlignmentPanel ap2)
167 return _aps.contains(ap2.av.getSequenceSetId());
170 public boolean isUsedforaligment(AlignmentViewPanel ap2)
173 return (_alignwith != null) && _alignwith.contains(ap2);
177 public boolean isUsedForColourBy(AlignmentViewPanel avp)
179 return (_colourwith != null) && _colourwith.contains(avp);
184 * @return TRUE if the view is NOT being coloured by the alignment colours.
186 public boolean isColouredByViewer()
188 return !getBinding().isColourBySequence();
191 public String getViewId()
195 viewId = System.currentTimeMillis() + "." + this.hashCode();
200 protected void setViewId(String viewId)
202 this.viewId = viewId;
205 protected void buildActionMenu()
207 if (_alignwith == null)
209 _alignwith = new Vector<>();
211 if (_alignwith.size() == 0 && ap != null)
216 for (Component c : viewerActionMenu.getMenuComponents())
218 if (c != alignStructs)
220 viewerActionMenu.remove((JMenuItem) c);
226 public AlignmentPanel getAlignmentPanel()
231 protected void setAlignmentPanel(AlignmentPanel alp)
237 public AlignmentPanel[] getAllAlignmentPanels()
239 AlignmentPanel[] t, list = new AlignmentPanel[0];
240 for (String setid : _aps)
242 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
245 t = new AlignmentPanel[list.length + panels.length];
246 System.arraycopy(list, 0, t, 0, list.length);
247 System.arraycopy(panels, 0, t, list.length, panels.length);
256 * set the primary alignmentPanel reference and add another alignPanel to the
257 * list of ones to use for colouring and aligning
261 public void addAlignmentPanel(AlignmentPanel nap)
263 if (getAlignmentPanel() == null)
265 setAlignmentPanel(nap);
267 if (!_aps.contains(nap.av.getSequenceSetId()))
269 _aps.add(nap.av.getSequenceSetId());
274 * remove any references held to the given alignment panel
279 public void removeAlignmentPanel(AlignmentViewPanel nap)
283 _alignwith.remove(nap);
284 _colourwith.remove(nap);
285 if (getAlignmentPanel() == nap)
287 setAlignmentPanel(null);
288 for (AlignmentPanel aps : getAllAlignmentPanels())
292 setAlignmentPanel(aps);
297 } catch (Exception ex)
300 if (getAlignmentPanel() != null)
306 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
308 addAlignmentPanel(nap);
309 if (!_alignwith.contains(nap))
315 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
317 if (_alignwith.contains(nap))
319 _alignwith.remove(nap);
323 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
324 boolean enableColourBySeq)
326 useAlignmentPanelForColourbyseq(nap);
327 getBinding().setColourBySequence(enableColourBySeq);
328 seqColour.setSelected(enableColourBySeq);
329 viewerColour.setSelected(!enableColourBySeq);
332 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
334 addAlignmentPanel(nap);
335 if (!_colourwith.contains(nap))
337 _colourwith.add(nap);
341 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
343 if (_colourwith.contains(nap))
345 _colourwith.remove(nap);
349 public abstract ViewerType getViewerType();
352 * add a new structure (with associated sequences and chains) to this viewer,
353 * retrieving it if necessary first.
359 * if true, new structure(s) will be aligned using associated
363 protected void addStructure(final PDBEntry pdbentry,
364 final SequenceI[] seqs, final String[] chains,
365 final IProgressIndicator alignFrame)
367 if (pdbentry.getFile() == null)
369 if (worker != null && worker.isAlive())
371 // a retrieval is in progress, wait around and add ourselves to the
373 new Thread(new Runnable()
378 while (worker != null && worker.isAlive() && _started)
382 Thread.sleep(100 + ((int) Math.random() * 100));
384 } catch (Exception e)
388 // and call ourselves again.
389 addStructure(pdbentry, seqs, chains, alignFrame);
395 // otherwise, start adding the structure.
396 getBinding().addSequenceAndChain(new PDBEntry[] { pdbentry },
398 { seqs }, new String[][] { chains });
399 addingStructures = true;
401 worker = new Thread(this);
406 protected boolean hasPdbId(String pdbId)
408 return getBinding().hasPdbId(pdbId);
412 * Returns a list of any viewer of the instantiated type. The list is
413 * restricted to those linked to the given alignment panel if it is not null.
415 protected List<StructureViewerBase> getViewersFor(AlignmentPanel alp)
417 return Desktop.instance.getStructureViewers(alp, this.getClass());
421 public void addToExistingViewer(PDBEntry pdbentry, SequenceI[] seq,
422 String[] chains, final AlignmentViewPanel apanel, String pdbId)
425 * JAL-1742 exclude view with this structure already mapped (don't offer
426 * to align chain B to chain A of the same structure); code may defend
427 * against this possibility before we reach here
433 AlignmentPanel alignPanel = (AlignmentPanel) apanel; // Implementation error if this
435 useAlignmentPanelForSuperposition(alignPanel);
436 addStructure(pdbentry, seq, chains, alignPanel.alignFrame);
440 * Adds mappings for the given sequences to an already opened PDB structure,
441 * and updates any viewers that have the PDB file
448 public void addSequenceMappingsToStructure(SequenceI[] seq,
449 String[] chains, final AlignmentViewPanel alpanel,
452 AlignmentPanel apanel = (AlignmentPanel) alpanel;
454 // TODO : Fix multiple seq to one chain issue here.
456 * create the mappings
458 apanel.getStructureSelectionManager().setMapping(seq, chains,
459 pdbFilename, DataSourceType.FILE, getProgressIndicator());
462 * alert the FeatureRenderer to show new (PDB RESNUM) features
464 if (apanel.getSeqPanel().seqCanvas.fr != null)
466 apanel.getSeqPanel().seqCanvas.fr.featuresAdded();
467 // note - we don't do a refresh for structure here because we do it
468 // explicitly for all panels later on
469 apanel.paintAlignment(true, false);
473 * add the sequences to any other viewers (of the same type) for this pdb
476 // JBPNOTE: this looks like a binding routine, rather than a gui routine
477 for (StructureViewerBase viewer : getViewersFor(null))
479 AAStructureBindingModel bindingModel = viewer.getBinding();
480 for (int pe = 0; pe < bindingModel.getPdbCount(); pe++)
482 if (bindingModel.getPdbEntry(pe).getFile().equals(pdbFilename))
484 bindingModel.addSequence(pe, seq);
485 viewer.addAlignmentPanel(apanel);
487 * add it to the set of alignments used for colouring structure by
490 viewer.useAlignmentPanelForColourbyseq(apanel);
491 viewer.buildActionMenu();
492 apanel.getStructureSelectionManager()
493 .sequenceColoursChanged(apanel);
501 public boolean addAlreadyLoadedFile(SequenceI[] seq, String[] chains,
502 final AlignmentViewPanel apanel, String pdbId)
504 String alreadyMapped = apanel.getStructureSelectionManager()
505 .alreadyMappedToFile(pdbId);
507 if (alreadyMapped == null)
512 addSequenceMappingsToStructure(seq, chains, apanel, alreadyMapped);
516 void setChainMenuItems(List<String> chainNames)
518 chainMenu.removeAll();
519 if (chainNames == null || chainNames.isEmpty())
525 * add the 'All' menu item
527 JMenuItem menuItem = new JMenuItem(
528 MessageManager.getString("label.all"));
529 menuItem.addActionListener(new ActionListener()
532 public void actionPerformed(ActionEvent evt)
534 allChainsSelected = true;
535 for (int i = 0; i < chainMenu.getItemCount(); i++)
537 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
539 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
542 showSelectedChains();
543 allChainsSelected = false;
546 chainMenu.add(menuItem);
549 * add a menu item for each structure and chain
551 Collections.sort(chainNames);
552 for (String chain : chainNames)
554 String seqName = getSequenceNameForChain(chain);
559 int nameLength = seqName.length();
562 seqName = seqName.substring(0, 8) + "..."
563 + seqName.substring(nameLength - 8, nameLength);
565 String text = chain + " " + seqName;
566 menuItem = new JCheckBoxMenuItem(text, true);
567 menuItem.addItemListener(new ItemListener()
570 public void itemStateChanged(ItemEvent evt)
572 if (!allChainsSelected)
574 showSelectedChains();
579 chainMenu.add(menuItem);
584 * Answers the name of the sequence mapped to the given chain (formatted as
585 * pdbId:chainId, e.g. 1A70:A). Answers null if no mapped sequence is found. If
586 * more than one sequence is matched, just answers the name of the first one
592 private String getSequenceNameForChain(String chain)
594 String[] tokens = chain.split(":");
595 String pdbId = tokens[0];
596 String chainId = tokens[1];
597 List<StructureMapping> mappings = getBinding().getSsm()
598 .getMappingForChain(pdbId, chainId);
599 return mappings.isEmpty() ? null
600 : mappings.get(0).getSequence().getName();
604 * Action on selecting one of Jalview's registered colour schemes
607 public void changeColour_actionPerformed(String colourSchemeName)
609 AlignmentI al = getAlignmentPanel().av.getAlignment();
610 ColourSchemeI cs = ColourSchemes.getInstance()
611 .getColourScheme(colourSchemeName, getAlignmentPanel().av, al,
613 getBinding().colourByJalviewColourScheme(cs);
617 * Builds the colour menu
619 protected void buildColourMenu()
621 colourMenu.removeAll();
622 AlignmentI al = getAlignmentPanel().av.getAlignment();
625 * add colour by sequence, by chain, by charge and cysteine
627 colourMenu.add(seqColour);
628 colourMenu.add(chainColour);
629 colourMenu.add(chargeColour);
630 chargeColour.setEnabled(!al.isNucleotide());
633 * add all 'simple' (per-residue) colour schemes registered to Jalview
635 ButtonGroup itemGroup = ColourMenuHelper.addMenuItems(colourMenu, this,
639 * add 'colour by viewer' (menu item text is set in subclasses)
641 viewerColour.setSelected(false);
642 viewerColour.addActionListener(new ActionListener()
645 public void actionPerformed(ActionEvent actionEvent)
647 viewerColour_actionPerformed();
650 colourMenu.add(viewerColour);
653 * add 'set background colour'
655 JMenuItem backGround = new JMenuItem();
657 .setText(MessageManager.getString("action.background_colour"));
658 backGround.addActionListener(new ActionListener()
661 public void actionPerformed(ActionEvent actionEvent)
663 background_actionPerformed();
666 colourMenu.add(backGround);
669 * add colour buttons to a group so their selection is
670 * mutually exclusive (background colour is a separate option)
672 itemGroup.add(seqColour);
673 itemGroup.add(chainColour);
674 itemGroup.add(chargeColour);
675 itemGroup.add(viewerColour);
679 * Construct menu items
681 protected void initMenus()
683 AAStructureBindingModel binding = getBinding();
685 seqColour = new JRadioButtonMenuItem();
686 seqColour.setText(MessageManager.getString("action.by_sequence"));
687 seqColour.setName(ViewerColour.BySequence.name());
688 seqColour.setSelected(binding.isColourBySequence());
689 seqColour.addActionListener(new ActionListener()
692 public void actionPerformed(ActionEvent actionEvent)
694 seqColour_actionPerformed();
698 chainColour = new JRadioButtonMenuItem();
699 chainColour.setText(MessageManager.getString("action.by_chain"));
700 chainColour.setName(ViewerColour.ByChain.name());
701 chainColour.addActionListener(new ActionListener()
704 public void actionPerformed(ActionEvent actionEvent)
706 chainColour_actionPerformed();
710 chargeColour = new JRadioButtonMenuItem();
711 chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
712 chargeColour.setName(ViewerColour.ChargeCysteine.name());
713 chargeColour.addActionListener(new ActionListener()
716 public void actionPerformed(ActionEvent actionEvent)
718 chargeColour_actionPerformed();
722 viewerColour = new JRadioButtonMenuItem();
724 .setText(MessageManager.getString("label.colour_with_viewer"));
725 viewerColour.setToolTipText(MessageManager
726 .getString("label.let_viewer_manage_structure_colours"));
727 viewerColour.setName(ViewerColour.ByViewer.name());
728 viewerColour.setSelected(!binding.isColourBySequence());
730 if (_colourwith == null)
732 _colourwith = new Vector<>();
734 if (_alignwith == null)
736 _alignwith = new Vector<>();
739 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
740 MessageManager.getString("label.colour_by"), this, _colourwith,
744 public void itemStateChanged(ItemEvent e)
746 if (!seqColour.isSelected())
752 // update the viewer display now.
753 seqColour_actionPerformed();
757 viewMenu.add(seqColourBy);
759 showAlignmentOnly = new JCheckBoxMenuItem(
760 MessageManager.getString("label.show_alignment_only"));
761 showAlignmentOnly.addActionListener(new ActionListener()
764 public void actionPerformed(ActionEvent e)
766 hideHiddenRegions.setEnabled(showAlignmentOnly.isSelected());
767 getBinding().setShowAlignmentOnly(showAlignmentOnly.isSelected());
768 getBinding().showStructures(getAlignmentPanel().getAlignViewport(),
772 viewMenu.add(showAlignmentOnly);
774 hideHiddenRegions = new JCheckBoxMenuItem(
775 MessageManager.getString("label.hide_hidden_regions"));
776 hideHiddenRegions.setEnabled(false);
777 hideHiddenRegions.addActionListener(new ActionListener()
780 public void actionPerformed(ActionEvent e)
782 getBinding().setHideHiddenRegions(hideHiddenRegions.isSelected());
783 getBinding().showStructures(getAlignmentPanel().getAlignViewport(),
787 viewMenu.add(hideHiddenRegions);
788 viewMenu.add(fitToWindow);
790 final ItemListener handler = new ItemListener()
793 public void itemStateChanged(ItemEvent e)
795 if (_alignwith.isEmpty())
797 alignStructs.setEnabled(false);
798 alignStructs.setToolTipText(null);
802 alignStructs.setEnabled(true);
803 alignStructs.setToolTipText(MessageManager.formatMessage(
804 "label.align_structures_using_linked_alignment_views",
809 viewSelectionMenu = new ViewSelectionMenu(
810 MessageManager.getString("label.superpose_with"), this,
811 _alignwith, handler);
812 handler.itemStateChanged(null);
813 viewerActionMenu.add(viewSelectionMenu, 0);
814 viewerActionMenu.addMenuListener(new MenuListener()
817 public void menuSelected(MenuEvent e)
819 handler.itemStateChanged(null);
823 public void menuDeselected(MenuEvent e)
828 public void menuCanceled(MenuEvent e)
833 viewerActionMenu.setText(getViewerName());
834 helpItem.setText(MessageManager.formatMessage("label.viewer_help",
841 * Sends commands to the structure viewer to superimpose structures based on
842 * currently associated alignments. May optionally return an error message for
846 protected String alignStructsWithAllAlignPanels()
848 if (getAlignmentPanel() == null)
853 if (_alignwith.size() == 0)
855 _alignwith.add(getAlignmentPanel());
861 reply = getBinding().superposeStructures(_alignwith);
862 if (reply != null && !reply.isEmpty())
864 String text = MessageManager
865 .formatMessage("error.superposition_failed", reply);
866 statusBar.setText(text);
868 } catch (Exception e)
870 StringBuilder sb = new StringBuilder();
871 for (AlignmentViewPanel alignPanel : _alignwith)
873 sb.append("'").append(alignPanel.getViewName()).append("' ");
875 Cache.log.info("Couldn't align structures with the " + sb.toString()
876 + "associated alignment panels.", e);
882 * Opens a colour chooser dialog, and applies the chosen colour to the
883 * background of the structure viewer
886 public void background_actionPerformed()
888 String ttl = MessageManager.getString("label.select_background_colour");
889 ColourChooserListener listener = new ColourChooserListener()
892 public void colourSelected(Color c)
894 getBinding().setBackgroundColour(c);
897 JalviewColourChooser.showColourChooser(this, ttl, null, listener);
901 public void viewerColour_actionPerformed()
903 if (viewerColour.isSelected())
905 // disable automatic sequence colouring.
906 getBinding().setColourBySequence(false);
911 public void chainColour_actionPerformed()
913 chainColour.setSelected(true);
914 getBinding().colourByChain();
918 public void chargeColour_actionPerformed()
920 chargeColour.setSelected(true);
921 getBinding().colourByCharge();
925 public void seqColour_actionPerformed()
927 AAStructureBindingModel binding = getBinding();
928 binding.setColourBySequence(seqColour.isSelected());
929 if (_colourwith == null)
931 _colourwith = new Vector<>();
933 if (binding.isColourBySequence())
935 if (!binding.isLoadingFromArchive())
937 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
939 // Make the currently displayed alignment panel the associated view
940 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
943 // Set the colour using the current view for the associated alignframe
944 for (AlignmentViewPanel avp : _colourwith)
946 binding.updateStructureColours(avp);
948 seqColoursApplied = true;
953 public void pdbFile_actionPerformed()
955 // TODO: JAL-3048 not needed for Jalview-JS - save PDB file
956 JalviewFileChooser chooser = new JalviewFileChooser(
957 Cache.getProperty("LAST_DIRECTORY"));
959 chooser.setFileView(new JalviewFileView());
960 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
961 chooser.setToolTipText(MessageManager.getString("action.save"));
963 int value = chooser.showSaveDialog(this);
965 if (value == JalviewFileChooser.APPROVE_OPTION)
967 BufferedReader in = null;
970 // TODO: cope with multiple PDB files in view
971 in = new BufferedReader(
972 new FileReader(getBinding().getStructureFiles()[0]));
973 File outFile = chooser.getSelectedFile();
975 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
977 while ((data = in.readLine()) != null)
979 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
985 } catch (Exception ex)
987 ex.printStackTrace();
995 } catch (IOException e)
1005 public void viewMapping_actionPerformed()
1007 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1010 cap.appendText(getBinding().printMappings());
1011 } catch (OutOfMemoryError e)
1014 "composing sequence-structure alignments for display in text box.",
1019 Desktop.addInternalFrame(cap,
1020 MessageManager.getString("label.pdb_sequence_mapping"), 550,
1024 protected abstract String getViewerName();
1027 * Configures the title and menu items of the viewer panel.
1030 public void updateTitleAndMenus()
1032 AAStructureBindingModel binding = getBinding();
1033 if (binding.hasFileLoadingError())
1038 setChainMenuItems(binding.getChainNames());
1040 this.setTitle(binding.getViewerTitle(getViewerName(), true));
1043 * enable 'Superpose with' if more than one mapped structure
1045 viewSelectionMenu.setEnabled(false);
1046 if (getBinding().getMappedStructureCount() > 1
1047 && getBinding().getSequence().length > 1)
1049 viewSelectionMenu.setEnabled(true);
1053 * Show action menu if it has any enabled items
1055 viewerActionMenu.setVisible(false);
1056 for (int i = 0; i < viewerActionMenu.getItemCount(); i++)
1058 if (viewerActionMenu.getItem(i).isEnabled())
1060 viewerActionMenu.setVisible(true);
1065 if (!binding.isLoadingFromArchive())
1067 seqColour_actionPerformed();
1072 public String toString()
1078 public boolean hasMapping()
1080 if (worker != null && (addingStructures || _started))
1084 if (getBinding() == null)
1086 if (_aps == null || _aps.size() == 0)
1088 // viewer has been closed, but we did at some point run.
1093 String[] pdbids = getBinding().getStructureFiles();
1099 for (String pdbid:pdbids) {
1100 StructureMapping sm[] = getBinding().getSsm().getMapping(pdbid);
1101 if (sm!=null && sm.length>0 && sm[0]!=null) {
1105 // only return true if there is a mapping for every structure file we have loaded
1106 if (p == 0 || p != pdbids.length)
1110 // and that coloring has been applied
1111 return seqColoursApplied;
1115 public void raiseViewer()
1121 public abstract AAStructureBindingModel getBinding();
1124 * Show only the selected chain(s) in the viewer
1126 protected void showSelectedChains()
1131 * refresh display without resizing - easier to see what changed
1133 getBinding().showStructures(getAlignmentPanel().getAlignViewport(),
1138 public long startProgressBar(String msg)
1140 // TODO would rather have startProgress/stopProgress as the
1141 // IProgressIndicator interface
1142 long tm = random.nextLong();
1143 if (progressBar != null)
1145 progressBar.setProgressBar(msg, tm);
1151 public void stopProgressBar(String msg, long handle)
1153 if (progressBar != null)
1155 progressBar.setProgressBar(msg, handle);
1159 protected IProgressIndicator getProgressIndicator()
1164 protected void setProgressIndicator(IProgressIndicator pi)
1169 protected void setProgressMessage(String message, long id)
1171 if (progressBar != null)
1173 progressBar.setProgressBar(message, id);
1178 public void showConsole(boolean show)
1180 // default does nothing
1184 * Tries to fetch a PDB file and save to a temporary local file. Returns the
1185 * saved file path if successful, or null if not.
1187 * @param processingEntry
1190 protected String fetchPdbFile(PDBEntry processingEntry)
1192 String filePath = null;
1193 Pdb pdbclient = new Pdb();
1194 AlignmentI pdbseq = null;
1195 String pdbid = processingEntry.getId();
1196 long handle = System.currentTimeMillis()
1197 + Thread.currentThread().hashCode();
1200 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
1202 String msg = MessageManager.formatMessage("status.fetching_pdb",
1205 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1206 // long hdl = startProgressBar(MessageManager.formatMessage(
1207 // "status.fetching_pdb", new Object[]
1211 pdbseq = pdbclient.getSequenceRecords(pdbid);
1212 } catch (Exception e)
1215 "Error retrieving PDB id " + pdbid + ": " + e.getMessage());
1218 msg = pdbid + " " + MessageManager.getString("label.state_completed");
1219 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1220 // stopProgressBar(msg, hdl);
1223 * If PDB data were saved and are not invalid (empty alignment), return the
1226 if (pdbseq != null && pdbseq.getHeight() > 0)
1228 // just use the file name from the first sequence's first PDBEntry
1229 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
1230 .elementAt(0).getFile()).getAbsolutePath();
1231 processingEntry.setFile(filePath);
1237 * If supported, saves the state of the structure viewer to a temporary file
1238 * and returns the file, else returns null
1242 public File saveSession()
1244 // TODO: a wait loop to ensure the file is written fully before returning?
1245 return getBinding() == null ? null : getBinding().saveSession();
1249 * Close down this instance of Jalview's Chimera viewer, giving the user the
1250 * option to close the associated Chimera window (process). They may wish to
1251 * keep it open until they have had an opportunity to save any work.
1254 * if true, close any linked Chimera process; if false, prompt first
1257 public void closeViewer(boolean forceClose)
1259 AAStructureBindingModel binding = getBinding();
1260 if (binding != null && binding.isViewerRunning())
1264 String viewerName = getViewerName();
1265 String prompt = MessageManager
1266 .formatMessage("label.confirm_close_viewer", new Object[]
1267 { binding.getViewerTitle(viewerName, false), viewerName });
1268 prompt = JvSwingUtils.wrapTooltip(true, prompt);
1269 int confirm = JvOptionPane.showConfirmDialog(this, prompt,
1270 MessageManager.getString("label.close_viewer"),
1271 JvOptionPane.YES_NO_CANCEL_OPTION);
1273 * abort closure if user hits escape or Cancel
1275 if (confirm == JvOptionPane.CANCEL_OPTION
1276 || confirm == JvOptionPane.CLOSED_OPTION)
1280 forceClose = confirm == JvOptionPane.YES_OPTION;
1282 binding.closeViewer(forceClose);
1284 setAlignmentPanel(null);
1287 _colourwith.clear();
1288 // TODO: check for memory leaks where instance isn't finalised because jmb
1289 // holds a reference to the window
1295 public void showHelp_actionPerformed()
1299 String url = getBinding().getHelpURL();
1302 BrowserLauncher.openURL(url);
1304 } catch (IOException ex)
1307 .println("Show " + getViewerName() + " failed with: "