2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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.bin.Cache;
24 import jalview.datamodel.Alignment;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.ColumnSelection;
27 import jalview.datamodel.PDBEntry;
28 import jalview.datamodel.SequenceI;
29 import jalview.gui.StructureViewer.ViewerType;
30 import jalview.io.AppletFormatAdapter;
31 import jalview.io.JalviewFileChooser;
32 import jalview.io.JalviewFileView;
33 import jalview.schemes.BuriedColourScheme;
34 import jalview.schemes.ColourSchemeI;
35 import jalview.schemes.HelixColourScheme;
36 import jalview.schemes.HydrophobicColourScheme;
37 import jalview.schemes.PurinePyrimidineColourScheme;
38 import jalview.schemes.StrandColourScheme;
39 import jalview.schemes.TaylorColourScheme;
40 import jalview.schemes.TurnColourScheme;
41 import jalview.schemes.ZappoColourScheme;
42 import jalview.structures.models.AAStructureBindingModel;
43 import jalview.util.MessageManager;
44 import jalview.util.Platform;
46 import java.awt.BorderLayout;
47 import java.awt.Color;
48 import java.awt.Dimension;
50 import java.awt.Graphics;
51 import java.awt.Rectangle;
52 import java.awt.event.ActionEvent;
53 import java.awt.event.ActionListener;
54 import java.awt.event.ItemEvent;
55 import java.awt.event.ItemListener;
56 import java.io.BufferedReader;
58 import java.io.FileOutputStream;
59 import java.io.FileReader;
60 import java.io.PrintWriter;
61 import java.util.Enumeration;
62 import java.util.Vector;
64 import javax.swing.JCheckBoxMenuItem;
65 import javax.swing.JColorChooser;
66 import javax.swing.JInternalFrame;
67 import javax.swing.JMenu;
68 import javax.swing.JMenuItem;
69 import javax.swing.JOptionPane;
70 import javax.swing.JPanel;
71 import javax.swing.JSplitPane;
72 import javax.swing.event.InternalFrameAdapter;
73 import javax.swing.event.InternalFrameEvent;
74 import javax.swing.event.MenuEvent;
75 import javax.swing.event.MenuListener;
77 public class AppJmol extends StructureViewerBase
85 RenderPanel renderPanel;
87 private boolean addingStructures = false;
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(files[i], ids[i]);
119 PDBEntry pdbentry = new PDBEntry(ids[i], null, PDBEntry.Type.PDB,
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 viewerColour.setSelected(true);
140 else if (usetoColour)
142 useAlignmentPanelForColourbyseq(ap);
143 jmb.setColourBySequence(true);
144 seqColour.setSelected(true);
145 viewerColour.setSelected(false);
147 this.setBounds(bounds);
150 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
151 // bounds.width,bounds.height);
153 this.addInternalFrameListener(new InternalFrameAdapter()
156 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
161 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
165 private void initMenus()
167 seqColour.setSelected(jmb.isColourBySequence());
168 viewerColour.setSelected(!jmb.isColourBySequence());
169 if (_colourwith == null)
171 _colourwith = new Vector<AlignmentPanel>();
173 if (_alignwith == null)
175 _alignwith = new Vector<AlignmentPanel>();
178 seqColourBy = new ViewSelectionMenu(MessageManager.getString("label.colour_by"), this, _colourwith,
183 public void itemStateChanged(ItemEvent e)
185 if (!seqColour.isSelected())
191 // update the jmol display now.
192 seqColour_actionPerformed(null);
196 viewMenu.add(seqColourBy);
197 final ItemListener handler;
198 JMenu alpanels = new ViewSelectionMenu(MessageManager.getString("label.superpose_with"), this,
199 _alignwith, handler = new ItemListener()
203 public void itemStateChanged(ItemEvent e)
205 alignStructs.setEnabled(_alignwith.size() > 0);
206 alignStructs.setToolTipText(MessageManager
208 "label.align_structures_using_linked_alignment_views",
210 { new Integer(_alignwith.size()).toString() }));
213 handler.itemStateChanged(null);
214 viewerActionMenu.add(alpanels);
215 viewerActionMenu.addMenuListener(new MenuListener()
219 public void menuSelected(MenuEvent e)
221 handler.itemStateChanged(null);
225 public void menuDeselected(MenuEvent e)
227 // TODO Auto-generated method stub
232 public void menuCanceled(MenuEvent e)
234 // TODO Auto-generated method stub
240 IProgressIndicator progressBar = null;
243 * add a single PDB structure to a new or existing Jmol view
250 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
251 final AlignmentPanel ap)
253 progressBar = ap.alignFrame;
254 // ////////////////////////////////
255 // Is the pdb file already loaded?
256 String alreadyMapped = ap.getStructureSelectionManager()
257 .alreadyMappedToFile(pdbentry.getId());
259 if (alreadyMapped != null)
261 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
262 MessageManager.formatMessage(
263 "label.pdb_entry_is_already_displayed", new String[]
264 { pdbentry.getId() }), MessageManager.formatMessage(
265 "label.map_sequences_to_visible_window", new String[]
266 { pdbentry.getId() }),
267 JOptionPane.YES_NO_CANCEL_OPTION);
269 if (option == JOptionPane.CANCEL_OPTION)
273 if (option == JOptionPane.YES_OPTION)
275 // TODO : Fix multiple seq to one chain issue here.
276 ap.getStructureSelectionManager().setMapping(seq, chains,
277 alreadyMapped, AppletFormatAdapter.FILE);
278 if (ap.getSeqPanel().seqCanvas.fr != null)
280 ap.getSeqPanel().seqCanvas.fr.featuresAdded();
281 ap.paintAlignment(true);
284 // Now this AppJmol is mapped to new sequences. We must add them to
285 // the exisiting array
286 JInternalFrame[] frames = Desktop.instance.getAllFrames();
288 for (int i = 0; i < frames.length; i++)
290 if (frames[i] instanceof AppJmol)
292 final AppJmol topJmol = ((AppJmol) frames[i]);
293 // JBPNOTE: this looks like a binding routine, rather than a gui
295 for (int pe = 0; pe < topJmol.jmb.getPdbCount(); pe++)
297 if (topJmol.jmb.getPdbEntry(pe).getFile()
298 .equals(alreadyMapped))
300 topJmol.jmb.addSequence(pe, seq);
301 topJmol.addAlignmentPanel(ap);
302 // add it to the set used for colouring
303 topJmol.useAlignmentPanelForColourbyseq(ap);
304 topJmol.buildActionMenu();
305 ap.getStructureSelectionManager()
306 .sequenceColoursChanged(ap);
316 // /////////////////////////////////
317 // Check if there are other Jmol views involving this alignment
318 // and prompt user about adding this molecule to one of them
319 Vector existingViews = getJmolsFor(ap);
320 if (existingViews.size() > 0)
322 Enumeration jm = existingViews.elements();
323 while (jm.hasMoreElements())
325 AppJmol topJmol = (AppJmol) jm.nextElement();
326 // TODO: highlight topJmol in view somehow
327 int option = JOptionPane
328 .showInternalConfirmDialog(
330 MessageManager.formatMessage(
331 "label.add_pdbentry_to_view", new String[]
332 { pdbentry.getId(), topJmol.getTitle() }),
334 .getString("label.align_to_existing_structure_view"),
335 JOptionPane.YES_NO_CANCEL_OPTION);
336 if (option == JOptionPane.CANCEL_OPTION)
340 if (option == JOptionPane.YES_OPTION)
342 topJmol.useAlignmentPanelForSuperposition(ap);
343 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
348 // /////////////////////////////////
349 openNewJmol(ap, new PDBEntry[]
350 { pdbentry }, new SequenceI[][]
354 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
357 progressBar = ap.alignFrame;
358 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
359 pdbentrys, seqs, null, null);
360 addAlignmentPanel(ap);
361 useAlignmentPanelForColourbyseq(ap);
362 if (pdbentrys.length > 1)
364 alignAddedStructures = true;
365 useAlignmentPanelForSuperposition(ap);
367 jmb.setColourBySequence(true);
368 setSize(400, 400); // probably should be a configurable/dynamic default here
372 addingStructures = false;
373 worker = new Thread(this);
376 this.addInternalFrameListener(new InternalFrameAdapter()
379 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
388 * create a new Jmol containing several structures superimposed using the
395 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
397 openNewJmol(ap, pe, seqs);
401 * pdb retrieval thread.
403 private Thread worker = null;
406 * add a new structure (with associated sequences and chains) to this viewer,
407 * retrieving it if necessary first.
414 * if true, new structure(s) will be align using associated alignment
416 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
417 final String[] chains, final boolean b,
418 final IProgressIndicator alignFrame)
420 if (pdbentry.getFile() == null)
422 if (worker != null && worker.isAlive())
424 // a retrieval is in progress, wait around and add ourselves to the
426 new Thread(new Runnable()
430 while (worker != null && worker.isAlive() && _started)
434 Thread.sleep(100 + ((int) Math.random() * 100));
436 } catch (Exception e)
441 // and call ourselves again.
442 addStructure(pdbentry, seq, chains, b, alignFrame);
448 // otherwise, start adding the structure.
449 jmb.addSequenceAndChain(new PDBEntry[]
450 { pdbentry }, new SequenceI[][]
451 { seq }, new String[][]
453 addingStructures = true;
455 alignAddedStructures = b;
456 progressBar = alignFrame; // visual indication happens on caller frame.
457 (worker = new Thread(this)).start();
461 private Vector getJmolsFor(AlignmentPanel apanel)
463 Vector result = new Vector();
464 JInternalFrame[] frames = Desktop.instance.getAllFrames();
466 for (JInternalFrame frame : frames)
468 if (frame instanceof AppJmol)
470 if (((StructureViewerBase) frame).isLinkedWith(apanel))
472 result.addElement(frame);
479 void initJmol(String command)
481 jmb.setFinishedInit(false);
482 renderPanel = new RenderPanel();
483 // TODO: consider waiting until the structure/view is fully loaded before
485 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
486 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
487 getBounds().width, getBounds().height);
488 if (scriptWindow == null)
490 BorderLayout bl = new BorderLayout();
493 scriptWindow = new JPanel(bl);
494 scriptWindow.setVisible(false);
497 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
499 jmb.newJmolPopup("Jmol");
504 jmb.evalStateCommand(command);
505 jmb.setFinishedInit(true);
508 void setChainMenuItems(Vector chains)
510 chainMenu.removeAll();
515 JMenuItem menuItem = new JMenuItem(
516 MessageManager.getString("label.all"));
517 menuItem.addActionListener(new ActionListener()
519 public void actionPerformed(ActionEvent evt)
521 allChainsSelected = true;
522 for (int i = 0; i < chainMenu.getItemCount(); i++)
524 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
526 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
530 allChainsSelected = false;
534 chainMenu.add(menuItem);
536 for (int c = 0; c < chains.size(); c++)
538 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
539 menuItem.addItemListener(new ItemListener()
541 public void itemStateChanged(ItemEvent evt)
543 if (!allChainsSelected)
550 chainMenu.add(menuItem);
554 boolean allChainsSelected = false;
556 private boolean alignAddedStructures = false;
560 Vector toshow = new Vector();
562 int mlength, p, mnum;
563 for (int i = 0; i < chainMenu.getItemCount(); i++)
565 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
567 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
568 if (item.isSelected())
570 toshow.addElement(item.getText());
574 jmb.centerViewer(toshow);
577 public void closeViewer(boolean closeExternalViewer)
579 // JMol does not use an external viewer
581 setAlignmentPanel(null);
585 // TODO: check for memory leaks where instance isn't finalised because jmb
586 // holds a reference to the window
591 * state flag for PDB retrieval thread
593 private boolean _started = false;
599 // todo - record which pdbids were successfuly imported.
600 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
603 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
604 // TODO: replace with reference fetching/transfer code (validate PDBentry
606 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
607 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
609 String file = jmb.getPdbEntry(pi).getFile();
612 // retrieve the pdb and store it locally
613 AlignmentI pdbseq = null;
614 pdbid = jmb.getPdbEntry(pi).getId();
615 long hdl = pdbid.hashCode() - System.currentTimeMillis();
616 if (progressBar != null)
618 progressBar.setProgressBar(MessageManager.formatMessage("status.fetching_pdb", new String[]{pdbid}), hdl);
622 pdbseq = pdbclient.getSequenceRecords(pdbid);
623 } catch (OutOfMemoryError oomerror)
625 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
626 } catch (Exception ex)
628 ex.printStackTrace();
629 errormsgs.append("'" + pdbid + "'");
631 if (progressBar != null)
633 progressBar.setProgressBar(MessageManager.getString("label.state_completed"), hdl);
637 // just transfer the file name from the first sequence's first
639 file = new File(pdbseq.getSequenceAt(0).getPDBId()
640 .elementAt(0).getFile()).getAbsolutePath();
641 jmb.getPdbEntry(pi).setFile(file);
643 files.append(" \"" + Platform.escapeString(file) + "\"");
647 errormsgs.append("'" + pdbid + "' ");
652 if (curfiles != null && curfiles.length > 0)
654 addingStructures = true; // already files loaded.
655 for (int c = 0; c < curfiles.length; c++)
657 if (curfiles[c].equals(file))
666 files.append(" \"" + Platform.escapeString(file) + "\"");
670 } catch (OutOfMemoryError oomerror)
672 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
673 } catch (Exception ex)
675 ex.printStackTrace();
676 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
679 if (errormsgs.length() > 0)
682 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
683 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
685 { errormsgs.toString() }), MessageManager
686 .getString("label.couldnt_load_file"),
687 JOptionPane.ERROR_MESSAGE);
690 long lastnotify = jmb.getLoadNotifiesHandled();
691 if (files.length() > 0)
693 if (!addingStructures)
698 initJmol("load FILES " + files.toString());
699 } catch (OutOfMemoryError oomerror)
701 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
702 Cache.log.debug("File locations are " + files);
703 } catch (Exception ex)
705 Cache.log.error("Couldn't open Jmol viewer!", ex);
710 StringBuffer cmd = new StringBuffer();
711 cmd.append("loadingJalviewdata=true\nload APPEND ");
712 cmd.append(files.toString());
713 cmd.append("\nloadingJalviewdata=null");
714 final String command = cmd.toString();
716 lastnotify = jmb.getLoadNotifiesHandled();
720 jmb.evalStateCommand(command);
721 } catch (OutOfMemoryError oomerror)
724 "When trying to add structures to the Jmol viewer!",
726 Cache.log.debug("File locations are " + files);
727 } catch (Exception ex)
729 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
733 // need to wait around until script has finished
734 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
735 : (jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb
736 .getPdbFile().length != jmb.getPdbCount()))
740 Cache.log.debug("Waiting around for jmb notify.");
742 } catch (Exception e)
746 // refresh the sequence colours for the new structure(s)
747 for (AlignmentPanel ap : _colourwith)
749 jmb.updateColours(ap);
751 // do superposition if asked to
752 if (alignAddedStructures)
754 javax.swing.SwingUtilities.invokeLater(new Runnable()
758 alignStructs_withAllAlignPanels();
759 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
762 alignAddedStructures = false;
764 addingStructures = false;
772 public void pdbFile_actionPerformed(ActionEvent actionEvent)
774 JalviewFileChooser chooser = new JalviewFileChooser(
775 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
777 chooser.setFileView(new JalviewFileView());
778 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
779 chooser.setToolTipText(MessageManager.getString("action.save"));
781 int value = chooser.showSaveDialog(this);
783 if (value == JalviewFileChooser.APPROVE_OPTION)
787 // TODO: cope with multiple PDB files in view
788 BufferedReader in = new BufferedReader(new FileReader(
789 jmb.getPdbFile()[0]));
790 File outFile = chooser.getSelectedFile();
792 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
794 while ((data = in.readLine()) != null)
796 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
802 } catch (Exception ex)
804 ex.printStackTrace();
810 public void viewMapping_actionPerformed(ActionEvent actionEvent)
812 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
815 cap.appendText(jmb.printMappings());
816 } catch (OutOfMemoryError e)
819 "composing sequence-structure alignments for display in text box.",
824 jalview.gui.Desktop.addInternalFrame(cap,
825 MessageManager.getString("label.pdb_sequence_mapping"), 550,
830 public void eps_actionPerformed(ActionEvent e)
832 makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
836 public void png_actionPerformed(ActionEvent e)
838 makePDBImage(jalview.util.ImageMaker.TYPE.PNG);
841 void makePDBImage(jalview.util.ImageMaker.TYPE type)
843 int width = getWidth();
844 int height = getHeight();
846 jalview.util.ImageMaker im;
848 if (type == jalview.util.ImageMaker.TYPE.PNG)
850 im = new jalview.util.ImageMaker(this,
851 jalview.util.ImageMaker.TYPE.PNG,
852 "Make PNG image from view", width, height, null, null);
854 else if (type == jalview.util.ImageMaker.TYPE.EPS)
856 im = new jalview.util.ImageMaker(this,
857 jalview.util.ImageMaker.TYPE.EPS,
858 "Make EPS file from view", width, height, null,
864 im = new jalview.util.ImageMaker(this,
865 jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
866 width, height, null, this.getTitle());
869 if (im.getGraphics() != null)
871 jmb.viewer.renderScreenImage(im.getGraphics(), width, height);
877 public void viewerColour_actionPerformed(ActionEvent actionEvent)
879 if (viewerColour.isSelected())
881 // disable automatic sequence colouring.
882 jmb.setColourBySequence(false);
887 public void seqColour_actionPerformed(ActionEvent actionEvent)
889 jmb.setColourBySequence(seqColour.isSelected());
890 if (_colourwith == null)
892 _colourwith = new Vector<AlignmentPanel>();
894 if (jmb.isColourBySequence())
896 if (!jmb.isLoadingFromArchive())
898 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
900 // Make the currently displayed alignment panel the associated view
901 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
904 // Set the colour using the current view for the associated alignframe
905 for (AlignmentPanel ap : _colourwith)
907 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
913 public void chainColour_actionPerformed(ActionEvent actionEvent)
915 chainColour.setSelected(true);
920 public void chargeColour_actionPerformed(ActionEvent actionEvent)
922 chargeColour.setSelected(true);
923 jmb.colourByCharge();
927 public void zappoColour_actionPerformed(ActionEvent actionEvent)
929 zappoColour.setSelected(true);
930 jmb.setJalviewColourScheme(new ZappoColourScheme());
934 public void taylorColour_actionPerformed(ActionEvent actionEvent)
936 taylorColour.setSelected(true);
937 jmb.setJalviewColourScheme(new TaylorColourScheme());
941 public void hydroColour_actionPerformed(ActionEvent actionEvent)
943 hydroColour.setSelected(true);
944 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
948 public void helixColour_actionPerformed(ActionEvent actionEvent)
950 helixColour.setSelected(true);
951 jmb.setJalviewColourScheme(new HelixColourScheme());
955 public void strandColour_actionPerformed(ActionEvent actionEvent)
957 strandColour.setSelected(true);
958 jmb.setJalviewColourScheme(new StrandColourScheme());
962 public void turnColour_actionPerformed(ActionEvent actionEvent)
964 turnColour.setSelected(true);
965 jmb.setJalviewColourScheme(new TurnColourScheme());
969 public void buriedColour_actionPerformed(ActionEvent actionEvent)
971 buriedColour.setSelected(true);
972 jmb.setJalviewColourScheme(new BuriedColourScheme());
976 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
978 setJalviewColourScheme(new PurinePyrimidineColourScheme());
982 public void userColour_actionPerformed(ActionEvent actionEvent)
984 userColour.setSelected(true);
985 new UserDefinedColours(this, null);
989 public void backGround_actionPerformed(ActionEvent actionEvent)
991 java.awt.Color col = JColorChooser.showDialog(this,
992 MessageManager.getString("label.select_backgroud_colour"), null);
995 jmb.setBackgroundColour(col);
1000 public void showHelp_actionPerformed(ActionEvent actionEvent)
1004 jalview.util.BrowserLauncher
1005 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1006 } catch (Exception ex)
1011 public void showConsole(boolean showConsole)
1016 if (splitPane == null)
1018 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1019 splitPane.setTopComponent(renderPanel);
1020 splitPane.setBottomComponent(scriptWindow);
1021 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1022 splitPane.setDividerLocation(getHeight() - 200);
1023 scriptWindow.setVisible(true);
1024 scriptWindow.validate();
1025 splitPane.validate();
1031 if (splitPane != null)
1033 splitPane.setVisible(false);
1038 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1044 class RenderPanel extends JPanel
1046 final Dimension currentSize = new Dimension();
1049 public void paintComponent(Graphics g)
1051 getSize(currentSize);
1053 if (jmb != null && jmb.fileLoadingError != null)
1055 g.setColor(Color.black);
1056 g.fillRect(0, 0, currentSize.width, currentSize.height);
1057 g.setColor(Color.white);
1058 g.setFont(new Font("Verdana", Font.BOLD, 14));
1059 g.drawString(MessageManager.getString("label.error_loading_file")
1060 + "...", 20, currentSize.height / 2);
1061 StringBuffer sb = new StringBuffer();
1063 for (int e = 0; e < jmb.getPdbCount(); e++)
1065 sb.append(jmb.getPdbEntry(e).getId());
1066 if (e < jmb.getPdbCount() - 1)
1071 if (e == jmb.getPdbCount() - 1 || sb.length() > 20)
1074 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1075 * g.getFontMetrics().getHeight());
1079 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1081 g.setColor(Color.black);
1082 g.fillRect(0, 0, currentSize.width, currentSize.height);
1083 g.setColor(Color.white);
1084 g.setFont(new Font("Verdana", Font.BOLD, 14));
1085 g.drawString(MessageManager.getString("label.retrieving_pdb_data"),
1086 20, currentSize.height / 2);
1090 jmb.viewer.renderScreenImage(g, currentSize.width,
1091 currentSize.height);
1096 public void updateTitleAndMenus()
1098 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1103 setChainMenuItems(jmb.chainNames);
1105 this.setTitle(jmb.getViewerTitle());
1106 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1108 viewerActionMenu.setVisible(true);
1110 if (!jmb.isLoadingFromArchive())
1112 seqColour_actionPerformed(null);
1120 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1124 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1126 alignStructs_withAllAlignPanels();
1129 private void alignStructs_withAllAlignPanels()
1131 if (getAlignmentPanel() == null)
1136 if (_alignwith.size() == 0)
1138 _alignwith.add(getAlignmentPanel());
1143 AlignmentI[] als = new Alignment[_alignwith.size()];
1144 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1145 int[] alm = new int[_alignwith.size()];
1148 for (AlignmentPanel ap : _alignwith)
1150 als[a] = ap.av.getAlignment();
1152 alc[a++] = ap.av.getColumnSelection();
1154 jmb.superposeStructures(als, alm, alc);
1155 } catch (Exception e)
1157 StringBuffer sp = new StringBuffer();
1158 for (AlignmentPanel ap : _alignwith)
1160 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1162 Cache.log.info("Couldn't align structures with the " + sp.toString()
1163 + "associated alignment panels.", e);
1169 public void setJalviewColourScheme(ColourSchemeI ucs)
1171 jmb.setJalviewColourScheme(ucs);
1178 * @return first alignment panel displaying given alignment, or the default
1181 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1183 for (AlignmentPanel ap : getAllAlignmentPanels())
1185 if (ap.av.getAlignment() == alignment)
1190 return getAlignmentPanel();
1194 public AAStructureBindingModel getBinding()
1200 public String getStateInfo()
1202 return jmb == null ? null : jmb.viewer.getStateInfo();
1206 public ViewerType getViewerType()
1208 return ViewerType.JMOL;