2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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.datamodel.PDBEntry;
35 import jalview.schemes.*;
36 import jalview.util.Platform;
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
106 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
107 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
108 boolean leaveColouringToJmol, String loadStatus,
109 Rectangle bounds, String viewid)
111 PDBEntry[] pdbentrys = new PDBEntry[files.length];
112 for (int i = 0; i < pdbentrys.length; i++)
114 PDBEntry pdbentry = new PDBEntry();
115 pdbentry.setFile(files[i]);
116 pdbentry.setId(ids[i]);
117 pdbentrys[i] = pdbentry;
119 // / TODO: check if protocol is needed to be set, and if chains are
121 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
122 pdbentrys, seqs, null, null);
124 jmb.setLoadingFromArchive(true);
125 addAlignmentPanel(ap);
128 useAlignmentPanelForSuperposition(ap);
130 if (leaveColouringToJmol || !usetoColour)
132 jmb.setColourBySequence(false);
133 seqColour.setSelected(false);
134 jmolColour.setSelected(true);
138 useAlignmentPanelForColourbyseq(ap);
139 jmb.setColourBySequence(true);
140 seqColour.setSelected(true);
141 jmolColour.setSelected(false);
143 this.setBounds(bounds);
146 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
147 // bounds.width,bounds.height);
149 this.addInternalFrameListener(new InternalFrameAdapter()
151 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
156 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
160 private void initMenus()
162 seqColour.setSelected(jmb.isColourBySequence());
163 jmolColour.setSelected(!jmb.isColourBySequence());
164 if (_colourwith == null)
166 _colourwith = new Vector<AlignmentPanel>();
168 if (_alignwith == null)
170 _alignwith = new Vector<AlignmentPanel>();
173 seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith,
178 public void itemStateChanged(ItemEvent e)
180 if (!seqColour.isSelected())
186 // update the jmol display now.
187 seqColour_actionPerformed(null);
191 viewMenu.add(seqColourBy);
192 final ItemListener handler;
193 JMenu alpanels = new ViewSelectionMenu("Superpose with ..", this,
194 _alignwith, handler = new ItemListener()
198 public void itemStateChanged(ItemEvent e)
200 alignStructs.setEnabled(_alignwith.size() > 0);
201 alignStructs.setToolTipText("Align structures using "
202 + _alignwith.size() + " linked alignment views");
205 handler.itemStateChanged(null);
206 jmolActionMenu.add(alpanels);
207 jmolActionMenu.addMenuListener(new MenuListener()
211 public void menuSelected(MenuEvent e)
213 handler.itemStateChanged(null);
217 public void menuDeselected(MenuEvent e)
219 // TODO Auto-generated method stub
224 public void menuCanceled(MenuEvent e)
226 // TODO Auto-generated method stub
232 IProgressIndicator progressBar = null;
235 * add a single PDB structure to a new or existing Jmol view
242 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
243 final AlignmentPanel ap)
245 progressBar = ap.alignFrame;
246 // ////////////////////////////////
247 // Is the pdb file already loaded?
248 String alreadyMapped = ap.getStructureSelectionManager()
249 .alreadyMappedToFile(pdbentry.getId());
251 if (alreadyMapped != null)
253 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
254 pdbentry.getId() + " is already displayed."
255 + "\nDo you want to re-use this viewer ?",
256 "Map Sequences to Visible Window: " + pdbentry.getId(),
257 JOptionPane.YES_NO_OPTION);
259 if (option == JOptionPane.YES_OPTION)
261 // TODO : Fix multiple seq to one chain issue here.
262 ap.getStructureSelectionManager().setMapping(seq, chains,
263 alreadyMapped, AppletFormatAdapter.FILE);
264 if (ap.seqPanel.seqCanvas.fr != null)
266 ap.seqPanel.seqCanvas.fr.featuresAdded();
267 ap.paintAlignment(true);
270 // Now this AppJmol is mapped to new sequences. We must add them to
271 // the exisiting array
272 JInternalFrame[] frames = Desktop.instance.getAllFrames();
274 for (int i = 0; i < frames.length; i++)
276 if (frames[i] instanceof AppJmol)
278 final AppJmol topJmol = ((AppJmol) frames[i]);
279 // JBPNOTE: this looks like a binding routine, rather than a gui
281 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
283 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
285 topJmol.jmb.addSequence(pe, seq);
286 topJmol.addAlignmentPanel(ap);
287 // add it to the set used for colouring
288 topJmol.useAlignmentPanelForColourbyseq(ap);
289 topJmol.buildJmolActionMenu();
290 ap.getStructureSelectionManager()
291 .sequenceColoursChanged(ap);
301 // /////////////////////////////////
302 // Check if there are other Jmol views involving this alignment
303 // and prompt user about adding this molecule to one of them
304 Vector existingViews = getJmolsFor(ap);
305 if (existingViews.size() > 0)
307 Enumeration jm = existingViews.elements();
308 while (jm.hasMoreElements())
310 AppJmol topJmol = (AppJmol) jm.nextElement();
311 // TODO: highlight topJmol in view somehow
312 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
313 "Do you want to add " + pdbentry.getId()
314 + " to the view called\n'" + topJmol.getTitle()
315 + "'\n", "Align to existing structure view",
316 JOptionPane.YES_NO_OPTION);
317 if (option == JOptionPane.YES_OPTION)
319 topJmol.useAlignmentPanelForSuperposition(ap);
320 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
325 // /////////////////////////////////
326 openNewJmol(ap, new PDBEntry[]
327 { pdbentry }, new SequenceI[][]
331 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
334 progressBar = ap.alignFrame;
335 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
336 pdbentrys, seqs, null, null);
337 addAlignmentPanel(ap);
338 useAlignmentPanelForColourbyseq(ap);
339 if (pdbentrys.length > 1)
341 alignAddedStructures = true;
342 useAlignmentPanelForSuperposition(ap);
344 jmb.setColourBySequence(true);
345 setSize(400, 400); // probably should be a configurable/dynamic default here
349 addingStructures = false;
350 worker = new Thread(this);
353 this.addInternalFrameListener(new InternalFrameAdapter()
355 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
364 * create a new Jmol containing several structures superimposed using the
371 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
373 openNewJmol(ap, pe, seqs);
377 * list of sequenceSet ids associated with the view
379 ArrayList<String> _aps = new ArrayList();
381 public AlignmentPanel[] getAllAlignmentPanels()
383 AlignmentPanel[] t, list = new AlignmentPanel[0];
384 for (String setid : _aps)
386 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
389 t = new AlignmentPanel[list.length + panels.length];
390 System.arraycopy(list, 0, t, 0, list.length);
391 System.arraycopy(panels, 0, t, list.length, panels.length);
400 * list of alignment panels to use for superposition
402 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
405 * list of alignment panels that are used for colouring structures by aligned
408 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
411 * set the primary alignmentPanel reference and add another alignPanel to the
412 * list of ones to use for colouring and aligning
416 public void addAlignmentPanel(AlignmentPanel nap)
422 if (!_aps.contains(nap.av.getSequenceSetId()))
424 _aps.add(nap.av.getSequenceSetId());
429 * remove any references held to the given alignment panel
433 public void removeAlignmentPanel(AlignmentPanel nap)
437 _alignwith.remove(nap);
438 _colourwith.remove(nap);
442 for (AlignmentPanel aps : getAllAlignmentPanels())
451 } catch (Exception ex)
456 buildJmolActionMenu();
460 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
462 addAlignmentPanel(nap);
463 if (!_alignwith.contains(nap))
469 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
471 if (_alignwith.contains(nap))
473 _alignwith.remove(nap);
477 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
478 boolean enableColourBySeq)
480 useAlignmentPanelForColourbyseq(nap);
481 jmb.setColourBySequence(enableColourBySeq);
482 seqColour.setSelected(enableColourBySeq);
483 jmolColour.setSelected(!enableColourBySeq);
486 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
488 addAlignmentPanel(nap);
489 if (!_colourwith.contains(nap))
491 _colourwith.add(nap);
495 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
497 if (_colourwith.contains(nap))
499 _colourwith.remove(nap);
504 * pdb retrieval thread.
506 private Thread worker = null;
509 * add a new structure (with associated sequences and chains) to this viewer,
510 * retrieving it if necessary first.
517 * if true, new structure(s) will be align using associated alignment
519 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
520 final String[] chains, final boolean b,
521 final IProgressIndicator alignFrame)
523 if (pdbentry.getFile() == null)
525 if (worker != null && worker.isAlive())
527 // a retrieval is in progress, wait around and add ourselves to the
529 new Thread(new Runnable()
533 while (worker != null && worker.isAlive() && _started)
537 Thread.sleep(100 + ((int) Math.random() * 100));
539 } catch (Exception e)
544 // and call ourselves again.
545 addStructure(pdbentry, seq, chains, b, alignFrame);
551 // otherwise, start adding the structure.
552 jmb.addSequenceAndChain(new PDBEntry[]
553 { pdbentry }, new SequenceI[][]
554 { seq }, new String[][]
556 addingStructures = true;
558 alignAddedStructures = b;
559 progressBar = alignFrame; // visual indication happens on caller frame.
560 (worker = new Thread(this)).start();
564 private Vector getJmolsFor(AlignmentPanel ap2)
566 Vector otherJmols = new Vector();
567 // Now this AppJmol is mapped to new sequences. We must add them to
568 // the exisiting array
569 JInternalFrame[] frames = Desktop.instance.getAllFrames();
571 for (int i = 0; i < frames.length; i++)
573 if (frames[i] instanceof AppJmol)
575 AppJmol topJmol = ((AppJmol) frames[i]);
576 if (topJmol.isLinkedWith(ap2))
578 otherJmols.addElement(topJmol);
585 void initJmol(String command)
587 jmb.setFinishedInit(false);
588 renderPanel = new RenderPanel();
589 // TODO: consider waiting until the structure/view is fully loaded before
591 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
592 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
593 getBounds().width, getBounds().height);
594 if (scriptWindow == null)
596 BorderLayout bl = new BorderLayout();
599 scriptWindow = new JPanel(bl);
600 scriptWindow.setVisible(false);
603 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
605 jmb.newJmolPopup(true, "Jmol", true);
610 jmb.evalStateCommand(command);
611 jmb.setFinishedInit(true);
614 void setChainMenuItems(Vector chains)
616 chainMenu.removeAll();
621 JMenuItem menuItem = new JMenuItem("All");
622 menuItem.addActionListener(new ActionListener()
624 public void actionPerformed(ActionEvent evt)
626 allChainsSelected = true;
627 for (int i = 0; i < chainMenu.getItemCount(); i++)
629 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
630 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
633 allChainsSelected = false;
637 chainMenu.add(menuItem);
639 for (int c = 0; c < chains.size(); c++)
641 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
642 menuItem.addItemListener(new ItemListener()
644 public void itemStateChanged(ItemEvent evt)
646 if (!allChainsSelected)
651 chainMenu.add(menuItem);
655 boolean allChainsSelected = false;
657 private boolean alignAddedStructures = false;
661 Vector toshow = new Vector();
663 int mlength, p, mnum;
664 for (int i = 0; i < chainMenu.getItemCount(); i++)
666 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
668 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
669 if (item.isSelected())
671 toshow.addElement(item.getText());
675 jmb.centerViewer(toshow);
685 // TODO: check for memory leaks where instance isn't finalised because jmb
686 // holds a reference to the window
691 * state flag for PDB retrieval thread
693 private boolean _started = false;
699 // todo - record which pdbids were successfuly imported.
700 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
703 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
704 // TODO: replace with reference fetching/transfer code (validate PDBentry
706 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
707 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
709 String file = jmb.pdbentry[pi].getFile();
712 // retrieve the pdb and store it locally
713 AlignmentI pdbseq = null;
714 pdbid = jmb.pdbentry[pi].getId();
715 long hdl = pdbid.hashCode() - System.currentTimeMillis();
716 if (progressBar != null)
718 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
722 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
724 } catch (OutOfMemoryError oomerror)
726 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
727 } catch (Exception ex)
729 ex.printStackTrace();
730 errormsgs.append("'" + pdbid + "'");
732 if (progressBar != null)
734 progressBar.setProgressBar("Finished.", hdl);
738 // just transfer the file name from the first sequence's first
740 file = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
741 .elementAt(0)).getFile()).getAbsolutePath();
742 jmb.pdbentry[pi].setFile(file);
744 files.append(" \"" + Platform.escapeString(file) + "\"");
748 errormsgs.append("'" + pdbid + "' ");
753 if (curfiles != null && curfiles.length > 0)
755 addingStructures = true; // already files loaded.
756 for (int c = 0; c < curfiles.length; c++)
758 if (curfiles[c].equals(file))
767 files.append(" \"" + Platform.escapeString(file) + "\"");
771 } catch (OutOfMemoryError oomerror)
773 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
774 } catch (Exception ex)
776 ex.printStackTrace();
777 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
780 if (errormsgs.length() > 0)
783 JOptionPane.showInternalMessageDialog(Desktop.desktop,
784 "The following pdb entries could not be retrieved from the PDB:\n"
785 + errormsgs.toString()
786 + "\nPlease try downloading them manually.",
787 "Couldn't load file", JOptionPane.ERROR_MESSAGE);
790 long lastnotify = jmb.getLoadNotifiesHandled();
791 if (files.length() > 0)
793 if (!addingStructures)
798 initJmol("load FILES " + files.toString());
799 } catch (OutOfMemoryError oomerror)
801 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
802 Cache.log.debug("File locations are " + files);
803 } catch (Exception ex)
805 Cache.log.error("Couldn't open Jmol viewer!", ex);
810 StringBuffer cmd = new StringBuffer();
811 cmd.append("loadingJalviewdata=true\nload APPEND ");
812 cmd.append(files.toString());
813 cmd.append("\nloadingJalviewdata=null");
814 final String command = cmd.toString();
816 lastnotify = jmb.getLoadNotifiesHandled();
820 jmb.evalStateCommand(command);
821 } catch (OutOfMemoryError oomerror)
824 "When trying to add structures to the Jmol viewer!",
826 Cache.log.debug("File locations are " + files);
827 } catch (Exception ex)
829 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
833 // need to wait around until script has finished
834 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
835 : (jmb.isFinishedInit() && jmb.getPdbFile().length != jmb.pdbentry.length))
839 Cache.log.debug("Waiting around for jmb notify.");
841 } catch (Exception e)
845 // refresh the sequence colours for the new structure(s)
846 for (AlignmentPanel ap : _colourwith)
848 jmb.updateColours(ap);
850 // do superposition if asked to
851 if (alignAddedStructures)
853 javax.swing.SwingUtilities.invokeLater(new Runnable()
857 alignStructs_withAllAlignPanels();
858 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
861 alignAddedStructures = false;
863 addingStructures = false;
870 public void pdbFile_actionPerformed(ActionEvent actionEvent)
872 JalviewFileChooser chooser = new JalviewFileChooser(
873 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
875 chooser.setFileView(new JalviewFileView());
876 chooser.setDialogTitle("Save PDB File");
877 chooser.setToolTipText("Save");
879 int value = chooser.showSaveDialog(this);
881 if (value == JalviewFileChooser.APPROVE_OPTION)
885 // TODO: cope with multiple PDB files in view
886 BufferedReader in = new BufferedReader(new FileReader(
887 jmb.getPdbFile()[0]));
888 File outFile = chooser.getSelectedFile();
890 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
892 while ((data = in.readLine()) != null)
894 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
900 } catch (Exception ex)
902 ex.printStackTrace();
907 public void viewMapping_actionPerformed(ActionEvent actionEvent)
909 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
912 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
914 cap.appendText(jmb.printMapping(jmb.pdbentry[pdbe].getFile()));
915 cap.appendText("\n");
917 } catch (OutOfMemoryError e)
920 "composing sequence-structure alignments for display in text box.",
925 jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
935 public void eps_actionPerformed(ActionEvent e)
937 makePDBImage(jalview.util.ImageMaker.EPS);
946 public void png_actionPerformed(ActionEvent e)
948 makePDBImage(jalview.util.ImageMaker.PNG);
951 void makePDBImage(int type)
953 int width = getWidth();
954 int height = getHeight();
956 jalview.util.ImageMaker im;
958 if (type == jalview.util.ImageMaker.PNG)
960 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
961 "Make PNG image from view", width, height, null, null);
965 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
966 "Make EPS file from view", width, height, null,
970 if (im.getGraphics() != null)
972 Rectangle rect = new Rectangle(width, height);
973 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
978 public void jmolColour_actionPerformed(ActionEvent actionEvent)
980 if (jmolColour.isSelected())
982 // disable automatic sequence colouring.
983 jmb.setColourBySequence(false);
987 public void seqColour_actionPerformed(ActionEvent actionEvent)
989 jmb.setColourBySequence(seqColour.isSelected());
990 if (_colourwith == null)
992 _colourwith = new Vector<AlignmentPanel>();
994 if (jmb.isColourBySequence())
996 if (!jmb.isLoadingFromArchive())
998 if (_colourwith.size() == 0 && ap != null)
1000 // Make the currently displayed alignment panel the associated view
1001 _colourwith.add(ap.alignFrame.alignPanel);
1004 // Set the colour using the current view for the associated alignframe
1005 for (AlignmentPanel ap : _colourwith)
1007 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
1012 public void chainColour_actionPerformed(ActionEvent actionEvent)
1014 chainColour.setSelected(true);
1015 jmb.colourByChain();
1018 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1020 chargeColour.setSelected(true);
1021 jmb.colourByCharge();
1024 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1026 zappoColour.setSelected(true);
1027 jmb.setJalviewColourScheme(new ZappoColourScheme());
1030 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1032 taylorColour.setSelected(true);
1033 jmb.setJalviewColourScheme(new TaylorColourScheme());
1036 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1038 hydroColour.setSelected(true);
1039 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1042 public void helixColour_actionPerformed(ActionEvent actionEvent)
1044 helixColour.setSelected(true);
1045 jmb.setJalviewColourScheme(new HelixColourScheme());
1048 public void strandColour_actionPerformed(ActionEvent actionEvent)
1050 strandColour.setSelected(true);
1051 jmb.setJalviewColourScheme(new StrandColourScheme());
1054 public void turnColour_actionPerformed(ActionEvent actionEvent)
1056 turnColour.setSelected(true);
1057 jmb.setJalviewColourScheme(new TurnColourScheme());
1060 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1062 buriedColour.setSelected(true);
1063 jmb.setJalviewColourScheme(new BuriedColourScheme());
1066 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1068 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1071 public void userColour_actionPerformed(ActionEvent actionEvent)
1073 userColour.setSelected(true);
1074 new UserDefinedColours(this, null);
1077 public void backGround_actionPerformed(ActionEvent actionEvent)
1079 java.awt.Color col = JColorChooser.showDialog(this,
1080 "Select Background Colour", null);
1083 jmb.setBackgroundColour(col);
1087 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1091 jalview.util.BrowserLauncher
1092 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1093 } catch (Exception ex)
1098 public void showConsole(boolean showConsole)
1103 if (splitPane == null)
1105 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1106 splitPane.setTopComponent(renderPanel);
1107 splitPane.setBottomComponent(scriptWindow);
1108 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1109 splitPane.setDividerLocation(getHeight() - 200);
1110 scriptWindow.setVisible(true);
1111 scriptWindow.validate();
1112 splitPane.validate();
1118 if (splitPane != null)
1120 splitPane.setVisible(false);
1125 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1131 class RenderPanel extends JPanel
1133 final Dimension currentSize = new Dimension();
1135 final Rectangle rectClip = new Rectangle();
1137 public void paintComponent(Graphics g)
1139 getSize(currentSize);
1140 g.getClipBounds(rectClip);
1142 if (jmb.fileLoadingError != null)
1144 g.setColor(Color.black);
1145 g.fillRect(0, 0, currentSize.width, currentSize.height);
1146 g.setColor(Color.white);
1147 g.setFont(new Font("Verdana", Font.BOLD, 14));
1148 g.drawString("Error loading file...", 20, currentSize.height / 2);
1149 StringBuffer sb = new StringBuffer();
1151 for (int e = 0; e < jmb.pdbentry.length; e++)
1153 sb.append(jmb.pdbentry[e].getId());
1154 if (e < jmb.pdbentry.length - 1)
1159 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1162 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1163 * g.getFontMetrics().getHeight());
1167 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1169 g.setColor(Color.black);
1170 g.fillRect(0, 0, currentSize.width, currentSize.height);
1171 g.setColor(Color.white);
1172 g.setFont(new Font("Verdana", Font.BOLD, 14));
1173 g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
1177 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1182 String viewId = null;
1184 public String getViewId()
1188 viewId = System.currentTimeMillis() + "." + this.hashCode();
1193 public void updateTitleAndMenus()
1195 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1200 setChainMenuItems(jmb.chainNames);
1202 this.setTitle(jmb.getViewerTitle());
1203 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1205 jmolActionMenu.setVisible(true);
1207 if (!jmb.isLoadingFromArchive())
1209 seqColour_actionPerformed(null);
1213 protected void buildJmolActionMenu()
1215 if (_alignwith == null)
1217 _alignwith = new Vector<AlignmentPanel>();
1219 if (_alignwith.size() == 0 && ap != null)
1224 for (Component c : jmolActionMenu.getMenuComponents())
1226 if (c != alignStructs)
1228 jmolActionMenu.remove((JMenuItem) c);
1231 final ItemListener handler;
1238 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1242 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1244 alignStructs_withAllAlignPanels();
1247 private void alignStructs_withAllAlignPanels()
1254 if (_alignwith.size() == 0)
1261 AlignmentI[] als = new Alignment[_alignwith.size()];
1262 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1263 int[] alm = new int[_alignwith.size()];
1266 for (AlignmentPanel ap : _alignwith)
1268 als[a] = ap.av.getAlignment();
1270 alc[a++] = ap.av.getColumnSelection();
1272 jmb.superposeStructures(als, alm, alc);
1273 } catch (Exception e)
1275 StringBuffer sp = new StringBuffer();
1276 for (AlignmentPanel ap : _alignwith)
1278 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1280 Cache.log.info("Couldn't align structures with the " + sp.toString()
1281 + "associated alignment panels.", e);
1287 public void setJalviewColourScheme(ColourSchemeI ucs)
1289 jmb.setJalviewColourScheme(ucs);
1296 * @return first alignment panel displaying given alignment, or the default
1299 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1301 for (AlignmentPanel ap : getAllAlignmentPanels())
1303 if (ap.av.getAlignment() == alignment)
1314 * @return true if this Jmol instance is linked with the given alignPanel
1316 public boolean isLinkedWith(AlignmentPanel ap2)
1318 return _aps.contains(ap2.av.getSequenceSetId());
1321 public boolean isUsedforaligment(AlignmentPanel ap2)
1324 return (_alignwith != null) && _alignwith.contains(ap2);
1327 public boolean isUsedforcolourby(AlignmentPanel ap2)
1329 return (_colourwith != null) && _colourwith.contains(ap2);
1334 * @return TRUE if the view is NOT being coloured by sequence associations.
1336 public boolean isColouredByJmol()
1338 return !jmb.isColourBySequence();