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.gui.StructureViewer.ViewerType;
30 import jalview.io.AppletFormatAdapter;
31 import jalview.io.JalviewFileChooser;
32 import jalview.io.JalviewFileView;
33 import jalview.schemes.BuriedColourScheme;
34 import jalview.schemes.ColourSchemeI;
35 import jalview.schemes.HelixColourScheme;
36 import jalview.schemes.HydrophobicColourScheme;
37 import jalview.schemes.PurinePyrimidineColourScheme;
38 import jalview.schemes.StrandColourScheme;
39 import jalview.schemes.TaylorColourScheme;
40 import jalview.schemes.TurnColourScheme;
41 import jalview.schemes.ZappoColourScheme;
42 import jalview.structures.models.AAStructureBindingModel;
43 import jalview.util.MessageManager;
44 import jalview.util.Platform;
46 import java.awt.BorderLayout;
47 import java.awt.Color;
48 import java.awt.Dimension;
50 import java.awt.Graphics;
51 import java.awt.Rectangle;
52 import java.awt.event.ActionEvent;
53 import java.awt.event.ActionListener;
54 import java.awt.event.ItemEvent;
55 import java.awt.event.ItemListener;
56 import java.io.BufferedReader;
58 import java.io.FileOutputStream;
59 import java.io.FileReader;
60 import java.io.IOException;
61 import java.io.PrintWriter;
62 import java.util.Vector;
64 import javax.swing.JCheckBoxMenuItem;
65 import javax.swing.JColorChooser;
66 import javax.swing.JInternalFrame;
67 import javax.swing.JMenu;
68 import javax.swing.JMenuItem;
69 import javax.swing.JOptionPane;
70 import javax.swing.JPanel;
71 import javax.swing.JSplitPane;
72 import javax.swing.event.InternalFrameAdapter;
73 import javax.swing.event.InternalFrameEvent;
74 import javax.swing.event.MenuEvent;
75 import javax.swing.event.MenuListener;
77 public class AppJmol extends StructureViewerBase
85 RenderPanel renderPanel;
87 private boolean addingStructures = false;
89 ViewSelectionMenu seqColourBy;
98 * - add the alignment panel to the list used for colouring these
101 * - add the alignment panel to the list used for aligning these
103 * @param leaveColouringToJmol
104 * - do not update the colours from any other source. Jmol is
110 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
111 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
112 boolean leaveColouringToJmol, String loadStatus,
113 Rectangle bounds, String viewid)
115 PDBEntry[] pdbentrys = new PDBEntry[files.length];
116 for (int i = 0; i < pdbentrys.length; i++)
118 // PDBEntry pdbentry = new PDBEntry(files[i], ids[i]);
119 PDBEntry pdbentry = new PDBEntry(ids[i], null, PDBEntry.Type.PDB,
121 pdbentrys[i] = pdbentry;
123 // / TODO: check if protocol is needed to be set, and if chains are
125 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
126 pdbentrys, seqs, null, null);
128 jmb.setLoadingFromArchive(true);
129 addAlignmentPanel(ap);
132 useAlignmentPanelForSuperposition(ap);
134 if (leaveColouringToJmol || !usetoColour)
136 jmb.setColourBySequence(false);
137 seqColour.setSelected(false);
138 viewerColour.setSelected(true);
140 else if (usetoColour)
142 useAlignmentPanelForColourbyseq(ap);
143 jmb.setColourBySequence(true);
144 seqColour.setSelected(true);
145 viewerColour.setSelected(false);
147 this.setBounds(bounds);
150 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
151 // bounds.width,bounds.height);
153 this.addInternalFrameListener(new InternalFrameAdapter()
156 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
161 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
165 private void initMenus()
167 seqColour.setSelected(jmb.isColourBySequence());
168 viewerColour.setSelected(!jmb.isColourBySequence());
169 if (_colourwith == null)
171 _colourwith = new Vector<AlignmentPanel>();
173 if (_alignwith == null)
175 _alignwith = new Vector<AlignmentPanel>();
178 seqColourBy = new ViewSelectionMenu(MessageManager.getString("label.colour_by"), this, _colourwith,
183 public void itemStateChanged(ItemEvent e)
185 if (!seqColour.isSelected())
191 // update the jmol display now.
192 seqColour_actionPerformed(null);
196 viewMenu.add(seqColourBy);
197 final ItemListener handler;
198 JMenu alpanels = new ViewSelectionMenu(MessageManager.getString("label.superpose_with"), this,
199 _alignwith, handler = new ItemListener()
203 public void itemStateChanged(ItemEvent e)
205 alignStructs.setEnabled(_alignwith.size() > 0);
206 alignStructs.setToolTipText(MessageManager
208 "label.align_structures_using_linked_alignment_views",
210 { new Integer(_alignwith.size()).toString() }));
213 handler.itemStateChanged(null);
214 viewerActionMenu.add(alpanels);
215 viewerActionMenu.addMenuListener(new MenuListener()
219 public void menuSelected(MenuEvent e)
221 handler.itemStateChanged(null);
225 public void menuDeselected(MenuEvent e)
227 // TODO Auto-generated method stub
232 public void menuCanceled(MenuEvent e)
234 // TODO Auto-generated method stub
240 IProgressIndicator progressBar = null;
243 * add a single PDB structure to a new or existing Jmol view
250 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
251 final AlignmentPanel ap)
253 progressBar = ap.alignFrame;
254 // ////////////////////////////////
255 // Is the pdb file already loaded?
256 String alreadyMapped = ap.getStructureSelectionManager()
257 .alreadyMappedToFile(pdbentry.getId());
259 if (alreadyMapped != null)
261 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
262 MessageManager.formatMessage(
263 "label.pdb_entry_is_already_displayed", new String[]
264 { pdbentry.getId() }), MessageManager.formatMessage(
265 "label.map_sequences_to_visible_window", new String[]
266 { pdbentry.getId() }),
267 JOptionPane.YES_NO_CANCEL_OPTION);
269 if (option == JOptionPane.CANCEL_OPTION)
273 if (option == JOptionPane.YES_OPTION)
275 // TODO : Fix multiple seq to one chain issue here.
276 ap.getStructureSelectionManager().setMapping(seq, chains,
277 alreadyMapped, AppletFormatAdapter.FILE);
278 if (ap.getSeqPanel().seqCanvas.fr != null)
280 ap.getSeqPanel().seqCanvas.fr.featuresAdded();
281 ap.paintAlignment(true);
284 // Now this AppJmol is mapped to new sequences. We must add them to
285 // the exisiting array
286 JInternalFrame[] frames = Desktop.instance.getAllFrames();
288 for (int i = 0; i < frames.length; i++)
290 if (frames[i] instanceof AppJmol)
292 final AppJmol topJmol = ((AppJmol) frames[i]);
293 // JBPNOTE: this looks like a binding routine, rather than a gui
295 for (int pe = 0; pe < topJmol.jmb.getPdbCount(); pe++)
297 if (topJmol.jmb.getPdbEntry(pe).getFile()
298 .equals(alreadyMapped))
300 topJmol.jmb.addSequence(pe, seq);
301 topJmol.addAlignmentPanel(ap);
302 // add it to the set used for colouring
303 topJmol.useAlignmentPanelForColourbyseq(ap);
304 topJmol.buildActionMenu();
305 ap.getStructureSelectionManager()
306 .sequenceColoursChanged(ap);
318 * Check if there are other Jmol views involving this alignment and prompt
319 * user about adding this molecule to one of them
321 for (AppJmol topJmol : getJmolsFor(ap))
323 // TODO: highlight topJmol in view somehow
324 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
325 MessageManager.formatMessage("label.add_pdbentry_to_view",
327 { pdbentry.getId(), topJmol.getTitle() }),
329 .getString("label.align_to_existing_structure_view"),
330 JOptionPane.YES_NO_CANCEL_OPTION);
331 if (option == JOptionPane.CANCEL_OPTION)
335 if (option == JOptionPane.YES_OPTION)
337 topJmol.useAlignmentPanelForSuperposition(ap);
338 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
342 // /////////////////////////////////
343 openNewJmol(ap, new PDBEntry[]
344 { pdbentry }, new SequenceI[][]
348 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
351 progressBar = ap.alignFrame;
352 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
353 pdbentrys, seqs, null, null);
354 addAlignmentPanel(ap);
355 useAlignmentPanelForColourbyseq(ap);
356 if (pdbentrys.length > 1)
358 alignAddedStructures = true;
359 useAlignmentPanelForSuperposition(ap);
361 jmb.setColourBySequence(true);
362 setSize(400, 400); // probably should be a configurable/dynamic default here
366 addingStructures = false;
367 worker = new Thread(this);
370 this.addInternalFrameListener(new InternalFrameAdapter()
373 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
382 * create a new Jmol containing several structures superimposed using the
389 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
391 openNewJmol(ap, pe, seqs);
395 * pdb retrieval thread.
397 private Thread worker = null;
400 * add a new structure (with associated sequences and chains) to this viewer,
401 * retrieving it if necessary first.
408 * if true, new structure(s) will be align using associated alignment
410 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
411 final String[] chains, final boolean b,
412 final IProgressIndicator alignFrame)
414 if (pdbentry.getFile() == null)
416 if (worker != null && worker.isAlive())
418 // a retrieval is in progress, wait around and add ourselves to the
420 new Thread(new Runnable()
424 while (worker != null && worker.isAlive() && _started)
428 Thread.sleep(100 + ((int) Math.random() * 100));
430 } catch (Exception e)
435 // and call ourselves again.
436 addStructure(pdbentry, seq, chains, b, alignFrame);
442 // otherwise, start adding the structure.
443 jmb.addSequenceAndChain(new PDBEntry[]
444 { pdbentry }, new SequenceI[][]
445 { seq }, new String[][]
447 addingStructures = true;
449 alignAddedStructures = b;
450 progressBar = alignFrame; // visual indication happens on caller frame.
451 (worker = new Thread(this)).start();
455 private Vector<AppJmol> getJmolsFor(AlignmentPanel apanel)
457 Vector<AppJmol> result = new Vector<AppJmol>();
458 JInternalFrame[] frames = Desktop.instance.getAllFrames();
460 for (JInternalFrame frame : frames)
462 if (frame instanceof AppJmol)
464 if (((AppJmol) frame).isLinkedWith(apanel))
466 result.addElement((AppJmol) frame);
473 void initJmol(String command)
475 jmb.setFinishedInit(false);
476 renderPanel = new RenderPanel();
477 // TODO: consider waiting until the structure/view is fully loaded before
479 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
480 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
481 getBounds().width, getBounds().height);
482 if (scriptWindow == null)
484 BorderLayout bl = new BorderLayout();
487 scriptWindow = new JPanel(bl);
488 scriptWindow.setVisible(false);
491 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
493 // jmb.newJmolPopup("Jmol");
498 jmb.evalStateCommand(command);
499 jmb.setFinishedInit(true);
502 void setChainMenuItems(Vector<String> chains)
504 chainMenu.removeAll();
509 JMenuItem menuItem = new JMenuItem(
510 MessageManager.getString("label.all"));
511 menuItem.addActionListener(new ActionListener()
513 public void actionPerformed(ActionEvent evt)
515 allChainsSelected = true;
516 for (int i = 0; i < chainMenu.getItemCount(); i++)
518 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
520 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
524 allChainsSelected = false;
528 chainMenu.add(menuItem);
530 for (String chain : chains)
532 menuItem = new JCheckBoxMenuItem(chain, true);
533 menuItem.addItemListener(new ItemListener()
535 public void itemStateChanged(ItemEvent evt)
537 if (!allChainsSelected)
544 chainMenu.add(menuItem);
548 boolean allChainsSelected = false;
550 private boolean alignAddedStructures = false;
554 Vector<String> toshow = new Vector<String>();
555 for (int i = 0; i < chainMenu.getItemCount(); i++)
557 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
559 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
560 if (item.isSelected())
562 toshow.addElement(item.getText());
566 jmb.centerViewer(toshow);
569 public void closeViewer(boolean closeExternalViewer)
571 // JMol does not use an external viewer
573 setAlignmentPanel(null);
577 // TODO: check for memory leaks where instance isn't finalised because jmb
578 // holds a reference to the window
583 * state flag for PDB retrieval thread
585 private boolean _started = false;
591 // todo - record which pdbids were successfuly imported.
592 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
595 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
596 // TODO: replace with reference fetching/transfer code (validate PDBentry
598 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
599 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
601 String file = jmb.getPdbEntry(pi).getFile();
604 // retrieve the pdb and store it locally
605 AlignmentI pdbseq = null;
606 pdbid = jmb.getPdbEntry(pi).getId();
607 long hdl = pdbid.hashCode() - System.currentTimeMillis();
608 if (progressBar != null)
610 progressBar.setProgressBar(MessageManager.formatMessage("status.fetching_pdb", new String[]{pdbid}), hdl);
614 pdbseq = pdbclient.getSequenceRecords(pdbid);
615 } catch (OutOfMemoryError oomerror)
617 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
618 } catch (Exception ex)
620 ex.printStackTrace();
621 errormsgs.append("'" + pdbid + "'");
623 if (progressBar != null)
625 progressBar.setProgressBar(MessageManager.getString("label.state_completed"), hdl);
629 // just transfer the file name from the first sequence's first
631 file = new File(pdbseq.getSequenceAt(0).getPDBId()
632 .elementAt(0).getFile()).getAbsolutePath();
633 jmb.getPdbEntry(pi).setFile(file);
635 files.append(" \"" + Platform.escapeString(file) + "\"");
639 errormsgs.append("'" + pdbid + "' ");
644 if (curfiles != null && curfiles.length > 0)
646 addingStructures = true; // already files loaded.
647 for (int c = 0; c < curfiles.length; c++)
649 if (curfiles[c].equals(file))
658 files.append(" \"" + Platform.escapeString(file) + "\"");
662 } catch (OutOfMemoryError oomerror)
664 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
665 } catch (Exception ex)
667 ex.printStackTrace();
668 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
671 if (errormsgs.length() > 0)
674 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
675 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
677 { errormsgs.toString() }), MessageManager
678 .getString("label.couldnt_load_file"),
679 JOptionPane.ERROR_MESSAGE);
682 long lastnotify = jmb.getLoadNotifiesHandled();
683 if (files.length() > 0)
685 if (!addingStructures)
690 initJmol("load FILES " + files.toString());
691 } catch (OutOfMemoryError oomerror)
693 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
694 Cache.log.debug("File locations are " + files);
695 } catch (Exception ex)
697 Cache.log.error("Couldn't open Jmol viewer!", ex);
702 StringBuffer cmd = new StringBuffer();
703 cmd.append("loadingJalviewdata=true\nload APPEND ");
704 cmd.append(files.toString());
705 cmd.append("\nloadingJalviewdata=null");
706 final String command = cmd.toString();
708 lastnotify = jmb.getLoadNotifiesHandled();
712 jmb.evalStateCommand(command);
713 } catch (OutOfMemoryError oomerror)
716 "When trying to add structures to the Jmol viewer!",
718 Cache.log.debug("File locations are " + files);
719 } catch (Exception ex)
721 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
725 // need to wait around until script has finished
726 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
727 : (!jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb
728 .getPdbFile().length != jmb.getPdbCount()))
732 Cache.log.debug("Waiting around for jmb notify.");
734 } catch (Exception e)
739 // refresh the sequence colours for the new structure(s)
740 for (AlignmentPanel ap : _colourwith)
742 jmb.updateColours(ap);
744 // do superposition if asked to
745 if (alignAddedStructures)
747 javax.swing.SwingUtilities.invokeLater(new Runnable()
751 alignStructs_withAllAlignPanels();
752 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
755 alignAddedStructures = false;
757 addingStructures = false;
765 public void pdbFile_actionPerformed(ActionEvent actionEvent)
767 JalviewFileChooser chooser = new JalviewFileChooser(
768 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
770 chooser.setFileView(new JalviewFileView());
771 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
772 chooser.setToolTipText(MessageManager.getString("action.save"));
774 int value = chooser.showSaveDialog(this);
776 if (value == JalviewFileChooser.APPROVE_OPTION)
778 BufferedReader in = null;
781 // TODO: cope with multiple PDB files in view
782 in = new BufferedReader(new FileReader(
783 jmb.getPdbFile()[0]));
784 File outFile = chooser.getSelectedFile();
786 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
788 while ((data = in.readLine()) != null)
790 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
796 } catch (Exception ex)
798 ex.printStackTrace();
806 } catch (IOException e)
816 public void viewMapping_actionPerformed(ActionEvent actionEvent)
818 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
821 cap.appendText(jmb.printMappings());
822 } catch (OutOfMemoryError e)
825 "composing sequence-structure alignments for display in text box.",
830 jalview.gui.Desktop.addInternalFrame(cap,
831 MessageManager.getString("label.pdb_sequence_mapping"), 550,
836 public void eps_actionPerformed(ActionEvent e)
838 makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
842 public void png_actionPerformed(ActionEvent e)
844 makePDBImage(jalview.util.ImageMaker.TYPE.PNG);
847 void makePDBImage(jalview.util.ImageMaker.TYPE type)
849 int width = getWidth();
850 int height = getHeight();
852 jalview.util.ImageMaker im;
854 if (type == jalview.util.ImageMaker.TYPE.PNG)
856 im = new jalview.util.ImageMaker(this,
857 jalview.util.ImageMaker.TYPE.PNG,
858 "Make PNG image from view", width, height, null, null);
860 else if (type == jalview.util.ImageMaker.TYPE.EPS)
862 im = new jalview.util.ImageMaker(this,
863 jalview.util.ImageMaker.TYPE.EPS,
864 "Make EPS file from view", width, height, null,
870 im = new jalview.util.ImageMaker(this,
871 jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
872 width, height, null, this.getTitle());
875 if (im.getGraphics() != null)
877 jmb.viewer.renderScreenImage(im.getGraphics(), width, height);
883 public void viewerColour_actionPerformed(ActionEvent actionEvent)
885 if (viewerColour.isSelected())
887 // disable automatic sequence colouring.
888 jmb.setColourBySequence(false);
893 public void seqColour_actionPerformed(ActionEvent actionEvent)
895 jmb.setColourBySequence(seqColour.isSelected());
896 if (_colourwith == null)
898 _colourwith = new Vector<AlignmentPanel>();
900 if (jmb.isColourBySequence())
902 if (!jmb.isLoadingFromArchive())
904 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
906 // Make the currently displayed alignment panel the associated view
907 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
910 // Set the colour using the current view for the associated alignframe
911 for (AlignmentPanel ap : _colourwith)
913 jmb.colourBySequence(ap);
919 public void chainColour_actionPerformed(ActionEvent actionEvent)
921 chainColour.setSelected(true);
926 public void chargeColour_actionPerformed(ActionEvent actionEvent)
928 chargeColour.setSelected(true);
929 jmb.colourByCharge();
933 public void zappoColour_actionPerformed(ActionEvent actionEvent)
935 zappoColour.setSelected(true);
936 jmb.setJalviewColourScheme(new ZappoColourScheme());
940 public void taylorColour_actionPerformed(ActionEvent actionEvent)
942 taylorColour.setSelected(true);
943 jmb.setJalviewColourScheme(new TaylorColourScheme());
947 public void hydroColour_actionPerformed(ActionEvent actionEvent)
949 hydroColour.setSelected(true);
950 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
954 public void helixColour_actionPerformed(ActionEvent actionEvent)
956 helixColour.setSelected(true);
957 jmb.setJalviewColourScheme(new HelixColourScheme());
961 public void strandColour_actionPerformed(ActionEvent actionEvent)
963 strandColour.setSelected(true);
964 jmb.setJalviewColourScheme(new StrandColourScheme());
968 public void turnColour_actionPerformed(ActionEvent actionEvent)
970 turnColour.setSelected(true);
971 jmb.setJalviewColourScheme(new TurnColourScheme());
975 public void buriedColour_actionPerformed(ActionEvent actionEvent)
977 buriedColour.setSelected(true);
978 jmb.setJalviewColourScheme(new BuriedColourScheme());
982 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
984 setJalviewColourScheme(new PurinePyrimidineColourScheme());
988 public void userColour_actionPerformed(ActionEvent actionEvent)
990 userColour.setSelected(true);
991 new UserDefinedColours(this, null);
995 public void backGround_actionPerformed(ActionEvent actionEvent)
997 java.awt.Color col = JColorChooser.showDialog(this,
998 MessageManager.getString("label.select_backgroud_colour"), null);
1001 jmb.setBackgroundColour(col);
1006 public void showHelp_actionPerformed(ActionEvent actionEvent)
1010 jalview.util.BrowserLauncher
1011 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1012 } catch (Exception ex)
1017 public void showConsole(boolean showConsole)
1022 if (splitPane == null)
1024 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1025 splitPane.setTopComponent(renderPanel);
1026 splitPane.setBottomComponent(scriptWindow);
1027 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1028 splitPane.setDividerLocation(getHeight() - 200);
1029 scriptWindow.setVisible(true);
1030 scriptWindow.validate();
1031 splitPane.validate();
1037 if (splitPane != null)
1039 splitPane.setVisible(false);
1044 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1050 class RenderPanel extends JPanel
1052 final Dimension currentSize = new Dimension();
1055 public void paintComponent(Graphics g)
1057 getSize(currentSize);
1059 if (jmb != null && jmb.fileLoadingError != null)
1061 g.setColor(Color.black);
1062 g.fillRect(0, 0, currentSize.width, currentSize.height);
1063 g.setColor(Color.white);
1064 g.setFont(new Font("Verdana", Font.BOLD, 14));
1065 g.drawString(MessageManager.getString("label.error_loading_file")
1066 + "...", 20, currentSize.height / 2);
1067 StringBuffer sb = new StringBuffer();
1069 for (int e = 0; e < jmb.getPdbCount(); e++)
1071 sb.append(jmb.getPdbEntry(e).getId());
1072 if (e < jmb.getPdbCount() - 1)
1077 if (e == jmb.getPdbCount() - 1 || sb.length() > 20)
1080 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1081 * g.getFontMetrics().getHeight());
1085 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1087 g.setColor(Color.black);
1088 g.fillRect(0, 0, currentSize.width, currentSize.height);
1089 g.setColor(Color.white);
1090 g.setFont(new Font("Verdana", Font.BOLD, 14));
1091 g.drawString(MessageManager.getString("label.retrieving_pdb_data"),
1092 20, currentSize.height / 2);
1096 jmb.viewer.renderScreenImage(g, currentSize.width,
1097 currentSize.height);
1102 public void updateTitleAndMenus()
1104 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1109 setChainMenuItems(jmb.chainNames);
1111 this.setTitle(jmb.getViewerTitle());
1112 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1114 viewerActionMenu.setVisible(true);
1116 if (!jmb.isLoadingFromArchive())
1118 seqColour_actionPerformed(null);
1126 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1130 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1132 alignStructs_withAllAlignPanels();
1135 private void alignStructs_withAllAlignPanels()
1137 if (getAlignmentPanel() == null)
1142 if (_alignwith.size() == 0)
1144 _alignwith.add(getAlignmentPanel());
1149 AlignmentI[] als = new Alignment[_alignwith.size()];
1150 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1151 int[] alm = new int[_alignwith.size()];
1154 for (AlignmentPanel ap : _alignwith)
1156 als[a] = ap.av.getAlignment();
1158 alc[a++] = ap.av.getColumnSelection();
1160 jmb.superposeStructures(als, alm, alc);
1161 } catch (Exception e)
1163 StringBuffer sp = new StringBuffer();
1164 for (AlignmentPanel ap : _alignwith)
1166 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1168 Cache.log.info("Couldn't align structures with the " + sp.toString()
1169 + "associated alignment panels.", e);
1175 public void setJalviewColourScheme(ColourSchemeI ucs)
1177 jmb.setJalviewColourScheme(ucs);
1184 * @return first alignment panel displaying given alignment, or the default
1187 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1189 for (AlignmentPanel ap : getAllAlignmentPanels())
1191 if (ap.av.getAlignment() == alignment)
1196 return getAlignmentPanel();
1200 public AAStructureBindingModel getBinding()
1206 public String getStateInfo()
1208 return jmb == null ? null : jmb.viewer.getStateInfo();
1212 public ViewerType getViewerType()
1214 return ViewerType.JMOL;