2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
23 import javax.swing.event.*;
25 import java.awt.event.*;
28 import jalview.jbgui.GStructureViewer;
29 import jalview.api.SequenceStructureBinding;
30 import jalview.bin.Cache;
31 import jalview.datamodel.*;
32 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
33 import jalview.structure.*;
34 import jalview.datamodel.PDBEntry;
36 import jalview.schemes.*;
38 public class AppJmol extends GStructureViewer implements Runnable,
39 SequenceStructureBinding, ViewSetProvider
48 RenderPanel renderPanel;
52 Vector atomsPicked = new Vector();
54 private boolean addingStructures = false;
64 * @deprecated defaults to AppJmol(String[] files, ... , viewid);
66 public AppJmol(String file, String id, SequenceI[] seq,
67 AlignmentPanel ap, String loadStatus, Rectangle bounds)
69 this(file, id, seq, ap, loadStatus, bounds, null);
75 public AppJmol(String file, String id, SequenceI[] seq,
76 AlignmentPanel ap, String loadStatus, Rectangle bounds,
80 { file }, new String[]
81 { id }, new SequenceI[][]
82 { seq }, ap, true,true, loadStatus, bounds, viewid);
85 ViewSelectionMenu seqColourBy;
93 * @param usetoColour - add the alignment panel to the list used for colouring these structures
94 * @param useToAlign - add the alignment panel to the list used for aligning these structures
99 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
100 AlignmentPanel ap, boolean usetoColour,boolean useToAlign, String loadStatus, Rectangle bounds,
103 PDBEntry[] pdbentrys = new PDBEntry[files.length];
104 for (int i = 0; i < pdbentrys.length; i++)
106 PDBEntry pdbentry = new PDBEntry();
107 pdbentry.setFile(files[i]);
108 pdbentry.setId(ids[i]);
109 pdbentrys[i] = pdbentry;
111 // / TODO: check if protocol is needed to be set, and if chains are
113 jmb = new AppJmolBinding(this, pdbentrys, seqs, null, null);
115 jmb.setLoadingFromArchive(true);
116 addAlignmentPanel(ap);
119 useAlignmentPanelForSuperposition(ap);
123 useAlignmentPanelForColourbyseq(ap);
125 this.setBounds(bounds);
126 jmb.setColourBySequence(false);
127 seqColour.setSelected(false);
130 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
131 // bounds.width,bounds.height);
133 this.addInternalFrameListener(new InternalFrameAdapter()
135 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
140 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
143 private void initMenus() {
144 seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith,
149 public void itemStateChanged(ItemEvent e)
151 if (!seqColour.isSelected())
157 // update the jmol display now.
158 seqColour_actionPerformed(null);
162 viewMenu.add(seqColourBy);
163 final ItemListener handler;
164 JMenu alpanels = new ViewSelectionMenu("Superpose with ..", this,
165 _alignwith, handler=new ItemListener()
169 public void itemStateChanged(ItemEvent e)
171 alignStructs.setEnabled(_alignwith.size() > 0);
172 alignStructs.setToolTipText("Align structures using "
173 + _alignwith.size() + " linked alignment views");
176 handler.itemStateChanged(null);
177 jmolActionMenu.add(alpanels);
178 jmolActionMenu.addMenuListener(new MenuListener()
182 public void menuSelected(MenuEvent e)
184 handler.itemStateChanged(null);
188 public void menuDeselected(MenuEvent e)
190 // TODO Auto-generated method stub
195 public void menuCanceled(MenuEvent e)
197 // TODO Auto-generated method stub
203 IProgressIndicator progressBar = null;
205 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
208 progressBar = ap.alignFrame;
209 // ////////////////////////////////
210 // Is the pdb file already loaded?
211 String alreadyMapped = StructureSelectionManager
212 .getStructureSelectionManager().alreadyMappedToFile(
215 if (alreadyMapped != null)
217 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
218 pdbentry.getId() + " is already displayed."
219 + "\nDo you want to re-use this viewer ?",
220 "Map Sequences to Visible Window: " + pdbentry.getId(),
221 JOptionPane.YES_NO_OPTION);
223 if (option == JOptionPane.YES_OPTION)
225 StructureSelectionManager.getStructureSelectionManager()
226 .setMapping(seq, chains, alreadyMapped,
227 AppletFormatAdapter.FILE);
228 if (ap.seqPanel.seqCanvas.fr != null)
230 ap.seqPanel.seqCanvas.fr.featuresAdded();
231 ap.paintAlignment(true);
234 // Now this AppJmol is mapped to new sequences. We must add them to
235 // the exisiting array
236 JInternalFrame[] frames = Desktop.instance.getAllFrames();
238 for (int i = 0; i < frames.length; i++)
240 if (frames[i] instanceof AppJmol)
242 AppJmol topJmol = ((AppJmol) frames[i]);
243 // JBPNOTE: this looks like a binding routine, rather than a gui
245 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
247 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
249 topJmol.jmb.addSequence(pe, seq);
250 topJmol.addAlignmentPanel(ap);
251 topJmol.buildJmolActionMenu();
261 // /////////////////////////////////
262 // Check if there are other Jmol views involving this alignment
263 // and prompt user about adding this molecule to one of them
264 Vector existingViews = getJmolsFor(ap);
265 if (existingViews.size() > 0)
267 Enumeration jm = existingViews.elements();
268 while (jm.hasMoreElements())
270 AppJmol topJmol = (AppJmol) jm.nextElement();
271 // TODO: highlight topJmol in view somehow
272 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
273 "Do you want to add " + pdbentry.getId()
274 + " to the view called\n'" + topJmol.getTitle()
275 + "'\n", "Align to existing structure view",
276 JOptionPane.YES_NO_OPTION);
277 if (option == JOptionPane.YES_OPTION)
279 topJmol.useAlignmentPanelForSuperposition(ap);
280 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
285 // /////////////////////////////////
287 jmb = new AppJmolBinding(this, new PDBEntry[]
288 { pdbentry }, new SequenceI[][]
289 { seq }, null, null);
290 addAlignmentPanel(ap);
291 setSize(400, 400); // probably should be a configurable/dynamic default here
294 if (pdbentry.getFile() != null)
296 initJmol("load \"" + pdbentry.getFile() + "\"");
300 addingStructures = false;
301 worker = new Thread(this);
305 this.addInternalFrameListener(new InternalFrameAdapter()
307 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
316 * list of sequenceSet ids associated with the view
318 ArrayList<String> _aps = new ArrayList();
320 public AlignmentPanel[] getAllAlignmentPanels()
322 AlignmentPanel[] t, list = new AlignmentPanel[0];
323 for (String setid : _aps)
325 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
328 t = new AlignmentPanel[list.length + panels.length];
329 System.arraycopy(list, 0, t, 0, list.length);
330 System.arraycopy(panels, 0, t, list.length, panels.length);
339 * list of alignment panels to use for superposition
341 ArrayList<AlignmentPanel> _alignwith = new ArrayList();
344 * list of alignment panels that are used for colouring structures by aligned
347 ArrayList<AlignmentPanel> _colourwith = new ArrayList();
350 * set the primary alignmentPanel reference and add another alignPanel to the
351 * list of ones to use for colouring and aligning
355 public void addAlignmentPanel(AlignmentPanel nap)
361 if (!_aps.contains(nap.av.getSequenceSetId()))
363 _aps.add(nap.av.getSequenceSetId());
368 * remove any references held to the given alignment panel
372 public void removeAlignmentPanel(AlignmentPanel nap)
376 _alignwith.remove(nap);
377 _colourwith.remove(nap);
381 for (AlignmentPanel aps : getAllAlignmentPanels())
390 } catch (Exception ex)
395 buildJmolActionMenu();
399 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
401 addAlignmentPanel(nap);
402 if (!_alignwith.contains(nap))
408 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
410 if (_alignwith.contains(nap))
412 _alignwith.remove(nap);
416 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
418 addAlignmentPanel(nap);
419 if (!_colourwith.contains(nap))
421 _colourwith.add(nap);
425 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
427 if (_colourwith.contains(nap))
429 _colourwith.remove(nap);
434 * pdb retrieval thread.
436 private Thread worker = null;
439 * add a new structure (with associated sequences and chains) to this viewer,
440 * retrieving it if necessary first.
447 * if true, new structure(s) will be align using associated alignment
449 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
450 final String[] chains, final boolean b,
451 final IProgressIndicator alignFrame)
453 if (pdbentry.getFile() == null)
455 if (worker != null && worker.isAlive())
457 // a retrieval is in progress, wait around and add ourselves to the
459 new Thread(new Runnable()
463 while (worker != null && worker.isAlive() && _started)
467 Thread.sleep(100 + ((int) Math.random() * 100));
469 } catch (Exception e)
474 // and call ourselves again.
475 addStructure(pdbentry, seq, chains, b, alignFrame);
481 // otherwise, start adding the structure.
482 jmb.addSequenceAndChain(new PDBEntry[]
483 { pdbentry }, new SequenceI[][]
484 { seq }, new String[][]
486 addingStructures = true;
488 alignAddedStructures = b;
489 progressBar = alignFrame; // visual indication happens on caller frame.
490 (worker = new Thread(this)).start();
494 private Vector getJmolsFor(AlignmentPanel ap2)
496 Vector otherJmols = new Vector();
497 // Now this AppJmol is mapped to new sequences. We must add them to
498 // the exisiting array
499 JInternalFrame[] frames = Desktop.instance.getAllFrames();
501 for (int i = 0; i < frames.length; i++)
503 if (frames[i] instanceof AppJmol)
505 AppJmol topJmol = ((AppJmol) frames[i]);
506 if (topJmol.isLinkedWith(ap2))
508 otherJmols.addElement(topJmol);
515 void initJmol(String command)
517 jmb.setFinishedInit(false);
518 renderPanel = new RenderPanel();
519 // TODO: consider waiting until the structure/view is fully loaded before
521 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
522 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
523 getBounds().width, getBounds().height);
524 if (scriptWindow == null)
526 BorderLayout bl = new BorderLayout();
529 scriptWindow = new JPanel(bl);
530 scriptWindow.setVisible(false);
533 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
535 jmb.newJmolPopup(true, "Jmol", true);
536 jmb.evalStateCommand(command);
537 jmb.setFinishedInit(true);
540 void setChainMenuItems(Vector chains)
542 chainMenu.removeAll();
547 JMenuItem menuItem = new JMenuItem("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)
556 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
559 allChainsSelected = false;
563 chainMenu.add(menuItem);
565 for (int c = 0; c < chains.size(); c++)
567 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
568 menuItem.addItemListener(new ItemListener()
570 public void itemStateChanged(ItemEvent evt)
572 if (!allChainsSelected)
577 chainMenu.add(menuItem);
581 boolean allChainsSelected = false;
583 private boolean alignAddedStructures = false;
587 Vector toshow = new Vector();
589 int mlength, p, mnum;
590 for (int i = 0; i < chainMenu.getItemCount(); i++)
592 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
594 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
595 if (item.isSelected())
597 toshow.addElement(item.getText());
601 jmb.centerViewer(toshow);
611 // TODO: check for memory leaks where instance isn't finalised because jmb
612 // holds a reference to the window
617 * state flag for PDB retrieval thread
619 private boolean _started = false;
625 // todo - record which pdbids were successfuly imported.
626 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
629 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
630 // TODO: replace with reference fetching/transfer code (validate PDBentry
632 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
633 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
635 String file = jmb.pdbentry[pi].getFile();
638 // retrieve the pdb and store it locally
639 AlignmentI pdbseq = null;
640 pdbid = jmb.pdbentry[pi].getId();
641 long hdl = pdbid.hashCode() - System.currentTimeMillis();
642 if (progressBar != null)
644 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
648 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
650 } catch (OutOfMemoryError oomerror)
652 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
653 } catch (Exception ex)
655 ex.printStackTrace();
656 errormsgs.append("'" + pdbid + "'");
658 if (progressBar != null)
660 progressBar.setProgressBar("Finished.", hdl);
664 // just transfer the file name from the first sequence's first
666 jmb.pdbentry[pi].setFile(file = ((PDBEntry) pdbseq
667 .getSequenceAt(0).getPDBId().elementAt(0)).getFile());
668 files.append(" \"" + file + "\"");
672 errormsgs.append("'" + pdbid + "' ");
677 if (curfiles != null && curfiles.length > 0)
679 addingStructures = true; // already files loaded.
680 for (int c = 0; c < curfiles.length; c++)
682 if (curfiles[c].equals(file))
691 files.append(" \"" + file + "\"");
695 } catch (OutOfMemoryError oomerror)
697 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
698 } catch (Exception ex)
700 ex.printStackTrace();
701 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
704 if (errormsgs.length() > 0)
707 JOptionPane.showInternalMessageDialog(Desktop.desktop,
708 "The following pdb entries could not be retrieved from the PDB:\n"
709 + errormsgs.toString()
710 + "\nPlease try downloading them manually.",
711 "Couldn't load file", JOptionPane.ERROR_MESSAGE);
714 if (files.length() > 0)
716 if (!addingStructures)
721 initJmol("load FILES " + files.toString());
722 } catch (OutOfMemoryError oomerror)
724 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
725 Cache.log.debug("File locations are " + files);
726 } catch (Exception ex)
728 Cache.log.error("Couldn't open Jmol viewer!", ex);
733 StringBuffer cmd = new StringBuffer();
734 cmd.append("loadingJalviewdata=true\nload APPEND ");
735 cmd.append(files.toString());
736 cmd.append("\nloadingJalviewdata=null");
737 final String command = cmd.toString();
739 long lastnotify = jmb.getLoadNotifiesHandled();
742 jmb.evalStateCommand(command);
743 } catch (OutOfMemoryError oomerror)
746 "When trying to add structures to the Jmol viewer!",
748 Cache.log.debug("File locations are " + files);
749 } catch (Exception ex)
751 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
753 // need to wait around until script has finished
754 while (lastnotify >= jmb.getLoadNotifiesHandled())
760 } catch (Exception e)
764 // refresh the sequence colours for the new structure(s)
765 for (AlignmentPanel ap : _colourwith)
767 jmb.updateColours(ap);
769 // do superposition if asked to
770 if (alignAddedStructures)
772 javax.swing.SwingUtilities.invokeLater(new Runnable()
776 alignStructs_withAllAlignPanels();
777 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
780 alignAddedStructures = false;
782 addingStructures = false;
789 public void pdbFile_actionPerformed(ActionEvent actionEvent)
791 JalviewFileChooser chooser = new JalviewFileChooser(
792 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
794 chooser.setFileView(new JalviewFileView());
795 chooser.setDialogTitle("Save PDB File");
796 chooser.setToolTipText("Save");
798 int value = chooser.showSaveDialog(this);
800 if (value == JalviewFileChooser.APPROVE_OPTION)
804 // TODO: cope with multiple PDB files in view
805 BufferedReader in = new BufferedReader(new FileReader(
806 jmb.getPdbFile()[0]));
807 File outFile = chooser.getSelectedFile();
809 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
811 while ((data = in.readLine()) != null)
813 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
819 } catch (Exception ex)
821 ex.printStackTrace();
826 public void viewMapping_actionPerformed(ActionEvent actionEvent)
828 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
831 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
833 cap.appendText(StructureSelectionManager
834 .getStructureSelectionManager().printMapping(
835 jmb.pdbentry[pdbe].getFile()));
836 cap.appendText("\n");
838 } catch (OutOfMemoryError e)
841 "composing sequence-structure alignments for display in text box.",
846 jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
856 public void eps_actionPerformed(ActionEvent e)
858 makePDBImage(jalview.util.ImageMaker.EPS);
867 public void png_actionPerformed(ActionEvent e)
869 makePDBImage(jalview.util.ImageMaker.PNG);
872 void makePDBImage(int type)
874 int width = getWidth();
875 int height = getHeight();
877 jalview.util.ImageMaker im;
879 if (type == jalview.util.ImageMaker.PNG)
881 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
882 "Make PNG image from view", width, height, null, null);
886 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
887 "Make EPS file from view", width, height, null,
891 if (im.getGraphics() != null)
893 Rectangle rect = new Rectangle(width, height);
894 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
899 public void seqColour_actionPerformed(ActionEvent actionEvent)
901 jmb.setColourBySequence(seqColour.isSelected());
902 if (_colourwith==null) { _colourwith=new ArrayList<AlignmentPanel>();};
903 if (_colourwith.size()==0){ _colourwith.add(ap); };
905 // Set the colour using the current view for the associated alignframe
906 for (AlignmentPanel ap : _colourwith)
908 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
912 public void chainColour_actionPerformed(ActionEvent actionEvent)
914 chainColour.setSelected(true);
918 public void chargeColour_actionPerformed(ActionEvent actionEvent)
920 chargeColour.setSelected(true);
921 jmb.colourByCharge();
924 public void zappoColour_actionPerformed(ActionEvent actionEvent)
926 zappoColour.setSelected(true);
927 jmb.setJalviewColourScheme(new ZappoColourScheme());
930 public void taylorColour_actionPerformed(ActionEvent actionEvent)
932 taylorColour.setSelected(true);
933 jmb.setJalviewColourScheme(new TaylorColourScheme());
936 public void hydroColour_actionPerformed(ActionEvent actionEvent)
938 hydroColour.setSelected(true);
939 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
942 public void helixColour_actionPerformed(ActionEvent actionEvent)
944 helixColour.setSelected(true);
945 jmb.setJalviewColourScheme(new HelixColourScheme());
948 public void strandColour_actionPerformed(ActionEvent actionEvent)
950 strandColour.setSelected(true);
951 jmb.setJalviewColourScheme(new StrandColourScheme());
954 public void turnColour_actionPerformed(ActionEvent actionEvent)
956 turnColour.setSelected(true);
957 jmb.setJalviewColourScheme(new TurnColourScheme());
960 public void buriedColour_actionPerformed(ActionEvent actionEvent)
962 buriedColour.setSelected(true);
963 jmb.setJalviewColourScheme(new BuriedColourScheme());
966 public void userColour_actionPerformed(ActionEvent actionEvent)
968 userColour.setSelected(true);
969 new UserDefinedColours(this, null);
972 public void backGround_actionPerformed(ActionEvent actionEvent)
974 java.awt.Color col = JColorChooser.showDialog(this,
975 "Select Background Colour", null);
978 jmb.setBackgroundColour(col);
982 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
986 jalview.util.BrowserLauncher
987 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
988 } catch (Exception ex)
993 public void showConsole(boolean showConsole)
998 if (splitPane == null)
1000 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1001 splitPane.setTopComponent(renderPanel);
1002 splitPane.setBottomComponent(scriptWindow);
1003 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1004 splitPane.setDividerLocation(getHeight() - 200);
1005 scriptWindow.setVisible(true);
1006 scriptWindow.validate();
1007 splitPane.validate();
1013 if (splitPane != null)
1015 splitPane.setVisible(false);
1020 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1026 class RenderPanel extends JPanel
1028 final Dimension currentSize = new Dimension();
1030 final Rectangle rectClip = new Rectangle();
1032 public void paintComponent(Graphics g)
1034 getSize(currentSize);
1035 g.getClipBounds(rectClip);
1037 if (jmb.fileLoadingError != null)
1039 g.setColor(Color.black);
1040 g.fillRect(0, 0, currentSize.width, currentSize.height);
1041 g.setColor(Color.white);
1042 g.setFont(new Font("Verdana", Font.BOLD, 14));
1043 g.drawString("Error loading file...", 20, currentSize.height / 2);
1044 StringBuffer sb = new StringBuffer();
1046 for (int e = 0; e < jmb.pdbentry.length; e++)
1048 sb.append(jmb.pdbentry[e].getId());
1049 if (e < jmb.pdbentry.length - 1)
1054 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1057 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1058 * g.getFontMetrics().getHeight());
1062 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1064 g.setColor(Color.black);
1065 g.fillRect(0, 0, currentSize.width, currentSize.height);
1066 g.setColor(Color.white);
1067 g.setFont(new Font("Verdana", Font.BOLD, 14));
1068 g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
1072 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1077 String viewId = null;
1079 public String getViewId()
1083 viewId = System.currentTimeMillis() + "." + this.hashCode();
1088 public void updateTitleAndMenus()
1090 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1095 setChainMenuItems(jmb.chainNames);
1097 this.setTitle(jmb.getViewerTitle());
1098 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1100 jmolActionMenu.setVisible(true);
1102 if (!jmb.isLoadingFromArchive()) {
1103 seqColour_actionPerformed(null);
1107 protected void buildJmolActionMenu()
1109 if (_alignwith==null) { _alignwith=new ArrayList<AlignmentPanel>();}
1110 if (_alignwith.size()==0 && ap!=null) { _alignwith.add(ap);};
1111 for (Component c : jmolActionMenu.getMenuComponents())
1113 if (c != alignStructs)
1115 jmolActionMenu.remove((JMenuItem) c);
1118 final ItemListener handler;
1125 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1129 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1131 alignStructs_withAllAlignPanels();
1134 private void alignStructs_withAllAlignPanels()
1136 if (ap==null) { return; };
1137 if (_alignwith.size()==0) { _alignwith.add(ap);};
1140 AlignmentI[] als = new Alignment[_alignwith.size()];
1141 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1142 int[] alm = new int[_alignwith.size()];
1145 for (AlignmentPanel ap : _alignwith)
1147 als[a] = ap.av.getAlignment();
1149 alc[a++] = ap.av.getColumnSelection();
1151 jmb.superposeStructures(als, alm, alc);
1152 } catch (Exception e)
1154 StringBuffer sp = new StringBuffer();
1155 for (AlignmentPanel ap : _alignwith)
1157 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1159 Cache.log.info("Couldn't align structures with the " + sp.toString()
1160 + "associated alignment panels.", e);
1166 public void setJalviewColourScheme(ColourSchemeI ucs)
1168 jmb.setJalviewColourScheme(ucs);
1175 * @return first alignment panel displaying given alignment, or the default
1178 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1180 for (AlignmentPanel ap : getAllAlignmentPanels())
1182 if (ap.av.getAlignment() == alignment)
1193 * @return true if this Jmol instance is linked with the given alignPanel
1195 public boolean isLinkedWith(AlignmentPanel ap2)
1197 return _aps.contains(ap2.av.getSequenceSetId());
1200 public boolean isUsedforaligment(AlignmentPanel ap2)
1203 return (_alignwith != null) && _alignwith.contains(ap2);
1206 public boolean isUsedforcolourby(AlignmentPanel ap2)
1208 return (_colourwith != null) && _colourwith.contains(ap2);