2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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.AlignmentViewPanel;
30 import jalview.api.SequenceStructureBinding;
31 import jalview.bin.Cache;
32 import jalview.datamodel.*;
33 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
34 import jalview.structure.*;
35 import jalview.datamodel.PDBEntry;
37 import jalview.schemes.*;
38 import jalview.util.Platform;
40 public class AppJmol extends GStructureViewer implements Runnable,
41 SequenceStructureBinding, ViewSetProvider
50 RenderPanel renderPanel;
54 Vector atomsPicked = new Vector();
56 private boolean addingStructures = false;
66 * @deprecated defaults to AppJmol(String[] files, ... , viewid);
68 public AppJmol(String file, String id, SequenceI[] seq,
69 AlignmentPanel ap, String loadStatus, Rectangle bounds)
71 this(file, id, seq, ap, loadStatus, bounds, null);
77 public AppJmol(String file, String id, SequenceI[] seq,
78 AlignmentPanel ap, String loadStatus, Rectangle bounds,
82 { file }, new String[]
83 { id }, new SequenceI[][]
84 { seq }, ap, true, true, false, loadStatus, bounds, viewid);
87 ViewSelectionMenu seqColourBy;
96 * - add the alignment panel to the list used for colouring these
99 * - add the alignment panel to the list used for aligning these
101 * @param leaveColouringToJmol
102 * - do not update the colours from any other source. Jmol is
108 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
109 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
110 boolean leaveColouringToJmol, String loadStatus,
111 Rectangle bounds, String viewid)
113 PDBEntry[] pdbentrys = new PDBEntry[files.length];
114 for (int i = 0; i < pdbentrys.length; i++)
116 PDBEntry pdbentry = new PDBEntry();
117 pdbentry.setFile(files[i]);
118 pdbentry.setId(ids[i]);
119 pdbentrys[i] = pdbentry;
121 // / TODO: check if protocol is needed to be set, and if chains are
123 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
124 pdbentrys, seqs, null, null);
126 jmb.setLoadingFromArchive(true);
127 addAlignmentPanel(ap);
130 useAlignmentPanelForSuperposition(ap);
132 if (leaveColouringToJmol || !usetoColour)
134 jmb.setColourBySequence(false);
135 seqColour.setSelected(false);
136 jmolColour.setSelected(true);
140 useAlignmentPanelForColourbyseq(ap);
141 jmb.setColourBySequence(true);
142 seqColour.setSelected(true);
143 jmolColour.setSelected(false);
145 this.setBounds(bounds);
148 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
149 // bounds.width,bounds.height);
151 this.addInternalFrameListener(new InternalFrameAdapter()
153 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
158 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
162 private void initMenus()
164 seqColour.setSelected(jmb.isColourBySequence());
165 jmolColour.setSelected(!jmb.isColourBySequence());
166 if (_colourwith == null)
168 _colourwith = new Vector<AlignmentPanel>();
170 if (_alignwith == null)
172 _alignwith = new Vector<AlignmentPanel>();
175 seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith,
180 public void itemStateChanged(ItemEvent e)
182 if (!seqColour.isSelected())
188 // update the jmol display now.
189 seqColour_actionPerformed(null);
193 viewMenu.add(seqColourBy);
194 final ItemListener handler;
195 JMenu alpanels = new ViewSelectionMenu("Superpose with ..", this,
196 _alignwith, handler = new ItemListener()
200 public void itemStateChanged(ItemEvent e)
202 alignStructs.setEnabled(_alignwith.size() > 0);
203 alignStructs.setToolTipText("Align structures using "
204 + _alignwith.size() + " linked alignment views");
207 handler.itemStateChanged(null);
208 jmolActionMenu.add(alpanels);
209 jmolActionMenu.addMenuListener(new MenuListener()
213 public void menuSelected(MenuEvent e)
215 handler.itemStateChanged(null);
219 public void menuDeselected(MenuEvent e)
221 // TODO Auto-generated method stub
226 public void menuCanceled(MenuEvent e)
228 // TODO Auto-generated method stub
234 IProgressIndicator progressBar = null;
237 * add a single PDB structure to a new or existing Jmol view
244 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
245 final AlignmentPanel ap)
247 progressBar = ap.alignFrame;
248 // ////////////////////////////////
249 // Is the pdb file already loaded?
250 String alreadyMapped = ap.getStructureSelectionManager()
251 .alreadyMappedToFile(pdbentry.getId());
253 if (alreadyMapped != null)
255 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
256 pdbentry.getId() + " is already displayed."
257 + "\nDo you want to re-use this viewer ?",
258 "Map Sequences to Visible Window: " + pdbentry.getId(),
259 JOptionPane.YES_NO_OPTION);
261 if (option == JOptionPane.YES_OPTION)
263 // TODO : Fix multiple seq to one chain issue here.
264 ap.getStructureSelectionManager().setMapping(seq, chains,
265 alreadyMapped, AppletFormatAdapter.FILE);
266 if (ap.seqPanel.seqCanvas.fr != null)
268 ap.seqPanel.seqCanvas.fr.featuresAdded();
269 ap.paintAlignment(true);
272 // Now this AppJmol is mapped to new sequences. We must add them to
273 // the exisiting array
274 JInternalFrame[] frames = Desktop.instance.getAllFrames();
276 for (int i = 0; i < frames.length; i++)
278 if (frames[i] instanceof AppJmol)
280 final AppJmol topJmol = ((AppJmol) frames[i]);
281 // JBPNOTE: this looks like a binding routine, rather than a gui
283 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
285 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
287 topJmol.jmb.addSequence(pe, seq);
288 topJmol.addAlignmentPanel(ap);
289 // add it to the set used for colouring
290 topJmol.useAlignmentPanelForColourbyseq(ap);
291 topJmol.buildJmolActionMenu();
292 ap.getStructureSelectionManager()
293 .sequenceColoursChanged(ap);
303 // /////////////////////////////////
304 // Check if there are other Jmol views involving this alignment
305 // and prompt user about adding this molecule to one of them
306 Vector existingViews = getJmolsFor(ap);
307 if (existingViews.size() > 0)
309 Enumeration jm = existingViews.elements();
310 while (jm.hasMoreElements())
312 AppJmol topJmol = (AppJmol) jm.nextElement();
313 // TODO: highlight topJmol in view somehow
314 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
315 "Do you want to add " + pdbentry.getId()
316 + " to the view called\n'" + topJmol.getTitle()
317 + "'\n", "Align to existing structure view",
318 JOptionPane.YES_NO_OPTION);
319 if (option == JOptionPane.YES_OPTION)
321 topJmol.useAlignmentPanelForSuperposition(ap);
322 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
327 // /////////////////////////////////
328 openNewJmol(ap, new PDBEntry[]
329 { pdbentry }, new SequenceI[][]
333 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
336 progressBar = ap.alignFrame;
337 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
338 pdbentrys, seqs, null, null);
339 addAlignmentPanel(ap);
340 useAlignmentPanelForColourbyseq(ap);
341 if (pdbentrys.length > 1)
343 alignAddedStructures = true;
344 useAlignmentPanelForSuperposition(ap);
346 jmb.setColourBySequence(true);
347 setSize(400, 400); // probably should be a configurable/dynamic default here
351 addingStructures = false;
352 worker = new Thread(this);
355 this.addInternalFrameListener(new InternalFrameAdapter()
357 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
366 * create a new Jmol containing several structures superimposed using the
373 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
375 openNewJmol(ap, pe, seqs);
379 * list of sequenceSet ids associated with the view
381 ArrayList<String> _aps = new ArrayList();
383 public AlignmentPanel[] getAllAlignmentPanels()
385 AlignmentPanel[] t, list = new AlignmentPanel[0];
386 for (String setid : _aps)
388 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
391 t = new AlignmentPanel[list.length + panels.length];
392 System.arraycopy(list, 0, t, 0, list.length);
393 System.arraycopy(panels, 0, t, list.length, panels.length);
402 * list of alignment panels to use for superposition
404 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
407 * list of alignment panels that are used for colouring structures by aligned
410 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
413 * set the primary alignmentPanel reference and add another alignPanel to the
414 * list of ones to use for colouring and aligning
418 public void addAlignmentPanel(AlignmentPanel nap)
424 if (!_aps.contains(nap.av.getSequenceSetId()))
426 _aps.add(nap.av.getSequenceSetId());
431 * remove any references held to the given alignment panel
435 public void removeAlignmentPanel(AlignmentPanel nap)
439 _alignwith.remove(nap);
440 _colourwith.remove(nap);
444 for (AlignmentPanel aps : getAllAlignmentPanels())
453 } catch (Exception ex)
458 buildJmolActionMenu();
462 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
464 addAlignmentPanel(nap);
465 if (!_alignwith.contains(nap))
471 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
473 if (_alignwith.contains(nap))
475 _alignwith.remove(nap);
479 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
480 boolean enableColourBySeq)
482 useAlignmentPanelForColourbyseq(nap);
483 jmb.setColourBySequence(enableColourBySeq);
484 seqColour.setSelected(enableColourBySeq);
485 jmolColour.setSelected(!enableColourBySeq);
488 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
490 addAlignmentPanel(nap);
491 if (!_colourwith.contains(nap))
493 _colourwith.add(nap);
497 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
499 if (_colourwith.contains(nap))
501 _colourwith.remove(nap);
506 * pdb retrieval thread.
508 private Thread worker = null;
511 * add a new structure (with associated sequences and chains) to this viewer,
512 * retrieving it if necessary first.
519 * if true, new structure(s) will be align using associated alignment
521 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
522 final String[] chains, final boolean b,
523 final IProgressIndicator alignFrame)
525 if (pdbentry.getFile() == null)
527 if (worker != null && worker.isAlive())
529 // a retrieval is in progress, wait around and add ourselves to the
531 new Thread(new Runnable()
535 while (worker != null && worker.isAlive() && _started)
539 Thread.sleep(100 + ((int) Math.random() * 100));
541 } catch (Exception e)
546 // and call ourselves again.
547 addStructure(pdbentry, seq, chains, b, alignFrame);
553 // otherwise, start adding the structure.
554 jmb.addSequenceAndChain(new PDBEntry[]
555 { pdbentry }, new SequenceI[][]
556 { seq }, new String[][]
558 addingStructures = true;
560 alignAddedStructures = b;
561 progressBar = alignFrame; // visual indication happens on caller frame.
562 (worker = new Thread(this)).start();
566 private Vector getJmolsFor(AlignmentPanel ap2)
568 Vector otherJmols = new Vector();
569 // Now this AppJmol is mapped to new sequences. We must add them to
570 // the exisiting array
571 JInternalFrame[] frames = Desktop.instance.getAllFrames();
573 for (int i = 0; i < frames.length; i++)
575 if (frames[i] instanceof AppJmol)
577 AppJmol topJmol = ((AppJmol) frames[i]);
578 if (topJmol.isLinkedWith(ap2))
580 otherJmols.addElement(topJmol);
587 void initJmol(String command)
589 jmb.setFinishedInit(false);
590 renderPanel = new RenderPanel();
591 // TODO: consider waiting until the structure/view is fully loaded before
593 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
594 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
595 getBounds().width, getBounds().height);
596 if (scriptWindow == null)
598 BorderLayout bl = new BorderLayout();
601 scriptWindow = new JPanel(bl);
602 scriptWindow.setVisible(false);
605 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
607 jmb.newJmolPopup(true, "Jmol", true);
612 jmb.evalStateCommand(command);
613 jmb.setFinishedInit(true);
616 void setChainMenuItems(Vector chains)
618 chainMenu.removeAll();
623 JMenuItem menuItem = new JMenuItem("All");
624 menuItem.addActionListener(new ActionListener()
626 public void actionPerformed(ActionEvent evt)
628 allChainsSelected = true;
629 for (int i = 0; i < chainMenu.getItemCount(); i++)
631 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
632 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
635 allChainsSelected = false;
639 chainMenu.add(menuItem);
641 for (int c = 0; c < chains.size(); c++)
643 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
644 menuItem.addItemListener(new ItemListener()
646 public void itemStateChanged(ItemEvent evt)
648 if (!allChainsSelected)
653 chainMenu.add(menuItem);
657 boolean allChainsSelected = false;
659 private boolean alignAddedStructures = false;
663 Vector toshow = new Vector();
665 int mlength, p, mnum;
666 for (int i = 0; i < chainMenu.getItemCount(); i++)
668 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
670 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
671 if (item.isSelected())
673 toshow.addElement(item.getText());
677 jmb.centerViewer(toshow);
687 // TODO: check for memory leaks where instance isn't finalised because jmb
688 // holds a reference to the window
693 * state flag for PDB retrieval thread
695 private boolean _started = false;
701 // todo - record which pdbids were successfuly imported.
702 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
705 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
706 // TODO: replace with reference fetching/transfer code (validate PDBentry
708 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
709 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
711 String file = jmb.pdbentry[pi].getFile();
714 // retrieve the pdb and store it locally
715 AlignmentI pdbseq = null;
716 pdbid = jmb.pdbentry[pi].getId();
717 long hdl = pdbid.hashCode() - System.currentTimeMillis();
718 if (progressBar != null)
720 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
724 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
726 } catch (OutOfMemoryError oomerror)
728 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
729 } catch (Exception ex)
731 ex.printStackTrace();
732 errormsgs.append("'" + pdbid + "'");
734 if (progressBar != null)
736 progressBar.setProgressBar("Finished.", hdl);
740 // just transfer the file name from the first sequence's first
742 file = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
743 .elementAt(0)).getFile()).getAbsolutePath();
744 jmb.pdbentry[pi].setFile(file);
746 files.append(" \"" + Platform.escapeString(file) + "\"");
750 errormsgs.append("'" + pdbid + "' ");
755 if (curfiles != null && curfiles.length > 0)
757 addingStructures = true; // already files loaded.
758 for (int c = 0; c < curfiles.length; c++)
760 if (curfiles[c].equals(file))
769 files.append(" \"" + Platform.escapeString(file) + "\"");
773 } catch (OutOfMemoryError oomerror)
775 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
776 } catch (Exception ex)
778 ex.printStackTrace();
779 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
782 if (errormsgs.length() > 0)
785 JOptionPane.showInternalMessageDialog(Desktop.desktop,
786 "The following pdb entries could not be retrieved from the PDB:\n"
787 + errormsgs.toString()
788 + "\nPlease try downloading them manually.",
789 "Couldn't load file", JOptionPane.ERROR_MESSAGE);
792 long lastnotify = jmb.getLoadNotifiesHandled();
793 if (files.length() > 0)
795 if (!addingStructures)
800 initJmol("load FILES " + files.toString());
801 } catch (OutOfMemoryError oomerror)
803 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
804 Cache.log.debug("File locations are " + files);
805 } catch (Exception ex)
807 Cache.log.error("Couldn't open Jmol viewer!", ex);
812 StringBuffer cmd = new StringBuffer();
813 cmd.append("loadingJalviewdata=true\nload APPEND ");
814 cmd.append(files.toString());
815 cmd.append("\nloadingJalviewdata=null");
816 final String command = cmd.toString();
818 lastnotify = jmb.getLoadNotifiesHandled();
822 jmb.evalStateCommand(command);
823 } catch (OutOfMemoryError oomerror)
826 "When trying to add structures to the Jmol viewer!",
828 Cache.log.debug("File locations are " + files);
829 } catch (Exception ex)
831 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
835 // need to wait around until script has finished
836 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
837 : (jmb.isFinishedInit() && jmb.getPdbFile().length != jmb.pdbentry.length))
841 Cache.log.debug("Waiting around for jmb notify.");
843 } catch (Exception e)
847 // refresh the sequence colours for the new structure(s)
848 for (AlignmentPanel ap : _colourwith)
850 jmb.updateColours(ap);
852 // do superposition if asked to
853 if (alignAddedStructures)
855 javax.swing.SwingUtilities.invokeLater(new Runnable()
859 alignStructs_withAllAlignPanels();
860 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
863 alignAddedStructures = false;
865 addingStructures = false;
872 public void pdbFile_actionPerformed(ActionEvent actionEvent)
874 JalviewFileChooser chooser = new JalviewFileChooser(
875 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
877 chooser.setFileView(new JalviewFileView());
878 chooser.setDialogTitle("Save PDB File");
879 chooser.setToolTipText("Save");
881 int value = chooser.showSaveDialog(this);
883 if (value == JalviewFileChooser.APPROVE_OPTION)
887 // TODO: cope with multiple PDB files in view
888 BufferedReader in = new BufferedReader(new FileReader(
889 jmb.getPdbFile()[0]));
890 File outFile = chooser.getSelectedFile();
892 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
894 while ((data = in.readLine()) != null)
896 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
902 } catch (Exception ex)
904 ex.printStackTrace();
909 public void viewMapping_actionPerformed(ActionEvent actionEvent)
911 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
914 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
916 cap.appendText(jmb.printMapping(jmb.pdbentry[pdbe].getFile()));
917 cap.appendText("\n");
919 } catch (OutOfMemoryError e)
922 "composing sequence-structure alignments for display in text box.",
927 jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
937 public void eps_actionPerformed(ActionEvent e)
939 makePDBImage(jalview.util.ImageMaker.EPS);
948 public void png_actionPerformed(ActionEvent e)
950 makePDBImage(jalview.util.ImageMaker.PNG);
953 void makePDBImage(int type)
955 int width = getWidth();
956 int height = getHeight();
958 jalview.util.ImageMaker im;
960 if (type == jalview.util.ImageMaker.PNG)
962 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
963 "Make PNG image from view", width, height, null, null);
967 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
968 "Make EPS file from view", width, height, null,
972 if (im.getGraphics() != null)
974 Rectangle rect = new Rectangle(width, height);
975 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
980 public void jmolColour_actionPerformed(ActionEvent actionEvent)
982 if (jmolColour.isSelected())
984 // disable automatic sequence colouring.
985 jmb.setColourBySequence(false);
989 public void seqColour_actionPerformed(ActionEvent actionEvent)
991 jmb.setColourBySequence(seqColour.isSelected());
992 if (_colourwith == null)
994 _colourwith = new Vector<AlignmentPanel>();
996 if (jmb.isColourBySequence())
998 if (!jmb.isLoadingFromArchive())
1000 if (_colourwith.size() == 0 && ap != null)
1002 // Make the currently displayed alignment panel the associated view
1003 _colourwith.add(ap.alignFrame.alignPanel);
1006 // Set the colour using the current view for the associated alignframe
1007 for (AlignmentPanel ap : _colourwith)
1009 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
1014 public void chainColour_actionPerformed(ActionEvent actionEvent)
1016 chainColour.setSelected(true);
1017 jmb.colourByChain();
1020 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1022 chargeColour.setSelected(true);
1023 jmb.colourByCharge();
1026 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1028 zappoColour.setSelected(true);
1029 jmb.setJalviewColourScheme(new ZappoColourScheme());
1032 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1034 taylorColour.setSelected(true);
1035 jmb.setJalviewColourScheme(new TaylorColourScheme());
1038 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1040 hydroColour.setSelected(true);
1041 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1044 public void helixColour_actionPerformed(ActionEvent actionEvent)
1046 helixColour.setSelected(true);
1047 jmb.setJalviewColourScheme(new HelixColourScheme());
1050 public void strandColour_actionPerformed(ActionEvent actionEvent)
1052 strandColour.setSelected(true);
1053 jmb.setJalviewColourScheme(new StrandColourScheme());
1056 public void turnColour_actionPerformed(ActionEvent actionEvent)
1058 turnColour.setSelected(true);
1059 jmb.setJalviewColourScheme(new TurnColourScheme());
1062 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1064 buriedColour.setSelected(true);
1065 jmb.setJalviewColourScheme(new BuriedColourScheme());
1068 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1070 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1073 public void userColour_actionPerformed(ActionEvent actionEvent)
1075 userColour.setSelected(true);
1076 new UserDefinedColours(this, null);
1079 public void backGround_actionPerformed(ActionEvent actionEvent)
1081 java.awt.Color col = JColorChooser.showDialog(this,
1082 "Select Background Colour", null);
1085 jmb.setBackgroundColour(col);
1089 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1093 jalview.util.BrowserLauncher
1094 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1095 } catch (Exception ex)
1100 public void showConsole(boolean showConsole)
1105 if (splitPane == null)
1107 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1108 splitPane.setTopComponent(renderPanel);
1109 splitPane.setBottomComponent(scriptWindow);
1110 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1111 splitPane.setDividerLocation(getHeight() - 200);
1112 scriptWindow.setVisible(true);
1113 scriptWindow.validate();
1114 splitPane.validate();
1120 if (splitPane != null)
1122 splitPane.setVisible(false);
1127 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1133 class RenderPanel extends JPanel
1135 final Dimension currentSize = new Dimension();
1137 final Rectangle rectClip = new Rectangle();
1139 public void paintComponent(Graphics g)
1141 getSize(currentSize);
1142 g.getClipBounds(rectClip);
1144 if (jmb.fileLoadingError != null)
1146 g.setColor(Color.black);
1147 g.fillRect(0, 0, currentSize.width, currentSize.height);
1148 g.setColor(Color.white);
1149 g.setFont(new Font("Verdana", Font.BOLD, 14));
1150 g.drawString("Error loading file...", 20, currentSize.height / 2);
1151 StringBuffer sb = new StringBuffer();
1153 for (int e = 0; e < jmb.pdbentry.length; e++)
1155 sb.append(jmb.pdbentry[e].getId());
1156 if (e < jmb.pdbentry.length - 1)
1161 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1164 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1165 * g.getFontMetrics().getHeight());
1169 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1171 g.setColor(Color.black);
1172 g.fillRect(0, 0, currentSize.width, currentSize.height);
1173 g.setColor(Color.white);
1174 g.setFont(new Font("Verdana", Font.BOLD, 14));
1175 g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
1179 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1184 String viewId = null;
1186 public String getViewId()
1190 viewId = System.currentTimeMillis() + "." + this.hashCode();
1195 public void updateTitleAndMenus()
1197 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1202 setChainMenuItems(jmb.chainNames);
1204 this.setTitle(jmb.getViewerTitle());
1205 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1207 jmolActionMenu.setVisible(true);
1209 if (!jmb.isLoadingFromArchive())
1211 seqColour_actionPerformed(null);
1215 protected void buildJmolActionMenu()
1217 if (_alignwith == null)
1219 _alignwith = new Vector<AlignmentPanel>();
1221 if (_alignwith.size() == 0 && ap != null)
1226 for (Component c : jmolActionMenu.getMenuComponents())
1228 if (c != alignStructs)
1230 jmolActionMenu.remove((JMenuItem) c);
1233 final ItemListener handler;
1240 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1244 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1246 alignStructs_withAllAlignPanels();
1249 private void alignStructs_withAllAlignPanels()
1256 if (_alignwith.size() == 0)
1263 AlignmentI[] als = new Alignment[_alignwith.size()];
1264 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1265 int[] alm = new int[_alignwith.size()];
1268 for (AlignmentPanel ap : _alignwith)
1270 als[a] = ap.av.getAlignment();
1272 alc[a++] = ap.av.getColumnSelection();
1274 jmb.superposeStructures(als, alm, alc);
1275 } catch (Exception e)
1277 StringBuffer sp = new StringBuffer();
1278 for (AlignmentPanel ap : _alignwith)
1280 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1282 Cache.log.info("Couldn't align structures with the " + sp.toString()
1283 + "associated alignment panels.", e);
1289 public void setJalviewColourScheme(ColourSchemeI ucs)
1291 jmb.setJalviewColourScheme(ucs);
1298 * @return first alignment panel displaying given alignment, or the default
1301 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1303 for (AlignmentPanel ap : getAllAlignmentPanels())
1305 if (ap.av.getAlignment() == alignment)
1316 * @return true if this Jmol instance is linked with the given alignPanel
1318 public boolean isLinkedWith(AlignmentPanel ap2)
1320 return _aps.contains(ap2.av.getSequenceSetId());
1323 public boolean isUsedforaligment(AlignmentPanel ap2)
1326 return (_alignwith != null) && _alignwith.contains(ap2);
1329 public boolean isUsedforcolourby(AlignmentPanel ap2)
1331 return (_colourwith != null) && _colourwith.contains(ap2);
1336 * @return TRUE if the view is NOT being coloured by sequence associations.
1338 public boolean isColouredByJmol()
1340 return !jmb.isColourBySequence();