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 viewerColour.setSelected(true);
183 useAlignmentPanelForColourbyseq(ap);
184 jmb.setColourBySequence(true);
185 seqColour.setSelected(true);
186 viewerColour.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 viewerColour.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 viewerActionMenu.add(alpanels);
255 viewerActionMenu.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() }),
307 JOptionPane.YES_NO_CANCEL_OPTION);
309 if (option == JOptionPane.CANCEL_OPTION)
313 if (option == JOptionPane.YES_OPTION)
315 // TODO : Fix multiple seq to one chain issue here.
316 ap.getStructureSelectionManager().setMapping(seq, chains,
317 alreadyMapped, AppletFormatAdapter.FILE);
318 if (ap.seqPanel.seqCanvas.fr != null)
320 ap.seqPanel.seqCanvas.fr.featuresAdded();
321 ap.paintAlignment(true);
324 // Now this AppJmol is mapped to new sequences. We must add them to
325 // the exisiting array
326 JInternalFrame[] frames = Desktop.instance.getAllFrames();
328 for (int i = 0; i < frames.length; i++)
330 if (frames[i] instanceof AppJmol)
332 final AppJmol topJmol = ((AppJmol) frames[i]);
333 // JBPNOTE: this looks like a binding routine, rather than a gui
335 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
337 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
339 topJmol.jmb.addSequence(pe, seq);
340 topJmol.addAlignmentPanel(ap);
341 // add it to the set used for colouring
342 topJmol.useAlignmentPanelForColourbyseq(ap);
343 topJmol.buildJmolActionMenu();
344 ap.getStructureSelectionManager()
345 .sequenceColoursChanged(ap);
355 // /////////////////////////////////
356 // Check if there are other Jmol views involving this alignment
357 // and prompt user about adding this molecule to one of them
358 Vector existingViews = getJmolsFor(ap);
359 if (existingViews.size() > 0)
361 Enumeration jm = existingViews.elements();
362 while (jm.hasMoreElements())
364 AppJmol topJmol = (AppJmol) jm.nextElement();
365 // TODO: highlight topJmol in view somehow
366 int option = JOptionPane
367 .showInternalConfirmDialog(
369 MessageManager.formatMessage(
370 "label.add_pdbentry_to_view", new String[]
371 { pdbentry.getId(), topJmol.getTitle() }),
373 .getString("label.align_to_existing_structure_view"),
374 JOptionPane.YES_NO_CANCEL_OPTION);
375 if (option == JOptionPane.CANCEL_OPTION)
379 if (option == JOptionPane.YES_OPTION)
381 topJmol.useAlignmentPanelForSuperposition(ap);
382 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
387 // /////////////////////////////////
388 openNewJmol(ap, new PDBEntry[]
389 { pdbentry }, new SequenceI[][]
393 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
396 progressBar = ap.alignFrame;
397 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
398 pdbentrys, seqs, null, null);
399 addAlignmentPanel(ap);
400 useAlignmentPanelForColourbyseq(ap);
401 if (pdbentrys.length > 1)
403 alignAddedStructures = true;
404 useAlignmentPanelForSuperposition(ap);
406 jmb.setColourBySequence(true);
407 setSize(400, 400); // probably should be a configurable/dynamic default here
411 addingStructures = false;
412 worker = new Thread(this);
415 this.addInternalFrameListener(new InternalFrameAdapter()
417 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
426 * create a new Jmol containing several structures superimposed using the
433 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
435 openNewJmol(ap, pe, seqs);
439 * list of sequenceSet ids associated with the view
441 ArrayList<String> _aps = new ArrayList();
443 public AlignmentPanel[] getAllAlignmentPanels()
445 AlignmentPanel[] t, list = new AlignmentPanel[0];
446 for (String setid : _aps)
448 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
451 t = new AlignmentPanel[list.length + panels.length];
452 System.arraycopy(list, 0, t, 0, list.length);
453 System.arraycopy(panels, 0, t, list.length, panels.length);
462 * list of alignment panels to use for superposition
464 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
467 * list of alignment panels that are used for colouring structures by aligned
470 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
473 * set the primary alignmentPanel reference and add another alignPanel to the
474 * list of ones to use for colouring and aligning
478 public void addAlignmentPanel(AlignmentPanel nap)
484 if (!_aps.contains(nap.av.getSequenceSetId()))
486 _aps.add(nap.av.getSequenceSetId());
491 * remove any references held to the given alignment panel
495 public void removeAlignmentPanel(AlignmentPanel nap)
499 _alignwith.remove(nap);
500 _colourwith.remove(nap);
504 for (AlignmentPanel aps : getAllAlignmentPanels())
513 } catch (Exception ex)
518 buildJmolActionMenu();
522 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
524 addAlignmentPanel(nap);
525 if (!_alignwith.contains(nap))
531 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
533 if (_alignwith.contains(nap))
535 _alignwith.remove(nap);
539 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
540 boolean enableColourBySeq)
542 useAlignmentPanelForColourbyseq(nap);
543 jmb.setColourBySequence(enableColourBySeq);
544 seqColour.setSelected(enableColourBySeq);
545 viewerColour.setSelected(!enableColourBySeq);
548 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
550 addAlignmentPanel(nap);
551 if (!_colourwith.contains(nap))
553 _colourwith.add(nap);
557 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
559 if (_colourwith.contains(nap))
561 _colourwith.remove(nap);
566 * pdb retrieval thread.
568 private Thread worker = null;
571 * add a new structure (with associated sequences and chains) to this viewer,
572 * retrieving it if necessary first.
579 * if true, new structure(s) will be align using associated alignment
581 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
582 final String[] chains, final boolean b,
583 final IProgressIndicator alignFrame)
585 if (pdbentry.getFile() == null)
587 if (worker != null && worker.isAlive())
589 // a retrieval is in progress, wait around and add ourselves to the
591 new Thread(new Runnable()
595 while (worker != null && worker.isAlive() && _started)
599 Thread.sleep(100 + ((int) Math.random() * 100));
601 } catch (Exception e)
606 // and call ourselves again.
607 addStructure(pdbentry, seq, chains, b, alignFrame);
613 // otherwise, start adding the structure.
614 jmb.addSequenceAndChain(new PDBEntry[]
615 { pdbentry }, new SequenceI[][]
616 { seq }, new String[][]
618 addingStructures = true;
620 alignAddedStructures = b;
621 progressBar = alignFrame; // visual indication happens on caller frame.
622 (worker = new Thread(this)).start();
626 private Vector getJmolsFor(AlignmentPanel apanel)
628 Vector result = new Vector();
629 JInternalFrame[] frames = Desktop.instance.getAllFrames();
631 for (JInternalFrame frame : frames)
633 if (frame instanceof AppJmol)
635 if (((AppJmol) frame).isLinkedWith(apanel))
637 result.addElement(frame);
644 void initJmol(String command)
646 jmb.setFinishedInit(false);
647 renderPanel = new RenderPanel();
648 // TODO: consider waiting until the structure/view is fully loaded before
650 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
651 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
652 getBounds().width, getBounds().height);
653 if (scriptWindow == null)
655 BorderLayout bl = new BorderLayout();
658 scriptWindow = new JPanel(bl);
659 scriptWindow.setVisible(false);
662 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
664 jmb.newJmolPopup(true, "Jmol", true);
669 jmb.evalStateCommand(command);
670 jmb.setFinishedInit(true);
673 void setChainMenuItems(Vector chains)
675 chainMenu.removeAll();
680 JMenuItem menuItem = new JMenuItem(
681 MessageManager.getString("label.all"));
682 menuItem.addActionListener(new ActionListener()
684 public void actionPerformed(ActionEvent evt)
686 allChainsSelected = true;
687 for (int i = 0; i < chainMenu.getItemCount(); i++)
689 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
691 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
695 allChainsSelected = false;
699 chainMenu.add(menuItem);
701 for (int c = 0; c < chains.size(); c++)
703 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
704 menuItem.addItemListener(new ItemListener()
706 public void itemStateChanged(ItemEvent evt)
708 if (!allChainsSelected)
715 chainMenu.add(menuItem);
719 boolean allChainsSelected = false;
721 private boolean alignAddedStructures = false;
725 Vector toshow = new Vector();
727 int mlength, p, mnum;
728 for (int i = 0; i < chainMenu.getItemCount(); i++)
730 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
732 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
733 if (item.isSelected())
735 toshow.addElement(item.getText());
739 jmb.centerViewer(toshow);
742 public void closeViewer()
749 // TODO: check for memory leaks where instance isn't finalised because jmb
750 // holds a reference to the window
755 * state flag for PDB retrieval thread
757 private boolean _started = false;
763 // todo - record which pdbids were successfuly imported.
764 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
767 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
768 // TODO: replace with reference fetching/transfer code (validate PDBentry
770 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
771 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
773 String file = jmb.pdbentry[pi].getFile();
776 // retrieve the pdb and store it locally
777 AlignmentI pdbseq = null;
778 pdbid = jmb.pdbentry[pi].getId();
779 long hdl = pdbid.hashCode() - System.currentTimeMillis();
780 if (progressBar != null)
782 progressBar.setProgressBar(MessageManager.formatMessage("status.fetching_pdb", new String[]{pdbid}), hdl);
786 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
788 } catch (OutOfMemoryError oomerror)
790 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
791 } catch (Exception ex)
793 ex.printStackTrace();
794 errormsgs.append("'" + pdbid + "'");
796 if (progressBar != null)
798 progressBar.setProgressBar(MessageManager.getString("label.state_completed"), hdl);
802 // just transfer the file name from the first sequence's first
804 file = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
805 .elementAt(0)).getFile()).getAbsolutePath();
806 jmb.pdbentry[pi].setFile(file);
808 files.append(" \"" + Platform.escapeString(file) + "\"");
812 errormsgs.append("'" + pdbid + "' ");
817 if (curfiles != null && curfiles.length > 0)
819 addingStructures = true; // already files loaded.
820 for (int c = 0; c < curfiles.length; c++)
822 if (curfiles[c].equals(file))
831 files.append(" \"" + Platform.escapeString(file) + "\"");
835 } catch (OutOfMemoryError oomerror)
837 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
838 } catch (Exception ex)
840 ex.printStackTrace();
841 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
844 if (errormsgs.length() > 0)
847 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
848 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
850 { errormsgs.toString() }), MessageManager
851 .getString("label.couldnt_load_file"),
852 JOptionPane.ERROR_MESSAGE);
855 long lastnotify = jmb.getLoadNotifiesHandled();
856 if (files.length() > 0)
858 if (!addingStructures)
863 initJmol("load FILES " + files.toString());
864 } catch (OutOfMemoryError oomerror)
866 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
867 Cache.log.debug("File locations are " + files);
868 } catch (Exception ex)
870 Cache.log.error("Couldn't open Jmol viewer!", ex);
875 StringBuffer cmd = new StringBuffer();
876 cmd.append("loadingJalviewdata=true\nload APPEND ");
877 cmd.append(files.toString());
878 cmd.append("\nloadingJalviewdata=null");
879 final String command = cmd.toString();
881 lastnotify = jmb.getLoadNotifiesHandled();
885 jmb.evalStateCommand(command);
886 } catch (OutOfMemoryError oomerror)
889 "When trying to add structures to the Jmol viewer!",
891 Cache.log.debug("File locations are " + files);
892 } catch (Exception ex)
894 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
898 // need to wait around until script has finished
899 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
900 : (jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb
901 .getPdbFile().length != jmb.pdbentry.length))
905 Cache.log.debug("Waiting around for jmb notify.");
907 } catch (Exception e)
911 // refresh the sequence colours for the new structure(s)
912 for (AlignmentPanel ap : _colourwith)
914 jmb.updateColours(ap);
916 // do superposition if asked to
917 if (alignAddedStructures)
919 javax.swing.SwingUtilities.invokeLater(new Runnable()
923 alignStructs_withAllAlignPanels();
924 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
927 alignAddedStructures = false;
929 addingStructures = false;
937 public void pdbFile_actionPerformed(ActionEvent actionEvent)
939 JalviewFileChooser chooser = new JalviewFileChooser(
940 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
942 chooser.setFileView(new JalviewFileView());
943 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
944 chooser.setToolTipText(MessageManager.getString("action.save"));
946 int value = chooser.showSaveDialog(this);
948 if (value == JalviewFileChooser.APPROVE_OPTION)
952 // TODO: cope with multiple PDB files in view
953 BufferedReader in = new BufferedReader(new FileReader(
954 jmb.getPdbFile()[0]));
955 File outFile = chooser.getSelectedFile();
957 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
959 while ((data = in.readLine()) != null)
961 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
967 } catch (Exception ex)
969 ex.printStackTrace();
975 public void viewMapping_actionPerformed(ActionEvent actionEvent)
977 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
980 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
982 cap.appendText(jmb.printMapping(jmb.pdbentry[pdbe].getFile()));
983 cap.appendText("\n");
985 } catch (OutOfMemoryError e)
988 "composing sequence-structure alignments for display in text box.",
993 jalview.gui.Desktop.addInternalFrame(cap,
994 MessageManager.getString("label.pdb_sequence_mapping"), 550,
999 public void eps_actionPerformed(ActionEvent e)
1001 makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
1005 public void png_actionPerformed(ActionEvent e)
1007 makePDBImage(jalview.util.ImageMaker.TYPE.PNG);
1010 void makePDBImage(jalview.util.ImageMaker.TYPE type)
1012 int width = getWidth();
1013 int height = getHeight();
1015 jalview.util.ImageMaker im;
1017 if (type == jalview.util.ImageMaker.TYPE.PNG)
1019 im = new jalview.util.ImageMaker(this,
1020 jalview.util.ImageMaker.TYPE.PNG,
1021 "Make PNG image from view", width, height, null, null);
1023 else if (type == jalview.util.ImageMaker.TYPE.EPS)
1025 im = new jalview.util.ImageMaker(this,
1026 jalview.util.ImageMaker.TYPE.EPS,
1027 "Make EPS file from view", width, height, null,
1033 im = new jalview.util.ImageMaker(this,
1034 jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
1035 width, height, null, this.getTitle());
1038 if (im.getGraphics() != null)
1040 Rectangle rect = new Rectangle(width, height);
1041 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
1047 public void viewerColour_actionPerformed(ActionEvent actionEvent)
1049 if (viewerColour.isSelected())
1051 // disable automatic sequence colouring.
1052 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);
1083 public void chainColour_actionPerformed(ActionEvent actionEvent)
1085 chainColour.setSelected(true);
1086 jmb.colourByChain();
1090 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1092 chargeColour.setSelected(true);
1093 jmb.colourByCharge();
1097 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1099 zappoColour.setSelected(true);
1100 jmb.setJalviewColourScheme(new ZappoColourScheme());
1104 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1106 taylorColour.setSelected(true);
1107 jmb.setJalviewColourScheme(new TaylorColourScheme());
1111 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1113 hydroColour.setSelected(true);
1114 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1118 public void helixColour_actionPerformed(ActionEvent actionEvent)
1120 helixColour.setSelected(true);
1121 jmb.setJalviewColourScheme(new HelixColourScheme());
1125 public void strandColour_actionPerformed(ActionEvent actionEvent)
1127 strandColour.setSelected(true);
1128 jmb.setJalviewColourScheme(new StrandColourScheme());
1132 public void turnColour_actionPerformed(ActionEvent actionEvent)
1134 turnColour.setSelected(true);
1135 jmb.setJalviewColourScheme(new TurnColourScheme());
1139 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1141 buriedColour.setSelected(true);
1142 jmb.setJalviewColourScheme(new BuriedColourScheme());
1146 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1148 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1152 public void userColour_actionPerformed(ActionEvent actionEvent)
1154 userColour.setSelected(true);
1155 new UserDefinedColours(this, null);
1159 public void backGround_actionPerformed(ActionEvent actionEvent)
1161 java.awt.Color col = JColorChooser.showDialog(this,
1162 MessageManager.getString("label.select_backgroud_colour"), null);
1165 jmb.setBackgroundColour(col);
1170 public void showHelp_actionPerformed(ActionEvent actionEvent)
1174 jalview.util.BrowserLauncher
1175 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1176 } catch (Exception ex)
1181 public void showConsole(boolean showConsole)
1186 if (splitPane == null)
1188 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1189 splitPane.setTopComponent(renderPanel);
1190 splitPane.setBottomComponent(scriptWindow);
1191 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1192 splitPane.setDividerLocation(getHeight() - 200);
1193 scriptWindow.setVisible(true);
1194 scriptWindow.validate();
1195 splitPane.validate();
1201 if (splitPane != null)
1203 splitPane.setVisible(false);
1208 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1214 class RenderPanel extends JPanel
1216 final Dimension currentSize = new Dimension();
1218 final Rectangle rectClip = new Rectangle();
1220 public void paintComponent(Graphics g)
1222 getSize(currentSize);
1223 g.getClipBounds(rectClip);
1225 if (jmb.fileLoadingError != null)
1227 g.setColor(Color.black);
1228 g.fillRect(0, 0, currentSize.width, currentSize.height);
1229 g.setColor(Color.white);
1230 g.setFont(new Font("Verdana", Font.BOLD, 14));
1231 g.drawString(MessageManager.getString("label.error_loading_file")
1232 + "...", 20, currentSize.height / 2);
1233 StringBuffer sb = new StringBuffer();
1235 for (int e = 0; e < jmb.pdbentry.length; e++)
1237 sb.append(jmb.pdbentry[e].getId());
1238 if (e < jmb.pdbentry.length - 1)
1243 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1246 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1247 * g.getFontMetrics().getHeight());
1251 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1253 g.setColor(Color.black);
1254 g.fillRect(0, 0, currentSize.width, currentSize.height);
1255 g.setColor(Color.white);
1256 g.setFont(new Font("Verdana", Font.BOLD, 14));
1257 g.drawString(MessageManager.getString("label.retrieving_pdb_data"),
1258 20, currentSize.height / 2);
1262 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1267 String viewId = null;
1269 public String getViewId()
1273 viewId = System.currentTimeMillis() + "." + this.hashCode();
1278 public void updateTitleAndMenus()
1280 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1285 setChainMenuItems(jmb.chainNames);
1287 this.setTitle(jmb.getViewerTitle());
1288 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1290 viewerActionMenu.setVisible(true);
1292 if (!jmb.isLoadingFromArchive())
1294 seqColour_actionPerformed(null);
1298 protected void buildJmolActionMenu()
1300 if (_alignwith == null)
1302 _alignwith = new Vector<AlignmentPanel>();
1304 if (_alignwith.size() == 0 && ap != null)
1309 for (Component c : viewerActionMenu.getMenuComponents())
1311 if (c != alignStructs)
1313 viewerActionMenu.remove((JMenuItem) c);
1316 final ItemListener handler;
1323 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1327 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1329 alignStructs_withAllAlignPanels();
1332 private void alignStructs_withAllAlignPanels()
1339 if (_alignwith.size() == 0)
1346 AlignmentI[] als = new Alignment[_alignwith.size()];
1347 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1348 int[] alm = new int[_alignwith.size()];
1351 for (AlignmentPanel ap : _alignwith)
1353 als[a] = ap.av.getAlignment();
1355 alc[a++] = ap.av.getColumnSelection();
1357 jmb.superposeStructures(als, alm, alc);
1358 } catch (Exception e)
1360 StringBuffer sp = new StringBuffer();
1361 for (AlignmentPanel ap : _alignwith)
1363 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1365 Cache.log.info("Couldn't align structures with the " + sp.toString()
1366 + "associated alignment panels.", e);
1372 public void setJalviewColourScheme(ColourSchemeI ucs)
1374 jmb.setJalviewColourScheme(ucs);
1381 * @return first alignment panel displaying given alignment, or the default
1384 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1386 for (AlignmentPanel ap : getAllAlignmentPanels())
1388 if (ap.av.getAlignment() == alignment)
1399 * @return true if this Jmol instance is linked with the given alignPanel
1401 public boolean isLinkedWith(AlignmentPanel ap2)
1403 return _aps.contains(ap2.av.getSequenceSetId());
1406 public boolean isUsedforaligment(AlignmentPanel ap2)
1409 return (_alignwith != null) && _alignwith.contains(ap2);
1412 public boolean isUsedforcolourby(AlignmentPanel ap2)
1414 return (_colourwith != null) && _colourwith.contains(ap2);
1419 * @return TRUE if the view is NOT being coloured by sequence associations.
1421 public boolean isColouredByJmol()
1423 return !jmb.isColourBySequence();
1426 public JalviewJmolBinding getBinding()