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.
26 import javax.swing.event.*;
28 import java.awt.event.*;
31 import jalview.jbgui.GStructureViewer;
32 import jalview.api.SequenceStructureBinding;
33 import jalview.bin.Cache;
34 import jalview.datamodel.*;
35 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
36 import jalview.datamodel.PDBEntry;
38 import jalview.schemes.*;
39 import jalview.util.MessageManager;
40 import jalview.util.Platform;
42 public class AppJmol extends GStructureViewer implements Runnable,
43 SequenceStructureBinding, ViewSetProvider
52 RenderPanel renderPanel;
56 Vector atomsPicked = new Vector();
58 private boolean addingStructures = false;
68 * @deprecated defaults to AppJmol(String[] files, ... , viewid);
70 public AppJmol(String file, String id, SequenceI[] seq,
71 AlignmentPanel ap, String loadStatus, Rectangle bounds)
73 this(file, id, seq, ap, loadStatus, bounds, null);
79 public AppJmol(String file, String id, SequenceI[] seq,
80 AlignmentPanel ap, String loadStatus, Rectangle bounds,
84 { file }, new String[]
85 { id }, new SequenceI[][]
86 { seq }, ap, true, true, false, loadStatus, bounds, viewid);
89 ViewSelectionMenu seqColourBy;
98 * - add the alignment panel to the list used for colouring these
101 * - add the alignment panel to the list used for aligning these
103 * @param leaveColouringToJmol
104 * - do not update the colours from any other source. Jmol is
110 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
111 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
112 boolean leaveColouringToJmol, String loadStatus,
113 Rectangle bounds, String viewid)
115 PDBEntry[] pdbentrys = new PDBEntry[files.length];
116 for (int i = 0; i < pdbentrys.length; i++)
118 PDBEntry pdbentry = new PDBEntry();
119 pdbentry.setFile(files[i]);
120 pdbentry.setId(ids[i]);
121 pdbentrys[i] = pdbentry;
123 // / TODO: check if protocol is needed to be set, and if chains are
125 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
126 pdbentrys, seqs, null, null);
128 jmb.setLoadingFromArchive(true);
129 addAlignmentPanel(ap);
132 useAlignmentPanelForSuperposition(ap);
134 if (leaveColouringToJmol || !usetoColour)
136 jmb.setColourBySequence(false);
137 seqColour.setSelected(false);
138 jmolColour.setSelected(true);
142 useAlignmentPanelForColourbyseq(ap);
143 jmb.setColourBySequence(true);
144 seqColour.setSelected(true);
145 jmolColour.setSelected(false);
147 this.setBounds(bounds);
150 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
151 // bounds.width,bounds.height);
153 this.addInternalFrameListener(new InternalFrameAdapter()
155 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
160 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
164 private void initMenus()
166 seqColour.setSelected(jmb.isColourBySequence());
167 jmolColour.setSelected(!jmb.isColourBySequence());
168 if (_colourwith == null)
170 _colourwith = new Vector<AlignmentPanel>();
172 if (_alignwith == null)
174 _alignwith = new Vector<AlignmentPanel>();
177 seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith,
182 public void itemStateChanged(ItemEvent e)
184 if (!seqColour.isSelected())
190 // update the jmol display now.
191 seqColour_actionPerformed(null);
195 viewMenu.add(seqColourBy);
196 final ItemListener handler;
197 JMenu alpanels = new ViewSelectionMenu("Superpose with ..", this,
198 _alignwith, handler = new ItemListener()
202 public void itemStateChanged(ItemEvent e)
204 alignStructs.setEnabled(_alignwith.size() > 0);
205 alignStructs.setToolTipText(MessageManager
207 "label.align_structures_using_linked_alignment_views",
209 { new Integer(_alignwith.size()).toString() }));
212 handler.itemStateChanged(null);
213 jmolActionMenu.add(alpanels);
214 jmolActionMenu.addMenuListener(new MenuListener()
218 public void menuSelected(MenuEvent e)
220 handler.itemStateChanged(null);
224 public void menuDeselected(MenuEvent e)
226 // TODO Auto-generated method stub
231 public void menuCanceled(MenuEvent e)
233 // TODO Auto-generated method stub
239 IProgressIndicator progressBar = null;
242 * add a single PDB structure to a new or existing Jmol view
249 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
250 final AlignmentPanel ap)
252 progressBar = ap.alignFrame;
253 // ////////////////////////////////
254 // Is the pdb file already loaded?
255 String alreadyMapped = ap.getStructureSelectionManager()
256 .alreadyMappedToFile(pdbentry.getId());
258 if (alreadyMapped != null)
260 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
261 MessageManager.formatMessage(
262 "label.pdb_entry_is_already_displayed", new String[]
263 { pdbentry.getId() }), MessageManager.formatMessage(
264 "label.map_sequences_to_visible_window", new String[]
265 { pdbentry.getId() }), JOptionPane.YES_NO_OPTION);
267 if (option == JOptionPane.YES_OPTION)
269 // TODO : Fix multiple seq to one chain issue here.
270 ap.getStructureSelectionManager().setMapping(seq, chains,
271 alreadyMapped, AppletFormatAdapter.FILE);
272 if (ap.seqPanel.seqCanvas.fr != null)
274 ap.seqPanel.seqCanvas.fr.featuresAdded();
275 ap.paintAlignment(true);
278 // Now this AppJmol is mapped to new sequences. We must add them to
279 // the exisiting array
280 JInternalFrame[] frames = Desktop.instance.getAllFrames();
282 for (int i = 0; i < frames.length; i++)
284 if (frames[i] instanceof AppJmol)
286 final AppJmol topJmol = ((AppJmol) frames[i]);
287 // JBPNOTE: this looks like a binding routine, rather than a gui
289 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
291 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
293 topJmol.jmb.addSequence(pe, seq);
294 topJmol.addAlignmentPanel(ap);
295 // add it to the set used for colouring
296 topJmol.useAlignmentPanelForColourbyseq(ap);
297 topJmol.buildJmolActionMenu();
298 ap.getStructureSelectionManager()
299 .sequenceColoursChanged(ap);
309 // /////////////////////////////////
310 // Check if there are other Jmol views involving this alignment
311 // and prompt user about adding this molecule to one of them
312 Vector existingViews = getJmolsFor(ap);
313 if (existingViews.size() > 0)
315 Enumeration jm = existingViews.elements();
316 while (jm.hasMoreElements())
318 AppJmol topJmol = (AppJmol) jm.nextElement();
319 // TODO: highlight topJmol in view somehow
320 int option = JOptionPane
321 .showInternalConfirmDialog(
323 MessageManager.formatMessage(
324 "label.add_pdbentry_to_view", new String[]
325 { pdbentry.getId(), topJmol.getTitle() }),
327 .getString("label.align_to_existing_structure_view"),
328 JOptionPane.YES_NO_OPTION);
329 if (option == JOptionPane.YES_OPTION)
331 topJmol.useAlignmentPanelForSuperposition(ap);
332 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
337 // /////////////////////////////////
338 openNewJmol(ap, new PDBEntry[]
339 { pdbentry }, new SequenceI[][]
343 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
346 progressBar = ap.alignFrame;
347 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
348 pdbentrys, seqs, null, null);
349 addAlignmentPanel(ap);
350 useAlignmentPanelForColourbyseq(ap);
351 if (pdbentrys.length > 1)
353 alignAddedStructures = true;
354 useAlignmentPanelForSuperposition(ap);
356 jmb.setColourBySequence(true);
357 setSize(400, 400); // probably should be a configurable/dynamic default here
361 addingStructures = false;
362 worker = new Thread(this);
365 this.addInternalFrameListener(new InternalFrameAdapter()
367 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
376 * create a new Jmol containing several structures superimposed using the
383 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
385 openNewJmol(ap, pe, seqs);
389 * list of sequenceSet ids associated with the view
391 ArrayList<String> _aps = new ArrayList();
393 public AlignmentPanel[] getAllAlignmentPanels()
395 AlignmentPanel[] t, list = new AlignmentPanel[0];
396 for (String setid : _aps)
398 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
401 t = new AlignmentPanel[list.length + panels.length];
402 System.arraycopy(list, 0, t, 0, list.length);
403 System.arraycopy(panels, 0, t, list.length, panels.length);
412 * list of alignment panels to use for superposition
414 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
417 * list of alignment panels that are used for colouring structures by aligned
420 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
423 * set the primary alignmentPanel reference and add another alignPanel to the
424 * list of ones to use for colouring and aligning
428 public void addAlignmentPanel(AlignmentPanel nap)
434 if (!_aps.contains(nap.av.getSequenceSetId()))
436 _aps.add(nap.av.getSequenceSetId());
441 * remove any references held to the given alignment panel
445 public void removeAlignmentPanel(AlignmentPanel nap)
449 _alignwith.remove(nap);
450 _colourwith.remove(nap);
454 for (AlignmentPanel aps : getAllAlignmentPanels())
463 } catch (Exception ex)
468 buildJmolActionMenu();
472 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
474 addAlignmentPanel(nap);
475 if (!_alignwith.contains(nap))
481 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
483 if (_alignwith.contains(nap))
485 _alignwith.remove(nap);
489 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
490 boolean enableColourBySeq)
492 useAlignmentPanelForColourbyseq(nap);
493 jmb.setColourBySequence(enableColourBySeq);
494 seqColour.setSelected(enableColourBySeq);
495 jmolColour.setSelected(!enableColourBySeq);
498 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
500 addAlignmentPanel(nap);
501 if (!_colourwith.contains(nap))
503 _colourwith.add(nap);
507 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
509 if (_colourwith.contains(nap))
511 _colourwith.remove(nap);
516 * pdb retrieval thread.
518 private Thread worker = null;
521 * add a new structure (with associated sequences and chains) to this viewer,
522 * retrieving it if necessary first.
529 * if true, new structure(s) will be align using associated alignment
531 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
532 final String[] chains, final boolean b,
533 final IProgressIndicator alignFrame)
535 if (pdbentry.getFile() == null)
537 if (worker != null && worker.isAlive())
539 // a retrieval is in progress, wait around and add ourselves to the
541 new Thread(new Runnable()
545 while (worker != null && worker.isAlive() && _started)
549 Thread.sleep(100 + ((int) Math.random() * 100));
551 } catch (Exception e)
556 // and call ourselves again.
557 addStructure(pdbentry, seq, chains, b, alignFrame);
563 // otherwise, start adding the structure.
564 jmb.addSequenceAndChain(new PDBEntry[]
565 { pdbentry }, new SequenceI[][]
566 { seq }, new String[][]
568 addingStructures = true;
570 alignAddedStructures = b;
571 progressBar = alignFrame; // visual indication happens on caller frame.
572 (worker = new Thread(this)).start();
576 private Vector getJmolsFor(AlignmentPanel ap2)
578 Vector otherJmols = new Vector();
579 // Now this AppJmol is mapped to new sequences. We must add them to
580 // the exisiting array
581 JInternalFrame[] frames = Desktop.instance.getAllFrames();
583 for (int i = 0; i < frames.length; i++)
585 if (frames[i] instanceof AppJmol)
587 AppJmol topJmol = ((AppJmol) frames[i]);
588 if (topJmol.isLinkedWith(ap2))
590 otherJmols.addElement(topJmol);
597 void initJmol(String command)
599 jmb.setFinishedInit(false);
600 renderPanel = new RenderPanel();
601 // TODO: consider waiting until the structure/view is fully loaded before
603 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
604 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
605 getBounds().width, getBounds().height);
606 if (scriptWindow == null)
608 BorderLayout bl = new BorderLayout();
611 scriptWindow = new JPanel(bl);
612 scriptWindow.setVisible(false);
615 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
617 jmb.newJmolPopup(true, "Jmol", true);
622 jmb.evalStateCommand(command);
623 jmb.setFinishedInit(true);
626 void setChainMenuItems(Vector chains)
628 chainMenu.removeAll();
633 JMenuItem menuItem = new JMenuItem(
634 MessageManager.getString("label.all"));
635 menuItem.addActionListener(new ActionListener()
637 public void actionPerformed(ActionEvent evt)
639 allChainsSelected = true;
640 for (int i = 0; i < chainMenu.getItemCount(); i++)
642 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
643 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
646 allChainsSelected = false;
650 chainMenu.add(menuItem);
652 for (int c = 0; c < chains.size(); c++)
654 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
655 menuItem.addItemListener(new ItemListener()
657 public void itemStateChanged(ItemEvent evt)
659 if (!allChainsSelected)
664 chainMenu.add(menuItem);
668 boolean allChainsSelected = false;
670 private boolean alignAddedStructures = false;
674 Vector toshow = new Vector();
676 int mlength, p, mnum;
677 for (int i = 0; i < chainMenu.getItemCount(); i++)
679 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
681 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
682 if (item.isSelected())
684 toshow.addElement(item.getText());
688 jmb.centerViewer(toshow);
698 // TODO: check for memory leaks where instance isn't finalised because jmb
699 // holds a reference to the window
704 * state flag for PDB retrieval thread
706 private boolean _started = false;
712 // todo - record which pdbids were successfuly imported.
713 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
716 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
717 // TODO: replace with reference fetching/transfer code (validate PDBentry
719 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
720 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
722 String file = jmb.pdbentry[pi].getFile();
725 // retrieve the pdb and store it locally
726 AlignmentI pdbseq = null;
727 pdbid = jmb.pdbentry[pi].getId();
728 long hdl = pdbid.hashCode() - System.currentTimeMillis();
729 if (progressBar != null)
731 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
735 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
737 } catch (OutOfMemoryError oomerror)
739 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
740 } catch (Exception ex)
742 ex.printStackTrace();
743 errormsgs.append("'" + pdbid + "'");
745 if (progressBar != null)
747 progressBar.setProgressBar("Finished.", hdl);
751 // just transfer the file name from the first sequence's first
753 file = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
754 .elementAt(0)).getFile()).getAbsolutePath();
755 jmb.pdbentry[pi].setFile(file);
757 files.append(" \"" + Platform.escapeString(file) + "\"");
761 errormsgs.append("'" + pdbid + "' ");
766 if (curfiles != null && curfiles.length > 0)
768 addingStructures = true; // already files loaded.
769 for (int c = 0; c < curfiles.length; c++)
771 if (curfiles[c].equals(file))
780 files.append(" \"" + Platform.escapeString(file) + "\"");
784 } catch (OutOfMemoryError oomerror)
786 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
787 } catch (Exception ex)
789 ex.printStackTrace();
790 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
793 if (errormsgs.length() > 0)
796 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
797 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
799 { errormsgs.toString() }), MessageManager
800 .getString("label.couldnt_load_file"),
801 JOptionPane.ERROR_MESSAGE);
804 long lastnotify = jmb.getLoadNotifiesHandled();
805 if (files.length() > 0)
807 if (!addingStructures)
812 initJmol("load FILES " + files.toString());
813 } catch (OutOfMemoryError oomerror)
815 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
816 Cache.log.debug("File locations are " + files);
817 } catch (Exception ex)
819 Cache.log.error("Couldn't open Jmol viewer!", ex);
824 StringBuffer cmd = new StringBuffer();
825 cmd.append("loadingJalviewdata=true\nload APPEND ");
826 cmd.append(files.toString());
827 cmd.append("\nloadingJalviewdata=null");
828 final String command = cmd.toString();
830 lastnotify = jmb.getLoadNotifiesHandled();
834 jmb.evalStateCommand(command);
835 } catch (OutOfMemoryError oomerror)
838 "When trying to add structures to the Jmol viewer!",
840 Cache.log.debug("File locations are " + files);
841 } catch (Exception ex)
843 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
847 // need to wait around until script has finished
848 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
849 : (jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb
850 .getPdbFile().length != jmb.pdbentry.length))
854 Cache.log.debug("Waiting around for jmb notify.");
856 } catch (Exception e)
860 // refresh the sequence colours for the new structure(s)
861 for (AlignmentPanel ap : _colourwith)
863 jmb.updateColours(ap);
865 // do superposition if asked to
866 if (alignAddedStructures)
868 javax.swing.SwingUtilities.invokeLater(new Runnable()
872 alignStructs_withAllAlignPanels();
873 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
876 alignAddedStructures = false;
878 addingStructures = false;
885 public void pdbFile_actionPerformed(ActionEvent actionEvent)
887 JalviewFileChooser chooser = new JalviewFileChooser(
888 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
890 chooser.setFileView(new JalviewFileView());
891 chooser.setDialogTitle("Save PDB File");
892 chooser.setToolTipText(MessageManager.getString("action.save"));
894 int value = chooser.showSaveDialog(this);
896 if (value == JalviewFileChooser.APPROVE_OPTION)
900 // TODO: cope with multiple PDB files in view
901 BufferedReader in = new BufferedReader(new FileReader(
902 jmb.getPdbFile()[0]));
903 File outFile = chooser.getSelectedFile();
905 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
907 while ((data = in.readLine()) != null)
909 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
915 } catch (Exception ex)
917 ex.printStackTrace();
922 public void viewMapping_actionPerformed(ActionEvent actionEvent)
924 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
927 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
929 cap.appendText(jmb.printMapping(jmb.pdbentry[pdbe].getFile()));
930 cap.appendText("\n");
932 } catch (OutOfMemoryError e)
935 "composing sequence-structure alignments for display in text box.",
940 jalview.gui.Desktop.addInternalFrame(cap,
941 MessageManager.getString("label.pdb_sequence_mapping"), 550,
951 public void eps_actionPerformed(ActionEvent e)
953 makePDBImage(jalview.util.ImageMaker.EPS);
962 public void png_actionPerformed(ActionEvent e)
964 makePDBImage(jalview.util.ImageMaker.PNG);
967 void makePDBImage(int type)
969 int width = getWidth();
970 int height = getHeight();
972 jalview.util.ImageMaker im;
974 if (type == jalview.util.ImageMaker.PNG)
976 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
977 "Make PNG image from view", width, height, null, null);
981 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
982 "Make EPS file from view", width, height, null,
986 if (im.getGraphics() != null)
988 Rectangle rect = new Rectangle(width, height);
989 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
994 public void jmolColour_actionPerformed(ActionEvent actionEvent)
996 if (jmolColour.isSelected())
998 // disable automatic sequence colouring.
999 jmb.setColourBySequence(false);
1003 public void seqColour_actionPerformed(ActionEvent actionEvent)
1005 jmb.setColourBySequence(seqColour.isSelected());
1006 if (_colourwith == null)
1008 _colourwith = new Vector<AlignmentPanel>();
1010 if (jmb.isColourBySequence())
1012 if (!jmb.isLoadingFromArchive())
1014 if (_colourwith.size() == 0 && ap != null)
1016 // Make the currently displayed alignment panel the associated view
1017 _colourwith.add(ap.alignFrame.alignPanel);
1020 // Set the colour using the current view for the associated alignframe
1021 for (AlignmentPanel ap : _colourwith)
1023 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
1028 public void chainColour_actionPerformed(ActionEvent actionEvent)
1030 chainColour.setSelected(true);
1031 jmb.colourByChain();
1034 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1036 chargeColour.setSelected(true);
1037 jmb.colourByCharge();
1040 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1042 zappoColour.setSelected(true);
1043 jmb.setJalviewColourScheme(new ZappoColourScheme());
1046 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1048 taylorColour.setSelected(true);
1049 jmb.setJalviewColourScheme(new TaylorColourScheme());
1052 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1054 hydroColour.setSelected(true);
1055 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1058 public void helixColour_actionPerformed(ActionEvent actionEvent)
1060 helixColour.setSelected(true);
1061 jmb.setJalviewColourScheme(new HelixColourScheme());
1064 public void strandColour_actionPerformed(ActionEvent actionEvent)
1066 strandColour.setSelected(true);
1067 jmb.setJalviewColourScheme(new StrandColourScheme());
1070 public void turnColour_actionPerformed(ActionEvent actionEvent)
1072 turnColour.setSelected(true);
1073 jmb.setJalviewColourScheme(new TurnColourScheme());
1076 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1078 buriedColour.setSelected(true);
1079 jmb.setJalviewColourScheme(new BuriedColourScheme());
1082 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1084 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1087 public void userColour_actionPerformed(ActionEvent actionEvent)
1089 userColour.setSelected(true);
1090 new UserDefinedColours(this, null);
1093 public void backGround_actionPerformed(ActionEvent actionEvent)
1095 java.awt.Color col = JColorChooser.showDialog(this,
1096 "Select Background Colour", null);
1099 jmb.setBackgroundColour(col);
1103 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1107 jalview.util.BrowserLauncher
1108 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1109 } catch (Exception ex)
1114 public void showConsole(boolean showConsole)
1119 if (splitPane == null)
1121 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1122 splitPane.setTopComponent(renderPanel);
1123 splitPane.setBottomComponent(scriptWindow);
1124 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1125 splitPane.setDividerLocation(getHeight() - 200);
1126 scriptWindow.setVisible(true);
1127 scriptWindow.validate();
1128 splitPane.validate();
1134 if (splitPane != null)
1136 splitPane.setVisible(false);
1141 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1147 class RenderPanel extends JPanel
1149 final Dimension currentSize = new Dimension();
1151 final Rectangle rectClip = new Rectangle();
1153 public void paintComponent(Graphics g)
1155 getSize(currentSize);
1156 g.getClipBounds(rectClip);
1158 if (jmb.fileLoadingError != null)
1160 g.setColor(Color.black);
1161 g.fillRect(0, 0, currentSize.width, currentSize.height);
1162 g.setColor(Color.white);
1163 g.setFont(new Font("Verdana", Font.BOLD, 14));
1164 g.drawString(MessageManager.getString("label.error_loading_file")
1165 + "...", 20, currentSize.height / 2);
1166 StringBuffer sb = new StringBuffer();
1168 for (int e = 0; e < jmb.pdbentry.length; e++)
1170 sb.append(jmb.pdbentry[e].getId());
1171 if (e < jmb.pdbentry.length - 1)
1176 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1179 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1180 * g.getFontMetrics().getHeight());
1184 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1186 g.setColor(Color.black);
1187 g.fillRect(0, 0, currentSize.width, currentSize.height);
1188 g.setColor(Color.white);
1189 g.setFont(new Font("Verdana", Font.BOLD, 14));
1190 g.drawString(MessageManager.getString("label.retrieving_pdb_data"),
1191 20, currentSize.height / 2);
1195 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1200 String viewId = null;
1202 public String getViewId()
1206 viewId = System.currentTimeMillis() + "." + this.hashCode();
1211 public void updateTitleAndMenus()
1213 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1218 setChainMenuItems(jmb.chainNames);
1220 this.setTitle(jmb.getViewerTitle());
1221 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1223 jmolActionMenu.setVisible(true);
1225 if (!jmb.isLoadingFromArchive())
1227 seqColour_actionPerformed(null);
1231 protected void buildJmolActionMenu()
1233 if (_alignwith == null)
1235 _alignwith = new Vector<AlignmentPanel>();
1237 if (_alignwith.size() == 0 && ap != null)
1242 for (Component c : jmolActionMenu.getMenuComponents())
1244 if (c != alignStructs)
1246 jmolActionMenu.remove((JMenuItem) c);
1249 final ItemListener handler;
1256 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1260 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1262 alignStructs_withAllAlignPanels();
1265 private void alignStructs_withAllAlignPanels()
1272 if (_alignwith.size() == 0)
1279 AlignmentI[] als = new Alignment[_alignwith.size()];
1280 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1281 int[] alm = new int[_alignwith.size()];
1284 for (AlignmentPanel ap : _alignwith)
1286 als[a] = ap.av.getAlignment();
1288 alc[a++] = ap.av.getColumnSelection();
1290 jmb.superposeStructures(als, alm, alc);
1291 } catch (Exception e)
1293 StringBuffer sp = new StringBuffer();
1294 for (AlignmentPanel ap : _alignwith)
1296 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1298 Cache.log.info("Couldn't align structures with the " + sp.toString()
1299 + "associated alignment panels.", e);
1305 public void setJalviewColourScheme(ColourSchemeI ucs)
1307 jmb.setJalviewColourScheme(ucs);
1314 * @return first alignment panel displaying given alignment, or the default
1317 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1319 for (AlignmentPanel ap : getAllAlignmentPanels())
1321 if (ap.av.getAlignment() == alignment)
1332 * @return true if this Jmol instance is linked with the given alignPanel
1334 public boolean isLinkedWith(AlignmentPanel ap2)
1336 return _aps.contains(ap2.av.getSequenceSetId());
1339 public boolean isUsedforaligment(AlignmentPanel ap2)
1342 return (_alignwith != null) && _alignwith.contains(ap2);
1345 public boolean isUsedforcolourby(AlignmentPanel ap2)
1347 return (_colourwith != null) && _colourwith.contains(ap2);
1352 * @return TRUE if the view is NOT being coloured by sequence associations.
1354 public boolean isColouredByJmol()
1356 return !jmb.isColourBySequence();