2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 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,
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 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 topJmol.buildJmolActionMenu();
293 // /////////////////////////////////
294 // Check if there are other Jmol views involving this alignment
295 // and prompt user about adding this molecule to one of them
296 Vector existingViews = getJmolsFor(ap);
297 if (existingViews.size() > 0)
299 Enumeration jm = existingViews.elements();
300 while (jm.hasMoreElements())
302 AppJmol topJmol = (AppJmol) jm.nextElement();
303 // TODO: highlight topJmol in view somehow
304 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
305 "Do you want to add " + pdbentry.getId()
306 + " to the view called\n'" + topJmol.getTitle()
307 + "'\n", "Align to existing structure view",
308 JOptionPane.YES_NO_OPTION);
309 if (option == JOptionPane.YES_OPTION)
311 topJmol.useAlignmentPanelForSuperposition(ap);
312 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
317 // /////////////////////////////////
318 openNewJmol(ap, new PDBEntry[] { pdbentry }, new SequenceI[][] { seq });
320 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys, SequenceI[][] seqs) {
321 boolean promptUser=pdbentrys.length==1;
322 progressBar = ap.alignFrame;
323 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), pdbentrys, seqs, null, null);
324 addAlignmentPanel(ap);
325 useAlignmentPanelForColourbyseq(ap);
326 if (pdbentrys.length>1)
328 alignAddedStructures=true;
329 useAlignmentPanelForSuperposition(ap);
331 jmb.setColourBySequence(true);
332 setSize(400, 400); // probably should be a configurable/dynamic default here
336 // for (PDBEntry pe: pdbentrys)
338 // if (pe.getFile()==null)
340 addingStructures = false;
341 worker = new Thread(this);
345 // filelist+=" \""+pe.getFile()+"\"";
350 initJmol("load"+(pdbentrys.length>1 ? " APPEND" : "") + filelist);
353 this.addInternalFrameListener(new InternalFrameAdapter()
355 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
364 * create a new Jmol containing several structures superimposed using the given alignPanel.
369 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
371 openNewJmol(ap, pe, seqs);
375 * list of sequenceSet ids associated with the view
377 ArrayList<String> _aps = new ArrayList();
379 public AlignmentPanel[] getAllAlignmentPanels()
381 AlignmentPanel[] t, list = new AlignmentPanel[0];
382 for (String setid : _aps)
384 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
387 t = new AlignmentPanel[list.length + panels.length];
388 System.arraycopy(list, 0, t, 0, list.length);
389 System.arraycopy(panels, 0, t, list.length, panels.length);
398 * list of alignment panels to use for superposition
400 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
403 * list of alignment panels that are used for colouring structures by aligned
406 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
409 * set the primary alignmentPanel reference and add another alignPanel to the
410 * list of ones to use for colouring and aligning
414 public void addAlignmentPanel(AlignmentPanel nap)
420 if (!_aps.contains(nap.av.getSequenceSetId()))
422 _aps.add(nap.av.getSequenceSetId());
427 * remove any references held to the given alignment panel
431 public void removeAlignmentPanel(AlignmentPanel nap)
435 _alignwith.remove(nap);
436 _colourwith.remove(nap);
440 for (AlignmentPanel aps : getAllAlignmentPanels())
449 } catch (Exception ex)
454 buildJmolActionMenu();
458 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
460 addAlignmentPanel(nap);
461 if (!_alignwith.contains(nap))
467 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
469 if (_alignwith.contains(nap))
471 _alignwith.remove(nap);
475 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap, boolean enableColourBySeq)
477 useAlignmentPanelForColourbyseq(nap);
478 jmb.setColourBySequence(enableColourBySeq);
479 seqColour.setSelected(enableColourBySeq);
480 jmolColour.setSelected(!enableColourBySeq);
482 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
484 addAlignmentPanel(nap);
485 if (!_colourwith.contains(nap))
487 _colourwith.add(nap);
491 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
493 if (_colourwith.contains(nap))
495 _colourwith.remove(nap);
500 * pdb retrieval thread.
502 private Thread worker = null;
505 * add a new structure (with associated sequences and chains) to this viewer,
506 * retrieving it if necessary first.
513 * if true, new structure(s) will be align using associated alignment
515 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
516 final String[] chains, final boolean b,
517 final IProgressIndicator alignFrame)
519 if (pdbentry.getFile() == null)
521 if (worker != null && worker.isAlive())
523 // a retrieval is in progress, wait around and add ourselves to the
525 new Thread(new Runnable()
529 while (worker != null && worker.isAlive() && _started)
533 Thread.sleep(100 + ((int) Math.random() * 100));
535 } catch (Exception e)
540 // and call ourselves again.
541 addStructure(pdbentry, seq, chains, b, alignFrame);
547 // otherwise, start adding the structure.
548 jmb.addSequenceAndChain(new PDBEntry[]
549 { pdbentry }, new SequenceI[][]
550 { seq }, new String[][]
552 addingStructures = true;
554 alignAddedStructures = b;
555 progressBar = alignFrame; // visual indication happens on caller frame.
556 (worker = new Thread(this)).start();
560 private Vector getJmolsFor(AlignmentPanel ap2)
562 Vector otherJmols = new Vector();
563 // Now this AppJmol is mapped to new sequences. We must add them to
564 // the exisiting array
565 JInternalFrame[] frames = Desktop.instance.getAllFrames();
567 for (int i = 0; i < frames.length; i++)
569 if (frames[i] instanceof AppJmol)
571 AppJmol topJmol = ((AppJmol) frames[i]);
572 if (topJmol.isLinkedWith(ap2))
574 otherJmols.addElement(topJmol);
581 void initJmol(String command)
583 jmb.setFinishedInit(false);
584 renderPanel = new RenderPanel();
585 // TODO: consider waiting until the structure/view is fully loaded before
587 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
588 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
589 getBounds().width, getBounds().height);
590 if (scriptWindow == null)
592 BorderLayout bl = new BorderLayout();
595 scriptWindow = new JPanel(bl);
596 scriptWindow.setVisible(false);
599 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
601 jmb.newJmolPopup(true, "Jmol", true);
606 jmb.evalStateCommand(command);
607 jmb.setFinishedInit(true);
610 void setChainMenuItems(Vector chains)
612 chainMenu.removeAll();
617 JMenuItem menuItem = new JMenuItem("All");
618 menuItem.addActionListener(new ActionListener()
620 public void actionPerformed(ActionEvent evt)
622 allChainsSelected = true;
623 for (int i = 0; i < chainMenu.getItemCount(); i++)
625 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
626 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
629 allChainsSelected = false;
633 chainMenu.add(menuItem);
635 for (int c = 0; c < chains.size(); c++)
637 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
638 menuItem.addItemListener(new ItemListener()
640 public void itemStateChanged(ItemEvent evt)
642 if (!allChainsSelected)
647 chainMenu.add(menuItem);
651 boolean allChainsSelected = false;
653 private boolean alignAddedStructures = false;
657 Vector toshow = new Vector();
659 int mlength, p, mnum;
660 for (int i = 0; i < chainMenu.getItemCount(); i++)
662 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
664 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
665 if (item.isSelected())
667 toshow.addElement(item.getText());
671 jmb.centerViewer(toshow);
681 // TODO: check for memory leaks where instance isn't finalised because jmb
682 // holds a reference to the window
687 * state flag for PDB retrieval thread
689 private boolean _started = false;
695 // todo - record which pdbids were successfuly imported.
696 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
699 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
700 // TODO: replace with reference fetching/transfer code (validate PDBentry
702 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
703 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
705 String file = jmb.pdbentry[pi].getFile();
708 // retrieve the pdb and store it locally
709 AlignmentI pdbseq = null;
710 pdbid = jmb.pdbentry[pi].getId();
711 long hdl = pdbid.hashCode() - System.currentTimeMillis();
712 if (progressBar != null)
714 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
718 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
720 } catch (OutOfMemoryError oomerror)
722 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
723 } catch (Exception ex)
725 ex.printStackTrace();
726 errormsgs.append("'" + pdbid + "'");
728 if (progressBar != null)
730 progressBar.setProgressBar("Finished.", hdl);
734 // just transfer the file name from the first sequence's first
736 jmb.pdbentry[pi].setFile(file = ((PDBEntry) pdbseq
737 .getSequenceAt(0).getPDBId().elementAt(0)).getFile());
738 files.append(" \"" + file + "\"");
742 errormsgs.append("'" + pdbid + "' ");
747 if (curfiles != null && curfiles.length > 0)
749 addingStructures = true; // already files loaded.
750 for (int c = 0; c < curfiles.length; c++)
752 if (curfiles[c].equals(file))
761 files.append(" \"" + file + "\"");
765 } catch (OutOfMemoryError oomerror)
767 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
768 } catch (Exception ex)
770 ex.printStackTrace();
771 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
774 if (errormsgs.length() > 0)
777 JOptionPane.showInternalMessageDialog(Desktop.desktop,
778 "The following pdb entries could not be retrieved from the PDB:\n"
779 + errormsgs.toString()
780 + "\nPlease try downloading them manually.",
781 "Couldn't load file", JOptionPane.ERROR_MESSAGE);
784 long lastnotify = jmb.getLoadNotifiesHandled();
785 if (files.length() > 0)
787 if (!addingStructures)
792 initJmol("load FILES " + files.toString());
793 } catch (OutOfMemoryError oomerror)
795 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
796 Cache.log.debug("File locations are " + files);
797 } catch (Exception ex)
799 Cache.log.error("Couldn't open Jmol viewer!", ex);
804 StringBuffer cmd = new StringBuffer();
805 cmd.append("loadingJalviewdata=true\nload APPEND ");
806 cmd.append(files.toString());
807 cmd.append("\nloadingJalviewdata=null");
808 final String command = cmd.toString();
810 lastnotify = jmb.getLoadNotifiesHandled();
814 jmb.evalStateCommand(command);
815 } catch (OutOfMemoryError oomerror)
818 "When trying to add structures to the Jmol viewer!",
820 Cache.log.debug("File locations are " + files);
821 } catch (Exception ex)
823 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
827 // need to wait around until script has finished
828 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
829 : (jmb.isFinishedInit() && jmb.getPdbFile().length!=jmb.pdbentry.length))
833 Cache.log.debug("Waiting around for jmb notify.");
835 } catch (Exception e)
839 // refresh the sequence colours for the new structure(s)
840 for (AlignmentPanel ap : _colourwith)
842 jmb.updateColours(ap);
844 // do superposition if asked to
845 if (alignAddedStructures)
847 javax.swing.SwingUtilities.invokeLater(new Runnable()
851 alignStructs_withAllAlignPanels();
852 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
855 alignAddedStructures = false;
857 addingStructures = false;
864 public void pdbFile_actionPerformed(ActionEvent actionEvent)
866 JalviewFileChooser chooser = new JalviewFileChooser(
867 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
869 chooser.setFileView(new JalviewFileView());
870 chooser.setDialogTitle("Save PDB File");
871 chooser.setToolTipText("Save");
873 int value = chooser.showSaveDialog(this);
875 if (value == JalviewFileChooser.APPROVE_OPTION)
879 // TODO: cope with multiple PDB files in view
880 BufferedReader in = new BufferedReader(new FileReader(
881 jmb.getPdbFile()[0]));
882 File outFile = chooser.getSelectedFile();
884 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
886 while ((data = in.readLine()) != null)
888 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
894 } catch (Exception ex)
896 ex.printStackTrace();
901 public void viewMapping_actionPerformed(ActionEvent actionEvent)
903 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
906 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
908 cap.appendText(jmb.printMapping(
909 jmb.pdbentry[pdbe].getFile()));
910 cap.appendText("\n");
912 } catch (OutOfMemoryError e)
915 "composing sequence-structure alignments for display in text box.",
920 jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
930 public void eps_actionPerformed(ActionEvent e)
932 makePDBImage(jalview.util.ImageMaker.EPS);
941 public void png_actionPerformed(ActionEvent e)
943 makePDBImage(jalview.util.ImageMaker.PNG);
946 void makePDBImage(int type)
948 int width = getWidth();
949 int height = getHeight();
951 jalview.util.ImageMaker im;
953 if (type == jalview.util.ImageMaker.PNG)
955 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
956 "Make PNG image from view", width, height, null, null);
960 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
961 "Make EPS file from view", width, height, null,
965 if (im.getGraphics() != null)
967 Rectangle rect = new Rectangle(width, height);
968 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
972 public void jmolColour_actionPerformed(ActionEvent actionEvent)
974 if (jmolColour.isSelected()) {
975 // disable automatic sequence colouring.
976 jmb.setColourBySequence(false);
979 public void seqColour_actionPerformed(ActionEvent actionEvent)
981 jmb.setColourBySequence(seqColour.isSelected());
982 if (_colourwith == null)
984 _colourwith = new Vector<AlignmentPanel>();
986 if (jmb.isColourBySequence())
988 if (!jmb.isLoadingFromArchive())
990 if (_colourwith.size()==0 && ap!=null) {
991 // Make the currently displayed alignment panel the associated view
992 _colourwith.add(ap.alignFrame.alignPanel);
995 // Set the colour using the current view for the associated alignframe
996 for (AlignmentPanel ap : _colourwith)
998 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
1003 public void chainColour_actionPerformed(ActionEvent actionEvent)
1005 chainColour.setSelected(true);
1006 jmb.colourByChain();
1009 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1011 chargeColour.setSelected(true);
1012 jmb.colourByCharge();
1015 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1017 zappoColour.setSelected(true);
1018 jmb.setJalviewColourScheme(new ZappoColourScheme());
1021 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1023 taylorColour.setSelected(true);
1024 jmb.setJalviewColourScheme(new TaylorColourScheme());
1027 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1029 hydroColour.setSelected(true);
1030 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1033 public void helixColour_actionPerformed(ActionEvent actionEvent)
1035 helixColour.setSelected(true);
1036 jmb.setJalviewColourScheme(new HelixColourScheme());
1039 public void strandColour_actionPerformed(ActionEvent actionEvent)
1041 strandColour.setSelected(true);
1042 jmb.setJalviewColourScheme(new StrandColourScheme());
1045 public void turnColour_actionPerformed(ActionEvent actionEvent)
1047 turnColour.setSelected(true);
1048 jmb.setJalviewColourScheme(new TurnColourScheme());
1051 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1053 buriedColour.setSelected(true);
1054 jmb.setJalviewColourScheme(new BuriedColourScheme());
1057 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1059 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1062 public void userColour_actionPerformed(ActionEvent actionEvent)
1064 userColour.setSelected(true);
1065 new UserDefinedColours(this, null);
1068 public void backGround_actionPerformed(ActionEvent actionEvent)
1070 java.awt.Color col = JColorChooser.showDialog(this,
1071 "Select Background Colour", null);
1074 jmb.setBackgroundColour(col);
1078 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1082 jalview.util.BrowserLauncher
1083 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1084 } catch (Exception ex)
1089 public void showConsole(boolean showConsole)
1094 if (splitPane == null)
1096 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1097 splitPane.setTopComponent(renderPanel);
1098 splitPane.setBottomComponent(scriptWindow);
1099 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1100 splitPane.setDividerLocation(getHeight() - 200);
1101 scriptWindow.setVisible(true);
1102 scriptWindow.validate();
1103 splitPane.validate();
1109 if (splitPane != null)
1111 splitPane.setVisible(false);
1116 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1122 class RenderPanel extends JPanel
1124 final Dimension currentSize = new Dimension();
1126 final Rectangle rectClip = new Rectangle();
1128 public void paintComponent(Graphics g)
1130 getSize(currentSize);
1131 g.getClipBounds(rectClip);
1133 if (jmb.fileLoadingError != null)
1135 g.setColor(Color.black);
1136 g.fillRect(0, 0, currentSize.width, currentSize.height);
1137 g.setColor(Color.white);
1138 g.setFont(new Font("Verdana", Font.BOLD, 14));
1139 g.drawString("Error loading file...", 20, currentSize.height / 2);
1140 StringBuffer sb = new StringBuffer();
1142 for (int e = 0; e < jmb.pdbentry.length; e++)
1144 sb.append(jmb.pdbentry[e].getId());
1145 if (e < jmb.pdbentry.length - 1)
1150 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1153 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1154 * g.getFontMetrics().getHeight());
1158 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1160 g.setColor(Color.black);
1161 g.fillRect(0, 0, currentSize.width, currentSize.height);
1162 g.setColor(Color.white);
1163 g.setFont(new Font("Verdana", Font.BOLD, 14));
1164 g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
1168 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1173 String viewId = null;
1175 public String getViewId()
1179 viewId = System.currentTimeMillis() + "." + this.hashCode();
1184 public void updateTitleAndMenus()
1186 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1191 setChainMenuItems(jmb.chainNames);
1193 this.setTitle(jmb.getViewerTitle());
1194 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1196 jmolActionMenu.setVisible(true);
1198 if (!jmb.isLoadingFromArchive())
1200 seqColour_actionPerformed(null);
1204 protected void buildJmolActionMenu()
1206 if (_alignwith == null)
1208 _alignwith = new Vector<AlignmentPanel>();
1210 if (_alignwith.size() == 0 && ap != null)
1215 for (Component c : jmolActionMenu.getMenuComponents())
1217 if (c != alignStructs)
1219 jmolActionMenu.remove((JMenuItem) c);
1222 final ItemListener handler;
1229 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1233 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1235 alignStructs_withAllAlignPanels();
1238 private void alignStructs_withAllAlignPanels()
1245 if (_alignwith.size() == 0)
1252 AlignmentI[] als = new Alignment[_alignwith.size()];
1253 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1254 int[] alm = new int[_alignwith.size()];
1257 for (AlignmentPanel ap : _alignwith)
1259 als[a] = ap.av.getAlignment();
1261 alc[a++] = ap.av.getColumnSelection();
1263 jmb.superposeStructures(als, alm, alc);
1264 } catch (Exception e)
1266 StringBuffer sp = new StringBuffer();
1267 for (AlignmentPanel ap : _alignwith)
1269 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1271 Cache.log.info("Couldn't align structures with the " + sp.toString()
1272 + "associated alignment panels.", e);
1278 public void setJalviewColourScheme(ColourSchemeI ucs)
1280 jmb.setJalviewColourScheme(ucs);
1287 * @return first alignment panel displaying given alignment, or the default
1290 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1292 for (AlignmentPanel ap : getAllAlignmentPanels())
1294 if (ap.av.getAlignment() == alignment)
1305 * @return true if this Jmol instance is linked with the given alignPanel
1307 public boolean isLinkedWith(AlignmentPanel ap2)
1309 return _aps.contains(ap2.av.getSequenceSetId());
1312 public boolean isUsedforaligment(AlignmentPanel ap2)
1315 return (_alignwith != null) && _alignwith.contains(ap2);
1318 public boolean isUsedforcolourby(AlignmentPanel ap2)
1320 return (_colourwith != null) && _colourwith.contains(ap2);
1325 * @return TRUE if the view is NOT being coloured by sequence associations.
1327 public boolean isColouredByJmol()
1329 return !jmb.isColourBySequence();