2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import java.util.regex.*;
22 import java.util.List;
25 import javax.swing.event.*;
27 import java.awt.event.*;
30 import jalview.jbgui.GStructureViewer;
31 import jalview.api.SequenceStructureBinding;
32 import jalview.bin.Cache;
33 import jalview.datamodel.*;
35 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
36 import jalview.structure.*;
37 import jalview.datamodel.PDBEntry;
39 import jalview.schemes.*;
40 import jalview.ws.ebi.EBIFetchClient;
42 import org.jmol.api.*;
43 import org.jmol.adapter.smarter.SmarterJmolAdapter;
44 import org.jmol.popup.*;
45 import org.jmol.viewer.JmolConstants;
46 import org.openscience.jmol.app.jmolpanel.AppConsole;
48 import com.sun.org.apache.xml.internal.security.Init;
49 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;
51 public class AppJmol extends GStructureViewer implements Runnable,
52 SequenceStructureBinding, ViewSetProvider
61 RenderPanel renderPanel;
65 Vector atomsPicked = new Vector();
67 private boolean addingStructures = false;
77 * @deprecated defaults to AppJmol(String[] files, ... , viewid);
79 public AppJmol(String file, String id, SequenceI[] seq,
80 AlignmentPanel ap, String loadStatus, Rectangle bounds)
82 this(file, id, seq, ap, loadStatus, bounds, null);
88 public AppJmol(String file, String id, SequenceI[] seq,
89 AlignmentPanel ap, String loadStatus, Rectangle bounds,
93 { file }, new String[]
94 { id }, new SequenceI[][]
95 { seq }, ap, true,true, loadStatus, bounds, viewid);
98 ViewSelectionMenu seqColourBy;
106 * @param usetoColour - add the alignment panel to the list used for colouring these structures
107 * @param useToAlign - add the alignment panel to the list used for aligning these structures
112 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
113 AlignmentPanel ap, boolean usetoColour,boolean useToAlign, String loadStatus, Rectangle bounds,
116 PDBEntry[] pdbentrys = new PDBEntry[files.length];
117 for (int i = 0; i < pdbentrys.length; i++)
119 PDBEntry pdbentry = new PDBEntry();
120 pdbentry.setFile(files[i]);
121 pdbentry.setId(ids[i]);
122 pdbentrys[i] = pdbentry;
124 // / TODO: check if protocol is needed to be set, and if chains are
126 jmb = new AppJmolBinding(this, pdbentrys, seqs, null, null);
128 jmb.setLoadingFromArchive(true);
129 addAlignmentPanel(ap);
132 useAlignmentPanelForSuperposition(ap);
136 useAlignmentPanelForColourbyseq(ap);
138 this.setBounds(bounds);
139 jmb.setColourBySequence(false);
140 seqColour.setSelected(false);
143 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
144 // bounds.width,bounds.height);
146 this.addInternalFrameListener(new InternalFrameAdapter()
148 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
153 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
156 private void initMenus() {
157 seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith,
162 public void itemStateChanged(ItemEvent e)
164 if (!seqColour.isSelected())
170 // update the jmol display now.
171 seqColour_actionPerformed(null);
175 viewMenu.add(seqColourBy);
176 final ItemListener handler;
177 JMenu alpanels = new ViewSelectionMenu("Superpose with ..", this,
178 _alignwith, handler=new ItemListener()
182 public void itemStateChanged(ItemEvent e)
184 alignStructs.setEnabled(_alignwith.size() > 0);
185 alignStructs.setToolTipText("Align structures using "
186 + _alignwith.size() + " linked alignment views");
189 handler.itemStateChanged(null);
190 jmolActionMenu.add(alpanels);
191 jmolActionMenu.addMenuListener(new MenuListener()
195 public void menuSelected(MenuEvent e)
197 handler.itemStateChanged(null);
201 public void menuDeselected(MenuEvent e)
203 // TODO Auto-generated method stub
208 public void menuCanceled(MenuEvent e)
210 // TODO Auto-generated method stub
216 IProgressIndicator progressBar = null;
218 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
221 progressBar = ap.alignFrame;
222 // ////////////////////////////////
223 // Is the pdb file already loaded?
224 String alreadyMapped = StructureSelectionManager
225 .getStructureSelectionManager().alreadyMappedToFile(
228 if (alreadyMapped != null)
230 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
231 pdbentry.getId() + " is already displayed."
232 + "\nDo you want to re-use this viewer ?",
233 "Map Sequences to Visible Window: " + pdbentry.getId(),
234 JOptionPane.YES_NO_OPTION);
236 if (option == JOptionPane.YES_OPTION)
238 StructureSelectionManager.getStructureSelectionManager()
239 .setMapping(seq, chains, alreadyMapped,
240 AppletFormatAdapter.FILE);
241 if (ap.seqPanel.seqCanvas.fr != null)
243 ap.seqPanel.seqCanvas.fr.featuresAdded();
244 ap.paintAlignment(true);
247 // Now this AppJmol is mapped to new sequences. We must add them to
248 // the exisiting array
249 JInternalFrame[] frames = Desktop.instance.getAllFrames();
251 for (int i = 0; i < frames.length; i++)
253 if (frames[i] instanceof AppJmol)
255 AppJmol topJmol = ((AppJmol) frames[i]);
256 // JBPNOTE: this looks like a binding routine, rather than a gui
258 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
260 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
262 topJmol.jmb.addSequence(pe, seq);
263 topJmol.addAlignmentPanel(ap);
264 topJmol.buildJmolActionMenu();
274 // /////////////////////////////////
275 // Check if there are other Jmol views involving this alignment
276 // and prompt user about adding this molecule to one of them
277 Vector existingViews = getJmolsFor(ap);
278 if (existingViews.size() > 0)
280 Enumeration jm = existingViews.elements();
281 while (jm.hasMoreElements())
283 AppJmol topJmol = (AppJmol) jm.nextElement();
284 // TODO: highlight topJmol in view somehow
285 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
286 "Do you want to add " + pdbentry.getId()
287 + " to the view called\n'" + topJmol.getTitle()
288 + "'\n", "Align to existing structure view",
289 JOptionPane.YES_NO_OPTION);
290 if (option == JOptionPane.YES_OPTION)
292 topJmol.useAlignmentPanelForSuperposition(ap);
293 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
298 // /////////////////////////////////
300 jmb = new AppJmolBinding(this, new PDBEntry[]
301 { pdbentry }, new SequenceI[][]
302 { seq }, null, null);
303 addAlignmentPanel(ap);
304 setSize(400, 400); // probably should be a configurable/dynamic default here
307 if (pdbentry.getFile() != null)
309 initJmol("load \"" + pdbentry.getFile() + "\"");
313 addingStructures = false;
314 worker = new Thread(this);
318 this.addInternalFrameListener(new InternalFrameAdapter()
320 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
329 * list of sequenceSet ids associated with the view
331 ArrayList<String> _aps = new ArrayList();
333 public AlignmentPanel[] getAllAlignmentPanels()
335 AlignmentPanel[] t, list = new AlignmentPanel[0];
336 for (String setid : _aps)
338 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
341 t = new AlignmentPanel[list.length + panels.length];
342 System.arraycopy(list, 0, t, 0, list.length);
343 System.arraycopy(panels, 0, t, list.length, panels.length);
352 * list of alignment panels to use for superposition
354 ArrayList<AlignmentPanel> _alignwith = new ArrayList();
357 * list of alignment panels that are used for colouring structures by aligned
360 ArrayList<AlignmentPanel> _colourwith = new ArrayList();
363 * set the primary alignmentPanel reference and add another alignPanel to the
364 * list of ones to use for colouring and aligning
368 public void addAlignmentPanel(AlignmentPanel nap)
374 if (!_aps.contains(nap.av.getSequenceSetId()))
376 _aps.add(nap.av.getSequenceSetId());
381 * remove any references held to the given alignment panel
385 public void removeAlignmentPanel(AlignmentPanel nap)
389 _alignwith.remove(nap);
390 _colourwith.remove(nap);
394 for (AlignmentPanel aps : getAllAlignmentPanels())
403 } catch (Exception ex)
408 buildJmolActionMenu();
412 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
414 addAlignmentPanel(nap);
415 if (!_alignwith.contains(nap))
421 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
423 if (_alignwith.contains(nap))
425 _alignwith.remove(nap);
429 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
431 addAlignmentPanel(nap);
432 if (!_colourwith.contains(nap))
434 _colourwith.add(nap);
438 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
440 if (_colourwith.contains(nap))
442 _colourwith.remove(nap);
447 * pdb retrieval thread.
449 private Thread worker = null;
452 * add a new structure (with associated sequences and chains) to this viewer,
453 * retrieving it if necessary first.
460 * if true, new structure(s) will be align using associated alignment
462 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
463 final String[] chains, final boolean b,
464 final IProgressIndicator alignFrame)
466 if (pdbentry.getFile() == null)
468 if (worker != null && worker.isAlive())
470 // a retrieval is in progress, wait around and add ourselves to the
472 new Thread(new Runnable()
476 while (worker != null && worker.isAlive() && _started)
480 Thread.sleep(100 + ((int) Math.random() * 100));
482 } catch (Exception e)
487 // and call ourselves again.
488 addStructure(pdbentry, seq, chains, b, alignFrame);
494 // otherwise, start adding the structure.
495 jmb.addSequenceAndChain(new PDBEntry[]
496 { pdbentry }, new SequenceI[][]
497 { seq }, new String[][]
499 addingStructures = true;
501 alignAddedStructures = b;
502 progressBar = alignFrame; // visual indication happens on caller frame.
503 (worker = new Thread(this)).start();
507 private Vector getJmolsFor(AlignmentPanel ap2)
509 Vector otherJmols = new Vector();
510 // Now this AppJmol is mapped to new sequences. We must add them to
511 // the exisiting array
512 JInternalFrame[] frames = Desktop.instance.getAllFrames();
514 for (int i = 0; i < frames.length; i++)
516 if (frames[i] instanceof AppJmol)
518 AppJmol topJmol = ((AppJmol) frames[i]);
519 if (topJmol.isLinkedWith(ap2))
521 otherJmols.addElement(topJmol);
528 void initJmol(String command)
530 jmb.setFinishedInit(false);
531 renderPanel = new RenderPanel();
532 // TODO: consider waiting until the structure/view is fully loaded before
534 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
535 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
536 getBounds().width, getBounds().height);
537 if (scriptWindow == null)
539 BorderLayout bl = new BorderLayout();
542 scriptWindow = new JPanel(bl);
543 scriptWindow.setVisible(false);
546 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
548 jmb.newJmolPopup(true, "Jmol", true);
549 jmb.evalStateCommand(command);
550 jmb.setFinishedInit(true);
553 void setChainMenuItems(Vector chains)
555 chainMenu.removeAll();
560 JMenuItem menuItem = new JMenuItem("All");
561 menuItem.addActionListener(new ActionListener()
563 public void actionPerformed(ActionEvent evt)
565 allChainsSelected = true;
566 for (int i = 0; i < chainMenu.getItemCount(); i++)
568 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
569 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
572 allChainsSelected = false;
576 chainMenu.add(menuItem);
578 for (int c = 0; c < chains.size(); c++)
580 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
581 menuItem.addItemListener(new ItemListener()
583 public void itemStateChanged(ItemEvent evt)
585 if (!allChainsSelected)
590 chainMenu.add(menuItem);
594 boolean allChainsSelected = false;
596 private boolean alignAddedStructures = false;
600 Vector toshow = new Vector();
602 int mlength, p, mnum;
603 for (int i = 0; i < chainMenu.getItemCount(); i++)
605 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
607 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
608 if (item.isSelected())
610 toshow.addElement(item.getText());
614 jmb.centerViewer(toshow);
624 // TODO: check for memory leaks where instance isn't finalised because jmb
625 // holds a reference to the window
630 * state flag for PDB retrieval thread
632 private boolean _started = false;
638 // todo - record which pdbids were successfuly imported.
639 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
642 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
643 // TODO: replace with reference fetching/transfer code (validate PDBentry
645 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
646 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
648 String file = jmb.pdbentry[pi].getFile();
651 // retrieve the pdb and store it locally
652 AlignmentI pdbseq = null;
653 pdbid = jmb.pdbentry[pi].getId();
654 long hdl = pdbid.hashCode() - System.currentTimeMillis();
655 if (progressBar != null)
657 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
661 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
663 } catch (OutOfMemoryError oomerror)
665 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
666 } catch (Exception ex)
668 ex.printStackTrace();
669 errormsgs.append("'" + pdbid + "'");
671 if (progressBar != null)
673 progressBar.setProgressBar("Finished.", hdl);
677 // just transfer the file name from the first sequence's first
679 jmb.pdbentry[pi].setFile(file = ((PDBEntry) pdbseq
680 .getSequenceAt(0).getPDBId().elementAt(0)).getFile());
681 files.append(" \"" + file + "\"");
685 errormsgs.append("'" + pdbid + "' ");
690 if (curfiles != null && curfiles.length > 0)
692 addingStructures = true; // already files loaded.
693 for (int c = 0; c < curfiles.length; c++)
695 if (curfiles[c].equals(file))
704 files.append(" \"" + file + "\"");
708 } catch (OutOfMemoryError oomerror)
710 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
711 } catch (Exception ex)
713 ex.printStackTrace();
714 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
717 if (errormsgs.length() > 0)
720 JOptionPane.showInternalMessageDialog(Desktop.desktop,
721 "The following pdb entries could not be retrieved from the PDB:\n"
722 + errormsgs.toString()
723 + "\nPlease try downloading them manually.",
724 "Couldn't load file", JOptionPane.ERROR_MESSAGE);
727 if (files.length() > 0)
729 if (!addingStructures)
734 initJmol("load FILES " + files.toString());
735 } catch (OutOfMemoryError oomerror)
737 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
738 Cache.log.debug("File locations are " + files);
739 } catch (Exception ex)
741 Cache.log.error("Couldn't open Jmol viewer!", ex);
746 StringBuffer cmd = new StringBuffer();
747 cmd.append("loadingJalviewdata=true\nload APPEND ");
748 cmd.append(files.toString());
749 cmd.append("\nloadingJalviewdata=null");
750 final String command = cmd.toString();
752 long lastnotify = jmb.getLoadNotifiesHandled();
755 jmb.evalStateCommand(command);
756 } catch (OutOfMemoryError oomerror)
759 "When trying to add structures to the Jmol viewer!",
761 Cache.log.debug("File locations are " + files);
762 } catch (Exception ex)
764 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
766 // need to wait around until script has finished
767 while (lastnotify >= jmb.getLoadNotifiesHandled())
773 } catch (Exception e)
777 // refresh the sequence colours for the new structure(s)
778 for (AlignmentPanel ap : _colourwith)
780 jmb.updateColours(ap);
782 // do superposition if asked to
783 if (alignAddedStructures)
785 javax.swing.SwingUtilities.invokeLater(new Runnable()
789 alignStructs_withAllAlignPanels();
790 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
793 alignAddedStructures = false;
795 addingStructures = false;
802 public void pdbFile_actionPerformed(ActionEvent actionEvent)
804 JalviewFileChooser chooser = new JalviewFileChooser(
805 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
807 chooser.setFileView(new JalviewFileView());
808 chooser.setDialogTitle("Save PDB File");
809 chooser.setToolTipText("Save");
811 int value = chooser.showSaveDialog(this);
813 if (value == JalviewFileChooser.APPROVE_OPTION)
817 // TODO: cope with multiple PDB files in view
818 BufferedReader in = new BufferedReader(new FileReader(
819 jmb.getPdbFile()[0]));
820 File outFile = chooser.getSelectedFile();
822 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
824 while ((data = in.readLine()) != null)
826 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
832 } catch (Exception ex)
834 ex.printStackTrace();
839 public void viewMapping_actionPerformed(ActionEvent actionEvent)
841 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
844 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
846 cap.appendText(StructureSelectionManager
847 .getStructureSelectionManager().printMapping(
848 jmb.pdbentry[pdbe].getFile()));
849 cap.appendText("\n");
851 } catch (OutOfMemoryError e)
854 "composing sequence-structure alignments for display in text box.",
859 jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
869 public void eps_actionPerformed(ActionEvent e)
871 makePDBImage(jalview.util.ImageMaker.EPS);
880 public void png_actionPerformed(ActionEvent e)
882 makePDBImage(jalview.util.ImageMaker.PNG);
885 void makePDBImage(int type)
887 int width = getWidth();
888 int height = getHeight();
890 jalview.util.ImageMaker im;
892 if (type == jalview.util.ImageMaker.PNG)
894 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
895 "Make PNG image from view", width, height, null, null);
899 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
900 "Make EPS file from view", width, height, null,
904 if (im.getGraphics() != null)
906 Rectangle rect = new Rectangle(width, height);
907 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
912 public void seqColour_actionPerformed(ActionEvent actionEvent)
914 jmb.setColourBySequence(seqColour.isSelected());
915 if (_colourwith==null) { _colourwith=new ArrayList<AlignmentPanel>();};
916 if (_colourwith.size()==0){ _colourwith.add(ap); };
918 // Set the colour using the current view for the associated alignframe
919 for (AlignmentPanel ap : _colourwith)
921 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
925 public void chainColour_actionPerformed(ActionEvent actionEvent)
927 chainColour.setSelected(true);
931 public void chargeColour_actionPerformed(ActionEvent actionEvent)
933 chargeColour.setSelected(true);
934 jmb.colourByCharge();
937 public void zappoColour_actionPerformed(ActionEvent actionEvent)
939 zappoColour.setSelected(true);
940 jmb.setJalviewColourScheme(new ZappoColourScheme());
943 public void taylorColour_actionPerformed(ActionEvent actionEvent)
945 taylorColour.setSelected(true);
946 jmb.setJalviewColourScheme(new TaylorColourScheme());
949 public void hydroColour_actionPerformed(ActionEvent actionEvent)
951 hydroColour.setSelected(true);
952 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
955 public void helixColour_actionPerformed(ActionEvent actionEvent)
957 helixColour.setSelected(true);
958 jmb.setJalviewColourScheme(new HelixColourScheme());
961 public void strandColour_actionPerformed(ActionEvent actionEvent)
963 strandColour.setSelected(true);
964 jmb.setJalviewColourScheme(new StrandColourScheme());
967 public void turnColour_actionPerformed(ActionEvent actionEvent)
969 turnColour.setSelected(true);
970 jmb.setJalviewColourScheme(new TurnColourScheme());
973 public void buriedColour_actionPerformed(ActionEvent actionEvent)
975 buriedColour.setSelected(true);
976 jmb.setJalviewColourScheme(new BuriedColourScheme());
979 public void userColour_actionPerformed(ActionEvent actionEvent)
981 userColour.setSelected(true);
982 new UserDefinedColours(this, null);
985 public void backGround_actionPerformed(ActionEvent actionEvent)
987 java.awt.Color col = JColorChooser.showDialog(this,
988 "Select Background Colour", null);
991 jmb.setBackgroundColour(col);
995 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
999 jalview.util.BrowserLauncher
1000 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1001 } catch (Exception ex)
1006 public void showConsole(boolean showConsole)
1011 if (splitPane == null)
1013 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1014 splitPane.setTopComponent(renderPanel);
1015 splitPane.setBottomComponent(scriptWindow);
1016 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1017 splitPane.setDividerLocation(getHeight() - 200);
1018 scriptWindow.setVisible(true);
1019 scriptWindow.validate();
1020 splitPane.validate();
1026 if (splitPane != null)
1028 splitPane.setVisible(false);
1033 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1039 class RenderPanel extends JPanel
1041 final Dimension currentSize = new Dimension();
1043 final Rectangle rectClip = new Rectangle();
1045 public void paintComponent(Graphics g)
1047 getSize(currentSize);
1048 g.getClipBounds(rectClip);
1050 if (jmb.fileLoadingError != null)
1052 g.setColor(Color.black);
1053 g.fillRect(0, 0, currentSize.width, currentSize.height);
1054 g.setColor(Color.white);
1055 g.setFont(new Font("Verdana", Font.BOLD, 14));
1056 g.drawString("Error loading file...", 20, currentSize.height / 2);
1057 StringBuffer sb = new StringBuffer();
1059 for (int e = 0; e < jmb.pdbentry.length; e++)
1061 sb.append(jmb.pdbentry[e].getId());
1062 if (e < jmb.pdbentry.length - 1)
1067 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1070 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1071 * g.getFontMetrics().getHeight());
1075 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1077 g.setColor(Color.black);
1078 g.fillRect(0, 0, currentSize.width, currentSize.height);
1079 g.setColor(Color.white);
1080 g.setFont(new Font("Verdana", Font.BOLD, 14));
1081 g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
1085 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1090 String viewId = null;
1092 public String getViewId()
1096 viewId = System.currentTimeMillis() + "." + this.hashCode();
1101 public void updateTitleAndMenus()
1103 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1108 setChainMenuItems(jmb.chainNames);
1110 this.setTitle(jmb.getViewerTitle());
1111 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1113 jmolActionMenu.setVisible(true);
1115 if (!jmb.isLoadingFromArchive()) {
1116 seqColour_actionPerformed(null);
1120 protected void buildJmolActionMenu()
1122 if (_alignwith==null) { _alignwith=new ArrayList<AlignmentPanel>();}
1123 if (_alignwith.size()==0 && ap!=null) { _alignwith.add(ap);};
1124 for (Component c : jmolActionMenu.getMenuComponents())
1126 if (c != alignStructs)
1128 jmolActionMenu.remove((JMenuItem) c);
1131 final ItemListener handler;
1138 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1142 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1144 alignStructs_withAllAlignPanels();
1147 private void alignStructs_withAllAlignPanels()
1149 if (ap==null) { return; };
1150 if (_alignwith.size()==0) { _alignwith.add(ap);};
1153 AlignmentI[] als = new Alignment[_alignwith.size()];
1154 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1155 int[] alm = new int[_alignwith.size()];
1158 for (AlignmentPanel ap : _alignwith)
1160 als[a] = ap.av.getAlignment();
1162 alc[a++] = ap.av.getColumnSelection();
1164 jmb.superposeStructures(als, alm, alc);
1165 } catch (Exception e)
1167 StringBuffer sp = new StringBuffer();
1168 for (AlignmentPanel ap : _alignwith)
1170 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1172 Cache.log.info("Couldn't align structures with the " + sp.toString()
1173 + "associated alignment panels.", e);
1179 public void setJalviewColourScheme(ColourSchemeI ucs)
1181 jmb.setJalviewColourScheme(ucs);
1188 * @return first alignment panel displaying given alignment, or the default
1191 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1193 for (AlignmentPanel ap : getAllAlignmentPanels())
1195 if (ap.av.getAlignment() == alignment)
1206 * @return true if this Jmol instance is linked with the given alignPanel
1208 public boolean isLinkedWith(AlignmentPanel ap2)
1210 return _aps.contains(ap2.av.getSequenceSetId());
1213 public boolean isUsedforaligment(AlignmentPanel ap2)
1216 return (_alignwith != null) && _alignwith.contains(ap2);
1219 public boolean isUsedforcolourby(AlignmentPanel ap2)
1221 return (_colourwith != null) && _colourwith.contains(ap2);