2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
27 import javax.swing.event.*;
29 import java.awt.event.*;
32 import jalview.jbgui.GStructureViewer;
33 import jalview.api.SequenceStructureBinding;
34 import jalview.api.structures.JalviewStructureDisplayI;
35 import jalview.bin.Cache;
36 import jalview.datamodel.*;
37 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
38 import jalview.datamodel.PDBEntry;
39 import jalview.ext.jmol.JalviewJmolBinding;
41 import jalview.schemes.*;
42 import jalview.util.MessageManager;
43 import jalview.util.Platform;
45 public class AppJmol extends GStructureViewer implements Runnable,
46 ViewSetProvider, JalviewStructureDisplayI
55 RenderPanel renderPanel;
59 Vector atomsPicked = new Vector();
61 private boolean addingStructures = false;
71 * @deprecated defaults to AppJmol(String[] files, ... , viewid);
73 public AppJmol(String file, String id, SequenceI[] seq,
74 AlignmentPanel ap, String loadStatus, Rectangle bounds)
76 this(file, id, seq, ap, loadStatus, bounds, null);
82 public AppJmol(String file, String id, SequenceI[] seq,
83 AlignmentPanel ap, String loadStatus, Rectangle bounds,
87 { file }, new String[]
88 { id }, new SequenceI[][]
89 { seq }, ap, true, true, false, loadStatus, bounds, viewid);
92 ViewSelectionMenu seqColourBy;
101 * - add the alignment panel to the list used for colouring these
104 * - add the alignment panel to the list used for aligning these
106 * @param leaveColouringToJmol
107 * - do not update the colours from any other source. Jmol is
113 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
114 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
115 boolean leaveColouringToJmol, String loadStatus,
116 Rectangle bounds, String viewid)
118 PDBEntry[] pdbentrys = new PDBEntry[files.length];
119 for (int i = 0; i < pdbentrys.length; i++)
121 PDBEntry pdbentry = new PDBEntry();
122 pdbentry.setFile(files[i]);
123 pdbentry.setId(ids[i]);
124 pdbentrys[i] = pdbentry;
126 // / TODO: check if protocol is needed to be set, and if chains are
128 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
129 pdbentrys, seqs, null, null);
131 jmb.setLoadingFromArchive(true);
132 addAlignmentPanel(ap);
135 useAlignmentPanelForSuperposition(ap);
137 if (leaveColouringToJmol || !usetoColour)
139 jmb.setColourBySequence(false);
140 seqColour.setSelected(false);
141 jmolColour.setSelected(true);
145 useAlignmentPanelForColourbyseq(ap);
146 jmb.setColourBySequence(true);
147 seqColour.setSelected(true);
148 jmolColour.setSelected(false);
150 this.setBounds(bounds);
153 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
154 // bounds.width,bounds.height);
156 this.addInternalFrameListener(new InternalFrameAdapter()
158 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
163 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
167 private void initMenus()
169 seqColour.setSelected(jmb.isColourBySequence());
170 jmolColour.setSelected(!jmb.isColourBySequence());
171 if (_colourwith == null)
173 _colourwith = new Vector<AlignmentPanel>();
175 if (_alignwith == null)
177 _alignwith = new Vector<AlignmentPanel>();
180 seqColourBy = new ViewSelectionMenu(MessageManager.getString("label.colour_by"), this, _colourwith,
185 public void itemStateChanged(ItemEvent e)
187 if (!seqColour.isSelected())
193 // update the jmol display now.
194 seqColour_actionPerformed(null);
198 viewMenu.add(seqColourBy);
199 final ItemListener handler;
200 JMenu alpanels = new ViewSelectionMenu(MessageManager.getString("label.superpose_with"), this,
201 _alignwith, handler = new ItemListener()
205 public void itemStateChanged(ItemEvent e)
207 alignStructs.setEnabled(_alignwith.size() > 0);
208 alignStructs.setToolTipText(MessageManager
210 "label.align_structures_using_linked_alignment_views",
212 { new Integer(_alignwith.size()).toString() }));
215 handler.itemStateChanged(null);
216 jmolActionMenu.add(alpanels);
217 jmolActionMenu.addMenuListener(new MenuListener()
221 public void menuSelected(MenuEvent e)
223 handler.itemStateChanged(null);
227 public void menuDeselected(MenuEvent e)
229 // TODO Auto-generated method stub
234 public void menuCanceled(MenuEvent e)
236 // TODO Auto-generated method stub
242 IProgressIndicator progressBar = null;
245 * add a single PDB structure to a new or existing Jmol view
252 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
253 final AlignmentPanel ap)
255 progressBar = ap.alignFrame;
256 // ////////////////////////////////
257 // Is the pdb file already loaded?
258 String alreadyMapped = ap.getStructureSelectionManager()
259 .alreadyMappedToFile(pdbentry.getId());
261 if (alreadyMapped != null)
263 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
264 MessageManager.formatMessage(
265 "label.pdb_entry_is_already_displayed", new String[]
266 { pdbentry.getId() }), MessageManager.formatMessage(
267 "label.map_sequences_to_visible_window", new String[]
268 { pdbentry.getId() }), JOptionPane.YES_NO_OPTION);
270 if (option == JOptionPane.YES_OPTION)
272 // TODO : Fix multiple seq to one chain issue here.
273 ap.getStructureSelectionManager().setMapping(seq, chains,
274 alreadyMapped, AppletFormatAdapter.FILE);
275 if (ap.seqPanel.seqCanvas.fr != null)
277 ap.seqPanel.seqCanvas.fr.featuresAdded();
278 ap.paintAlignment(true);
281 // Now this AppJmol is mapped to new sequences. We must add them to
282 // the exisiting array
283 JInternalFrame[] frames = Desktop.instance.getAllFrames();
285 for (int i = 0; i < frames.length; i++)
287 if (frames[i] instanceof AppJmol)
289 final AppJmol topJmol = ((AppJmol) frames[i]);
290 // JBPNOTE: this looks like a binding routine, rather than a gui
292 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
294 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
296 topJmol.jmb.addSequence(pe, seq);
297 topJmol.addAlignmentPanel(ap);
298 // add it to the set used for colouring
299 topJmol.useAlignmentPanelForColourbyseq(ap);
300 topJmol.buildJmolActionMenu();
301 ap.getStructureSelectionManager()
302 .sequenceColoursChanged(ap);
312 // /////////////////////////////////
313 // Check if there are other Jmol views involving this alignment
314 // and prompt user about adding this molecule to one of them
315 Vector existingViews = getJmolsFor(ap);
316 if (existingViews.size() > 0)
318 Enumeration jm = existingViews.elements();
319 while (jm.hasMoreElements())
321 AppJmol topJmol = (AppJmol) jm.nextElement();
322 // TODO: highlight topJmol in view somehow
323 int option = JOptionPane
324 .showInternalConfirmDialog(
326 MessageManager.formatMessage(
327 "label.add_pdbentry_to_view", new String[]
328 { pdbentry.getId(), topJmol.getTitle() }),
330 .getString("label.align_to_existing_structure_view"),
331 JOptionPane.YES_NO_OPTION);
332 if (option == JOptionPane.YES_OPTION)
334 topJmol.useAlignmentPanelForSuperposition(ap);
335 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
340 // /////////////////////////////////
341 openNewJmol(ap, new PDBEntry[]
342 { pdbentry }, new SequenceI[][]
346 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
349 progressBar = ap.alignFrame;
350 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
351 pdbentrys, seqs, null, null);
352 addAlignmentPanel(ap);
353 useAlignmentPanelForColourbyseq(ap);
354 if (pdbentrys.length > 1)
356 alignAddedStructures = true;
357 useAlignmentPanelForSuperposition(ap);
359 jmb.setColourBySequence(true);
360 setSize(400, 400); // probably should be a configurable/dynamic default here
364 addingStructures = false;
365 worker = new Thread(this);
368 this.addInternalFrameListener(new InternalFrameAdapter()
370 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
379 * create a new Jmol containing several structures superimposed using the
386 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
388 openNewJmol(ap, pe, seqs);
392 * list of sequenceSet ids associated with the view
394 ArrayList<String> _aps = new ArrayList();
396 public AlignmentPanel[] getAllAlignmentPanels()
398 AlignmentPanel[] t, list = new AlignmentPanel[0];
399 for (String setid : _aps)
401 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
404 t = new AlignmentPanel[list.length + panels.length];
405 System.arraycopy(list, 0, t, 0, list.length);
406 System.arraycopy(panels, 0, t, list.length, panels.length);
415 * list of alignment panels to use for superposition
417 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
420 * list of alignment panels that are used for colouring structures by aligned
423 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
426 * set the primary alignmentPanel reference and add another alignPanel to the
427 * list of ones to use for colouring and aligning
431 public void addAlignmentPanel(AlignmentPanel nap)
437 if (!_aps.contains(nap.av.getSequenceSetId()))
439 _aps.add(nap.av.getSequenceSetId());
444 * remove any references held to the given alignment panel
448 public void removeAlignmentPanel(AlignmentPanel nap)
452 _alignwith.remove(nap);
453 _colourwith.remove(nap);
457 for (AlignmentPanel aps : getAllAlignmentPanels())
466 } catch (Exception ex)
471 buildJmolActionMenu();
475 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
477 addAlignmentPanel(nap);
478 if (!_alignwith.contains(nap))
484 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
486 if (_alignwith.contains(nap))
488 _alignwith.remove(nap);
492 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
493 boolean enableColourBySeq)
495 useAlignmentPanelForColourbyseq(nap);
496 jmb.setColourBySequence(enableColourBySeq);
497 seqColour.setSelected(enableColourBySeq);
498 jmolColour.setSelected(!enableColourBySeq);
501 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
503 addAlignmentPanel(nap);
504 if (!_colourwith.contains(nap))
506 _colourwith.add(nap);
510 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
512 if (_colourwith.contains(nap))
514 _colourwith.remove(nap);
519 * pdb retrieval thread.
521 private Thread worker = null;
524 * add a new structure (with associated sequences and chains) to this viewer,
525 * retrieving it if necessary first.
532 * if true, new structure(s) will be align using associated alignment
534 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
535 final String[] chains, final boolean b,
536 final IProgressIndicator alignFrame)
538 if (pdbentry.getFile() == null)
540 if (worker != null && worker.isAlive())
542 // a retrieval is in progress, wait around and add ourselves to the
544 new Thread(new Runnable()
548 while (worker != null && worker.isAlive() && _started)
552 Thread.sleep(100 + ((int) Math.random() * 100));
554 } catch (Exception e)
559 // and call ourselves again.
560 addStructure(pdbentry, seq, chains, b, alignFrame);
566 // otherwise, start adding the structure.
567 jmb.addSequenceAndChain(new PDBEntry[]
568 { pdbentry }, new SequenceI[][]
569 { seq }, new String[][]
571 addingStructures = true;
573 alignAddedStructures = b;
574 progressBar = alignFrame; // visual indication happens on caller frame.
575 (worker = new Thread(this)).start();
579 private Vector getJmolsFor(AlignmentPanel ap2)
581 Vector otherJmols = new Vector();
582 // Now this AppJmol is mapped to new sequences. We must add them to
583 // the exisiting array
584 JInternalFrame[] frames = Desktop.instance.getAllFrames();
586 for (int i = 0; i < frames.length; i++)
588 if (frames[i] instanceof AppJmol)
590 AppJmol topJmol = ((AppJmol) frames[i]);
591 if (topJmol.isLinkedWith(ap2))
593 otherJmols.addElement(topJmol);
600 void initJmol(String command)
602 jmb.setFinishedInit(false);
603 renderPanel = new RenderPanel();
604 // TODO: consider waiting until the structure/view is fully loaded before
606 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
607 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
608 getBounds().width, getBounds().height);
609 if (scriptWindow == null)
611 BorderLayout bl = new BorderLayout();
614 scriptWindow = new JPanel(bl);
615 scriptWindow.setVisible(false);
618 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
620 jmb.newJmolPopup(true, "Jmol", true);
625 jmb.evalStateCommand(command);
626 jmb.setFinishedInit(true);
629 void setChainMenuItems(Vector chains)
631 chainMenu.removeAll();
636 JMenuItem menuItem = new JMenuItem(
637 MessageManager.getString("label.all"));
638 menuItem.addActionListener(new ActionListener()
640 public void actionPerformed(ActionEvent evt)
642 allChainsSelected = true;
643 for (int i = 0; i < chainMenu.getItemCount(); i++)
645 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
646 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
649 allChainsSelected = false;
653 chainMenu.add(menuItem);
655 for (int c = 0; c < chains.size(); c++)
657 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
658 menuItem.addItemListener(new ItemListener()
660 public void itemStateChanged(ItemEvent evt)
662 if (!allChainsSelected)
667 chainMenu.add(menuItem);
671 boolean allChainsSelected = false;
673 private boolean alignAddedStructures = false;
677 Vector toshow = new Vector();
679 int mlength, p, mnum;
680 for (int i = 0; i < chainMenu.getItemCount(); i++)
682 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
684 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
685 if (item.isSelected())
687 toshow.addElement(item.getText());
691 jmb.centerViewer(toshow);
694 public void closeViewer()
701 // TODO: check for memory leaks where instance isn't finalised because jmb
702 // holds a reference to the window
707 * state flag for PDB retrieval thread
709 private boolean _started = false;
715 // todo - record which pdbids were successfuly imported.
716 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
719 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
720 // TODO: replace with reference fetching/transfer code (validate PDBentry
722 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
723 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
725 String file = jmb.pdbentry[pi].getFile();
728 // retrieve the pdb and store it locally
729 AlignmentI pdbseq = null;
730 pdbid = jmb.pdbentry[pi].getId();
731 long hdl = pdbid.hashCode() - System.currentTimeMillis();
732 if (progressBar != null)
734 progressBar.setProgressBar(MessageManager.formatMessage("status.fetching_pdb", new String[]{pdbid}), hdl);
738 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
740 } catch (OutOfMemoryError oomerror)
742 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
743 } catch (Exception ex)
745 ex.printStackTrace();
746 errormsgs.append("'" + pdbid + "'");
748 if (progressBar != null)
750 progressBar.setProgressBar(MessageManager.getString("label.state_completed"), hdl);
754 // just transfer the file name from the first sequence's first
756 file = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
757 .elementAt(0)).getFile()).getAbsolutePath();
758 jmb.pdbentry[pi].setFile(file);
760 files.append(" \"" + Platform.escapeString(file) + "\"");
764 errormsgs.append("'" + pdbid + "' ");
769 if (curfiles != null && curfiles.length > 0)
771 addingStructures = true; // already files loaded.
772 for (int c = 0; c < curfiles.length; c++)
774 if (curfiles[c].equals(file))
783 files.append(" \"" + Platform.escapeString(file) + "\"");
787 } catch (OutOfMemoryError oomerror)
789 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
790 } catch (Exception ex)
792 ex.printStackTrace();
793 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
796 if (errormsgs.length() > 0)
799 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
800 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
802 { errormsgs.toString() }), MessageManager
803 .getString("label.couldnt_load_file"),
804 JOptionPane.ERROR_MESSAGE);
807 long lastnotify = jmb.getLoadNotifiesHandled();
808 if (files.length() > 0)
810 if (!addingStructures)
815 initJmol("load FILES " + files.toString());
816 } catch (OutOfMemoryError oomerror)
818 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
819 Cache.log.debug("File locations are " + files);
820 } catch (Exception ex)
822 Cache.log.error("Couldn't open Jmol viewer!", ex);
827 StringBuffer cmd = new StringBuffer();
828 cmd.append("loadingJalviewdata=true\nload APPEND ");
829 cmd.append(files.toString());
830 cmd.append("\nloadingJalviewdata=null");
831 final String command = cmd.toString();
833 lastnotify = jmb.getLoadNotifiesHandled();
837 jmb.evalStateCommand(command);
838 } catch (OutOfMemoryError oomerror)
841 "When trying to add structures to the Jmol viewer!",
843 Cache.log.debug("File locations are " + files);
844 } catch (Exception ex)
846 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
850 // need to wait around until script has finished
851 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
852 : (jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb
853 .getPdbFile().length != jmb.pdbentry.length))
857 Cache.log.debug("Waiting around for jmb notify.");
859 } catch (Exception e)
863 // refresh the sequence colours for the new structure(s)
864 for (AlignmentPanel ap : _colourwith)
866 jmb.updateColours(ap);
868 // do superposition if asked to
869 if (alignAddedStructures)
871 javax.swing.SwingUtilities.invokeLater(new Runnable()
875 alignStructs_withAllAlignPanels();
876 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
879 alignAddedStructures = false;
881 addingStructures = false;
888 public void pdbFile_actionPerformed(ActionEvent actionEvent)
890 JalviewFileChooser chooser = new JalviewFileChooser(
891 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
893 chooser.setFileView(new JalviewFileView());
894 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
895 chooser.setToolTipText(MessageManager.getString("action.save"));
897 int value = chooser.showSaveDialog(this);
899 if (value == JalviewFileChooser.APPROVE_OPTION)
903 // TODO: cope with multiple PDB files in view
904 BufferedReader in = new BufferedReader(new FileReader(
905 jmb.getPdbFile()[0]));
906 File outFile = chooser.getSelectedFile();
908 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
910 while ((data = in.readLine()) != null)
912 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
918 } catch (Exception ex)
920 ex.printStackTrace();
925 public void viewMapping_actionPerformed(ActionEvent actionEvent)
927 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
930 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
932 cap.appendText(jmb.printMapping(jmb.pdbentry[pdbe].getFile()));
933 cap.appendText("\n");
935 } catch (OutOfMemoryError e)
938 "composing sequence-structure alignments for display in text box.",
943 jalview.gui.Desktop.addInternalFrame(cap,
944 MessageManager.getString("label.pdb_sequence_mapping"), 550,
954 public void eps_actionPerformed(ActionEvent e)
956 makePDBImage(jalview.util.ImageMaker.EPS);
965 public void png_actionPerformed(ActionEvent e)
967 makePDBImage(jalview.util.ImageMaker.PNG);
970 void makePDBImage(int type)
972 int width = getWidth();
973 int height = getHeight();
975 jalview.util.ImageMaker im;
977 if (type == jalview.util.ImageMaker.PNG)
979 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
980 "Make PNG image from view", width, height, null, null);
984 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
985 "Make EPS file from view", width, height, null,
989 if (im.getGraphics() != null)
991 Rectangle rect = new Rectangle(width, height);
992 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
997 public void jmolColour_actionPerformed(ActionEvent actionEvent)
999 if (jmolColour.isSelected())
1001 // disable automatic sequence colouring.
1002 jmb.setColourBySequence(false);
1006 public void seqColour_actionPerformed(ActionEvent actionEvent)
1008 jmb.setColourBySequence(seqColour.isSelected());
1009 if (_colourwith == null)
1011 _colourwith = new Vector<AlignmentPanel>();
1013 if (jmb.isColourBySequence())
1015 if (!jmb.isLoadingFromArchive())
1017 if (_colourwith.size() == 0 && ap != null)
1019 // Make the currently displayed alignment panel the associated view
1020 _colourwith.add(ap.alignFrame.alignPanel);
1023 // Set the colour using the current view for the associated alignframe
1024 for (AlignmentPanel ap : _colourwith)
1026 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
1031 public void chainColour_actionPerformed(ActionEvent actionEvent)
1033 chainColour.setSelected(true);
1034 jmb.colourByChain();
1037 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1039 chargeColour.setSelected(true);
1040 jmb.colourByCharge();
1043 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1045 zappoColour.setSelected(true);
1046 jmb.setJalviewColourScheme(new ZappoColourScheme());
1049 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1051 taylorColour.setSelected(true);
1052 jmb.setJalviewColourScheme(new TaylorColourScheme());
1055 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1057 hydroColour.setSelected(true);
1058 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1061 public void helixColour_actionPerformed(ActionEvent actionEvent)
1063 helixColour.setSelected(true);
1064 jmb.setJalviewColourScheme(new HelixColourScheme());
1067 public void strandColour_actionPerformed(ActionEvent actionEvent)
1069 strandColour.setSelected(true);
1070 jmb.setJalviewColourScheme(new StrandColourScheme());
1073 public void turnColour_actionPerformed(ActionEvent actionEvent)
1075 turnColour.setSelected(true);
1076 jmb.setJalviewColourScheme(new TurnColourScheme());
1079 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1081 buriedColour.setSelected(true);
1082 jmb.setJalviewColourScheme(new BuriedColourScheme());
1085 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1087 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1090 public void userColour_actionPerformed(ActionEvent actionEvent)
1092 userColour.setSelected(true);
1093 new UserDefinedColours(this, null);
1096 public void backGround_actionPerformed(ActionEvent actionEvent)
1098 java.awt.Color col = JColorChooser.showDialog(this,
1099 MessageManager.getString("label.select_backgroud_colour"), null);
1102 jmb.setBackgroundColour(col);
1106 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1110 jalview.util.BrowserLauncher
1111 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1112 } catch (Exception ex)
1117 public void showConsole(boolean showConsole)
1122 if (splitPane == null)
1124 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1125 splitPane.setTopComponent(renderPanel);
1126 splitPane.setBottomComponent(scriptWindow);
1127 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1128 splitPane.setDividerLocation(getHeight() - 200);
1129 scriptWindow.setVisible(true);
1130 scriptWindow.validate();
1131 splitPane.validate();
1137 if (splitPane != null)
1139 splitPane.setVisible(false);
1144 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1150 class RenderPanel extends JPanel
1152 final Dimension currentSize = new Dimension();
1154 final Rectangle rectClip = new Rectangle();
1156 public void paintComponent(Graphics g)
1158 getSize(currentSize);
1159 g.getClipBounds(rectClip);
1161 if (jmb.fileLoadingError != null)
1163 g.setColor(Color.black);
1164 g.fillRect(0, 0, currentSize.width, currentSize.height);
1165 g.setColor(Color.white);
1166 g.setFont(new Font("Verdana", Font.BOLD, 14));
1167 g.drawString(MessageManager.getString("label.error_loading_file")
1168 + "...", 20, currentSize.height / 2);
1169 StringBuffer sb = new StringBuffer();
1171 for (int e = 0; e < jmb.pdbentry.length; e++)
1173 sb.append(jmb.pdbentry[e].getId());
1174 if (e < jmb.pdbentry.length - 1)
1179 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1182 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1183 * g.getFontMetrics().getHeight());
1187 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1189 g.setColor(Color.black);
1190 g.fillRect(0, 0, currentSize.width, currentSize.height);
1191 g.setColor(Color.white);
1192 g.setFont(new Font("Verdana", Font.BOLD, 14));
1193 g.drawString(MessageManager.getString("label.retrieving_pdb_data"),
1194 20, currentSize.height / 2);
1198 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1203 String viewId = null;
1205 public String getViewId()
1209 viewId = System.currentTimeMillis() + "." + this.hashCode();
1214 public void updateTitleAndMenus()
1216 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1221 setChainMenuItems(jmb.chainNames);
1223 this.setTitle(jmb.getViewerTitle());
1224 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1226 jmolActionMenu.setVisible(true);
1228 if (!jmb.isLoadingFromArchive())
1230 seqColour_actionPerformed(null);
1234 protected void buildJmolActionMenu()
1236 if (_alignwith == null)
1238 _alignwith = new Vector<AlignmentPanel>();
1240 if (_alignwith.size() == 0 && ap != null)
1245 for (Component c : jmolActionMenu.getMenuComponents())
1247 if (c != alignStructs)
1249 jmolActionMenu.remove((JMenuItem) c);
1252 final ItemListener handler;
1259 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1263 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1265 alignStructs_withAllAlignPanels();
1268 private void alignStructs_withAllAlignPanels()
1275 if (_alignwith.size() == 0)
1282 AlignmentI[] als = new Alignment[_alignwith.size()];
1283 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1284 int[] alm = new int[_alignwith.size()];
1287 for (AlignmentPanel ap : _alignwith)
1289 als[a] = ap.av.getAlignment();
1291 alc[a++] = ap.av.getColumnSelection();
1293 jmb.superposeStructures(als, alm, alc);
1294 } catch (Exception e)
1296 StringBuffer sp = new StringBuffer();
1297 for (AlignmentPanel ap : _alignwith)
1299 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1301 Cache.log.info("Couldn't align structures with the " + sp.toString()
1302 + "associated alignment panels.", e);
1308 public void setJalviewColourScheme(ColourSchemeI ucs)
1310 jmb.setJalviewColourScheme(ucs);
1317 * @return first alignment panel displaying given alignment, or the default
1320 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1322 for (AlignmentPanel ap : getAllAlignmentPanels())
1324 if (ap.av.getAlignment() == alignment)
1335 * @return true if this Jmol instance is linked with the given alignPanel
1337 public boolean isLinkedWith(AlignmentPanel ap2)
1339 return _aps.contains(ap2.av.getSequenceSetId());
1342 public boolean isUsedforaligment(AlignmentPanel ap2)
1345 return (_alignwith != null) && _alignwith.contains(ap2);
1348 public boolean isUsedforcolourby(AlignmentPanel ap2)
1350 return (_colourwith != null) && _colourwith.contains(ap2);
1355 * @return TRUE if the view is NOT being coloured by sequence associations.
1357 public boolean isColouredByJmol()
1359 return !jmb.isColourBySequence();
1362 public JalviewJmolBinding getBinding()