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.formatMessage("label.align_structures_using_linked_alignment_views", new String[] {new Integer(_alignwith.size()).toString()}));
208 handler.itemStateChanged(null);
209 jmolActionMenu.add(alpanels);
210 jmolActionMenu.addMenuListener(new MenuListener()
214 public void menuSelected(MenuEvent e)
216 handler.itemStateChanged(null);
220 public void menuDeselected(MenuEvent e)
222 // TODO Auto-generated method stub
227 public void menuCanceled(MenuEvent e)
229 // TODO Auto-generated method stub
235 IProgressIndicator progressBar = null;
238 * add a single PDB structure to a new or existing Jmol view
245 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
246 final AlignmentPanel ap)
248 progressBar = ap.alignFrame;
249 // ////////////////////////////////
250 // Is the pdb file already loaded?
251 String alreadyMapped = ap.getStructureSelectionManager()
252 .alreadyMappedToFile(pdbentry.getId());
254 if (alreadyMapped != null)
256 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
257 MessageManager.formatMessage("label.pdb_entry_is_already_displayed", new String[]{pdbentry.getId()}),
258 MessageManager.formatMessage("label.map_sequences_to_visible_window", new String[]{pdbentry.getId()}),
259 JOptionPane.YES_NO_OPTION);
261 if (option == JOptionPane.YES_OPTION)
263 // TODO : Fix multiple seq to one chain issue here.
264 ap.getStructureSelectionManager().setMapping(seq, chains,
265 alreadyMapped, AppletFormatAdapter.FILE);
266 if (ap.seqPanel.seqCanvas.fr != null)
268 ap.seqPanel.seqCanvas.fr.featuresAdded();
269 ap.paintAlignment(true);
272 // Now this AppJmol is mapped to new sequences. We must add them to
273 // the exisiting array
274 JInternalFrame[] frames = Desktop.instance.getAllFrames();
276 for (int i = 0; i < frames.length; i++)
278 if (frames[i] instanceof AppJmol)
280 final AppJmol topJmol = ((AppJmol) frames[i]);
281 // JBPNOTE: this looks like a binding routine, rather than a gui
283 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
285 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
287 topJmol.jmb.addSequence(pe, seq);
288 topJmol.addAlignmentPanel(ap);
289 // add it to the set used for colouring
290 topJmol.useAlignmentPanelForColourbyseq(ap);
291 topJmol.buildJmolActionMenu();
292 ap.getStructureSelectionManager()
293 .sequenceColoursChanged(ap);
303 // /////////////////////////////////
304 // Check if there are other Jmol views involving this alignment
305 // and prompt user about adding this molecule to one of them
306 Vector existingViews = getJmolsFor(ap);
307 if (existingViews.size() > 0)
309 Enumeration jm = existingViews.elements();
310 while (jm.hasMoreElements())
312 AppJmol topJmol = (AppJmol) jm.nextElement();
313 // TODO: highlight topJmol in view somehow
314 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
315 MessageManager.formatMessage("label.add_pdbentry_to_view", new String[]{pdbentry.getId(),topJmol.getTitle()}),
316 MessageManager.getString("label.align_to_existing_structure_view"),
317 JOptionPane.YES_NO_OPTION);
318 if (option == JOptionPane.YES_OPTION)
320 topJmol.useAlignmentPanelForSuperposition(ap);
321 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
326 // /////////////////////////////////
327 openNewJmol(ap, new PDBEntry[]
328 { pdbentry }, new SequenceI[][]
332 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
335 progressBar = ap.alignFrame;
336 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
337 pdbentrys, seqs, null, null);
338 addAlignmentPanel(ap);
339 useAlignmentPanelForColourbyseq(ap);
340 if (pdbentrys.length > 1)
342 alignAddedStructures = true;
343 useAlignmentPanelForSuperposition(ap);
345 jmb.setColourBySequence(true);
346 setSize(400, 400); // probably should be a configurable/dynamic default here
350 addingStructures = false;
351 worker = new Thread(this);
354 this.addInternalFrameListener(new InternalFrameAdapter()
356 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
365 * create a new Jmol containing several structures superimposed using the
372 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
374 openNewJmol(ap, pe, seqs);
378 * list of sequenceSet ids associated with the view
380 ArrayList<String> _aps = new ArrayList();
382 public AlignmentPanel[] getAllAlignmentPanels()
384 AlignmentPanel[] t, list = new AlignmentPanel[0];
385 for (String setid : _aps)
387 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
390 t = new AlignmentPanel[list.length + panels.length];
391 System.arraycopy(list, 0, t, 0, list.length);
392 System.arraycopy(panels, 0, t, list.length, panels.length);
401 * list of alignment panels to use for superposition
403 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
406 * list of alignment panels that are used for colouring structures by aligned
409 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
412 * set the primary alignmentPanel reference and add another alignPanel to the
413 * list of ones to use for colouring and aligning
417 public void addAlignmentPanel(AlignmentPanel nap)
423 if (!_aps.contains(nap.av.getSequenceSetId()))
425 _aps.add(nap.av.getSequenceSetId());
430 * remove any references held to the given alignment panel
434 public void removeAlignmentPanel(AlignmentPanel nap)
438 _alignwith.remove(nap);
439 _colourwith.remove(nap);
443 for (AlignmentPanel aps : getAllAlignmentPanels())
452 } catch (Exception ex)
457 buildJmolActionMenu();
461 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
463 addAlignmentPanel(nap);
464 if (!_alignwith.contains(nap))
470 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
472 if (_alignwith.contains(nap))
474 _alignwith.remove(nap);
478 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
479 boolean enableColourBySeq)
481 useAlignmentPanelForColourbyseq(nap);
482 jmb.setColourBySequence(enableColourBySeq);
483 seqColour.setSelected(enableColourBySeq);
484 jmolColour.setSelected(!enableColourBySeq);
487 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
489 addAlignmentPanel(nap);
490 if (!_colourwith.contains(nap))
492 _colourwith.add(nap);
496 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
498 if (_colourwith.contains(nap))
500 _colourwith.remove(nap);
505 * pdb retrieval thread.
507 private Thread worker = null;
510 * add a new structure (with associated sequences and chains) to this viewer,
511 * retrieving it if necessary first.
518 * if true, new structure(s) will be align using associated alignment
520 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
521 final String[] chains, final boolean b,
522 final IProgressIndicator alignFrame)
524 if (pdbentry.getFile() == null)
526 if (worker != null && worker.isAlive())
528 // a retrieval is in progress, wait around and add ourselves to the
530 new Thread(new Runnable()
534 while (worker != null && worker.isAlive() && _started)
538 Thread.sleep(100 + ((int) Math.random() * 100));
540 } catch (Exception e)
545 // and call ourselves again.
546 addStructure(pdbentry, seq, chains, b, alignFrame);
552 // otherwise, start adding the structure.
553 jmb.addSequenceAndChain(new PDBEntry[]
554 { pdbentry }, new SequenceI[][]
555 { seq }, new String[][]
557 addingStructures = true;
559 alignAddedStructures = b;
560 progressBar = alignFrame; // visual indication happens on caller frame.
561 (worker = new Thread(this)).start();
565 private Vector getJmolsFor(AlignmentPanel ap2)
567 Vector otherJmols = new Vector();
568 // Now this AppJmol is mapped to new sequences. We must add them to
569 // the exisiting array
570 JInternalFrame[] frames = Desktop.instance.getAllFrames();
572 for (int i = 0; i < frames.length; i++)
574 if (frames[i] instanceof AppJmol)
576 AppJmol topJmol = ((AppJmol) frames[i]);
577 if (topJmol.isLinkedWith(ap2))
579 otherJmols.addElement(topJmol);
586 void initJmol(String command)
588 jmb.setFinishedInit(false);
589 renderPanel = new RenderPanel();
590 // TODO: consider waiting until the structure/view is fully loaded before
592 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
593 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
594 getBounds().width, getBounds().height);
595 if (scriptWindow == null)
597 BorderLayout bl = new BorderLayout();
600 scriptWindow = new JPanel(bl);
601 scriptWindow.setVisible(false);
604 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
606 jmb.newJmolPopup(true, "Jmol", true);
611 jmb.evalStateCommand(command);
612 jmb.setFinishedInit(true);
615 void setChainMenuItems(Vector chains)
617 chainMenu.removeAll();
622 JMenuItem menuItem = new JMenuItem(MessageManager.getString("label.all"));
623 menuItem.addActionListener(new ActionListener()
625 public void actionPerformed(ActionEvent evt)
627 allChainsSelected = true;
628 for (int i = 0; i < chainMenu.getItemCount(); i++)
630 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
631 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
634 allChainsSelected = false;
638 chainMenu.add(menuItem);
640 for (int c = 0; c < chains.size(); c++)
642 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
643 menuItem.addItemListener(new ItemListener()
645 public void itemStateChanged(ItemEvent evt)
647 if (!allChainsSelected)
652 chainMenu.add(menuItem);
656 boolean allChainsSelected = false;
658 private boolean alignAddedStructures = false;
662 Vector toshow = new Vector();
664 int mlength, p, mnum;
665 for (int i = 0; i < chainMenu.getItemCount(); i++)
667 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
669 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
670 if (item.isSelected())
672 toshow.addElement(item.getText());
676 jmb.centerViewer(toshow);
686 // TODO: check for memory leaks where instance isn't finalised because jmb
687 // holds a reference to the window
692 * state flag for PDB retrieval thread
694 private boolean _started = false;
700 // todo - record which pdbids were successfuly imported.
701 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
704 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
705 // TODO: replace with reference fetching/transfer code (validate PDBentry
707 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
708 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
710 String file = jmb.pdbentry[pi].getFile();
713 // retrieve the pdb and store it locally
714 AlignmentI pdbseq = null;
715 pdbid = jmb.pdbentry[pi].getId();
716 long hdl = pdbid.hashCode() - System.currentTimeMillis();
717 if (progressBar != null)
719 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
723 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
725 } catch (OutOfMemoryError oomerror)
727 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
728 } catch (Exception ex)
730 ex.printStackTrace();
731 errormsgs.append("'" + pdbid + "'");
733 if (progressBar != null)
735 progressBar.setProgressBar("Finished.", hdl);
739 // just transfer the file name from the first sequence's first
741 file = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
742 .elementAt(0)).getFile()).getAbsolutePath();
743 jmb.pdbentry[pi].setFile(file);
745 files.append(" \"" + Platform.escapeString(file) + "\"");
749 errormsgs.append("'" + pdbid + "' ");
754 if (curfiles != null && curfiles.length > 0)
756 addingStructures = true; // already files loaded.
757 for (int c = 0; c < curfiles.length; c++)
759 if (curfiles[c].equals(file))
768 files.append(" \"" + Platform.escapeString(file) + "\"");
772 } catch (OutOfMemoryError oomerror)
774 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
775 } catch (Exception ex)
777 ex.printStackTrace();
778 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
781 if (errormsgs.length() > 0)
784 JOptionPane.showInternalMessageDialog(Desktop.desktop,
785 MessageManager.formatMessage("label.pdb_entries_couldnt_be_retrieved", new String[]{errormsgs.toString()}),
786 MessageManager.getString("label.couldnt_load_file"), JOptionPane.ERROR_MESSAGE);
789 long lastnotify = jmb.getLoadNotifiesHandled();
790 if (files.length() > 0)
792 if (!addingStructures)
797 initJmol("load FILES " + files.toString());
798 } catch (OutOfMemoryError oomerror)
800 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
801 Cache.log.debug("File locations are " + files);
802 } catch (Exception ex)
804 Cache.log.error("Couldn't open Jmol viewer!", ex);
809 StringBuffer cmd = new StringBuffer();
810 cmd.append("loadingJalviewdata=true\nload APPEND ");
811 cmd.append(files.toString());
812 cmd.append("\nloadingJalviewdata=null");
813 final String command = cmd.toString();
815 lastnotify = jmb.getLoadNotifiesHandled();
819 jmb.evalStateCommand(command);
820 } catch (OutOfMemoryError oomerror)
823 "When trying to add structures to the Jmol viewer!",
825 Cache.log.debug("File locations are " + files);
826 } catch (Exception ex)
828 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
832 // need to wait around until script has finished
833 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
834 : (jmb.isFinishedInit() && jmb.getPdbFile()!=null && jmb.getPdbFile().length != jmb.pdbentry.length))
838 Cache.log.debug("Waiting around for jmb notify.");
840 } catch (Exception e)
844 // refresh the sequence colours for the new structure(s)
845 for (AlignmentPanel ap : _colourwith)
847 jmb.updateColours(ap);
849 // do superposition if asked to
850 if (alignAddedStructures)
852 javax.swing.SwingUtilities.invokeLater(new Runnable()
856 alignStructs_withAllAlignPanels();
857 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
860 alignAddedStructures = false;
862 addingStructures = false;
869 public void pdbFile_actionPerformed(ActionEvent actionEvent)
871 JalviewFileChooser chooser = new JalviewFileChooser(
872 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
874 chooser.setFileView(new JalviewFileView());
875 chooser.setDialogTitle("Save PDB File");
876 chooser.setToolTipText(MessageManager.getString("action.save"));
878 int value = chooser.showSaveDialog(this);
880 if (value == JalviewFileChooser.APPROVE_OPTION)
884 // TODO: cope with multiple PDB files in view
885 BufferedReader in = new BufferedReader(new FileReader(
886 jmb.getPdbFile()[0]));
887 File outFile = chooser.getSelectedFile();
889 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
891 while ((data = in.readLine()) != null)
893 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
899 } catch (Exception ex)
901 ex.printStackTrace();
906 public void viewMapping_actionPerformed(ActionEvent actionEvent)
908 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
911 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
913 cap.appendText(jmb.printMapping(jmb.pdbentry[pdbe].getFile()));
914 cap.appendText("\n");
916 } catch (OutOfMemoryError e)
919 "composing sequence-structure alignments for display in text box.",
924 jalview.gui.Desktop.addInternalFrame(cap, MessageManager.getString("label.pdb_sequence_mapping"),
934 public void eps_actionPerformed(ActionEvent e)
936 makePDBImage(jalview.util.ImageMaker.EPS);
945 public void png_actionPerformed(ActionEvent e)
947 makePDBImage(jalview.util.ImageMaker.PNG);
950 void makePDBImage(int type)
952 int width = getWidth();
953 int height = getHeight();
955 jalview.util.ImageMaker im;
957 if (type == jalview.util.ImageMaker.PNG)
959 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
960 "Make PNG image from view", width, height, null, null);
964 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
965 "Make EPS file from view", width, height, null,
969 if (im.getGraphics() != null)
971 Rectangle rect = new Rectangle(width, height);
972 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
977 public void jmolColour_actionPerformed(ActionEvent actionEvent)
979 if (jmolColour.isSelected())
981 // disable automatic sequence colouring.
982 jmb.setColourBySequence(false);
986 public void seqColour_actionPerformed(ActionEvent actionEvent)
988 jmb.setColourBySequence(seqColour.isSelected());
989 if (_colourwith == null)
991 _colourwith = new Vector<AlignmentPanel>();
993 if (jmb.isColourBySequence())
995 if (!jmb.isLoadingFromArchive())
997 if (_colourwith.size() == 0 && ap != null)
999 // Make the currently displayed alignment panel the associated view
1000 _colourwith.add(ap.alignFrame.alignPanel);
1003 // Set the colour using the current view for the associated alignframe
1004 for (AlignmentPanel ap : _colourwith)
1006 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
1011 public void chainColour_actionPerformed(ActionEvent actionEvent)
1013 chainColour.setSelected(true);
1014 jmb.colourByChain();
1017 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1019 chargeColour.setSelected(true);
1020 jmb.colourByCharge();
1023 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1025 zappoColour.setSelected(true);
1026 jmb.setJalviewColourScheme(new ZappoColourScheme());
1029 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1031 taylorColour.setSelected(true);
1032 jmb.setJalviewColourScheme(new TaylorColourScheme());
1035 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1037 hydroColour.setSelected(true);
1038 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1041 public void helixColour_actionPerformed(ActionEvent actionEvent)
1043 helixColour.setSelected(true);
1044 jmb.setJalviewColourScheme(new HelixColourScheme());
1047 public void strandColour_actionPerformed(ActionEvent actionEvent)
1049 strandColour.setSelected(true);
1050 jmb.setJalviewColourScheme(new StrandColourScheme());
1053 public void turnColour_actionPerformed(ActionEvent actionEvent)
1055 turnColour.setSelected(true);
1056 jmb.setJalviewColourScheme(new TurnColourScheme());
1059 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1061 buriedColour.setSelected(true);
1062 jmb.setJalviewColourScheme(new BuriedColourScheme());
1065 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1067 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1070 public void userColour_actionPerformed(ActionEvent actionEvent)
1072 userColour.setSelected(true);
1073 new UserDefinedColours(this, null);
1076 public void backGround_actionPerformed(ActionEvent actionEvent)
1078 java.awt.Color col = JColorChooser.showDialog(this,
1079 "Select Background Colour", null);
1082 jmb.setBackgroundColour(col);
1086 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1090 jalview.util.BrowserLauncher
1091 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1092 } catch (Exception ex)
1097 public void showConsole(boolean showConsole)
1102 if (splitPane == null)
1104 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1105 splitPane.setTopComponent(renderPanel);
1106 splitPane.setBottomComponent(scriptWindow);
1107 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1108 splitPane.setDividerLocation(getHeight() - 200);
1109 scriptWindow.setVisible(true);
1110 scriptWindow.validate();
1111 splitPane.validate();
1117 if (splitPane != null)
1119 splitPane.setVisible(false);
1124 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1130 class RenderPanel extends JPanel
1132 final Dimension currentSize = new Dimension();
1134 final Rectangle rectClip = new Rectangle();
1136 public void paintComponent(Graphics g)
1138 getSize(currentSize);
1139 g.getClipBounds(rectClip);
1141 if (jmb.fileLoadingError != null)
1143 g.setColor(Color.black);
1144 g.fillRect(0, 0, currentSize.width, currentSize.height);
1145 g.setColor(Color.white);
1146 g.setFont(new Font("Verdana", Font.BOLD, 14));
1147 g.drawString(MessageManager.getString("label.error_loading_file") + "...", 20, currentSize.height / 2);
1148 StringBuffer sb = new StringBuffer();
1150 for (int e = 0; e < jmb.pdbentry.length; e++)
1152 sb.append(jmb.pdbentry[e].getId());
1153 if (e < jmb.pdbentry.length - 1)
1158 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1161 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1162 * g.getFontMetrics().getHeight());
1166 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1168 g.setColor(Color.black);
1169 g.fillRect(0, 0, currentSize.width, currentSize.height);
1170 g.setColor(Color.white);
1171 g.setFont(new Font("Verdana", Font.BOLD, 14));
1172 g.drawString(MessageManager.getString("label.retrieving_pdb_data"), 20, currentSize.height / 2);
1176 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1181 String viewId = null;
1183 public String getViewId()
1187 viewId = System.currentTimeMillis() + "." + this.hashCode();
1192 public void updateTitleAndMenus()
1194 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1199 setChainMenuItems(jmb.chainNames);
1201 this.setTitle(jmb.getViewerTitle());
1202 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1204 jmolActionMenu.setVisible(true);
1206 if (!jmb.isLoadingFromArchive())
1208 seqColour_actionPerformed(null);
1212 protected void buildJmolActionMenu()
1214 if (_alignwith == null)
1216 _alignwith = new Vector<AlignmentPanel>();
1218 if (_alignwith.size() == 0 && ap != null)
1223 for (Component c : jmolActionMenu.getMenuComponents())
1225 if (c != alignStructs)
1227 jmolActionMenu.remove((JMenuItem) c);
1230 final ItemListener handler;
1237 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1241 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1243 alignStructs_withAllAlignPanels();
1246 private void alignStructs_withAllAlignPanels()
1253 if (_alignwith.size() == 0)
1260 AlignmentI[] als = new Alignment[_alignwith.size()];
1261 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1262 int[] alm = new int[_alignwith.size()];
1265 for (AlignmentPanel ap : _alignwith)
1267 als[a] = ap.av.getAlignment();
1269 alc[a++] = ap.av.getColumnSelection();
1271 jmb.superposeStructures(als, alm, alc);
1272 } catch (Exception e)
1274 StringBuffer sp = new StringBuffer();
1275 for (AlignmentPanel ap : _alignwith)
1277 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1279 Cache.log.info("Couldn't align structures with the " + sp.toString()
1280 + "associated alignment panels.", e);
1286 public void setJalviewColourScheme(ColourSchemeI ucs)
1288 jmb.setJalviewColourScheme(ucs);
1295 * @return first alignment panel displaying given alignment, or the default
1298 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1300 for (AlignmentPanel ap : getAllAlignmentPanels())
1302 if (ap.av.getAlignment() == alignment)
1313 * @return true if this Jmol instance is linked with the given alignPanel
1315 public boolean isLinkedWith(AlignmentPanel ap2)
1317 return _aps.contains(ap2.av.getSequenceSetId());
1320 public boolean isUsedforaligment(AlignmentPanel ap2)
1323 return (_alignwith != null) && _alignwith.contains(ap2);
1326 public boolean isUsedforcolourby(AlignmentPanel ap2)
1328 return (_colourwith != null) && _colourwith.contains(ap2);
1333 * @return TRUE if the view is NOT being coloured by sequence associations.
1335 public boolean isColouredByJmol()
1337 return !jmb.isColourBySequence();