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.PrintWriter;
61 import java.util.Enumeration;
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 Vector atomsPicked = new Vector();
89 private boolean addingStructures = false;
99 * @deprecated defaults to AppJmol(String[] files, ... , viewid);
102 public AppJmol(String file, String id, SequenceI[] seq,
103 AlignmentPanel ap, String loadStatus, Rectangle bounds)
105 this(file, id, seq, ap, loadStatus, bounds, null);
112 public AppJmol(String file, String id, SequenceI[] seq,
113 AlignmentPanel ap, String loadStatus, Rectangle bounds,
117 { file }, new String[]
118 { id }, new SequenceI[][]
119 { seq }, ap, true, true, false, loadStatus, bounds, viewid);
122 ViewSelectionMenu seqColourBy;
131 * - add the alignment panel to the list used for colouring these
134 * - add the alignment panel to the list used for aligning these
136 * @param leaveColouringToJmol
137 * - do not update the colours from any other source. Jmol is
143 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
144 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
145 boolean leaveColouringToJmol, String loadStatus,
146 Rectangle bounds, String viewid)
148 PDBEntry[] pdbentrys = new PDBEntry[files.length];
149 for (int i = 0; i < pdbentrys.length; i++)
151 // PDBEntry pdbentry = new PDBEntry(files[i], ids[i]);
152 PDBEntry pdbentry = new PDBEntry(ids[i], null, PDBEntry.Type.PDB,
154 pdbentrys[i] = pdbentry;
156 // / TODO: check if protocol is needed to be set, and if chains are
158 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
159 pdbentrys, seqs, null, null);
161 jmb.setLoadingFromArchive(true);
162 addAlignmentPanel(ap);
165 useAlignmentPanelForSuperposition(ap);
167 if (leaveColouringToJmol || !usetoColour)
169 jmb.setColourBySequence(false);
170 seqColour.setSelected(false);
171 viewerColour.setSelected(true);
173 else if (usetoColour)
175 useAlignmentPanelForColourbyseq(ap);
176 jmb.setColourBySequence(true);
177 seqColour.setSelected(true);
178 viewerColour.setSelected(false);
180 this.setBounds(bounds);
183 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
184 // bounds.width,bounds.height);
186 this.addInternalFrameListener(new InternalFrameAdapter()
189 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
194 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
198 private void initMenus()
200 seqColour.setSelected(jmb.isColourBySequence());
201 viewerColour.setSelected(!jmb.isColourBySequence());
202 if (_colourwith == null)
204 _colourwith = new Vector<AlignmentPanel>();
206 if (_alignwith == null)
208 _alignwith = new Vector<AlignmentPanel>();
211 seqColourBy = new ViewSelectionMenu(MessageManager.getString("label.colour_by"), this, _colourwith,
216 public void itemStateChanged(ItemEvent e)
218 if (!seqColour.isSelected())
224 // update the jmol display now.
225 seqColour_actionPerformed(null);
229 viewMenu.add(seqColourBy);
230 final ItemListener handler;
231 JMenu alpanels = new ViewSelectionMenu(MessageManager.getString("label.superpose_with"), this,
232 _alignwith, handler = new ItemListener()
236 public void itemStateChanged(ItemEvent e)
238 alignStructs.setEnabled(_alignwith.size() > 0);
239 alignStructs.setToolTipText(MessageManager
241 "label.align_structures_using_linked_alignment_views",
243 { new Integer(_alignwith.size()).toString() }));
246 handler.itemStateChanged(null);
247 viewerActionMenu.add(alpanels);
248 viewerActionMenu.addMenuListener(new MenuListener()
252 public void menuSelected(MenuEvent e)
254 handler.itemStateChanged(null);
258 public void menuDeselected(MenuEvent e)
260 // TODO Auto-generated method stub
265 public void menuCanceled(MenuEvent e)
267 // TODO Auto-generated method stub
273 IProgressIndicator progressBar = null;
276 * add a single PDB structure to a new or existing Jmol view
283 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
284 final AlignmentPanel ap)
286 progressBar = ap.alignFrame;
287 // ////////////////////////////////
288 // Is the pdb file already loaded?
289 String alreadyMapped = ap.getStructureSelectionManager()
290 .alreadyMappedToFile(pdbentry.getId());
292 if (alreadyMapped != null)
294 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
295 MessageManager.formatMessage(
296 "label.pdb_entry_is_already_displayed", new String[]
297 { pdbentry.getId() }), MessageManager.formatMessage(
298 "label.map_sequences_to_visible_window", new String[]
299 { pdbentry.getId() }),
300 JOptionPane.YES_NO_CANCEL_OPTION);
302 if (option == JOptionPane.CANCEL_OPTION)
306 if (option == JOptionPane.YES_OPTION)
308 // TODO : Fix multiple seq to one chain issue here.
309 ap.getStructureSelectionManager().setMapping(seq, chains,
310 alreadyMapped, AppletFormatAdapter.FILE);
311 if (ap.getSeqPanel().seqCanvas.fr != null)
313 ap.getSeqPanel().seqCanvas.fr.featuresAdded();
314 ap.paintAlignment(true);
317 // Now this AppJmol is mapped to new sequences. We must add them to
318 // the exisiting array
319 JInternalFrame[] frames = Desktop.instance.getAllFrames();
321 for (int i = 0; i < frames.length; i++)
323 if (frames[i] instanceof AppJmol)
325 final AppJmol topJmol = ((AppJmol) frames[i]);
326 // JBPNOTE: this looks like a binding routine, rather than a gui
328 for (int pe = 0; pe < topJmol.jmb.getPdbCount(); pe++)
330 if (topJmol.jmb.getPdbEntry(pe).getFile()
331 .equals(alreadyMapped))
333 topJmol.jmb.addSequence(pe, seq);
334 topJmol.addAlignmentPanel(ap);
335 // add it to the set used for colouring
336 topJmol.useAlignmentPanelForColourbyseq(ap);
337 topJmol.buildActionMenu();
338 ap.getStructureSelectionManager()
339 .sequenceColoursChanged(ap);
349 // /////////////////////////////////
350 // Check if there are other Jmol views involving this alignment
351 // and prompt user about adding this molecule to one of them
352 Vector existingViews = getJmolsFor(ap);
353 if (existingViews.size() > 0)
355 Enumeration jm = existingViews.elements();
356 while (jm.hasMoreElements())
358 AppJmol topJmol = (AppJmol) jm.nextElement();
359 // TODO: highlight topJmol in view somehow
360 int option = JOptionPane
361 .showInternalConfirmDialog(
363 MessageManager.formatMessage(
364 "label.add_pdbentry_to_view", new String[]
365 { pdbentry.getId(), topJmol.getTitle() }),
367 .getString("label.align_to_existing_structure_view"),
368 JOptionPane.YES_NO_CANCEL_OPTION);
369 if (option == JOptionPane.CANCEL_OPTION)
373 if (option == JOptionPane.YES_OPTION)
375 topJmol.useAlignmentPanelForSuperposition(ap);
376 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
381 // /////////////////////////////////
382 openNewJmol(ap, new PDBEntry[]
383 { pdbentry }, new SequenceI[][]
387 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
390 progressBar = ap.alignFrame;
391 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
392 pdbentrys, seqs, null, null);
393 addAlignmentPanel(ap);
394 useAlignmentPanelForColourbyseq(ap);
395 if (pdbentrys.length > 1)
397 alignAddedStructures = true;
398 useAlignmentPanelForSuperposition(ap);
400 jmb.setColourBySequence(true);
401 setSize(400, 400); // probably should be a configurable/dynamic default here
405 addingStructures = false;
406 worker = new Thread(this);
409 this.addInternalFrameListener(new InternalFrameAdapter()
412 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
421 * create a new Jmol containing several structures superimposed using the
428 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
430 openNewJmol(ap, pe, seqs);
434 * pdb retrieval thread.
436 private Thread worker = null;
439 * add a new structure (with associated sequences and chains) to this viewer,
440 * retrieving it if necessary first.
447 * if true, new structure(s) will be align using associated alignment
449 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
450 final String[] chains, final boolean b,
451 final IProgressIndicator alignFrame)
453 if (pdbentry.getFile() == null)
455 if (worker != null && worker.isAlive())
457 // a retrieval is in progress, wait around and add ourselves to the
459 new Thread(new Runnable()
463 while (worker != null && worker.isAlive() && _started)
467 Thread.sleep(100 + ((int) Math.random() * 100));
469 } catch (Exception e)
474 // and call ourselves again.
475 addStructure(pdbentry, seq, chains, b, alignFrame);
481 // otherwise, start adding the structure.
482 jmb.addSequenceAndChain(new PDBEntry[]
483 { pdbentry }, new SequenceI[][]
484 { seq }, new String[][]
486 addingStructures = true;
488 alignAddedStructures = b;
489 progressBar = alignFrame; // visual indication happens on caller frame.
490 (worker = new Thread(this)).start();
494 private Vector getJmolsFor(AlignmentPanel apanel)
496 Vector result = new Vector();
497 JInternalFrame[] frames = Desktop.instance.getAllFrames();
499 for (JInternalFrame frame : frames)
501 if (frame instanceof AppJmol)
503 if (((StructureViewerBase) frame).isLinkedWith(apanel))
505 result.addElement(frame);
512 void initJmol(String command)
514 jmb.setFinishedInit(false);
515 renderPanel = new RenderPanel();
516 // TODO: consider waiting until the structure/view is fully loaded before
518 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
519 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
520 getBounds().width, getBounds().height);
521 if (scriptWindow == null)
523 BorderLayout bl = new BorderLayout();
526 scriptWindow = new JPanel(bl);
527 scriptWindow.setVisible(false);
530 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
532 jmb.newJmolPopup("Jmol");
537 jmb.evalStateCommand(command);
538 jmb.setFinishedInit(true);
541 void setChainMenuItems(Vector chains)
543 chainMenu.removeAll();
548 JMenuItem menuItem = new JMenuItem(
549 MessageManager.getString("label.all"));
550 menuItem.addActionListener(new ActionListener()
552 public void actionPerformed(ActionEvent evt)
554 allChainsSelected = true;
555 for (int i = 0; i < chainMenu.getItemCount(); i++)
557 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
559 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
563 allChainsSelected = false;
567 chainMenu.add(menuItem);
569 for (int c = 0; c < chains.size(); c++)
571 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
572 menuItem.addItemListener(new ItemListener()
574 public void itemStateChanged(ItemEvent evt)
576 if (!allChainsSelected)
583 chainMenu.add(menuItem);
587 boolean allChainsSelected = false;
589 private boolean alignAddedStructures = false;
593 Vector toshow = new Vector();
595 int mlength, p, mnum;
596 for (int i = 0; i < chainMenu.getItemCount(); i++)
598 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
600 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
601 if (item.isSelected())
603 toshow.addElement(item.getText());
607 jmb.centerViewer(toshow);
610 public void closeViewer(boolean closeExternalViewer)
612 // JMol does not use an external viewer
614 setAlignmentPanel(null);
618 // TODO: check for memory leaks where instance isn't finalised because jmb
619 // holds a reference to the window
624 * state flag for PDB retrieval thread
626 private boolean _started = false;
632 // todo - record which pdbids were successfuly imported.
633 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
636 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
637 // TODO: replace with reference fetching/transfer code (validate PDBentry
639 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
640 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
642 String file = jmb.getPdbEntry(pi).getFile();
645 // retrieve the pdb and store it locally
646 AlignmentI pdbseq = null;
647 pdbid = jmb.getPdbEntry(pi).getId();
648 long hdl = pdbid.hashCode() - System.currentTimeMillis();
649 if (progressBar != null)
651 progressBar.setProgressBar(MessageManager.formatMessage("status.fetching_pdb", new String[]{pdbid}), hdl);
655 pdbseq = pdbclient.getSequenceRecords(pdbid);
656 } catch (OutOfMemoryError oomerror)
658 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
659 } catch (Exception ex)
661 ex.printStackTrace();
662 errormsgs.append("'" + pdbid + "'");
664 if (progressBar != null)
666 progressBar.setProgressBar(MessageManager.getString("label.state_completed"), hdl);
670 // just transfer the file name from the first sequence's first
672 file = new File(pdbseq.getSequenceAt(0).getPDBId()
673 .elementAt(0).getFile()).getAbsolutePath();
674 jmb.getPdbEntry(pi).setFile(file);
676 files.append(" \"" + Platform.escapeString(file) + "\"");
680 errormsgs.append("'" + pdbid + "' ");
685 if (curfiles != null && curfiles.length > 0)
687 addingStructures = true; // already files loaded.
688 for (int c = 0; c < curfiles.length; c++)
690 if (curfiles[c].equals(file))
699 files.append(" \"" + Platform.escapeString(file) + "\"");
703 } catch (OutOfMemoryError oomerror)
705 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
706 } catch (Exception ex)
708 ex.printStackTrace();
709 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
712 if (errormsgs.length() > 0)
715 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
716 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
718 { errormsgs.toString() }), MessageManager
719 .getString("label.couldnt_load_file"),
720 JOptionPane.ERROR_MESSAGE);
723 long lastnotify = jmb.getLoadNotifiesHandled();
724 if (files.length() > 0)
726 if (!addingStructures)
731 initJmol("load FILES " + files.toString());
732 } catch (OutOfMemoryError oomerror)
734 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
735 Cache.log.debug("File locations are " + files);
736 } catch (Exception ex)
738 Cache.log.error("Couldn't open Jmol viewer!", ex);
743 StringBuffer cmd = new StringBuffer();
744 cmd.append("loadingJalviewdata=true\nload APPEND ");
745 cmd.append(files.toString());
746 cmd.append("\nloadingJalviewdata=null");
747 final String command = cmd.toString();
749 lastnotify = jmb.getLoadNotifiesHandled();
753 jmb.evalStateCommand(command);
754 } catch (OutOfMemoryError oomerror)
757 "When trying to add structures to the Jmol viewer!",
759 Cache.log.debug("File locations are " + files);
760 } catch (Exception ex)
762 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
766 // need to wait around until script has finished
767 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
768 : (jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb
769 .getPdbFile().length != jmb.getPdbCount()))
773 Cache.log.debug("Waiting around for jmb notify.");
775 } catch (Exception e)
779 // refresh the sequence colours for the new structure(s)
780 for (AlignmentPanel ap : _colourwith)
782 jmb.updateColours(ap);
784 // do superposition if asked to
785 if (alignAddedStructures)
787 javax.swing.SwingUtilities.invokeLater(new Runnable()
791 alignStructs_withAllAlignPanels();
792 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
795 alignAddedStructures = false;
797 addingStructures = false;
805 public void pdbFile_actionPerformed(ActionEvent actionEvent)
807 JalviewFileChooser chooser = new JalviewFileChooser(
808 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
810 chooser.setFileView(new JalviewFileView());
811 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
812 chooser.setToolTipText(MessageManager.getString("action.save"));
814 int value = chooser.showSaveDialog(this);
816 if (value == JalviewFileChooser.APPROVE_OPTION)
820 // TODO: cope with multiple PDB files in view
821 BufferedReader in = new BufferedReader(new FileReader(
822 jmb.getPdbFile()[0]));
823 File outFile = chooser.getSelectedFile();
825 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
827 while ((data = in.readLine()) != null)
829 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
835 } catch (Exception ex)
837 ex.printStackTrace();
843 public void viewMapping_actionPerformed(ActionEvent actionEvent)
845 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
848 cap.appendText(jmb.printMappings());
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 jmb.viewer.renderScreenImage(im.getGraphics(), width, height);
910 public void viewerColour_actionPerformed(ActionEvent actionEvent)
912 if (viewerColour.isSelected())
914 // disable automatic sequence colouring.
915 jmb.setColourBySequence(false);
920 public void seqColour_actionPerformed(ActionEvent actionEvent)
922 jmb.setColourBySequence(seqColour.isSelected());
923 if (_colourwith == null)
925 _colourwith = new Vector<AlignmentPanel>();
927 if (jmb.isColourBySequence())
929 if (!jmb.isLoadingFromArchive())
931 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
933 // Make the currently displayed alignment panel the associated view
934 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
937 // Set the colour using the current view for the associated alignframe
938 for (AlignmentPanel ap : _colourwith)
940 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
946 public void chainColour_actionPerformed(ActionEvent actionEvent)
948 chainColour.setSelected(true);
953 public void chargeColour_actionPerformed(ActionEvent actionEvent)
955 chargeColour.setSelected(true);
956 jmb.colourByCharge();
960 public void zappoColour_actionPerformed(ActionEvent actionEvent)
962 zappoColour.setSelected(true);
963 jmb.setJalviewColourScheme(new ZappoColourScheme());
967 public void taylorColour_actionPerformed(ActionEvent actionEvent)
969 taylorColour.setSelected(true);
970 jmb.setJalviewColourScheme(new TaylorColourScheme());
974 public void hydroColour_actionPerformed(ActionEvent actionEvent)
976 hydroColour.setSelected(true);
977 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
981 public void helixColour_actionPerformed(ActionEvent actionEvent)
983 helixColour.setSelected(true);
984 jmb.setJalviewColourScheme(new HelixColourScheme());
988 public void strandColour_actionPerformed(ActionEvent actionEvent)
990 strandColour.setSelected(true);
991 jmb.setJalviewColourScheme(new StrandColourScheme());
995 public void turnColour_actionPerformed(ActionEvent actionEvent)
997 turnColour.setSelected(true);
998 jmb.setJalviewColourScheme(new TurnColourScheme());
1002 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1004 buriedColour.setSelected(true);
1005 jmb.setJalviewColourScheme(new BuriedColourScheme());
1009 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1011 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1015 public void userColour_actionPerformed(ActionEvent actionEvent)
1017 userColour.setSelected(true);
1018 new UserDefinedColours(this, null);
1022 public void backGround_actionPerformed(ActionEvent actionEvent)
1024 java.awt.Color col = JColorChooser.showDialog(this,
1025 MessageManager.getString("label.select_backgroud_colour"), null);
1028 jmb.setBackgroundColour(col);
1033 public void showHelp_actionPerformed(ActionEvent actionEvent)
1037 jalview.util.BrowserLauncher
1038 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1039 } catch (Exception ex)
1044 public void showConsole(boolean showConsole)
1049 if (splitPane == null)
1051 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1052 splitPane.setTopComponent(renderPanel);
1053 splitPane.setBottomComponent(scriptWindow);
1054 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1055 splitPane.setDividerLocation(getHeight() - 200);
1056 scriptWindow.setVisible(true);
1057 scriptWindow.validate();
1058 splitPane.validate();
1064 if (splitPane != null)
1066 splitPane.setVisible(false);
1071 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1077 class RenderPanel extends JPanel
1079 final Dimension currentSize = new Dimension();
1082 public void paintComponent(Graphics g)
1084 getSize(currentSize);
1086 if (jmb != null && jmb.fileLoadingError != null)
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.error_loading_file")
1093 + "...", 20, currentSize.height / 2);
1094 StringBuffer sb = new StringBuffer();
1096 for (int e = 0; e < jmb.getPdbCount(); e++)
1098 sb.append(jmb.getPdbEntry(e).getId());
1099 if (e < jmb.getPdbCount() - 1)
1104 if (e == jmb.getPdbCount() - 1 || sb.length() > 20)
1107 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1108 * g.getFontMetrics().getHeight());
1112 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1114 g.setColor(Color.black);
1115 g.fillRect(0, 0, currentSize.width, currentSize.height);
1116 g.setColor(Color.white);
1117 g.setFont(new Font("Verdana", Font.BOLD, 14));
1118 g.drawString(MessageManager.getString("label.retrieving_pdb_data"),
1119 20, currentSize.height / 2);
1123 jmb.viewer.renderScreenImage(g, currentSize.width,
1124 currentSize.height);
1129 public void updateTitleAndMenus()
1131 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1136 setChainMenuItems(jmb.chainNames);
1138 this.setTitle(jmb.getViewerTitle());
1139 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1141 viewerActionMenu.setVisible(true);
1143 if (!jmb.isLoadingFromArchive())
1145 seqColour_actionPerformed(null);
1153 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1157 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1159 alignStructs_withAllAlignPanels();
1162 private void alignStructs_withAllAlignPanels()
1164 if (getAlignmentPanel() == null)
1169 if (_alignwith.size() == 0)
1171 _alignwith.add(getAlignmentPanel());
1176 AlignmentI[] als = new Alignment[_alignwith.size()];
1177 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1178 int[] alm = new int[_alignwith.size()];
1181 for (AlignmentPanel ap : _alignwith)
1183 als[a] = ap.av.getAlignment();
1185 alc[a++] = ap.av.getColumnSelection();
1187 jmb.superposeStructures(als, alm, alc);
1188 } catch (Exception e)
1190 StringBuffer sp = new StringBuffer();
1191 for (AlignmentPanel ap : _alignwith)
1193 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1195 Cache.log.info("Couldn't align structures with the " + sp.toString()
1196 + "associated alignment panels.", e);
1202 public void setJalviewColourScheme(ColourSchemeI ucs)
1204 jmb.setJalviewColourScheme(ucs);
1211 * @return first alignment panel displaying given alignment, or the default
1214 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1216 for (AlignmentPanel ap : getAllAlignmentPanels())
1218 if (ap.av.getAlignment() == alignment)
1223 return getAlignmentPanel();
1227 public AAStructureBindingModel getBinding()
1233 public String getStateInfo()
1235 return jmb == null ? null : jmb.viewer.getStateInfo();
1239 public ViewerType getViewerType()
1241 return ViewerType.JMOL;