2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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 PDBEntry pdbentry = new PDBEntry(ids[i], null, PDBEntry.Type.PDB,
153 pdbentrys[i] = pdbentry;
155 // / TODO: check if protocol is needed to be set, and if chains are
157 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
158 pdbentrys, seqs, null, null);
160 jmb.setLoadingFromArchive(true);
161 addAlignmentPanel(ap);
164 useAlignmentPanelForSuperposition(ap);
166 if (leaveColouringToJmol || !usetoColour)
168 jmb.setColourBySequence(false);
169 seqColour.setSelected(false);
170 viewerColour.setSelected(true);
172 else if (usetoColour)
174 useAlignmentPanelForColourbyseq(ap);
175 jmb.setColourBySequence(true);
176 seqColour.setSelected(true);
177 viewerColour.setSelected(false);
179 this.setBounds(bounds);
182 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
183 // bounds.width,bounds.height);
185 this.addInternalFrameListener(new InternalFrameAdapter()
187 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
192 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
196 private void initMenus()
198 seqColour.setSelected(jmb.isColourBySequence());
199 viewerColour.setSelected(!jmb.isColourBySequence());
200 if (_colourwith == null)
202 _colourwith = new Vector<AlignmentPanel>();
204 if (_alignwith == null)
206 _alignwith = new Vector<AlignmentPanel>();
209 seqColourBy = new ViewSelectionMenu(MessageManager.getString("label.colour_by"), this, _colourwith,
214 public void itemStateChanged(ItemEvent e)
216 if (!seqColour.isSelected())
222 // update the jmol display now.
223 seqColour_actionPerformed(null);
227 viewMenu.add(seqColourBy);
228 final ItemListener handler;
229 JMenu alpanels = new ViewSelectionMenu(MessageManager.getString("label.superpose_with"), this,
230 _alignwith, handler = new ItemListener()
234 public void itemStateChanged(ItemEvent e)
236 alignStructs.setEnabled(_alignwith.size() > 0);
237 alignStructs.setToolTipText(MessageManager
239 "label.align_structures_using_linked_alignment_views",
241 { new Integer(_alignwith.size()).toString() }));
244 handler.itemStateChanged(null);
245 viewerActionMenu.add(alpanels);
246 viewerActionMenu.addMenuListener(new MenuListener()
250 public void menuSelected(MenuEvent e)
252 handler.itemStateChanged(null);
256 public void menuDeselected(MenuEvent e)
258 // TODO Auto-generated method stub
263 public void menuCanceled(MenuEvent e)
265 // TODO Auto-generated method stub
271 IProgressIndicator progressBar = null;
274 * add a single PDB structure to a new or existing Jmol view
281 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
282 final AlignmentPanel ap)
284 progressBar = ap.alignFrame;
285 // ////////////////////////////////
286 // Is the pdb file already loaded?
287 String alreadyMapped = ap.getStructureSelectionManager()
288 .alreadyMappedToFile(pdbentry.getId());
290 if (alreadyMapped != null)
292 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
293 MessageManager.formatMessage(
294 "label.pdb_entry_is_already_displayed", new String[]
295 { pdbentry.getId() }), MessageManager.formatMessage(
296 "label.map_sequences_to_visible_window", new String[]
297 { pdbentry.getId() }),
298 JOptionPane.YES_NO_CANCEL_OPTION);
300 if (option == JOptionPane.CANCEL_OPTION)
304 if (option == JOptionPane.YES_OPTION)
306 // TODO : Fix multiple seq to one chain issue here.
307 ap.getStructureSelectionManager().setMapping(seq, chains,
308 alreadyMapped, AppletFormatAdapter.FILE);
309 if (ap.getSeqPanel().seqCanvas.fr != null)
311 ap.getSeqPanel().seqCanvas.fr.featuresAdded();
312 ap.paintAlignment(true);
315 // Now this AppJmol is mapped to new sequences. We must add them to
316 // the exisiting array
317 JInternalFrame[] frames = Desktop.instance.getAllFrames();
319 for (int i = 0; i < frames.length; i++)
321 if (frames[i] instanceof AppJmol)
323 final AppJmol topJmol = ((AppJmol) frames[i]);
324 // JBPNOTE: this looks like a binding routine, rather than a gui
326 for (int pe = 0; pe < topJmol.jmb.getPdbCount(); pe++)
328 if (topJmol.jmb.getPdbEntry(pe).getFile()
329 .equals(alreadyMapped))
331 topJmol.jmb.addSequence(pe, seq);
332 topJmol.addAlignmentPanel(ap);
333 // add it to the set used for colouring
334 topJmol.useAlignmentPanelForColourbyseq(ap);
335 topJmol.buildActionMenu();
336 ap.getStructureSelectionManager()
337 .sequenceColoursChanged(ap);
347 // /////////////////////////////////
348 // Check if there are other Jmol views involving this alignment
349 // and prompt user about adding this molecule to one of them
350 Vector existingViews = getJmolsFor(ap);
351 if (existingViews.size() > 0)
353 Enumeration jm = existingViews.elements();
354 while (jm.hasMoreElements())
356 AppJmol topJmol = (AppJmol) jm.nextElement();
357 // TODO: highlight topJmol in view somehow
358 int option = JOptionPane
359 .showInternalConfirmDialog(
361 MessageManager.formatMessage(
362 "label.add_pdbentry_to_view", new String[]
363 { pdbentry.getId(), topJmol.getTitle() }),
365 .getString("label.align_to_existing_structure_view"),
366 JOptionPane.YES_NO_CANCEL_OPTION);
367 if (option == JOptionPane.CANCEL_OPTION)
371 if (option == JOptionPane.YES_OPTION)
373 topJmol.useAlignmentPanelForSuperposition(ap);
374 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
379 // /////////////////////////////////
380 openNewJmol(ap, new PDBEntry[]
381 { pdbentry }, new SequenceI[][]
385 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
388 progressBar = ap.alignFrame;
389 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
390 pdbentrys, seqs, null, null);
391 addAlignmentPanel(ap);
392 useAlignmentPanelForColourbyseq(ap);
393 if (pdbentrys.length > 1)
395 alignAddedStructures = true;
396 useAlignmentPanelForSuperposition(ap);
398 jmb.setColourBySequence(true);
399 setSize(400, 400); // probably should be a configurable/dynamic default here
403 addingStructures = false;
404 worker = new Thread(this);
407 this.addInternalFrameListener(new InternalFrameAdapter()
409 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
418 * create a new Jmol containing several structures superimposed using the
425 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
427 openNewJmol(ap, pe, seqs);
431 * pdb retrieval thread.
433 private Thread worker = null;
436 * add a new structure (with associated sequences and chains) to this viewer,
437 * retrieving it if necessary first.
444 * if true, new structure(s) will be align using associated alignment
446 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
447 final String[] chains, final boolean b,
448 final IProgressIndicator alignFrame)
450 if (pdbentry.getFile() == null)
452 if (worker != null && worker.isAlive())
454 // a retrieval is in progress, wait around and add ourselves to the
456 new Thread(new Runnable()
460 while (worker != null && worker.isAlive() && _started)
464 Thread.sleep(100 + ((int) Math.random() * 100));
466 } catch (Exception e)
471 // and call ourselves again.
472 addStructure(pdbentry, seq, chains, b, alignFrame);
478 // otherwise, start adding the structure.
479 jmb.addSequenceAndChain(new PDBEntry[]
480 { pdbentry }, new SequenceI[][]
481 { seq }, new String[][]
483 addingStructures = true;
485 alignAddedStructures = b;
486 progressBar = alignFrame; // visual indication happens on caller frame.
487 (worker = new Thread(this)).start();
491 private Vector getJmolsFor(AlignmentPanel apanel)
493 Vector result = new Vector();
494 JInternalFrame[] frames = Desktop.instance.getAllFrames();
496 for (JInternalFrame frame : frames)
498 if (frame instanceof AppJmol)
500 if (((StructureViewerBase) frame).isLinkedWith(apanel))
502 result.addElement(frame);
509 void initJmol(String command)
511 jmb.setFinishedInit(false);
512 renderPanel = new RenderPanel();
513 // TODO: consider waiting until the structure/view is fully loaded before
515 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
516 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
517 getBounds().width, getBounds().height);
518 if (scriptWindow == null)
520 BorderLayout bl = new BorderLayout();
523 scriptWindow = new JPanel(bl);
524 scriptWindow.setVisible(false);
527 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
529 jmb.newJmolPopup(true, "Jmol", true);
534 jmb.evalStateCommand(command);
535 jmb.setFinishedInit(true);
538 void setChainMenuItems(Vector chains)
540 chainMenu.removeAll();
545 JMenuItem menuItem = new JMenuItem(
546 MessageManager.getString("label.all"));
547 menuItem.addActionListener(new ActionListener()
549 public void actionPerformed(ActionEvent evt)
551 allChainsSelected = true;
552 for (int i = 0; i < chainMenu.getItemCount(); i++)
554 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
556 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
560 allChainsSelected = false;
564 chainMenu.add(menuItem);
566 for (int c = 0; c < chains.size(); c++)
568 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
569 menuItem.addItemListener(new ItemListener()
571 public void itemStateChanged(ItemEvent evt)
573 if (!allChainsSelected)
580 chainMenu.add(menuItem);
584 boolean allChainsSelected = false;
586 private boolean alignAddedStructures = false;
590 Vector toshow = new Vector();
592 int mlength, p, mnum;
593 for (int i = 0; i < chainMenu.getItemCount(); i++)
595 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
597 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
598 if (item.isSelected())
600 toshow.addElement(item.getText());
604 jmb.centerViewer(toshow);
607 public void closeViewer(boolean closeExternalViewer)
609 // JMol does not use an external viewer
611 setAlignmentPanel(null);
615 // TODO: check for memory leaks where instance isn't finalised because jmb
616 // holds a reference to the window
621 * state flag for PDB retrieval thread
623 private boolean _started = false;
629 // todo - record which pdbids were successfuly imported.
630 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
633 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
634 // TODO: replace with reference fetching/transfer code (validate PDBentry
636 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
637 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
639 String file = jmb.getPdbEntry(pi).getFile();
642 // retrieve the pdb and store it locally
643 AlignmentI pdbseq = null;
644 pdbid = jmb.getPdbEntry(pi).getId();
645 long hdl = pdbid.hashCode() - System.currentTimeMillis();
646 if (progressBar != null)
648 progressBar.setProgressBar(MessageManager.formatMessage("status.fetching_pdb", new String[]{pdbid}), hdl);
652 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.getPdbEntry(
655 } catch (OutOfMemoryError oomerror)
657 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
658 } catch (Exception ex)
660 ex.printStackTrace();
661 errormsgs.append("'" + pdbid + "'");
663 if (progressBar != null)
665 progressBar.setProgressBar(MessageManager.getString("label.state_completed"), hdl);
669 // just transfer the file name from the first sequence's first
671 file = new File(pdbseq.getSequenceAt(0).getPDBId()
672 .elementAt(0).getFile()).getAbsolutePath();
673 jmb.getPdbEntry(pi).setFile(file);
675 files.append(" \"" + Platform.escapeString(file) + "\"");
679 errormsgs.append("'" + pdbid + "' ");
684 if (curfiles != null && curfiles.length > 0)
686 addingStructures = true; // already files loaded.
687 for (int c = 0; c < curfiles.length; c++)
689 if (curfiles[c].equals(file))
698 files.append(" \"" + Platform.escapeString(file) + "\"");
702 } catch (OutOfMemoryError oomerror)
704 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
705 } catch (Exception ex)
707 ex.printStackTrace();
708 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
711 if (errormsgs.length() > 0)
714 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
715 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
717 { errormsgs.toString() }), MessageManager
718 .getString("label.couldnt_load_file"),
719 JOptionPane.ERROR_MESSAGE);
722 long lastnotify = jmb.getLoadNotifiesHandled();
723 if (files.length() > 0)
725 if (!addingStructures)
730 initJmol("load FILES " + files.toString());
731 } catch (OutOfMemoryError oomerror)
733 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
734 Cache.log.debug("File locations are " + files);
735 } catch (Exception ex)
737 Cache.log.error("Couldn't open Jmol viewer!", ex);
742 StringBuffer cmd = new StringBuffer();
743 cmd.append("loadingJalviewdata=true\nload APPEND ");
744 cmd.append(files.toString());
745 cmd.append("\nloadingJalviewdata=null");
746 final String command = cmd.toString();
748 lastnotify = jmb.getLoadNotifiesHandled();
752 jmb.evalStateCommand(command);
753 } catch (OutOfMemoryError oomerror)
756 "When trying to add structures to the Jmol viewer!",
758 Cache.log.debug("File locations are " + files);
759 } catch (Exception ex)
761 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
765 // need to wait around until script has finished
766 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
767 : (jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb
768 .getPdbFile().length != jmb.getPdbCount()))
772 Cache.log.debug("Waiting around for jmb notify.");
774 } catch (Exception e)
778 // refresh the sequence colours for the new structure(s)
779 for (AlignmentPanel ap : _colourwith)
781 jmb.updateColours(ap);
783 // do superposition if asked to
784 if (alignAddedStructures)
786 javax.swing.SwingUtilities.invokeLater(new Runnable()
790 alignStructs_withAllAlignPanels();
791 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
794 alignAddedStructures = false;
796 addingStructures = false;
804 public void pdbFile_actionPerformed(ActionEvent actionEvent)
806 JalviewFileChooser chooser = new JalviewFileChooser(
807 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
809 chooser.setFileView(new JalviewFileView());
810 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
811 chooser.setToolTipText(MessageManager.getString("action.save"));
813 int value = chooser.showSaveDialog(this);
815 if (value == JalviewFileChooser.APPROVE_OPTION)
819 // TODO: cope with multiple PDB files in view
820 BufferedReader in = new BufferedReader(new FileReader(
821 jmb.getPdbFile()[0]));
822 File outFile = chooser.getSelectedFile();
824 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
826 while ((data = in.readLine()) != null)
828 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
834 } catch (Exception ex)
836 ex.printStackTrace();
842 public void viewMapping_actionPerformed(ActionEvent actionEvent)
844 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
847 for (int pdbe = 0; pdbe < jmb.getPdbCount(); pdbe++)
849 cap.appendText(jmb.printMapping(jmb.getPdbEntry(pdbe).getFile()));
850 cap.appendText("\n");
852 } catch (OutOfMemoryError e)
855 "composing sequence-structure alignments for display in text box.",
860 jalview.gui.Desktop.addInternalFrame(cap,
861 MessageManager.getString("label.pdb_sequence_mapping"), 550,
866 public void eps_actionPerformed(ActionEvent e)
868 makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
872 public void png_actionPerformed(ActionEvent e)
874 makePDBImage(jalview.util.ImageMaker.TYPE.PNG);
877 void makePDBImage(jalview.util.ImageMaker.TYPE type)
879 int width = getWidth();
880 int height = getHeight();
882 jalview.util.ImageMaker im;
884 if (type == jalview.util.ImageMaker.TYPE.PNG)
886 im = new jalview.util.ImageMaker(this,
887 jalview.util.ImageMaker.TYPE.PNG,
888 "Make PNG image from view", width, height, null, null);
890 else if (type == jalview.util.ImageMaker.TYPE.EPS)
892 im = new jalview.util.ImageMaker(this,
893 jalview.util.ImageMaker.TYPE.EPS,
894 "Make EPS file from view", width, height, null,
900 im = new jalview.util.ImageMaker(this,
901 jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
902 width, height, null, this.getTitle());
905 if (im.getGraphics() != null)
907 Rectangle rect = new Rectangle(width, height);
908 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
914 public void viewerColour_actionPerformed(ActionEvent actionEvent)
916 if (viewerColour.isSelected())
918 // disable automatic sequence colouring.
919 jmb.setColourBySequence(false);
924 public void seqColour_actionPerformed(ActionEvent actionEvent)
926 jmb.setColourBySequence(seqColour.isSelected());
927 if (_colourwith == null)
929 _colourwith = new Vector<AlignmentPanel>();
931 if (jmb.isColourBySequence())
933 if (!jmb.isLoadingFromArchive())
935 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
937 // Make the currently displayed alignment panel the associated view
938 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
941 // Set the colour using the current view for the associated alignframe
942 for (AlignmentPanel ap : _colourwith)
944 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
950 public void chainColour_actionPerformed(ActionEvent actionEvent)
952 chainColour.setSelected(true);
957 public void chargeColour_actionPerformed(ActionEvent actionEvent)
959 chargeColour.setSelected(true);
960 jmb.colourByCharge();
964 public void zappoColour_actionPerformed(ActionEvent actionEvent)
966 zappoColour.setSelected(true);
967 jmb.setJalviewColourScheme(new ZappoColourScheme());
971 public void taylorColour_actionPerformed(ActionEvent actionEvent)
973 taylorColour.setSelected(true);
974 jmb.setJalviewColourScheme(new TaylorColourScheme());
978 public void hydroColour_actionPerformed(ActionEvent actionEvent)
980 hydroColour.setSelected(true);
981 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
985 public void helixColour_actionPerformed(ActionEvent actionEvent)
987 helixColour.setSelected(true);
988 jmb.setJalviewColourScheme(new HelixColourScheme());
992 public void strandColour_actionPerformed(ActionEvent actionEvent)
994 strandColour.setSelected(true);
995 jmb.setJalviewColourScheme(new StrandColourScheme());
999 public void turnColour_actionPerformed(ActionEvent actionEvent)
1001 turnColour.setSelected(true);
1002 jmb.setJalviewColourScheme(new TurnColourScheme());
1006 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1008 buriedColour.setSelected(true);
1009 jmb.setJalviewColourScheme(new BuriedColourScheme());
1013 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1015 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1019 public void userColour_actionPerformed(ActionEvent actionEvent)
1021 userColour.setSelected(true);
1022 new UserDefinedColours(this, null);
1026 public void backGround_actionPerformed(ActionEvent actionEvent)
1028 java.awt.Color col = JColorChooser.showDialog(this,
1029 MessageManager.getString("label.select_backgroud_colour"), null);
1032 jmb.setBackgroundColour(col);
1037 public void showHelp_actionPerformed(ActionEvent actionEvent)
1041 jalview.util.BrowserLauncher
1042 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1043 } catch (Exception ex)
1048 public void showConsole(boolean showConsole)
1053 if (splitPane == null)
1055 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1056 splitPane.setTopComponent(renderPanel);
1057 splitPane.setBottomComponent(scriptWindow);
1058 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1059 splitPane.setDividerLocation(getHeight() - 200);
1060 scriptWindow.setVisible(true);
1061 scriptWindow.validate();
1062 splitPane.validate();
1068 if (splitPane != null)
1070 splitPane.setVisible(false);
1075 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1081 class RenderPanel extends JPanel
1083 final Dimension currentSize = new Dimension();
1085 final Rectangle rectClip = new Rectangle();
1087 public void paintComponent(Graphics g)
1089 getSize(currentSize);
1090 g.getClipBounds(rectClip);
1092 if (jmb.fileLoadingError != null)
1094 g.setColor(Color.black);
1095 g.fillRect(0, 0, currentSize.width, currentSize.height);
1096 g.setColor(Color.white);
1097 g.setFont(new Font("Verdana", Font.BOLD, 14));
1098 g.drawString(MessageManager.getString("label.error_loading_file")
1099 + "...", 20, currentSize.height / 2);
1100 StringBuffer sb = new StringBuffer();
1102 for (int e = 0; e < jmb.getPdbCount(); e++)
1104 sb.append(jmb.getPdbEntry(e).getId());
1105 if (e < jmb.getPdbCount() - 1)
1110 if (e == jmb.getPdbCount() - 1 || sb.length() > 20)
1113 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1114 * g.getFontMetrics().getHeight());
1118 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
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(MessageManager.getString("label.retrieving_pdb_data"),
1125 20, currentSize.height / 2);
1129 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1134 public void updateTitleAndMenus()
1136 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1141 setChainMenuItems(jmb.chainNames);
1143 this.setTitle(jmb.getViewerTitle());
1144 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1146 viewerActionMenu.setVisible(true);
1148 if (!jmb.isLoadingFromArchive())
1150 seqColour_actionPerformed(null);
1158 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1162 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1164 alignStructs_withAllAlignPanels();
1167 private void alignStructs_withAllAlignPanels()
1169 if (getAlignmentPanel() == null)
1174 if (_alignwith.size() == 0)
1176 _alignwith.add(getAlignmentPanel());
1181 AlignmentI[] als = new Alignment[_alignwith.size()];
1182 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1183 int[] alm = new int[_alignwith.size()];
1186 for (AlignmentPanel ap : _alignwith)
1188 als[a] = ap.av.getAlignment();
1190 alc[a++] = ap.av.getColumnSelection();
1192 jmb.superposeStructures(als, alm, alc);
1193 } catch (Exception e)
1195 StringBuffer sp = new StringBuffer();
1196 for (AlignmentPanel ap : _alignwith)
1198 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1200 Cache.log.info("Couldn't align structures with the " + sp.toString()
1201 + "associated alignment panels.", e);
1207 public void setJalviewColourScheme(ColourSchemeI ucs)
1209 jmb.setJalviewColourScheme(ucs);
1216 * @return first alignment panel displaying given alignment, or the default
1219 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1221 for (AlignmentPanel ap : getAllAlignmentPanels())
1223 if (ap.av.getAlignment() == alignment)
1228 return getAlignmentPanel();
1232 public AAStructureBindingModel getBinding()
1238 public String getStateInfo()
1240 return jmb == null ? null : jmb.viewer.getStateInfo();