2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 import javax.swing.event.*;
26 import java.awt.event.*;
29 import jalview.jbgui.GStructureViewer;
30 import jalview.api.SequenceStructureBinding;
31 import jalview.bin.Cache;
32 import jalview.datamodel.*;
33 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
34 import jalview.datamodel.PDBEntry;
36 import jalview.schemes.*;
37 import jalview.util.MessageManager;
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 MessageManager.formatMessage("label.pdb_entry_is_already_displayed", new String[]{pdbentry.getId()}),
257 MessageManager.formatMessage("label.map_sequences_to_visible_window", new String[]{pdbentry.getId()}),
258 JOptionPane.YES_NO_OPTION);
260 if (option == JOptionPane.YES_OPTION)
262 // TODO : Fix multiple seq to one chain issue here.
263 ap.getStructureSelectionManager().setMapping(seq, chains,
264 alreadyMapped, AppletFormatAdapter.FILE);
265 if (ap.seqPanel.seqCanvas.fr != null)
267 ap.seqPanel.seqCanvas.fr.featuresAdded();
268 ap.paintAlignment(true);
271 // Now this AppJmol is mapped to new sequences. We must add them to
272 // the exisiting array
273 JInternalFrame[] frames = Desktop.instance.getAllFrames();
275 for (int i = 0; i < frames.length; i++)
277 if (frames[i] instanceof AppJmol)
279 final AppJmol topJmol = ((AppJmol) frames[i]);
280 // JBPNOTE: this looks like a binding routine, rather than a gui
282 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
284 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
286 topJmol.jmb.addSequence(pe, seq);
287 topJmol.addAlignmentPanel(ap);
288 // add it to the set used for colouring
289 topJmol.useAlignmentPanelForColourbyseq(ap);
290 topJmol.buildJmolActionMenu();
291 ap.getStructureSelectionManager()
292 .sequenceColoursChanged(ap);
302 // /////////////////////////////////
303 // Check if there are other Jmol views involving this alignment
304 // and prompt user about adding this molecule to one of them
305 Vector existingViews = getJmolsFor(ap);
306 if (existingViews.size() > 0)
308 Enumeration jm = existingViews.elements();
309 while (jm.hasMoreElements())
311 AppJmol topJmol = (AppJmol) jm.nextElement();
312 // TODO: highlight topJmol in view somehow
313 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
314 MessageManager.formatMessage("label.add_pdbentry_to_view", new String[]{pdbentry.getId(),topJmol.getTitle()}),
315 MessageManager.getString("label.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 MessageManager.formatMessage("label.pdb_entries_couldnt_be_retrieved", new String[]{errormsgs.toString()}),
785 MessageManager.getString("label.couldnt_load_file"), JOptionPane.ERROR_MESSAGE);
788 long lastnotify = jmb.getLoadNotifiesHandled();
789 if (files.length() > 0)
791 if (!addingStructures)
796 initJmol("load FILES " + files.toString());
797 } catch (OutOfMemoryError oomerror)
799 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
800 Cache.log.debug("File locations are " + files);
801 } catch (Exception ex)
803 Cache.log.error("Couldn't open Jmol viewer!", ex);
808 StringBuffer cmd = new StringBuffer();
809 cmd.append("loadingJalviewdata=true\nload APPEND ");
810 cmd.append(files.toString());
811 cmd.append("\nloadingJalviewdata=null");
812 final String command = cmd.toString();
814 lastnotify = jmb.getLoadNotifiesHandled();
818 jmb.evalStateCommand(command);
819 } catch (OutOfMemoryError oomerror)
822 "When trying to add structures to the Jmol viewer!",
824 Cache.log.debug("File locations are " + files);
825 } catch (Exception ex)
827 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
831 // need to wait around until script has finished
832 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
833 : (jmb.isFinishedInit() && jmb.getPdbFile().length != jmb.pdbentry.length))
837 Cache.log.debug("Waiting around for jmb notify.");
839 } catch (Exception e)
843 // refresh the sequence colours for the new structure(s)
844 for (AlignmentPanel ap : _colourwith)
846 jmb.updateColours(ap);
848 // do superposition if asked to
849 if (alignAddedStructures)
851 javax.swing.SwingUtilities.invokeLater(new Runnable()
855 alignStructs_withAllAlignPanels();
856 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
859 alignAddedStructures = false;
861 addingStructures = false;
868 public void pdbFile_actionPerformed(ActionEvent actionEvent)
870 JalviewFileChooser chooser = new JalviewFileChooser(
871 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
873 chooser.setFileView(new JalviewFileView());
874 chooser.setDialogTitle("Save PDB File");
875 chooser.setToolTipText("Save");
877 int value = chooser.showSaveDialog(this);
879 if (value == JalviewFileChooser.APPROVE_OPTION)
883 // TODO: cope with multiple PDB files in view
884 BufferedReader in = new BufferedReader(new FileReader(
885 jmb.getPdbFile()[0]));
886 File outFile = chooser.getSelectedFile();
888 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
890 while ((data = in.readLine()) != null)
892 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
898 } catch (Exception ex)
900 ex.printStackTrace();
905 public void viewMapping_actionPerformed(ActionEvent actionEvent)
907 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
910 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
912 cap.appendText(jmb.printMapping(jmb.pdbentry[pdbe].getFile()));
913 cap.appendText("\n");
915 } catch (OutOfMemoryError e)
918 "composing sequence-structure alignments for display in text box.",
923 jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
933 public void eps_actionPerformed(ActionEvent e)
935 makePDBImage(jalview.util.ImageMaker.EPS);
944 public void png_actionPerformed(ActionEvent e)
946 makePDBImage(jalview.util.ImageMaker.PNG);
949 void makePDBImage(int type)
951 int width = getWidth();
952 int height = getHeight();
954 jalview.util.ImageMaker im;
956 if (type == jalview.util.ImageMaker.PNG)
958 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
959 "Make PNG image from view", width, height, null, null);
963 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
964 "Make EPS file from view", width, height, null,
968 if (im.getGraphics() != null)
970 Rectangle rect = new Rectangle(width, height);
971 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
976 public void jmolColour_actionPerformed(ActionEvent actionEvent)
978 if (jmolColour.isSelected())
980 // disable automatic sequence colouring.
981 jmb.setColourBySequence(false);
985 public void seqColour_actionPerformed(ActionEvent actionEvent)
987 jmb.setColourBySequence(seqColour.isSelected());
988 if (_colourwith == null)
990 _colourwith = new Vector<AlignmentPanel>();
992 if (jmb.isColourBySequence())
994 if (!jmb.isLoadingFromArchive())
996 if (_colourwith.size() == 0 && ap != null)
998 // Make the currently displayed alignment panel the associated view
999 _colourwith.add(ap.alignFrame.alignPanel);
1002 // Set the colour using the current view for the associated alignframe
1003 for (AlignmentPanel ap : _colourwith)
1005 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
1010 public void chainColour_actionPerformed(ActionEvent actionEvent)
1012 chainColour.setSelected(true);
1013 jmb.colourByChain();
1016 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1018 chargeColour.setSelected(true);
1019 jmb.colourByCharge();
1022 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1024 zappoColour.setSelected(true);
1025 jmb.setJalviewColourScheme(new ZappoColourScheme());
1028 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1030 taylorColour.setSelected(true);
1031 jmb.setJalviewColourScheme(new TaylorColourScheme());
1034 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1036 hydroColour.setSelected(true);
1037 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1040 public void helixColour_actionPerformed(ActionEvent actionEvent)
1042 helixColour.setSelected(true);
1043 jmb.setJalviewColourScheme(new HelixColourScheme());
1046 public void strandColour_actionPerformed(ActionEvent actionEvent)
1048 strandColour.setSelected(true);
1049 jmb.setJalviewColourScheme(new StrandColourScheme());
1052 public void turnColour_actionPerformed(ActionEvent actionEvent)
1054 turnColour.setSelected(true);
1055 jmb.setJalviewColourScheme(new TurnColourScheme());
1058 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1060 buriedColour.setSelected(true);
1061 jmb.setJalviewColourScheme(new BuriedColourScheme());
1064 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1066 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1069 public void userColour_actionPerformed(ActionEvent actionEvent)
1071 userColour.setSelected(true);
1072 new UserDefinedColours(this, null);
1075 public void backGround_actionPerformed(ActionEvent actionEvent)
1077 java.awt.Color col = JColorChooser.showDialog(this,
1078 "Select Background Colour", null);
1081 jmb.setBackgroundColour(col);
1085 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1089 jalview.util.BrowserLauncher
1090 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1091 } catch (Exception ex)
1096 public void showConsole(boolean showConsole)
1101 if (splitPane == null)
1103 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1104 splitPane.setTopComponent(renderPanel);
1105 splitPane.setBottomComponent(scriptWindow);
1106 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1107 splitPane.setDividerLocation(getHeight() - 200);
1108 scriptWindow.setVisible(true);
1109 scriptWindow.validate();
1110 splitPane.validate();
1116 if (splitPane != null)
1118 splitPane.setVisible(false);
1123 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1129 class RenderPanel extends JPanel
1131 final Dimension currentSize = new Dimension();
1133 final Rectangle rectClip = new Rectangle();
1135 public void paintComponent(Graphics g)
1137 getSize(currentSize);
1138 g.getClipBounds(rectClip);
1140 if (jmb.fileLoadingError != null)
1142 g.setColor(Color.black);
1143 g.fillRect(0, 0, currentSize.width, currentSize.height);
1144 g.setColor(Color.white);
1145 g.setFont(new Font("Verdana", Font.BOLD, 14));
1146 g.drawString(MessageManager.getString("label.error_loading_file") + "...", 20, currentSize.height / 2);
1147 StringBuffer sb = new StringBuffer();
1149 for (int e = 0; e < jmb.pdbentry.length; e++)
1151 sb.append(jmb.pdbentry[e].getId());
1152 if (e < jmb.pdbentry.length - 1)
1157 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1160 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1161 * g.getFontMetrics().getHeight());
1165 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1167 g.setColor(Color.black);
1168 g.fillRect(0, 0, currentSize.width, currentSize.height);
1169 g.setColor(Color.white);
1170 g.setFont(new Font("Verdana", Font.BOLD, 14));
1171 g.drawString(MessageManager.getString("label.retrieving_pdb_data"), 20, currentSize.height / 2);
1175 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1180 String viewId = null;
1182 public String getViewId()
1186 viewId = System.currentTimeMillis() + "." + this.hashCode();
1191 public void updateTitleAndMenus()
1193 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1198 setChainMenuItems(jmb.chainNames);
1200 this.setTitle(jmb.getViewerTitle());
1201 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1203 jmolActionMenu.setVisible(true);
1205 if (!jmb.isLoadingFromArchive())
1207 seqColour_actionPerformed(null);
1211 protected void buildJmolActionMenu()
1213 if (_alignwith == null)
1215 _alignwith = new Vector<AlignmentPanel>();
1217 if (_alignwith.size() == 0 && ap != null)
1222 for (Component c : jmolActionMenu.getMenuComponents())
1224 if (c != alignStructs)
1226 jmolActionMenu.remove((JMenuItem) c);
1229 final ItemListener handler;
1236 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1240 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1242 alignStructs_withAllAlignPanels();
1245 private void alignStructs_withAllAlignPanels()
1252 if (_alignwith.size() == 0)
1259 AlignmentI[] als = new Alignment[_alignwith.size()];
1260 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1261 int[] alm = new int[_alignwith.size()];
1264 for (AlignmentPanel ap : _alignwith)
1266 als[a] = ap.av.getAlignment();
1268 alc[a++] = ap.av.getColumnSelection();
1270 jmb.superposeStructures(als, alm, alc);
1271 } catch (Exception e)
1273 StringBuffer sp = new StringBuffer();
1274 for (AlignmentPanel ap : _alignwith)
1276 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1278 Cache.log.info("Couldn't align structures with the " + sp.toString()
1279 + "associated alignment panels.", e);
1285 public void setJalviewColourScheme(ColourSchemeI ucs)
1287 jmb.setJalviewColourScheme(ucs);
1294 * @return first alignment panel displaying given alignment, or the default
1297 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1299 for (AlignmentPanel ap : getAllAlignmentPanels())
1301 if (ap.av.getAlignment() == alignment)
1312 * @return true if this Jmol instance is linked with the given alignPanel
1314 public boolean isLinkedWith(AlignmentPanel ap2)
1316 return _aps.contains(ap2.av.getSequenceSetId());
1319 public boolean isUsedforaligment(AlignmentPanel ap2)
1322 return (_alignwith != null) && _alignwith.contains(ap2);
1325 public boolean isUsedforcolourby(AlignmentPanel ap2)
1327 return (_colourwith != null) && _colourwith.contains(ap2);
1332 * @return TRUE if the view is NOT being coloured by sequence associations.
1334 public boolean isColouredByJmol()
1336 return !jmb.isColourBySequence();