2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.bin.Cache;
24 import jalview.datamodel.Alignment;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.ColumnSelection;
27 import jalview.datamodel.PDBEntry;
28 import jalview.datamodel.SequenceI;
29 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
30 import jalview.io.AppletFormatAdapter;
31 import jalview.io.JalviewFileChooser;
32 import jalview.io.JalviewFileView;
33 import jalview.jbgui.GStructureViewer;
34 import jalview.schemes.BuriedColourScheme;
35 import jalview.schemes.ColourSchemeI;
36 import jalview.schemes.HelixColourScheme;
37 import jalview.schemes.HydrophobicColourScheme;
38 import jalview.schemes.PurinePyrimidineColourScheme;
39 import jalview.schemes.StrandColourScheme;
40 import jalview.schemes.TaylorColourScheme;
41 import jalview.schemes.TurnColourScheme;
42 import jalview.schemes.ZappoColourScheme;
43 import jalview.structures.models.AAStructureBindingModel;
44 import jalview.util.MessageManager;
45 import jalview.util.Platform;
47 import java.awt.BorderLayout;
48 import java.awt.Color;
49 import java.awt.Component;
50 import java.awt.Dimension;
52 import java.awt.Graphics;
53 import java.awt.Rectangle;
54 import java.awt.event.ActionEvent;
55 import java.awt.event.ActionListener;
56 import java.awt.event.ItemEvent;
57 import java.awt.event.ItemListener;
58 import java.io.BufferedReader;
60 import java.io.FileOutputStream;
61 import java.io.FileReader;
62 import java.io.PrintWriter;
63 import java.util.Enumeration;
64 import java.util.Vector;
66 import javax.swing.JCheckBoxMenuItem;
67 import javax.swing.JColorChooser;
68 import javax.swing.JInternalFrame;
69 import javax.swing.JMenu;
70 import javax.swing.JMenuItem;
71 import javax.swing.JOptionPane;
72 import javax.swing.JPanel;
73 import javax.swing.JSplitPane;
74 import javax.swing.event.InternalFrameAdapter;
75 import javax.swing.event.InternalFrameEvent;
76 import javax.swing.event.MenuEvent;
77 import javax.swing.event.MenuListener;
79 public class AppJmol extends GStructureViewer implements Runnable,
89 RenderPanel renderPanel;
93 Vector atomsPicked = new Vector();
95 private boolean addingStructures = false;
105 * @deprecated defaults to AppJmol(String[] files, ... , viewid);
108 public AppJmol(String file, String id, SequenceI[] seq,
109 AlignmentPanel ap, String loadStatus, Rectangle bounds)
111 this(file, id, seq, ap, loadStatus, bounds, null);
118 public AppJmol(String file, String id, SequenceI[] seq,
119 AlignmentPanel ap, String loadStatus, Rectangle bounds,
123 { file }, new String[]
124 { id }, new SequenceI[][]
125 { seq }, ap, true, true, false, loadStatus, bounds, viewid);
128 ViewSelectionMenu seqColourBy;
137 * - add the alignment panel to the list used for colouring these
140 * - add the alignment panel to the list used for aligning these
142 * @param leaveColouringToJmol
143 * - do not update the colours from any other source. Jmol is
149 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
150 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
151 boolean leaveColouringToJmol, String loadStatus,
152 Rectangle bounds, String viewid)
154 PDBEntry[] pdbentrys = new PDBEntry[files.length];
155 for (int i = 0; i < pdbentrys.length; i++)
157 PDBEntry pdbentry = new PDBEntry();
158 pdbentry.setFile(files[i]);
159 pdbentry.setId(ids[i]);
160 pdbentrys[i] = pdbentry;
162 // / TODO: check if protocol is needed to be set, and if chains are
164 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
165 pdbentrys, seqs, null, null);
167 jmb.setLoadingFromArchive(true);
168 addAlignmentPanel(ap);
171 useAlignmentPanelForSuperposition(ap);
173 if (leaveColouringToJmol || !usetoColour)
175 jmb.setColourBySequence(false);
176 seqColour.setSelected(false);
177 viewerColour.setSelected(true);
181 useAlignmentPanelForColourbyseq(ap);
182 jmb.setColourBySequence(true);
183 seqColour.setSelected(true);
184 viewerColour.setSelected(false);
186 this.setBounds(bounds);
189 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
190 // bounds.width,bounds.height);
192 this.addInternalFrameListener(new InternalFrameAdapter()
194 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
199 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
203 private void initMenus()
205 seqColour.setSelected(jmb.isColourBySequence());
206 viewerColour.setSelected(!jmb.isColourBySequence());
207 if (_colourwith == null)
209 _colourwith = new Vector<AlignmentPanel>();
211 if (_alignwith == null)
213 _alignwith = new Vector<AlignmentPanel>();
216 seqColourBy = new ViewSelectionMenu(MessageManager.getString("label.colour_by"), this, _colourwith,
221 public void itemStateChanged(ItemEvent e)
223 if (!seqColour.isSelected())
229 // update the jmol display now.
230 seqColour_actionPerformed(null);
234 viewMenu.add(seqColourBy);
235 final ItemListener handler;
236 JMenu alpanels = new ViewSelectionMenu(MessageManager.getString("label.superpose_with"), this,
237 _alignwith, handler = new ItemListener()
241 public void itemStateChanged(ItemEvent e)
243 alignStructs.setEnabled(_alignwith.size() > 0);
244 alignStructs.setToolTipText(MessageManager
246 "label.align_structures_using_linked_alignment_views",
248 { new Integer(_alignwith.size()).toString() }));
251 handler.itemStateChanged(null);
252 viewerActionMenu.add(alpanels);
253 viewerActionMenu.addMenuListener(new MenuListener()
257 public void menuSelected(MenuEvent e)
259 handler.itemStateChanged(null);
263 public void menuDeselected(MenuEvent e)
265 // TODO Auto-generated method stub
270 public void menuCanceled(MenuEvent e)
272 // TODO Auto-generated method stub
278 IProgressIndicator progressBar = null;
281 * add a single PDB structure to a new or existing Jmol view
288 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
289 final AlignmentPanel ap)
291 progressBar = ap.alignFrame;
292 // ////////////////////////////////
293 // Is the pdb file already loaded?
294 String alreadyMapped = ap.getStructureSelectionManager()
295 .alreadyMappedToFile(pdbentry.getId());
297 if (alreadyMapped != null)
299 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
300 MessageManager.formatMessage(
301 "label.pdb_entry_is_already_displayed", new String[]
302 { pdbentry.getId() }), MessageManager.formatMessage(
303 "label.map_sequences_to_visible_window", new String[]
304 { pdbentry.getId() }),
305 JOptionPane.YES_NO_CANCEL_OPTION);
307 if (option == JOptionPane.CANCEL_OPTION)
311 if (option == JOptionPane.YES_OPTION)
313 // TODO : Fix multiple seq to one chain issue here.
314 ap.getStructureSelectionManager().setMapping(seq, chains,
315 alreadyMapped, AppletFormatAdapter.FILE);
316 if (ap.getSeqPanel().seqCanvas.fr != null)
318 ap.getSeqPanel().seqCanvas.fr.featuresAdded();
319 ap.paintAlignment(true);
322 // Now this AppJmol is mapped to new sequences. We must add them to
323 // the exisiting array
324 JInternalFrame[] frames = Desktop.instance.getAllFrames();
326 for (int i = 0; i < frames.length; i++)
328 if (frames[i] instanceof AppJmol)
330 final AppJmol topJmol = ((AppJmol) frames[i]);
331 // JBPNOTE: this looks like a binding routine, rather than a gui
333 for (int pe = 0; pe < topJmol.jmb.getPdbCount(); pe++)
335 if (topJmol.jmb.getPdbEntry(pe).getFile()
336 .equals(alreadyMapped))
338 topJmol.jmb.addSequence(pe, seq);
339 topJmol.addAlignmentPanel(ap);
340 // add it to the set used for colouring
341 topJmol.useAlignmentPanelForColourbyseq(ap);
342 topJmol.buildJmolActionMenu();
343 ap.getStructureSelectionManager()
344 .sequenceColoursChanged(ap);
354 // /////////////////////////////////
355 // Check if there are other Jmol views involving this alignment
356 // and prompt user about adding this molecule to one of them
357 Vector existingViews = getJmolsFor(ap);
358 if (existingViews.size() > 0)
360 Enumeration jm = existingViews.elements();
361 while (jm.hasMoreElements())
363 AppJmol topJmol = (AppJmol) jm.nextElement();
364 // TODO: highlight topJmol in view somehow
365 int option = JOptionPane
366 .showInternalConfirmDialog(
368 MessageManager.formatMessage(
369 "label.add_pdbentry_to_view", new String[]
370 { pdbentry.getId(), topJmol.getTitle() }),
372 .getString("label.align_to_existing_structure_view"),
373 JOptionPane.YES_NO_CANCEL_OPTION);
374 if (option == JOptionPane.CANCEL_OPTION)
378 if (option == JOptionPane.YES_OPTION)
380 topJmol.useAlignmentPanelForSuperposition(ap);
381 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
386 // /////////////////////////////////
387 openNewJmol(ap, new PDBEntry[]
388 { pdbentry }, new SequenceI[][]
392 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
395 progressBar = ap.alignFrame;
396 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
397 pdbentrys, seqs, null, null);
398 addAlignmentPanel(ap);
399 useAlignmentPanelForColourbyseq(ap);
400 if (pdbentrys.length > 1)
402 alignAddedStructures = true;
403 useAlignmentPanelForSuperposition(ap);
405 jmb.setColourBySequence(true);
406 setSize(400, 400); // probably should be a configurable/dynamic default here
410 addingStructures = false;
411 worker = new Thread(this);
414 this.addInternalFrameListener(new InternalFrameAdapter()
416 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
425 * create a new Jmol containing several structures superimposed using the
432 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
434 openNewJmol(ap, pe, seqs);
437 public AlignmentPanel[] getAllAlignmentPanels()
439 AlignmentPanel[] t, list = new AlignmentPanel[0];
440 for (String setid : _aps)
442 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
445 t = new AlignmentPanel[list.length + panels.length];
446 System.arraycopy(list, 0, t, 0, list.length);
447 System.arraycopy(panels, 0, t, list.length, panels.length);
456 * set the primary alignmentPanel reference and add another alignPanel to the
457 * list of ones to use for colouring and aligning
461 public void addAlignmentPanel(AlignmentPanel nap)
467 if (!_aps.contains(nap.av.getSequenceSetId()))
469 _aps.add(nap.av.getSequenceSetId());
474 * remove any references held to the given alignment panel
478 public void removeAlignmentPanel(AlignmentPanel nap)
482 _alignwith.remove(nap);
483 _colourwith.remove(nap);
487 for (AlignmentPanel aps : getAllAlignmentPanels())
496 } catch (Exception ex)
501 buildJmolActionMenu();
505 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
507 addAlignmentPanel(nap);
508 if (!_alignwith.contains(nap))
514 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
516 if (_alignwith.contains(nap))
518 _alignwith.remove(nap);
522 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
523 boolean enableColourBySeq)
525 useAlignmentPanelForColourbyseq(nap);
526 jmb.setColourBySequence(enableColourBySeq);
527 seqColour.setSelected(enableColourBySeq);
528 viewerColour.setSelected(!enableColourBySeq);
531 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
533 addAlignmentPanel(nap);
534 if (!_colourwith.contains(nap))
536 _colourwith.add(nap);
540 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
542 if (_colourwith.contains(nap))
544 _colourwith.remove(nap);
549 * pdb retrieval thread.
551 private Thread worker = null;
554 * add a new structure (with associated sequences and chains) to this viewer,
555 * retrieving it if necessary first.
562 * if true, new structure(s) will be align using associated alignment
564 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
565 final String[] chains, final boolean b,
566 final IProgressIndicator alignFrame)
568 if (pdbentry.getFile() == null)
570 if (worker != null && worker.isAlive())
572 // a retrieval is in progress, wait around and add ourselves to the
574 new Thread(new Runnable()
578 while (worker != null && worker.isAlive() && _started)
582 Thread.sleep(100 + ((int) Math.random() * 100));
584 } catch (Exception e)
589 // and call ourselves again.
590 addStructure(pdbentry, seq, chains, b, alignFrame);
596 // otherwise, start adding the structure.
597 jmb.addSequenceAndChain(new PDBEntry[]
598 { pdbentry }, new SequenceI[][]
599 { seq }, new String[][]
601 addingStructures = true;
603 alignAddedStructures = b;
604 progressBar = alignFrame; // visual indication happens on caller frame.
605 (worker = new Thread(this)).start();
609 private Vector getJmolsFor(AlignmentPanel apanel)
611 Vector result = new Vector();
612 JInternalFrame[] frames = Desktop.instance.getAllFrames();
614 for (JInternalFrame frame : frames)
616 if (frame instanceof AppJmol)
618 if (((GStructureViewer) frame).isLinkedWith(apanel))
620 result.addElement(frame);
627 void initJmol(String command)
629 jmb.setFinishedInit(false);
630 renderPanel = new RenderPanel();
631 // TODO: consider waiting until the structure/view is fully loaded before
633 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
634 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
635 getBounds().width, getBounds().height);
636 if (scriptWindow == null)
638 BorderLayout bl = new BorderLayout();
641 scriptWindow = new JPanel(bl);
642 scriptWindow.setVisible(false);
645 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
647 jmb.newJmolPopup(true, "Jmol", true);
652 jmb.evalStateCommand(command);
653 jmb.setFinishedInit(true);
656 void setChainMenuItems(Vector chains)
658 chainMenu.removeAll();
663 JMenuItem menuItem = new JMenuItem(
664 MessageManager.getString("label.all"));
665 menuItem.addActionListener(new ActionListener()
667 public void actionPerformed(ActionEvent evt)
669 allChainsSelected = true;
670 for (int i = 0; i < chainMenu.getItemCount(); i++)
672 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
674 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
678 allChainsSelected = false;
682 chainMenu.add(menuItem);
684 for (int c = 0; c < chains.size(); c++)
686 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
687 menuItem.addItemListener(new ItemListener()
689 public void itemStateChanged(ItemEvent evt)
691 if (!allChainsSelected)
698 chainMenu.add(menuItem);
702 boolean allChainsSelected = false;
704 private boolean alignAddedStructures = false;
708 Vector toshow = new Vector();
710 int mlength, p, mnum;
711 for (int i = 0; i < chainMenu.getItemCount(); i++)
713 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
715 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
716 if (item.isSelected())
718 toshow.addElement(item.getText());
722 jmb.centerViewer(toshow);
725 public void closeViewer()
732 // TODO: check for memory leaks where instance isn't finalised because jmb
733 // holds a reference to the window
738 * state flag for PDB retrieval thread
740 private boolean _started = false;
746 // todo - record which pdbids were successfuly imported.
747 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
750 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
751 // TODO: replace with reference fetching/transfer code (validate PDBentry
753 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
754 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
756 String file = jmb.getPdbEntry(pi).getFile();
759 // retrieve the pdb and store it locally
760 AlignmentI pdbseq = null;
761 pdbid = jmb.getPdbEntry(pi).getId();
762 long hdl = pdbid.hashCode() - System.currentTimeMillis();
763 if (progressBar != null)
765 progressBar.setProgressBar(MessageManager.formatMessage("status.fetching_pdb", new String[]{pdbid}), hdl);
769 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.getPdbEntry(
772 } catch (OutOfMemoryError oomerror)
774 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
775 } catch (Exception ex)
777 ex.printStackTrace();
778 errormsgs.append("'" + pdbid + "'");
780 if (progressBar != null)
782 progressBar.setProgressBar(MessageManager.getString("label.state_completed"), hdl);
786 // just transfer the file name from the first sequence's first
788 file = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
789 .elementAt(0)).getFile()).getAbsolutePath();
790 jmb.getPdbEntry(pi).setFile(file);
792 files.append(" \"" + Platform.escapeString(file) + "\"");
796 errormsgs.append("'" + pdbid + "' ");
801 if (curfiles != null && curfiles.length > 0)
803 addingStructures = true; // already files loaded.
804 for (int c = 0; c < curfiles.length; c++)
806 if (curfiles[c].equals(file))
815 files.append(" \"" + Platform.escapeString(file) + "\"");
819 } catch (OutOfMemoryError oomerror)
821 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
822 } catch (Exception ex)
824 ex.printStackTrace();
825 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
828 if (errormsgs.length() > 0)
831 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
832 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
834 { errormsgs.toString() }), MessageManager
835 .getString("label.couldnt_load_file"),
836 JOptionPane.ERROR_MESSAGE);
839 long lastnotify = jmb.getLoadNotifiesHandled();
840 if (files.length() > 0)
842 if (!addingStructures)
847 initJmol("load FILES " + files.toString());
848 } catch (OutOfMemoryError oomerror)
850 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
851 Cache.log.debug("File locations are " + files);
852 } catch (Exception ex)
854 Cache.log.error("Couldn't open Jmol viewer!", ex);
859 StringBuffer cmd = new StringBuffer();
860 cmd.append("loadingJalviewdata=true\nload APPEND ");
861 cmd.append(files.toString());
862 cmd.append("\nloadingJalviewdata=null");
863 final String command = cmd.toString();
865 lastnotify = jmb.getLoadNotifiesHandled();
869 jmb.evalStateCommand(command);
870 } catch (OutOfMemoryError oomerror)
873 "When trying to add structures to the Jmol viewer!",
875 Cache.log.debug("File locations are " + files);
876 } catch (Exception ex)
878 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
882 // need to wait around until script has finished
883 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
884 : (jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb
885 .getPdbFile().length != jmb.getPdbCount()))
889 Cache.log.debug("Waiting around for jmb notify.");
891 } catch (Exception e)
895 // refresh the sequence colours for the new structure(s)
896 for (AlignmentPanel ap : _colourwith)
898 jmb.updateColours(ap);
900 // do superposition if asked to
901 if (alignAddedStructures)
903 javax.swing.SwingUtilities.invokeLater(new Runnable()
907 alignStructs_withAllAlignPanels();
908 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
911 alignAddedStructures = false;
913 addingStructures = false;
921 public void pdbFile_actionPerformed(ActionEvent actionEvent)
923 JalviewFileChooser chooser = new JalviewFileChooser(
924 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
926 chooser.setFileView(new JalviewFileView());
927 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
928 chooser.setToolTipText(MessageManager.getString("action.save"));
930 int value = chooser.showSaveDialog(this);
932 if (value == JalviewFileChooser.APPROVE_OPTION)
936 // TODO: cope with multiple PDB files in view
937 BufferedReader in = new BufferedReader(new FileReader(
938 jmb.getPdbFile()[0]));
939 File outFile = chooser.getSelectedFile();
941 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
943 while ((data = in.readLine()) != null)
945 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
951 } catch (Exception ex)
953 ex.printStackTrace();
959 public void viewMapping_actionPerformed(ActionEvent actionEvent)
961 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
964 for (int pdbe = 0; pdbe < jmb.getPdbCount(); pdbe++)
966 cap.appendText(jmb.printMapping(jmb.getPdbEntry(pdbe).getFile()));
967 cap.appendText("\n");
969 } catch (OutOfMemoryError e)
972 "composing sequence-structure alignments for display in text box.",
977 jalview.gui.Desktop.addInternalFrame(cap,
978 MessageManager.getString("label.pdb_sequence_mapping"), 550,
983 public void eps_actionPerformed(ActionEvent e)
985 makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
989 public void png_actionPerformed(ActionEvent e)
991 makePDBImage(jalview.util.ImageMaker.TYPE.PNG);
994 void makePDBImage(jalview.util.ImageMaker.TYPE type)
996 int width = getWidth();
997 int height = getHeight();
999 jalview.util.ImageMaker im;
1001 if (type == jalview.util.ImageMaker.TYPE.PNG)
1003 im = new jalview.util.ImageMaker(this,
1004 jalview.util.ImageMaker.TYPE.PNG,
1005 "Make PNG image from view", width, height, null, null);
1007 else if (type == jalview.util.ImageMaker.TYPE.EPS)
1009 im = new jalview.util.ImageMaker(this,
1010 jalview.util.ImageMaker.TYPE.EPS,
1011 "Make EPS file from view", width, height, null,
1017 im = new jalview.util.ImageMaker(this,
1018 jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
1019 width, height, null, this.getTitle());
1022 if (im.getGraphics() != null)
1024 Rectangle rect = new Rectangle(width, height);
1025 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
1031 public void viewerColour_actionPerformed(ActionEvent actionEvent)
1033 if (viewerColour.isSelected())
1035 // disable automatic sequence colouring.
1036 jmb.setColourBySequence(false);
1041 public void seqColour_actionPerformed(ActionEvent actionEvent)
1043 jmb.setColourBySequence(seqColour.isSelected());
1044 if (_colourwith == null)
1046 _colourwith = new Vector<AlignmentPanel>();
1048 if (jmb.isColourBySequence())
1050 if (!jmb.isLoadingFromArchive())
1052 if (_colourwith.size() == 0 && ap != null)
1054 // Make the currently displayed alignment panel the associated view
1055 _colourwith.add(ap.alignFrame.alignPanel);
1058 // Set the colour using the current view for the associated alignframe
1059 for (AlignmentPanel ap : _colourwith)
1061 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
1067 public void chainColour_actionPerformed(ActionEvent actionEvent)
1069 chainColour.setSelected(true);
1070 jmb.colourByChain();
1074 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1076 chargeColour.setSelected(true);
1077 jmb.colourByCharge();
1081 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1083 zappoColour.setSelected(true);
1084 jmb.setJalviewColourScheme(new ZappoColourScheme());
1088 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1090 taylorColour.setSelected(true);
1091 jmb.setJalviewColourScheme(new TaylorColourScheme());
1095 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1097 hydroColour.setSelected(true);
1098 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1102 public void helixColour_actionPerformed(ActionEvent actionEvent)
1104 helixColour.setSelected(true);
1105 jmb.setJalviewColourScheme(new HelixColourScheme());
1109 public void strandColour_actionPerformed(ActionEvent actionEvent)
1111 strandColour.setSelected(true);
1112 jmb.setJalviewColourScheme(new StrandColourScheme());
1116 public void turnColour_actionPerformed(ActionEvent actionEvent)
1118 turnColour.setSelected(true);
1119 jmb.setJalviewColourScheme(new TurnColourScheme());
1123 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1125 buriedColour.setSelected(true);
1126 jmb.setJalviewColourScheme(new BuriedColourScheme());
1130 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1132 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1136 public void userColour_actionPerformed(ActionEvent actionEvent)
1138 userColour.setSelected(true);
1139 new UserDefinedColours(this, null);
1143 public void backGround_actionPerformed(ActionEvent actionEvent)
1145 java.awt.Color col = JColorChooser.showDialog(this,
1146 MessageManager.getString("label.select_backgroud_colour"), null);
1149 jmb.setBackgroundColour(col);
1154 public void showHelp_actionPerformed(ActionEvent actionEvent)
1158 jalview.util.BrowserLauncher
1159 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1160 } catch (Exception ex)
1165 public void showConsole(boolean showConsole)
1170 if (splitPane == null)
1172 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1173 splitPane.setTopComponent(renderPanel);
1174 splitPane.setBottomComponent(scriptWindow);
1175 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1176 splitPane.setDividerLocation(getHeight() - 200);
1177 scriptWindow.setVisible(true);
1178 scriptWindow.validate();
1179 splitPane.validate();
1185 if (splitPane != null)
1187 splitPane.setVisible(false);
1192 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1198 class RenderPanel extends JPanel
1200 final Dimension currentSize = new Dimension();
1202 final Rectangle rectClip = new Rectangle();
1204 public void paintComponent(Graphics g)
1206 getSize(currentSize);
1207 g.getClipBounds(rectClip);
1209 if (jmb.fileLoadingError != null)
1211 g.setColor(Color.black);
1212 g.fillRect(0, 0, currentSize.width, currentSize.height);
1213 g.setColor(Color.white);
1214 g.setFont(new Font("Verdana", Font.BOLD, 14));
1215 g.drawString(MessageManager.getString("label.error_loading_file")
1216 + "...", 20, currentSize.height / 2);
1217 StringBuffer sb = new StringBuffer();
1219 for (int e = 0; e < jmb.getPdbCount(); e++)
1221 sb.append(jmb.getPdbEntry(e).getId());
1222 if (e < jmb.getPdbCount() - 1)
1227 if (e == jmb.getPdbCount() - 1 || sb.length() > 20)
1230 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1231 * g.getFontMetrics().getHeight());
1235 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1237 g.setColor(Color.black);
1238 g.fillRect(0, 0, currentSize.width, currentSize.height);
1239 g.setColor(Color.white);
1240 g.setFont(new Font("Verdana", Font.BOLD, 14));
1241 g.drawString(MessageManager.getString("label.retrieving_pdb_data"),
1242 20, currentSize.height / 2);
1246 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1251 public void updateTitleAndMenus()
1253 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1258 setChainMenuItems(jmb.chainNames);
1260 this.setTitle(jmb.getViewerTitle());
1261 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1263 viewerActionMenu.setVisible(true);
1265 if (!jmb.isLoadingFromArchive())
1267 seqColour_actionPerformed(null);
1271 protected void buildJmolActionMenu()
1273 if (_alignwith == null)
1275 _alignwith = new Vector<AlignmentPanel>();
1277 if (_alignwith.size() == 0 && ap != null)
1282 for (Component c : viewerActionMenu.getMenuComponents())
1284 if (c != alignStructs)
1286 viewerActionMenu.remove((JMenuItem) c);
1289 final ItemListener handler;
1296 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1300 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1302 alignStructs_withAllAlignPanels();
1305 private void alignStructs_withAllAlignPanels()
1312 if (_alignwith.size() == 0)
1319 AlignmentI[] als = new Alignment[_alignwith.size()];
1320 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1321 int[] alm = new int[_alignwith.size()];
1324 for (AlignmentPanel ap : _alignwith)
1326 als[a] = ap.av.getAlignment();
1328 alc[a++] = ap.av.getColumnSelection();
1330 jmb.superposeStructures(als, alm, alc);
1331 } catch (Exception e)
1333 StringBuffer sp = new StringBuffer();
1334 for (AlignmentPanel ap : _alignwith)
1336 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1338 Cache.log.info("Couldn't align structures with the " + sp.toString()
1339 + "associated alignment panels.", e);
1345 public void setJalviewColourScheme(ColourSchemeI ucs)
1347 jmb.setJalviewColourScheme(ucs);
1354 * @return first alignment panel displaying given alignment, or the default
1357 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1359 for (AlignmentPanel ap : getAllAlignmentPanels())
1361 if (ap.av.getAlignment() == alignment)
1370 public AAStructureBindingModel getBinding()
1376 public String getStateInfo()
1378 return jmb == null ? null : jmb.viewer.getStateInfo();