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 ap.getStructureSelectionManager().setMapping(seq, chains, alreadyMapped,
258 AppletFormatAdapter.FILE);
259 if (ap.seqPanel.seqCanvas.fr != null)
261 ap.seqPanel.seqCanvas.fr.featuresAdded();
262 ap.paintAlignment(true);
265 // Now this AppJmol is mapped to new sequences. We must add them to
266 // the exisiting array
267 JInternalFrame[] frames = Desktop.instance.getAllFrames();
269 for (int i = 0; i < frames.length; i++)
271 if (frames[i] instanceof AppJmol)
273 AppJmol topJmol = ((AppJmol) frames[i]);
274 // JBPNOTE: this looks like a binding routine, rather than a gui
276 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
278 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
280 topJmol.jmb.addSequence(pe, seq);
281 topJmol.addAlignmentPanel(ap);
282 topJmol.buildJmolActionMenu();
292 // /////////////////////////////////
293 // Check if there are other Jmol views involving this alignment
294 // and prompt user about adding this molecule to one of them
295 Vector existingViews = getJmolsFor(ap);
296 if (existingViews.size() > 0)
298 Enumeration jm = existingViews.elements();
299 while (jm.hasMoreElements())
301 AppJmol topJmol = (AppJmol) jm.nextElement();
302 // TODO: highlight topJmol in view somehow
303 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
304 "Do you want to add " + pdbentry.getId()
305 + " to the view called\n'" + topJmol.getTitle()
306 + "'\n", "Align to existing structure view",
307 JOptionPane.YES_NO_OPTION);
308 if (option == JOptionPane.YES_OPTION)
310 topJmol.useAlignmentPanelForSuperposition(ap);
311 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
316 // /////////////////////////////////
317 openNewJmol(ap, new PDBEntry[] { pdbentry }, new SequenceI[][] { seq });
319 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys, SequenceI[][] seqs) {
320 boolean promptUser=pdbentrys.length==1;
321 progressBar = ap.alignFrame;
322 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), pdbentrys, seqs, null, null);
323 addAlignmentPanel(ap);
324 useAlignmentPanelForColourbyseq(ap);
325 if (pdbentrys.length>1)
327 alignAddedStructures=true;
328 useAlignmentPanelForSuperposition(ap);
330 jmb.setColourBySequence(true);
331 setSize(400, 400); // probably should be a configurable/dynamic default here
335 // for (PDBEntry pe: pdbentrys)
337 // if (pe.getFile()==null)
339 addingStructures = false;
340 worker = new Thread(this);
344 // filelist+=" \""+pe.getFile()+"\"";
349 initJmol("load"+(pdbentrys.length>1 ? " APPEND" : "") + filelist);
352 this.addInternalFrameListener(new InternalFrameAdapter()
354 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
363 * create a new Jmol containing several structures superimposed using the given alignPanel.
368 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
370 openNewJmol(ap, pe, seqs);
374 * list of sequenceSet ids associated with the view
376 ArrayList<String> _aps = new ArrayList();
378 public AlignmentPanel[] getAllAlignmentPanels()
380 AlignmentPanel[] t, list = new AlignmentPanel[0];
381 for (String setid : _aps)
383 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
386 t = new AlignmentPanel[list.length + panels.length];
387 System.arraycopy(list, 0, t, 0, list.length);
388 System.arraycopy(panels, 0, t, list.length, panels.length);
397 * list of alignment panels to use for superposition
399 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
402 * list of alignment panels that are used for colouring structures by aligned
405 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
408 * set the primary alignmentPanel reference and add another alignPanel to the
409 * list of ones to use for colouring and aligning
413 public void addAlignmentPanel(AlignmentPanel nap)
419 if (!_aps.contains(nap.av.getSequenceSetId()))
421 _aps.add(nap.av.getSequenceSetId());
426 * remove any references held to the given alignment panel
430 public void removeAlignmentPanel(AlignmentPanel nap)
434 _alignwith.remove(nap);
435 _colourwith.remove(nap);
439 for (AlignmentPanel aps : getAllAlignmentPanels())
448 } catch (Exception ex)
453 buildJmolActionMenu();
457 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
459 addAlignmentPanel(nap);
460 if (!_alignwith.contains(nap))
466 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
468 if (_alignwith.contains(nap))
470 _alignwith.remove(nap);
474 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap, boolean enableColourBySeq)
476 useAlignmentPanelForColourbyseq(nap);
477 jmb.setColourBySequence(enableColourBySeq);
478 seqColour.setSelected(enableColourBySeq);
479 jmolColour.setSelected(!enableColourBySeq);
481 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
483 addAlignmentPanel(nap);
484 if (!_colourwith.contains(nap))
486 _colourwith.add(nap);
490 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
492 if (_colourwith.contains(nap))
494 _colourwith.remove(nap);
499 * pdb retrieval thread.
501 private Thread worker = null;
504 * add a new structure (with associated sequences and chains) to this viewer,
505 * retrieving it if necessary first.
512 * if true, new structure(s) will be align using associated alignment
514 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
515 final String[] chains, final boolean b,
516 final IProgressIndicator alignFrame)
518 if (pdbentry.getFile() == null)
520 if (worker != null && worker.isAlive())
522 // a retrieval is in progress, wait around and add ourselves to the
524 new Thread(new Runnable()
528 while (worker != null && worker.isAlive() && _started)
532 Thread.sleep(100 + ((int) Math.random() * 100));
534 } catch (Exception e)
539 // and call ourselves again.
540 addStructure(pdbentry, seq, chains, b, alignFrame);
546 // otherwise, start adding the structure.
547 jmb.addSequenceAndChain(new PDBEntry[]
548 { pdbentry }, new SequenceI[][]
549 { seq }, new String[][]
551 addingStructures = true;
553 alignAddedStructures = b;
554 progressBar = alignFrame; // visual indication happens on caller frame.
555 (worker = new Thread(this)).start();
559 private Vector getJmolsFor(AlignmentPanel ap2)
561 Vector otherJmols = new Vector();
562 // Now this AppJmol is mapped to new sequences. We must add them to
563 // the exisiting array
564 JInternalFrame[] frames = Desktop.instance.getAllFrames();
566 for (int i = 0; i < frames.length; i++)
568 if (frames[i] instanceof AppJmol)
570 AppJmol topJmol = ((AppJmol) frames[i]);
571 if (topJmol.isLinkedWith(ap2))
573 otherJmols.addElement(topJmol);
580 void initJmol(String command)
582 jmb.setFinishedInit(false);
583 renderPanel = new RenderPanel();
584 // TODO: consider waiting until the structure/view is fully loaded before
586 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
587 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
588 getBounds().width, getBounds().height);
589 if (scriptWindow == null)
591 BorderLayout bl = new BorderLayout();
594 scriptWindow = new JPanel(bl);
595 scriptWindow.setVisible(false);
598 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
600 jmb.newJmolPopup(true, "Jmol", true);
605 jmb.evalStateCommand(command);
606 jmb.setFinishedInit(true);
609 void setChainMenuItems(Vector chains)
611 chainMenu.removeAll();
616 JMenuItem menuItem = new JMenuItem("All");
617 menuItem.addActionListener(new ActionListener()
619 public void actionPerformed(ActionEvent evt)
621 allChainsSelected = true;
622 for (int i = 0; i < chainMenu.getItemCount(); i++)
624 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
625 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
628 allChainsSelected = false;
632 chainMenu.add(menuItem);
634 for (int c = 0; c < chains.size(); c++)
636 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
637 menuItem.addItemListener(new ItemListener()
639 public void itemStateChanged(ItemEvent evt)
641 if (!allChainsSelected)
646 chainMenu.add(menuItem);
650 boolean allChainsSelected = false;
652 private boolean alignAddedStructures = false;
656 Vector toshow = new Vector();
658 int mlength, p, mnum;
659 for (int i = 0; i < chainMenu.getItemCount(); i++)
661 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
663 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
664 if (item.isSelected())
666 toshow.addElement(item.getText());
670 jmb.centerViewer(toshow);
680 // TODO: check for memory leaks where instance isn't finalised because jmb
681 // holds a reference to the window
686 * state flag for PDB retrieval thread
688 private boolean _started = false;
694 // todo - record which pdbids were successfuly imported.
695 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
698 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
699 // TODO: replace with reference fetching/transfer code (validate PDBentry
701 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
702 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
704 String file = jmb.pdbentry[pi].getFile();
707 // retrieve the pdb and store it locally
708 AlignmentI pdbseq = null;
709 pdbid = jmb.pdbentry[pi].getId();
710 long hdl = pdbid.hashCode() - System.currentTimeMillis();
711 if (progressBar != null)
713 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
717 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
719 } catch (OutOfMemoryError oomerror)
721 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
722 } catch (Exception ex)
724 ex.printStackTrace();
725 errormsgs.append("'" + pdbid + "'");
727 if (progressBar != null)
729 progressBar.setProgressBar("Finished.", hdl);
733 // just transfer the file name from the first sequence's first
735 jmb.pdbentry[pi].setFile(file = ((PDBEntry) pdbseq
736 .getSequenceAt(0).getPDBId().elementAt(0)).getFile());
737 files.append(" \"" + file + "\"");
741 errormsgs.append("'" + pdbid + "' ");
746 if (curfiles != null && curfiles.length > 0)
748 addingStructures = true; // already files loaded.
749 for (int c = 0; c < curfiles.length; c++)
751 if (curfiles[c].equals(file))
760 files.append(" \"" + file + "\"");
764 } catch (OutOfMemoryError oomerror)
766 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
767 } catch (Exception ex)
769 ex.printStackTrace();
770 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
773 if (errormsgs.length() > 0)
776 JOptionPane.showInternalMessageDialog(Desktop.desktop,
777 "The following pdb entries could not be retrieved from the PDB:\n"
778 + errormsgs.toString()
779 + "\nPlease try downloading them manually.",
780 "Couldn't load file", JOptionPane.ERROR_MESSAGE);
783 long lastnotify = jmb.getLoadNotifiesHandled();
784 if (files.length() > 0)
786 if (!addingStructures)
791 initJmol("load FILES " + files.toString());
792 } catch (OutOfMemoryError oomerror)
794 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
795 Cache.log.debug("File locations are " + files);
796 } catch (Exception ex)
798 Cache.log.error("Couldn't open Jmol viewer!", ex);
803 StringBuffer cmd = new StringBuffer();
804 cmd.append("loadingJalviewdata=true\nload APPEND ");
805 cmd.append(files.toString());
806 cmd.append("\nloadingJalviewdata=null");
807 final String command = cmd.toString();
809 lastnotify = jmb.getLoadNotifiesHandled();
813 jmb.evalStateCommand(command);
814 } catch (OutOfMemoryError oomerror)
817 "When trying to add structures to the Jmol viewer!",
819 Cache.log.debug("File locations are " + files);
820 } catch (Exception ex)
822 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
826 // need to wait around until script has finished
827 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
828 : (jmb.isFinishedInit() && jmb.getPdbFile().length!=jmb.pdbentry.length))
832 Cache.log.debug("Waiting around for jmb notify.");
834 } catch (Exception e)
838 // refresh the sequence colours for the new structure(s)
839 for (AlignmentPanel ap : _colourwith)
841 jmb.updateColours(ap);
843 // do superposition if asked to
844 if (alignAddedStructures)
846 javax.swing.SwingUtilities.invokeLater(new Runnable()
850 alignStructs_withAllAlignPanels();
851 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
854 alignAddedStructures = false;
856 addingStructures = false;
863 public void pdbFile_actionPerformed(ActionEvent actionEvent)
865 JalviewFileChooser chooser = new JalviewFileChooser(
866 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
868 chooser.setFileView(new JalviewFileView());
869 chooser.setDialogTitle("Save PDB File");
870 chooser.setToolTipText("Save");
872 int value = chooser.showSaveDialog(this);
874 if (value == JalviewFileChooser.APPROVE_OPTION)
878 // TODO: cope with multiple PDB files in view
879 BufferedReader in = new BufferedReader(new FileReader(
880 jmb.getPdbFile()[0]));
881 File outFile = chooser.getSelectedFile();
883 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
885 while ((data = in.readLine()) != null)
887 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
893 } catch (Exception ex)
895 ex.printStackTrace();
900 public void viewMapping_actionPerformed(ActionEvent actionEvent)
902 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
905 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
907 cap.appendText(jmb.printMapping(
908 jmb.pdbentry[pdbe].getFile()));
909 cap.appendText("\n");
911 } catch (OutOfMemoryError e)
914 "composing sequence-structure alignments for display in text box.",
919 jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
929 public void eps_actionPerformed(ActionEvent e)
931 makePDBImage(jalview.util.ImageMaker.EPS);
940 public void png_actionPerformed(ActionEvent e)
942 makePDBImage(jalview.util.ImageMaker.PNG);
945 void makePDBImage(int type)
947 int width = getWidth();
948 int height = getHeight();
950 jalview.util.ImageMaker im;
952 if (type == jalview.util.ImageMaker.PNG)
954 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
955 "Make PNG image from view", width, height, null, null);
959 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
960 "Make EPS file from view", width, height, null,
964 if (im.getGraphics() != null)
966 Rectangle rect = new Rectangle(width, height);
967 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
971 public void jmolColour_actionPerformed(ActionEvent actionEvent)
973 if (jmolColour.isSelected()) {
974 // disable automatic sequence colouring.
975 jmb.setColourBySequence(false);
978 public void seqColour_actionPerformed(ActionEvent actionEvent)
980 jmb.setColourBySequence(seqColour.isSelected());
981 if (_colourwith == null)
983 _colourwith = new Vector<AlignmentPanel>();
985 if (jmb.isColourBySequence())
987 if (!jmb.isLoadingFromArchive())
989 if (_colourwith.size()==0 && ap!=null) {
990 // Make the currently displayed alignment panel the associated view
991 _colourwith.add(ap.alignFrame.alignPanel);
994 // Set the colour using the current view for the associated alignframe
995 for (AlignmentPanel ap : _colourwith)
997 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
1002 public void chainColour_actionPerformed(ActionEvent actionEvent)
1004 chainColour.setSelected(true);
1005 jmb.colourByChain();
1008 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1010 chargeColour.setSelected(true);
1011 jmb.colourByCharge();
1014 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1016 zappoColour.setSelected(true);
1017 jmb.setJalviewColourScheme(new ZappoColourScheme());
1020 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1022 taylorColour.setSelected(true);
1023 jmb.setJalviewColourScheme(new TaylorColourScheme());
1026 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1028 hydroColour.setSelected(true);
1029 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1032 public void helixColour_actionPerformed(ActionEvent actionEvent)
1034 helixColour.setSelected(true);
1035 jmb.setJalviewColourScheme(new HelixColourScheme());
1038 public void strandColour_actionPerformed(ActionEvent actionEvent)
1040 strandColour.setSelected(true);
1041 jmb.setJalviewColourScheme(new StrandColourScheme());
1044 public void turnColour_actionPerformed(ActionEvent actionEvent)
1046 turnColour.setSelected(true);
1047 jmb.setJalviewColourScheme(new TurnColourScheme());
1050 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1052 buriedColour.setSelected(true);
1053 jmb.setJalviewColourScheme(new BuriedColourScheme());
1056 public void userColour_actionPerformed(ActionEvent actionEvent)
1058 userColour.setSelected(true);
1059 new UserDefinedColours(this, null);
1062 public void backGround_actionPerformed(ActionEvent actionEvent)
1064 java.awt.Color col = JColorChooser.showDialog(this,
1065 "Select Background Colour", null);
1068 jmb.setBackgroundColour(col);
1072 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1076 jalview.util.BrowserLauncher
1077 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1078 } catch (Exception ex)
1083 public void showConsole(boolean showConsole)
1088 if (splitPane == null)
1090 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1091 splitPane.setTopComponent(renderPanel);
1092 splitPane.setBottomComponent(scriptWindow);
1093 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1094 splitPane.setDividerLocation(getHeight() - 200);
1095 scriptWindow.setVisible(true);
1096 scriptWindow.validate();
1097 splitPane.validate();
1103 if (splitPane != null)
1105 splitPane.setVisible(false);
1110 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1116 class RenderPanel extends JPanel
1118 final Dimension currentSize = new Dimension();
1120 final Rectangle rectClip = new Rectangle();
1122 public void paintComponent(Graphics g)
1124 getSize(currentSize);
1125 g.getClipBounds(rectClip);
1127 if (jmb.fileLoadingError != null)
1129 g.setColor(Color.black);
1130 g.fillRect(0, 0, currentSize.width, currentSize.height);
1131 g.setColor(Color.white);
1132 g.setFont(new Font("Verdana", Font.BOLD, 14));
1133 g.drawString("Error loading file...", 20, currentSize.height / 2);
1134 StringBuffer sb = new StringBuffer();
1136 for (int e = 0; e < jmb.pdbentry.length; e++)
1138 sb.append(jmb.pdbentry[e].getId());
1139 if (e < jmb.pdbentry.length - 1)
1144 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1147 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1148 * g.getFontMetrics().getHeight());
1152 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1154 g.setColor(Color.black);
1155 g.fillRect(0, 0, currentSize.width, currentSize.height);
1156 g.setColor(Color.white);
1157 g.setFont(new Font("Verdana", Font.BOLD, 14));
1158 g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
1162 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1167 String viewId = null;
1169 public String getViewId()
1173 viewId = System.currentTimeMillis() + "." + this.hashCode();
1178 public void updateTitleAndMenus()
1180 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1185 setChainMenuItems(jmb.chainNames);
1187 this.setTitle(jmb.getViewerTitle());
1188 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1190 jmolActionMenu.setVisible(true);
1192 if (!jmb.isLoadingFromArchive())
1194 seqColour_actionPerformed(null);
1198 protected void buildJmolActionMenu()
1200 if (_alignwith == null)
1202 _alignwith = new Vector<AlignmentPanel>();
1204 if (_alignwith.size() == 0 && ap != null)
1209 for (Component c : jmolActionMenu.getMenuComponents())
1211 if (c != alignStructs)
1213 jmolActionMenu.remove((JMenuItem) c);
1216 final ItemListener handler;
1223 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1227 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1229 alignStructs_withAllAlignPanels();
1232 private void alignStructs_withAllAlignPanels()
1239 if (_alignwith.size() == 0)
1246 AlignmentI[] als = new Alignment[_alignwith.size()];
1247 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1248 int[] alm = new int[_alignwith.size()];
1251 for (AlignmentPanel ap : _alignwith)
1253 als[a] = ap.av.getAlignment();
1255 alc[a++] = ap.av.getColumnSelection();
1257 jmb.superposeStructures(als, alm, alc);
1258 } catch (Exception e)
1260 StringBuffer sp = new StringBuffer();
1261 for (AlignmentPanel ap : _alignwith)
1263 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1265 Cache.log.info("Couldn't align structures with the " + sp.toString()
1266 + "associated alignment panels.", e);
1272 public void setJalviewColourScheme(ColourSchemeI ucs)
1274 jmb.setJalviewColourScheme(ucs);
1281 * @return first alignment panel displaying given alignment, or the default
1284 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1286 for (AlignmentPanel ap : getAllAlignmentPanels())
1288 if (ap.av.getAlignment() == alignment)
1299 * @return true if this Jmol instance is linked with the given alignPanel
1301 public boolean isLinkedWith(AlignmentPanel ap2)
1303 return _aps.contains(ap2.av.getSequenceSetId());
1306 public boolean isUsedforaligment(AlignmentPanel ap2)
1309 return (_alignwith != null) && _alignwith.contains(ap2);
1312 public boolean isUsedforcolourby(AlignmentPanel ap2)
1314 return (_colourwith != null) && _colourwith.contains(ap2);
1319 * @return TRUE if the view is NOT being coloured by sequence associations.
1321 public boolean isColouredByJmol()
1323 return !jmb.isColourBySequence();