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.Platform;
39 public class AppJmol extends GStructureViewer implements Runnable,
40 SequenceStructureBinding, ViewSetProvider
49 RenderPanel renderPanel;
53 Vector atomsPicked = new Vector();
55 private boolean addingStructures = false;
65 * @deprecated defaults to AppJmol(String[] files, ... , viewid);
67 public AppJmol(String file, String id, SequenceI[] seq,
68 AlignmentPanel ap, String loadStatus, Rectangle bounds)
70 this(file, id, seq, ap, loadStatus, bounds, null);
76 public AppJmol(String file, String id, SequenceI[] seq,
77 AlignmentPanel ap, String loadStatus, Rectangle bounds,
81 { file }, new String[]
82 { id }, new SequenceI[][]
83 { seq }, ap, true, true, false, loadStatus, bounds, viewid);
86 ViewSelectionMenu seqColourBy;
95 * - add the alignment panel to the list used for colouring these
98 * - add the alignment panel to the list used for aligning these
100 * @param leaveColouringToJmol
101 * - do not update the colours from any other source. Jmol is
107 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
108 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
109 boolean leaveColouringToJmol, String loadStatus,
110 Rectangle bounds, String viewid)
112 PDBEntry[] pdbentrys = new PDBEntry[files.length];
113 for (int i = 0; i < pdbentrys.length; i++)
115 PDBEntry pdbentry = new PDBEntry();
116 pdbentry.setFile(files[i]);
117 pdbentry.setId(ids[i]);
118 pdbentrys[i] = pdbentry;
120 // / TODO: check if protocol is needed to be set, and if chains are
122 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
123 pdbentrys, seqs, null, null);
125 jmb.setLoadingFromArchive(true);
126 addAlignmentPanel(ap);
129 useAlignmentPanelForSuperposition(ap);
131 if (leaveColouringToJmol || !usetoColour)
133 jmb.setColourBySequence(false);
134 seqColour.setSelected(false);
135 jmolColour.setSelected(true);
139 useAlignmentPanelForColourbyseq(ap);
140 jmb.setColourBySequence(true);
141 seqColour.setSelected(true);
142 jmolColour.setSelected(false);
144 this.setBounds(bounds);
147 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
148 // bounds.width,bounds.height);
150 this.addInternalFrameListener(new InternalFrameAdapter()
152 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
157 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
161 private void initMenus()
163 seqColour.setSelected(jmb.isColourBySequence());
164 jmolColour.setSelected(!jmb.isColourBySequence());
165 if (_colourwith == null)
167 _colourwith = new Vector<AlignmentPanel>();
169 if (_alignwith == null)
171 _alignwith = new Vector<AlignmentPanel>();
174 seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith,
179 public void itemStateChanged(ItemEvent e)
181 if (!seqColour.isSelected())
187 // update the jmol display now.
188 seqColour_actionPerformed(null);
192 viewMenu.add(seqColourBy);
193 final ItemListener handler;
194 JMenu alpanels = new ViewSelectionMenu("Superpose with ..", this,
195 _alignwith, handler = new ItemListener()
199 public void itemStateChanged(ItemEvent e)
201 alignStructs.setEnabled(_alignwith.size() > 0);
202 alignStructs.setToolTipText("Align structures using "
203 + _alignwith.size() + " linked alignment views");
206 handler.itemStateChanged(null);
207 jmolActionMenu.add(alpanels);
208 jmolActionMenu.addMenuListener(new MenuListener()
212 public void menuSelected(MenuEvent e)
214 handler.itemStateChanged(null);
218 public void menuDeselected(MenuEvent e)
220 // TODO Auto-generated method stub
225 public void menuCanceled(MenuEvent e)
227 // TODO Auto-generated method stub
233 IProgressIndicator progressBar = null;
236 * add a single PDB structure to a new or existing Jmol view
243 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
244 final AlignmentPanel ap)
246 progressBar = ap.alignFrame;
247 // ////////////////////////////////
248 // Is the pdb file already loaded?
249 String alreadyMapped = ap.getStructureSelectionManager()
250 .alreadyMappedToFile(pdbentry.getId());
252 if (alreadyMapped != null)
254 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
255 pdbentry.getId() + " is already displayed."
256 + "\nDo you want to re-use this viewer ?",
257 "Map Sequences to Visible Window: " + 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 "Do you want to add " + pdbentry.getId()
315 + " to the view called\n'" + topJmol.getTitle()
316 + "'\n", "Align to existing structure view",
317 JOptionPane.YES_NO_OPTION);
318 if (option == JOptionPane.YES_OPTION)
320 topJmol.useAlignmentPanelForSuperposition(ap);
321 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
326 // /////////////////////////////////
327 openNewJmol(ap, new PDBEntry[]
328 { pdbentry }, new SequenceI[][]
332 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
335 progressBar = ap.alignFrame;
336 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
337 pdbentrys, seqs, null, null);
338 addAlignmentPanel(ap);
339 useAlignmentPanelForColourbyseq(ap);
340 if (pdbentrys.length > 1)
342 alignAddedStructures = true;
343 useAlignmentPanelForSuperposition(ap);
345 jmb.setColourBySequence(true);
346 setSize(400, 400); // probably should be a configurable/dynamic default here
350 addingStructures = false;
351 worker = new Thread(this);
354 this.addInternalFrameListener(new InternalFrameAdapter()
356 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
365 * create a new Jmol containing several structures superimposed using the
372 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
374 openNewJmol(ap, pe, seqs);
378 * list of sequenceSet ids associated with the view
380 ArrayList<String> _aps = new ArrayList();
382 public AlignmentPanel[] getAllAlignmentPanels()
384 AlignmentPanel[] t, list = new AlignmentPanel[0];
385 for (String setid : _aps)
387 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
390 t = new AlignmentPanel[list.length + panels.length];
391 System.arraycopy(list, 0, t, 0, list.length);
392 System.arraycopy(panels, 0, t, list.length, panels.length);
401 * list of alignment panels to use for superposition
403 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
406 * list of alignment panels that are used for colouring structures by aligned
409 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
412 * set the primary alignmentPanel reference and add another alignPanel to the
413 * list of ones to use for colouring and aligning
417 public void addAlignmentPanel(AlignmentPanel nap)
423 if (!_aps.contains(nap.av.getSequenceSetId()))
425 _aps.add(nap.av.getSequenceSetId());
430 * remove any references held to the given alignment panel
434 public void removeAlignmentPanel(AlignmentPanel nap)
438 _alignwith.remove(nap);
439 _colourwith.remove(nap);
443 for (AlignmentPanel aps : getAllAlignmentPanels())
452 } catch (Exception ex)
457 buildJmolActionMenu();
461 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
463 addAlignmentPanel(nap);
464 if (!_alignwith.contains(nap))
470 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
472 if (_alignwith.contains(nap))
474 _alignwith.remove(nap);
478 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
479 boolean enableColourBySeq)
481 useAlignmentPanelForColourbyseq(nap);
482 jmb.setColourBySequence(enableColourBySeq);
483 seqColour.setSelected(enableColourBySeq);
484 jmolColour.setSelected(!enableColourBySeq);
487 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
489 addAlignmentPanel(nap);
490 if (!_colourwith.contains(nap))
492 _colourwith.add(nap);
496 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
498 if (_colourwith.contains(nap))
500 _colourwith.remove(nap);
505 * pdb retrieval thread.
507 private Thread worker = null;
510 * add a new structure (with associated sequences and chains) to this viewer,
511 * retrieving it if necessary first.
518 * if true, new structure(s) will be align using associated alignment
520 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
521 final String[] chains, final boolean b,
522 final IProgressIndicator alignFrame)
524 if (pdbentry.getFile() == null)
526 if (worker != null && worker.isAlive())
528 // a retrieval is in progress, wait around and add ourselves to the
530 new Thread(new Runnable()
534 while (worker != null && worker.isAlive() && _started)
538 Thread.sleep(100 + ((int) Math.random() * 100));
540 } catch (Exception e)
545 // and call ourselves again.
546 addStructure(pdbentry, seq, chains, b, alignFrame);
552 // otherwise, start adding the structure.
553 jmb.addSequenceAndChain(new PDBEntry[]
554 { pdbentry }, new SequenceI[][]
555 { seq }, new String[][]
557 addingStructures = true;
559 alignAddedStructures = b;
560 progressBar = alignFrame; // visual indication happens on caller frame.
561 (worker = new Thread(this)).start();
565 private Vector getJmolsFor(AlignmentPanel ap2)
567 Vector otherJmols = new Vector();
568 // Now this AppJmol is mapped to new sequences. We must add them to
569 // the exisiting array
570 JInternalFrame[] frames = Desktop.instance.getAllFrames();
572 for (int i = 0; i < frames.length; i++)
574 if (frames[i] instanceof AppJmol)
576 AppJmol topJmol = ((AppJmol) frames[i]);
577 if (topJmol.isLinkedWith(ap2))
579 otherJmols.addElement(topJmol);
586 void initJmol(String command)
588 jmb.setFinishedInit(false);
589 renderPanel = new RenderPanel();
590 // TODO: consider waiting until the structure/view is fully loaded before
592 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
593 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
594 getBounds().width, getBounds().height);
595 if (scriptWindow == null)
597 BorderLayout bl = new BorderLayout();
600 scriptWindow = new JPanel(bl);
601 scriptWindow.setVisible(false);
604 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
606 jmb.newJmolPopup(true, "Jmol", true);
611 jmb.evalStateCommand(command);
612 jmb.setFinishedInit(true);
615 void setChainMenuItems(Vector chains)
617 chainMenu.removeAll();
622 JMenuItem menuItem = new JMenuItem("All");
623 menuItem.addActionListener(new ActionListener()
625 public void actionPerformed(ActionEvent evt)
627 allChainsSelected = true;
628 for (int i = 0; i < chainMenu.getItemCount(); i++)
630 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
631 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
634 allChainsSelected = false;
638 chainMenu.add(menuItem);
640 for (int c = 0; c < chains.size(); c++)
642 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
643 menuItem.addItemListener(new ItemListener()
645 public void itemStateChanged(ItemEvent evt)
647 if (!allChainsSelected)
652 chainMenu.add(menuItem);
656 boolean allChainsSelected = false;
658 private boolean alignAddedStructures = false;
662 Vector toshow = new Vector();
664 int mlength, p, mnum;
665 for (int i = 0; i < chainMenu.getItemCount(); i++)
667 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
669 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
670 if (item.isSelected())
672 toshow.addElement(item.getText());
676 jmb.centerViewer(toshow);
686 // TODO: check for memory leaks where instance isn't finalised because jmb
687 // holds a reference to the window
692 * state flag for PDB retrieval thread
694 private boolean _started = false;
700 // todo - record which pdbids were successfuly imported.
701 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
704 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
705 // TODO: replace with reference fetching/transfer code (validate PDBentry
707 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
708 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
710 String file = jmb.pdbentry[pi].getFile();
713 // retrieve the pdb and store it locally
714 AlignmentI pdbseq = null;
715 pdbid = jmb.pdbentry[pi].getId();
716 long hdl = pdbid.hashCode() - System.currentTimeMillis();
717 if (progressBar != null)
719 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
723 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
725 } catch (OutOfMemoryError oomerror)
727 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
728 } catch (Exception ex)
730 ex.printStackTrace();
731 errormsgs.append("'" + pdbid + "'");
733 if (progressBar != null)
735 progressBar.setProgressBar("Finished.", hdl);
739 // just transfer the file name from the first sequence's first
741 file = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
742 .elementAt(0)).getFile()).getAbsolutePath();
743 jmb.pdbentry[pi].setFile(file);
745 files.append(" \"" + Platform.escapeString(file) + "\"");
749 errormsgs.append("'" + pdbid + "' ");
754 if (curfiles != null && curfiles.length > 0)
756 addingStructures = true; // already files loaded.
757 for (int c = 0; c < curfiles.length; c++)
759 if (curfiles[c].equals(file))
768 files.append(" \"" + Platform.escapeString(file) + "\"");
772 } catch (OutOfMemoryError oomerror)
774 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
775 } catch (Exception ex)
777 ex.printStackTrace();
778 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
781 if (errormsgs.length() > 0)
784 JOptionPane.showInternalMessageDialog(Desktop.desktop,
785 "The following pdb entries could not be retrieved from the PDB:\n"
786 + errormsgs.toString()
787 + "\nPlease try downloading them manually.",
788 "Couldn't load file", JOptionPane.ERROR_MESSAGE);
791 long lastnotify = jmb.getLoadNotifiesHandled();
792 if (files.length() > 0)
794 if (!addingStructures)
799 initJmol("load FILES " + files.toString());
800 } catch (OutOfMemoryError oomerror)
802 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
803 Cache.log.debug("File locations are " + files);
804 } catch (Exception ex)
806 Cache.log.error("Couldn't open Jmol viewer!", ex);
811 StringBuffer cmd = new StringBuffer();
812 cmd.append("loadingJalviewdata=true\nload APPEND ");
813 cmd.append(files.toString());
814 cmd.append("\nloadingJalviewdata=null");
815 final String command = cmd.toString();
817 lastnotify = jmb.getLoadNotifiesHandled();
821 jmb.evalStateCommand(command);
822 } catch (OutOfMemoryError oomerror)
825 "When trying to add structures to the Jmol viewer!",
827 Cache.log.debug("File locations are " + files);
828 } catch (Exception ex)
830 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
834 // need to wait around until script has finished
835 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
836 : (jmb.isFinishedInit() && jmb.getPdbFile().length != jmb.pdbentry.length))
840 Cache.log.debug("Waiting around for jmb notify.");
842 } catch (Exception e)
846 // refresh the sequence colours for the new structure(s)
847 for (AlignmentPanel ap : _colourwith)
849 jmb.updateColours(ap);
851 // do superposition if asked to
852 if (alignAddedStructures)
854 javax.swing.SwingUtilities.invokeLater(new Runnable()
858 alignStructs_withAllAlignPanels();
859 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
862 alignAddedStructures = false;
864 addingStructures = false;
871 public void pdbFile_actionPerformed(ActionEvent actionEvent)
873 JalviewFileChooser chooser = new JalviewFileChooser(
874 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
876 chooser.setFileView(new JalviewFileView());
877 chooser.setDialogTitle("Save PDB File");
878 chooser.setToolTipText("Save");
880 int value = chooser.showSaveDialog(this);
882 if (value == JalviewFileChooser.APPROVE_OPTION)
886 // TODO: cope with multiple PDB files in view
887 BufferedReader in = new BufferedReader(new FileReader(
888 jmb.getPdbFile()[0]));
889 File outFile = chooser.getSelectedFile();
891 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
893 while ((data = in.readLine()) != null)
895 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
901 } catch (Exception ex)
903 ex.printStackTrace();
908 public void viewMapping_actionPerformed(ActionEvent actionEvent)
910 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
913 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
915 cap.appendText(jmb.printMapping(jmb.pdbentry[pdbe].getFile()));
916 cap.appendText("\n");
918 } catch (OutOfMemoryError e)
921 "composing sequence-structure alignments for display in text box.",
926 jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
936 public void eps_actionPerformed(ActionEvent e)
938 makePDBImage(jalview.util.ImageMaker.EPS);
947 public void png_actionPerformed(ActionEvent e)
949 makePDBImage(jalview.util.ImageMaker.PNG);
952 void makePDBImage(int type)
954 int width = getWidth();
955 int height = getHeight();
957 jalview.util.ImageMaker im;
959 if (type == jalview.util.ImageMaker.PNG)
961 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
962 "Make PNG image from view", width, height, null, null);
966 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
967 "Make EPS file from view", width, height, null,
971 if (im.getGraphics() != null)
973 Rectangle rect = new Rectangle(width, height);
974 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
979 public void jmolColour_actionPerformed(ActionEvent actionEvent)
981 if (jmolColour.isSelected())
983 // disable automatic sequence colouring.
984 jmb.setColourBySequence(false);
988 public void seqColour_actionPerformed(ActionEvent actionEvent)
990 jmb.setColourBySequence(seqColour.isSelected());
991 if (_colourwith == null)
993 _colourwith = new Vector<AlignmentPanel>();
995 if (jmb.isColourBySequence())
997 if (!jmb.isLoadingFromArchive())
999 if (_colourwith.size() == 0 && ap != null)
1001 // Make the currently displayed alignment panel the associated view
1002 _colourwith.add(ap.alignFrame.alignPanel);
1005 // Set the colour using the current view for the associated alignframe
1006 for (AlignmentPanel ap : _colourwith)
1008 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
1013 public void chainColour_actionPerformed(ActionEvent actionEvent)
1015 chainColour.setSelected(true);
1016 jmb.colourByChain();
1019 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1021 chargeColour.setSelected(true);
1022 jmb.colourByCharge();
1025 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1027 zappoColour.setSelected(true);
1028 jmb.setJalviewColourScheme(new ZappoColourScheme());
1031 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1033 taylorColour.setSelected(true);
1034 jmb.setJalviewColourScheme(new TaylorColourScheme());
1037 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1039 hydroColour.setSelected(true);
1040 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1043 public void helixColour_actionPerformed(ActionEvent actionEvent)
1045 helixColour.setSelected(true);
1046 jmb.setJalviewColourScheme(new HelixColourScheme());
1049 public void strandColour_actionPerformed(ActionEvent actionEvent)
1051 strandColour.setSelected(true);
1052 jmb.setJalviewColourScheme(new StrandColourScheme());
1055 public void turnColour_actionPerformed(ActionEvent actionEvent)
1057 turnColour.setSelected(true);
1058 jmb.setJalviewColourScheme(new TurnColourScheme());
1061 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1063 buriedColour.setSelected(true);
1064 jmb.setJalviewColourScheme(new BuriedColourScheme());
1067 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1069 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1072 public void userColour_actionPerformed(ActionEvent actionEvent)
1074 userColour.setSelected(true);
1075 new UserDefinedColours(this, null);
1078 public void backGround_actionPerformed(ActionEvent actionEvent)
1080 java.awt.Color col = JColorChooser.showDialog(this,
1081 "Select Background Colour", null);
1084 jmb.setBackgroundColour(col);
1088 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1092 jalview.util.BrowserLauncher
1093 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1094 } catch (Exception ex)
1099 public void showConsole(boolean showConsole)
1104 if (splitPane == null)
1106 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1107 splitPane.setTopComponent(renderPanel);
1108 splitPane.setBottomComponent(scriptWindow);
1109 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1110 splitPane.setDividerLocation(getHeight() - 200);
1111 scriptWindow.setVisible(true);
1112 scriptWindow.validate();
1113 splitPane.validate();
1119 if (splitPane != null)
1121 splitPane.setVisible(false);
1126 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1132 class RenderPanel extends JPanel
1134 final Dimension currentSize = new Dimension();
1136 final Rectangle rectClip = new Rectangle();
1138 public void paintComponent(Graphics g)
1140 getSize(currentSize);
1141 g.getClipBounds(rectClip);
1143 if (jmb.fileLoadingError != null)
1145 g.setColor(Color.black);
1146 g.fillRect(0, 0, currentSize.width, currentSize.height);
1147 g.setColor(Color.white);
1148 g.setFont(new Font("Verdana", Font.BOLD, 14));
1149 g.drawString("Error loading file...", 20, currentSize.height / 2);
1150 StringBuffer sb = new StringBuffer();
1152 for (int e = 0; e < jmb.pdbentry.length; e++)
1154 sb.append(jmb.pdbentry[e].getId());
1155 if (e < jmb.pdbentry.length - 1)
1160 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1163 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1164 * g.getFontMetrics().getHeight());
1168 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1170 g.setColor(Color.black);
1171 g.fillRect(0, 0, currentSize.width, currentSize.height);
1172 g.setColor(Color.white);
1173 g.setFont(new Font("Verdana", Font.BOLD, 14));
1174 g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
1178 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1183 String viewId = null;
1185 public String getViewId()
1189 viewId = System.currentTimeMillis() + "." + this.hashCode();
1194 public void updateTitleAndMenus()
1196 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1201 setChainMenuItems(jmb.chainNames);
1203 this.setTitle(jmb.getViewerTitle());
1204 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1206 jmolActionMenu.setVisible(true);
1208 if (!jmb.isLoadingFromArchive())
1210 seqColour_actionPerformed(null);
1214 protected void buildJmolActionMenu()
1216 if (_alignwith == null)
1218 _alignwith = new Vector<AlignmentPanel>();
1220 if (_alignwith.size() == 0 && ap != null)
1225 for (Component c : jmolActionMenu.getMenuComponents())
1227 if (c != alignStructs)
1229 jmolActionMenu.remove((JMenuItem) c);
1232 final ItemListener handler;
1239 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1243 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1245 alignStructs_withAllAlignPanels();
1248 private void alignStructs_withAllAlignPanels()
1255 if (_alignwith.size() == 0)
1262 AlignmentI[] als = new Alignment[_alignwith.size()];
1263 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1264 int[] alm = new int[_alignwith.size()];
1267 for (AlignmentPanel ap : _alignwith)
1269 als[a] = ap.av.getAlignment();
1271 alc[a++] = ap.av.getColumnSelection();
1273 jmb.superposeStructures(als, alm, alc);
1274 } catch (Exception e)
1276 StringBuffer sp = new StringBuffer();
1277 for (AlignmentPanel ap : _alignwith)
1279 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1281 Cache.log.info("Couldn't align structures with the " + sp.toString()
1282 + "associated alignment panels.", e);
1288 public void setJalviewColourScheme(ColourSchemeI ucs)
1290 jmb.setJalviewColourScheme(ucs);
1297 * @return first alignment panel displaying given alignment, or the default
1300 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1302 for (AlignmentPanel ap : getAllAlignmentPanels())
1304 if (ap.av.getAlignment() == alignment)
1315 * @return true if this Jmol instance is linked with the given alignPanel
1317 public boolean isLinkedWith(AlignmentPanel ap2)
1319 return _aps.contains(ap2.av.getSequenceSetId());
1322 public boolean isUsedforaligment(AlignmentPanel ap2)
1325 return (_alignwith != null) && _alignwith.contains(ap2);
1328 public boolean isUsedforcolourby(AlignmentPanel ap2)
1330 return (_colourwith != null) && _colourwith.contains(ap2);
1335 * @return TRUE if the view is NOT being coloured by sequence associations.
1337 public boolean isColouredByJmol()
1339 return !jmb.isColourBySequence();