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, ap.getStructureSelectionManager(), 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 = ap.getStructureSelectionManager().alreadyMappedToFile(
239 if (alreadyMapped != null)
241 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
242 pdbentry.getId() + " is already displayed."
243 + "\nDo you want to re-use this viewer ?",
244 "Map Sequences to Visible Window: " + pdbentry.getId(),
245 JOptionPane.YES_NO_OPTION);
247 if (option == JOptionPane.YES_OPTION)
249 jmb.ssm.setMapping(seq, chains, alreadyMapped,
250 AppletFormatAdapter.FILE);
251 if (ap.seqPanel.seqCanvas.fr != null)
253 ap.seqPanel.seqCanvas.fr.featuresAdded();
254 ap.paintAlignment(true);
257 // Now this AppJmol is mapped to new sequences. We must add them to
258 // the exisiting array
259 JInternalFrame[] frames = Desktop.instance.getAllFrames();
261 for (int i = 0; i < frames.length; i++)
263 if (frames[i] instanceof AppJmol)
265 AppJmol topJmol = ((AppJmol) frames[i]);
266 // JBPNOTE: this looks like a binding routine, rather than a gui
268 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
270 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
272 topJmol.jmb.addSequence(pe, seq);
273 topJmol.addAlignmentPanel(ap);
274 topJmol.buildJmolActionMenu();
284 // /////////////////////////////////
285 // Check if there are other Jmol views involving this alignment
286 // and prompt user about adding this molecule to one of them
287 Vector existingViews = getJmolsFor(ap);
288 if (existingViews.size() > 0)
290 Enumeration jm = existingViews.elements();
291 while (jm.hasMoreElements())
293 AppJmol topJmol = (AppJmol) jm.nextElement();
294 // TODO: highlight topJmol in view somehow
295 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
296 "Do you want to add " + pdbentry.getId()
297 + " to the view called\n'" + topJmol.getTitle()
298 + "'\n", "Align to existing structure view",
299 JOptionPane.YES_NO_OPTION);
300 if (option == JOptionPane.YES_OPTION)
302 topJmol.useAlignmentPanelForSuperposition(ap);
303 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
308 // /////////////////////////////////
310 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), new PDBEntry[]
311 { pdbentry }, new SequenceI[][]
312 { seq }, null, null);
313 addAlignmentPanel(ap);
314 useAlignmentPanelForColourbyseq(ap);
315 jmb.setColourBySequence(true);
316 setSize(400, 400); // probably should be a configurable/dynamic default here
319 if (pdbentry.getFile() != null)
321 initJmol("load \"" + pdbentry.getFile() + "\"");
325 addingStructures = false;
326 worker = new Thread(this);
330 this.addInternalFrameListener(new InternalFrameAdapter()
332 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
341 * list of sequenceSet ids associated with the view
343 ArrayList<String> _aps = new ArrayList();
345 public AlignmentPanel[] getAllAlignmentPanels()
347 AlignmentPanel[] t, list = new AlignmentPanel[0];
348 for (String setid : _aps)
350 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
353 t = new AlignmentPanel[list.length + panels.length];
354 System.arraycopy(list, 0, t, 0, list.length);
355 System.arraycopy(panels, 0, t, list.length, panels.length);
364 * list of alignment panels to use for superposition
366 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
369 * list of alignment panels that are used for colouring structures by aligned
372 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
375 * set the primary alignmentPanel reference and add another alignPanel to the
376 * list of ones to use for colouring and aligning
380 public void addAlignmentPanel(AlignmentPanel nap)
386 if (!_aps.contains(nap.av.getSequenceSetId()))
388 _aps.add(nap.av.getSequenceSetId());
393 * remove any references held to the given alignment panel
397 public void removeAlignmentPanel(AlignmentPanel nap)
401 _alignwith.remove(nap);
402 _colourwith.remove(nap);
406 for (AlignmentPanel aps : getAllAlignmentPanels())
415 } catch (Exception ex)
420 buildJmolActionMenu();
424 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
426 addAlignmentPanel(nap);
427 if (!_alignwith.contains(nap))
433 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
435 if (_alignwith.contains(nap))
437 _alignwith.remove(nap);
441 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap, boolean enableColourBySeq)
443 useAlignmentPanelForColourbyseq(nap);
444 jmb.setColourBySequence(enableColourBySeq);
445 seqColour.setSelected(enableColourBySeq);
446 jmolColour.setSelected(!enableColourBySeq);
448 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
450 addAlignmentPanel(nap);
451 if (!_colourwith.contains(nap))
453 _colourwith.add(nap);
457 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
459 if (_colourwith.contains(nap))
461 _colourwith.remove(nap);
466 * pdb retrieval thread.
468 private Thread worker = null;
471 * add a new structure (with associated sequences and chains) to this viewer,
472 * retrieving it if necessary first.
479 * if true, new structure(s) will be align using associated alignment
481 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
482 final String[] chains, final boolean b,
483 final IProgressIndicator alignFrame)
485 if (pdbentry.getFile() == null)
487 if (worker != null && worker.isAlive())
489 // a retrieval is in progress, wait around and add ourselves to the
491 new Thread(new Runnable()
495 while (worker != null && worker.isAlive() && _started)
499 Thread.sleep(100 + ((int) Math.random() * 100));
501 } catch (Exception e)
506 // and call ourselves again.
507 addStructure(pdbentry, seq, chains, b, alignFrame);
513 // otherwise, start adding the structure.
514 jmb.addSequenceAndChain(new PDBEntry[]
515 { pdbentry }, new SequenceI[][]
516 { seq }, new String[][]
518 addingStructures = true;
520 alignAddedStructures = b;
521 progressBar = alignFrame; // visual indication happens on caller frame.
522 (worker = new Thread(this)).start();
526 private Vector getJmolsFor(AlignmentPanel ap2)
528 Vector otherJmols = new Vector();
529 // Now this AppJmol is mapped to new sequences. We must add them to
530 // the exisiting array
531 JInternalFrame[] frames = Desktop.instance.getAllFrames();
533 for (int i = 0; i < frames.length; i++)
535 if (frames[i] instanceof AppJmol)
537 AppJmol topJmol = ((AppJmol) frames[i]);
538 if (topJmol.isLinkedWith(ap2))
540 otherJmols.addElement(topJmol);
547 void initJmol(String command)
549 jmb.setFinishedInit(false);
550 renderPanel = new RenderPanel();
551 // TODO: consider waiting until the structure/view is fully loaded before
553 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
554 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
555 getBounds().width, getBounds().height);
556 if (scriptWindow == null)
558 BorderLayout bl = new BorderLayout();
561 scriptWindow = new JPanel(bl);
562 scriptWindow.setVisible(false);
565 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
567 jmb.newJmolPopup(true, "Jmol", true);
572 jmb.evalStateCommand(command);
573 jmb.setFinishedInit(true);
576 void setChainMenuItems(Vector chains)
578 chainMenu.removeAll();
583 JMenuItem menuItem = new JMenuItem("All");
584 menuItem.addActionListener(new ActionListener()
586 public void actionPerformed(ActionEvent evt)
588 allChainsSelected = true;
589 for (int i = 0; i < chainMenu.getItemCount(); i++)
591 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
592 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
595 allChainsSelected = false;
599 chainMenu.add(menuItem);
601 for (int c = 0; c < chains.size(); c++)
603 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
604 menuItem.addItemListener(new ItemListener()
606 public void itemStateChanged(ItemEvent evt)
608 if (!allChainsSelected)
613 chainMenu.add(menuItem);
617 boolean allChainsSelected = false;
619 private boolean alignAddedStructures = false;
623 Vector toshow = new Vector();
625 int mlength, p, mnum;
626 for (int i = 0; i < chainMenu.getItemCount(); i++)
628 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
630 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
631 if (item.isSelected())
633 toshow.addElement(item.getText());
637 jmb.centerViewer(toshow);
647 // TODO: check for memory leaks where instance isn't finalised because jmb
648 // holds a reference to the window
653 * state flag for PDB retrieval thread
655 private boolean _started = false;
661 // todo - record which pdbids were successfuly imported.
662 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
665 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
666 // TODO: replace with reference fetching/transfer code (validate PDBentry
668 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
669 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
671 String file = jmb.pdbentry[pi].getFile();
674 // retrieve the pdb and store it locally
675 AlignmentI pdbseq = null;
676 pdbid = jmb.pdbentry[pi].getId();
677 long hdl = pdbid.hashCode() - System.currentTimeMillis();
678 if (progressBar != null)
680 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
684 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
686 } catch (OutOfMemoryError oomerror)
688 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
689 } catch (Exception ex)
691 ex.printStackTrace();
692 errormsgs.append("'" + pdbid + "'");
694 if (progressBar != null)
696 progressBar.setProgressBar("Finished.", hdl);
700 // just transfer the file name from the first sequence's first
702 jmb.pdbentry[pi].setFile(file = ((PDBEntry) pdbseq
703 .getSequenceAt(0).getPDBId().elementAt(0)).getFile());
704 files.append(" \"" + file + "\"");
708 errormsgs.append("'" + pdbid + "' ");
713 if (curfiles != null && curfiles.length > 0)
715 addingStructures = true; // already files loaded.
716 for (int c = 0; c < curfiles.length; c++)
718 if (curfiles[c].equals(file))
727 files.append(" \"" + file + "\"");
731 } catch (OutOfMemoryError oomerror)
733 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
734 } catch (Exception ex)
736 ex.printStackTrace();
737 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
740 if (errormsgs.length() > 0)
743 JOptionPane.showInternalMessageDialog(Desktop.desktop,
744 "The following pdb entries could not be retrieved from the PDB:\n"
745 + errormsgs.toString()
746 + "\nPlease try downloading them manually.",
747 "Couldn't load file", JOptionPane.ERROR_MESSAGE);
750 if (files.length() > 0)
752 if (!addingStructures)
757 initJmol("load FILES " + files.toString());
758 } catch (OutOfMemoryError oomerror)
760 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
761 Cache.log.debug("File locations are " + files);
762 } catch (Exception ex)
764 Cache.log.error("Couldn't open Jmol viewer!", ex);
769 StringBuffer cmd = new StringBuffer();
770 cmd.append("loadingJalviewdata=true\nload APPEND ");
771 cmd.append(files.toString());
772 cmd.append("\nloadingJalviewdata=null");
773 final String command = cmd.toString();
775 long lastnotify = jmb.getLoadNotifiesHandled();
778 jmb.evalStateCommand(command);
779 } catch (OutOfMemoryError oomerror)
782 "When trying to add structures to the Jmol viewer!",
784 Cache.log.debug("File locations are " + files);
785 } catch (Exception ex)
787 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
789 // need to wait around until script has finished
790 while (lastnotify >= jmb.getLoadNotifiesHandled())
796 } catch (Exception e)
800 // refresh the sequence colours for the new structure(s)
801 for (AlignmentPanel ap : _colourwith)
803 jmb.updateColours(ap);
805 // do superposition if asked to
806 if (alignAddedStructures)
808 javax.swing.SwingUtilities.invokeLater(new Runnable()
812 alignStructs_withAllAlignPanels();
813 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
816 alignAddedStructures = false;
818 addingStructures = false;
825 public void pdbFile_actionPerformed(ActionEvent actionEvent)
827 JalviewFileChooser chooser = new JalviewFileChooser(
828 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
830 chooser.setFileView(new JalviewFileView());
831 chooser.setDialogTitle("Save PDB File");
832 chooser.setToolTipText("Save");
834 int value = chooser.showSaveDialog(this);
836 if (value == JalviewFileChooser.APPROVE_OPTION)
840 // TODO: cope with multiple PDB files in view
841 BufferedReader in = new BufferedReader(new FileReader(
842 jmb.getPdbFile()[0]));
843 File outFile = chooser.getSelectedFile();
845 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
847 while ((data = in.readLine()) != null)
849 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
855 } catch (Exception ex)
857 ex.printStackTrace();
862 public void viewMapping_actionPerformed(ActionEvent actionEvent)
864 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
867 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
869 cap.appendText(jmb.printMapping(
870 jmb.pdbentry[pdbe].getFile()));
871 cap.appendText("\n");
873 } catch (OutOfMemoryError e)
876 "composing sequence-structure alignments for display in text box.",
881 jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
891 public void eps_actionPerformed(ActionEvent e)
893 makePDBImage(jalview.util.ImageMaker.EPS);
902 public void png_actionPerformed(ActionEvent e)
904 makePDBImage(jalview.util.ImageMaker.PNG);
907 void makePDBImage(int type)
909 int width = getWidth();
910 int height = getHeight();
912 jalview.util.ImageMaker im;
914 if (type == jalview.util.ImageMaker.PNG)
916 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
917 "Make PNG image from view", width, height, null, null);
921 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
922 "Make EPS file from view", width, height, null,
926 if (im.getGraphics() != null)
928 Rectangle rect = new Rectangle(width, height);
929 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
933 public void jmolColour_actionPerformed(ActionEvent actionEvent)
935 if (jmolColour.isSelected()) {
936 // disable automatic sequence colouring.
937 jmb.setColourBySequence(false);
940 public void seqColour_actionPerformed(ActionEvent actionEvent)
942 jmb.setColourBySequence(seqColour.isSelected());
943 if (_colourwith == null)
945 _colourwith = new Vector<AlignmentPanel>();
947 if (jmb.isColourBySequence())
949 if (!jmb.isLoadingFromArchive())
951 if (_colourwith.size()==0 && ap!=null) {
952 // Make the currently displayed alignment panel the associated view
953 _colourwith.add(ap.alignFrame.alignPanel);
956 // Set the colour using the current view for the associated alignframe
957 for (AlignmentPanel ap : _colourwith)
959 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
964 public void chainColour_actionPerformed(ActionEvent actionEvent)
966 chainColour.setSelected(true);
970 public void chargeColour_actionPerformed(ActionEvent actionEvent)
972 chargeColour.setSelected(true);
973 jmb.colourByCharge();
976 public void zappoColour_actionPerformed(ActionEvent actionEvent)
978 zappoColour.setSelected(true);
979 jmb.setJalviewColourScheme(new ZappoColourScheme());
982 public void taylorColour_actionPerformed(ActionEvent actionEvent)
984 taylorColour.setSelected(true);
985 jmb.setJalviewColourScheme(new TaylorColourScheme());
988 public void hydroColour_actionPerformed(ActionEvent actionEvent)
990 hydroColour.setSelected(true);
991 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
994 public void helixColour_actionPerformed(ActionEvent actionEvent)
996 helixColour.setSelected(true);
997 jmb.setJalviewColourScheme(new HelixColourScheme());
1000 public void strandColour_actionPerformed(ActionEvent actionEvent)
1002 strandColour.setSelected(true);
1003 jmb.setJalviewColourScheme(new StrandColourScheme());
1006 public void turnColour_actionPerformed(ActionEvent actionEvent)
1008 turnColour.setSelected(true);
1009 jmb.setJalviewColourScheme(new TurnColourScheme());
1012 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1014 buriedColour.setSelected(true);
1015 jmb.setJalviewColourScheme(new BuriedColourScheme());
1018 public void userColour_actionPerformed(ActionEvent actionEvent)
1020 userColour.setSelected(true);
1021 new UserDefinedColours(this, null);
1024 public void backGround_actionPerformed(ActionEvent actionEvent)
1026 java.awt.Color col = JColorChooser.showDialog(this,
1027 "Select Background Colour", null);
1030 jmb.setBackgroundColour(col);
1034 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1038 jalview.util.BrowserLauncher
1039 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1040 } catch (Exception ex)
1045 public void showConsole(boolean showConsole)
1050 if (splitPane == null)
1052 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1053 splitPane.setTopComponent(renderPanel);
1054 splitPane.setBottomComponent(scriptWindow);
1055 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1056 splitPane.setDividerLocation(getHeight() - 200);
1057 scriptWindow.setVisible(true);
1058 scriptWindow.validate();
1059 splitPane.validate();
1065 if (splitPane != null)
1067 splitPane.setVisible(false);
1072 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1078 class RenderPanel extends JPanel
1080 final Dimension currentSize = new Dimension();
1082 final Rectangle rectClip = new Rectangle();
1084 public void paintComponent(Graphics g)
1086 getSize(currentSize);
1087 g.getClipBounds(rectClip);
1089 if (jmb.fileLoadingError != null)
1091 g.setColor(Color.black);
1092 g.fillRect(0, 0, currentSize.width, currentSize.height);
1093 g.setColor(Color.white);
1094 g.setFont(new Font("Verdana", Font.BOLD, 14));
1095 g.drawString("Error loading file...", 20, currentSize.height / 2);
1096 StringBuffer sb = new StringBuffer();
1098 for (int e = 0; e < jmb.pdbentry.length; e++)
1100 sb.append(jmb.pdbentry[e].getId());
1101 if (e < jmb.pdbentry.length - 1)
1106 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1109 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1110 * g.getFontMetrics().getHeight());
1114 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1116 g.setColor(Color.black);
1117 g.fillRect(0, 0, currentSize.width, currentSize.height);
1118 g.setColor(Color.white);
1119 g.setFont(new Font("Verdana", Font.BOLD, 14));
1120 g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
1124 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1129 String viewId = null;
1131 public String getViewId()
1135 viewId = System.currentTimeMillis() + "." + this.hashCode();
1140 public void updateTitleAndMenus()
1142 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1147 setChainMenuItems(jmb.chainNames);
1149 this.setTitle(jmb.getViewerTitle());
1150 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1152 jmolActionMenu.setVisible(true);
1154 if (!jmb.isLoadingFromArchive())
1156 seqColour_actionPerformed(null);
1160 protected void buildJmolActionMenu()
1162 if (_alignwith == null)
1164 _alignwith = new Vector<AlignmentPanel>();
1166 if (_alignwith.size() == 0 && ap != null)
1171 for (Component c : jmolActionMenu.getMenuComponents())
1173 if (c != alignStructs)
1175 jmolActionMenu.remove((JMenuItem) c);
1178 final ItemListener handler;
1185 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1189 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1191 alignStructs_withAllAlignPanels();
1194 private void alignStructs_withAllAlignPanels()
1201 if (_alignwith.size() == 0)
1208 AlignmentI[] als = new Alignment[_alignwith.size()];
1209 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1210 int[] alm = new int[_alignwith.size()];
1213 for (AlignmentPanel ap : _alignwith)
1215 als[a] = ap.av.getAlignment();
1217 alc[a++] = ap.av.getColumnSelection();
1219 jmb.superposeStructures(als, alm, alc);
1220 } catch (Exception e)
1222 StringBuffer sp = new StringBuffer();
1223 for (AlignmentPanel ap : _alignwith)
1225 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1227 Cache.log.info("Couldn't align structures with the " + sp.toString()
1228 + "associated alignment panels.", e);
1234 public void setJalviewColourScheme(ColourSchemeI ucs)
1236 jmb.setJalviewColourScheme(ucs);
1243 * @return first alignment panel displaying given alignment, or the default
1246 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1248 for (AlignmentPanel ap : getAllAlignmentPanels())
1250 if (ap.av.getAlignment() == alignment)
1261 * @return true if this Jmol instance is linked with the given alignPanel
1263 public boolean isLinkedWith(AlignmentPanel ap2)
1265 return _aps.contains(ap2.av.getSequenceSetId());
1268 public boolean isUsedforaligment(AlignmentPanel ap2)
1271 return (_alignwith != null) && _alignwith.contains(ap2);
1274 public boolean isUsedforcolourby(AlignmentPanel ap2)
1276 return (_colourwith != null) && _colourwith.contains(ap2);
1281 * @return TRUE if the view is NOT being coloured by sequence associations.
1283 public boolean isColouredByJmol()
1285 return !jmb.isColourBySequence();