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 handling them
107 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
108 AlignmentPanel ap, boolean usetoColour, boolean useToAlign, boolean leaveColouringToJmol,
109 String loadStatus, 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(), pdbentrys, seqs, null, null);
123 jmb.setLoadingFromArchive(true);
124 addAlignmentPanel(ap);
127 useAlignmentPanelForSuperposition(ap);
129 if (leaveColouringToJmol || !usetoColour)
131 jmb.setColourBySequence(false);
132 seqColour.setSelected(false);
133 jmolColour.setSelected(true);
137 useAlignmentPanelForColourbyseq(ap);
138 jmb.setColourBySequence(true);
139 seqColour.setSelected(true);
140 jmolColour.setSelected(false);
142 this.setBounds(bounds);
145 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
146 // bounds.width,bounds.height);
148 this.addInternalFrameListener(new InternalFrameAdapter()
150 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
155 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
159 private void initMenus()
161 seqColour.setSelected(jmb.isColourBySequence());
162 jmolColour.setSelected(!jmb.isColourBySequence());
163 if (_colourwith==null)
165 _colourwith=new Vector<AlignmentPanel>();
167 if (_alignwith==null)
169 _alignwith=new Vector<AlignmentPanel>();
172 seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith,
177 public void itemStateChanged(ItemEvent e)
179 if (!seqColour.isSelected())
185 // update the jmol display now.
186 seqColour_actionPerformed(null);
190 viewMenu.add(seqColourBy);
191 final ItemListener handler;
192 JMenu alpanels = new ViewSelectionMenu("Superpose with ..", this,
193 _alignwith, handler = new ItemListener()
197 public void itemStateChanged(ItemEvent e)
199 alignStructs.setEnabled(_alignwith.size() > 0);
200 alignStructs.setToolTipText("Align structures using "
201 + _alignwith.size() + " linked alignment views");
204 handler.itemStateChanged(null);
205 jmolActionMenu.add(alpanels);
206 jmolActionMenu.addMenuListener(new MenuListener()
210 public void menuSelected(MenuEvent e)
212 handler.itemStateChanged(null);
216 public void menuDeselected(MenuEvent e)
218 // TODO Auto-generated method stub
223 public void menuCanceled(MenuEvent e)
225 // TODO Auto-generated method stub
230 IProgressIndicator progressBar = null;
233 * add a single PDB structure to a new or existing Jmol view
239 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
240 final AlignmentPanel ap)
242 progressBar = ap.alignFrame;
243 // ////////////////////////////////
244 // Is the pdb file already loaded?
245 String alreadyMapped = ap.getStructureSelectionManager().alreadyMappedToFile(
248 if (alreadyMapped != null)
250 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
251 pdbentry.getId() + " is already displayed."
252 + "\nDo you want to re-use this viewer ?",
253 "Map Sequences to Visible Window: " + pdbentry.getId(),
254 JOptionPane.YES_NO_OPTION);
256 if (option == JOptionPane.YES_OPTION)
258 // TODO : Fix multiple seq to one chain issue here.
259 ap.getStructureSelectionManager().setMapping(seq, chains, alreadyMapped,
260 AppletFormatAdapter.FILE);
261 if (ap.seqPanel.seqCanvas.fr != null)
263 ap.seqPanel.seqCanvas.fr.featuresAdded();
264 ap.paintAlignment(true);
267 // Now this AppJmol is mapped to new sequences. We must add them to
268 // the exisiting array
269 JInternalFrame[] frames = Desktop.instance.getAllFrames();
271 for (int i = 0; i < frames.length; i++)
273 if (frames[i] instanceof AppJmol)
275 final AppJmol topJmol = ((AppJmol) frames[i]);
276 // JBPNOTE: this looks like a binding routine, rather than a gui
278 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
280 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
282 topJmol.jmb.addSequence(pe, seq);
283 topJmol.addAlignmentPanel(ap);
284 // add it to the set used for colouring
285 topJmol.useAlignmentPanelForColourbyseq(ap);
286 topJmol.buildJmolActionMenu();
287 ap.getStructureSelectionManager().sequenceColoursChanged(ap);
297 // /////////////////////////////////
298 // Check if there are other Jmol views involving this alignment
299 // and prompt user about adding this molecule to one of them
300 Vector existingViews = getJmolsFor(ap);
301 if (existingViews.size() > 0)
303 Enumeration jm = existingViews.elements();
304 while (jm.hasMoreElements())
306 AppJmol topJmol = (AppJmol) jm.nextElement();
307 // TODO: highlight topJmol in view somehow
308 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
309 "Do you want to add " + pdbentry.getId()
310 + " to the view called\n'" + topJmol.getTitle()
311 + "'\n", "Align to existing structure view",
312 JOptionPane.YES_NO_OPTION);
313 if (option == JOptionPane.YES_OPTION)
315 topJmol.useAlignmentPanelForSuperposition(ap);
316 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
321 // /////////////////////////////////
322 openNewJmol(ap, new PDBEntry[] { pdbentry }, new SequenceI[][] { seq });
324 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys, SequenceI[][] seqs) {
325 progressBar = ap.alignFrame;
326 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), pdbentrys, seqs, null, null);
327 addAlignmentPanel(ap);
328 useAlignmentPanelForColourbyseq(ap);
329 if (pdbentrys.length>1)
331 alignAddedStructures=true;
332 useAlignmentPanelForSuperposition(ap);
334 jmb.setColourBySequence(true);
335 setSize(400, 400); // probably should be a configurable/dynamic default here
339 addingStructures = false;
340 worker = new Thread(this);
343 this.addInternalFrameListener(new InternalFrameAdapter()
345 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
354 * create a new Jmol containing several structures superimposed using the given alignPanel.
359 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
361 openNewJmol(ap, pe, seqs);
365 * list of sequenceSet ids associated with the view
367 ArrayList<String> _aps = new ArrayList();
369 public AlignmentPanel[] getAllAlignmentPanels()
371 AlignmentPanel[] t, list = new AlignmentPanel[0];
372 for (String setid : _aps)
374 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
377 t = new AlignmentPanel[list.length + panels.length];
378 System.arraycopy(list, 0, t, 0, list.length);
379 System.arraycopy(panels, 0, t, list.length, panels.length);
388 * list of alignment panels to use for superposition
390 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
393 * list of alignment panels that are used for colouring structures by aligned
396 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
399 * set the primary alignmentPanel reference and add another alignPanel to the
400 * list of ones to use for colouring and aligning
404 public void addAlignmentPanel(AlignmentPanel nap)
410 if (!_aps.contains(nap.av.getSequenceSetId()))
412 _aps.add(nap.av.getSequenceSetId());
417 * remove any references held to the given alignment panel
421 public void removeAlignmentPanel(AlignmentPanel nap)
425 _alignwith.remove(nap);
426 _colourwith.remove(nap);
430 for (AlignmentPanel aps : getAllAlignmentPanels())
439 } catch (Exception ex)
444 buildJmolActionMenu();
448 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
450 addAlignmentPanel(nap);
451 if (!_alignwith.contains(nap))
457 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
459 if (_alignwith.contains(nap))
461 _alignwith.remove(nap);
465 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap, boolean enableColourBySeq)
467 useAlignmentPanelForColourbyseq(nap);
468 jmb.setColourBySequence(enableColourBySeq);
469 seqColour.setSelected(enableColourBySeq);
470 jmolColour.setSelected(!enableColourBySeq);
472 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
474 addAlignmentPanel(nap);
475 if (!_colourwith.contains(nap))
477 _colourwith.add(nap);
481 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
483 if (_colourwith.contains(nap))
485 _colourwith.remove(nap);
490 * pdb retrieval thread.
492 private Thread worker = null;
495 * add a new structure (with associated sequences and chains) to this viewer,
496 * retrieving it if necessary first.
503 * if true, new structure(s) will be align using associated alignment
505 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
506 final String[] chains, final boolean b,
507 final IProgressIndicator alignFrame)
509 if (pdbentry.getFile() == null)
511 if (worker != null && worker.isAlive())
513 // a retrieval is in progress, wait around and add ourselves to the
515 new Thread(new Runnable()
519 while (worker != null && worker.isAlive() && _started)
523 Thread.sleep(100 + ((int) Math.random() * 100));
525 } catch (Exception e)
530 // and call ourselves again.
531 addStructure(pdbentry, seq, chains, b, alignFrame);
537 // otherwise, start adding the structure.
538 jmb.addSequenceAndChain(new PDBEntry[]
539 { pdbentry }, new SequenceI[][]
540 { seq }, new String[][]
542 addingStructures = true;
544 alignAddedStructures = b;
545 progressBar = alignFrame; // visual indication happens on caller frame.
546 (worker = new Thread(this)).start();
550 private Vector getJmolsFor(AlignmentPanel ap2)
552 Vector otherJmols = new Vector();
553 // Now this AppJmol is mapped to new sequences. We must add them to
554 // the exisiting array
555 JInternalFrame[] frames = Desktop.instance.getAllFrames();
557 for (int i = 0; i < frames.length; i++)
559 if (frames[i] instanceof AppJmol)
561 AppJmol topJmol = ((AppJmol) frames[i]);
562 if (topJmol.isLinkedWith(ap2))
564 otherJmols.addElement(topJmol);
571 void initJmol(String command)
573 jmb.setFinishedInit(false);
574 renderPanel = new RenderPanel();
575 // TODO: consider waiting until the structure/view is fully loaded before
577 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
578 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
579 getBounds().width, getBounds().height);
580 if (scriptWindow == null)
582 BorderLayout bl = new BorderLayout();
585 scriptWindow = new JPanel(bl);
586 scriptWindow.setVisible(false);
589 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
591 jmb.newJmolPopup(true, "Jmol", true);
596 jmb.evalStateCommand(command);
597 jmb.setFinishedInit(true);
600 void setChainMenuItems(Vector chains)
602 chainMenu.removeAll();
607 JMenuItem menuItem = new JMenuItem("All");
608 menuItem.addActionListener(new ActionListener()
610 public void actionPerformed(ActionEvent evt)
612 allChainsSelected = true;
613 for (int i = 0; i < chainMenu.getItemCount(); i++)
615 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
616 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
619 allChainsSelected = false;
623 chainMenu.add(menuItem);
625 for (int c = 0; c < chains.size(); c++)
627 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
628 menuItem.addItemListener(new ItemListener()
630 public void itemStateChanged(ItemEvent evt)
632 if (!allChainsSelected)
637 chainMenu.add(menuItem);
641 boolean allChainsSelected = false;
643 private boolean alignAddedStructures = false;
647 Vector toshow = new Vector();
649 int mlength, p, mnum;
650 for (int i = 0; i < chainMenu.getItemCount(); i++)
652 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
654 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
655 if (item.isSelected())
657 toshow.addElement(item.getText());
661 jmb.centerViewer(toshow);
671 // TODO: check for memory leaks where instance isn't finalised because jmb
672 // holds a reference to the window
677 * state flag for PDB retrieval thread
679 private boolean _started = false;
685 // todo - record which pdbids were successfuly imported.
686 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
689 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
690 // TODO: replace with reference fetching/transfer code (validate PDBentry
692 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
693 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
695 String file = jmb.pdbentry[pi].getFile();
698 // retrieve the pdb and store it locally
699 AlignmentI pdbseq = null;
700 pdbid = jmb.pdbentry[pi].getId();
701 long hdl = pdbid.hashCode() - System.currentTimeMillis();
702 if (progressBar != null)
704 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
708 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
710 } catch (OutOfMemoryError oomerror)
712 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
713 } catch (Exception ex)
715 ex.printStackTrace();
716 errormsgs.append("'" + pdbid + "'");
718 if (progressBar != null)
720 progressBar.setProgressBar("Finished.", hdl);
724 // just transfer the file name from the first sequence's first
726 file = new File(((PDBEntry) pdbseq
727 .getSequenceAt(0).getPDBId().elementAt(0)).getFile()).getAbsolutePath();
728 jmb.pdbentry[pi].setFile(file);
730 files.append(" \"" + Platform.escapeString(file) + "\"");
734 errormsgs.append("'" + pdbid + "' ");
739 if (curfiles != null && curfiles.length > 0)
741 addingStructures = true; // already files loaded.
742 for (int c = 0; c < curfiles.length; c++)
744 if (curfiles[c].equals(file))
753 files.append(" \"" + Platform.escapeString(file) + "\"");
757 } catch (OutOfMemoryError oomerror)
759 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
760 } catch (Exception ex)
762 ex.printStackTrace();
763 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
766 if (errormsgs.length() > 0)
769 JOptionPane.showInternalMessageDialog(Desktop.desktop,
770 "The following pdb entries could not be retrieved from the PDB:\n"
771 + errormsgs.toString()
772 + "\nPlease try downloading them manually.",
773 "Couldn't load file", JOptionPane.ERROR_MESSAGE);
776 long lastnotify = jmb.getLoadNotifiesHandled();
777 if (files.length() > 0)
779 if (!addingStructures)
784 initJmol("load FILES " + files.toString());
785 } catch (OutOfMemoryError oomerror)
787 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
788 Cache.log.debug("File locations are " + files);
789 } catch (Exception ex)
791 Cache.log.error("Couldn't open Jmol viewer!", ex);
796 StringBuffer cmd = new StringBuffer();
797 cmd.append("loadingJalviewdata=true\nload APPEND ");
798 cmd.append(files.toString());
799 cmd.append("\nloadingJalviewdata=null");
800 final String command = cmd.toString();
802 lastnotify = jmb.getLoadNotifiesHandled();
806 jmb.evalStateCommand(command);
807 } catch (OutOfMemoryError oomerror)
810 "When trying to add structures to the Jmol viewer!",
812 Cache.log.debug("File locations are " + files);
813 } catch (Exception ex)
815 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
819 // need to wait around until script has finished
820 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
821 : (jmb.isFinishedInit() && jmb.getPdbFile().length!=jmb.pdbentry.length))
825 Cache.log.debug("Waiting around for jmb notify.");
827 } catch (Exception e)
831 // refresh the sequence colours for the new structure(s)
832 for (AlignmentPanel ap : _colourwith)
834 jmb.updateColours(ap);
836 // do superposition if asked to
837 if (alignAddedStructures)
839 javax.swing.SwingUtilities.invokeLater(new Runnable()
843 alignStructs_withAllAlignPanels();
844 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
847 alignAddedStructures = false;
849 addingStructures = false;
856 public void pdbFile_actionPerformed(ActionEvent actionEvent)
858 JalviewFileChooser chooser = new JalviewFileChooser(
859 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
861 chooser.setFileView(new JalviewFileView());
862 chooser.setDialogTitle("Save PDB File");
863 chooser.setToolTipText("Save");
865 int value = chooser.showSaveDialog(this);
867 if (value == JalviewFileChooser.APPROVE_OPTION)
871 // TODO: cope with multiple PDB files in view
872 BufferedReader in = new BufferedReader(new FileReader(
873 jmb.getPdbFile()[0]));
874 File outFile = chooser.getSelectedFile();
876 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
878 while ((data = in.readLine()) != null)
880 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
886 } catch (Exception ex)
888 ex.printStackTrace();
893 public void viewMapping_actionPerformed(ActionEvent actionEvent)
895 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
898 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
900 cap.appendText(jmb.printMapping(
901 jmb.pdbentry[pdbe].getFile()));
902 cap.appendText("\n");
904 } catch (OutOfMemoryError e)
907 "composing sequence-structure alignments for display in text box.",
912 jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
922 public void eps_actionPerformed(ActionEvent e)
924 makePDBImage(jalview.util.ImageMaker.EPS);
933 public void png_actionPerformed(ActionEvent e)
935 makePDBImage(jalview.util.ImageMaker.PNG);
938 void makePDBImage(int type)
940 int width = getWidth();
941 int height = getHeight();
943 jalview.util.ImageMaker im;
945 if (type == jalview.util.ImageMaker.PNG)
947 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
948 "Make PNG image from view", width, height, null, null);
952 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
953 "Make EPS file from view", width, height, null,
957 if (im.getGraphics() != null)
959 Rectangle rect = new Rectangle(width, height);
960 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
964 public void jmolColour_actionPerformed(ActionEvent actionEvent)
966 if (jmolColour.isSelected()) {
967 // disable automatic sequence colouring.
968 jmb.setColourBySequence(false);
971 public void seqColour_actionPerformed(ActionEvent actionEvent)
973 jmb.setColourBySequence(seqColour.isSelected());
974 if (_colourwith == null)
976 _colourwith = new Vector<AlignmentPanel>();
978 if (jmb.isColourBySequence())
980 if (!jmb.isLoadingFromArchive())
982 if (_colourwith.size()==0 && ap!=null) {
983 // Make the currently displayed alignment panel the associated view
984 _colourwith.add(ap.alignFrame.alignPanel);
987 // Set the colour using the current view for the associated alignframe
988 for (AlignmentPanel ap : _colourwith)
990 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
995 public void chainColour_actionPerformed(ActionEvent actionEvent)
997 chainColour.setSelected(true);
1001 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1003 chargeColour.setSelected(true);
1004 jmb.colourByCharge();
1007 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1009 zappoColour.setSelected(true);
1010 jmb.setJalviewColourScheme(new ZappoColourScheme());
1013 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1015 taylorColour.setSelected(true);
1016 jmb.setJalviewColourScheme(new TaylorColourScheme());
1019 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1021 hydroColour.setSelected(true);
1022 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1025 public void helixColour_actionPerformed(ActionEvent actionEvent)
1027 helixColour.setSelected(true);
1028 jmb.setJalviewColourScheme(new HelixColourScheme());
1031 public void strandColour_actionPerformed(ActionEvent actionEvent)
1033 strandColour.setSelected(true);
1034 jmb.setJalviewColourScheme(new StrandColourScheme());
1037 public void turnColour_actionPerformed(ActionEvent actionEvent)
1039 turnColour.setSelected(true);
1040 jmb.setJalviewColourScheme(new TurnColourScheme());
1043 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1045 buriedColour.setSelected(true);
1046 jmb.setJalviewColourScheme(new BuriedColourScheme());
1049 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1051 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1054 public void userColour_actionPerformed(ActionEvent actionEvent)
1056 userColour.setSelected(true);
1057 new UserDefinedColours(this, null);
1060 public void backGround_actionPerformed(ActionEvent actionEvent)
1062 java.awt.Color col = JColorChooser.showDialog(this,
1063 "Select Background Colour", null);
1066 jmb.setBackgroundColour(col);
1070 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1074 jalview.util.BrowserLauncher
1075 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1076 } catch (Exception ex)
1081 public void showConsole(boolean showConsole)
1086 if (splitPane == null)
1088 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1089 splitPane.setTopComponent(renderPanel);
1090 splitPane.setBottomComponent(scriptWindow);
1091 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1092 splitPane.setDividerLocation(getHeight() - 200);
1093 scriptWindow.setVisible(true);
1094 scriptWindow.validate();
1095 splitPane.validate();
1101 if (splitPane != null)
1103 splitPane.setVisible(false);
1108 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1114 class RenderPanel extends JPanel
1116 final Dimension currentSize = new Dimension();
1118 final Rectangle rectClip = new Rectangle();
1120 public void paintComponent(Graphics g)
1122 getSize(currentSize);
1123 g.getClipBounds(rectClip);
1125 if (jmb.fileLoadingError != null)
1127 g.setColor(Color.black);
1128 g.fillRect(0, 0, currentSize.width, currentSize.height);
1129 g.setColor(Color.white);
1130 g.setFont(new Font("Verdana", Font.BOLD, 14));
1131 g.drawString("Error loading file...", 20, currentSize.height / 2);
1132 StringBuffer sb = new StringBuffer();
1134 for (int e = 0; e < jmb.pdbentry.length; e++)
1136 sb.append(jmb.pdbentry[e].getId());
1137 if (e < jmb.pdbentry.length - 1)
1142 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1145 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1146 * g.getFontMetrics().getHeight());
1150 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1152 g.setColor(Color.black);
1153 g.fillRect(0, 0, currentSize.width, currentSize.height);
1154 g.setColor(Color.white);
1155 g.setFont(new Font("Verdana", Font.BOLD, 14));
1156 g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
1160 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1165 String viewId = null;
1167 public String getViewId()
1171 viewId = System.currentTimeMillis() + "." + this.hashCode();
1176 public void updateTitleAndMenus()
1178 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1183 setChainMenuItems(jmb.chainNames);
1185 this.setTitle(jmb.getViewerTitle());
1186 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1188 jmolActionMenu.setVisible(true);
1190 if (!jmb.isLoadingFromArchive())
1192 seqColour_actionPerformed(null);
1196 protected void buildJmolActionMenu()
1198 if (_alignwith == null)
1200 _alignwith = new Vector<AlignmentPanel>();
1202 if (_alignwith.size() == 0 && ap != null)
1207 for (Component c : jmolActionMenu.getMenuComponents())
1209 if (c != alignStructs)
1211 jmolActionMenu.remove((JMenuItem) c);
1214 final ItemListener handler;
1221 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1225 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1227 alignStructs_withAllAlignPanels();
1230 private void alignStructs_withAllAlignPanels()
1237 if (_alignwith.size() == 0)
1244 AlignmentI[] als = new Alignment[_alignwith.size()];
1245 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1246 int[] alm = new int[_alignwith.size()];
1249 for (AlignmentPanel ap : _alignwith)
1251 als[a] = ap.av.getAlignment();
1253 alc[a++] = ap.av.getColumnSelection();
1255 jmb.superposeStructures(als, alm, alc);
1256 } catch (Exception e)
1258 StringBuffer sp = new StringBuffer();
1259 for (AlignmentPanel ap : _alignwith)
1261 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1263 Cache.log.info("Couldn't align structures with the " + sp.toString()
1264 + "associated alignment panels.", e);
1270 public void setJalviewColourScheme(ColourSchemeI ucs)
1272 jmb.setJalviewColourScheme(ucs);
1279 * @return first alignment panel displaying given alignment, or the default
1282 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1284 for (AlignmentPanel ap : getAllAlignmentPanels())
1286 if (ap.av.getAlignment() == alignment)
1297 * @return true if this Jmol instance is linked with the given alignPanel
1299 public boolean isLinkedWith(AlignmentPanel ap2)
1301 return _aps.contains(ap2.av.getSequenceSetId());
1304 public boolean isUsedforaligment(AlignmentPanel ap2)
1307 return (_alignwith != null) && _alignwith.contains(ap2);
1310 public boolean isUsedforcolourby(AlignmentPanel ap2)
1312 return (_colourwith != null) && _colourwith.contains(ap2);
1317 * @return TRUE if the view is NOT being coloured by sequence associations.
1319 public boolean isColouredByJmol()
1321 return !jmb.isColourBySequence();