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;
94 * - add the alignment panel to the list used for colouring these
97 * - add the alignment panel to the list used for aligning these
103 public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
104 AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
105 String loadStatus, Rectangle bounds, String viewid)
107 PDBEntry[] pdbentrys = new PDBEntry[files.length];
108 for (int i = 0; i < pdbentrys.length; i++)
110 PDBEntry pdbentry = new PDBEntry();
111 pdbentry.setFile(files[i]);
112 pdbentry.setId(ids[i]);
113 pdbentrys[i] = pdbentry;
115 // / TODO: check if protocol is needed to be set, and if chains are
117 jmb = new AppJmolBinding(this, pdbentrys, seqs, null, null);
119 jmb.setLoadingFromArchive(true);
120 addAlignmentPanel(ap);
123 useAlignmentPanelForSuperposition(ap);
127 useAlignmentPanelForColourbyseq(ap);
128 jmb.setColourBySequence(true);
129 seqColour.setSelected(true);
131 jmb.setColourBySequence(false);
132 seqColour.setSelected(false);
133 jmolColour.setSelected(true);
135 this.setBounds(bounds);
138 // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
139 // bounds.width,bounds.height);
141 this.addInternalFrameListener(new InternalFrameAdapter()
143 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
148 initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
152 private void initMenus()
154 seqColour.setSelected(jmb.isColourBySequence());
155 jmolColour.setSelected(!jmb.isColourBySequence());
156 if (_colourwith==null)
158 _colourwith=new Vector<AlignmentPanel>();
160 if (_alignwith==null)
162 _alignwith=new Vector<AlignmentPanel>();
165 seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith,
170 public void itemStateChanged(ItemEvent e)
172 if (!seqColour.isSelected())
178 // update the jmol display now.
179 seqColour_actionPerformed(null);
183 viewMenu.add(seqColourBy);
184 final ItemListener handler;
185 JMenu alpanels = new ViewSelectionMenu("Superpose with ..", this,
186 _alignwith, handler = new ItemListener()
190 public void itemStateChanged(ItemEvent e)
192 alignStructs.setEnabled(_alignwith.size() > 0);
193 alignStructs.setToolTipText("Align structures using "
194 + _alignwith.size() + " linked alignment views");
197 handler.itemStateChanged(null);
198 jmolActionMenu.add(alpanels);
199 jmolActionMenu.addMenuListener(new MenuListener()
203 public void menuSelected(MenuEvent e)
205 handler.itemStateChanged(null);
209 public void menuDeselected(MenuEvent e)
211 // TODO Auto-generated method stub
216 public void menuCanceled(MenuEvent e)
218 // TODO Auto-generated method stub
223 IProgressIndicator progressBar = null;
225 public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
228 progressBar = ap.alignFrame;
229 // ////////////////////////////////
230 // Is the pdb file already loaded?
231 String alreadyMapped = StructureSelectionManager
232 .getStructureSelectionManager().alreadyMappedToFile(
235 if (alreadyMapped != null)
237 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
238 pdbentry.getId() + " is already displayed."
239 + "\nDo you want to re-use this viewer ?",
240 "Map Sequences to Visible Window: " + pdbentry.getId(),
241 JOptionPane.YES_NO_OPTION);
243 if (option == JOptionPane.YES_OPTION)
245 StructureSelectionManager.getStructureSelectionManager()
246 .setMapping(seq, chains, alreadyMapped,
247 AppletFormatAdapter.FILE);
248 if (ap.seqPanel.seqCanvas.fr != null)
250 ap.seqPanel.seqCanvas.fr.featuresAdded();
251 ap.paintAlignment(true);
254 // Now this AppJmol is mapped to new sequences. We must add them to
255 // the exisiting array
256 JInternalFrame[] frames = Desktop.instance.getAllFrames();
258 for (int i = 0; i < frames.length; i++)
260 if (frames[i] instanceof AppJmol)
262 AppJmol topJmol = ((AppJmol) frames[i]);
263 // JBPNOTE: this looks like a binding routine, rather than a gui
265 for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
267 if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
269 topJmol.jmb.addSequence(pe, seq);
270 topJmol.addAlignmentPanel(ap);
271 topJmol.buildJmolActionMenu();
281 // /////////////////////////////////
282 // Check if there are other Jmol views involving this alignment
283 // and prompt user about adding this molecule to one of them
284 Vector existingViews = getJmolsFor(ap);
285 if (existingViews.size() > 0)
287 Enumeration jm = existingViews.elements();
288 while (jm.hasMoreElements())
290 AppJmol topJmol = (AppJmol) jm.nextElement();
291 // TODO: highlight topJmol in view somehow
292 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
293 "Do you want to add " + pdbentry.getId()
294 + " to the view called\n'" + topJmol.getTitle()
295 + "'\n", "Align to existing structure view",
296 JOptionPane.YES_NO_OPTION);
297 if (option == JOptionPane.YES_OPTION)
299 topJmol.useAlignmentPanelForSuperposition(ap);
300 topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
305 // /////////////////////////////////
307 jmb = new AppJmolBinding(this, new PDBEntry[]
308 { pdbentry }, new SequenceI[][]
309 { seq }, null, null);
310 addAlignmentPanel(ap);
311 useAlignmentPanelForColourbyseq(ap);
312 jmb.setColourBySequence(true);
313 setSize(400, 400); // probably should be a configurable/dynamic default here
316 if (pdbentry.getFile() != null)
318 initJmol("load \"" + pdbentry.getFile() + "\"");
322 addingStructures = false;
323 worker = new Thread(this);
327 this.addInternalFrameListener(new InternalFrameAdapter()
329 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
338 * list of sequenceSet ids associated with the view
340 ArrayList<String> _aps = new ArrayList();
342 public AlignmentPanel[] getAllAlignmentPanels()
344 AlignmentPanel[] t, list = new AlignmentPanel[0];
345 for (String setid : _aps)
347 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
350 t = new AlignmentPanel[list.length + panels.length];
351 System.arraycopy(list, 0, t, 0, list.length);
352 System.arraycopy(panels, 0, t, list.length, panels.length);
361 * list of alignment panels to use for superposition
363 Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
366 * list of alignment panels that are used for colouring structures by aligned
369 Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
372 * set the primary alignmentPanel reference and add another alignPanel to the
373 * list of ones to use for colouring and aligning
377 public void addAlignmentPanel(AlignmentPanel nap)
383 if (!_aps.contains(nap.av.getSequenceSetId()))
385 _aps.add(nap.av.getSequenceSetId());
390 * remove any references held to the given alignment panel
394 public void removeAlignmentPanel(AlignmentPanel nap)
398 _alignwith.remove(nap);
399 _colourwith.remove(nap);
403 for (AlignmentPanel aps : getAllAlignmentPanels())
412 } catch (Exception ex)
417 buildJmolActionMenu();
421 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
423 addAlignmentPanel(nap);
424 if (!_alignwith.contains(nap))
430 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
432 if (_alignwith.contains(nap))
434 _alignwith.remove(nap);
438 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
440 addAlignmentPanel(nap);
441 if (!_colourwith.contains(nap))
443 _colourwith.add(nap);
447 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
449 if (_colourwith.contains(nap))
451 _colourwith.remove(nap);
456 * pdb retrieval thread.
458 private Thread worker = null;
461 * add a new structure (with associated sequences and chains) to this viewer,
462 * retrieving it if necessary first.
469 * if true, new structure(s) will be align using associated alignment
471 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
472 final String[] chains, final boolean b,
473 final IProgressIndicator alignFrame)
475 if (pdbentry.getFile() == null)
477 if (worker != null && worker.isAlive())
479 // a retrieval is in progress, wait around and add ourselves to the
481 new Thread(new Runnable()
485 while (worker != null && worker.isAlive() && _started)
489 Thread.sleep(100 + ((int) Math.random() * 100));
491 } catch (Exception e)
496 // and call ourselves again.
497 addStructure(pdbentry, seq, chains, b, alignFrame);
503 // otherwise, start adding the structure.
504 jmb.addSequenceAndChain(new PDBEntry[]
505 { pdbentry }, new SequenceI[][]
506 { seq }, new String[][]
508 addingStructures = true;
510 alignAddedStructures = b;
511 progressBar = alignFrame; // visual indication happens on caller frame.
512 (worker = new Thread(this)).start();
516 private Vector getJmolsFor(AlignmentPanel ap2)
518 Vector otherJmols = new Vector();
519 // Now this AppJmol is mapped to new sequences. We must add them to
520 // the exisiting array
521 JInternalFrame[] frames = Desktop.instance.getAllFrames();
523 for (int i = 0; i < frames.length; i++)
525 if (frames[i] instanceof AppJmol)
527 AppJmol topJmol = ((AppJmol) frames[i]);
528 if (topJmol.isLinkedWith(ap2))
530 otherJmols.addElement(topJmol);
537 void initJmol(String command)
539 jmb.setFinishedInit(false);
540 renderPanel = new RenderPanel();
541 // TODO: consider waiting until the structure/view is fully loaded before
543 this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
544 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
545 getBounds().width, getBounds().height);
546 if (scriptWindow == null)
548 BorderLayout bl = new BorderLayout();
551 scriptWindow = new JPanel(bl);
552 scriptWindow.setVisible(false);
555 jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
557 jmb.newJmolPopup(true, "Jmol", true);
562 jmb.evalStateCommand(command);
563 jmb.setFinishedInit(true);
566 void setChainMenuItems(Vector chains)
568 chainMenu.removeAll();
573 JMenuItem menuItem = new JMenuItem("All");
574 menuItem.addActionListener(new ActionListener()
576 public void actionPerformed(ActionEvent evt)
578 allChainsSelected = true;
579 for (int i = 0; i < chainMenu.getItemCount(); i++)
581 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
582 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
585 allChainsSelected = false;
589 chainMenu.add(menuItem);
591 for (int c = 0; c < chains.size(); c++)
593 menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
594 menuItem.addItemListener(new ItemListener()
596 public void itemStateChanged(ItemEvent evt)
598 if (!allChainsSelected)
603 chainMenu.add(menuItem);
607 boolean allChainsSelected = false;
609 private boolean alignAddedStructures = false;
613 Vector toshow = new Vector();
615 int mlength, p, mnum;
616 for (int i = 0; i < chainMenu.getItemCount(); i++)
618 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
620 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
621 if (item.isSelected())
623 toshow.addElement(item.getText());
627 jmb.centerViewer(toshow);
637 // TODO: check for memory leaks where instance isn't finalised because jmb
638 // holds a reference to the window
643 * state flag for PDB retrieval thread
645 private boolean _started = false;
651 // todo - record which pdbids were successfuly imported.
652 StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
655 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
656 // TODO: replace with reference fetching/transfer code (validate PDBentry
658 jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
659 for (int pi = 0; pi < jmb.pdbentry.length; pi++)
661 String file = jmb.pdbentry[pi].getFile();
664 // retrieve the pdb and store it locally
665 AlignmentI pdbseq = null;
666 pdbid = jmb.pdbentry[pi].getId();
667 long hdl = pdbid.hashCode() - System.currentTimeMillis();
668 if (progressBar != null)
670 progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
674 pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
676 } catch (OutOfMemoryError oomerror)
678 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
679 } catch (Exception ex)
681 ex.printStackTrace();
682 errormsgs.append("'" + pdbid + "'");
684 if (progressBar != null)
686 progressBar.setProgressBar("Finished.", hdl);
690 // just transfer the file name from the first sequence's first
692 jmb.pdbentry[pi].setFile(file = ((PDBEntry) pdbseq
693 .getSequenceAt(0).getPDBId().elementAt(0)).getFile());
694 files.append(" \"" + file + "\"");
698 errormsgs.append("'" + pdbid + "' ");
703 if (curfiles != null && curfiles.length > 0)
705 addingStructures = true; // already files loaded.
706 for (int c = 0; c < curfiles.length; c++)
708 if (curfiles[c].equals(file))
717 files.append(" \"" + file + "\"");
721 } catch (OutOfMemoryError oomerror)
723 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
724 } catch (Exception ex)
726 ex.printStackTrace();
727 errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
730 if (errormsgs.length() > 0)
733 JOptionPane.showInternalMessageDialog(Desktop.desktop,
734 "The following pdb entries could not be retrieved from the PDB:\n"
735 + errormsgs.toString()
736 + "\nPlease try downloading them manually.",
737 "Couldn't load file", JOptionPane.ERROR_MESSAGE);
740 if (files.length() > 0)
742 if (!addingStructures)
747 initJmol("load FILES " + files.toString());
748 } catch (OutOfMemoryError oomerror)
750 new OOMWarning("When trying to open the Jmol viewer!", oomerror);
751 Cache.log.debug("File locations are " + files);
752 } catch (Exception ex)
754 Cache.log.error("Couldn't open Jmol viewer!", ex);
759 StringBuffer cmd = new StringBuffer();
760 cmd.append("loadingJalviewdata=true\nload APPEND ");
761 cmd.append(files.toString());
762 cmd.append("\nloadingJalviewdata=null");
763 final String command = cmd.toString();
765 long lastnotify = jmb.getLoadNotifiesHandled();
768 jmb.evalStateCommand(command);
769 } catch (OutOfMemoryError oomerror)
772 "When trying to add structures to the Jmol viewer!",
774 Cache.log.debug("File locations are " + files);
775 } catch (Exception ex)
777 Cache.log.error("Couldn't add files to Jmol viewer!", ex);
779 // need to wait around until script has finished
780 while (lastnotify >= jmb.getLoadNotifiesHandled())
786 } catch (Exception e)
790 // refresh the sequence colours for the new structure(s)
791 for (AlignmentPanel ap : _colourwith)
793 jmb.updateColours(ap);
795 // do superposition if asked to
796 if (alignAddedStructures)
798 javax.swing.SwingUtilities.invokeLater(new Runnable()
802 alignStructs_withAllAlignPanels();
803 // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
806 alignAddedStructures = false;
808 addingStructures = false;
815 public void pdbFile_actionPerformed(ActionEvent actionEvent)
817 JalviewFileChooser chooser = new JalviewFileChooser(
818 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
820 chooser.setFileView(new JalviewFileView());
821 chooser.setDialogTitle("Save PDB File");
822 chooser.setToolTipText("Save");
824 int value = chooser.showSaveDialog(this);
826 if (value == JalviewFileChooser.APPROVE_OPTION)
830 // TODO: cope with multiple PDB files in view
831 BufferedReader in = new BufferedReader(new FileReader(
832 jmb.getPdbFile()[0]));
833 File outFile = chooser.getSelectedFile();
835 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
837 while ((data = in.readLine()) != null)
839 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
845 } catch (Exception ex)
847 ex.printStackTrace();
852 public void viewMapping_actionPerformed(ActionEvent actionEvent)
854 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
857 for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
859 cap.appendText(StructureSelectionManager
860 .getStructureSelectionManager().printMapping(
861 jmb.pdbentry[pdbe].getFile()));
862 cap.appendText("\n");
864 } catch (OutOfMemoryError e)
867 "composing sequence-structure alignments for display in text box.",
872 jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
882 public void eps_actionPerformed(ActionEvent e)
884 makePDBImage(jalview.util.ImageMaker.EPS);
893 public void png_actionPerformed(ActionEvent e)
895 makePDBImage(jalview.util.ImageMaker.PNG);
898 void makePDBImage(int type)
900 int width = getWidth();
901 int height = getHeight();
903 jalview.util.ImageMaker im;
905 if (type == jalview.util.ImageMaker.PNG)
907 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
908 "Make PNG image from view", width, height, null, null);
912 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
913 "Make EPS file from view", width, height, null,
917 if (im.getGraphics() != null)
919 Rectangle rect = new Rectangle(width, height);
920 jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
924 public void jmolColour_actionPerformed(ActionEvent actionEvent)
926 if (jmolColour.isSelected()) {
927 // disable automatic sequence colouring.
928 jmb.setColourBySequence(false);
931 public void seqColour_actionPerformed(ActionEvent actionEvent)
933 jmb.setColourBySequence(seqColour.isSelected());
934 if (_colourwith == null)
936 _colourwith = new Vector<AlignmentPanel>();
938 if (jmb.isColourBySequence())
940 if (!jmb.isLoadingFromArchive())
942 if (_colourwith.size()==0 && ap!=null) {
943 // Make the currently displayed alignment panel the associated view
944 _colourwith.add(ap.alignFrame.alignPanel);
947 // Set the colour using the current view for the associated alignframe
948 for (AlignmentPanel ap : _colourwith)
950 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
955 public void chainColour_actionPerformed(ActionEvent actionEvent)
957 chainColour.setSelected(true);
961 public void chargeColour_actionPerformed(ActionEvent actionEvent)
963 chargeColour.setSelected(true);
964 jmb.colourByCharge();
967 public void zappoColour_actionPerformed(ActionEvent actionEvent)
969 zappoColour.setSelected(true);
970 jmb.setJalviewColourScheme(new ZappoColourScheme());
973 public void taylorColour_actionPerformed(ActionEvent actionEvent)
975 taylorColour.setSelected(true);
976 jmb.setJalviewColourScheme(new TaylorColourScheme());
979 public void hydroColour_actionPerformed(ActionEvent actionEvent)
981 hydroColour.setSelected(true);
982 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
985 public void helixColour_actionPerformed(ActionEvent actionEvent)
987 helixColour.setSelected(true);
988 jmb.setJalviewColourScheme(new HelixColourScheme());
991 public void strandColour_actionPerformed(ActionEvent actionEvent)
993 strandColour.setSelected(true);
994 jmb.setJalviewColourScheme(new StrandColourScheme());
997 public void turnColour_actionPerformed(ActionEvent actionEvent)
999 turnColour.setSelected(true);
1000 jmb.setJalviewColourScheme(new TurnColourScheme());
1003 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1005 buriedColour.setSelected(true);
1006 jmb.setJalviewColourScheme(new BuriedColourScheme());
1009 public void userColour_actionPerformed(ActionEvent actionEvent)
1011 userColour.setSelected(true);
1012 new UserDefinedColours(this, null);
1015 public void backGround_actionPerformed(ActionEvent actionEvent)
1017 java.awt.Color col = JColorChooser.showDialog(this,
1018 "Select Background Colour", null);
1021 jmb.setBackgroundColour(col);
1025 public void jmolHelp_actionPerformed(ActionEvent actionEvent)
1029 jalview.util.BrowserLauncher
1030 .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
1031 } catch (Exception ex)
1036 public void showConsole(boolean showConsole)
1041 if (splitPane == null)
1043 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
1044 splitPane.setTopComponent(renderPanel);
1045 splitPane.setBottomComponent(scriptWindow);
1046 this.getContentPane().add(splitPane, BorderLayout.CENTER);
1047 splitPane.setDividerLocation(getHeight() - 200);
1048 scriptWindow.setVisible(true);
1049 scriptWindow.validate();
1050 splitPane.validate();
1056 if (splitPane != null)
1058 splitPane.setVisible(false);
1063 this.getContentPane().add(renderPanel, BorderLayout.CENTER);
1069 class RenderPanel extends JPanel
1071 final Dimension currentSize = new Dimension();
1073 final Rectangle rectClip = new Rectangle();
1075 public void paintComponent(Graphics g)
1077 getSize(currentSize);
1078 g.getClipBounds(rectClip);
1080 if (jmb.fileLoadingError != null)
1082 g.setColor(Color.black);
1083 g.fillRect(0, 0, currentSize.width, currentSize.height);
1084 g.setColor(Color.white);
1085 g.setFont(new Font("Verdana", Font.BOLD, 14));
1086 g.drawString("Error loading file...", 20, currentSize.height / 2);
1087 StringBuffer sb = new StringBuffer();
1089 for (int e = 0; e < jmb.pdbentry.length; e++)
1091 sb.append(jmb.pdbentry[e].getId());
1092 if (e < jmb.pdbentry.length - 1)
1097 if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
1100 g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
1101 * g.getFontMetrics().getHeight());
1105 else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
1107 g.setColor(Color.black);
1108 g.fillRect(0, 0, currentSize.width, currentSize.height);
1109 g.setColor(Color.white);
1110 g.setFont(new Font("Verdana", Font.BOLD, 14));
1111 g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
1115 jmb.viewer.renderScreenImage(g, currentSize, rectClip);
1120 String viewId = null;
1122 public String getViewId()
1126 viewId = System.currentTimeMillis() + "." + this.hashCode();
1131 public void updateTitleAndMenus()
1133 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1138 setChainMenuItems(jmb.chainNames);
1140 this.setTitle(jmb.getViewerTitle());
1141 if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
1143 jmolActionMenu.setVisible(true);
1145 if (!jmb.isLoadingFromArchive())
1147 seqColour_actionPerformed(null);
1151 protected void buildJmolActionMenu()
1153 if (_alignwith == null)
1155 _alignwith = new Vector<AlignmentPanel>();
1157 if (_alignwith.size() == 0 && ap != null)
1162 for (Component c : jmolActionMenu.getMenuComponents())
1164 if (c != alignStructs)
1166 jmolActionMenu.remove((JMenuItem) c);
1169 final ItemListener handler;
1176 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1180 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1182 alignStructs_withAllAlignPanels();
1185 private void alignStructs_withAllAlignPanels()
1192 if (_alignwith.size() == 0)
1199 AlignmentI[] als = new Alignment[_alignwith.size()];
1200 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1201 int[] alm = new int[_alignwith.size()];
1204 for (AlignmentPanel ap : _alignwith)
1206 als[a] = ap.av.getAlignment();
1208 alc[a++] = ap.av.getColumnSelection();
1210 jmb.superposeStructures(als, alm, alc);
1211 } catch (Exception e)
1213 StringBuffer sp = new StringBuffer();
1214 for (AlignmentPanel ap : _alignwith)
1216 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1218 Cache.log.info("Couldn't align structures with the " + sp.toString()
1219 + "associated alignment panels.", e);
1225 public void setJalviewColourScheme(ColourSchemeI ucs)
1227 jmb.setJalviewColourScheme(ucs);
1234 * @return first alignment panel displaying given alignment, or the default
1237 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1239 for (AlignmentPanel ap : getAllAlignmentPanels())
1241 if (ap.av.getAlignment() == alignment)
1252 * @return true if this Jmol instance is linked with the given alignPanel
1254 public boolean isLinkedWith(AlignmentPanel ap2)
1256 return _aps.contains(ap2.av.getSequenceSetId());
1259 public boolean isUsedforaligment(AlignmentPanel ap2)
1262 return (_alignwith != null) && _alignwith.contains(ap2);
1265 public boolean isUsedforcolourby(AlignmentPanel ap2)
1267 return (_colourwith != null) && _colourwith.contains(ap2);