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.JalviewFileChooser;
31 import jalview.io.JalviewFileView;
32 import jalview.schemes.BuriedColourScheme;
33 import jalview.schemes.ColourSchemeI;
34 import jalview.schemes.HelixColourScheme;
35 import jalview.schemes.HydrophobicColourScheme;
36 import jalview.schemes.PurinePyrimidineColourScheme;
37 import jalview.schemes.StrandColourScheme;
38 import jalview.schemes.TaylorColourScheme;
39 import jalview.schemes.TurnColourScheme;
40 import jalview.schemes.ZappoColourScheme;
41 import jalview.structures.models.AAStructureBindingModel;
42 import jalview.util.MessageManager;
43 import jalview.util.Platform;
44 import jalview.ws.dbsources.Pdb;
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.IOException;
61 import java.io.PrintWriter;
62 import java.util.ArrayList;
63 import java.util.List;
64 import java.util.Vector;
66 import javax.swing.JCheckBoxMenuItem;
67 import javax.swing.JColorChooser;
68 import javax.swing.JInternalFrame;
69 import javax.swing.JMenu;
70 import javax.swing.JMenuItem;
71 import javax.swing.JOptionPane;
72 import javax.swing.JPanel;
73 import javax.swing.JSplitPane;
74 import javax.swing.SwingUtilities;
75 import javax.swing.event.InternalFrameAdapter;
76 import javax.swing.event.InternalFrameEvent;
77 import javax.swing.event.MenuEvent;
78 import javax.swing.event.MenuListener;
80 public class AppJmol extends StructureViewerBase
82 private static final String SPACE = " ";
84 private static final String BACKSLASH = "\"";
92 RenderPanel renderPanel;
94 ViewSelectionMenu seqColourBy;
103 * - add the alignment panel to the list used for colouring these
106 * - add the alignment panel to the list used for aligning these
108 * @param leaveColouringToJmol
109 * - do not update the colours from any other source. Jmol is
115 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
116 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
117 boolean leaveColouringToJmol, String loadStatus,
118 Rectangle bounds, String viewid)
120 PDBEntry[] pdbentrys = new PDBEntry[files.length];
121 for (int i = 0; i < pdbentrys.length; i++)
123 // PDBEntry pdbentry = new PDBEntry(files[i], ids[i]);
124 PDBEntry pdbentry = new PDBEntry(ids[i], null, PDBEntry.Type.PDB,
126 pdbentrys[i] = pdbentry;
128 // / TODO: check if protocol is needed to be set, and if chains are
130 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
131 pdbentrys, seqs, null, null);
133 jmb.setLoadingFromArchive(true);
134 addAlignmentPanel(ap);
137 useAlignmentPanelForSuperposition(ap);
139 if (leaveColouringToJmol || !usetoColour)
141 jmb.setColourBySequence(false);
142 seqColour.setSelected(false);
143 viewerColour.setSelected(true);
145 else if (usetoColour)
147 useAlignmentPanelForColourbyseq(ap);
148 jmb.setColourBySequence(true);
149 seqColour.setSelected(true);
150 viewerColour.setSelected(false);
152 this.setBounds(bounds);
155 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
156 // bounds.width,bounds.height);
158 this.addInternalFrameListener(new InternalFrameAdapter()
161 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
166 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
170 private void initMenus()
172 seqColour.setSelected(jmb.isColourBySequence());
173 viewerColour.setSelected(!jmb.isColourBySequence());
174 if (_colourwith == null)
176 _colourwith = new Vector<AlignmentPanel>();
178 if (_alignwith == null)
180 _alignwith = new Vector<AlignmentPanel>();
183 seqColourBy = new ViewSelectionMenu(
184 MessageManager.getString("label.colour_by"), this, _colourwith,
189 public void itemStateChanged(ItemEvent e)
191 if (!seqColour.isSelected())
197 // update the jmol display now.
198 seqColour_actionPerformed(null);
202 viewMenu.add(seqColourBy);
203 final ItemListener handler;
204 JMenu alpanels = new ViewSelectionMenu(
205 MessageManager.getString("label.superpose_with"), this,
206 _alignwith, handler = new ItemListener()
210 public void itemStateChanged(ItemEvent e)
212 alignStructs.setEnabled(_alignwith.size() > 0);
213 alignStructs.setToolTipText(MessageManager
215 "label.align_structures_using_linked_alignment_views",
216 new String[] { new Integer(_alignwith
217 .size()).toString() }));
220 handler.itemStateChanged(null);
221 viewerActionMenu.add(alpanels);
222 viewerActionMenu.addMenuListener(new MenuListener()
226 public void menuSelected(MenuEvent e)
228 handler.itemStateChanged(null);
232 public void menuDeselected(MenuEvent e)
234 // TODO Auto-generated method stub
239 public void menuCanceled(MenuEvent e)
241 // TODO Auto-generated method stub
247 IProgressIndicator progressBar = null;
250 * add a single PDB structure to a new or existing Jmol view
257 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
258 final AlignmentPanel ap)
260 progressBar = ap.alignFrame;
261 String pdbId = pdbentry.getId();
264 * If the PDB file is already loaded, the user may just choose to add to an
265 * existing viewer (or cancel)
267 if (addAlreadyLoadedFile(seq, chains, ap, pdbId))
273 * Check if there are other Jmol views involving this alignment and prompt
274 * user about adding this molecule to one of them
276 if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId))
282 * If the options above are declined or do not apply, open a new viewer
284 openNewJmol(ap, new PDBEntry[] { pdbentry }, new SequenceI[][] { seq });
288 * Answers true if this viewer already involves the given PDB ID
291 protected boolean hasPdbId(String pdbId)
293 return jmb.hasPdbId(pdbId);
296 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
299 progressBar = ap.alignFrame;
300 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
301 pdbentrys, seqs, null, null);
302 addAlignmentPanel(ap);
303 useAlignmentPanelForColourbyseq(ap);
304 if (pdbentrys.length > 1)
306 alignAddedStructures = true;
307 useAlignmentPanelForSuperposition(ap);
309 jmb.setColourBySequence(true);
310 setSize(400, 400); // probably should be a configurable/dynamic default here
314 addingStructures = false;
315 worker = new Thread(this);
318 this.addInternalFrameListener(new InternalFrameAdapter()
321 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
330 * create a new Jmol containing several structures superimposed using the
337 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
339 openNewJmol(ap, pe, seqs);
343 * Returns a list of any Jmol viewers. The list is restricted to those linked
344 * to the given alignment panel if it is not null.
347 protected List<StructureViewerBase> getViewersFor(AlignmentPanel apanel)
349 List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
350 JInternalFrame[] frames = Desktop.instance.getAllFrames();
352 for (JInternalFrame frame : frames)
354 if (frame instanceof AppJmol)
357 || ((StructureViewerBase) frame).isLinkedWith(apanel))
359 result.add((StructureViewerBase) frame);
366 void initJmol(String command)
368 jmb.setFinishedInit(false);
369 renderPanel = new RenderPanel();
370 // TODO: consider waiting until the structure/view is fully loaded before
372 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
373 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
374 getBounds().width, getBounds().height);
375 if (scriptWindow == null)
377 BorderLayout bl = new BorderLayout();
380 scriptWindow = new JPanel(bl);
381 scriptWindow.setVisible(false);
384 jmb.allocateViewer(renderPanel, true, "", null, null, "",
386 // jmb.newJmolPopup("Jmol");
391 jmb.evalStateCommand(command);
392 jmb.evalStateCommand("set hoverDelay=0.1");
393 jmb.setFinishedInit(true);
396 void setChainMenuItems(Vector<String> chains)
398 chainMenu.removeAll();
403 JMenuItem menuItem = new JMenuItem(
404 MessageManager.getString("label.all"));
405 menuItem.addActionListener(new ActionListener()
408 public void actionPerformed(ActionEvent evt)
410 allChainsSelected = true;
411 for (int i = 0; i < chainMenu.getItemCount(); i++)
413 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
415 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
419 allChainsSelected = false;
423 chainMenu.add(menuItem);
425 for (String chain : chains)
427 menuItem = new JCheckBoxMenuItem(chain, true);
428 menuItem.addItemListener(new ItemListener()
431 public void itemStateChanged(ItemEvent evt)
433 if (!allChainsSelected)
440 chainMenu.add(menuItem);
444 boolean allChainsSelected = false;
448 Vector<String> toshow = new Vector<String>();
449 for (int i = 0; i < chainMenu.getItemCount(); i++)
451 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
453 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
454 if (item.isSelected())
456 toshow.addElement(item.getText());
460 jmb.centerViewer(toshow);
464 public void closeViewer(boolean closeExternalViewer)
466 // Jmol does not use an external viewer
471 setAlignmentPanel(null);
475 // TODO: check for memory leaks where instance isn't finalised because jmb
476 // holds a reference to the window
486 List<String> files = fetchPdbFiles();
487 if (files.size() > 0)
489 showFilesInViewer(files);
499 * Either adds the given files to a structure viewer or opens a new viewer to
503 * list of absolute paths to structure files
505 void showFilesInViewer(List<String> files)
507 long lastnotify = jmb.getLoadNotifiesHandled();
508 StringBuilder fileList = new StringBuilder();
509 for (String s : files)
511 fileList.append(SPACE).append(BACKSLASH)
512 .append(Platform.escapeString(s)).append(BACKSLASH);
514 String filesString = fileList.toString();
516 if (!addingStructures)
520 initJmol("load FILES " + filesString);
521 } catch (OutOfMemoryError oomerror)
523 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
524 Cache.log.debug("File locations are " + filesString);
525 } catch (Exception ex)
527 Cache.log.error("Couldn't open Jmol viewer!", ex);
532 StringBuilder cmd = new StringBuilder();
533 cmd.append("loadingJalviewdata=true\nload APPEND ");
534 cmd.append(filesString);
535 cmd.append("\nloadingJalviewdata=null");
536 final String command = cmd.toString();
537 lastnotify = jmb.getLoadNotifiesHandled();
541 jmb.evalStateCommand(command);
542 } catch (OutOfMemoryError oomerror)
544 new OOMWarning("When trying to add structures to the Jmol viewer!",
546 Cache.log.debug("File locations are " + filesString);
547 } catch (Exception ex)
549 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
553 // need to wait around until script has finished
554 int waitMax = 5000; // give up after 5 seconds
557 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
558 : !(jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb
559 .getPdbFile().length == files.size()))
563 Cache.log.debug("Waiting around for jmb notify.");
564 Thread.sleep(waitFor);
565 waitTotal += waitFor;
566 } catch (Exception e)
569 if (waitTotal > waitMax)
571 System.err.println("Timed out waiting for Jmol to load files");
576 // refresh the sequence colours for the new structure(s)
577 for (AlignmentPanel ap : _colourwith)
579 jmb.updateColours(ap);
581 // do superposition if asked to
582 if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures)
584 alignAddedStructures();
586 addingStructures = false;
590 * Queues a thread to align structures with Jalview alignments
592 void alignAddedStructures()
594 javax.swing.SwingUtilities.invokeLater(new Runnable()
599 if (jmb.viewer.isScriptExecuting())
601 SwingUtilities.invokeLater(this);
605 } catch (InterruptedException q)
612 alignStructs_withAllAlignPanels();
616 alignAddedStructures = false;
620 * Retrieves and saves as file any modelled PDB entries for which we do not
621 * already have a file saved. Returns a list of absolute paths to structure
622 * files which were either retrieved, or already stored but not modelled in
623 * the structure viewer (i.e. files to add to the viewer display).
627 List<String> fetchPdbFiles()
629 // todo - record which pdbids were successfully imported.
630 StringBuilder errormsgs = new StringBuilder();
632 List<String> files = new ArrayList<String>();
636 String[] filesInViewer = jmb.getPdbFile();
637 // TODO: replace with reference fetching/transfer code (validate PDBentry
639 Pdb pdbclient = new Pdb();
640 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
642 String file = jmb.getPdbEntry(pi).getFile();
645 // retrieve the pdb and store it locally
646 AlignmentI pdbseq = null;
647 pdbid = jmb.getPdbEntry(pi).getId();
648 long hdl = pdbid.hashCode() - System.currentTimeMillis();
649 if (progressBar != null)
651 progressBar.setProgressBar(MessageManager.formatMessage(
652 "status.fetching_pdb", new String[] { pdbid }), hdl);
656 pdbseq = pdbclient.getSequenceRecords(pdbid);
657 } catch (OutOfMemoryError oomerror)
659 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
660 } catch (Exception ex)
662 ex.printStackTrace();
663 errormsgs.append("'").append(pdbid).append("'");
666 if (progressBar != null)
668 progressBar.setProgressBar(
669 MessageManager.getString("label.state_completed"),
675 // just transfer the file name from the first sequence's first
677 file = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
678 .elementAt(0).getFile()).getAbsolutePath();
679 jmb.getPdbEntry(pi).setFile(file);
684 errormsgs.append("'").append(pdbid).append("' ");
689 if (filesInViewer != null && filesInViewer.length > 0)
691 addingStructures = true; // already files loaded.
692 for (int c = 0; c < filesInViewer.length; c++)
694 if (filesInViewer[c].equals(file))
707 } catch (OutOfMemoryError oomerror)
709 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
710 } catch (Exception ex)
712 ex.printStackTrace();
713 errormsgs.append("When retrieving pdbfiles : current was: '")
714 .append(pdbid).append("'");
716 if (errormsgs.length() > 0)
718 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
719 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
720 new String[] { errormsgs.toString() }),
721 MessageManager.getString("label.couldnt_load_file"),
722 JOptionPane.ERROR_MESSAGE);
728 public void pdbFile_actionPerformed(ActionEvent actionEvent)
730 JalviewFileChooser chooser = new JalviewFileChooser(
731 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
733 chooser.setFileView(new JalviewFileView());
734 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
735 chooser.setToolTipText(MessageManager.getString("action.save"));
737 int value = chooser.showSaveDialog(this);
739 if (value == JalviewFileChooser.APPROVE_OPTION)
741 BufferedReader in = null;
744 // TODO: cope with multiple PDB files in view
745 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
746 File outFile = chooser.getSelectedFile();
748 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
750 while ((data = in.readLine()) != null)
752 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
758 } catch (Exception ex)
760 ex.printStackTrace();
768 } catch (IOException e)
778 public void viewMapping_actionPerformed(ActionEvent actionEvent)
780 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
783 cap.appendText(jmb.printMappings());
784 } catch (OutOfMemoryError e)
787 "composing sequence-structure alignments for display in text box.",
792 jalview.gui.Desktop.addInternalFrame(cap,
793 MessageManager.getString("label.pdb_sequence_mapping"), 550,
798 public void eps_actionPerformed(ActionEvent e)
800 makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
804 public void png_actionPerformed(ActionEvent e)
806 makePDBImage(jalview.util.ImageMaker.TYPE.PNG);
809 void makePDBImage(jalview.util.ImageMaker.TYPE type)
811 int width = getWidth();
812 int height = getHeight();
814 jalview.util.ImageMaker im;
816 if (type == jalview.util.ImageMaker.TYPE.PNG)
818 im = new jalview.util.ImageMaker(this,
819 jalview.util.ImageMaker.TYPE.PNG, "Make PNG image from view",
820 width, height, null, null, null, 0, false);
822 else if (type == jalview.util.ImageMaker.TYPE.EPS)
824 im = new jalview.util.ImageMaker(this,
825 jalview.util.ImageMaker.TYPE.EPS, "Make EPS file from view",
826 width, height, null, this.getTitle(), null, 0, false);
831 im = new jalview.util.ImageMaker(this,
832 jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
833 width, height, null, this.getTitle(), null, 0, false);
836 if (im.getGraphics() != null)
838 jmb.viewer.renderScreenImage(im.getGraphics(), width, height);
844 public void viewerColour_actionPerformed(ActionEvent actionEvent)
846 if (viewerColour.isSelected())
848 // disable automatic sequence colouring.
849 jmb.setColourBySequence(false);
854 public void seqColour_actionPerformed(ActionEvent actionEvent)
856 jmb.setColourBySequence(seqColour.isSelected());
857 if (_colourwith == null)
859 _colourwith = new Vector<AlignmentPanel>();
861 if (jmb.isColourBySequence())
863 if (!jmb.isLoadingFromArchive())
865 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
867 // Make the currently displayed alignment panel the associated view
868 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
871 // Set the colour using the current view for the associated alignframe
872 for (AlignmentPanel ap : _colourwith)
874 jmb.colourBySequence(ap);
880 public void chainColour_actionPerformed(ActionEvent actionEvent)
882 chainColour.setSelected(true);
887 public void chargeColour_actionPerformed(ActionEvent actionEvent)
889 chargeColour.setSelected(true);
890 jmb.colourByCharge();
894 public void zappoColour_actionPerformed(ActionEvent actionEvent)
896 zappoColour.setSelected(true);
897 jmb.setJalviewColourScheme(new ZappoColourScheme());
901 public void taylorColour_actionPerformed(ActionEvent actionEvent)
903 taylorColour.setSelected(true);
904 jmb.setJalviewColourScheme(new TaylorColourScheme());
908 public void hydroColour_actionPerformed(ActionEvent actionEvent)
910 hydroColour.setSelected(true);
911 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
915 public void helixColour_actionPerformed(ActionEvent actionEvent)
917 helixColour.setSelected(true);
918 jmb.setJalviewColourScheme(new HelixColourScheme());
922 public void strandColour_actionPerformed(ActionEvent actionEvent)
924 strandColour.setSelected(true);
925 jmb.setJalviewColourScheme(new StrandColourScheme());
929 public void turnColour_actionPerformed(ActionEvent actionEvent)
931 turnColour.setSelected(true);
932 jmb.setJalviewColourScheme(new TurnColourScheme());
936 public void buriedColour_actionPerformed(ActionEvent actionEvent)
938 buriedColour.setSelected(true);
939 jmb.setJalviewColourScheme(new BuriedColourScheme());
943 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
945 setJalviewColourScheme(new PurinePyrimidineColourScheme());
949 public void userColour_actionPerformed(ActionEvent actionEvent)
951 userColour.setSelected(true);
952 new UserDefinedColours(this, null);
956 public void backGround_actionPerformed(ActionEvent actionEvent)
958 java.awt.Color col = JColorChooser
959 .showDialog(this, MessageManager
960 .getString("label.select_backgroud_colour"), null);
963 jmb.setBackgroundColour(col);
968 public void showHelp_actionPerformed(ActionEvent actionEvent)
972 jalview.util.BrowserLauncher
973 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
974 } catch (Exception ex)
979 public void showConsole(boolean showConsole)
984 if (splitPane == null)
986 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
987 splitPane.setTopComponent(renderPanel);
988 splitPane.setBottomComponent(scriptWindow);
989 this.getContentPane().add(splitPane, BorderLayout.CENTER);
990 splitPane.setDividerLocation(getHeight() - 200);
991 scriptWindow.setVisible(true);
992 scriptWindow.validate();
993 splitPane.validate();
999 if (splitPane != null)
1001 splitPane.setVisible(false);
1006 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1012 class RenderPanel extends JPanel
1014 final Dimension currentSize = new Dimension();
1017 public void paintComponent(Graphics g)
1019 getSize(currentSize);
1021 if (jmb != null && jmb.fileLoadingError != null)
1023 g.setColor(Color.black);
1024 g.fillRect(0, 0, currentSize.width, currentSize.height);
1025 g.setColor(Color.white);
1026 g.setFont(new Font("Verdana", Font.BOLD, 14));
1027 g.drawString(MessageManager.getString("label.error_loading_file")
1028 + "...", 20, currentSize.height / 2);
1029 StringBuffer sb = new StringBuffer();
1031 for (int e = 0; e < jmb.getPdbCount(); e++)
1033 sb.append(jmb.getPdbEntry(e).getId());
1034 if (e < jmb.getPdbCount() - 1)
1039 if (e == jmb.getPdbCount() - 1 || sb.length() > 20)
1042 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1043 * g.getFontMetrics().getHeight());
1047 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1049 g.setColor(Color.black);
1050 g.fillRect(0, 0, currentSize.width, currentSize.height);
1051 g.setColor(Color.white);
1052 g.setFont(new Font("Verdana", Font.BOLD, 14));
1053 g.drawString(MessageManager.getString("label.retrieving_pdb_data"),
1054 20, currentSize.height / 2);
1058 jmb.viewer.renderScreenImage(g, currentSize.width,
1059 currentSize.height);
1064 public void updateTitleAndMenus()
1066 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1071 setChainMenuItems(jmb.chainNames);
1073 this.setTitle(jmb.getViewerTitle());
1074 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1076 viewerActionMenu.setVisible(true);
1078 if (!jmb.isLoadingFromArchive())
1080 seqColour_actionPerformed(null);
1088 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1092 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1094 alignStructs_withAllAlignPanels();
1097 private void alignStructs_withAllAlignPanels()
1099 if (getAlignmentPanel() == null)
1104 if (_alignwith.size() == 0)
1106 _alignwith.add(getAlignmentPanel());
1111 AlignmentI[] als = new Alignment[_alignwith.size()];
1112 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1113 int[] alm = new int[_alignwith.size()];
1116 for (AlignmentPanel ap : _alignwith)
1118 als[a] = ap.av.getAlignment();
1120 alc[a++] = ap.av.getColumnSelection();
1122 jmb.superposeStructures(als, alm, alc);
1123 } catch (Exception e)
1125 StringBuffer sp = new StringBuffer();
1126 for (AlignmentPanel ap : _alignwith)
1128 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1130 Cache.log.info("Couldn't align structures with the " + sp.toString()
1131 + "associated alignment panels.", e);
1138 public void setJalviewColourScheme(ColourSchemeI ucs)
1140 jmb.setJalviewColourScheme(ucs);
1147 * @return first alignment panel displaying given alignment, or the default
1150 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1152 for (AlignmentPanel ap : getAllAlignmentPanels())
1154 if (ap.av.getAlignment() == alignment)
1159 return getAlignmentPanel();
1163 public AAStructureBindingModel getBinding()
1169 public String getStateInfo()
1171 return jmb == null ? null : jmb.viewer.getStateInfo();
1175 public ViewerType getViewerType()
1177 return ViewerType.JMOL;
1181 protected AAStructureBindingModel getBindingModel()