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.api.structures.JalviewStructureDisplayI;
24 import jalview.bin.Cache;
25 import jalview.datamodel.Alignment;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.ColumnSelection;
28 import jalview.datamodel.PDBEntry;
29 import jalview.datamodel.SequenceI;
30 import jalview.ext.jmol.JalviewJmolBinding;
31 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
32 import jalview.io.AppletFormatAdapter;
33 import jalview.io.JalviewFileChooser;
34 import jalview.io.JalviewFileView;
35 import jalview.jbgui.GStructureViewer;
36 import jalview.schemes.BuriedColourScheme;
37 import jalview.schemes.ColourSchemeI;
38 import jalview.schemes.HelixColourScheme;
39 import jalview.schemes.HydrophobicColourScheme;
40 import jalview.schemes.PurinePyrimidineColourScheme;
41 import jalview.schemes.StrandColourScheme;
42 import jalview.schemes.TaylorColourScheme;
43 import jalview.schemes.TurnColourScheme;
44 import jalview.schemes.ZappoColourScheme;
45 import jalview.util.MessageManager;
46 import jalview.util.Platform;
48 import java.awt.BorderLayout;
49 import java.awt.Color;
50 import java.awt.Component;
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.PrintWriter;
64 import java.util.ArrayList;
65 import java.util.Enumeration;
66 import java.util.Vector;
68 import javax.swing.JCheckBoxMenuItem;
69 import javax.swing.JColorChooser;
70 import javax.swing.JInternalFrame;
71 import javax.swing.JMenu;
72 import javax.swing.JMenuItem;
73 import javax.swing.JOptionPane;
74 import javax.swing.JPanel;
75 import javax.swing.JSplitPane;
76 import javax.swing.event.InternalFrameAdapter;
77 import javax.swing.event.InternalFrameEvent;
78 import javax.swing.event.MenuEvent;
79 import javax.swing.event.MenuListener;
81 public class AppJmol extends GStructureViewer implements Runnable,
82 ViewSetProvider, JalviewStructureDisplayI
91 RenderPanel renderPanel;
95 Vector atomsPicked = new Vector();
97 private boolean addingStructures = false;
107 * @deprecated defaults to AppJmol(String[] files, ... , viewid);
110 public AppJmol(String file, String id, SequenceI[] seq,
111 AlignmentPanel ap, String loadStatus, Rectangle bounds)
113 this(file, id, seq, ap, loadStatus, bounds, null);
120 public AppJmol(String file, String id, SequenceI[] seq,
121 AlignmentPanel ap, String loadStatus, Rectangle bounds,
125 { file }, new String[]
126 { id }, new SequenceI[][]
127 { seq }, ap, true, true, false, loadStatus, bounds, viewid);
130 ViewSelectionMenu seqColourBy;
139 * - add the alignment panel to the list used for colouring these
142 * - add the alignment panel to the list used for aligning these
144 * @param leaveColouringToJmol
145 * - do not update the colours from any other source. Jmol is
151 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
152 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
153 boolean leaveColouringToJmol, String loadStatus,
154 Rectangle bounds, String viewid)
156 PDBEntry[] pdbentrys = new PDBEntry[files.length];
157 for (int i = 0; i < pdbentrys.length; i++)
159 PDBEntry pdbentry = new PDBEntry();
160 pdbentry.setFile(files[i]);
161 pdbentry.setId(ids[i]);
162 pdbentrys[i] = pdbentry;
164 // / TODO: check if protocol is needed to be set, and if chains are
166 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
167 pdbentrys, seqs, null, null);
169 jmb.setLoadingFromArchive(true);
170 addAlignmentPanel(ap);
173 useAlignmentPanelForSuperposition(ap);
175 if (leaveColouringToJmol || !usetoColour)
177 jmb.setColourBySequence(false);
178 seqColour.setSelected(false);
179 jmolColour.setSelected(true);
183 useAlignmentPanelForColourbyseq(ap);
184 jmb.setColourBySequence(true);
185 seqColour.setSelected(true);
186 jmolColour.setSelected(false);
188 this.setBounds(bounds);
191 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
192 // bounds.width,bounds.height);
194 this.addInternalFrameListener(new InternalFrameAdapter()
196 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
201 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
205 private void initMenus()
207 seqColour.setSelected(jmb.isColourBySequence());
208 jmolColour.setSelected(!jmb.isColourBySequence());
209 if (_colourwith == null)
211 _colourwith = new Vector<AlignmentPanel>();
213 if (_alignwith == null)
215 _alignwith = new Vector<AlignmentPanel>();
218 seqColourBy = new ViewSelectionMenu(MessageManager.getString("label.colour_by"), this, _colourwith,
223 public void itemStateChanged(ItemEvent e)
225 if (!seqColour.isSelected())
231 // update the jmol display now.
232 seqColour_actionPerformed(null);
236 viewMenu.add(seqColourBy);
237 final ItemListener handler;
238 JMenu alpanels = new ViewSelectionMenu(MessageManager.getString("label.superpose_with"), this,
239 _alignwith, handler = new ItemListener()
243 public void itemStateChanged(ItemEvent e)
245 alignStructs.setEnabled(_alignwith.size() > 0);
246 alignStructs.setToolTipText(MessageManager
248 "label.align_structures_using_linked_alignment_views",
250 { new Integer(_alignwith.size()).toString() }));
253 handler.itemStateChanged(null);
254 jmolActionMenu.add(alpanels);
255 jmolActionMenu.addMenuListener(new MenuListener()
259 public void menuSelected(MenuEvent e)
261 handler.itemStateChanged(null);
265 public void menuDeselected(MenuEvent e)
267 // TODO Auto-generated method stub
272 public void menuCanceled(MenuEvent e)
274 // TODO Auto-generated method stub
280 IProgressIndicator progressBar = null;
283 * add a single PDB structure to a new or existing Jmol view
290 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
291 final AlignmentPanel ap)
293 progressBar = ap.alignFrame;
294 // ////////////////////////////////
295 // Is the pdb file already loaded?
296 String alreadyMapped = ap.getStructureSelectionManager()
297 .alreadyMappedToFile(pdbentry.getId());
299 if (alreadyMapped != null)
301 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
302 MessageManager.formatMessage(
303 "label.pdb_entry_is_already_displayed", new String[]
304 { pdbentry.getId() }), MessageManager.formatMessage(
305 "label.map_sequences_to_visible_window", new String[]
306 { pdbentry.getId() }), JOptionPane.YES_NO_OPTION);
308 if (option == JOptionPane.YES_OPTION)
310 // TODO : Fix multiple seq to one chain issue here.
311 ap.getStructureSelectionManager().setMapping(seq, chains,
312 alreadyMapped, AppletFormatAdapter.FILE);
313 if (ap.seqPanel.seqCanvas.fr != null)
315 ap.seqPanel.seqCanvas.fr.featuresAdded();
316 ap.paintAlignment(true);
319 // Now this AppJmol is mapped to new sequences. We must add them to
320 // the exisiting array
321 JInternalFrame[] frames = Desktop.instance.getAllFrames();
323 for (int i = 0; i < frames.length; i++)
325 if (frames[i] instanceof AppJmol)
327 final AppJmol topJmol = ((AppJmol) frames[i]);
328 // JBPNOTE: this looks like a binding routine, rather than a gui
330 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
332 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
334 topJmol.jmb.addSequence(pe, seq);
335 topJmol.addAlignmentPanel(ap);
336 // add it to the set used for colouring
337 topJmol.useAlignmentPanelForColourbyseq(ap);
338 topJmol.buildJmolActionMenu();
339 ap.getStructureSelectionManager()
340 .sequenceColoursChanged(ap);
350 // /////////////////////////////////
351 // Check if there are other Jmol views involving this alignment
352 // and prompt user about adding this molecule to one of them
353 Vector existingViews = getJmolsFor(ap);
354 if (existingViews.size() > 0)
356 Enumeration jm = existingViews.elements();
357 while (jm.hasMoreElements())
359 AppJmol topJmol = (AppJmol) jm.nextElement();
360 // TODO: highlight topJmol in view somehow
361 int option = JOptionPane
362 .showInternalConfirmDialog(
364 MessageManager.formatMessage(
365 "label.add_pdbentry_to_view", new String[]
366 { pdbentry.getId(), topJmol.getTitle() }),
368 .getString("label.align_to_existing_structure_view"),
369 JOptionPane.YES_NO_OPTION);
370 if (option == JOptionPane.YES_OPTION)
372 topJmol.useAlignmentPanelForSuperposition(ap);
373 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
378 // /////////////////////////////////
379 openNewJmol(ap, new PDBEntry[]
380 { pdbentry }, new SequenceI[][]
384 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
387 progressBar = ap.alignFrame;
388 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
389 pdbentrys, seqs, null, null);
390 addAlignmentPanel(ap);
391 useAlignmentPanelForColourbyseq(ap);
392 if (pdbentrys.length > 1)
394 alignAddedStructures = true;
395 useAlignmentPanelForSuperposition(ap);
397 jmb.setColourBySequence(true);
398 setSize(400, 400); // probably should be a configurable/dynamic default here
402 addingStructures = false;
403 worker = new Thread(this);
406 this.addInternalFrameListener(new InternalFrameAdapter()
408 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
417 * create a new Jmol containing several structures superimposed using the
424 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
426 openNewJmol(ap, pe, seqs);
430 * list of sequenceSet ids associated with the view
432 ArrayList<String> _aps = new ArrayList();
434 public AlignmentPanel[] getAllAlignmentPanels()
436 AlignmentPanel[] t, list = new AlignmentPanel[0];
437 for (String setid : _aps)
439 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
442 t = new AlignmentPanel[list.length + panels.length];
443 System.arraycopy(list, 0, t, 0, list.length);
444 System.arraycopy(panels, 0, t, list.length, panels.length);
453 * list of alignment panels to use for superposition
455 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
458 * list of alignment panels that are used for colouring structures by aligned
461 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
464 * set the primary alignmentPanel reference and add another alignPanel to the
465 * list of ones to use for colouring and aligning
469 public void addAlignmentPanel(AlignmentPanel nap)
475 if (!_aps.contains(nap.av.getSequenceSetId()))
477 _aps.add(nap.av.getSequenceSetId());
482 * remove any references held to the given alignment panel
486 public void removeAlignmentPanel(AlignmentPanel nap)
490 _alignwith.remove(nap);
491 _colourwith.remove(nap);
495 for (AlignmentPanel aps : getAllAlignmentPanels())
504 } catch (Exception ex)
509 buildJmolActionMenu();
513 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
515 addAlignmentPanel(nap);
516 if (!_alignwith.contains(nap))
522 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
524 if (_alignwith.contains(nap))
526 _alignwith.remove(nap);
530 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
531 boolean enableColourBySeq)
533 useAlignmentPanelForColourbyseq(nap);
534 jmb.setColourBySequence(enableColourBySeq);
535 seqColour.setSelected(enableColourBySeq);
536 jmolColour.setSelected(!enableColourBySeq);
539 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
541 addAlignmentPanel(nap);
542 if (!_colourwith.contains(nap))
544 _colourwith.add(nap);
548 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
550 if (_colourwith.contains(nap))
552 _colourwith.remove(nap);
557 * pdb retrieval thread.
559 private Thread worker = null;
562 * add a new structure (with associated sequences and chains) to this viewer,
563 * retrieving it if necessary first.
570 * if true, new structure(s) will be align using associated alignment
572 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
573 final String[] chains, final boolean b,
574 final IProgressIndicator alignFrame)
576 if (pdbentry.getFile() == null)
578 if (worker != null && worker.isAlive())
580 // a retrieval is in progress, wait around and add ourselves to the
582 new Thread(new Runnable()
586 while (worker != null && worker.isAlive() && _started)
590 Thread.sleep(100 + ((int) Math.random() * 100));
592 } catch (Exception e)
597 // and call ourselves again.
598 addStructure(pdbentry, seq, chains, b, alignFrame);
604 // otherwise, start adding the structure.
605 jmb.addSequenceAndChain(new PDBEntry[]
606 { pdbentry }, new SequenceI[][]
607 { seq }, new String[][]
609 addingStructures = true;
611 alignAddedStructures = b;
612 progressBar = alignFrame; // visual indication happens on caller frame.
613 (worker = new Thread(this)).start();
617 private Vector getJmolsFor(AlignmentPanel ap2)
619 Vector otherJmols = new Vector();
620 // Now this AppJmol is mapped to new sequences. We must add them to
621 // the exisiting array
622 JInternalFrame[] frames = Desktop.instance.getAllFrames();
624 for (int i = 0; i < frames.length; i++)
626 if (frames[i] instanceof AppJmol)
628 AppJmol topJmol = ((AppJmol) frames[i]);
629 if (topJmol.isLinkedWith(ap2))
631 otherJmols.addElement(topJmol);
638 void initJmol(String command)
640 jmb.setFinishedInit(false);
641 renderPanel = new RenderPanel();
642 // TODO: consider waiting until the structure/view is fully loaded before
644 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
645 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
646 getBounds().width, getBounds().height);
647 if (scriptWindow == null)
649 BorderLayout bl = new BorderLayout();
652 scriptWindow = new JPanel(bl);
653 scriptWindow.setVisible(false);
656 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
658 jmb.newJmolPopup(true, "Jmol", true);
663 jmb.evalStateCommand(command);
664 jmb.setFinishedInit(true);
667 void setChainMenuItems(Vector chains)
669 chainMenu.removeAll();
674 JMenuItem menuItem = new JMenuItem(
675 MessageManager.getString("label.all"));
676 menuItem.addActionListener(new ActionListener()
678 public void actionPerformed(ActionEvent evt)
680 allChainsSelected = true;
681 for (int i = 0; i < chainMenu.getItemCount(); i++)
683 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
685 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
689 allChainsSelected = false;
693 chainMenu.add(menuItem);
695 for (int c = 0; c < chains.size(); c++)
697 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
698 menuItem.addItemListener(new ItemListener()
700 public void itemStateChanged(ItemEvent evt)
702 if (!allChainsSelected)
709 chainMenu.add(menuItem);
713 boolean allChainsSelected = false;
715 private boolean alignAddedStructures = false;
719 Vector toshow = new Vector();
721 int mlength, p, mnum;
722 for (int i = 0; i < chainMenu.getItemCount(); i++)
724 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
726 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
727 if (item.isSelected())
729 toshow.addElement(item.getText());
733 jmb.centerViewer(toshow);
736 public void closeViewer()
743 // TODO: check for memory leaks where instance isn't finalised because jmb
744 // holds a reference to the window
749 * state flag for PDB retrieval thread
751 private boolean _started = false;
757 // todo - record which pdbids were successfuly imported.
758 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
761 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
762 // TODO: replace with reference fetching/transfer code (validate PDBentry
764 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
765 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
767 String file = jmb.pdbentry[pi].getFile();
770 // retrieve the pdb and store it locally
771 AlignmentI pdbseq = null;
772 pdbid = jmb.pdbentry[pi].getId();
773 long hdl = pdbid.hashCode() - System.currentTimeMillis();
774 if (progressBar != null)
776 progressBar.setProgressBar(MessageManager.formatMessage("status.fetching_pdb", new String[]{pdbid}), hdl);
780 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
782 } catch (OutOfMemoryError oomerror)
784 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
785 } catch (Exception ex)
787 ex.printStackTrace();
788 errormsgs.append("'" + pdbid + "'");
790 if (progressBar != null)
792 progressBar.setProgressBar(MessageManager.getString("label.state_completed"), hdl);
796 // just transfer the file name from the first sequence's first
798 file = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
799 .elementAt(0)).getFile()).getAbsolutePath();
800 jmb.pdbentry[pi].setFile(file);
802 files.append(" \"" + Platform.escapeString(file) + "\"");
806 errormsgs.append("'" + pdbid + "' ");
811 if (curfiles != null && curfiles.length > 0)
813 addingStructures = true; // already files loaded.
814 for (int c = 0; c < curfiles.length; c++)
816 if (curfiles[c].equals(file))
825 files.append(" \"" + Platform.escapeString(file) + "\"");
829 } catch (OutOfMemoryError oomerror)
831 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
832 } catch (Exception ex)
834 ex.printStackTrace();
835 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
838 if (errormsgs.length() > 0)
841 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
842 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
844 { errormsgs.toString() }), MessageManager
845 .getString("label.couldnt_load_file"),
846 JOptionPane.ERROR_MESSAGE);
849 long lastnotify = jmb.getLoadNotifiesHandled();
850 if (files.length() > 0)
852 if (!addingStructures)
857 initJmol("load FILES " + files.toString());
858 } catch (OutOfMemoryError oomerror)
860 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
861 Cache.log.debug("File locations are " + files);
862 } catch (Exception ex)
864 Cache.log.error("Couldn't open Jmol viewer!", ex);
869 StringBuffer cmd = new StringBuffer();
870 cmd.append("loadingJalviewdata=true\nload APPEND ");
871 cmd.append(files.toString());
872 cmd.append("\nloadingJalviewdata=null");
873 final String command = cmd.toString();
875 lastnotify = jmb.getLoadNotifiesHandled();
879 jmb.evalStateCommand(command);
880 } catch (OutOfMemoryError oomerror)
883 "When trying to add structures to the Jmol viewer!",
885 Cache.log.debug("File locations are " + files);
886 } catch (Exception ex)
888 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
892 // need to wait around until script has finished
893 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
894 : (jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb
895 .getPdbFile().length != jmb.pdbentry.length))
899 Cache.log.debug("Waiting around for jmb notify.");
901 } catch (Exception e)
905 // refresh the sequence colours for the new structure(s)
906 for (AlignmentPanel ap : _colourwith)
908 jmb.updateColours(ap);
910 // do superposition if asked to
911 if (alignAddedStructures)
913 javax.swing.SwingUtilities.invokeLater(new Runnable()
917 alignStructs_withAllAlignPanels();
918 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
921 alignAddedStructures = false;
923 addingStructures = false;
930 public void pdbFile_actionPerformed(ActionEvent actionEvent)
932 JalviewFileChooser chooser = new JalviewFileChooser(
933 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
935 chooser.setFileView(new JalviewFileView());
936 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
937 chooser.setToolTipText(MessageManager.getString("action.save"));
939 int value = chooser.showSaveDialog(this);
941 if (value == JalviewFileChooser.APPROVE_OPTION)
945 // TODO: cope with multiple PDB files in view
946 BufferedReader in = new BufferedReader(new FileReader(
947 jmb.getPdbFile()[0]));
948 File outFile = chooser.getSelectedFile();
950 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
952 while ((data = in.readLine()) != null)
954 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
960 } catch (Exception ex)
962 ex.printStackTrace();
967 public void viewMapping_actionPerformed(ActionEvent actionEvent)
969 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
972 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
974 cap.appendText(jmb.printMapping(jmb.pdbentry[pdbe].getFile()));
975 cap.appendText("\n");
977 } catch (OutOfMemoryError e)
980 "composing sequence-structure alignments for display in text box.",
985 jalview.gui.Desktop.addInternalFrame(cap,
986 MessageManager.getString("label.pdb_sequence_mapping"), 550,
996 public void eps_actionPerformed(ActionEvent e)
998 makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
1007 public void png_actionPerformed(ActionEvent e)
1009 makePDBImage(jalview.util.ImageMaker.TYPE.PNG);
1012 void makePDBImage(jalview.util.ImageMaker.TYPE type)
1014 int width = getWidth();
1015 int height = getHeight();
1017 jalview.util.ImageMaker im;
1019 if (type == jalview.util.ImageMaker.TYPE.PNG)
1021 im = new jalview.util.ImageMaker(this,
1022 jalview.util.ImageMaker.TYPE.PNG,
1023 "Make PNG image from view", width, height, null, null);
1025 else if (type == jalview.util.ImageMaker.TYPE.EPS)
1027 im = new jalview.util.ImageMaker(this,
1028 jalview.util.ImageMaker.TYPE.EPS,
1029 "Make EPS file from view", width, height, null,
1035 im = new jalview.util.ImageMaker(this,
1036 jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
1037 width, height, null, this.getTitle());
1040 if (im.getGraphics() != null)
1042 Rectangle rect = new Rectangle(width, height);
1043 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
1048 public void jmolColour_actionPerformed(ActionEvent actionEvent)
1050 if (jmolColour.isSelected())
1052 // disable automatic sequence colouring.
1053 jmb.setColourBySequence(false);
1057 public void seqColour_actionPerformed(ActionEvent actionEvent)
1059 jmb.setColourBySequence(seqColour.isSelected());
1060 if (_colourwith == null)
1062 _colourwith = new Vector<AlignmentPanel>();
1064 if (jmb.isColourBySequence())
1066 if (!jmb.isLoadingFromArchive())
1068 if (_colourwith.size() == 0 && ap != null)
1070 // Make the currently displayed alignment panel the associated view
1071 _colourwith.add(ap.alignFrame.alignPanel);
1074 // Set the colour using the current view for the associated alignframe
1075 for (AlignmentPanel ap : _colourwith)
1077 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
1082 public void chainColour_actionPerformed(ActionEvent actionEvent)
1084 chainColour.setSelected(true);
1085 jmb.colourByChain();
1088 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1090 chargeColour.setSelected(true);
1091 jmb.colourByCharge();
1094 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1096 zappoColour.setSelected(true);
1097 jmb.setJalviewColourScheme(new ZappoColourScheme());
1100 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1102 taylorColour.setSelected(true);
1103 jmb.setJalviewColourScheme(new TaylorColourScheme());
1106 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1108 hydroColour.setSelected(true);
1109 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1112 public void helixColour_actionPerformed(ActionEvent actionEvent)
1114 helixColour.setSelected(true);
1115 jmb.setJalviewColourScheme(new HelixColourScheme());
1118 public void strandColour_actionPerformed(ActionEvent actionEvent)
1120 strandColour.setSelected(true);
1121 jmb.setJalviewColourScheme(new StrandColourScheme());
1124 public void turnColour_actionPerformed(ActionEvent actionEvent)
1126 turnColour.setSelected(true);
1127 jmb.setJalviewColourScheme(new TurnColourScheme());
1130 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1132 buriedColour.setSelected(true);
1133 jmb.setJalviewColourScheme(new BuriedColourScheme());
1136 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1138 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1141 public void userColour_actionPerformed(ActionEvent actionEvent)
1143 userColour.setSelected(true);
1144 new UserDefinedColours(this, null);
1147 public void backGround_actionPerformed(ActionEvent actionEvent)
1149 java.awt.Color col = JColorChooser.showDialog(this,
1150 MessageManager.getString("label.select_backgroud_colour"), null);
1153 jmb.setBackgroundColour(col);
1157 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1161 jalview.util.BrowserLauncher
1162 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1163 } catch (Exception ex)
1168 public void showConsole(boolean showConsole)
1173 if (splitPane == null)
1175 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1176 splitPane.setTopComponent(renderPanel);
1177 splitPane.setBottomComponent(scriptWindow);
1178 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1179 splitPane.setDividerLocation(getHeight() - 200);
1180 scriptWindow.setVisible(true);
1181 scriptWindow.validate();
1182 splitPane.validate();
1188 if (splitPane != null)
1190 splitPane.setVisible(false);
1195 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1201 class RenderPanel extends JPanel
1203 final Dimension currentSize = new Dimension();
1205 final Rectangle rectClip = new Rectangle();
1207 public void paintComponent(Graphics g)
1209 getSize(currentSize);
1210 g.getClipBounds(rectClip);
1212 if (jmb.fileLoadingError != null)
1214 g.setColor(Color.black);
1215 g.fillRect(0, 0, currentSize.width, currentSize.height);
1216 g.setColor(Color.white);
1217 g.setFont(new Font("Verdana", Font.BOLD, 14));
1218 g.drawString(MessageManager.getString("label.error_loading_file")
1219 + "...", 20, currentSize.height / 2);
1220 StringBuffer sb = new StringBuffer();
1222 for (int e = 0; e < jmb.pdbentry.length; e++)
1224 sb.append(jmb.pdbentry[e].getId());
1225 if (e < jmb.pdbentry.length - 1)
1230 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1233 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1234 * g.getFontMetrics().getHeight());
1238 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1240 g.setColor(Color.black);
1241 g.fillRect(0, 0, currentSize.width, currentSize.height);
1242 g.setColor(Color.white);
1243 g.setFont(new Font("Verdana", Font.BOLD, 14));
1244 g.drawString(MessageManager.getString("label.retrieving_pdb_data"),
1245 20, currentSize.height / 2);
1249 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1254 String viewId = null;
1256 public String getViewId()
1260 viewId = System.currentTimeMillis() + "." + this.hashCode();
1265 public void updateTitleAndMenus()
1267 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1272 setChainMenuItems(jmb.chainNames);
1274 this.setTitle(jmb.getViewerTitle());
1275 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1277 jmolActionMenu.setVisible(true);
1279 if (!jmb.isLoadingFromArchive())
1281 seqColour_actionPerformed(null);
1285 protected void buildJmolActionMenu()
1287 if (_alignwith == null)
1289 _alignwith = new Vector<AlignmentPanel>();
1291 if (_alignwith.size() == 0 && ap != null)
1296 for (Component c : jmolActionMenu.getMenuComponents())
1298 if (c != alignStructs)
1300 jmolActionMenu.remove((JMenuItem) c);
1303 final ItemListener handler;
1310 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1314 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1316 alignStructs_withAllAlignPanels();
1319 private void alignStructs_withAllAlignPanels()
1326 if (_alignwith.size() == 0)
1333 AlignmentI[] als = new Alignment[_alignwith.size()];
1334 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1335 int[] alm = new int[_alignwith.size()];
1338 for (AlignmentPanel ap : _alignwith)
1340 als[a] = ap.av.getAlignment();
1342 alc[a++] = ap.av.getColumnSelection();
1344 jmb.superposeStructures(als, alm, alc);
1345 } catch (Exception e)
1347 StringBuffer sp = new StringBuffer();
1348 for (AlignmentPanel ap : _alignwith)
1350 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1352 Cache.log.info("Couldn't align structures with the " + sp.toString()
1353 + "associated alignment panels.", e);
1359 public void setJalviewColourScheme(ColourSchemeI ucs)
1361 jmb.setJalviewColourScheme(ucs);
1368 * @return first alignment panel displaying given alignment, or the default
1371 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1373 for (AlignmentPanel ap : getAllAlignmentPanels())
1375 if (ap.av.getAlignment() == alignment)
1386 * @return true if this Jmol instance is linked with the given alignPanel
1388 public boolean isLinkedWith(AlignmentPanel ap2)
1390 return _aps.contains(ap2.av.getSequenceSetId());
1393 public boolean isUsedforaligment(AlignmentPanel ap2)
1396 return (_alignwith != null) && _alignwith.contains(ap2);
1399 public boolean isUsedforcolourby(AlignmentPanel ap2)
1401 return (_colourwith != null) && _colourwith.contains(ap2);
1406 * @return TRUE if the view is NOT being coloured by sequence associations.
1408 public boolean isColouredByJmol()
1410 return !jmb.isColourBySequence();
1413 public JalviewJmolBinding getBinding()