2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2)
3 * Copyright (C) 2015 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 // ms to wait for Jmol to load files
83 private static final int JMOL_LOAD_TIMEOUT = 20000;
85 private static final String SPACE = " ";
87 private static final String BACKSLASH = "\"";
95 RenderPanel renderPanel;
97 ViewSelectionMenu seqColourBy;
106 * - add the alignment panel to the list used for colouring these
109 * - add the alignment panel to the list used for aligning these
111 * @param leaveColouringToJmol
112 * - do not update the colours from any other source. Jmol is
118 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
119 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
120 boolean leaveColouringToJmol, String loadStatus,
121 Rectangle bounds, String viewid)
123 PDBEntry[] pdbentrys = new PDBEntry[files.length];
124 for (int i = 0; i < pdbentrys.length; i++)
126 // PDBEntry pdbentry = new PDBEntry(files[i], ids[i]);
127 PDBEntry pdbentry = new PDBEntry(ids[i], null, PDBEntry.Type.PDB,
129 pdbentrys[i] = pdbentry;
131 // / TODO: check if protocol is needed to be set, and if chains are
133 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
134 pdbentrys, seqs, null, null);
136 jmb.setLoadingFromArchive(true);
137 addAlignmentPanel(ap);
140 useAlignmentPanelForSuperposition(ap);
142 if (leaveColouringToJmol || !usetoColour)
144 jmb.setColourBySequence(false);
145 seqColour.setSelected(false);
146 viewerColour.setSelected(true);
148 else if (usetoColour)
150 useAlignmentPanelForColourbyseq(ap);
151 jmb.setColourBySequence(true);
152 seqColour.setSelected(true);
153 viewerColour.setSelected(false);
155 this.setBounds(bounds);
158 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
159 // bounds.width,bounds.height);
161 this.addInternalFrameListener(new InternalFrameAdapter()
164 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
169 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
173 private void initMenus()
175 seqColour.setSelected(jmb.isColourBySequence());
176 viewerColour.setSelected(!jmb.isColourBySequence());
177 if (_colourwith == null)
179 _colourwith = new Vector<AlignmentPanel>();
181 if (_alignwith == null)
183 _alignwith = new Vector<AlignmentPanel>();
186 seqColourBy = new ViewSelectionMenu(
187 MessageManager.getString("label.colour_by"), this, _colourwith,
192 public void itemStateChanged(ItemEvent e)
194 if (!seqColour.isSelected())
200 // update the jmol display now.
201 seqColour_actionPerformed(null);
205 viewMenu.add(seqColourBy);
206 final ItemListener handler;
207 JMenu alpanels = new ViewSelectionMenu(
208 MessageManager.getString("label.superpose_with"), this,
209 _alignwith, handler = new ItemListener()
213 public void itemStateChanged(ItemEvent e)
215 alignStructs.setEnabled(_alignwith.size() > 0);
216 alignStructs.setToolTipText(MessageManager
218 "label.align_structures_using_linked_alignment_views",
219 new String[] { new Integer(_alignwith
220 .size()).toString() }));
223 handler.itemStateChanged(null);
224 viewerActionMenu.add(alpanels);
225 viewerActionMenu.addMenuListener(new MenuListener()
229 public void menuSelected(MenuEvent e)
231 handler.itemStateChanged(null);
235 public void menuDeselected(MenuEvent e)
237 // TODO Auto-generated method stub
242 public void menuCanceled(MenuEvent e)
244 // TODO Auto-generated method stub
250 IProgressIndicator progressBar = null;
253 * add a single PDB structure to a new or existing Jmol view
260 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
261 final AlignmentPanel ap)
263 progressBar = ap.alignFrame;
264 String pdbId = pdbentry.getId();
267 * If the PDB file is already loaded, the user may just choose to add to an
268 * existing viewer (or cancel)
270 if (addAlreadyLoadedFile(seq, chains, ap, pdbId))
276 * Check if there are other Jmol views involving this alignment and prompt
277 * user about adding this molecule to one of them
279 if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId))
285 * If the options above are declined or do not apply, open a new viewer
287 openNewJmol(ap, new PDBEntry[] { pdbentry }, new SequenceI[][] { seq });
291 * Answers true if this viewer already involves the given PDB ID
294 protected boolean hasPdbId(String pdbId)
296 return jmb.hasPdbId(pdbId);
299 private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
302 progressBar = ap.alignFrame;
303 jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
304 pdbentrys, seqs, null, null);
305 addAlignmentPanel(ap);
306 useAlignmentPanelForColourbyseq(ap);
307 if (pdbentrys.length > 1)
309 alignAddedStructures = true;
310 useAlignmentPanelForSuperposition(ap);
312 jmb.setColourBySequence(true);
313 setSize(400, 400); // probably should be a configurable/dynamic default here
315 addingStructures = false;
316 worker = new Thread(this);
319 this.addInternalFrameListener(new InternalFrameAdapter()
322 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
331 * create a new Jmol containing several structures superimposed using the
338 public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs)
340 openNewJmol(ap, pe, seqs);
344 * Returns a list of any Jmol viewers. The list is restricted to those linked
345 * to the given alignment panel if it is not null.
348 protected List<StructureViewerBase> getViewersFor(AlignmentPanel apanel)
350 List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
351 JInternalFrame[] frames = Desktop.instance.getAllFrames();
353 for (JInternalFrame frame : frames)
355 if (frame instanceof AppJmol)
358 || ((StructureViewerBase) frame).isLinkedWith(apanel))
360 result.add((StructureViewerBase) frame);
367 void initJmol(String command)
369 jmb.setFinishedInit(false);
370 renderPanel = new RenderPanel();
371 // TODO: consider waiting until the structure/view is fully loaded before
373 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
374 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
375 getBounds().width, getBounds().height);
376 if (scriptWindow == null)
378 BorderLayout bl = new BorderLayout();
381 scriptWindow = new JPanel(bl);
382 scriptWindow.setVisible(false);
385 jmb.allocateViewer(renderPanel, true, "", null, null, "",
387 // jmb.newJmolPopup("Jmol");
392 jmb.evalStateCommand(command);
393 jmb.evalStateCommand("set hoverDelay=0.1");
394 jmb.setFinishedInit(true);
397 void setChainMenuItems(Vector<String> chains)
399 chainMenu.removeAll();
404 JMenuItem menuItem = new JMenuItem(
405 MessageManager.getString("label.all"));
406 menuItem.addActionListener(new ActionListener()
409 public void actionPerformed(ActionEvent evt)
411 allChainsSelected = true;
412 for (int i = 0; i < chainMenu.getItemCount(); i++)
414 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
416 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
420 allChainsSelected = false;
424 chainMenu.add(menuItem);
426 for (String chain : chains)
428 menuItem = new JCheckBoxMenuItem(chain, true);
429 menuItem.addItemListener(new ItemListener()
432 public void itemStateChanged(ItemEvent evt)
434 if (!allChainsSelected)
441 chainMenu.add(menuItem);
445 boolean allChainsSelected = false;
449 Vector<String> toshow = new Vector<String>();
450 for (int i = 0; i < chainMenu.getItemCount(); i++)
452 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
454 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
455 if (item.isSelected())
457 toshow.addElement(item.getText());
461 jmb.centerViewer(toshow);
465 public void closeViewer(boolean closeExternalViewer)
467 // Jmol does not use an external viewer
472 setAlignmentPanel(null);
476 // TODO: check for memory leaks where instance isn't finalised because jmb
477 // holds a reference to the window
487 List<String> files = fetchPdbFiles();
488 if (files.size() > 0)
490 showFilesInViewer(files);
500 * Either adds the given files to a structure viewer or opens a new viewer to
504 * list of absolute paths to structure files
506 void showFilesInViewer(List<String> files)
508 long lastnotify = jmb.getLoadNotifiesHandled();
509 StringBuilder fileList = new StringBuilder();
510 for (String s : files)
512 fileList.append(SPACE).append(BACKSLASH)
513 .append(Platform.escapeString(s)).append(BACKSLASH);
515 String filesString = fileList.toString();
517 if (!addingStructures)
521 initJmol("load FILES " + filesString);
522 } catch (OutOfMemoryError oomerror)
524 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
525 Cache.log.debug("File locations are " + filesString);
526 } catch (Exception ex)
528 Cache.log.error("Couldn't open Jmol viewer!", ex);
533 StringBuilder cmd = new StringBuilder();
534 cmd.append("loadingJalviewdata=true\nload APPEND ");
535 cmd.append(filesString);
536 cmd.append("\nloadingJalviewdata=null");
537 final String command = cmd.toString();
538 lastnotify = jmb.getLoadNotifiesHandled();
542 jmb.evalStateCommand(command);
543 } catch (OutOfMemoryError oomerror)
545 new OOMWarning("When trying to add structures to the Jmol viewer!",
547 Cache.log.debug("File locations are " + filesString);
548 } catch (Exception ex)
550 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
554 // need to wait around until script has finished
555 int waitMax = JMOL_LOAD_TIMEOUT;
558 while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
559 : !(jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb
560 .getPdbFile().length == files.size()))
564 Cache.log.debug("Waiting around for jmb notify.");
565 Thread.sleep(waitFor);
566 waitTotal += waitFor;
567 } catch (Exception e)
570 if (waitTotal > waitMax)
573 .println("Timed out waiting for Jmol to load files after "
575 // System.err.println("finished: " + jmb.isFinishedInit()
576 // + "; loaded: " + Arrays.toString(jmb.getPdbFile())
577 // + "; files: " + files.toString());
583 // refresh the sequence colours for the new structure(s)
584 for (AlignmentPanel ap : _colourwith)
586 jmb.updateColours(ap);
588 // do superposition if asked to
589 if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures)
591 alignAddedStructures();
593 addingStructures = false;
597 * Queues a thread to align structures with Jalview alignments
599 void alignAddedStructures()
601 javax.swing.SwingUtilities.invokeLater(new Runnable()
606 if (jmb.viewer.isScriptExecuting())
608 SwingUtilities.invokeLater(this);
612 } catch (InterruptedException q)
619 alignStructs_withAllAlignPanels();
623 alignAddedStructures = false;
627 * Retrieves and saves as file any modelled PDB entries for which we do not
628 * already have a file saved. Returns a list of absolute paths to structure
629 * files which were either retrieved, or already stored but not modelled in
630 * the structure viewer (i.e. files to add to the viewer display).
634 List<String> fetchPdbFiles()
636 // todo - record which pdbids were successfully imported.
637 StringBuilder errormsgs = new StringBuilder();
639 List<String> files = new ArrayList<String>();
643 String[] filesInViewer = jmb.getPdbFile();
644 // TODO: replace with reference fetching/transfer code (validate PDBentry
646 Pdb pdbclient = new Pdb();
647 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
649 String file = jmb.getPdbEntry(pi).getFile();
652 // retrieve the pdb and store it locally
653 AlignmentI pdbseq = null;
654 pdbid = jmb.getPdbEntry(pi).getId();
655 long hdl = pdbid.hashCode() - System.currentTimeMillis();
656 if (progressBar != null)
658 progressBar.setProgressBar(MessageManager.formatMessage(
659 "status.fetching_pdb", new String[] { pdbid }), hdl);
663 pdbseq = pdbclient.getSequenceRecords(pdbid);
664 } catch (OutOfMemoryError oomerror)
666 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
667 } catch (Exception ex)
669 ex.printStackTrace();
670 errormsgs.append("'").append(pdbid).append("'");
673 if (progressBar != null)
675 progressBar.setProgressBar(
676 MessageManager.getString("label.state_completed"),
682 // just transfer the file name from the first sequence's first
684 file = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
685 .elementAt(0).getFile()).getAbsolutePath();
686 jmb.getPdbEntry(pi).setFile(file);
691 errormsgs.append("'").append(pdbid).append("' ");
696 if (filesInViewer != null && filesInViewer.length > 0)
698 addingStructures = true; // already files loaded.
699 for (int c = 0; c < filesInViewer.length; c++)
701 if (filesInViewer[c].equals(file))
714 } catch (OutOfMemoryError oomerror)
716 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
717 } catch (Exception ex)
719 ex.printStackTrace();
720 errormsgs.append("When retrieving pdbfiles : current was: '")
721 .append(pdbid).append("'");
723 if (errormsgs.length() > 0)
725 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
726 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
727 new String[] { errormsgs.toString() }),
728 MessageManager.getString("label.couldnt_load_file"),
729 JOptionPane.ERROR_MESSAGE);
735 public void pdbFile_actionPerformed(ActionEvent actionEvent)
737 JalviewFileChooser chooser = new JalviewFileChooser(
738 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
740 chooser.setFileView(new JalviewFileView());
741 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
742 chooser.setToolTipText(MessageManager.getString("action.save"));
744 int value = chooser.showSaveDialog(this);
746 if (value == JalviewFileChooser.APPROVE_OPTION)
748 BufferedReader in = null;
751 // TODO: cope with multiple PDB files in view
752 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
753 File outFile = chooser.getSelectedFile();
755 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
757 while ((data = in.readLine()) != null)
759 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
765 } catch (Exception ex)
767 ex.printStackTrace();
775 } catch (IOException e)
785 public void viewMapping_actionPerformed(ActionEvent actionEvent)
787 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
790 cap.appendText(jmb.printMappings());
791 } catch (OutOfMemoryError e)
794 "composing sequence-structure alignments for display in text box.",
799 jalview.gui.Desktop.addInternalFrame(cap,
800 MessageManager.getString("label.pdb_sequence_mapping"), 550,
805 public void eps_actionPerformed(ActionEvent e)
807 makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
811 public void png_actionPerformed(ActionEvent e)
813 makePDBImage(jalview.util.ImageMaker.TYPE.PNG);
816 void makePDBImage(jalview.util.ImageMaker.TYPE type)
818 int width = getWidth();
819 int height = getHeight();
821 jalview.util.ImageMaker im;
823 if (type == jalview.util.ImageMaker.TYPE.PNG)
825 im = new jalview.util.ImageMaker(this,
826 jalview.util.ImageMaker.TYPE.PNG, "Make PNG image from view",
827 width, height, null, null, null, 0, false);
829 else if (type == jalview.util.ImageMaker.TYPE.EPS)
831 im = new jalview.util.ImageMaker(this,
832 jalview.util.ImageMaker.TYPE.EPS, "Make EPS file from view",
833 width, height, null, this.getTitle(), null, 0, false);
838 im = new jalview.util.ImageMaker(this,
839 jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
840 width, height, null, this.getTitle(), null, 0, false);
843 if (im.getGraphics() != null)
845 jmb.viewer.renderScreenImage(im.getGraphics(), width, height);
851 public void viewerColour_actionPerformed(ActionEvent actionEvent)
853 if (viewerColour.isSelected())
855 // disable automatic sequence colouring.
856 jmb.setColourBySequence(false);
861 public void seqColour_actionPerformed(ActionEvent actionEvent)
863 jmb.setColourBySequence(seqColour.isSelected());
864 if (_colourwith == null)
866 _colourwith = new Vector<AlignmentPanel>();
868 if (jmb.isColourBySequence())
870 if (!jmb.isLoadingFromArchive())
872 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
874 // Make the currently displayed alignment panel the associated view
875 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
878 // Set the colour using the current view for the associated alignframe
879 for (AlignmentPanel ap : _colourwith)
881 jmb.colourBySequence(ap);
887 public void chainColour_actionPerformed(ActionEvent actionEvent)
889 chainColour.setSelected(true);
894 public void chargeColour_actionPerformed(ActionEvent actionEvent)
896 chargeColour.setSelected(true);
897 jmb.colourByCharge();
901 public void zappoColour_actionPerformed(ActionEvent actionEvent)
903 zappoColour.setSelected(true);
904 jmb.setJalviewColourScheme(new ZappoColourScheme());
908 public void taylorColour_actionPerformed(ActionEvent actionEvent)
910 taylorColour.setSelected(true);
911 jmb.setJalviewColourScheme(new TaylorColourScheme());
915 public void hydroColour_actionPerformed(ActionEvent actionEvent)
917 hydroColour.setSelected(true);
918 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
922 public void helixColour_actionPerformed(ActionEvent actionEvent)
924 helixColour.setSelected(true);
925 jmb.setJalviewColourScheme(new HelixColourScheme());
929 public void strandColour_actionPerformed(ActionEvent actionEvent)
931 strandColour.setSelected(true);
932 jmb.setJalviewColourScheme(new StrandColourScheme());
936 public void turnColour_actionPerformed(ActionEvent actionEvent)
938 turnColour.setSelected(true);
939 jmb.setJalviewColourScheme(new TurnColourScheme());
943 public void buriedColour_actionPerformed(ActionEvent actionEvent)
945 buriedColour.setSelected(true);
946 jmb.setJalviewColourScheme(new BuriedColourScheme());
950 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
952 setJalviewColourScheme(new PurinePyrimidineColourScheme());
956 public void userColour_actionPerformed(ActionEvent actionEvent)
958 userColour.setSelected(true);
959 new UserDefinedColours(this, null);
963 public void backGround_actionPerformed(ActionEvent actionEvent)
965 java.awt.Color col = JColorChooser
966 .showDialog(this, MessageManager
967 .getString("label.select_backgroud_colour"), null);
970 jmb.setBackgroundColour(col);
975 public void showHelp_actionPerformed(ActionEvent actionEvent)
979 jalview.util.BrowserLauncher
980 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
981 } catch (Exception ex)
986 public void showConsole(boolean showConsole)
991 if (splitPane == null)
993 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
994 splitPane.setTopComponent(renderPanel);
995 splitPane.setBottomComponent(scriptWindow);
996 this.getContentPane().add(splitPane, BorderLayout.CENTER);
997 splitPane.setDividerLocation(getHeight() - 200);
998 scriptWindow.setVisible(true);
999 scriptWindow.validate();
1000 splitPane.validate();
1006 if (splitPane != null)
1008 splitPane.setVisible(false);
1013 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1019 class RenderPanel extends JPanel
1021 final Dimension currentSize = new Dimension();
1024 public void paintComponent(Graphics g)
1026 getSize(currentSize);
1028 if (jmb != null && jmb.fileLoadingError != null)
1030 g.setColor(Color.black);
1031 g.fillRect(0, 0, currentSize.width, currentSize.height);
1032 g.setColor(Color.white);
1033 g.setFont(new Font("Verdana", Font.BOLD, 14));
1034 g.drawString(MessageManager.getString("label.error_loading_file")
1035 + "...", 20, currentSize.height / 2);
1036 StringBuffer sb = new StringBuffer();
1038 for (int e = 0; e < jmb.getPdbCount(); e++)
1040 sb.append(jmb.getPdbEntry(e).getId());
1041 if (e < jmb.getPdbCount() - 1)
1046 if (e == jmb.getPdbCount() - 1 || sb.length() > 20)
1049 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1050 * g.getFontMetrics().getHeight());
1054 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1056 g.setColor(Color.black);
1057 g.fillRect(0, 0, currentSize.width, currentSize.height);
1058 g.setColor(Color.white);
1059 g.setFont(new Font("Verdana", Font.BOLD, 14));
1060 g.drawString(MessageManager.getString("label.retrieving_pdb_data"),
1061 20, currentSize.height / 2);
1065 jmb.viewer.renderScreenImage(g, currentSize.width,
1066 currentSize.height);
1071 public void updateTitleAndMenus()
1073 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1078 setChainMenuItems(jmb.chainNames);
1080 this.setTitle(jmb.getViewerTitle());
1081 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1083 viewerActionMenu.setVisible(true);
1085 if (!jmb.isLoadingFromArchive())
1087 seqColour_actionPerformed(null);
1095 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1099 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1101 alignStructs_withAllAlignPanels();
1104 private void alignStructs_withAllAlignPanels()
1106 if (getAlignmentPanel() == null)
1111 if (_alignwith.size() == 0)
1113 _alignwith.add(getAlignmentPanel());
1118 AlignmentI[] als = new Alignment[_alignwith.size()];
1119 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1120 int[] alm = new int[_alignwith.size()];
1123 for (AlignmentPanel ap : _alignwith)
1125 als[a] = ap.av.getAlignment();
1127 alc[a++] = ap.av.getColumnSelection();
1129 jmb.superposeStructures(als, alm, alc);
1130 } catch (Exception e)
1132 StringBuffer sp = new StringBuffer();
1133 for (AlignmentPanel ap : _alignwith)
1135 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1137 Cache.log.info("Couldn't align structures with the " + sp.toString()
1138 + "associated alignment panels.", e);
1145 public void setJalviewColourScheme(ColourSchemeI ucs)
1147 jmb.setJalviewColourScheme(ucs);
1154 * @return first alignment panel displaying given alignment, or the default
1157 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1159 for (AlignmentPanel ap : getAllAlignmentPanels())
1161 if (ap.av.getAlignment() == alignment)
1166 return getAlignmentPanel();
1170 public AAStructureBindingModel getBinding()
1176 public String getStateInfo()
1178 return jmb == null ? null : jmb.viewer.getStateInfo();
1182 public ViewerType getViewerType()
1184 return ViewerType.JMOL;
1188 protected AAStructureBindingModel getBindingModel()