2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 import javax.swing.event.*;
26 import java.awt.event.*;
29 import jalview.jbgui.GStructureViewer;
30 import jalview.api.SequenceStructureBinding;
31 import jalview.bin.Cache;
32 import jalview.datamodel.*;
33 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
34 import jalview.datamodel.PDBEntry;
36 import jalview.schemes.*;
37 import jalview.util.MessageManager;
38 import jalview.util.Platform;
40 public class AppJmol extends GStructureViewer implements Runnable,
41 SequenceStructureBinding, ViewSetProvider
50 RenderPanel renderPanel;
54 Vector atomsPicked = new Vector();
56 private boolean addingStructures = false;
66 * @deprecated defaults to AppJmol(String[] files, ... , viewid);
68 public AppJmol(String file, String id, SequenceI[] seq,
69 AlignmentPanel ap, String loadStatus, Rectangle bounds)
71 this(file, id, seq, ap, loadStatus, bounds, null);
77 public AppJmol(String file, String id, SequenceI[] seq,
78 AlignmentPanel ap, String loadStatus, Rectangle bounds,
82 { file }, new String[]
83 { id }, new SequenceI[][]
84 { seq }, ap, true, true, false, loadStatus, bounds, viewid);
87 ViewSelectionMenu seqColourBy;
96 * - add the alignment panel to the list used for colouring these
99 * - add the alignment panel to the list used for aligning these
101 * @param leaveColouringToJmol
102 * - do not update the colours from any other source. Jmol is
108 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
109 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
110 boolean leaveColouringToJmol, String loadStatus,
111 Rectangle bounds, String viewid)
113 PDBEntry[] pdbentrys = new PDBEntry[files.length];
114 for (int i = 0; i < pdbentrys.length; i++)
116 PDBEntry pdbentry = new PDBEntry();
117 pdbentry.setFile(files[i]);
118 pdbentry.setId(ids[i]);
119 pdbentrys[i] = pdbentry;
121 // / TODO: check if protocol is needed to be set, and if chains are
123 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
124 pdbentrys, seqs, null, null);
126 jmb.setLoadingFromArchive(true);
127 addAlignmentPanel(ap);
130 useAlignmentPanelForSuperposition(ap);
132 if (leaveColouringToJmol || !usetoColour)
134 jmb.setColourBySequence(false);
135 seqColour.setSelected(false);
136 jmolColour.setSelected(true);
140 useAlignmentPanelForColourbyseq(ap);
141 jmb.setColourBySequence(true);
142 seqColour.setSelected(true);
143 jmolColour.setSelected(false);
145 this.setBounds(bounds);
148 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
149 // bounds.width,bounds.height);
151 this.addInternalFrameListener(new InternalFrameAdapter()
153 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
158 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
162 private void initMenus()
164 seqColour.setSelected(jmb.isColourBySequence());
165 jmolColour.setSelected(!jmb.isColourBySequence());
166 if (_colourwith == null)
168 _colourwith = new Vector<AlignmentPanel>();
170 if (_alignwith == null)
172 _alignwith = new Vector<AlignmentPanel>();
175 seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith,
180 public void itemStateChanged(ItemEvent e)
182 if (!seqColour.isSelected())
188 // update the jmol display now.
189 seqColour_actionPerformed(null);
193 viewMenu.add(seqColourBy);
194 final ItemListener handler;
195 JMenu alpanels = new ViewSelectionMenu("Superpose with ..", this,
196 _alignwith, handler = new ItemListener()
200 public void itemStateChanged(ItemEvent e)
202 alignStructs.setEnabled(_alignwith.size() > 0);
203 alignStructs.setToolTipText(MessageManager.formatMessage("label.align_structures_using_linked_alignment_views", new String[] {new Integer(_alignwith.size()).toString()}));
\r
206 handler.itemStateChanged(null);
207 jmolActionMenu.add(alpanels);
208 jmolActionMenu.addMenuListener(new MenuListener()
212 public void menuSelected(MenuEvent e)
214 handler.itemStateChanged(null);
218 public void menuDeselected(MenuEvent e)
220 // TODO Auto-generated method stub
225 public void menuCanceled(MenuEvent e)
227 // TODO Auto-generated method stub
233 IProgressIndicator progressBar = null;
236 * add a single PDB structure to a new or existing Jmol view
243 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
244 final AlignmentPanel ap)
246 progressBar = ap.alignFrame;
247 // ////////////////////////////////
248 // Is the pdb file already loaded?
249 String alreadyMapped = ap.getStructureSelectionManager()
250 .alreadyMappedToFile(pdbentry.getId());
252 if (alreadyMapped != null)
254 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
255 MessageManager.formatMessage("label.pdb_entry_is_already_displayed", new String[]{pdbentry.getId()}),
256 MessageManager.formatMessage("label.map_sequences_to_visible_window", new String[]{pdbentry.getId()}),
257 JOptionPane.YES_NO_OPTION);
259 if (option == JOptionPane.YES_OPTION)
261 // TODO : Fix multiple seq to one chain issue here.
262 ap.getStructureSelectionManager().setMapping(seq, chains,
263 alreadyMapped, AppletFormatAdapter.FILE);
264 if (ap.seqPanel.seqCanvas.fr != null)
266 ap.seqPanel.seqCanvas.fr.featuresAdded();
267 ap.paintAlignment(true);
270 // Now this AppJmol is mapped to new sequences. We must add them to
271 // the exisiting array
272 JInternalFrame[] frames = Desktop.instance.getAllFrames();
274 for (int i = 0; i < frames.length; i++)
276 if (frames[i] instanceof AppJmol)
278 final AppJmol topJmol = ((AppJmol) frames[i]);
279 // JBPNOTE: this looks like a binding routine, rather than a gui
281 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
283 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
285 topJmol.jmb.addSequence(pe, seq);
286 topJmol.addAlignmentPanel(ap);
287 // add it to the set used for colouring
288 topJmol.useAlignmentPanelForColourbyseq(ap);
289 topJmol.buildJmolActionMenu();
290 ap.getStructureSelectionManager()
291 .sequenceColoursChanged(ap);
301 // /////////////////////////////////
302 // Check if there are other Jmol views involving this alignment
303 // and prompt user about adding this molecule to one of them
304 Vector existingViews = getJmolsFor(ap);
305 if (existingViews.size() > 0)
307 Enumeration jm = existingViews.elements();
308 while (jm.hasMoreElements())
310 AppJmol topJmol = (AppJmol) jm.nextElement();
311 // TODO: highlight topJmol in view somehow
312 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
313 MessageManager.formatMessage("label.add_pdbentry_to_view", new String[]{pdbentry.getId(),topJmol.getTitle()}),
314 MessageManager.getString("label.align_to_existing_structure_view"),
315 JOptionPane.YES_NO_OPTION);
316 if (option == JOptionPane.YES_OPTION)
318 topJmol.useAlignmentPanelForSuperposition(ap);
319 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
324 // /////////////////////////////////
325 openNewJmol(ap, new PDBEntry[]
326 { pdbentry }, new SequenceI[][]
330 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
333 progressBar = ap.alignFrame;
334 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
335 pdbentrys, seqs, null, null);
336 addAlignmentPanel(ap);
337 useAlignmentPanelForColourbyseq(ap);
338 if (pdbentrys.length > 1)
340 alignAddedStructures = true;
341 useAlignmentPanelForSuperposition(ap);
343 jmb.setColourBySequence(true);
344 setSize(400, 400); // probably should be a configurable/dynamic default here
348 addingStructures = false;
349 worker = new Thread(this);
352 this.addInternalFrameListener(new InternalFrameAdapter()
354 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
363 * create a new Jmol containing several structures superimposed using the
370 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
372 openNewJmol(ap, pe, seqs);
376 * list of sequenceSet ids associated with the view
378 ArrayList<String> _aps = new ArrayList();
380 public AlignmentPanel[] getAllAlignmentPanels()
382 AlignmentPanel[] t, list = new AlignmentPanel[0];
383 for (String setid : _aps)
385 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
388 t = new AlignmentPanel[list.length + panels.length];
389 System.arraycopy(list, 0, t, 0, list.length);
390 System.arraycopy(panels, 0, t, list.length, panels.length);
399 * list of alignment panels to use for superposition
401 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
404 * list of alignment panels that are used for colouring structures by aligned
407 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
410 * set the primary alignmentPanel reference and add another alignPanel to the
411 * list of ones to use for colouring and aligning
415 public void addAlignmentPanel(AlignmentPanel nap)
421 if (!_aps.contains(nap.av.getSequenceSetId()))
423 _aps.add(nap.av.getSequenceSetId());
428 * remove any references held to the given alignment panel
432 public void removeAlignmentPanel(AlignmentPanel nap)
436 _alignwith.remove(nap);
437 _colourwith.remove(nap);
441 for (AlignmentPanel aps : getAllAlignmentPanels())
450 } catch (Exception ex)
455 buildJmolActionMenu();
459 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
461 addAlignmentPanel(nap);
462 if (!_alignwith.contains(nap))
468 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
470 if (_alignwith.contains(nap))
472 _alignwith.remove(nap);
476 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
477 boolean enableColourBySeq)
479 useAlignmentPanelForColourbyseq(nap);
480 jmb.setColourBySequence(enableColourBySeq);
481 seqColour.setSelected(enableColourBySeq);
482 jmolColour.setSelected(!enableColourBySeq);
485 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
487 addAlignmentPanel(nap);
488 if (!_colourwith.contains(nap))
490 _colourwith.add(nap);
494 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
496 if (_colourwith.contains(nap))
498 _colourwith.remove(nap);
503 * pdb retrieval thread.
505 private Thread worker = null;
508 * add a new structure (with associated sequences and chains) to this viewer,
509 * retrieving it if necessary first.
516 * if true, new structure(s) will be align using associated alignment
518 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
519 final String[] chains, final boolean b,
520 final IProgressIndicator alignFrame)
522 if (pdbentry.getFile() == null)
524 if (worker != null && worker.isAlive())
526 // a retrieval is in progress, wait around and add ourselves to the
528 new Thread(new Runnable()
532 while (worker != null && worker.isAlive() && _started)
536 Thread.sleep(100 + ((int) Math.random() * 100));
538 } catch (Exception e)
543 // and call ourselves again.
544 addStructure(pdbentry, seq, chains, b, alignFrame);
550 // otherwise, start adding the structure.
551 jmb.addSequenceAndChain(new PDBEntry[]
552 { pdbentry }, new SequenceI[][]
553 { seq }, new String[][]
555 addingStructures = true;
557 alignAddedStructures = b;
558 progressBar = alignFrame; // visual indication happens on caller frame.
559 (worker = new Thread(this)).start();
563 private Vector getJmolsFor(AlignmentPanel ap2)
565 Vector otherJmols = new Vector();
566 // Now this AppJmol is mapped to new sequences. We must add them to
567 // the exisiting array
568 JInternalFrame[] frames = Desktop.instance.getAllFrames();
570 for (int i = 0; i < frames.length; i++)
572 if (frames[i] instanceof AppJmol)
574 AppJmol topJmol = ((AppJmol) frames[i]);
575 if (topJmol.isLinkedWith(ap2))
577 otherJmols.addElement(topJmol);
584 void initJmol(String command)
586 jmb.setFinishedInit(false);
587 renderPanel = new RenderPanel();
588 // TODO: consider waiting until the structure/view is fully loaded before
590 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
591 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
592 getBounds().width, getBounds().height);
593 if (scriptWindow == null)
595 BorderLayout bl = new BorderLayout();
598 scriptWindow = new JPanel(bl);
599 scriptWindow.setVisible(false);
602 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
604 jmb.newJmolPopup(true, "Jmol", true);
609 jmb.evalStateCommand(command);
610 jmb.setFinishedInit(true);
613 void setChainMenuItems(Vector chains)
615 chainMenu.removeAll();
620 JMenuItem menuItem = new JMenuItem(MessageManager.getString("label.all"));
\r
621 menuItem.addActionListener(new ActionListener()
623 public void actionPerformed(ActionEvent evt)
625 allChainsSelected = true;
626 for (int i = 0; i < chainMenu.getItemCount(); i++)
628 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
629 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
632 allChainsSelected = false;
636 chainMenu.add(menuItem);
638 for (int c = 0; c < chains.size(); c++)
640 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
641 menuItem.addItemListener(new ItemListener()
643 public void itemStateChanged(ItemEvent evt)
645 if (!allChainsSelected)
650 chainMenu.add(menuItem);
654 boolean allChainsSelected = false;
656 private boolean alignAddedStructures = false;
660 Vector toshow = new Vector();
662 int mlength, p, mnum;
663 for (int i = 0; i < chainMenu.getItemCount(); i++)
665 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
667 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
668 if (item.isSelected())
670 toshow.addElement(item.getText());
674 jmb.centerViewer(toshow);
684 // TODO: check for memory leaks where instance isn't finalised because jmb
685 // holds a reference to the window
690 * state flag for PDB retrieval thread
692 private boolean _started = false;
698 // todo - record which pdbids were successfuly imported.
699 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
702 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
703 // TODO: replace with reference fetching/transfer code (validate PDBentry
705 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
706 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
708 String file = jmb.pdbentry[pi].getFile();
711 // retrieve the pdb and store it locally
712 AlignmentI pdbseq = null;
713 pdbid = jmb.pdbentry[pi].getId();
714 long hdl = pdbid.hashCode() - System.currentTimeMillis();
715 if (progressBar != null)
717 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
721 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
723 } catch (OutOfMemoryError oomerror)
725 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
726 } catch (Exception ex)
728 ex.printStackTrace();
729 errormsgs.append("'" + pdbid + "'");
731 if (progressBar != null)
733 progressBar.setProgressBar("Finished.", hdl);
737 // just transfer the file name from the first sequence's first
739 file = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
740 .elementAt(0)).getFile()).getAbsolutePath();
741 jmb.pdbentry[pi].setFile(file);
743 files.append(" \"" + Platform.escapeString(file) + "\"");
747 errormsgs.append("'" + pdbid + "' ");
752 if (curfiles != null && curfiles.length > 0)
754 addingStructures = true; // already files loaded.
755 for (int c = 0; c < curfiles.length; c++)
757 if (curfiles[c].equals(file))
766 files.append(" \"" + Platform.escapeString(file) + "\"");
770 } catch (OutOfMemoryError oomerror)
772 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
773 } catch (Exception ex)
775 ex.printStackTrace();
776 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
779 if (errormsgs.length() > 0)
782 JOptionPane.showInternalMessageDialog(Desktop.desktop,
783 MessageManager.formatMessage("label.pdb_entries_couldnt_be_retrieved", new String[]{errormsgs.toString()}),
784 MessageManager.getString("label.couldnt_load_file"), JOptionPane.ERROR_MESSAGE);
787 long lastnotify = jmb.getLoadNotifiesHandled();
788 if (files.length() > 0)
790 if (!addingStructures)
795 initJmol("load FILES " + files.toString());
796 } catch (OutOfMemoryError oomerror)
798 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
799 Cache.log.debug("File locations are " + files);
800 } catch (Exception ex)
802 Cache.log.error("Couldn't open Jmol viewer!", ex);
807 StringBuffer cmd = new StringBuffer();
808 cmd.append("loadingJalviewdata=true\nload APPEND ");
809 cmd.append(files.toString());
810 cmd.append("\nloadingJalviewdata=null");
811 final String command = cmd.toString();
813 lastnotify = jmb.getLoadNotifiesHandled();
817 jmb.evalStateCommand(command);
818 } catch (OutOfMemoryError oomerror)
821 "When trying to add structures to the Jmol viewer!",
823 Cache.log.debug("File locations are " + files);
824 } catch (Exception ex)
826 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
830 // need to wait around until script has finished
831 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
832 : (jmb.isFinishedInit() && jmb.getPdbFile()!=null && jmb.getPdbFile().length != jmb.pdbentry.length))
836 Cache.log.debug("Waiting around for jmb notify.");
838 } catch (Exception e)
842 // refresh the sequence colours for the new structure(s)
843 for (AlignmentPanel ap : _colourwith)
845 jmb.updateColours(ap);
847 // do superposition if asked to
848 if (alignAddedStructures)
850 javax.swing.SwingUtilities.invokeLater(new Runnable()
854 alignStructs_withAllAlignPanels();
855 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
858 alignAddedStructures = false;
860 addingStructures = false;
867 public void pdbFile_actionPerformed(ActionEvent actionEvent)
869 JalviewFileChooser chooser = new JalviewFileChooser(
870 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
872 chooser.setFileView(new JalviewFileView());
873 chooser.setDialogTitle("Save PDB File");
874 chooser.setToolTipText(MessageManager.getString("action.save"));
\r
876 int value = chooser.showSaveDialog(this);
878 if (value == JalviewFileChooser.APPROVE_OPTION)
882 // TODO: cope with multiple PDB files in view
883 BufferedReader in = new BufferedReader(new FileReader(
884 jmb.getPdbFile()[0]));
885 File outFile = chooser.getSelectedFile();
887 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
889 while ((data = in.readLine()) != null)
891 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
897 } catch (Exception ex)
899 ex.printStackTrace();
904 public void viewMapping_actionPerformed(ActionEvent actionEvent)
906 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
909 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
911 cap.appendText(jmb.printMapping(jmb.pdbentry[pdbe].getFile()));
912 cap.appendText("\n");
914 } catch (OutOfMemoryError e)
917 "composing sequence-structure alignments for display in text box.",
922 jalview.gui.Desktop.addInternalFrame(cap, MessageManager.getString("label.pdb_sequence_mapping"),
\r
932 public void eps_actionPerformed(ActionEvent e)
934 makePDBImage(jalview.util.ImageMaker.EPS);
943 public void png_actionPerformed(ActionEvent e)
945 makePDBImage(jalview.util.ImageMaker.PNG);
948 void makePDBImage(int type)
950 int width = getWidth();
951 int height = getHeight();
953 jalview.util.ImageMaker im;
955 if (type == jalview.util.ImageMaker.PNG)
957 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
958 "Make PNG image from view", width, height, null, null);
962 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
963 "Make EPS file from view", width, height, null,
967 if (im.getGraphics() != null)
969 Rectangle rect = new Rectangle(width, height);
970 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
975 public void jmolColour_actionPerformed(ActionEvent actionEvent)
977 if (jmolColour.isSelected())
979 // disable automatic sequence colouring.
980 jmb.setColourBySequence(false);
984 public void seqColour_actionPerformed(ActionEvent actionEvent)
986 jmb.setColourBySequence(seqColour.isSelected());
987 if (_colourwith == null)
989 _colourwith = new Vector<AlignmentPanel>();
991 if (jmb.isColourBySequence())
993 if (!jmb.isLoadingFromArchive())
995 if (_colourwith.size() == 0 && ap != null)
997 // Make the currently displayed alignment panel the associated view
998 _colourwith.add(ap.alignFrame.alignPanel);
1001 // Set the colour using the current view for the associated alignframe
1002 for (AlignmentPanel ap : _colourwith)
1004 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
1009 public void chainColour_actionPerformed(ActionEvent actionEvent)
1011 chainColour.setSelected(true);
1012 jmb.colourByChain();
1015 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1017 chargeColour.setSelected(true);
1018 jmb.colourByCharge();
1021 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1023 zappoColour.setSelected(true);
1024 jmb.setJalviewColourScheme(new ZappoColourScheme());
1027 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1029 taylorColour.setSelected(true);
1030 jmb.setJalviewColourScheme(new TaylorColourScheme());
1033 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1035 hydroColour.setSelected(true);
1036 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1039 public void helixColour_actionPerformed(ActionEvent actionEvent)
1041 helixColour.setSelected(true);
1042 jmb.setJalviewColourScheme(new HelixColourScheme());
1045 public void strandColour_actionPerformed(ActionEvent actionEvent)
1047 strandColour.setSelected(true);
1048 jmb.setJalviewColourScheme(new StrandColourScheme());
1051 public void turnColour_actionPerformed(ActionEvent actionEvent)
1053 turnColour.setSelected(true);
1054 jmb.setJalviewColourScheme(new TurnColourScheme());
1057 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1059 buriedColour.setSelected(true);
1060 jmb.setJalviewColourScheme(new BuriedColourScheme());
1063 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1065 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1068 public void userColour_actionPerformed(ActionEvent actionEvent)
1070 userColour.setSelected(true);
1071 new UserDefinedColours(this, null);
1074 public void backGround_actionPerformed(ActionEvent actionEvent)
1076 java.awt.Color col = JColorChooser.showDialog(this,
1077 "Select Background Colour", null);
1080 jmb.setBackgroundColour(col);
1084 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1088 jalview.util.BrowserLauncher
1089 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1090 } catch (Exception ex)
1095 public void showConsole(boolean showConsole)
1100 if (splitPane == null)
1102 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1103 splitPane.setTopComponent(renderPanel);
1104 splitPane.setBottomComponent(scriptWindow);
1105 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1106 splitPane.setDividerLocation(getHeight() - 200);
1107 scriptWindow.setVisible(true);
1108 scriptWindow.validate();
1109 splitPane.validate();
1115 if (splitPane != null)
1117 splitPane.setVisible(false);
1122 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1128 class RenderPanel extends JPanel
1130 final Dimension currentSize = new Dimension();
1132 final Rectangle rectClip = new Rectangle();
1134 public void paintComponent(Graphics g)
1136 getSize(currentSize);
1137 g.getClipBounds(rectClip);
1139 if (jmb.fileLoadingError != null)
1141 g.setColor(Color.black);
1142 g.fillRect(0, 0, currentSize.width, currentSize.height);
1143 g.setColor(Color.white);
1144 g.setFont(new Font("Verdana", Font.BOLD, 14));
1145 g.drawString(MessageManager.getString("label.error_loading_file") + "...", 20, currentSize.height / 2);
1146 StringBuffer sb = new StringBuffer();
1148 for (int e = 0; e < jmb.pdbentry.length; e++)
1150 sb.append(jmb.pdbentry[e].getId());
1151 if (e < jmb.pdbentry.length - 1)
1156 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1159 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1160 * g.getFontMetrics().getHeight());
1164 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1166 g.setColor(Color.black);
1167 g.fillRect(0, 0, currentSize.width, currentSize.height);
1168 g.setColor(Color.white);
1169 g.setFont(new Font("Verdana", Font.BOLD, 14));
1170 g.drawString(MessageManager.getString("label.retrieving_pdb_data"), 20, currentSize.height / 2);
1174 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1179 String viewId = null;
1181 public String getViewId()
1185 viewId = System.currentTimeMillis() + "." + this.hashCode();
1190 public void updateTitleAndMenus()
1192 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1197 setChainMenuItems(jmb.chainNames);
1199 this.setTitle(jmb.getViewerTitle());
1200 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1202 jmolActionMenu.setVisible(true);
1204 if (!jmb.isLoadingFromArchive())
1206 seqColour_actionPerformed(null);
1210 protected void buildJmolActionMenu()
1212 if (_alignwith == null)
1214 _alignwith = new Vector<AlignmentPanel>();
1216 if (_alignwith.size() == 0 && ap != null)
1221 for (Component c : jmolActionMenu.getMenuComponents())
1223 if (c != alignStructs)
1225 jmolActionMenu.remove((JMenuItem) c);
1228 final ItemListener handler;
1235 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1239 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1241 alignStructs_withAllAlignPanels();
1244 private void alignStructs_withAllAlignPanels()
1251 if (_alignwith.size() == 0)
1258 AlignmentI[] als = new Alignment[_alignwith.size()];
1259 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1260 int[] alm = new int[_alignwith.size()];
1263 for (AlignmentPanel ap : _alignwith)
1265 als[a] = ap.av.getAlignment();
1267 alc[a++] = ap.av.getColumnSelection();
1269 jmb.superposeStructures(als, alm, alc);
1270 } catch (Exception e)
1272 StringBuffer sp = new StringBuffer();
1273 for (AlignmentPanel ap : _alignwith)
1275 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1277 Cache.log.info("Couldn't align structures with the " + sp.toString()
1278 + "associated alignment panels.", e);
1284 public void setJalviewColourScheme(ColourSchemeI ucs)
1286 jmb.setJalviewColourScheme(ucs);
1293 * @return first alignment panel displaying given alignment, or the default
1296 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1298 for (AlignmentPanel ap : getAllAlignmentPanels())
1300 if (ap.av.getAlignment() == alignment)
1311 * @return true if this Jmol instance is linked with the given alignPanel
1313 public boolean isLinkedWith(AlignmentPanel ap2)
1315 return _aps.contains(ap2.av.getSequenceSetId());
1318 public boolean isUsedforaligment(AlignmentPanel ap2)
1321 return (_alignwith != null) && _alignwith.contains(ap2);
1324 public boolean isUsedforcolourby(AlignmentPanel ap2)
1326 return (_colourwith != null) && _colourwith.contains(ap2);
1331 * @return TRUE if the view is NOT being coloured by sequence associations.
1333 public boolean isColouredByJmol()
1335 return !jmb.isColourBySequence();