2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, 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.*;
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 handling them
106 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
107 AlignmentPanel ap, boolean usetoColour, boolean useToAlign, boolean leaveColouringToJmol,
108 String loadStatus, Rectangle bounds, String viewid)
110 PDBEntry[] pdbentrys = new PDBEntry[files.length];
111 for (int i = 0; i < pdbentrys.length; i++)
113 PDBEntry pdbentry = new PDBEntry();
114 pdbentry.setFile(files[i]);
115 pdbentry.setId(ids[i]);
116 pdbentrys[i] = pdbentry;
118 // / TODO: check if protocol is needed to be set, and if chains are
120 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), pdbentrys, seqs, null, null);
122 jmb.setLoadingFromArchive(true);
123 addAlignmentPanel(ap);
126 useAlignmentPanelForSuperposition(ap);
128 if (leaveColouringToJmol || !usetoColour)
130 jmb.setColourBySequence(false);
131 seqColour.setSelected(false);
132 jmolColour.setSelected(true);
136 useAlignmentPanelForColourbyseq(ap);
137 jmb.setColourBySequence(true);
138 seqColour.setSelected(true);
139 jmolColour.setSelected(false);
141 this.setBounds(bounds);
144 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
145 // bounds.width,bounds.height);
147 this.addInternalFrameListener(new InternalFrameAdapter()
149 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
154 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
158 private void initMenus()
160 seqColour.setSelected(jmb.isColourBySequence());
161 jmolColour.setSelected(!jmb.isColourBySequence());
162 if (_colourwith==null)
164 _colourwith=new Vector<AlignmentPanel>();
166 if (_alignwith==null)
168 _alignwith=new Vector<AlignmentPanel>();
171 seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith,
176 public void itemStateChanged(ItemEvent e)
178 if (!seqColour.isSelected())
184 // update the jmol display now.
185 seqColour_actionPerformed(null);
189 viewMenu.add(seqColourBy);
190 final ItemListener handler;
191 JMenu alpanels = new ViewSelectionMenu("Superpose with ..", this,
192 _alignwith, handler = new ItemListener()
196 public void itemStateChanged(ItemEvent e)
198 alignStructs.setEnabled(_alignwith.size() > 0);
199 alignStructs.setToolTipText("Align structures using "
200 + _alignwith.size() + " linked alignment views");
203 handler.itemStateChanged(null);
204 jmolActionMenu.add(alpanels);
205 jmolActionMenu.addMenuListener(new MenuListener()
209 public void menuSelected(MenuEvent e)
211 handler.itemStateChanged(null);
215 public void menuDeselected(MenuEvent e)
217 // TODO Auto-generated method stub
222 public void menuCanceled(MenuEvent e)
224 // TODO Auto-generated method stub
229 IProgressIndicator progressBar = null;
232 * add a single PDB structure to a new or existing Jmol view
238 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
239 final AlignmentPanel ap)
241 progressBar = ap.alignFrame;
242 // ////////////////////////////////
243 // Is the pdb file already loaded?
244 String alreadyMapped = ap.getStructureSelectionManager().alreadyMappedToFile(
247 if (alreadyMapped != null)
249 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
250 pdbentry.getId() + " is already displayed."
251 + "\nDo you want to re-use this viewer ?",
252 "Map Sequences to Visible Window: " + pdbentry.getId(),
253 JOptionPane.YES_NO_OPTION);
255 if (option == JOptionPane.YES_OPTION)
257 // TODO : Fix multiple seq to one chain issue here.
258 ap.getStructureSelectionManager().setMapping(seq, chains, alreadyMapped,
259 AppletFormatAdapter.FILE);
260 if (ap.seqPanel.seqCanvas.fr != null)
262 ap.seqPanel.seqCanvas.fr.featuresAdded();
263 ap.paintAlignment(true);
266 // Now this AppJmol is mapped to new sequences. We must add them to
267 // the exisiting array
268 JInternalFrame[] frames = Desktop.instance.getAllFrames();
270 for (int i = 0; i < frames.length; i++)
272 if (frames[i] instanceof AppJmol)
274 final AppJmol topJmol = ((AppJmol) frames[i]);
275 // JBPNOTE: this looks like a binding routine, rather than a gui
277 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
279 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
281 topJmol.jmb.addSequence(pe, seq);
282 topJmol.addAlignmentPanel(ap);
283 // add it to the set used for colouring
284 topJmol.useAlignmentPanelForColourbyseq(ap);
285 topJmol.buildJmolActionMenu();
286 ap.getStructureSelectionManager().sequenceColoursChanged(ap);
296 // /////////////////////////////////
297 // Check if there are other Jmol views involving this alignment
298 // and prompt user about adding this molecule to one of them
299 Vector existingViews = getJmolsFor(ap);
300 if (existingViews.size() > 0)
302 Enumeration jm = existingViews.elements();
303 while (jm.hasMoreElements())
305 AppJmol topJmol = (AppJmol) jm.nextElement();
306 // TODO: highlight topJmol in view somehow
307 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
308 "Do you want to add " + pdbentry.getId()
309 + " to the view called\n'" + topJmol.getTitle()
310 + "'\n", "Align to existing structure view",
311 JOptionPane.YES_NO_OPTION);
312 if (option == JOptionPane.YES_OPTION)
314 topJmol.useAlignmentPanelForSuperposition(ap);
315 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
320 // /////////////////////////////////
321 openNewJmol(ap, new PDBEntry[] { pdbentry }, new SequenceI[][] { seq });
323 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys, SequenceI[][] seqs) {
324 progressBar = ap.alignFrame;
325 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), pdbentrys, seqs, null, null);
326 addAlignmentPanel(ap);
327 useAlignmentPanelForColourbyseq(ap);
328 if (pdbentrys.length>1)
330 alignAddedStructures=true;
331 useAlignmentPanelForSuperposition(ap);
333 jmb.setColourBySequence(true);
334 setSize(400, 400); // probably should be a configurable/dynamic default here
338 addingStructures = false;
339 worker = new Thread(this);
342 this.addInternalFrameListener(new InternalFrameAdapter()
344 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
353 * create a new Jmol containing several structures superimposed using the given alignPanel.
358 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
360 openNewJmol(ap, pe, seqs);
364 * list of sequenceSet ids associated with the view
366 ArrayList<String> _aps = new ArrayList();
368 public AlignmentPanel[] getAllAlignmentPanels()
370 AlignmentPanel[] t, list = new AlignmentPanel[0];
371 for (String setid : _aps)
373 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
376 t = new AlignmentPanel[list.length + panels.length];
377 System.arraycopy(list, 0, t, 0, list.length);
378 System.arraycopy(panels, 0, t, list.length, panels.length);
387 * list of alignment panels to use for superposition
389 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
392 * list of alignment panels that are used for colouring structures by aligned
395 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
398 * set the primary alignmentPanel reference and add another alignPanel to the
399 * list of ones to use for colouring and aligning
403 public void addAlignmentPanel(AlignmentPanel nap)
409 if (!_aps.contains(nap.av.getSequenceSetId()))
411 _aps.add(nap.av.getSequenceSetId());
416 * remove any references held to the given alignment panel
420 public void removeAlignmentPanel(AlignmentPanel nap)
424 _alignwith.remove(nap);
425 _colourwith.remove(nap);
429 for (AlignmentPanel aps : getAllAlignmentPanels())
438 } catch (Exception ex)
443 buildJmolActionMenu();
447 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
449 addAlignmentPanel(nap);
450 if (!_alignwith.contains(nap))
456 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
458 if (_alignwith.contains(nap))
460 _alignwith.remove(nap);
464 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap, boolean enableColourBySeq)
466 useAlignmentPanelForColourbyseq(nap);
467 jmb.setColourBySequence(enableColourBySeq);
468 seqColour.setSelected(enableColourBySeq);
469 jmolColour.setSelected(!enableColourBySeq);
471 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
473 addAlignmentPanel(nap);
474 if (!_colourwith.contains(nap))
476 _colourwith.add(nap);
480 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
482 if (_colourwith.contains(nap))
484 _colourwith.remove(nap);
489 * pdb retrieval thread.
491 private Thread worker = null;
494 * add a new structure (with associated sequences and chains) to this viewer,
495 * retrieving it if necessary first.
502 * if true, new structure(s) will be align using associated alignment
504 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
505 final String[] chains, final boolean b,
506 final IProgressIndicator alignFrame)
508 if (pdbentry.getFile() == null)
510 if (worker != null && worker.isAlive())
512 // a retrieval is in progress, wait around and add ourselves to the
514 new Thread(new Runnable()
518 while (worker != null && worker.isAlive() && _started)
522 Thread.sleep(100 + ((int) Math.random() * 100));
524 } catch (Exception e)
529 // and call ourselves again.
530 addStructure(pdbentry, seq, chains, b, alignFrame);
536 // otherwise, start adding the structure.
537 jmb.addSequenceAndChain(new PDBEntry[]
538 { pdbentry }, new SequenceI[][]
539 { seq }, new String[][]
541 addingStructures = true;
543 alignAddedStructures = b;
544 progressBar = alignFrame; // visual indication happens on caller frame.
545 (worker = new Thread(this)).start();
549 private Vector getJmolsFor(AlignmentPanel ap2)
551 Vector otherJmols = new Vector();
552 // Now this AppJmol is mapped to new sequences. We must add them to
553 // the exisiting array
554 JInternalFrame[] frames = Desktop.instance.getAllFrames();
556 for (int i = 0; i < frames.length; i++)
558 if (frames[i] instanceof AppJmol)
560 AppJmol topJmol = ((AppJmol) frames[i]);
561 if (topJmol.isLinkedWith(ap2))
563 otherJmols.addElement(topJmol);
570 void initJmol(String command)
572 jmb.setFinishedInit(false);
573 renderPanel = new RenderPanel();
574 // TODO: consider waiting until the structure/view is fully loaded before
576 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
577 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
578 getBounds().width, getBounds().height);
579 if (scriptWindow == null)
581 BorderLayout bl = new BorderLayout();
584 scriptWindow = new JPanel(bl);
585 scriptWindow.setVisible(false);
588 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
590 jmb.newJmolPopup(true, "Jmol", true);
595 jmb.evalStateCommand(command);
596 jmb.setFinishedInit(true);
599 void setChainMenuItems(Vector chains)
601 chainMenu.removeAll();
606 JMenuItem menuItem = new JMenuItem("All");
607 menuItem.addActionListener(new ActionListener()
609 public void actionPerformed(ActionEvent evt)
611 allChainsSelected = true;
612 for (int i = 0; i < chainMenu.getItemCount(); i++)
614 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
615 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
618 allChainsSelected = false;
622 chainMenu.add(menuItem);
624 for (int c = 0; c < chains.size(); c++)
626 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
627 menuItem.addItemListener(new ItemListener()
629 public void itemStateChanged(ItemEvent evt)
631 if (!allChainsSelected)
636 chainMenu.add(menuItem);
640 boolean allChainsSelected = false;
642 private boolean alignAddedStructures = false;
646 Vector toshow = new Vector();
648 int mlength, p, mnum;
649 for (int i = 0; i < chainMenu.getItemCount(); i++)
651 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
653 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
654 if (item.isSelected())
656 toshow.addElement(item.getText());
660 jmb.centerViewer(toshow);
670 // TODO: check for memory leaks where instance isn't finalised because jmb
671 // holds a reference to the window
676 * state flag for PDB retrieval thread
678 private boolean _started = false;
684 // todo - record which pdbids were successfuly imported.
685 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
688 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
689 // TODO: replace with reference fetching/transfer code (validate PDBentry
691 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
692 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
694 String file = jmb.pdbentry[pi].getFile();
697 // retrieve the pdb and store it locally
698 AlignmentI pdbseq = null;
699 pdbid = jmb.pdbentry[pi].getId();
700 long hdl = pdbid.hashCode() - System.currentTimeMillis();
701 if (progressBar != null)
703 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
707 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
709 } catch (OutOfMemoryError oomerror)
711 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
712 } catch (Exception ex)
714 ex.printStackTrace();
715 errormsgs.append("'" + pdbid + "'");
717 if (progressBar != null)
719 progressBar.setProgressBar("Finished.", hdl);
723 // just transfer the file name from the first sequence's first
725 jmb.pdbentry[pi].setFile(file = ((PDBEntry) pdbseq
726 .getSequenceAt(0).getPDBId().elementAt(0)).getFile());
728 files.append(" \"" + jalview.util.Platform.escapeString(file) + "\"");
732 errormsgs.append("'" + pdbid + "' ");
737 if (curfiles != null && curfiles.length > 0)
739 addingStructures = true; // already files loaded.
740 for (int c = 0; c < curfiles.length; c++)
742 if (curfiles[c].equals(file))
751 files.append(" \"" + jalview.util.Platform.escapeString(file) + "\"");
755 } catch (OutOfMemoryError oomerror)
757 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
758 } catch (Exception ex)
760 ex.printStackTrace();
761 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
764 if (errormsgs.length() > 0)
767 JOptionPane.showInternalMessageDialog(Desktop.desktop,
768 "The following pdb entries could not be retrieved from the PDB:\n"
769 + errormsgs.toString()
770 + "\nPlease try downloading them manually.",
771 "Couldn't load file", JOptionPane.ERROR_MESSAGE);
774 long lastnotify = jmb.getLoadNotifiesHandled();
775 if (files.length() > 0)
777 if (!addingStructures)
782 initJmol("load FILES " + files.toString());
783 } catch (OutOfMemoryError oomerror)
785 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
786 Cache.log.debug("File locations are " + files);
787 } catch (Exception ex)
789 Cache.log.error("Couldn't open Jmol viewer!", ex);
794 StringBuffer cmd = new StringBuffer();
795 cmd.append("loadingJalviewdata=true\nload APPEND ");
796 cmd.append(files.toString());
797 cmd.append("\nloadingJalviewdata=null");
798 final String command = cmd.toString();
800 lastnotify = jmb.getLoadNotifiesHandled();
804 jmb.evalStateCommand(command);
805 } catch (OutOfMemoryError oomerror)
808 "When trying to add structures to the Jmol viewer!",
810 Cache.log.debug("File locations are " + files);
811 } catch (Exception ex)
813 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
817 // need to wait around until script has finished
818 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
819 : (jmb.isFinishedInit() && jmb.getPdbFile().length!=jmb.pdbentry.length))
823 Cache.log.debug("Waiting around for jmb notify.");
825 } catch (Exception e)
829 // refresh the sequence colours for the new structure(s)
830 for (AlignmentPanel ap : _colourwith)
832 jmb.updateColours(ap);
834 // do superposition if asked to
835 if (alignAddedStructures)
837 javax.swing.SwingUtilities.invokeLater(new Runnable()
841 alignStructs_withAllAlignPanels();
842 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
845 alignAddedStructures = false;
847 addingStructures = false;
854 public void pdbFile_actionPerformed(ActionEvent actionEvent)
856 JalviewFileChooser chooser = new JalviewFileChooser(
857 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
859 chooser.setFileView(new JalviewFileView());
860 chooser.setDialogTitle("Save PDB File");
861 chooser.setToolTipText("Save");
863 int value = chooser.showSaveDialog(this);
865 if (value == JalviewFileChooser.APPROVE_OPTION)
869 // TODO: cope with multiple PDB files in view
870 BufferedReader in = new BufferedReader(new FileReader(
871 jmb.getPdbFile()[0]));
872 File outFile = chooser.getSelectedFile();
874 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
876 while ((data = in.readLine()) != null)
878 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
884 } catch (Exception ex)
886 ex.printStackTrace();
891 public void viewMapping_actionPerformed(ActionEvent actionEvent)
893 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
896 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
898 cap.appendText(jmb.printMapping(
899 jmb.pdbentry[pdbe].getFile()));
900 cap.appendText("\n");
902 } catch (OutOfMemoryError e)
905 "composing sequence-structure alignments for display in text box.",
910 jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
920 public void eps_actionPerformed(ActionEvent e)
922 makePDBImage(jalview.util.ImageMaker.EPS);
931 public void png_actionPerformed(ActionEvent e)
933 makePDBImage(jalview.util.ImageMaker.PNG);
936 void makePDBImage(int type)
938 int width = getWidth();
939 int height = getHeight();
941 jalview.util.ImageMaker im;
943 if (type == jalview.util.ImageMaker.PNG)
945 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
946 "Make PNG image from view", width, height, null, null);
950 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
951 "Make EPS file from view", width, height, null,
955 if (im.getGraphics() != null)
957 Rectangle rect = new Rectangle(width, height);
958 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
962 public void jmolColour_actionPerformed(ActionEvent actionEvent)
964 if (jmolColour.isSelected()) {
965 // disable automatic sequence colouring.
966 jmb.setColourBySequence(false);
969 public void seqColour_actionPerformed(ActionEvent actionEvent)
971 jmb.setColourBySequence(seqColour.isSelected());
972 if (_colourwith == null)
974 _colourwith = new Vector<AlignmentPanel>();
976 if (jmb.isColourBySequence())
978 if (!jmb.isLoadingFromArchive())
980 if (_colourwith.size()==0 && ap!=null) {
981 // Make the currently displayed alignment panel the associated view
982 _colourwith.add(ap.alignFrame.alignPanel);
985 // Set the colour using the current view for the associated alignframe
986 for (AlignmentPanel ap : _colourwith)
988 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
993 public void chainColour_actionPerformed(ActionEvent actionEvent)
995 chainColour.setSelected(true);
999 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1001 chargeColour.setSelected(true);
1002 jmb.colourByCharge();
1005 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1007 zappoColour.setSelected(true);
1008 jmb.setJalviewColourScheme(new ZappoColourScheme());
1011 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1013 taylorColour.setSelected(true);
1014 jmb.setJalviewColourScheme(new TaylorColourScheme());
1017 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1019 hydroColour.setSelected(true);
1020 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1023 public void helixColour_actionPerformed(ActionEvent actionEvent)
1025 helixColour.setSelected(true);
1026 jmb.setJalviewColourScheme(new HelixColourScheme());
1029 public void strandColour_actionPerformed(ActionEvent actionEvent)
1031 strandColour.setSelected(true);
1032 jmb.setJalviewColourScheme(new StrandColourScheme());
1035 public void turnColour_actionPerformed(ActionEvent actionEvent)
1037 turnColour.setSelected(true);
1038 jmb.setJalviewColourScheme(new TurnColourScheme());
1041 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1043 buriedColour.setSelected(true);
1044 jmb.setJalviewColourScheme(new BuriedColourScheme());
1047 public void userColour_actionPerformed(ActionEvent actionEvent)
1049 userColour.setSelected(true);
1050 new UserDefinedColours(this, null);
1053 public void backGround_actionPerformed(ActionEvent actionEvent)
1055 java.awt.Color col = JColorChooser.showDialog(this,
1056 "Select Background Colour", null);
1059 jmb.setBackgroundColour(col);
1063 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1067 jalview.util.BrowserLauncher
1068 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1069 } catch (Exception ex)
1074 public void showConsole(boolean showConsole)
1079 if (splitPane == null)
1081 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1082 splitPane.setTopComponent(renderPanel);
1083 splitPane.setBottomComponent(scriptWindow);
1084 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1085 splitPane.setDividerLocation(getHeight() - 200);
1086 scriptWindow.setVisible(true);
1087 scriptWindow.validate();
1088 splitPane.validate();
1094 if (splitPane != null)
1096 splitPane.setVisible(false);
1101 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1107 class RenderPanel extends JPanel
1109 final Dimension currentSize = new Dimension();
1111 final Rectangle rectClip = new Rectangle();
1113 public void paintComponent(Graphics g)
1115 getSize(currentSize);
1116 g.getClipBounds(rectClip);
1118 if (jmb.fileLoadingError != null)
1120 g.setColor(Color.black);
1121 g.fillRect(0, 0, currentSize.width, currentSize.height);
1122 g.setColor(Color.white);
1123 g.setFont(new Font("Verdana", Font.BOLD, 14));
1124 g.drawString("Error loading file...", 20, currentSize.height / 2);
1125 StringBuffer sb = new StringBuffer();
1127 for (int e = 0; e < jmb.pdbentry.length; e++)
1129 sb.append(jmb.pdbentry[e].getId());
1130 if (e < jmb.pdbentry.length - 1)
1135 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1138 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1139 * g.getFontMetrics().getHeight());
1143 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
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("Retrieving PDB data....", 20, currentSize.height / 2);
1153 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1158 String viewId = null;
1160 public String getViewId()
1164 viewId = System.currentTimeMillis() + "." + this.hashCode();
1169 public void updateTitleAndMenus()
1171 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1176 setChainMenuItems(jmb.chainNames);
1178 this.setTitle(jmb.getViewerTitle());
1179 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1181 jmolActionMenu.setVisible(true);
1183 if (!jmb.isLoadingFromArchive())
1185 seqColour_actionPerformed(null);
1189 protected void buildJmolActionMenu()
1191 if (_alignwith == null)
1193 _alignwith = new Vector<AlignmentPanel>();
1195 if (_alignwith.size() == 0 && ap != null)
1200 for (Component c : jmolActionMenu.getMenuComponents())
1202 if (c != alignStructs)
1204 jmolActionMenu.remove((JMenuItem) c);
1207 final ItemListener handler;
1214 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1218 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1220 alignStructs_withAllAlignPanels();
1223 private void alignStructs_withAllAlignPanels()
1230 if (_alignwith.size() == 0)
1237 AlignmentI[] als = new Alignment[_alignwith.size()];
1238 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1239 int[] alm = new int[_alignwith.size()];
1242 for (AlignmentPanel ap : _alignwith)
1244 als[a] = ap.av.getAlignment();
1246 alc[a++] = ap.av.getColumnSelection();
1248 jmb.superposeStructures(als, alm, alc);
1249 } catch (Exception e)
1251 StringBuffer sp = new StringBuffer();
1252 for (AlignmentPanel ap : _alignwith)
1254 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1256 Cache.log.info("Couldn't align structures with the " + sp.toString()
1257 + "associated alignment panels.", e);
1263 public void setJalviewColourScheme(ColourSchemeI ucs)
1265 jmb.setJalviewColourScheme(ucs);
1272 * @return first alignment panel displaying given alignment, or the default
1275 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1277 for (AlignmentPanel ap : getAllAlignmentPanels())
1279 if (ap.av.getAlignment() == alignment)
1290 * @return true if this Jmol instance is linked with the given alignPanel
1292 public boolean isLinkedWith(AlignmentPanel ap2)
1294 return _aps.contains(ap2.av.getSequenceSetId());
1297 public boolean isUsedforaligment(AlignmentPanel ap2)
1300 return (_alignwith != null) && _alignwith.contains(ap2);
1303 public boolean isUsedforcolourby(AlignmentPanel ap2)
1305 return (_colourwith != null) && _colourwith.contains(ap2);
1310 * @return TRUE if the view is NOT being coloured by sequence associations.
1312 public boolean isColouredByJmol()
1314 return !jmb.isColourBySequence();