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 java.awt.BorderLayout;
24 import java.awt.Color;
25 import java.awt.Dimension;
27 import java.awt.Graphics;
28 import java.awt.Rectangle;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.awt.event.ItemEvent;
32 import java.awt.event.ItemListener;
33 import java.io.BufferedReader;
35 import java.io.FileOutputStream;
36 import java.io.FileReader;
37 import java.io.PrintWriter;
38 import java.util.Enumeration;
39 import java.util.Vector;
41 import javax.swing.JCheckBoxMenuItem;
42 import javax.swing.JColorChooser;
43 import javax.swing.JInternalFrame;
44 import javax.swing.JMenu;
45 import javax.swing.JMenuItem;
46 import javax.swing.JOptionPane;
47 import javax.swing.JPanel;
48 import javax.swing.JSplitPane;
49 import javax.swing.event.InternalFrameAdapter;
50 import javax.swing.event.InternalFrameEvent;
51 import javax.swing.event.MenuEvent;
52 import javax.swing.event.MenuListener;
54 import jalview.bin.Cache;
55 import jalview.datamodel.Alignment;
56 import jalview.datamodel.AlignmentI;
57 import jalview.datamodel.ColumnSelection;
58 import jalview.datamodel.PDBEntry;
59 import jalview.datamodel.SequenceI;
60 import jalview.gui.StructureViewer.ViewerType;
61 import jalview.io.AppletFormatAdapter;
62 import jalview.io.JalviewFileChooser;
63 import jalview.io.JalviewFileView;
64 import jalview.schemes.BuriedColourScheme;
65 import jalview.schemes.ColourSchemeI;
66 import jalview.schemes.HelixColourScheme;
67 import jalview.schemes.HydrophobicColourScheme;
68 import jalview.schemes.PurinePyrimidineColourScheme;
69 import jalview.schemes.StrandColourScheme;
70 import jalview.schemes.TaylorColourScheme;
71 import jalview.schemes.TurnColourScheme;
72 import jalview.schemes.ZappoColourScheme;
73 import jalview.structures.models.AAStructureBindingModel;
74 import jalview.util.MessageManager;
75 import jalview.util.Platform;
77 public class AppJmol extends StructureViewerBase
85 RenderPanel renderPanel;
87 Vector atomsPicked = new Vector();
89 private boolean addingStructures = false;
99 * @deprecated defaults to AppJmol(String[] files, ... , viewid);
102 public AppJmol(String file, String id, SequenceI[] seq,
103 AlignmentPanel ap, String loadStatus, Rectangle bounds)
105 this(file, id, seq, ap, loadStatus, bounds, null);
112 public AppJmol(String file, String id, SequenceI[] seq,
113 AlignmentPanel ap, String loadStatus, Rectangle bounds,
117 { file }, new String[]
118 { id }, new SequenceI[][]
119 { seq }, ap, true, true, false, loadStatus, bounds, viewid);
122 ViewSelectionMenu seqColourBy;
131 * - add the alignment panel to the list used for colouring these
134 * - add the alignment panel to the list used for aligning these
136 * @param leaveColouringToJmol
137 * - do not update the colours from any other source. Jmol is
143 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
144 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
145 boolean leaveColouringToJmol, String loadStatus,
146 Rectangle bounds, String viewid)
148 PDBEntry[] pdbentrys = new PDBEntry[files.length];
149 for (int i = 0; i < pdbentrys.length; i++)
151 // PDBEntry pdbentry = new PDBEntry(files[i], ids[i]);
152 PDBEntry pdbentry = new PDBEntry(ids[i], null, PDBEntry.Type.PDB,
154 pdbentrys[i] = pdbentry;
156 // / TODO: check if protocol is needed to be set, and if chains are
158 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
159 pdbentrys, seqs, null, null);
161 jmb.setLoadingFromArchive(true);
162 addAlignmentPanel(ap);
165 useAlignmentPanelForSuperposition(ap);
167 if (leaveColouringToJmol || !usetoColour)
169 jmb.setColourBySequence(false);
170 seqColour.setSelected(false);
171 viewerColour.setSelected(true);
173 else if (usetoColour)
175 useAlignmentPanelForColourbyseq(ap);
176 jmb.setColourBySequence(true);
177 seqColour.setSelected(true);
178 viewerColour.setSelected(false);
180 this.setBounds(bounds);
183 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
184 // bounds.width,bounds.height);
186 this.addInternalFrameListener(new InternalFrameAdapter()
188 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
193 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
197 private void initMenus()
199 seqColour.setSelected(jmb.isColourBySequence());
200 viewerColour.setSelected(!jmb.isColourBySequence());
201 if (_colourwith == null)
203 _colourwith = new Vector<AlignmentPanel>();
205 if (_alignwith == null)
207 _alignwith = new Vector<AlignmentPanel>();
210 seqColourBy = new ViewSelectionMenu(MessageManager.getString("label.colour_by"), this, _colourwith,
215 public void itemStateChanged(ItemEvent e)
217 if (!seqColour.isSelected())
223 // update the jmol display now.
224 seqColour_actionPerformed(null);
228 viewMenu.add(seqColourBy);
229 final ItemListener handler;
230 JMenu alpanels = new ViewSelectionMenu(MessageManager.getString("label.superpose_with"), this,
231 _alignwith, handler = new ItemListener()
235 public void itemStateChanged(ItemEvent e)
237 alignStructs.setEnabled(_alignwith.size() > 0);
238 alignStructs.setToolTipText(MessageManager
240 "label.align_structures_using_linked_alignment_views",
242 { new Integer(_alignwith.size()).toString() }));
245 handler.itemStateChanged(null);
246 viewerActionMenu.add(alpanels);
247 viewerActionMenu.addMenuListener(new MenuListener()
251 public void menuSelected(MenuEvent e)
253 handler.itemStateChanged(null);
257 public void menuDeselected(MenuEvent e)
259 // TODO Auto-generated method stub
264 public void menuCanceled(MenuEvent e)
266 // TODO Auto-generated method stub
272 IProgressIndicator progressBar = null;
275 * add a single PDB structure to a new or existing Jmol view
282 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
283 final AlignmentPanel ap)
285 progressBar = ap.alignFrame;
286 // ////////////////////////////////
287 // Is the pdb file already loaded?
288 String alreadyMapped = ap.getStructureSelectionManager()
289 .alreadyMappedToFile(pdbentry.getId());
291 if (alreadyMapped != null)
293 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
294 MessageManager.formatMessage(
295 "label.pdb_entry_is_already_displayed", new String[]
296 { pdbentry.getId() }), MessageManager.formatMessage(
297 "label.map_sequences_to_visible_window", new String[]
298 { pdbentry.getId() }),
299 JOptionPane.YES_NO_CANCEL_OPTION);
301 if (option == JOptionPane.CANCEL_OPTION)
305 if (option == JOptionPane.YES_OPTION)
307 // TODO : Fix multiple seq to one chain issue here.
308 ap.getStructureSelectionManager().setMapping(seq, chains,
309 alreadyMapped, AppletFormatAdapter.FILE);
310 if (ap.getSeqPanel().seqCanvas.fr != null)
312 ap.getSeqPanel().seqCanvas.fr.featuresAdded();
313 ap.paintAlignment(true);
316 // Now this AppJmol is mapped to new sequences. We must add them to
317 // the exisiting array
318 JInternalFrame[] frames = Desktop.instance.getAllFrames();
320 for (int i = 0; i < frames.length; i++)
322 if (frames[i] instanceof AppJmol)
324 final AppJmol topJmol = ((AppJmol) frames[i]);
325 // JBPNOTE: this looks like a binding routine, rather than a gui
327 for (int pe = 0; pe < topJmol.jmb.getPdbCount(); pe++)
329 if (topJmol.jmb.getPdbEntry(pe).getFile()
330 .equals(alreadyMapped))
332 topJmol.jmb.addSequence(pe, seq);
333 topJmol.addAlignmentPanel(ap);
334 // add it to the set used for colouring
335 topJmol.useAlignmentPanelForColourbyseq(ap);
336 topJmol.buildActionMenu();
337 ap.getStructureSelectionManager()
338 .sequenceColoursChanged(ap);
348 // /////////////////////////////////
349 // Check if there are other Jmol views involving this alignment
350 // and prompt user about adding this molecule to one of them
351 Vector existingViews = getJmolsFor(ap);
352 if (existingViews.size() > 0)
354 Enumeration jm = existingViews.elements();
355 while (jm.hasMoreElements())
357 AppJmol topJmol = (AppJmol) jm.nextElement();
358 // TODO: highlight topJmol in view somehow
359 int option = JOptionPane
360 .showInternalConfirmDialog(
362 MessageManager.formatMessage(
363 "label.add_pdbentry_to_view", new String[]
364 { pdbentry.getId(), topJmol.getTitle() }),
366 .getString("label.align_to_existing_structure_view"),
367 JOptionPane.YES_NO_CANCEL_OPTION);
368 if (option == JOptionPane.CANCEL_OPTION)
372 if (option == JOptionPane.YES_OPTION)
374 topJmol.useAlignmentPanelForSuperposition(ap);
375 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
380 // /////////////////////////////////
381 openNewJmol(ap, new PDBEntry[]
382 { pdbentry }, new SequenceI[][]
386 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
389 progressBar = ap.alignFrame;
390 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
391 pdbentrys, seqs, null, null);
392 addAlignmentPanel(ap);
393 useAlignmentPanelForColourbyseq(ap);
394 if (pdbentrys.length > 1)
396 alignAddedStructures = true;
397 useAlignmentPanelForSuperposition(ap);
399 jmb.setColourBySequence(true);
400 setSize(400, 400); // probably should be a configurable/dynamic default here
404 addingStructures = false;
405 worker = new Thread(this);
408 this.addInternalFrameListener(new InternalFrameAdapter()
410 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
419 * create a new Jmol containing several structures superimposed using the
426 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
428 openNewJmol(ap, pe, seqs);
432 * pdb retrieval thread.
434 private Thread worker = null;
437 * add a new structure (with associated sequences and chains) to this viewer,
438 * retrieving it if necessary first.
445 * if true, new structure(s) will be align using associated alignment
447 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
448 final String[] chains, final boolean b,
449 final IProgressIndicator alignFrame)
451 if (pdbentry.getFile() == null)
453 if (worker != null && worker.isAlive())
455 // a retrieval is in progress, wait around and add ourselves to the
457 new Thread(new Runnable()
461 while (worker != null && worker.isAlive() && _started)
465 Thread.sleep(100 + ((int) Math.random() * 100));
467 } catch (Exception e)
472 // and call ourselves again.
473 addStructure(pdbentry, seq, chains, b, alignFrame);
479 // otherwise, start adding the structure.
480 jmb.addSequenceAndChain(new PDBEntry[]
481 { pdbentry }, new SequenceI[][]
482 { seq }, new String[][]
484 addingStructures = true;
486 alignAddedStructures = b;
487 progressBar = alignFrame; // visual indication happens on caller frame.
488 (worker = new Thread(this)).start();
492 private Vector getJmolsFor(AlignmentPanel apanel)
494 Vector result = new Vector();
495 JInternalFrame[] frames = Desktop.instance.getAllFrames();
497 for (JInternalFrame frame : frames)
499 if (frame instanceof AppJmol)
501 if (((StructureViewerBase) frame).isLinkedWith(apanel))
503 result.addElement(frame);
510 void initJmol(String command)
512 jmb.setFinishedInit(false);
513 renderPanel = new RenderPanel();
514 // TODO: consider waiting until the structure/view is fully loaded before
516 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
517 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
518 getBounds().width, getBounds().height);
519 if (scriptWindow == null)
521 BorderLayout bl = new BorderLayout();
524 scriptWindow = new JPanel(bl);
525 scriptWindow.setVisible(false);
528 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
530 jmb.newJmolPopup(true, "Jmol", true);
535 jmb.evalStateCommand(command);
536 jmb.setFinishedInit(true);
539 void setChainMenuItems(Vector chains)
541 chainMenu.removeAll();
546 JMenuItem menuItem = new JMenuItem(
547 MessageManager.getString("label.all"));
548 menuItem.addActionListener(new ActionListener()
550 public void actionPerformed(ActionEvent evt)
552 allChainsSelected = true;
553 for (int i = 0; i < chainMenu.getItemCount(); i++)
555 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
557 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
561 allChainsSelected = false;
565 chainMenu.add(menuItem);
567 for (int c = 0; c < chains.size(); c++)
569 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
570 menuItem.addItemListener(new ItemListener()
572 public void itemStateChanged(ItemEvent evt)
574 if (!allChainsSelected)
581 chainMenu.add(menuItem);
585 boolean allChainsSelected = false;
587 private boolean alignAddedStructures = false;
591 Vector toshow = new Vector();
593 int mlength, p, mnum;
594 for (int i = 0; i < chainMenu.getItemCount(); i++)
596 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
598 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
599 if (item.isSelected())
601 toshow.addElement(item.getText());
605 jmb.centerViewer(toshow);
608 public void closeViewer(boolean closeExternalViewer)
610 // JMol does not use an external viewer
612 setAlignmentPanel(null);
616 // TODO: check for memory leaks where instance isn't finalised because jmb
617 // holds a reference to the window
622 * state flag for PDB retrieval thread
624 private boolean _started = false;
630 // todo - record which pdbids were successfuly imported.
631 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
634 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
635 // TODO: replace with reference fetching/transfer code (validate PDBentry
637 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
638 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
640 String file = jmb.getPdbEntry(pi).getFile();
643 // retrieve the pdb and store it locally
644 AlignmentI pdbseq = null;
645 pdbid = jmb.getPdbEntry(pi).getId();
646 long hdl = pdbid.hashCode() - System.currentTimeMillis();
647 if (progressBar != null)
649 progressBar.setProgressBar(MessageManager.formatMessage("status.fetching_pdb", new String[]{pdbid}), hdl);
653 pdbseq = pdbclient.getSequenceRecords(pdbid);
654 } catch (OutOfMemoryError oomerror)
656 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
657 } catch (Exception ex)
659 ex.printStackTrace();
660 errormsgs.append("'" + pdbid + "'");
662 if (progressBar != null)
664 progressBar.setProgressBar(MessageManager.getString("label.state_completed"), hdl);
668 // just transfer the file name from the first sequence's first
670 file = new File(pdbseq.getSequenceAt(0).getPDBId()
671 .elementAt(0).getFile()).getAbsolutePath();
672 jmb.getPdbEntry(pi).setFile(file);
674 files.append(" \"" + Platform.escapeString(file) + "\"");
678 errormsgs.append("'" + pdbid + "' ");
683 if (curfiles != null && curfiles.length > 0)
685 addingStructures = true; // already files loaded.
686 for (int c = 0; c < curfiles.length; c++)
688 if (curfiles[c].equals(file))
697 files.append(" \"" + Platform.escapeString(file) + "\"");
701 } catch (OutOfMemoryError oomerror)
703 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
704 } catch (Exception ex)
706 ex.printStackTrace();
707 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
710 if (errormsgs.length() > 0)
713 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
714 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
716 { errormsgs.toString() }), MessageManager
717 .getString("label.couldnt_load_file"),
718 JOptionPane.ERROR_MESSAGE);
721 long lastnotify = jmb.getLoadNotifiesHandled();
722 if (files.length() > 0)
724 if (!addingStructures)
729 initJmol("load FILES " + files.toString());
730 } catch (OutOfMemoryError oomerror)
732 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
733 Cache.log.debug("File locations are " + files);
734 } catch (Exception ex)
736 Cache.log.error("Couldn't open Jmol viewer!", ex);
741 StringBuffer cmd = new StringBuffer();
742 cmd.append("loadingJalviewdata=true\nload APPEND ");
743 cmd.append(files.toString());
744 cmd.append("\nloadingJalviewdata=null");
745 final String command = cmd.toString();
747 lastnotify = jmb.getLoadNotifiesHandled();
751 jmb.evalStateCommand(command);
752 } catch (OutOfMemoryError oomerror)
755 "When trying to add structures to the Jmol viewer!",
757 Cache.log.debug("File locations are " + files);
758 } catch (Exception ex)
760 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
764 // need to wait around until script has finished
765 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
766 : (jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb
767 .getPdbFile().length != jmb.getPdbCount()))
771 Cache.log.debug("Waiting around for jmb notify.");
773 } catch (Exception e)
777 // refresh the sequence colours for the new structure(s)
778 for (AlignmentPanel ap : _colourwith)
780 jmb.updateColours(ap);
782 // do superposition if asked to
783 if (alignAddedStructures)
785 javax.swing.SwingUtilities.invokeLater(new Runnable()
789 alignStructs_withAllAlignPanels();
790 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
793 alignAddedStructures = false;
795 addingStructures = false;
803 public void pdbFile_actionPerformed(ActionEvent actionEvent)
805 JalviewFileChooser chooser = new JalviewFileChooser(
806 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
808 chooser.setFileView(new JalviewFileView());
809 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
810 chooser.setToolTipText(MessageManager.getString("action.save"));
812 int value = chooser.showSaveDialog(this);
814 if (value == JalviewFileChooser.APPROVE_OPTION)
818 // TODO: cope with multiple PDB files in view
819 BufferedReader in = new BufferedReader(new FileReader(
820 jmb.getPdbFile()[0]));
821 File outFile = chooser.getSelectedFile();
823 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
825 while ((data = in.readLine()) != null)
827 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
833 } catch (Exception ex)
835 ex.printStackTrace();
841 public void viewMapping_actionPerformed(ActionEvent actionEvent)
843 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
846 cap.appendText(jmb.printMappings());
847 } catch (OutOfMemoryError e)
850 "composing sequence-structure alignments for display in text box.",
855 jalview.gui.Desktop.addInternalFrame(cap,
856 MessageManager.getString("label.pdb_sequence_mapping"), 550,
861 public void eps_actionPerformed(ActionEvent e)
863 makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
867 public void png_actionPerformed(ActionEvent e)
869 makePDBImage(jalview.util.ImageMaker.TYPE.PNG);
872 void makePDBImage(jalview.util.ImageMaker.TYPE type)
874 int width = getWidth();
875 int height = getHeight();
877 jalview.util.ImageMaker im;
879 if (type == jalview.util.ImageMaker.TYPE.PNG)
881 im = new jalview.util.ImageMaker(this,
882 jalview.util.ImageMaker.TYPE.PNG,
883 "Make PNG image from view", width, height, null, null);
885 else if (type == jalview.util.ImageMaker.TYPE.EPS)
887 im = new jalview.util.ImageMaker(this,
888 jalview.util.ImageMaker.TYPE.EPS,
889 "Make EPS file from view", width, height, null,
895 im = new jalview.util.ImageMaker(this,
896 jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
897 width, height, null, this.getTitle());
900 if (im.getGraphics() != null)
902 Rectangle rect = new Rectangle(width, height);
903 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
909 public void viewerColour_actionPerformed(ActionEvent actionEvent)
911 if (viewerColour.isSelected())
913 // disable automatic sequence colouring.
914 jmb.setColourBySequence(false);
919 public void seqColour_actionPerformed(ActionEvent actionEvent)
921 jmb.setColourBySequence(seqColour.isSelected());
922 if (_colourwith == null)
924 _colourwith = new Vector<AlignmentPanel>();
926 if (jmb.isColourBySequence())
928 if (!jmb.isLoadingFromArchive())
930 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
932 // Make the currently displayed alignment panel the associated view
933 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
936 // Set the colour using the current view for the associated alignframe
937 for (AlignmentPanel ap : _colourwith)
939 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
945 public void chainColour_actionPerformed(ActionEvent actionEvent)
947 chainColour.setSelected(true);
952 public void chargeColour_actionPerformed(ActionEvent actionEvent)
954 chargeColour.setSelected(true);
955 jmb.colourByCharge();
959 public void zappoColour_actionPerformed(ActionEvent actionEvent)
961 zappoColour.setSelected(true);
962 jmb.setJalviewColourScheme(new ZappoColourScheme());
966 public void taylorColour_actionPerformed(ActionEvent actionEvent)
968 taylorColour.setSelected(true);
969 jmb.setJalviewColourScheme(new TaylorColourScheme());
973 public void hydroColour_actionPerformed(ActionEvent actionEvent)
975 hydroColour.setSelected(true);
976 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
980 public void helixColour_actionPerformed(ActionEvent actionEvent)
982 helixColour.setSelected(true);
983 jmb.setJalviewColourScheme(new HelixColourScheme());
987 public void strandColour_actionPerformed(ActionEvent actionEvent)
989 strandColour.setSelected(true);
990 jmb.setJalviewColourScheme(new StrandColourScheme());
994 public void turnColour_actionPerformed(ActionEvent actionEvent)
996 turnColour.setSelected(true);
997 jmb.setJalviewColourScheme(new TurnColourScheme());
1001 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1003 buriedColour.setSelected(true);
1004 jmb.setJalviewColourScheme(new BuriedColourScheme());
1008 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1010 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1014 public void userColour_actionPerformed(ActionEvent actionEvent)
1016 userColour.setSelected(true);
1017 new UserDefinedColours(this, null);
1021 public void backGround_actionPerformed(ActionEvent actionEvent)
1023 java.awt.Color col = JColorChooser.showDialog(this,
1024 MessageManager.getString("label.select_backgroud_colour"), null);
1027 jmb.setBackgroundColour(col);
1032 public void showHelp_actionPerformed(ActionEvent actionEvent)
1036 jalview.util.BrowserLauncher
1037 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1038 } catch (Exception ex)
1043 public void showConsole(boolean showConsole)
1048 if (splitPane == null)
1050 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1051 splitPane.setTopComponent(renderPanel);
1052 splitPane.setBottomComponent(scriptWindow);
1053 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1054 splitPane.setDividerLocation(getHeight() - 200);
1055 scriptWindow.setVisible(true);
1056 scriptWindow.validate();
1057 splitPane.validate();
1063 if (splitPane != null)
1065 splitPane.setVisible(false);
1070 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1076 class RenderPanel extends JPanel
1078 final Dimension currentSize = new Dimension();
1080 final Rectangle rectClip = new Rectangle();
1082 public void paintComponent(Graphics g)
1084 getSize(currentSize);
1085 g.getClipBounds(rectClip);
1087 if (jmb != null && jmb.fileLoadingError != null)
1089 g.setColor(Color.black);
1090 g.fillRect(0, 0, currentSize.width, currentSize.height);
1091 g.setColor(Color.white);
1092 g.setFont(new Font("Verdana", Font.BOLD, 14));
1093 g.drawString(MessageManager.getString("label.error_loading_file")
1094 + "...", 20, currentSize.height / 2);
1095 StringBuffer sb = new StringBuffer();
1097 for (int e = 0; e < jmb.getPdbCount(); e++)
1099 sb.append(jmb.getPdbEntry(e).getId());
1100 if (e < jmb.getPdbCount() - 1)
1105 if (e == jmb.getPdbCount() - 1 || sb.length() > 20)
1108 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1109 * g.getFontMetrics().getHeight());
1113 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1115 g.setColor(Color.black);
1116 g.fillRect(0, 0, currentSize.width, currentSize.height);
1117 g.setColor(Color.white);
1118 g.setFont(new Font("Verdana", Font.BOLD, 14));
1119 g.drawString(MessageManager.getString("label.retrieving_pdb_data"),
1120 20, currentSize.height / 2);
1124 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1129 public void updateTitleAndMenus()
1131 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1136 setChainMenuItems(jmb.chainNames);
1138 this.setTitle(jmb.getViewerTitle());
1139 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1141 viewerActionMenu.setVisible(true);
1143 if (!jmb.isLoadingFromArchive())
1145 seqColour_actionPerformed(null);
1153 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1157 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1159 alignStructs_withAllAlignPanels();
1162 private void alignStructs_withAllAlignPanels()
1164 if (getAlignmentPanel() == null)
1169 if (_alignwith.size() == 0)
1171 _alignwith.add(getAlignmentPanel());
1176 AlignmentI[] als = new Alignment[_alignwith.size()];
1177 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1178 int[] alm = new int[_alignwith.size()];
1181 for (AlignmentPanel ap : _alignwith)
1183 als[a] = ap.av.getAlignment();
1185 alc[a++] = ap.av.getColumnSelection();
1187 jmb.superposeStructures(als, alm, alc);
1188 } catch (Exception e)
1190 StringBuffer sp = new StringBuffer();
1191 for (AlignmentPanel ap : _alignwith)
1193 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1195 Cache.log.info("Couldn't align structures with the " + sp.toString()
1196 + "associated alignment panels.", e);
1202 public void setJalviewColourScheme(ColourSchemeI ucs)
1204 jmb.setJalviewColourScheme(ucs);
1211 * @return first alignment panel displaying given alignment, or the default
1214 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1216 for (AlignmentPanel ap : getAllAlignmentPanels())
1218 if (ap.av.getAlignment() == alignment)
1223 return getAlignmentPanel();
1227 public AAStructureBindingModel getBinding()
1233 public String getStateInfo()
1235 return jmb == null ? null : jmb.viewer.getStateInfo();
1239 public ViewerType getViewerType()
1241 return ViewerType.JMOL;