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, false, 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
99 * @param leaveColouringToJmol
100 * - do not update the colours from any other source. Jmol is handling them
105 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
106 AlignmentPanel ap, boolean usetoColour, boolean useToAlign, boolean leaveColouringToJmol,
107 String loadStatus, Rectangle bounds, String viewid)
109 PDBEntry[] pdbentrys = new PDBEntry[files.length];
110 for (int i = 0; i < pdbentrys.length; i++)
112 PDBEntry pdbentry = new PDBEntry();
113 pdbentry.setFile(files[i]);
114 pdbentry.setId(ids[i]);
115 pdbentrys[i] = pdbentry;
117 // / TODO: check if protocol is needed to be set, and if chains are
119 jmb = new AppJmolBinding(this, pdbentrys, seqs, null, null);
121 jmb.setLoadingFromArchive(true);
122 addAlignmentPanel(ap);
125 useAlignmentPanelForSuperposition(ap);
127 if (leaveColouringToJmol || !usetoColour)
129 jmb.setColourBySequence(false);
130 seqColour.setSelected(false);
131 jmolColour.setSelected(true);
135 useAlignmentPanelForColourbyseq(ap);
136 jmb.setColourBySequence(true);
137 seqColour.setSelected(true);
138 jmolColour.setSelected(false);
140 this.setBounds(bounds);
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!
157 private void initMenus()
159 seqColour.setSelected(jmb.isColourBySequence());
160 jmolColour.setSelected(!jmb.isColourBySequence());
161 if (_colourwith==null)
163 _colourwith=new Vector<AlignmentPanel>();
165 if (_alignwith==null)
167 _alignwith=new Vector<AlignmentPanel>();
170 seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith,
175 public void itemStateChanged(ItemEvent e)
177 if (!seqColour.isSelected())
183 // update the jmol display now.
184 seqColour_actionPerformed(null);
188 viewMenu.add(seqColourBy);
189 final ItemListener handler;
190 JMenu alpanels = new ViewSelectionMenu("Superpose with ..", this,
191 _alignwith, handler = new ItemListener()
195 public void itemStateChanged(ItemEvent e)
197 alignStructs.setEnabled(_alignwith.size() > 0);
198 alignStructs.setToolTipText("Align structures using "
199 + _alignwith.size() + " linked alignment views");
202 handler.itemStateChanged(null);
203 jmolActionMenu.add(alpanels);
204 jmolActionMenu.addMenuListener(new MenuListener()
208 public void menuSelected(MenuEvent e)
210 handler.itemStateChanged(null);
214 public void menuDeselected(MenuEvent e)
216 // TODO Auto-generated method stub
221 public void menuCanceled(MenuEvent e)
223 // TODO Auto-generated method stub
228 IProgressIndicator progressBar = null;
230 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
233 progressBar = ap.alignFrame;
234 // ////////////////////////////////
235 // Is the pdb file already loaded?
236 String alreadyMapped = StructureSelectionManager
237 .getStructureSelectionManager().alreadyMappedToFile(
240 if (alreadyMapped != null)
242 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
243 pdbentry.getId() + " is already displayed."
244 + "\nDo you want to re-use this viewer ?",
245 "Map Sequences to Visible Window: " + pdbentry.getId(),
246 JOptionPane.YES_NO_OPTION);
248 if (option == JOptionPane.YES_OPTION)
250 StructureSelectionManager.getStructureSelectionManager()
251 .setMapping(seq, chains, alreadyMapped,
252 AppletFormatAdapter.FILE);
253 if (ap.seqPanel.seqCanvas.fr != null)
255 ap.seqPanel.seqCanvas.fr.featuresAdded();
256 ap.paintAlignment(true);
259 // Now this AppJmol is mapped to new sequences. We must add them to
260 // the exisiting array
261 JInternalFrame[] frames = Desktop.instance.getAllFrames();
263 for (int i = 0; i < frames.length; i++)
265 if (frames[i] instanceof AppJmol)
267 AppJmol topJmol = ((AppJmol) frames[i]);
268 // JBPNOTE: this looks like a binding routine, rather than a gui
270 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
272 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
274 topJmol.jmb.addSequence(pe, seq);
275 topJmol.addAlignmentPanel(ap);
276 topJmol.buildJmolActionMenu();
286 // /////////////////////////////////
287 // Check if there are other Jmol views involving this alignment
288 // and prompt user about adding this molecule to one of them
289 Vector existingViews = getJmolsFor(ap);
290 if (existingViews.size() > 0)
292 Enumeration jm = existingViews.elements();
293 while (jm.hasMoreElements())
295 AppJmol topJmol = (AppJmol) jm.nextElement();
296 // TODO: highlight topJmol in view somehow
297 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
298 "Do you want to add " + pdbentry.getId()
299 + " to the view called\n'" + topJmol.getTitle()
300 + "'\n", "Align to existing structure view",
301 JOptionPane.YES_NO_OPTION);
302 if (option == JOptionPane.YES_OPTION)
304 topJmol.useAlignmentPanelForSuperposition(ap);
305 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
310 // /////////////////////////////////
312 jmb = new AppJmolBinding(this, new PDBEntry[]
313 { pdbentry }, new SequenceI[][]
314 { seq }, null, null);
315 addAlignmentPanel(ap);
316 useAlignmentPanelForColourbyseq(ap);
317 jmb.setColourBySequence(true);
318 setSize(400, 400); // probably should be a configurable/dynamic default here
321 if (pdbentry.getFile() != null)
323 initJmol("load \"" + pdbentry.getFile() + "\"");
327 addingStructures = false;
328 worker = new Thread(this);
332 this.addInternalFrameListener(new InternalFrameAdapter()
334 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
343 * list of sequenceSet ids associated with the view
345 ArrayList<String> _aps = new ArrayList();
347 public AlignmentPanel[] getAllAlignmentPanels()
349 AlignmentPanel[] t, list = new AlignmentPanel[0];
350 for (String setid : _aps)
352 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
355 t = new AlignmentPanel[list.length + panels.length];
356 System.arraycopy(list, 0, t, 0, list.length);
357 System.arraycopy(panels, 0, t, list.length, panels.length);
366 * list of alignment panels to use for superposition
368 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
371 * list of alignment panels that are used for colouring structures by aligned
374 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
377 * set the primary alignmentPanel reference and add another alignPanel to the
378 * list of ones to use for colouring and aligning
382 public void addAlignmentPanel(AlignmentPanel nap)
388 if (!_aps.contains(nap.av.getSequenceSetId()))
390 _aps.add(nap.av.getSequenceSetId());
395 * remove any references held to the given alignment panel
399 public void removeAlignmentPanel(AlignmentPanel nap)
403 _alignwith.remove(nap);
404 _colourwith.remove(nap);
408 for (AlignmentPanel aps : getAllAlignmentPanels())
417 } catch (Exception ex)
422 buildJmolActionMenu();
426 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
428 addAlignmentPanel(nap);
429 if (!_alignwith.contains(nap))
435 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
437 if (_alignwith.contains(nap))
439 _alignwith.remove(nap);
443 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap, boolean enableColourBySeq)
445 useAlignmentPanelForColourbyseq(nap);
446 jmb.setColourBySequence(enableColourBySeq);
447 seqColour.setSelected(enableColourBySeq);
448 jmolColour.setSelected(!enableColourBySeq);
450 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
452 addAlignmentPanel(nap);
453 if (!_colourwith.contains(nap))
455 _colourwith.add(nap);
459 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
461 if (_colourwith.contains(nap))
463 _colourwith.remove(nap);
468 * pdb retrieval thread.
470 private Thread worker = null;
473 * add a new structure (with associated sequences and chains) to this viewer,
474 * retrieving it if necessary first.
481 * if true, new structure(s) will be align using associated alignment
483 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
484 final String[] chains, final boolean b,
485 final IProgressIndicator alignFrame)
487 if (pdbentry.getFile() == null)
489 if (worker != null && worker.isAlive())
491 // a retrieval is in progress, wait around and add ourselves to the
493 new Thread(new Runnable()
497 while (worker != null && worker.isAlive() && _started)
501 Thread.sleep(100 + ((int) Math.random() * 100));
503 } catch (Exception e)
508 // and call ourselves again.
509 addStructure(pdbentry, seq, chains, b, alignFrame);
515 // otherwise, start adding the structure.
516 jmb.addSequenceAndChain(new PDBEntry[]
517 { pdbentry }, new SequenceI[][]
518 { seq }, new String[][]
520 addingStructures = true;
522 alignAddedStructures = b;
523 progressBar = alignFrame; // visual indication happens on caller frame.
524 (worker = new Thread(this)).start();
528 private Vector getJmolsFor(AlignmentPanel ap2)
530 Vector otherJmols = new Vector();
531 // Now this AppJmol is mapped to new sequences. We must add them to
532 // the exisiting array
533 JInternalFrame[] frames = Desktop.instance.getAllFrames();
535 for (int i = 0; i < frames.length; i++)
537 if (frames[i] instanceof AppJmol)
539 AppJmol topJmol = ((AppJmol) frames[i]);
540 if (topJmol.isLinkedWith(ap2))
542 otherJmols.addElement(topJmol);
549 void initJmol(String command)
551 jmb.setFinishedInit(false);
552 renderPanel = new RenderPanel();
553 // TODO: consider waiting until the structure/view is fully loaded before
555 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
556 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
557 getBounds().width, getBounds().height);
558 if (scriptWindow == null)
560 BorderLayout bl = new BorderLayout();
563 scriptWindow = new JPanel(bl);
564 scriptWindow.setVisible(false);
567 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
569 jmb.newJmolPopup(true, "Jmol", true);
574 jmb.evalStateCommand(command);
575 jmb.setFinishedInit(true);
578 void setChainMenuItems(Vector chains)
580 chainMenu.removeAll();
585 JMenuItem menuItem = new JMenuItem("All");
586 menuItem.addActionListener(new ActionListener()
588 public void actionPerformed(ActionEvent evt)
590 allChainsSelected = true;
591 for (int i = 0; i < chainMenu.getItemCount(); i++)
593 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
594 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
597 allChainsSelected = false;
601 chainMenu.add(menuItem);
603 for (int c = 0; c < chains.size(); c++)
605 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
606 menuItem.addItemListener(new ItemListener()
608 public void itemStateChanged(ItemEvent evt)
610 if (!allChainsSelected)
615 chainMenu.add(menuItem);
619 boolean allChainsSelected = false;
621 private boolean alignAddedStructures = false;
625 Vector toshow = new Vector();
627 int mlength, p, mnum;
628 for (int i = 0; i < chainMenu.getItemCount(); i++)
630 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
632 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
633 if (item.isSelected())
635 toshow.addElement(item.getText());
639 jmb.centerViewer(toshow);
649 // TODO: check for memory leaks where instance isn't finalised because jmb
650 // holds a reference to the window
655 * state flag for PDB retrieval thread
657 private boolean _started = false;
663 // todo - record which pdbids were successfuly imported.
664 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
667 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
668 // TODO: replace with reference fetching/transfer code (validate PDBentry
670 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
671 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
673 String file = jmb.pdbentry[pi].getFile();
676 // retrieve the pdb and store it locally
677 AlignmentI pdbseq = null;
678 pdbid = jmb.pdbentry[pi].getId();
679 long hdl = pdbid.hashCode() - System.currentTimeMillis();
680 if (progressBar != null)
682 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
686 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
688 } catch (OutOfMemoryError oomerror)
690 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
691 } catch (Exception ex)
693 ex.printStackTrace();
694 errormsgs.append("'" + pdbid + "'");
696 if (progressBar != null)
698 progressBar.setProgressBar("Finished.", hdl);
702 // just transfer the file name from the first sequence's first
704 jmb.pdbentry[pi].setFile(file = ((PDBEntry) pdbseq
705 .getSequenceAt(0).getPDBId().elementAt(0)).getFile());
706 files.append(" \"" + file + "\"");
710 errormsgs.append("'" + pdbid + "' ");
715 if (curfiles != null && curfiles.length > 0)
717 addingStructures = true; // already files loaded.
718 for (int c = 0; c < curfiles.length; c++)
720 if (curfiles[c].equals(file))
729 files.append(" \"" + file + "\"");
733 } catch (OutOfMemoryError oomerror)
735 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
736 } catch (Exception ex)
738 ex.printStackTrace();
739 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
742 if (errormsgs.length() > 0)
745 JOptionPane.showInternalMessageDialog(Desktop.desktop,
746 "The following pdb entries could not be retrieved from the PDB:\n"
747 + errormsgs.toString()
748 + "\nPlease try downloading them manually.",
749 "Couldn't load file", JOptionPane.ERROR_MESSAGE);
752 if (files.length() > 0)
754 if (!addingStructures)
759 initJmol("load FILES " + files.toString());
760 } catch (OutOfMemoryError oomerror)
762 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
763 Cache.log.debug("File locations are " + files);
764 } catch (Exception ex)
766 Cache.log.error("Couldn't open Jmol viewer!", ex);
771 StringBuffer cmd = new StringBuffer();
772 cmd.append("loadingJalviewdata=true\nload APPEND ");
773 cmd.append(files.toString());
774 cmd.append("\nloadingJalviewdata=null");
775 final String command = cmd.toString();
777 long lastnotify = jmb.getLoadNotifiesHandled();
780 jmb.evalStateCommand(command);
781 } catch (OutOfMemoryError oomerror)
784 "When trying to add structures to the Jmol viewer!",
786 Cache.log.debug("File locations are " + files);
787 } catch (Exception ex)
789 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
791 // need to wait around until script has finished
792 while (lastnotify >= jmb.getLoadNotifiesHandled())
798 } catch (Exception e)
802 // refresh the sequence colours for the new structure(s)
803 for (AlignmentPanel ap : _colourwith)
805 jmb.updateColours(ap);
807 // do superposition if asked to
808 if (alignAddedStructures)
810 javax.swing.SwingUtilities.invokeLater(new Runnable()
814 alignStructs_withAllAlignPanels();
815 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
818 alignAddedStructures = false;
820 addingStructures = false;
827 public void pdbFile_actionPerformed(ActionEvent actionEvent)
829 JalviewFileChooser chooser = new JalviewFileChooser(
830 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
832 chooser.setFileView(new JalviewFileView());
833 chooser.setDialogTitle("Save PDB File");
834 chooser.setToolTipText("Save");
836 int value = chooser.showSaveDialog(this);
838 if (value == JalviewFileChooser.APPROVE_OPTION)
842 // TODO: cope with multiple PDB files in view
843 BufferedReader in = new BufferedReader(new FileReader(
844 jmb.getPdbFile()[0]));
845 File outFile = chooser.getSelectedFile();
847 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
849 while ((data = in.readLine()) != null)
851 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
857 } catch (Exception ex)
859 ex.printStackTrace();
864 public void viewMapping_actionPerformed(ActionEvent actionEvent)
866 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
869 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
871 cap.appendText(StructureSelectionManager
872 .getStructureSelectionManager().printMapping(
873 jmb.pdbentry[pdbe].getFile()));
874 cap.appendText("\n");
876 } catch (OutOfMemoryError e)
879 "composing sequence-structure alignments for display in text box.",
884 jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
894 public void eps_actionPerformed(ActionEvent e)
896 makePDBImage(jalview.util.ImageMaker.EPS);
905 public void png_actionPerformed(ActionEvent e)
907 makePDBImage(jalview.util.ImageMaker.PNG);
910 void makePDBImage(int type)
912 int width = getWidth();
913 int height = getHeight();
915 jalview.util.ImageMaker im;
917 if (type == jalview.util.ImageMaker.PNG)
919 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
920 "Make PNG image from view", width, height, null, null);
924 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
925 "Make EPS file from view", width, height, null,
929 if (im.getGraphics() != null)
931 Rectangle rect = new Rectangle(width, height);
932 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
936 public void jmolColour_actionPerformed(ActionEvent actionEvent)
938 if (jmolColour.isSelected()) {
939 // disable automatic sequence colouring.
940 jmb.setColourBySequence(false);
943 public void seqColour_actionPerformed(ActionEvent actionEvent)
945 jmb.setColourBySequence(seqColour.isSelected());
946 if (_colourwith == null)
948 _colourwith = new Vector<AlignmentPanel>();
950 if (jmb.isColourBySequence())
952 if (!jmb.isLoadingFromArchive())
954 if (_colourwith.size()==0 && ap!=null) {
955 // Make the currently displayed alignment panel the associated view
956 _colourwith.add(ap.alignFrame.alignPanel);
959 // Set the colour using the current view for the associated alignframe
960 for (AlignmentPanel ap : _colourwith)
962 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
967 public void chainColour_actionPerformed(ActionEvent actionEvent)
969 chainColour.setSelected(true);
973 public void chargeColour_actionPerformed(ActionEvent actionEvent)
975 chargeColour.setSelected(true);
976 jmb.colourByCharge();
979 public void zappoColour_actionPerformed(ActionEvent actionEvent)
981 zappoColour.setSelected(true);
982 jmb.setJalviewColourScheme(new ZappoColourScheme());
985 public void taylorColour_actionPerformed(ActionEvent actionEvent)
987 taylorColour.setSelected(true);
988 jmb.setJalviewColourScheme(new TaylorColourScheme());
991 public void hydroColour_actionPerformed(ActionEvent actionEvent)
993 hydroColour.setSelected(true);
994 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
997 public void helixColour_actionPerformed(ActionEvent actionEvent)
999 helixColour.setSelected(true);
1000 jmb.setJalviewColourScheme(new HelixColourScheme());
1003 public void strandColour_actionPerformed(ActionEvent actionEvent)
1005 strandColour.setSelected(true);
1006 jmb.setJalviewColourScheme(new StrandColourScheme());
1009 public void turnColour_actionPerformed(ActionEvent actionEvent)
1011 turnColour.setSelected(true);
1012 jmb.setJalviewColourScheme(new TurnColourScheme());
1015 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1017 buriedColour.setSelected(true);
1018 jmb.setJalviewColourScheme(new BuriedColourScheme());
1021 public void userColour_actionPerformed(ActionEvent actionEvent)
1023 userColour.setSelected(true);
1024 new UserDefinedColours(this, null);
1027 public void backGround_actionPerformed(ActionEvent actionEvent)
1029 java.awt.Color col = JColorChooser.showDialog(this,
1030 "Select Background Colour", null);
1033 jmb.setBackgroundColour(col);
1037 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1041 jalview.util.BrowserLauncher
1042 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1043 } catch (Exception ex)
1048 public void showConsole(boolean showConsole)
1053 if (splitPane == null)
1055 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1056 splitPane.setTopComponent(renderPanel);
1057 splitPane.setBottomComponent(scriptWindow);
1058 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1059 splitPane.setDividerLocation(getHeight() - 200);
1060 scriptWindow.setVisible(true);
1061 scriptWindow.validate();
1062 splitPane.validate();
1068 if (splitPane != null)
1070 splitPane.setVisible(false);
1075 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1081 class RenderPanel extends JPanel
1083 final Dimension currentSize = new Dimension();
1085 final Rectangle rectClip = new Rectangle();
1087 public void paintComponent(Graphics g)
1089 getSize(currentSize);
1090 g.getClipBounds(rectClip);
1092 if (jmb.fileLoadingError != null)
1094 g.setColor(Color.black);
1095 g.fillRect(0, 0, currentSize.width, currentSize.height);
1096 g.setColor(Color.white);
1097 g.setFont(new Font("Verdana", Font.BOLD, 14));
1098 g.drawString("Error loading file...", 20, currentSize.height / 2);
1099 StringBuffer sb = new StringBuffer();
1101 for (int e = 0; e < jmb.pdbentry.length; e++)
1103 sb.append(jmb.pdbentry[e].getId());
1104 if (e < jmb.pdbentry.length - 1)
1109 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1112 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1113 * g.getFontMetrics().getHeight());
1117 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1119 g.setColor(Color.black);
1120 g.fillRect(0, 0, currentSize.width, currentSize.height);
1121 g.setColor(Color.white);
1122 g.setFont(new Font("Verdana", Font.BOLD, 14));
1123 g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
1127 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1132 String viewId = null;
1134 public String getViewId()
1138 viewId = System.currentTimeMillis() + "." + this.hashCode();
1143 public void updateTitleAndMenus()
1145 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1150 setChainMenuItems(jmb.chainNames);
1152 this.setTitle(jmb.getViewerTitle());
1153 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1155 jmolActionMenu.setVisible(true);
1157 if (!jmb.isLoadingFromArchive())
1159 seqColour_actionPerformed(null);
1163 protected void buildJmolActionMenu()
1165 if (_alignwith == null)
1167 _alignwith = new Vector<AlignmentPanel>();
1169 if (_alignwith.size() == 0 && ap != null)
1174 for (Component c : jmolActionMenu.getMenuComponents())
1176 if (c != alignStructs)
1178 jmolActionMenu.remove((JMenuItem) c);
1181 final ItemListener handler;
1188 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1192 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1194 alignStructs_withAllAlignPanels();
1197 private void alignStructs_withAllAlignPanels()
1204 if (_alignwith.size() == 0)
1211 AlignmentI[] als = new Alignment[_alignwith.size()];
1212 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1213 int[] alm = new int[_alignwith.size()];
1216 for (AlignmentPanel ap : _alignwith)
1218 als[a] = ap.av.getAlignment();
1220 alc[a++] = ap.av.getColumnSelection();
1222 jmb.superposeStructures(als, alm, alc);
1223 } catch (Exception e)
1225 StringBuffer sp = new StringBuffer();
1226 for (AlignmentPanel ap : _alignwith)
1228 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1230 Cache.log.info("Couldn't align structures with the " + sp.toString()
1231 + "associated alignment panels.", e);
1237 public void setJalviewColourScheme(ColourSchemeI ucs)
1239 jmb.setJalviewColourScheme(ucs);
1246 * @return first alignment panel displaying given alignment, or the default
1249 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1251 for (AlignmentPanel ap : getAllAlignmentPanels())
1253 if (ap.av.getAlignment() == alignment)
1264 * @return true if this Jmol instance is linked with the given alignPanel
1266 public boolean isLinkedWith(AlignmentPanel ap2)
1268 return _aps.contains(ap2.av.getSequenceSetId());
1271 public boolean isUsedforaligment(AlignmentPanel ap2)
1274 return (_alignwith != null) && _alignwith.contains(ap2);
1277 public boolean isUsedforcolourby(AlignmentPanel ap2)
1279 return (_colourwith != null) && _colourwith.contains(ap2);
1284 * @return TRUE if the view is NOT being coloured by sequence associations.
1286 public boolean isColouredByJmol()
1288 return !jmb.isColourBySequence();