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.BrowserLauncher;
44 import jalview.util.ImageMaker;
45 import jalview.util.MessageManager;
46 import jalview.util.Platform;
47 import jalview.ws.dbsources.Pdb;
49 import java.awt.BorderLayout;
50 import java.awt.Color;
51 import java.awt.Dimension;
53 import java.awt.Graphics;
54 import java.awt.Rectangle;
55 import java.awt.event.ActionEvent;
56 import java.awt.event.ActionListener;
57 import java.awt.event.ItemEvent;
58 import java.awt.event.ItemListener;
59 import java.io.BufferedReader;
61 import java.io.FileOutputStream;
62 import java.io.FileReader;
63 import java.io.IOException;
64 import java.io.PrintWriter;
65 import java.util.Vector;
67 import javax.swing.JCheckBoxMenuItem;
68 import javax.swing.JColorChooser;
69 import javax.swing.JInternalFrame;
70 import javax.swing.JMenu;
71 import javax.swing.JMenuItem;
72 import javax.swing.JOptionPane;
73 import javax.swing.JPanel;
74 import javax.swing.JSplitPane;
75 import javax.swing.event.InternalFrameAdapter;
76 import javax.swing.event.InternalFrameEvent;
77 import javax.swing.event.MenuEvent;
78 import javax.swing.event.MenuListener;
80 public class AppJmol extends StructureViewerBase
88 RenderPanel renderPanel;
90 private boolean addingStructures = false;
92 ViewSelectionMenu seqColourBy;
101 * - add the alignment panel to the list used for colouring these
104 * - add the alignment panel to the list used for aligning these
106 * @param leaveColouringToJmol
107 * - do not update the colours from any other source. Jmol is
113 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
114 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
115 boolean leaveColouringToJmol, String loadStatus,
116 Rectangle bounds, String viewid)
118 PDBEntry[] pdbentrys = new PDBEntry[files.length];
119 for (int i = 0; i < pdbentrys.length; i++)
121 // PDBEntry pdbentry = new PDBEntry(files[i], ids[i]);
122 PDBEntry pdbentry = new PDBEntry(ids[i], null, PDBEntry.Type.PDB,
124 pdbentrys[i] = pdbentry;
126 // / TODO: check if protocol is needed to be set, and if chains are
128 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
129 pdbentrys, seqs, null, null);
131 jmb.setLoadingFromArchive(true);
132 addAlignmentPanel(ap);
135 useAlignmentPanelForSuperposition(ap);
137 if (leaveColouringToJmol || !usetoColour)
139 jmb.setColourBySequence(false);
140 seqColour.setSelected(false);
141 viewerColour.setSelected(true);
143 else if (usetoColour)
145 useAlignmentPanelForColourbyseq(ap);
146 jmb.setColourBySequence(true);
147 seqColour.setSelected(true);
148 viewerColour.setSelected(false);
150 this.setBounds(bounds);
153 // Desktop.addInternalFrame(this, "Loading File",
154 // bounds.width,bounds.height);
156 this.addInternalFrameListener(new InternalFrameAdapter()
159 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
164 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
168 private void initMenus()
170 seqColour.setSelected(jmb.isColourBySequence());
171 viewerColour.setSelected(!jmb.isColourBySequence());
172 if (_colourwith == null)
174 _colourwith = new Vector<AlignmentPanel>();
176 if (_alignwith == null)
178 _alignwith = new Vector<AlignmentPanel>();
181 seqColourBy = new ViewSelectionMenu(MessageManager.getString("label.colour_by"), this, _colourwith,
186 public void itemStateChanged(ItemEvent e)
188 if (!seqColour.isSelected())
194 // update the jmol display now.
195 seqColour_actionPerformed(null);
199 viewMenu.add(seqColourBy);
200 final ItemListener handler;
201 JMenu alpanels = new ViewSelectionMenu(MessageManager.getString("label.superpose_with"), this,
202 _alignwith, handler = new ItemListener()
206 public void itemStateChanged(ItemEvent e)
208 alignStructs.setEnabled(_alignwith.size() > 0);
209 alignStructs.setToolTipText(MessageManager
211 "label.align_structures_using_linked_alignment_views",
213 { new Integer(_alignwith.size()).toString() }));
216 handler.itemStateChanged(null);
217 viewerActionMenu.add(alpanels);
218 viewerActionMenu.addMenuListener(new MenuListener()
222 public void menuSelected(MenuEvent e)
224 handler.itemStateChanged(null);
228 public void menuDeselected(MenuEvent e)
230 // TODO Auto-generated method stub
235 public void menuCanceled(MenuEvent e)
237 // TODO Auto-generated method stub
243 IProgressIndicator progressBar = null;
246 * add a single PDB structure to a new or existing Jmol view
253 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
254 final AlignmentPanel ap)
256 progressBar = ap.alignFrame;
257 // ////////////////////////////////
258 // Is the pdb file already loaded?
259 String alreadyMapped = ap.getStructureSelectionManager()
260 .alreadyMappedToFile(pdbentry.getId());
262 if (alreadyMapped != null)
264 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
265 MessageManager.formatMessage(
266 "label.pdb_entry_is_already_displayed", new String[]
267 { pdbentry.getId() }), MessageManager.formatMessage(
268 "label.map_sequences_to_visible_window", new String[]
269 { pdbentry.getId() }),
270 JOptionPane.YES_NO_CANCEL_OPTION);
272 if (option == JOptionPane.CANCEL_OPTION)
276 if (option == JOptionPane.YES_OPTION)
278 // TODO : Fix multiple seq to one chain issue here.
279 ap.getStructureSelectionManager().setMapping(seq, chains,
280 alreadyMapped, AppletFormatAdapter.FILE);
281 if (ap.getSeqPanel().seqCanvas.fr != null)
283 ap.getSeqPanel().seqCanvas.fr.featuresAdded();
284 ap.paintAlignment(true);
287 // Now this AppJmol is mapped to new sequences. We must add them to
288 // the exisiting array
289 JInternalFrame[] frames = Desktop.instance.getAllFrames();
291 for (int i = 0; i < frames.length; i++)
293 if (frames[i] instanceof AppJmol)
295 final AppJmol topJmol = ((AppJmol) frames[i]);
296 // JBPNOTE: this looks like a binding routine, rather than a gui
298 for (int pe = 0; pe < topJmol.jmb.getPdbCount(); pe++)
300 if (topJmol.jmb.getPdbEntry(pe).getFile()
301 .equals(alreadyMapped))
303 topJmol.jmb.addSequence(pe, seq);
304 topJmol.addAlignmentPanel(ap);
305 // add it to the set used for colouring
306 topJmol.useAlignmentPanelForColourbyseq(ap);
307 topJmol.buildActionMenu();
308 ap.getStructureSelectionManager()
309 .sequenceColoursChanged(ap);
321 * Check if there are other Jmol views involving this alignment and prompt
322 * user about adding this molecule to one of them
324 for (AppJmol topJmol : getJmolsFor(ap))
326 // TODO: highlight topJmol in view somehow
327 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
328 MessageManager.formatMessage("label.add_pdbentry_to_view",
330 { pdbentry.getId(), topJmol.getTitle() }),
332 .getString("label.align_to_existing_structure_view"),
333 JOptionPane.YES_NO_CANCEL_OPTION);
334 if (option == JOptionPane.CANCEL_OPTION)
338 if (option == JOptionPane.YES_OPTION)
340 topJmol.useAlignmentPanelForSuperposition(ap);
341 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
345 // /////////////////////////////////
346 openNewJmol(ap, new PDBEntry[]
347 { pdbentry }, new SequenceI[][]
351 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
354 progressBar = ap.alignFrame;
355 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
356 pdbentrys, seqs, null, null);
357 addAlignmentPanel(ap);
358 useAlignmentPanelForColourbyseq(ap);
359 if (pdbentrys.length > 1)
361 alignAddedStructures = true;
362 useAlignmentPanelForSuperposition(ap);
364 jmb.setColourBySequence(true);
365 setSize(400, 400); // probably should be a configurable/dynamic default here
369 addingStructures = false;
370 worker = new Thread(this);
373 this.addInternalFrameListener(new InternalFrameAdapter()
376 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
385 * create a new Jmol containing several structures superimposed using the
392 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
394 openNewJmol(ap, pe, seqs);
398 * pdb retrieval thread.
400 private Thread worker = null;
403 * add a new structure (with associated sequences and chains) to this viewer,
404 * retrieving it if necessary first.
411 * if true, new structure(s) will be align using associated alignment
413 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
414 final String[] chains, final boolean b,
415 final IProgressIndicator alignFrame)
417 if (pdbentry.getFile() == null)
419 if (worker != null && worker.isAlive())
421 // a retrieval is in progress, wait around and add ourselves to the
423 new Thread(new Runnable()
427 while (worker != null && worker.isAlive() && _started)
431 Thread.sleep(100 + ((int) Math.random() * 100));
433 } catch (Exception e)
438 // and call ourselves again.
439 addStructure(pdbentry, seq, chains, b, alignFrame);
445 // otherwise, start adding the structure.
446 jmb.addSequenceAndChain(new PDBEntry[]
447 { pdbentry }, new SequenceI[][]
448 { seq }, new String[][]
450 addingStructures = true;
452 alignAddedStructures = b;
453 progressBar = alignFrame; // visual indication happens on caller frame.
454 (worker = new Thread(this)).start();
458 private Vector<AppJmol> getJmolsFor(AlignmentPanel apanel)
460 Vector<AppJmol> result = new Vector<AppJmol>();
461 JInternalFrame[] frames = Desktop.instance.getAllFrames();
463 for (JInternalFrame frame : frames)
465 if (frame instanceof AppJmol)
467 if (((AppJmol) frame).isLinkedWith(apanel))
469 result.addElement((AppJmol) frame);
476 void initJmol(String command)
478 jmb.setFinishedInit(false);
479 renderPanel = new RenderPanel();
480 // TODO: consider waiting until the structure/view is fully loaded before
482 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
483 Desktop.addInternalFrame(this, jmb.getViewerTitle(),
484 getBounds().width, getBounds().height);
485 if (scriptWindow == null)
487 BorderLayout bl = new BorderLayout();
490 scriptWindow = new JPanel(bl);
491 scriptWindow.setVisible(false);
494 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
496 // jmb.newJmolPopup("Jmol");
501 jmb.evalStateCommand(command);
502 jmb.setFinishedInit(true);
505 void setChainMenuItems(Vector<String> chains)
507 chainMenu.removeAll();
512 JMenuItem menuItem = new JMenuItem(
513 MessageManager.getString("label.all"));
514 menuItem.addActionListener(new ActionListener()
516 public void actionPerformed(ActionEvent evt)
518 allChainsSelected = true;
519 for (int i = 0; i < chainMenu.getItemCount(); i++)
521 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
523 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
527 allChainsSelected = false;
531 chainMenu.add(menuItem);
533 for (String chain : chains)
535 menuItem = new JCheckBoxMenuItem(chain, true);
536 menuItem.addItemListener(new ItemListener()
538 public void itemStateChanged(ItemEvent evt)
540 if (!allChainsSelected)
547 chainMenu.add(menuItem);
551 boolean allChainsSelected = false;
553 private boolean alignAddedStructures = false;
557 Vector<String> toshow = new Vector<String>();
558 for (int i = 0; i < chainMenu.getItemCount(); i++)
560 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
562 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
563 if (item.isSelected())
565 toshow.addElement(item.getText());
569 jmb.centerViewer(toshow);
572 public void closeViewer(boolean closeExternalViewer)
574 // JMol does not use an external viewer
576 setAlignmentPanel(null);
580 // TODO: check for memory leaks where instance isn't finalised because jmb
581 // holds a reference to the window
586 * state flag for PDB retrieval thread
588 private boolean _started = false;
594 // todo - record which pdbids were successfuly imported.
595 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
598 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
599 // TODO: replace with reference fetching/transfer code (validate PDBentry
601 Pdb pdbclient = new Pdb();
602 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
604 String file = jmb.getPdbEntry(pi).getFile();
607 // retrieve the pdb and store it locally
608 AlignmentI pdbseq = null;
609 pdbid = jmb.getPdbEntry(pi).getId();
610 long hdl = pdbid.hashCode() - System.currentTimeMillis();
611 if (progressBar != null)
613 progressBar.setProgressBar(MessageManager.formatMessage("status.fetching_pdb", new String[]{pdbid}), hdl);
617 pdbseq = pdbclient.getSequenceRecords(pdbid);
618 } catch (OutOfMemoryError oomerror)
620 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
621 } catch (Exception ex)
623 ex.printStackTrace();
624 errormsgs.append("'" + pdbid + "'");
626 if (progressBar != null)
628 progressBar.setProgressBar(MessageManager.getString("label.state_completed"), hdl);
632 // just transfer the file name from the first sequence's first
634 file = new File(pdbseq.getSequenceAt(0).getPDBId()
635 .elementAt(0).getFile()).getAbsolutePath();
636 jmb.getPdbEntry(pi).setFile(file);
638 files.append(" \"" + Platform.escapeString(file) + "\"");
642 errormsgs.append("'" + pdbid + "' ");
647 if (curfiles != null && curfiles.length > 0)
649 addingStructures = true; // already files loaded.
650 for (int c = 0; c < curfiles.length; c++)
652 if (curfiles[c].equals(file))
661 files.append(" \"" + Platform.escapeString(file) + "\"");
665 } catch (OutOfMemoryError oomerror)
667 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
668 } catch (Exception ex)
670 ex.printStackTrace();
671 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
674 if (errormsgs.length() > 0)
677 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
678 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
680 { errormsgs.toString() }), MessageManager
681 .getString("label.couldnt_load_file"),
682 JOptionPane.ERROR_MESSAGE);
685 long lastnotify = jmb.getLoadNotifiesHandled();
686 if (files.length() > 0)
688 if (!addingStructures)
693 initJmol("load FILES " + files.toString());
694 } catch (OutOfMemoryError oomerror)
696 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
697 Cache.log.debug("File locations are " + files);
698 } catch (Exception ex)
700 Cache.log.error("Couldn't open Jmol viewer!", ex);
705 StringBuffer cmd = new StringBuffer();
706 cmd.append("loadingJalviewdata=true\nload APPEND ");
707 cmd.append(files.toString());
708 cmd.append("\nloadingJalviewdata=null");
709 final String command = cmd.toString();
711 lastnotify = jmb.getLoadNotifiesHandled();
715 jmb.evalStateCommand(command);
716 } catch (OutOfMemoryError oomerror)
719 "When trying to add structures to the Jmol viewer!",
721 Cache.log.debug("File locations are " + files);
722 } catch (Exception ex)
724 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
728 // need to wait around until script has finished
729 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
730 : (!jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb
731 .getPdbFile().length != jmb.getPdbCount()))
735 Cache.log.debug("Waiting around for jmb notify.");
737 } catch (Exception e)
742 // refresh the sequence colours for the new structure(s)
743 for (AlignmentPanel ap : _colourwith)
745 jmb.updateColours(ap);
747 // do superposition if asked to
748 if (alignAddedStructures)
750 javax.swing.SwingUtilities.invokeLater(new Runnable()
754 alignStructs_withAllAlignPanels();
755 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
758 alignAddedStructures = false;
760 addingStructures = false;
768 public void pdbFile_actionPerformed(ActionEvent actionEvent)
770 JalviewFileChooser chooser = new JalviewFileChooser(
771 Cache.getProperty("LAST_DIRECTORY"));
773 chooser.setFileView(new JalviewFileView());
774 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
775 chooser.setToolTipText(MessageManager.getString("action.save"));
777 int value = chooser.showSaveDialog(this);
779 if (value == JalviewFileChooser.APPROVE_OPTION)
781 BufferedReader in = null;
784 // TODO: cope with multiple PDB files in view
785 in = new BufferedReader(new FileReader(
786 jmb.getPdbFile()[0]));
787 File outFile = chooser.getSelectedFile();
789 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
791 while ((data = in.readLine()) != null)
793 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
799 } catch (Exception ex)
801 ex.printStackTrace();
809 } catch (IOException e)
819 public void viewMapping_actionPerformed(ActionEvent actionEvent)
821 CutAndPasteTransfer cap = new CutAndPasteTransfer();
824 cap.appendText(jmb.printMappings());
825 } catch (OutOfMemoryError e)
828 "composing sequence-structure alignments for display in text box.",
833 Desktop.addInternalFrame(cap,
834 MessageManager.getString("label.pdb_sequence_mapping"), 550,
839 public void eps_actionPerformed(ActionEvent e)
841 makePDBImage(ImageMaker.TYPE.EPS);
845 public void png_actionPerformed(ActionEvent e)
847 makePDBImage(ImageMaker.TYPE.PNG);
850 void makePDBImage(ImageMaker.TYPE type)
852 int width = getWidth();
853 int height = getHeight();
857 if (type == ImageMaker.TYPE.PNG)
859 im = new ImageMaker(this, ImageMaker.TYPE.PNG,
860 "Make PNG image from view", width, height, null, null);
862 else if (type == ImageMaker.TYPE.EPS)
864 im = new ImageMaker(this, ImageMaker.TYPE.EPS,
865 "Make EPS file from view", width, height, null,
871 im = new ImageMaker(this, ImageMaker.TYPE.SVG,
872 "Make SVG file from PCA",
873 width, height, null, this.getTitle());
876 if (im.getGraphics() != null)
878 jmb.viewer.renderScreenImage(im.getGraphics(), width, height);
884 public void viewerColour_actionPerformed(ActionEvent actionEvent)
886 if (viewerColour.isSelected())
888 // disable automatic sequence colouring.
889 jmb.setColourBySequence(false);
894 public void seqColour_actionPerformed(ActionEvent actionEvent)
896 jmb.setColourBySequence(seqColour.isSelected());
897 if (_colourwith == null)
899 _colourwith = new Vector<AlignmentPanel>();
901 if (jmb.isColourBySequence())
903 if (!jmb.isLoadingFromArchive())
905 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
907 // Make the currently displayed alignment panel the associated view
908 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
911 // Set the colour using the current view for the associated alignframe
912 for (AlignmentPanel ap : _colourwith)
914 jmb.colourBySequence(ap);
920 public void chainColour_actionPerformed(ActionEvent actionEvent)
922 chainColour.setSelected(true);
927 public void chargeColour_actionPerformed(ActionEvent actionEvent)
929 chargeColour.setSelected(true);
930 jmb.colourByCharge();
934 public void zappoColour_actionPerformed(ActionEvent actionEvent)
936 zappoColour.setSelected(true);
937 jmb.setJalviewColourScheme(new ZappoColourScheme());
941 public void taylorColour_actionPerformed(ActionEvent actionEvent)
943 taylorColour.setSelected(true);
944 jmb.setJalviewColourScheme(new TaylorColourScheme());
948 public void hydroColour_actionPerformed(ActionEvent actionEvent)
950 hydroColour.setSelected(true);
951 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
955 public void helixColour_actionPerformed(ActionEvent actionEvent)
957 helixColour.setSelected(true);
958 jmb.setJalviewColourScheme(new HelixColourScheme());
962 public void strandColour_actionPerformed(ActionEvent actionEvent)
964 strandColour.setSelected(true);
965 jmb.setJalviewColourScheme(new StrandColourScheme());
969 public void turnColour_actionPerformed(ActionEvent actionEvent)
971 turnColour.setSelected(true);
972 jmb.setJalviewColourScheme(new TurnColourScheme());
976 public void buriedColour_actionPerformed(ActionEvent actionEvent)
978 buriedColour.setSelected(true);
979 jmb.setJalviewColourScheme(new BuriedColourScheme());
983 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
985 setJalviewColourScheme(new PurinePyrimidineColourScheme());
989 public void userColour_actionPerformed(ActionEvent actionEvent)
991 userColour.setSelected(true);
992 new UserDefinedColours(this, null);
996 public void backGround_actionPerformed(ActionEvent actionEvent)
998 java.awt.Color col = JColorChooser.showDialog(this,
999 MessageManager.getString("label.select_backgroud_colour"), null);
1002 jmb.setBackgroundColour(col);
1007 public void showHelp_actionPerformed(ActionEvent actionEvent)
1012 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1013 } catch (Exception ex)
1018 public void showConsole(boolean showConsole)
1023 if (splitPane == null)
1025 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1026 splitPane.setTopComponent(renderPanel);
1027 splitPane.setBottomComponent(scriptWindow);
1028 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1029 splitPane.setDividerLocation(getHeight() - 200);
1030 scriptWindow.setVisible(true);
1031 scriptWindow.validate();
1032 splitPane.validate();
1038 if (splitPane != null)
1040 splitPane.setVisible(false);
1045 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1051 class RenderPanel extends JPanel
1053 final Dimension currentSize = new Dimension();
1056 public void paintComponent(Graphics g)
1058 getSize(currentSize);
1060 if (jmb != null && jmb.fileLoadingError != null)
1062 g.setColor(Color.black);
1063 g.fillRect(0, 0, currentSize.width, currentSize.height);
1064 g.setColor(Color.white);
1065 g.setFont(new Font("Verdana", Font.BOLD, 14));
1066 g.drawString(MessageManager.getString("label.error_loading_file")
1067 + "...", 20, currentSize.height / 2);
1068 StringBuffer sb = new StringBuffer();
1070 for (int e = 0; e < jmb.getPdbCount(); e++)
1072 sb.append(jmb.getPdbEntry(e).getId());
1073 if (e < jmb.getPdbCount() - 1)
1078 if (e == jmb.getPdbCount() - 1 || sb.length() > 20)
1081 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1082 * g.getFontMetrics().getHeight());
1086 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1088 g.setColor(Color.black);
1089 g.fillRect(0, 0, currentSize.width, currentSize.height);
1090 g.setColor(Color.white);
1091 g.setFont(new Font("Verdana", Font.BOLD, 14));
1092 g.drawString(MessageManager.getString("label.retrieving_pdb_data"),
1093 20, currentSize.height / 2);
1097 jmb.viewer.renderScreenImage(g, currentSize.width,
1098 currentSize.height);
1103 public void updateTitleAndMenus()
1105 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1110 setChainMenuItems(jmb.chainNames);
1112 this.setTitle(jmb.getViewerTitle());
1113 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1115 viewerActionMenu.setVisible(true);
1117 if (!jmb.isLoadingFromArchive())
1119 seqColour_actionPerformed(null);
1127 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1131 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1133 alignStructs_withAllAlignPanels();
1136 private void alignStructs_withAllAlignPanels()
1138 if (getAlignmentPanel() == null)
1143 if (_alignwith.size() == 0)
1145 _alignwith.add(getAlignmentPanel());
1150 AlignmentI[] als = new Alignment[_alignwith.size()];
1151 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1152 int[] alm = new int[_alignwith.size()];
1155 for (AlignmentPanel ap : _alignwith)
1157 als[a] = ap.av.getAlignment();
1159 alc[a++] = ap.av.getColumnSelection();
1161 jmb.superposeStructures(als, alm, alc);
1162 } catch (Exception e)
1164 StringBuffer sp = new StringBuffer();
1165 for (AlignmentPanel ap : _alignwith)
1167 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1169 Cache.log.info("Couldn't align structures with the " + sp.toString()
1170 + "associated alignment panels.", e);
1176 public void setJalviewColourScheme(ColourSchemeI ucs)
1178 jmb.setJalviewColourScheme(ucs);
1185 * @return first alignment panel displaying given alignment, or the default
1188 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1190 for (AlignmentPanel ap : getAllAlignmentPanels())
1192 if (ap.av.getAlignment() == alignment)
1197 return getAlignmentPanel();
1201 public AAStructureBindingModel getBinding()
1207 public String getStateInfo()
1209 return jmb == null ? null : jmb.viewer.getStateInfo();
1213 public ViewerType getViewerType()
1215 return ViewerType.JMOL;