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/>.
23 import javax.swing.event.*;
25 import java.awt.event.*;
28 import jalview.jbgui.GStructureViewer;
29 import jalview.api.SequenceStructureBinding;
30 import jalview.bin.Cache;
31 import jalview.datamodel.*;
32 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
33 import jalview.structure.*;
34 import jalview.datamodel.PDBEntry;
36 import jalview.schemes.*;
38 public class AppJmol extends GStructureViewer implements Runnable,
39 SequenceStructureBinding, ViewSetProvider
48 RenderPanel renderPanel;
52 Vector atomsPicked = new Vector();
54 private boolean addingStructures = false;
64 * @deprecated defaults to AppJmol(String[] files, ... , viewid);
66 public AppJmol(String file, String id, SequenceI[] seq,
67 AlignmentPanel ap, String loadStatus, Rectangle bounds)
69 this(file, id, seq, ap, loadStatus, bounds, null);
75 public AppJmol(String file, String id, SequenceI[] seq,
76 AlignmentPanel ap, String loadStatus, Rectangle bounds,
80 { file }, new String[]
81 { id }, new SequenceI[][]
82 { seq }, ap, true, true, loadStatus, bounds, viewid);
85 ViewSelectionMenu seqColourBy;
94 * - add the alignment panel to the list used for colouring these
97 * - add the alignment panel to the list used for aligning these
103 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
104 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
105 String loadStatus, Rectangle bounds, String viewid)
107 PDBEntry[] pdbentrys = new PDBEntry[files.length];
108 for (int i = 0; i < pdbentrys.length; i++)
110 PDBEntry pdbentry = new PDBEntry();
111 pdbentry.setFile(files[i]);
112 pdbentry.setId(ids[i]);
113 pdbentrys[i] = pdbentry;
115 // / TODO: check if protocol is needed to be set, and if chains are
117 jmb = new AppJmolBinding(this, pdbentrys, seqs, null, null);
119 jmb.setLoadingFromArchive(true);
120 addAlignmentPanel(ap);
123 useAlignmentPanelForSuperposition(ap);
127 useAlignmentPanelForColourbyseq(ap);
128 jmb.setColourBySequence(true);
129 seqColour.setSelected(true);
131 jmb.setColourBySequence(false);
132 seqColour.setSelected(false);
133 jmolColour.setSelected(true);
135 this.setBounds(bounds);
138 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
139 // bounds.width,bounds.height);
141 this.addInternalFrameListener(new InternalFrameAdapter()
143 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
148 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
152 private void initMenus()
154 seqColour.setSelected(jmb.isColourBySequence());
155 jmolColour.setSelected(!jmb.isColourBySequence());
156 seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith,
161 public void itemStateChanged(ItemEvent e)
163 if (!seqColour.isSelected())
169 // update the jmol display now.
170 seqColour_actionPerformed(null);
174 viewMenu.add(seqColourBy);
175 final ItemListener handler;
176 JMenu alpanels = new ViewSelectionMenu("Superpose with ..", this,
177 _alignwith, handler = new ItemListener()
181 public void itemStateChanged(ItemEvent e)
183 alignStructs.setEnabled(_alignwith.size() > 0);
184 alignStructs.setToolTipText("Align structures using "
185 + _alignwith.size() + " linked alignment views");
188 handler.itemStateChanged(null);
189 jmolActionMenu.add(alpanels);
190 jmolActionMenu.addMenuListener(new MenuListener()
194 public void menuSelected(MenuEvent e)
196 handler.itemStateChanged(null);
200 public void menuDeselected(MenuEvent e)
202 // TODO Auto-generated method stub
207 public void menuCanceled(MenuEvent e)
209 // TODO Auto-generated method stub
214 IProgressIndicator progressBar = null;
216 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
219 progressBar = ap.alignFrame;
220 // ////////////////////////////////
221 // Is the pdb file already loaded?
222 String alreadyMapped = StructureSelectionManager
223 .getStructureSelectionManager().alreadyMappedToFile(
226 if (alreadyMapped != null)
228 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
229 pdbentry.getId() + " is already displayed."
230 + "\nDo you want to re-use this viewer ?",
231 "Map Sequences to Visible Window: " + pdbentry.getId(),
232 JOptionPane.YES_NO_OPTION);
234 if (option == JOptionPane.YES_OPTION)
236 StructureSelectionManager.getStructureSelectionManager()
237 .setMapping(seq, chains, alreadyMapped,
238 AppletFormatAdapter.FILE);
239 if (ap.seqPanel.seqCanvas.fr != null)
241 ap.seqPanel.seqCanvas.fr.featuresAdded();
242 ap.paintAlignment(true);
245 // Now this AppJmol is mapped to new sequences. We must add them to
246 // the exisiting array
247 JInternalFrame[] frames = Desktop.instance.getAllFrames();
249 for (int i = 0; i < frames.length; i++)
251 if (frames[i] instanceof AppJmol)
253 AppJmol topJmol = ((AppJmol) frames[i]);
254 // JBPNOTE: this looks like a binding routine, rather than a gui
256 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
258 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
260 topJmol.jmb.addSequence(pe, seq);
261 topJmol.addAlignmentPanel(ap);
262 topJmol.buildJmolActionMenu();
272 // /////////////////////////////////
273 // Check if there are other Jmol views involving this alignment
274 // and prompt user about adding this molecule to one of them
275 Vector existingViews = getJmolsFor(ap);
276 if (existingViews.size() > 0)
278 Enumeration jm = existingViews.elements();
279 while (jm.hasMoreElements())
281 AppJmol topJmol = (AppJmol) jm.nextElement();
282 // TODO: highlight topJmol in view somehow
283 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
284 "Do you want to add " + pdbentry.getId()
285 + " to the view called\n'" + topJmol.getTitle()
286 + "'\n", "Align to existing structure view",
287 JOptionPane.YES_NO_OPTION);
288 if (option == JOptionPane.YES_OPTION)
290 topJmol.useAlignmentPanelForSuperposition(ap);
291 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
296 // /////////////////////////////////
298 jmb = new AppJmolBinding(this, new PDBEntry[]
299 { pdbentry }, new SequenceI[][]
300 { seq }, null, null);
301 addAlignmentPanel(ap);
302 useAlignmentPanelForColourbyseq(ap);
303 jmb.setColourBySequence(true);
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);
553 jmb.evalStateCommand(command);
554 jmb.setFinishedInit(true);
557 void setChainMenuItems(Vector chains)
559 chainMenu.removeAll();
564 JMenuItem menuItem = new JMenuItem("All");
565 menuItem.addActionListener(new ActionListener()
567 public void actionPerformed(ActionEvent evt)
569 allChainsSelected = true;
570 for (int i = 0; i < chainMenu.getItemCount(); i++)
572 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
573 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
576 allChainsSelected = false;
580 chainMenu.add(menuItem);
582 for (int c = 0; c < chains.size(); c++)
584 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
585 menuItem.addItemListener(new ItemListener()
587 public void itemStateChanged(ItemEvent evt)
589 if (!allChainsSelected)
594 chainMenu.add(menuItem);
598 boolean allChainsSelected = false;
600 private boolean alignAddedStructures = false;
604 Vector toshow = new Vector();
606 int mlength, p, mnum;
607 for (int i = 0; i < chainMenu.getItemCount(); i++)
609 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
611 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
612 if (item.isSelected())
614 toshow.addElement(item.getText());
618 jmb.centerViewer(toshow);
628 // TODO: check for memory leaks where instance isn't finalised because jmb
629 // holds a reference to the window
634 * state flag for PDB retrieval thread
636 private boolean _started = false;
642 // todo - record which pdbids were successfuly imported.
643 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
646 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
647 // TODO: replace with reference fetching/transfer code (validate PDBentry
649 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
650 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
652 String file = jmb.pdbentry[pi].getFile();
655 // retrieve the pdb and store it locally
656 AlignmentI pdbseq = null;
657 pdbid = jmb.pdbentry[pi].getId();
658 long hdl = pdbid.hashCode() - System.currentTimeMillis();
659 if (progressBar != null)
661 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
665 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
667 } catch (OutOfMemoryError oomerror)
669 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
670 } catch (Exception ex)
672 ex.printStackTrace();
673 errormsgs.append("'" + pdbid + "'");
675 if (progressBar != null)
677 progressBar.setProgressBar("Finished.", hdl);
681 // just transfer the file name from the first sequence's first
683 jmb.pdbentry[pi].setFile(file = ((PDBEntry) pdbseq
684 .getSequenceAt(0).getPDBId().elementAt(0)).getFile());
685 files.append(" \"" + file + "\"");
689 errormsgs.append("'" + pdbid + "' ");
694 if (curfiles != null && curfiles.length > 0)
696 addingStructures = true; // already files loaded.
697 for (int c = 0; c < curfiles.length; c++)
699 if (curfiles[c].equals(file))
708 files.append(" \"" + file + "\"");
712 } catch (OutOfMemoryError oomerror)
714 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
715 } catch (Exception ex)
717 ex.printStackTrace();
718 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
721 if (errormsgs.length() > 0)
724 JOptionPane.showInternalMessageDialog(Desktop.desktop,
725 "The following pdb entries could not be retrieved from the PDB:\n"
726 + errormsgs.toString()
727 + "\nPlease try downloading them manually.",
728 "Couldn't load file", JOptionPane.ERROR_MESSAGE);
731 if (files.length() > 0)
733 if (!addingStructures)
738 initJmol("load FILES " + files.toString());
739 } catch (OutOfMemoryError oomerror)
741 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
742 Cache.log.debug("File locations are " + files);
743 } catch (Exception ex)
745 Cache.log.error("Couldn't open Jmol viewer!", ex);
750 StringBuffer cmd = new StringBuffer();
751 cmd.append("loadingJalviewdata=true\nload APPEND ");
752 cmd.append(files.toString());
753 cmd.append("\nloadingJalviewdata=null");
754 final String command = cmd.toString();
756 long lastnotify = jmb.getLoadNotifiesHandled();
759 jmb.evalStateCommand(command);
760 } catch (OutOfMemoryError oomerror)
763 "When trying to add structures to the Jmol viewer!",
765 Cache.log.debug("File locations are " + files);
766 } catch (Exception ex)
768 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
770 // need to wait around until script has finished
771 while (lastnotify >= jmb.getLoadNotifiesHandled())
777 } catch (Exception e)
781 // refresh the sequence colours for the new structure(s)
782 for (AlignmentPanel ap : _colourwith)
784 jmb.updateColours(ap);
786 // do superposition if asked to
787 if (alignAddedStructures)
789 javax.swing.SwingUtilities.invokeLater(new Runnable()
793 alignStructs_withAllAlignPanels();
794 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
797 alignAddedStructures = false;
799 addingStructures = false;
806 public void pdbFile_actionPerformed(ActionEvent actionEvent)
808 JalviewFileChooser chooser = new JalviewFileChooser(
809 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
811 chooser.setFileView(new JalviewFileView());
812 chooser.setDialogTitle("Save PDB File");
813 chooser.setToolTipText("Save");
815 int value = chooser.showSaveDialog(this);
817 if (value == JalviewFileChooser.APPROVE_OPTION)
821 // TODO: cope with multiple PDB files in view
822 BufferedReader in = new BufferedReader(new FileReader(
823 jmb.getPdbFile()[0]));
824 File outFile = chooser.getSelectedFile();
826 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
828 while ((data = in.readLine()) != null)
830 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
836 } catch (Exception ex)
838 ex.printStackTrace();
843 public void viewMapping_actionPerformed(ActionEvent actionEvent)
845 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
848 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
850 cap.appendText(StructureSelectionManager
851 .getStructureSelectionManager().printMapping(
852 jmb.pdbentry[pdbe].getFile()));
853 cap.appendText("\n");
855 } catch (OutOfMemoryError e)
858 "composing sequence-structure alignments for display in text box.",
863 jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
873 public void eps_actionPerformed(ActionEvent e)
875 makePDBImage(jalview.util.ImageMaker.EPS);
884 public void png_actionPerformed(ActionEvent e)
886 makePDBImage(jalview.util.ImageMaker.PNG);
889 void makePDBImage(int type)
891 int width = getWidth();
892 int height = getHeight();
894 jalview.util.ImageMaker im;
896 if (type == jalview.util.ImageMaker.PNG)
898 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
899 "Make PNG image from view", width, height, null, null);
903 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
904 "Make EPS file from view", width, height, null,
908 if (im.getGraphics() != null)
910 Rectangle rect = new Rectangle(width, height);
911 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
915 public void jmolColour_actionPerformed(ActionEvent actionEvent)
917 if (jmolColour.isSelected()) {
918 // disable automatic sequence colouring.
919 jmb.setColourBySequence(false);
922 public void seqColour_actionPerformed(ActionEvent actionEvent)
924 jmb.setColourBySequence(seqColour.isSelected());
925 if (_colourwith == null)
927 _colourwith = new ArrayList<AlignmentPanel>();
929 if (jmb.isColourBySequence())
931 if (!jmb.isLoadingFromArchive())
934 // Make the currently displayed alignment panel the associated view
935 _colourwith.add(ap.alignFrame.alignPanel);
938 // Set the colour using the current view for the associated alignframe
939 for (AlignmentPanel ap : _colourwith)
941 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
946 public void chainColour_actionPerformed(ActionEvent actionEvent)
948 chainColour.setSelected(true);
952 public void chargeColour_actionPerformed(ActionEvent actionEvent)
954 chargeColour.setSelected(true);
955 jmb.colourByCharge();
958 public void zappoColour_actionPerformed(ActionEvent actionEvent)
960 zappoColour.setSelected(true);
961 jmb.setJalviewColourScheme(new ZappoColourScheme());
964 public void taylorColour_actionPerformed(ActionEvent actionEvent)
966 taylorColour.setSelected(true);
967 jmb.setJalviewColourScheme(new TaylorColourScheme());
970 public void hydroColour_actionPerformed(ActionEvent actionEvent)
972 hydroColour.setSelected(true);
973 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
976 public void helixColour_actionPerformed(ActionEvent actionEvent)
978 helixColour.setSelected(true);
979 jmb.setJalviewColourScheme(new HelixColourScheme());
982 public void strandColour_actionPerformed(ActionEvent actionEvent)
984 strandColour.setSelected(true);
985 jmb.setJalviewColourScheme(new StrandColourScheme());
988 public void turnColour_actionPerformed(ActionEvent actionEvent)
990 turnColour.setSelected(true);
991 jmb.setJalviewColourScheme(new TurnColourScheme());
994 public void buriedColour_actionPerformed(ActionEvent actionEvent)
996 buriedColour.setSelected(true);
997 jmb.setJalviewColourScheme(new BuriedColourScheme());
1000 public void userColour_actionPerformed(ActionEvent actionEvent)
1002 userColour.setSelected(true);
1003 new UserDefinedColours(this, null);
1006 public void backGround_actionPerformed(ActionEvent actionEvent)
1008 java.awt.Color col = JColorChooser.showDialog(this,
1009 "Select Background Colour", null);
1012 jmb.setBackgroundColour(col);
1016 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1020 jalview.util.BrowserLauncher
1021 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1022 } catch (Exception ex)
1027 public void showConsole(boolean showConsole)
1032 if (splitPane == null)
1034 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1035 splitPane.setTopComponent(renderPanel);
1036 splitPane.setBottomComponent(scriptWindow);
1037 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1038 splitPane.setDividerLocation(getHeight() - 200);
1039 scriptWindow.setVisible(true);
1040 scriptWindow.validate();
1041 splitPane.validate();
1047 if (splitPane != null)
1049 splitPane.setVisible(false);
1054 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1060 class RenderPanel extends JPanel
1062 final Dimension currentSize = new Dimension();
1064 final Rectangle rectClip = new Rectangle();
1066 public void paintComponent(Graphics g)
1068 getSize(currentSize);
1069 g.getClipBounds(rectClip);
1071 if (jmb.fileLoadingError != null)
1073 g.setColor(Color.black);
1074 g.fillRect(0, 0, currentSize.width, currentSize.height);
1075 g.setColor(Color.white);
1076 g.setFont(new Font("Verdana", Font.BOLD, 14));
1077 g.drawString("Error loading file...", 20, currentSize.height / 2);
1078 StringBuffer sb = new StringBuffer();
1080 for (int e = 0; e < jmb.pdbentry.length; e++)
1082 sb.append(jmb.pdbentry[e].getId());
1083 if (e < jmb.pdbentry.length - 1)
1088 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1091 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1092 * g.getFontMetrics().getHeight());
1096 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1098 g.setColor(Color.black);
1099 g.fillRect(0, 0, currentSize.width, currentSize.height);
1100 g.setColor(Color.white);
1101 g.setFont(new Font("Verdana", Font.BOLD, 14));
1102 g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
1106 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1111 String viewId = null;
1113 public String getViewId()
1117 viewId = System.currentTimeMillis() + "." + this.hashCode();
1122 public void updateTitleAndMenus()
1124 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1129 setChainMenuItems(jmb.chainNames);
1131 this.setTitle(jmb.getViewerTitle());
1132 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1134 jmolActionMenu.setVisible(true);
1136 if (!jmb.isLoadingFromArchive())
1138 seqColour_actionPerformed(null);
1142 protected void buildJmolActionMenu()
1144 if (_alignwith == null)
1146 _alignwith = new ArrayList<AlignmentPanel>();
1148 if (_alignwith.size() == 0 && ap != null)
1153 for (Component c : jmolActionMenu.getMenuComponents())
1155 if (c != alignStructs)
1157 jmolActionMenu.remove((JMenuItem) c);
1160 final ItemListener handler;
1167 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1171 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1173 alignStructs_withAllAlignPanels();
1176 private void alignStructs_withAllAlignPanels()
1183 if (_alignwith.size() == 0)
1190 AlignmentI[] als = new Alignment[_alignwith.size()];
1191 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1192 int[] alm = new int[_alignwith.size()];
1195 for (AlignmentPanel ap : _alignwith)
1197 als[a] = ap.av.getAlignment();
1199 alc[a++] = ap.av.getColumnSelection();
1201 jmb.superposeStructures(als, alm, alc);
1202 } catch (Exception e)
1204 StringBuffer sp = new StringBuffer();
1205 for (AlignmentPanel ap : _alignwith)
1207 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1209 Cache.log.info("Couldn't align structures with the " + sp.toString()
1210 + "associated alignment panels.", e);
1216 public void setJalviewColourScheme(ColourSchemeI ucs)
1218 jmb.setJalviewColourScheme(ucs);
1225 * @return first alignment panel displaying given alignment, or the default
1228 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1230 for (AlignmentPanel ap : getAllAlignmentPanels())
1232 if (ap.av.getAlignment() == alignment)
1243 * @return true if this Jmol instance is linked with the given alignPanel
1245 public boolean isLinkedWith(AlignmentPanel ap2)
1247 return _aps.contains(ap2.av.getSequenceSetId());
1250 public boolean isUsedforaligment(AlignmentPanel ap2)
1253 return (_alignwith != null) && _alignwith.contains(ap2);
1256 public boolean isUsedforcolourby(AlignmentPanel ap2)
1258 return (_colourwith != null) && _colourwith.contains(ap2);