2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.bin.Cache;
24 import jalview.datamodel.Alignment;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.ColumnSelection;
27 import jalview.datamodel.PDBEntry;
28 import jalview.datamodel.SequenceI;
29 import jalview.io.AppletFormatAdapter;
30 import jalview.io.JalviewFileChooser;
31 import jalview.io.JalviewFileView;
32 import jalview.schemes.BuriedColourScheme;
33 import jalview.schemes.ColourSchemeI;
34 import jalview.schemes.HelixColourScheme;
35 import jalview.schemes.HydrophobicColourScheme;
36 import jalview.schemes.PurinePyrimidineColourScheme;
37 import jalview.schemes.StrandColourScheme;
38 import jalview.schemes.TaylorColourScheme;
39 import jalview.schemes.TurnColourScheme;
40 import jalview.schemes.ZappoColourScheme;
41 import jalview.structures.models.AAStructureBindingModel;
42 import jalview.util.MessageManager;
43 import jalview.util.Platform;
45 import java.awt.BorderLayout;
46 import java.awt.Color;
47 import java.awt.Dimension;
49 import java.awt.Graphics;
50 import java.awt.Rectangle;
51 import java.awt.event.ActionEvent;
52 import java.awt.event.ActionListener;
53 import java.awt.event.ItemEvent;
54 import java.awt.event.ItemListener;
55 import java.io.BufferedReader;
57 import java.io.FileOutputStream;
58 import java.io.FileReader;
59 import java.io.PrintWriter;
60 import java.util.Enumeration;
61 import java.util.Vector;
63 import javax.swing.JCheckBoxMenuItem;
64 import javax.swing.JColorChooser;
65 import javax.swing.JInternalFrame;
66 import javax.swing.JMenu;
67 import javax.swing.JMenuItem;
68 import javax.swing.JOptionPane;
69 import javax.swing.JPanel;
70 import javax.swing.JSplitPane;
71 import javax.swing.event.InternalFrameAdapter;
72 import javax.swing.event.InternalFrameEvent;
73 import javax.swing.event.MenuEvent;
74 import javax.swing.event.MenuListener;
76 public class AppJmol extends StructureViewerBase
84 RenderPanel renderPanel;
86 Vector atomsPicked = new Vector();
88 private boolean addingStructures = false;
98 * @deprecated defaults to AppJmol(String[] files, ... , viewid);
101 public AppJmol(String file, String id, SequenceI[] seq,
102 AlignmentPanel ap, String loadStatus, Rectangle bounds)
104 this(file, id, seq, ap, loadStatus, bounds, null);
111 public AppJmol(String file, String id, SequenceI[] seq,
112 AlignmentPanel ap, String loadStatus, Rectangle bounds,
116 { file }, new String[]
117 { id }, new SequenceI[][]
118 { seq }, ap, true, true, false, loadStatus, bounds, viewid);
121 ViewSelectionMenu seqColourBy;
130 * - add the alignment panel to the list used for colouring these
133 * - add the alignment panel to the list used for aligning these
135 * @param leaveColouringToJmol
136 * - do not update the colours from any other source. Jmol is
142 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
143 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
144 boolean leaveColouringToJmol, String loadStatus,
145 Rectangle bounds, String viewid)
147 PDBEntry[] pdbentrys = new PDBEntry[files.length];
148 for (int i = 0; i < pdbentrys.length; i++)
150 PDBEntry pdbentry = new PDBEntry(files[i], ids[i]);
151 pdbentrys[i] = pdbentry;
153 // / TODO: check if protocol is needed to be set, and if chains are
155 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
156 pdbentrys, seqs, null, null);
158 jmb.setLoadingFromArchive(true);
159 addAlignmentPanel(ap);
162 useAlignmentPanelForSuperposition(ap);
164 if (leaveColouringToJmol || !usetoColour)
166 jmb.setColourBySequence(false);
167 seqColour.setSelected(false);
168 viewerColour.setSelected(true);
170 else if (usetoColour)
172 useAlignmentPanelForColourbyseq(ap);
173 jmb.setColourBySequence(true);
174 seqColour.setSelected(true);
175 viewerColour.setSelected(false);
177 this.setBounds(bounds);
180 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
181 // bounds.width,bounds.height);
183 this.addInternalFrameListener(new InternalFrameAdapter()
185 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
190 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
194 private void initMenus()
196 seqColour.setSelected(jmb.isColourBySequence());
197 viewerColour.setSelected(!jmb.isColourBySequence());
198 if (_colourwith == null)
200 _colourwith = new Vector<AlignmentPanel>();
202 if (_alignwith == null)
204 _alignwith = new Vector<AlignmentPanel>();
207 seqColourBy = new ViewSelectionMenu(MessageManager.getString("label.colour_by"), this, _colourwith,
212 public void itemStateChanged(ItemEvent e)
214 if (!seqColour.isSelected())
220 // update the jmol display now.
221 seqColour_actionPerformed(null);
225 viewMenu.add(seqColourBy);
226 final ItemListener handler;
227 JMenu alpanels = new ViewSelectionMenu(MessageManager.getString("label.superpose_with"), this,
228 _alignwith, handler = new ItemListener()
232 public void itemStateChanged(ItemEvent e)
234 alignStructs.setEnabled(_alignwith.size() > 0);
235 alignStructs.setToolTipText(MessageManager
237 "label.align_structures_using_linked_alignment_views",
239 { new Integer(_alignwith.size()).toString() }));
242 handler.itemStateChanged(null);
243 viewerActionMenu.add(alpanels);
244 viewerActionMenu.addMenuListener(new MenuListener()
248 public void menuSelected(MenuEvent e)
250 handler.itemStateChanged(null);
254 public void menuDeselected(MenuEvent e)
256 // TODO Auto-generated method stub
261 public void menuCanceled(MenuEvent e)
263 // TODO Auto-generated method stub
269 IProgressIndicator progressBar = null;
272 * add a single PDB structure to a new or existing Jmol view
279 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
280 final AlignmentPanel ap)
282 progressBar = ap.alignFrame;
283 // ////////////////////////////////
284 // Is the pdb file already loaded?
285 String alreadyMapped = ap.getStructureSelectionManager()
286 .alreadyMappedToFile(pdbentry.getId());
288 if (alreadyMapped != null)
290 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
291 MessageManager.formatMessage(
292 "label.pdb_entry_is_already_displayed", new String[]
293 { pdbentry.getId() }), MessageManager.formatMessage(
294 "label.map_sequences_to_visible_window", new String[]
295 { pdbentry.getId() }),
296 JOptionPane.YES_NO_CANCEL_OPTION);
298 if (option == JOptionPane.CANCEL_OPTION)
302 if (option == JOptionPane.YES_OPTION)
304 // TODO : Fix multiple seq to one chain issue here.
305 ap.getStructureSelectionManager().setMapping(seq, chains,
306 alreadyMapped, AppletFormatAdapter.FILE);
307 if (ap.getSeqPanel().seqCanvas.fr != null)
309 ap.getSeqPanel().seqCanvas.fr.featuresAdded();
310 ap.paintAlignment(true);
313 // Now this AppJmol is mapped to new sequences. We must add them to
314 // the exisiting array
315 JInternalFrame[] frames = Desktop.instance.getAllFrames();
317 for (int i = 0; i < frames.length; i++)
319 if (frames[i] instanceof AppJmol)
321 final AppJmol topJmol = ((AppJmol) frames[i]);
322 // JBPNOTE: this looks like a binding routine, rather than a gui
324 for (int pe = 0; pe < topJmol.jmb.getPdbCount(); pe++)
326 if (topJmol.jmb.getPdbEntry(pe).getFile()
327 .equals(alreadyMapped))
329 topJmol.jmb.addSequence(pe, seq);
330 topJmol.addAlignmentPanel(ap);
331 // add it to the set used for colouring
332 topJmol.useAlignmentPanelForColourbyseq(ap);
333 topJmol.buildActionMenu();
334 ap.getStructureSelectionManager()
335 .sequenceColoursChanged(ap);
345 // /////////////////////////////////
346 // Check if there are other Jmol views involving this alignment
347 // and prompt user about adding this molecule to one of them
348 Vector existingViews = getJmolsFor(ap);
349 if (existingViews.size() > 0)
351 Enumeration jm = existingViews.elements();
352 while (jm.hasMoreElements())
354 AppJmol topJmol = (AppJmol) jm.nextElement();
355 // TODO: highlight topJmol in view somehow
356 int option = JOptionPane
357 .showInternalConfirmDialog(
359 MessageManager.formatMessage(
360 "label.add_pdbentry_to_view", new String[]
361 { pdbentry.getId(), topJmol.getTitle() }),
363 .getString("label.align_to_existing_structure_view"),
364 JOptionPane.YES_NO_CANCEL_OPTION);
365 if (option == JOptionPane.CANCEL_OPTION)
369 if (option == JOptionPane.YES_OPTION)
371 topJmol.useAlignmentPanelForSuperposition(ap);
372 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
377 // /////////////////////////////////
378 openNewJmol(ap, new PDBEntry[]
379 { pdbentry }, new SequenceI[][]
383 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
386 progressBar = ap.alignFrame;
387 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
388 pdbentrys, seqs, null, null);
389 addAlignmentPanel(ap);
390 useAlignmentPanelForColourbyseq(ap);
391 if (pdbentrys.length > 1)
393 alignAddedStructures = true;
394 useAlignmentPanelForSuperposition(ap);
396 jmb.setColourBySequence(true);
397 setSize(400, 400); // probably should be a configurable/dynamic default here
401 addingStructures = false;
402 worker = new Thread(this);
405 this.addInternalFrameListener(new InternalFrameAdapter()
407 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
416 * create a new Jmol containing several structures superimposed using the
423 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
425 openNewJmol(ap, pe, seqs);
429 * pdb retrieval thread.
431 private Thread worker = null;
434 * add a new structure (with associated sequences and chains) to this viewer,
435 * retrieving it if necessary first.
442 * if true, new structure(s) will be align using associated alignment
444 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
445 final String[] chains, final boolean b,
446 final IProgressIndicator alignFrame)
448 if (pdbentry.getFile() == null)
450 if (worker != null && worker.isAlive())
452 // a retrieval is in progress, wait around and add ourselves to the
454 new Thread(new Runnable()
458 while (worker != null && worker.isAlive() && _started)
462 Thread.sleep(100 + ((int) Math.random() * 100));
464 } catch (Exception e)
469 // and call ourselves again.
470 addStructure(pdbentry, seq, chains, b, alignFrame);
476 // otherwise, start adding the structure.
477 jmb.addSequenceAndChain(new PDBEntry[]
478 { pdbentry }, new SequenceI[][]
479 { seq }, new String[][]
481 addingStructures = true;
483 alignAddedStructures = b;
484 progressBar = alignFrame; // visual indication happens on caller frame.
485 (worker = new Thread(this)).start();
489 private Vector getJmolsFor(AlignmentPanel apanel)
491 Vector result = new Vector();
492 JInternalFrame[] frames = Desktop.instance.getAllFrames();
494 for (JInternalFrame frame : frames)
496 if (frame instanceof AppJmol)
498 if (((StructureViewerBase) frame).isLinkedWith(apanel))
500 result.addElement(frame);
507 void initJmol(String command)
509 jmb.setFinishedInit(false);
510 renderPanel = new RenderPanel();
511 // TODO: consider waiting until the structure/view is fully loaded before
513 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
514 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
515 getBounds().width, getBounds().height);
516 if (scriptWindow == null)
518 BorderLayout bl = new BorderLayout();
521 scriptWindow = new JPanel(bl);
522 scriptWindow.setVisible(false);
525 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
527 jmb.newJmolPopup(true, "Jmol", true);
532 jmb.evalStateCommand(command);
533 jmb.setFinishedInit(true);
536 void setChainMenuItems(Vector chains)
538 chainMenu.removeAll();
543 JMenuItem menuItem = new JMenuItem(
544 MessageManager.getString("label.all"));
545 menuItem.addActionListener(new ActionListener()
547 public void actionPerformed(ActionEvent evt)
549 allChainsSelected = true;
550 for (int i = 0; i < chainMenu.getItemCount(); i++)
552 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
554 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
558 allChainsSelected = false;
562 chainMenu.add(menuItem);
564 for (int c = 0; c < chains.size(); c++)
566 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
567 menuItem.addItemListener(new ItemListener()
569 public void itemStateChanged(ItemEvent evt)
571 if (!allChainsSelected)
578 chainMenu.add(menuItem);
582 boolean allChainsSelected = false;
584 private boolean alignAddedStructures = false;
588 Vector toshow = new Vector();
590 int mlength, p, mnum;
591 for (int i = 0; i < chainMenu.getItemCount(); i++)
593 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
595 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
596 if (item.isSelected())
598 toshow.addElement(item.getText());
602 jmb.centerViewer(toshow);
605 public void closeViewer()
608 setAlignmentPanel(null);
612 // TODO: check for memory leaks where instance isn't finalised because jmb
613 // holds a reference to the window
618 * state flag for PDB retrieval thread
620 private boolean _started = false;
626 // todo - record which pdbids were successfuly imported.
627 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
630 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
631 // TODO: replace with reference fetching/transfer code (validate PDBentry
633 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
634 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
636 String file = jmb.getPdbEntry(pi).getFile();
639 // retrieve the pdb and store it locally
640 AlignmentI pdbseq = null;
641 pdbid = jmb.getPdbEntry(pi).getId();
642 long hdl = pdbid.hashCode() - System.currentTimeMillis();
643 if (progressBar != null)
645 progressBar.setProgressBar(MessageManager.formatMessage("status.fetching_pdb", new String[]{pdbid}), hdl);
649 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.getPdbEntry(
652 } catch (OutOfMemoryError oomerror)
654 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
655 } catch (Exception ex)
657 ex.printStackTrace();
658 errormsgs.append("'" + pdbid + "'");
660 if (progressBar != null)
662 progressBar.setProgressBar(MessageManager.getString("label.state_completed"), hdl);
666 // just transfer the file name from the first sequence's first
668 file = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
669 .elementAt(0)).getFile()).getAbsolutePath();
670 jmb.getPdbEntry(pi).setFile(file);
672 files.append(" \"" + Platform.escapeString(file) + "\"");
676 errormsgs.append("'" + pdbid + "' ");
681 if (curfiles != null && curfiles.length > 0)
683 addingStructures = true; // already files loaded.
684 for (int c = 0; c < curfiles.length; c++)
686 if (curfiles[c].equals(file))
695 files.append(" \"" + Platform.escapeString(file) + "\"");
699 } catch (OutOfMemoryError oomerror)
701 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
702 } catch (Exception ex)
704 ex.printStackTrace();
705 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
708 if (errormsgs.length() > 0)
711 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
712 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
714 { errormsgs.toString() }), MessageManager
715 .getString("label.couldnt_load_file"),
716 JOptionPane.ERROR_MESSAGE);
719 long lastnotify = jmb.getLoadNotifiesHandled();
720 if (files.length() > 0)
722 if (!addingStructures)
727 initJmol("load FILES " + files.toString());
728 } catch (OutOfMemoryError oomerror)
730 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
731 Cache.log.debug("File locations are " + files);
732 } catch (Exception ex)
734 Cache.log.error("Couldn't open Jmol viewer!", ex);
739 StringBuffer cmd = new StringBuffer();
740 cmd.append("loadingJalviewdata=true\nload APPEND ");
741 cmd.append(files.toString());
742 cmd.append("\nloadingJalviewdata=null");
743 final String command = cmd.toString();
745 lastnotify = jmb.getLoadNotifiesHandled();
749 jmb.evalStateCommand(command);
750 } catch (OutOfMemoryError oomerror)
753 "When trying to add structures to the Jmol viewer!",
755 Cache.log.debug("File locations are " + files);
756 } catch (Exception ex)
758 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
762 // need to wait around until script has finished
763 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
764 : (jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb
765 .getPdbFile().length != jmb.getPdbCount()))
769 Cache.log.debug("Waiting around for jmb notify.");
771 } catch (Exception e)
775 // refresh the sequence colours for the new structure(s)
776 for (AlignmentPanel ap : _colourwith)
778 jmb.updateColours(ap);
780 // do superposition if asked to
781 if (alignAddedStructures)
783 javax.swing.SwingUtilities.invokeLater(new Runnable()
787 alignStructs_withAllAlignPanels();
788 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
791 alignAddedStructures = false;
793 addingStructures = false;
801 public void pdbFile_actionPerformed(ActionEvent actionEvent)
803 JalviewFileChooser chooser = new JalviewFileChooser(
804 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
806 chooser.setFileView(new JalviewFileView());
807 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
808 chooser.setToolTipText(MessageManager.getString("action.save"));
810 int value = chooser.showSaveDialog(this);
812 if (value == JalviewFileChooser.APPROVE_OPTION)
816 // TODO: cope with multiple PDB files in view
817 BufferedReader in = new BufferedReader(new FileReader(
818 jmb.getPdbFile()[0]));
819 File outFile = chooser.getSelectedFile();
821 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
823 while ((data = in.readLine()) != null)
825 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
831 } catch (Exception ex)
833 ex.printStackTrace();
839 public void viewMapping_actionPerformed(ActionEvent actionEvent)
841 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
844 for (int pdbe = 0; pdbe < jmb.getPdbCount(); pdbe++)
846 cap.appendText(jmb.printMapping(jmb.getPdbEntry(pdbe).getFile()));
847 cap.appendText("\n");
849 } catch (OutOfMemoryError e)
852 "composing sequence-structure alignments for display in text box.",
857 jalview.gui.Desktop.addInternalFrame(cap,
858 MessageManager.getString("label.pdb_sequence_mapping"), 550,
863 public void eps_actionPerformed(ActionEvent e)
865 makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
869 public void png_actionPerformed(ActionEvent e)
871 makePDBImage(jalview.util.ImageMaker.TYPE.PNG);
874 void makePDBImage(jalview.util.ImageMaker.TYPE type)
876 int width = getWidth();
877 int height = getHeight();
879 jalview.util.ImageMaker im;
881 if (type == jalview.util.ImageMaker.TYPE.PNG)
883 im = new jalview.util.ImageMaker(this,
884 jalview.util.ImageMaker.TYPE.PNG,
885 "Make PNG image from view", width, height, null, null);
887 else if (type == jalview.util.ImageMaker.TYPE.EPS)
889 im = new jalview.util.ImageMaker(this,
890 jalview.util.ImageMaker.TYPE.EPS,
891 "Make EPS file from view", width, height, null,
897 im = new jalview.util.ImageMaker(this,
898 jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
899 width, height, null, this.getTitle());
902 if (im.getGraphics() != null)
904 Rectangle rect = new Rectangle(width, height);
905 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
911 public void viewerColour_actionPerformed(ActionEvent actionEvent)
913 if (viewerColour.isSelected())
915 // disable automatic sequence colouring.
916 jmb.setColourBySequence(false);
921 public void seqColour_actionPerformed(ActionEvent actionEvent)
923 jmb.setColourBySequence(seqColour.isSelected());
924 if (_colourwith == null)
926 _colourwith = new Vector<AlignmentPanel>();
928 if (jmb.isColourBySequence())
930 if (!jmb.isLoadingFromArchive())
932 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
934 // Make the currently displayed alignment panel the associated view
935 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
938 // Set the colour using the current view for the associated alignframe
939 for (AlignmentPanel ap : _colourwith)
941 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
947 public void chainColour_actionPerformed(ActionEvent actionEvent)
949 chainColour.setSelected(true);
954 public void chargeColour_actionPerformed(ActionEvent actionEvent)
956 chargeColour.setSelected(true);
957 jmb.colourByCharge();
961 public void zappoColour_actionPerformed(ActionEvent actionEvent)
963 zappoColour.setSelected(true);
964 jmb.setJalviewColourScheme(new ZappoColourScheme());
968 public void taylorColour_actionPerformed(ActionEvent actionEvent)
970 taylorColour.setSelected(true);
971 jmb.setJalviewColourScheme(new TaylorColourScheme());
975 public void hydroColour_actionPerformed(ActionEvent actionEvent)
977 hydroColour.setSelected(true);
978 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
982 public void helixColour_actionPerformed(ActionEvent actionEvent)
984 helixColour.setSelected(true);
985 jmb.setJalviewColourScheme(new HelixColourScheme());
989 public void strandColour_actionPerformed(ActionEvent actionEvent)
991 strandColour.setSelected(true);
992 jmb.setJalviewColourScheme(new StrandColourScheme());
996 public void turnColour_actionPerformed(ActionEvent actionEvent)
998 turnColour.setSelected(true);
999 jmb.setJalviewColourScheme(new TurnColourScheme());
1003 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1005 buriedColour.setSelected(true);
1006 jmb.setJalviewColourScheme(new BuriedColourScheme());
1010 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1012 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1016 public void userColour_actionPerformed(ActionEvent actionEvent)
1018 userColour.setSelected(true);
1019 new UserDefinedColours(this, null);
1023 public void backGround_actionPerformed(ActionEvent actionEvent)
1025 java.awt.Color col = JColorChooser.showDialog(this,
1026 MessageManager.getString("label.select_backgroud_colour"), null);
1029 jmb.setBackgroundColour(col);
1034 public void showHelp_actionPerformed(ActionEvent actionEvent)
1038 jalview.util.BrowserLauncher
1039 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1040 } catch (Exception ex)
1045 public void showConsole(boolean showConsole)
1050 if (splitPane == null)
1052 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1053 splitPane.setTopComponent(renderPanel);
1054 splitPane.setBottomComponent(scriptWindow);
1055 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1056 splitPane.setDividerLocation(getHeight() - 200);
1057 scriptWindow.setVisible(true);
1058 scriptWindow.validate();
1059 splitPane.validate();
1065 if (splitPane != null)
1067 splitPane.setVisible(false);
1072 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1078 class RenderPanel extends JPanel
1080 final Dimension currentSize = new Dimension();
1082 final Rectangle rectClip = new Rectangle();
1084 public void paintComponent(Graphics g)
1086 getSize(currentSize);
1087 g.getClipBounds(rectClip);
1089 if (jmb.fileLoadingError != null)
1091 g.setColor(Color.black);
1092 g.fillRect(0, 0, currentSize.width, currentSize.height);
1093 g.setColor(Color.white);
1094 g.setFont(new Font("Verdana", Font.BOLD, 14));
1095 g.drawString(MessageManager.getString("label.error_loading_file")
1096 + "...", 20, currentSize.height / 2);
1097 StringBuffer sb = new StringBuffer();
1099 for (int e = 0; e < jmb.getPdbCount(); e++)
1101 sb.append(jmb.getPdbEntry(e).getId());
1102 if (e < jmb.getPdbCount() - 1)
1107 if (e == jmb.getPdbCount() - 1 || sb.length() > 20)
1110 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1111 * g.getFontMetrics().getHeight());
1115 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1117 g.setColor(Color.black);
1118 g.fillRect(0, 0, currentSize.width, currentSize.height);
1119 g.setColor(Color.white);
1120 g.setFont(new Font("Verdana", Font.BOLD, 14));
1121 g.drawString(MessageManager.getString("label.retrieving_pdb_data"),
1122 20, currentSize.height / 2);
1126 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1131 public void updateTitleAndMenus()
1133 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1138 setChainMenuItems(jmb.chainNames);
1140 this.setTitle(jmb.getViewerTitle());
1141 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1143 viewerActionMenu.setVisible(true);
1145 if (!jmb.isLoadingFromArchive())
1147 seqColour_actionPerformed(null);
1155 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1159 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1161 alignStructs_withAllAlignPanels();
1164 private void alignStructs_withAllAlignPanels()
1166 if (getAlignmentPanel() == null)
1171 if (_alignwith.size() == 0)
1173 _alignwith.add(getAlignmentPanel());
1178 AlignmentI[] als = new Alignment[_alignwith.size()];
1179 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1180 int[] alm = new int[_alignwith.size()];
1183 for (AlignmentPanel ap : _alignwith)
1185 als[a] = ap.av.getAlignment();
1187 alc[a++] = ap.av.getColumnSelection();
1189 jmb.superposeStructures(als, alm, alc);
1190 } catch (Exception e)
1192 StringBuffer sp = new StringBuffer();
1193 for (AlignmentPanel ap : _alignwith)
1195 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1197 Cache.log.info("Couldn't align structures with the " + sp.toString()
1198 + "associated alignment panels.", e);
1204 public void setJalviewColourScheme(ColourSchemeI ucs)
1206 jmb.setJalviewColourScheme(ucs);
1213 * @return first alignment panel displaying given alignment, or the default
1216 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1218 for (AlignmentPanel ap : getAllAlignmentPanels())
1220 if (ap.av.getAlignment() == alignment)
1225 return getAlignmentPanel();
1229 public AAStructureBindingModel getBinding()
1235 public String getStateInfo()
1237 return jmb == null ? null : jmb.viewer.getStateInfo();